Index: maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/extension/ParserJavaActionConfig.java diff -u /dev/null maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/extension/ParserJavaActionConfig.java:1.1 --- /dev/null Sun Jan 20 18:35:40 2008 +++ maven-i18n-plugin/src/java/org/codelutin/i18n/plugin/extension/ParserJavaActionConfig.java Sun Jan 20 18:35:35 2008 @@ -0,0 +1,85 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, +* Tony Chemit +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package org.codelutin.i18n.plugin.extension; + +import org.codelutin.i18n.plugin.core.ParserEvent; + +import java.io.File; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Un paseur java pour scanner les annotations ActionConfig + * + * @author chemit + * @goal parserJavaActionConfig + * @phase compile + */ +public class ParserJavaActionConfig extends ParserJava { + + protected static final Pattern MATCH_PATTERN = Pattern.compile("(name|shortDescription|longDescription)\\s*=\\s*\"([\\w|\\.]+)\"\\s*,\\.*"); + + @Override + protected String getKeyModifierStart() { + return "[\\w|\\.]+\\s*=\\s*\""; + } + + @Override + protected String getKeyModifierEnd() { + return "\"\\s*(\\)|,|\\+|$)"; + } + + @Override + protected String getOutGetter() { + return "java-action-config.getter"; + } + + /* + * (non-Javadoc) + * @see org.codelutin.i18n.plugin.extension.XmlParser#extract(java.lang.String) + */ + public String extract(String i18nString) { + Matcher matcher = MATCH_PATTERN.matcher(i18nString.trim()); + if (matcher.matches()) { + return matcher.group(2); + } + return null; + } + + /* + * (non-Javadoc) + * @see org.codelutin.i18n.plugin.core.Parser#parseLine(java.io.File, java.lang.String) + */ + public void parseLine(File srcFile, String line) { + String key = extract(line); + if (key != null) { + String keyModified = key; + for (ParserEvent event : events) { + event.eventChangeKey(key, !oldLanguage.containsKey(key)); + keyModified = event.eventGetRealKey(); + } + if (oldParser.containsKey(key)) { + result.put(keyModified, oldParser.get(key)); + } else { + result.put(keyModified, key); + } + } + } + +}