Author: tchemit Date: 2011-01-20 08:33:24 +0100 (Thu, 20 Jan 2011) New Revision: 1848 Url: http://nuiton.org/repositories/revision/i18n/1848 Log: Evolution #1213: Updates to processor 1.1 (use his new api) Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserGWTJavaMojo.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaMojo.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserTapestryMojo.java trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ProcessorHelper.java Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserGWTJavaMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserGWTJavaMojo.java 2011-01-20 07:25:14 UTC (rev 1847) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserGWTJavaMojo.java 2011-01-20 07:33:24 UTC (rev 1848) @@ -34,6 +34,7 @@ import org.nuiton.io.FileUpdater; import org.nuiton.io.MirroredFileUpdater; import org.nuiton.io.SortedProperties; +import org.nuiton.processor.ProcessorUtil; import java.io.File; import java.io.FileInputStream; @@ -252,20 +253,20 @@ */ public static class GWTJavaProcessor extends ProcessorHelper.AbstractParserProcessor { - protected ProcessorHelper.KeyExtractor filter1 = - new ProcessorHelper.KeyExtractor( + protected ProcessorUtil.FragmentExtractor filter1 = + new ProcessorUtil.FragmentExtractor( "@Key(\"", "\")" ); - protected ProcessorHelper.KeyExtractor filter2 = - new ProcessorHelper.KeyExtractor( + protected ProcessorUtil.FragmentExtractor filter2 = + new ProcessorUtil.FragmentExtractor( "@LocalizableResource.Key(\"", "\")" ); - protected ProcessorHelper.KeyExtractor filter3 = - new ProcessorHelper.KeyExtractor( + protected ProcessorUtil.FragmentExtractor filter3 = + new ProcessorUtil.FragmentExtractor( "@com.google.gwt.i18n.client.LocalizableResource.Key(\"", "\")" ); Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaMojo.java 2011-01-20 07:25:14 UTC (rev 1847) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaMojo.java 2011-01-20 07:33:24 UTC (rev 1848) @@ -184,12 +184,17 @@ } } + /** + * Pour filtrer les clefs i18n dans un fichier java. + * + * @since 2.1 + */ public static class I18nFilter extends DefaultFilter { /** Instance logger */ private final Log log; -// private String header = "_\\(\\s*\""; + // private String header = "_\\(\\s*\""; private String header = "^_\\(\\s*\\\"|[^l]_\\(\\s*\\\"|l_\\([^,]+\\s*,\\s*\\\""; private String footer = "\"\\s*(\\)|,|\\+|$)"; Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserTapestryMojo.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserTapestryMojo.java 2011-01-20 07:25:14 UTC (rev 1847) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserTapestryMojo.java 2011-01-20 07:33:24 UTC (rev 1848) @@ -34,6 +34,7 @@ import org.nuiton.io.FileUpdater; import org.nuiton.io.MirroredFileUpdater; import org.nuiton.io.SortedProperties; +import org.nuiton.processor.ProcessorUtil; import java.io.File; import java.io.FileInputStream; @@ -256,14 +257,14 @@ "-" + "-" + ">" ); - protected ProcessorHelper.KeyExtractor extractor1 = - new ProcessorHelper.KeyExtractor( + protected ProcessorUtil.FragmentExtractor extractor1 = + new ProcessorUtil.FragmentExtractor( "$" + "{" + "m" + "e" + "s" + "s" + "a" + "g" + "e" + ":", "}" ); - protected ProcessorHelper.KeyExtractor extractor2 = - new ProcessorHelper.KeyExtractor( + protected ProcessorUtil.FragmentExtractor extractor2 = + new ProcessorUtil.FragmentExtractor( "$" + "{" + "f" + "o" + "r" + "m" + "a" + "t" + ":", "}") { Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ProcessorHelper.java =================================================================== --- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ProcessorHelper.java 2011-01-20 07:25:14 UTC (rev 1847) +++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ProcessorHelper.java 2011-01-20 07:33:24 UTC (rev 1848) @@ -30,16 +30,13 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.processor.Processor; import org.nuiton.processor.ProcessorUtil; -import org.nuiton.processor.filters.DefaultFilter; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.OutputStream; -import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -85,7 +82,7 @@ doProcess(this, filein, fileout, encoding); } - public void extractKeys(KeyExtractor filter, + public void extractKeys(FragmentExtractor filter, File filein, String encoding, boolean verbose, @@ -127,141 +124,4 @@ } } - /** - * To extract all content inside the header and footer. - * - * @author tchemit <chemit@codelutin.com> - * @since 2.1 - */ - public static class KeyExtractor extends DefaultFilter { - - /** Logger. */ - static protected final Log log = - LogFactory.getLog(KeyExtractor.class); - - protected String header; - - protected String footer; - - protected boolean verbose; - - public KeyExtractor(String header, String footer) { - this.header = header; - this.footer = footer; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - @Override - protected String performInFilter(String ch) { - if (verbose) { - log.info("Detected key " + ch); - } - return ch + "\n"; - } - - @Override - protected String performOutFilter(String ch) { - return EMPTY_STRING; - } - - @Override - protected String getHeader() { - return header; - } - - @Override - protected String getFooter() { - return footer; - } - } - - /** - * To remove all content inside the header and footer. - * - * @author tchemit <chemit@codelutin.com> - * @since 2.1 - */ - public static class FragmentRemover extends DefaultFilter { - - /** Logger. */ - static private final Log log = - LogFactory.getLog(FragmentRemover.class); - - protected String header; - - protected String footer; - - protected boolean verbose; - - public FragmentRemover(String header, String footer) { - this.header = header; - this.footer = footer; - } - - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - @Override - protected String performInFilter(String ch) { - if (verbose) { - log.info("Will remove " + ch); - } - return EMPTY_STRING; - } - - @Override - protected String performOutFilter(String ch) { - return ch; - } - - @Override - protected String getHeader() { - return header; - } - - @Override - protected String getFooter() { - return footer; - } - } - - /** - * Launch the process of the given {@code processor} to the given streams. - * - * @param processor the processor to launch - * @param in the input file - * @param out the output file - * @param encoding encoding to use to read and write files. - * @throws IOException if any problems while processing file - * @since 2.1 remove this when will use processor >= 1.1 - */ - public static void doProcess(Processor processor, - InputStream in, - OutputStream out, - String encoding) throws IOException { - InputStreamReader input = new InputStreamReader(in, encoding); - try { - OutputStreamWriter output = new OutputStreamWriter(out, encoding); - try { - processor.process(input, output); - } catch (IOException eee) { - if (log.isErrorEnabled()) { - log.error( - "Error while processing file " + in + " to " + out + - " with processor " + processor, eee); - } - throw eee; - } finally { - output.close(); - } - } finally { - input.close(); - } - } - - }