I18n-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- 802 discussions
Author: tchemit
Date: 2011-01-04 14:43:41 +0100 (Tue, 04 Jan 2011)
New Revision: 1837
Url: http://nuiton.org/repositories/revision/i18n/1837
Log:
pass to version 2.1-SNAPSHOT
Evolution #1196: Introduce GWT Parser to grab i18n keys from java files
refactor processor code to use for any Parser processor
Added:
trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/java/com/
trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/java/com/google/
trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/java/com/google/gwt/
trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/java/com/google/gwt/i18n/
trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/java/com/google/gwt/i18n/client/
trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/java/com/google/gwt/i18n/client/LocalizableResource.java
trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/java/org/nuiton/i18n/test/MyGWTBean.java
trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/java/com/
trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/java/com/google/
trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/java/com/google/gwt/
trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/java/com/google/gwt/i18n/
trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/java/com/google/gwt/i18n/client/
trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/java/com/google/gwt/i18n/client/LocalizableResource.java
trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/java/org/nuiton/i18n/test/MyGWTBean.java
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/ProcessorHelper.java
Removed:
trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/Parser.java
trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/JspFileProcessor.java
trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserXmlMojo.java
trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/TapestryFileProcessor.java
Modified:
trunk/ant-i18n-task/pom.xml
trunk/maven-i18n-plugin/pom.xml
trunk/maven-i18n-plugin/src/it/parsers/newProject/pom.xml
trunk/maven-i18n-plugin/src/it/parsers/newProject/verify.groovy
trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/pom.xml
trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/verify.groovy
trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJspMojo.java
trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserTapestryMojo.java
trunk/nuiton-i18n/pom.xml
trunk/pom.xml
Modified: trunk/ant-i18n-task/pom.xml
===================================================================
--- trunk/ant-i18n-task/pom.xml 2011-01-04 08:15:32 UTC (rev 1836)
+++ trunk/ant-i18n-task/pom.xml 2011-01-04 13:43:41 UTC (rev 1837)
@@ -34,7 +34,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>i18n</artifactId>
- <version>2.0.1-SNAPSHOT</version>
+ <version>2.1-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.i18n</groupId>
Modified: trunk/maven-i18n-plugin/pom.xml
===================================================================
--- trunk/maven-i18n-plugin/pom.xml 2011-01-04 08:15:32 UTC (rev 1836)
+++ trunk/maven-i18n-plugin/pom.xml 2011-01-04 13:43:41 UTC (rev 1837)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>i18n</artifactId>
- <version>2.0.2-SNAPSHOT</version>
+ <version>2.1-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.i18n</groupId>
Modified: trunk/maven-i18n-plugin/src/it/parsers/newProject/pom.xml
===================================================================
--- trunk/maven-i18n-plugin/src/it/parsers/newProject/pom.xml 2011-01-04 08:15:32 UTC (rev 1836)
+++ trunk/maven-i18n-plugin/src/it/parsers/newProject/pom.xml 2011-01-04 13:43:41 UTC (rev 1837)
@@ -73,6 +73,7 @@
<goal>parserJava</goal>
<goal>parserValidation</goal>
<goal>parserTapestry</goal>
+ <goal>parserGWTJava</goal>
</goals>
</execution>
<execution>
@@ -97,6 +98,7 @@
<goal>parserJava</goal>
<goal>parserValidation</goal>
<goal>parserTapestry</goal>
+ <goal>parserGWTJava</goal>
</goals>
<phase>compile</phase>
</execution>
Added: trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/java/com/google/gwt/i18n/client/LocalizableResource.java
===================================================================
--- trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/java/com/google/gwt/i18n/client/LocalizableResource.java (rev 0)
+++ trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/java/com/google/gwt/i18n/client/LocalizableResource.java 2011-01-04 13:43:41 UTC (rev 1837)
@@ -0,0 +1,13 @@
+package com.google.gwt.i18n.client;
+
+import java.lang.annotation.*;
+import static java.lang.annotation.ElementType.*;
+
+public class LocalizableResource {
+
+ @Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface Key {
+ String[] value();
+ }
+}
\ No newline at end of file
Property changes on: trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/java/com/google/gwt/i18n/client/LocalizableResource.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/java/org/nuiton/i18n/test/MyGWTBean.java (from rev 1834, trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/java/org/nuiton/i18n/test/MyBean.java)
===================================================================
--- trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/java/org/nuiton/i18n/test/MyGWTBean.java (rev 0)
+++ trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/java/org/nuiton/i18n/test/MyGWTBean.java 2011-01-04 13:43:41 UTC (rev 1837)
@@ -0,0 +1,41 @@
+/*
+ * #%L
+ * I18n :: Maven Plugin
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2007 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.i18n.test;
+
+import com.google.gwt.i18n.client.LocalizableResource;
+import static com.google.gwt.i18n.client.LocalizableResource.Key;
+
+public class MyGWTBean {
+
+ @Key("gwtJavaGetter.key1")
+ protected String field1;
+
+ @LocalizableResource.Key("gwtJavaGetter.key2")
+ protected String field2;
+
+ @com.google.gwt.i18n.client.LocalizableResource.Key("gwtJavaGetter.key3")
+ protected String field3;
+
+}
Modified: trunk/maven-i18n-plugin/src/it/parsers/newProject/verify.groovy
===================================================================
--- trunk/maven-i18n-plugin/src/it/parsers/newProject/verify.groovy 2011-01-04 08:15:32 UTC (rev 1836)
+++ trunk/maven-i18n-plugin/src/it/parsers/newProject/verify.groovy 2011-01-04 13:43:41 UTC (rev 1837)
@@ -51,4 +51,12 @@
assert content.contains( 'tmlGetter.key1=' );
assert content.contains( 'tmlGetter.key2=' );
+file = new File(basedir, 'target/generated-sources/i18n/gwt-java.getter');
+assert file.exists();
+
+content = file.text;
+assert content.contains( 'gwtJavaGetter.key1=' );
+assert content.contains( 'gwtJavaGetter.key2=' );
+assert content.contains( 'gwtJavaGetter.key3=' );
+
return true;
Modified: trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/pom.xml
===================================================================
--- trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/pom.xml 2011-01-04 08:15:32 UTC (rev 1836)
+++ trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/pom.xml 2011-01-04 13:43:41 UTC (rev 1837)
@@ -82,6 +82,7 @@
<id>first</id>
<goals>
<goal>parserJava</goal>
+ <goal>parserGWTJava</goal>
<goal>parserValidation</goal>
<goal>parserTapestry</goal>
</goals>
@@ -112,6 +113,7 @@
<id>second</id>
<goals>
<goal>parserJava</goal>
+ <goal>parserGWTJava</goal>
<goal>parserValidation</goal>
<goal>parserTapestry</goal>
<goal>gen</goal>
Added: trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/java/com/google/gwt/i18n/client/LocalizableResource.java
===================================================================
--- trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/java/com/google/gwt/i18n/client/LocalizableResource.java (rev 0)
+++ trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/java/com/google/gwt/i18n/client/LocalizableResource.java 2011-01-04 13:43:41 UTC (rev 1837)
@@ -0,0 +1,13 @@
+package com.google.gwt.i18n.client;
+
+import java.lang.annotation.*;
+import static java.lang.annotation.ElementType.*;
+
+public class LocalizableResource {
+
+ @Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface Key {
+ String[] value();
+ }
+}
\ No newline at end of file
Property changes on: trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/java/com/google/gwt/i18n/client/LocalizableResource.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/java/org/nuiton/i18n/test/MyGWTBean.java
===================================================================
--- trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/java/org/nuiton/i18n/test/MyGWTBean.java (rev 0)
+++ trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/java/org/nuiton/i18n/test/MyGWTBean.java 2011-01-04 13:43:41 UTC (rev 1837)
@@ -0,0 +1,41 @@
+/*
+ * #%L
+ * I18n :: Maven Plugin
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2007 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.i18n.test;
+
+import com.google.gwt.i18n.client.LocalizableResource;
+import static com.google.gwt.i18n.client.LocalizableResource.Key;
+
+public class MyGWTBean {
+
+ @Key("gwtJavaGetter.key1")
+ protected String field1;
+
+ @LocalizableResource.Key("gwtJavaGetter.key2")
+ protected String field2;
+
+ @com.google.gwt.i18n.client.LocalizableResource.Key("gwtJavaGetter.key3")
+ protected String field3;
+
+}
Property changes on: trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/java/org/nuiton/i18n/test/MyGWTBean.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/verify.groovy
===================================================================
--- trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/verify.groovy 2011-01-04 08:15:32 UTC (rev 1836)
+++ trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/verify.groovy 2011-01-04 13:43:41 UTC (rev 1837)
@@ -55,6 +55,15 @@
assert content.contains( 'tmlGetter.key1=' );
assert content.contains( 'tmlGetter.key2=' );
+
+file = new File(basedir, 'target/generated-sources/i18n/gwt-java.getter');
+assert file.exists();
+
+content = file.text;
+assert content.contains( 'gwtJavaGetter.key1=' );
+assert content.contains( 'gwtJavaGetter.key2=' );
+assert content.contains( 'gwtJavaGetter.key3=' );
+
file = new File(basedir, 'src/main/resources/i18n/parsers-withNewKeys_fr_FR.properties');
assert file.exists();
@@ -72,4 +81,8 @@
assert content.contains( 'tmlGetter.key1=' );
assert content.contains( 'tmlGetter.key2=' );
+assert content.contains( 'gwtJavaGetter.key1=' );
+assert content.contains( 'gwtJavaGetter.key2=' );
+assert content.contains( 'gwtJavaGetter.key3=' );
+
return true;
Deleted: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/Parser.java
===================================================================
--- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/Parser.java 2011-01-04 08:15:32 UTC (rev 1836)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/Parser.java 2011-01-04 13:43:41 UTC (rev 1837)
@@ -1,67 +0,0 @@
-/*
- * #%L
- * I18n :: Maven Plugin
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2007 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.i18n.plugin.parser;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * Interface type pour la définition d'un nouveau parser.
- * <p/>
- * Une implantation abstraite est proposée : {@link AbstractI18nParserMojo}.
- *
- * @author julien
- * @deprecated since 1.2, use now {@link FileParser} api, which is
- * multi-thread
- */
-@Deprecated
-public interface Parser {
-
- /**
- * Lancement du parser
- *
- * @throws IOException if any io pb
- */
- void parse() throws IOException;
-
- /**
- * Parse sur un fichier
- *
- * @param file le fichier à parser
- * @throws IOException if any pb
- */
- void parseFile(File file) throws IOException;
-
- /**
- * Parse une partie du fichier
- *
- * @param file le fichier à parser
- * @param line la ligne à parser
- * @throws IOException if any pb
- */
- void parseLine(File file, String line) throws IOException;
-
-}
Deleted: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/JspFileProcessor.java
===================================================================
--- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/JspFileProcessor.java 2011-01-04 08:15:32 UTC (rev 1836)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/JspFileProcessor.java 2011-01-04 13:43:41 UTC (rev 1837)
@@ -1,167 +0,0 @@
-/*
- * #%L
- * I18n :: Maven Plugin
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2007 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.i18n.plugin.parser.impl;
-
-import org.nuiton.processor.Processor;
-import org.nuiton.processor.ProcessorUtil;
-import org.nuiton.processor.filters.DefaultFilter;
-import org.nuiton.processor.filters.Filter;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * To transform jsp files to valid xml files.
- * <p/>
- * Says :
- * <ul>
- * <li>Remove jsp directive</li>
- * <li>Remove jsp comment</li>
- * <li>Remove any tags in attributes (used for example in struts)</li>
- * <li>? Other thing</li>
- * </ul>
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
-public class JspFileProcessor extends Processor {
-
- public JspFileProcessor() {
- setInputFilter(
- new Filter[]{
- new JspDirectiveFilter(),
- new JspCommentFilter(),
- new JspAttributeWithTagFilter()
- }
- );
- }
-
- /**
- * @param filein the source file to process
- * @param fileout the output file to generate
- * @param encoding encoding used to read and write files
- * @throws IOException if any io problems while processing
- * @since 1.0.4
- */
- public void process(File filein,
- File fileout,
- String encoding) throws IOException {
- ProcessorUtil.doProcess(this, filein, fileout, encoding);
- }
-
- /**
- * To remove in attributes any sub tags inside it (used for example in
- * struts) from jsp files.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
- public static class JspAttributeWithTagFilter extends DefaultFilter {
-
- private String header = "=" + "\"" + "<";
-
- private String footer = "\"" + "/" + ">" + "\"";
-
- @Override
- protected String performInFilter(String ch) {
- return "=\"\"";
- }
-
- @Override
- protected String performOutFilter(String ch) {
- return ch;
- }
-
- protected String getHeader() {
- return header;
- }
-
- protected String getFooter() {
- return footer;
- }
- }
-
- /**
- * To remove jsp comment from files.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
- public static class JspCommentFilter extends DefaultFilter {
-
- private String header = "<" + "%" + "-" + "-";
-
- private String footer = "-" + "-" + "%" + ">";
-
- @Override
- protected String performInFilter(String ch) {
- return EMPTY_STRING;
- }
-
- @Override
- protected String performOutFilter(String ch) {
- return ch;
- }
-
- protected String getHeader() {
- return header;
- }
-
- protected String getFooter() {
- return footer;
- }
- }
-
- /**
- * To remove jsp directive from files.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0
- */
- public static class JspDirectiveFilter extends DefaultFilter {
-
- private String header = "<" + "%";
-
- private String footer = "%" + ">";
-
- @Override
- protected String performInFilter(String ch) {
- return EMPTY_STRING;
- }
-
- @Override
- protected String performOutFilter(String ch) {
- return ch;
- }
-
- protected String getHeader() {
- return header;
- }
-
- protected String getFooter() {
- return footer;
- }
- }
-}
Added: 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 (rev 0)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserGWTJavaMojo.java 2011-01-04 13:43:41 UTC (rev 1837)
@@ -0,0 +1,263 @@
+package org.nuiton.i18n.plugin.parser.impl;
+
+import org.apache.maven.plugin.logging.Log;
+import org.nuiton.i18n.plugin.parser.AbstractFileParser;
+import org.nuiton.i18n.plugin.parser.AbstractI18nParserMojo;
+import org.nuiton.i18n.plugin.parser.FileParser;
+import org.nuiton.i18n.plugin.parser.I18nSourceEntry;
+import org.nuiton.i18n.plugin.parser.ParserException;
+import org.nuiton.i18n.plugin.parser.SourceEntry;
+import org.nuiton.io.FileUpdater;
+import org.nuiton.io.MirroredFileUpdater;
+import org.nuiton.io.SortedProperties;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * To detect from GWT java files Tapestry templates new I18n keys, says content of patterns :
+ * <ul>
+ * <li>{@code @Key("XXX")}</li>
+ * <li>{@code @LocalizableResource.Key("XXX")}</li>
+ * <li>{@code @com.google.gwt.i18n.client.LocalizableResource.Key("XXX")}</li>
+ * </ul>
+ * <b>Note: </b> this goal must always be invoked before the {@code process-resources}
+ * phase, otherwise all files will be considered as uptodate.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @goal parserGWTJava
+ * @phase generate-resources
+ * @since 2.1
+ */
+public class ParserGWTJavaMojo extends AbstractI18nParserMojo {
+
+ /**
+ * Root directory of the default entry.
+ *
+ * @parameter expression="${i18n.defaultBasedir}" default-value="${basedir}/src/main/java"
+ */
+ protected File defaultBasedir;
+
+ /**
+ * Default included files to process (ant-like expression).
+ *
+ * @parameter expression="${i18n.defaultIncludes}" default-value="**\/*.java"
+ */
+ protected String defaultIncludes;
+
+ /**
+ * Defines the file name of the getter where to put detected i18n keys
+ * while getter phase.
+ *
+ * @parameter expression="${i18n.outputGetter}" default-value="gwt-java.getter"
+ * @since 2.0
+ */
+ protected String outputGetter;
+
+ /**
+ * Where to generated temporary processed files.
+ *
+ * @parameter expression="${i18n.workdir}" default-value="${basedir}/target/i18n-workdir"
+ * @since 2.0
+ */
+ protected File workdir;
+
+ protected MirroredFileUpdater entryUpdater;
+
+ @Override
+ public String[] getDefaultIncludes() {
+ return new String[]{defaultIncludes};
+ }
+
+ @Override
+ public String[] getDefaultExcludes() {
+ return I18nSourceEntry.EMPTY_STRING_ARRAY;
+ }
+
+ @Override
+ public File getDefaultBasedir() {
+ return defaultBasedir;
+ }
+
+ @Override
+ protected boolean onEnterEntry(I18nSourceEntry entry) {
+ boolean b = super.onEnterEntry(entry);
+ if (!b) {
+
+ // no skipped entry
+ // keep the file updater
+ entryUpdater = (MirroredFileUpdater) entry.getUpdater();
+ }
+ return b;
+ }
+
+ @Override
+ public FileUpdater newFileUpdater(SourceEntry entry) {
+ return new MirroredFileUpdater("", "", entry.getBasedir(), workdir) {
+
+ @Override
+ public File getMirrorFile(File f) {
+ String file =
+ f.getAbsolutePath().substring(prefixSourceDirecotory);
+ return new File(destinationDirectory + File.separator + file);
+ }
+ };
+ }
+
+ @Override
+ @Deprecated
+ protected String getKeyModifierStart() {
+ return "_\\(\\s*\"";
+ }
+
+ @Override
+ @Deprecated
+ protected String getKeyModifierEnd() {
+ return "\"\\s*(\\)|,|\\+|$)";
+ }
+
+ @Override
+ protected String getOutGetter() {
+ return outputGetter;
+ }
+
+ @Override
+ public FileParser newFileParser() {
+
+ return new GWTJavaFileParser(getLog(),
+ getEncoding(),
+ oldParser,
+ isShowTouchedFiles()
+ );
+ }
+
+ protected class GWTJavaFileParser extends AbstractFileParser {
+
+
+ public GWTJavaFileParser(Log log,
+ String encoding,
+ SortedProperties oldParser,
+ boolean showTouchedFiles) {
+ super(log, encoding, oldParser, showTouchedFiles);
+ }
+
+
+ protected File prepareFile(File file) throws IOException {
+
+ // clean the jsp to make it xml
+
+ File result = entryUpdater.getMirrorFile(file);
+ if (isVerbose()) {
+ getLog().info("Will process [" + file + "] to " + result);
+ }
+ try {
+ createDirectoryIfNecessary(result.getParentFile());
+ } catch (IOException e) {
+ // don't care about it...
+ }
+ GWTJavaProcessor processor = new GWTJavaProcessor();
+ processor.setVerbose(isVerbose());
+ processor.process(file, result, getEncoding());
+ return result;
+ }
+
+ @Override
+ public void parseFile(File file) throws IOException {
+
+ // clean the jsp to make it xml
+
+ File processedFile = prepareFile(file);
+
+ // process file to obtain
+ String line = null;
+ LineNumberReader lnr = new LineNumberReader(new InputStreamReader(
+ new FileInputStream(processedFile), getEncoding()));
+ try {
+ while ((line = lnr.readLine()) != null) {
+ parseLine(processedFile, line);
+ }
+ } catch (Exception e) {
+ if (line != null) {
+ getLog().error(
+ "could not parse line (" + lnr.getLineNumber() + ") '"
+ + line + "' of file " + file);
+ }
+ throw new ParserException(e);
+ } finally {
+ lnr.close();
+ }
+ }
+
+ @Override
+ public void parseLine(File file, String line) throws IOException {
+
+ String key = line.trim();
+
+ if (key.isEmpty()) {
+ // no key detected on this line
+ return;
+ }
+
+ // one key found in file, so file is marked as touched
+ setTouched(true);
+ // Found a i18n key, register it.
+ if (getLog().isDebugEnabled()) {
+ getLog().debug(file.getName() + " detected key = " + key);
+ }
+ registerKey(key);
+ }
+ }
+
+ /**
+ * To Extract i18n keys from GWT java files.
+ * <p/>
+ * Says keep content only of those patterns :
+ * <ul>
+ * <li>{@code @Key("XXX")}</li>
+ * <li>{@code @LocalizableResource.Key("XXX")}</li>
+ * <li>{@code @com.google.gwt.i18n.client.LocalizableResource.Key("XXX")}</li>
+ * </ul>
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+ public static class GWTJavaProcessor extends ProcessorHelper.AbstractParserProcessor {
+
+ protected ProcessorHelper.KeyExtractor filter1 =
+ new ProcessorHelper.KeyExtractor(
+ "@Key(\"",
+ "\")"
+ );
+
+ protected ProcessorHelper.KeyExtractor filter2 =
+ new ProcessorHelper.KeyExtractor(
+ "@LocalizableResource.Key(\"",
+ "\")"
+ );
+
+ protected ProcessorHelper.KeyExtractor filter3 =
+ new ProcessorHelper.KeyExtractor(
+ "@com.google.gwt.i18n.client.LocalizableResource.Key(\"",
+ "\")"
+ );
+
+
+ @Override
+ public void process(File filein,
+ File fileout,
+ String encoding) throws IOException {
+
+ Set<String> keys = new HashSet<String>();
+ extractKeys(filter1, filein, encoding, verbose, keys);
+ extractKeys(filter2, filein, encoding, verbose, keys);
+ extractKeys(filter3, filein, encoding, verbose, keys);
+ saveKeysToFile(fileout, keys);
+ }
+
+ }
+}
\ No newline at end of file
Property changes on: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserGWTJavaMojo.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJspMojo.java
===================================================================
--- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJspMojo.java 2011-01-04 08:15:32 UTC (rev 1836)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJspMojo.java 2011-01-04 13:43:41 UTC (rev 1837)
@@ -29,6 +29,9 @@
import org.nuiton.i18n.plugin.parser.SourceEntry;
import org.nuiton.io.FileUpdater;
import org.nuiton.io.MirroredFileUpdater;
+import org.nuiton.processor.ProcessorUtil;
+import org.nuiton.processor.filters.DefaultFilter;
+import org.nuiton.processor.filters.Filter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.xpath.XPath;
@@ -195,4 +198,151 @@
protected String getKeyModifierEnd() {
return "[\"\']";
}
+
+ /**
+ * To transform jsp files to valid xml files.
+ * <p/>
+ * Says :
+ * <ul>
+ * <li>Remove jsp directive</li>
+ * <li>Remove jsp comment</li>
+ * <li>Remove any tags in attributes (used for example in struts)</li>
+ * <li>? Other thing</li>
+ * </ul>
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+ public static class JspFileProcessor extends ProcessorHelper.AbstractParserProcessor {
+
+ protected ProcessorHelper.FragmentRemover remover1 =
+ new ProcessorHelper.FragmentRemover(
+ "<" + "%" + "-" + "-",
+ "-" + "-" + "%" + ">"
+ );
+
+ protected ProcessorHelper.FragmentRemover remover2 =
+ new ProcessorHelper.FragmentRemover(
+ "<" + "%",
+ "%" + ">"
+ );
+
+ public JspFileProcessor() {
+ setInputFilter(
+ new Filter[]{
+ remover1,
+ remover2,
+ new JspAttributeWithTagFilter()
+ }
+ );
+ }
+
+ /**
+ * @param filein the source file to process
+ * @param fileout the output file to generate
+ * @param encoding encoding used to read and write files
+ * @throws IOException if any io problems while processing
+ * @since 1.0.4
+ */
+ @Override
+ public void process(File filein,
+ File fileout,
+ String encoding) throws IOException {
+ ProcessorUtil.doProcess(this, filein, fileout, encoding);
+ }
+
+ /**
+ * To remove in attributes any sub tags inside it (used for example in
+ * struts) from jsp files.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+ public static class JspAttributeWithTagFilter extends DefaultFilter {
+
+ private String header = "=" + "\"" + "<";
+
+ private String footer = "\"" + "/" + ">" + "\"";
+
+ @Override
+ protected String performInFilter(String ch) {
+ return "=\"\"";
+ }
+
+ @Override
+ protected String performOutFilter(String ch) {
+ return ch;
+ }
+
+ protected String getHeader() {
+ return header;
+ }
+
+ protected String getFooter() {
+ return footer;
+ }
+ }
+
+ // /**
+ // * To remove jsp comment from files.
+ // *
+ // * @author tchemit <chemit(a)codelutin.com>
+ // * @since 2.0
+ // */
+ // public static class JspCommentFilter extends DefaultFilter {
+ //
+ // private String header = "<" + "%" + "-" + "-";
+ //
+ // private String footer = "-" + "-" + "%" + ">";
+ //
+ // @Override
+ // protected String performInFilter(String ch) {
+ // return EMPTY_STRING;
+ // }
+ //
+ // @Override
+ // protected String performOutFilter(String ch) {
+ // return ch;
+ // }
+ //
+ // protected String getHeader() {
+ // return header;
+ // }
+ //
+ // protected String getFooter() {
+ // return footer;
+ // }
+ // }
+ //
+ // /**
+ // * To remove jsp directive from files.
+ // *
+ // * @author tchemit <chemit(a)codelutin.com>
+ // * @since 2.0
+ // */
+ // public static class JspDirectiveFilter extends DefaultFilter {
+ //
+ // private String header = "<" + "%";
+ //
+ // private String footer = "%" + ">";
+ //
+ // @Override
+ // protected String performInFilter(String ch) {
+ // return EMPTY_STRING;
+ // }
+ //
+ // @Override
+ // protected String performOutFilter(String ch) {
+ // return ch;
+ // }
+ //
+ // protected String getHeader() {
+ // return header;
+ // }
+ //
+ // protected String getFooter() {
+ // return footer;
+ // }
+ // }
+ }
}
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-04 08:15:32 UTC (rev 1836)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserTapestryMojo.java 2011-01-04 13:43:41 UTC (rev 1837)
@@ -40,12 +40,14 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
+import java.util.HashSet;
+import java.util.Set;
/**
* To parse Tapestry templates to detect new I18n keys, says content of patterns :
* {@code ${message:XXX}} and {@code ${format:XXX=...}}.
- *
* <p/>
+ * <p/>
* <b>Note: </b> this goal must always be invoked before the {@code process-resources}
* phase, otherwise all files will be considered as uptodate.
*
@@ -233,4 +235,65 @@
}
}
+ /**
+ * To Extract i18n keys from tapestry template files.
+ * <p/>
+ * Says :
+ * <ul>
+ * <li>Remove all xml comments</li>
+ * <li>Keep content of {@code ${message:XXX}}</li>
+ * <li>Keep content of {@code ${format:XXX}}}</li>
+ * </ul>
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+ public static class TapestryFileProcessor extends ProcessorHelper.AbstractParserProcessor {
+
+ protected ProcessorHelper.FragmentRemover remover1 =
+ new ProcessorHelper.FragmentRemover(
+ "<" + "!" + "-" + "-",
+ "-" + "-" + ">"
+ );
+
+ protected ProcessorHelper.KeyExtractor extractor1 =
+ new ProcessorHelper.KeyExtractor(
+ "$" + "{" + "m" + "e" + "s" + "s" + "a" + "g" + "e" + ":",
+ "}"
+ );
+
+ protected ProcessorHelper.KeyExtractor extractor2 =
+ new ProcessorHelper.KeyExtractor(
+ "$" + "{" + "f" + "o" + "r" + "m" + "a" + "t" + ":",
+ "}") {
+
+ @Override
+ protected String performInFilter(String ch) {
+ int i = ch.indexOf('=');
+ if (verbose) {
+ log.info("Detected key " + ch);
+ }
+ if (i == -1) {
+ return "";
+ }
+ return ch.substring(0, i) + "\n";
+ }
+ };
+
+
+ public void process(File filein,
+ File fileout,
+ String encoding) throws IOException {
+
+ // remove comment fragments
+ File fileTemp = new File(fileout.getAbsolutePath() + "-no-comment");
+ removefragments(remover1, filein, fileTemp, encoding, false);
+
+ Set<String> keys = new HashSet<String>();
+ extractKeys(extractor1, fileTemp, encoding, verbose, keys);
+ extractKeys(extractor2, fileTemp, encoding, verbose, keys);
+ saveKeysToFile(fileout, keys);
+ }
+
+ }
}
Deleted: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserXmlMojo.java
===================================================================
--- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserXmlMojo.java 2011-01-04 08:15:32 UTC (rev 1836)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserXmlMojo.java 2011-01-04 13:43:41 UTC (rev 1837)
@@ -1,263 +0,0 @@
-/*
- * #%L
- * I18n :: Maven Plugin
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2007 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.i18n.plugin.parser.impl;
-
-import org.apache.maven.plugin.logging.Log;
-import org.nuiton.i18n.plugin.parser.AbstractFileParser;
-import org.nuiton.i18n.plugin.parser.AbstractI18nParserMojo;
-import org.nuiton.i18n.plugin.parser.FileParser;
-import org.nuiton.i18n.plugin.parser.ParserException;
-import org.nuiton.io.SortedProperties;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpression;
-import javax.xml.xpath.XPathFactory;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * Récupération des chaines à traduire depuis les fichiers xml.
- *
- * @author julien
- * @deprecated since 2.0, prefer use the {@link AbstractParserXmlMojo} instead.
- */
-@Deprecated
-public abstract class ParserXmlMojo extends AbstractI18nParserMojo {
-
- /** Taille du buffer pour les lectures/écritures */
- protected static final int BUFFER_SIZE = 8 * 1024;
-
- protected String rules;
-
- protected XPathFactory factory;
-
- protected DocumentBuilderFactory documentBuilderFactory;
-
- /** @return le fichier des rules */
- protected abstract String getFileRules();
-
- /** @return le fichier des rules de base à toujours charger */
- protected abstract String getCoreFileRules();
-
- protected abstract XmlFileParser newXmlFileParser(XPath xpath,
- DocumentBuilder builder);
-
- @Override
- public void init() throws Exception {
- super.init();
- factory = XPathFactory.newInstance();
- rules = getRules(getFileRules());
-
- documentBuilderFactory = DocumentBuilderFactory.newInstance();
- documentBuilderFactory.setNamespaceAware(true);
- }
-
- @Override
- public final FileParser newFileParser() {
-
- DocumentBuilder builder;
- try {
- // never forget this!
- builder = documentBuilderFactory.newDocumentBuilder();
- } catch (ParserConfigurationException ex) {
- throw new IllegalStateException(
- "could not load DocumentBuilder for reason " +
- ex.getMessage(), ex);
- }
-
- XPath xpath = factory.newXPath();
-
- return newXmlFileParser(xpath, builder);
- }
-
- /**
- * Récupère le xpath à partir d'un fichier
- *
- * @param fileRules le nom du fichier contant les règles
- * @return le xpath à partir d'un fichier
- */
- private String getRules(String fileRules) {
- StringBuilder buffer = new StringBuilder();
-
- try {
- String readInputStream;
-
- // load core rules
- readInputStream = loadRulesFile(getCoreFileRules());
- if (!silent && verbose) {
- getLog().info("core rules : " + getCoreFileRules());
- }
- buffer.append(readInputStream);
-
- if (!fileRules.equals(getCoreFileRules())) {
- // add custom rules
- readInputStream = loadRulesFile(fileRules);
- if (!silent && verbose) {
- getLog().info("custom rules : " + fileRules);
- }
- buffer.append(" | ").append(readInputStream);
- }
- } catch (IOException e) {
- throw new ParserException(e);
- }
-
- return buffer.toString();
- }
-
- private String loadRulesFile(String fileRules) throws IOException {
- File f = new File(fileRules);
-
- InputStream inputStream;
- if (f.exists()) {
- // load from a file
- try {
- inputStream = new FileInputStream(f);
- } catch (FileNotFoundException e) {
- throw new ParserException(e);
- }
- } else {
- // load from classpath
- ClassLoader classLoader = getClass().getClassLoader();
- inputStream = classLoader.getResourceAsStream(fileRules);
- }
- if (inputStream == null) {
- throw new ParserException(
- "could not found file of rules : " + fileRules);
- }
-
- inputStream = new BufferedInputStream(inputStream);
-
- try {
- // Lecture
- String readInputStream;
- readInputStream = readInputStream(inputStream);
- return readInputStream;
- } catch (IOException e) {
- throw new ParserException(e);
- } finally {
- inputStream.close();
- }
- }
-
- /**
- * Permet la lecture d'un InputStream et Suppressions.
- *
- * @param in le flux entrant
- * @return le contenu du flux
- * @throws IOException si problème de lecture dans flux entrant
- */
- private String readInputStream(InputStream in) throws IOException {
- StringBuilder sb = new StringBuilder();
- byte[] buffer = new byte[BUFFER_SIZE];
- while (in.read(buffer, 0, BUFFER_SIZE) != -1) {
- String tmp = new String(buffer);
- sb.append(tmp);
- }
- in.close();
- // Suppression
- String txt = sb.toString().trim();
- // suppression des commentaires
- txt = txt.replaceAll("#.*\n", "");
- // contruction du xpath avec des ou
- txt = txt.replaceAll("\\s+", " | ");
- // suppression des ou de début ee fin
- txt = txt.replaceAll("(^ \\| )|( \\| $)", "");
- return txt;
- }
-
- public static abstract class XmlFileParser extends AbstractFileParser {
-
- private final XPath xpath;
-
- private final String rules;
-
- private final DocumentBuilder builder;
-
- /**
- * Fonction d'extraction de la chaine
- *
- * @param i18nString le clef i18n
- * @return la chaine
- */
- public abstract String extract(String i18nString);
-
- public XmlFileParser(Log log,
- String encoding,
- SortedProperties oldParser,
- boolean showTouchedFiles,
- String rules,
- XPath xpath,
- DocumentBuilder builder) {
- super(log, encoding, oldParser, showTouchedFiles);
- this.xpath = xpath;
- this.rules = rules;
- this.builder = builder;
-
- }
-
- @Override
- public void parseFile(File file) throws IOException {
-
- try {
-
- // Recherche des clés à partir d'un xpath
-
- Document doc = builder.parse(file.getAbsolutePath());
- XPathExpression expression = xpath.compile(rules);
- NodeList list = (NodeList)
- expression.evaluate(doc, XPathConstants.NODESET);
-
- for (int index = 0; index < list.getLength(); index++) {
- Node node = list.item(index);
- parseLine(file, node.getTextContent());
- }
- } catch (Exception e) {
- throw new ParserException(e);
- }
- }
-
- @Override
- public void parseLine(File file, String key) throws IOException {
-
- key = extract(key);
- if (key != null) {
- setTouched(true);
- registerKey(key);
- }
- }
- }
-}
Added: 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 (rev 0)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ProcessorHelper.java 2011-01-04 13:43:41 UTC (rev 1837)
@@ -0,0 +1,243 @@
+package org.nuiton.i18n.plugin.parser.impl;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+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;
+import java.util.Set;
+
+/**
+ * Helper of processor api.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
+public class ProcessorHelper extends ProcessorUtil {
+
+ /** Logger */
+ private static final Log log = LogFactory.getLog(ProcessorHelper.class);
+
+ /**
+ * Abstract processor to be used with some smooth logic...
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+ public abstract static class AbstractParserProcessor extends Processor {
+
+ protected boolean verbose;
+
+ public void setVerbose(boolean verbose) {
+ this.verbose = verbose;
+ }
+
+ public abstract void process(File filein,
+ File fileout,
+ String encoding) throws IOException;
+
+ protected void removefragments(FragmentRemover filter,
+ File filein,
+ File fileout,
+ String encoding,
+ boolean verbose) throws IOException {
+
+ filter.setVerbose(verbose || log.isDebugEnabled());
+ setInputFilter(filter);
+ doProcess(this, filein, fileout, encoding);
+ }
+
+ public void extractKeys(KeyExtractor filter,
+ File filein,
+ String encoding,
+ boolean verbose,
+ Set<String> result) throws IOException {
+
+ filter.setVerbose(verbose);
+ setInputFilter(filter);
+ InputStream in = new FileInputStream(filein);
+
+ try {
+ OutputStream out = new ByteArrayOutputStream();
+ try {
+ doProcess(this, in, out, encoding);
+ String lines = out.toString();
+ for (String line : lines.split("\n")) {
+ String key = line.trim();
+ if (StringUtils.isNotBlank(key)) {
+ result.add(key);
+ }
+ }
+ } finally {
+ out.close();
+ }
+ } finally {
+ in.close();
+ }
+ }
+
+ public void saveKeysToFile(File fileout,
+ Set<String> keys) throws IOException {
+ StringBuilder buffer = new StringBuilder();
+ List<String> sortedKeys = new ArrayList<String>(keys);
+ Collections.sort(sortedKeys);
+
+ for (String key : keys) {
+ buffer.append(key).append("\n");
+ }
+ FileUtils.writeStringToFile(fileout, buffer.toString());
+ }
+ }
+
+ /**
+ * To extract all content inside the header and footer.
+ *
+ * @author tchemit <chemit(a)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(a)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();
+ }
+ }
+
+
+}
Property changes on: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ProcessorHelper.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/TapestryFileProcessor.java
===================================================================
--- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/TapestryFileProcessor.java 2011-01-04 08:15:32 UTC (rev 1836)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/TapestryFileProcessor.java 2011-01-04 13:43:41 UTC (rev 1837)
@@ -1,192 +0,0 @@
-/*
- * #%L
- * I18n :: Maven Plugin
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 CodeLutin, Tony Chemit
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-package org.nuiton.i18n.plugin.parser.impl;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.processor.Processor;
-import org.nuiton.processor.ProcessorUtil;
-import org.nuiton.processor.filters.DefaultFilter;
-import org.nuiton.processor.filters.Filter;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * To Extract i18n keys from tapestry template files.
- * <p/>
- * Says :
- * <ul>
- * <li>Remove all xml comments</li>
- * <li>Keep content of {@code ${message:XXX}}</li>
- * <li>Keep content of {@code ${format:XXX}}}</li>
- * </ul>
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.1
- */
-public class TapestryFileProcessor extends Processor {
-
- /** Logger. */
- static private final Log log =
- LogFactory.getLog(TapestryFileProcessor.class);
-
- protected boolean verbose;
-
- public void setVerbose(boolean verbose) {
- this.verbose = verbose;
- }
-
- public void process(File filein,
- File fileout,
- String encoding) throws IOException {
- File fileTemp1 = new File(fileout.getAbsolutePath() + "~-message");
- setInputFilter(new Filter[]{
- new RemoveCommentFilter(),
- new ExtractMessageFilter()
- });
- ProcessorUtil.doProcess(this, filein, fileTemp1, encoding);
-
- File fileTemp2 = new File(fileout.getAbsolutePath() + "~-format");
-
- setInputFilter(new Filter[]{
- new RemoveCommentFilter(),
- new ExtractFormatFilter()
- });
- ProcessorUtil.doProcess(this, filein, fileTemp2, encoding);
-
- String tmp1 = FileUtils.readFileToString(fileTemp1).trim();
- String tmp2 = FileUtils.readFileToString(fileTemp2).trim();
- if (log.isDebugEnabled()) {
- log.debug("Keys from message:\n" + tmp1);
- log.debug("Keys from format:\n" + tmp2);
- }
- FileUtils.writeStringToFile(fileout, tmp1 + "\n" + tmp2);
- }
-
- /**
- * To remove comments from tapestry template files.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.1
- */
- public class RemoveCommentFilter extends DefaultFilter {
-
- private String header = "<" + "!" + "-" + "-";
-
- private String footer = "-" + "-" + ">";
-
- @Override
- protected String performInFilter(String ch) {
- return EMPTY_STRING;
- }
-
- @Override
- protected String performOutFilter(String ch) {
- return ch;
- }
-
- protected String getHeader() {
- return header;
- }
-
- protected String getFooter() {
- return footer;
- }
- }
-
- /**
- * To obtain inside of {@code ${message:XXX}} from tapestry template files.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.1
- */
- public class ExtractMessageFilter extends DefaultFilter {
-
- private String header = "$" + "{" + "m" + "e" + "s" + "s" + "a" + "g" + "e" + ":";
-
- private String footer = "}";
-
- @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;
- }
-
- protected String getHeader() {
- return header;
- }
-
- protected String getFooter() {
- return footer;
- }
- }
-
- /**
- * To obtain {@code XXX} data {@code ${format:XXX=YYY}} from tapestry template files.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.1
- */
- public class ExtractFormatFilter extends DefaultFilter {
-
- private String header = "$" + "{" + "f" + "o" + "r" + "m" + "a" + "t" + ":";
-
- private String footer = "}";
-
- @Override
- protected String performInFilter(String ch) {
- int i = ch.indexOf('=');
- if (verbose) {
- log.info("Detected key " + ch);
- }
- if (i == -1) {
- return "";
- }
- return ch.substring(0, i) + "\n";
- }
-
- @Override
- protected String performOutFilter(String ch) {
- return EMPTY_STRING;
- }
-
- protected String getHeader() {
- return header;
- }
-
- protected String getFooter() {
- return footer;
- }
- }
-}
Modified: trunk/nuiton-i18n/pom.xml
===================================================================
--- trunk/nuiton-i18n/pom.xml 2011-01-04 08:15:32 UTC (rev 1836)
+++ trunk/nuiton-i18n/pom.xml 2011-01-04 13:43:41 UTC (rev 1837)
@@ -34,7 +34,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>i18n</artifactId>
- <version>2.0.2-SNAPSHOT</version>
+ <version>2.1-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.i18n</groupId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-01-04 08:15:32 UTC (rev 1836)
+++ trunk/pom.xml 2011-01-04 13:43:41 UTC (rev 1837)
@@ -37,7 +37,7 @@
</parent>
<artifactId>i18n</artifactId>
- <version>2.0.2-SNAPSHOT</version>
+ <version>2.1-SNAPSHOT</version>
<modules>
<module>nuiton-i18n</module>
1
0
Author: tchemit
Date: 2011-01-04 09:15:32 +0100 (Tue, 04 Jan 2011)
New Revision: 1836
Url: http://nuiton.org/repositories/revision/i18n/1836
Log:
Evolution #1195: Clean site documentation
Evolution #1193: Introduce Tapestry Parser to grab i18n keys from tml files
Added:
trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/webapp/tapestry/
trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/webapp/tapestry/MyTml.tml
trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/webapp/tapestry/
trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/webapp/tapestry/MyTml.tml
trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/TapestryFileProcessor.java
Modified:
trunk/maven-i18n-plugin/pom.xml
trunk/maven-i18n-plugin/src/it/parsers/newProject/pom.xml
trunk/maven-i18n-plugin/src/it/parsers/newProject/verify.groovy
trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/pom.xml
trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/resources/i18n/parsers-withNewKeys_fr_FR.properties
trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/verify.groovy
trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/AbstractFileParser.java
trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserTapestryMojo.java
trunk/maven-i18n-plugin/src/site/apt/index.apt
trunk/maven-i18n-plugin/src/site/en/apt/index.apt
trunk/maven-i18n-plugin/src/site/site_en.xml
trunk/maven-i18n-plugin/src/site/site_fr.xml
Modified: trunk/maven-i18n-plugin/pom.xml
===================================================================
--- trunk/maven-i18n-plugin/pom.xml 2011-01-03 20:13:39 UTC (rev 1835)
+++ trunk/maven-i18n-plugin/pom.xml 2011-01-04 08:15:32 UTC (rev 1836)
@@ -67,12 +67,12 @@
<artifactId>commons-lang</artifactId>
</dependency>
- <!--dependency>
- <groupId>xalan</groupId>
- <artifactId>xalan</artifactId>
- </dependency-->
-
<dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-dependency-tree</artifactId>
</dependency>
@@ -159,6 +159,10 @@
<version>2.5.1</version>
</plugin>
+ <plugin>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <version>1.5</version>
+ </plugin>
</plugins>
</reporting>
Modified: trunk/maven-i18n-plugin/src/it/parsers/newProject/pom.xml
===================================================================
--- trunk/maven-i18n-plugin/src/it/parsers/newProject/pom.xml 2011-01-03 20:13:39 UTC (rev 1835)
+++ trunk/maven-i18n-plugin/src/it/parsers/newProject/pom.xml 2011-01-04 08:15:32 UTC (rev 1836)
@@ -72,7 +72,8 @@
<goals>
<goal>parserJava</goal>
<goal>parserValidation</goal>
- </goals>
+ <goal>parserTapestry</goal>
+ </goals>
</execution>
<execution>
<id>jsp</id>
@@ -95,6 +96,7 @@
<goals>
<goal>parserJava</goal>
<goal>parserValidation</goal>
+ <goal>parserTapestry</goal>
</goals>
<phase>compile</phase>
</execution>
Added: trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/webapp/tapestry/MyTml.tml
===================================================================
--- trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/webapp/tapestry/MyTml.tml (rev 0)
+++ trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/webapp/tapestry/MyTml.tml 2011-01-04 08:15:32 UTC (rev 1836)
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ #%L
+ I18n :: Maven Plugin
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2011 CodeLutin, Tony Chemit
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ #L%
+ -->
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<div>
+ <label>${message:tmlGetter.key1} : </label>
+ <label>${format:tmlGetter.key2=miamiam} : </label>
+</div>
\ No newline at end of file
Property changes on: trunk/maven-i18n-plugin/src/it/parsers/newProject/src/main/webapp/tapestry/MyTml.tml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/maven-i18n-plugin/src/it/parsers/newProject/verify.groovy
===================================================================
--- trunk/maven-i18n-plugin/src/it/parsers/newProject/verify.groovy 2011-01-03 20:13:39 UTC (rev 1835)
+++ trunk/maven-i18n-plugin/src/it/parsers/newProject/verify.groovy 2011-01-04 08:15:32 UTC (rev 1836)
@@ -44,4 +44,11 @@
assert content.contains( 'jspGetter.key1=' );
assert content.contains( 'jspGetter.key2=' );
+file = new File(basedir, 'target/generated-sources/i18n/tapestry.getter');
+assert file.exists();
+
+content = file.text;
+assert content.contains( 'tmlGetter.key1=' );
+assert content.contains( 'tmlGetter.key2=' );
+
return true;
Modified: trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/pom.xml
===================================================================
--- trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/pom.xml 2011-01-03 20:13:39 UTC (rev 1835)
+++ trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/pom.xml 2011-01-04 08:15:32 UTC (rev 1836)
@@ -83,6 +83,7 @@
<goals>
<goal>parserJava</goal>
<goal>parserValidation</goal>
+ <goal>parserTapestry</goal>
</goals>
</execution>
<execution>
@@ -112,6 +113,7 @@
<goals>
<goal>parserJava</goal>
<goal>parserValidation</goal>
+ <goal>parserTapestry</goal>
<goal>gen</goal>
</goals>
<phase>compile</phase>
Modified: trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/resources/i18n/parsers-withNewKeys_fr_FR.properties
===================================================================
--- trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/resources/i18n/parsers-withNewKeys_fr_FR.properties 2011-01-03 20:13:39 UTC (rev 1835)
+++ trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/resources/i18n/parsers-withNewKeys_fr_FR.properties 2011-01-04 08:15:32 UTC (rev 1836)
@@ -1,3 +1,4 @@
javaGetter.old.key1=hum1
javaGetter.old.key2=hum2
jspGetter.key1=humJsp1
+tmlGetter.key1=humTapestry1
Added: trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/webapp/tapestry/MyTml.tml
===================================================================
--- trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/webapp/tapestry/MyTml.tml (rev 0)
+++ trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/webapp/tapestry/MyTml.tml 2011-01-04 08:15:32 UTC (rev 1836)
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ #%L
+ I18n :: Maven Plugin
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2011 CodeLutin, Tony Chemit
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ #L%
+ -->
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<div>
+ <label>${message:tmlGetter.key1} : </label>
+ <label>${format:tmlGetter.key2=miamiam} : </label>
+</div>
\ No newline at end of file
Property changes on: trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/src/main/webapp/tapestry/MyTml.tml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/verify.groovy
===================================================================
--- trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/verify.groovy 2011-01-03 20:13:39 UTC (rev 1835)
+++ trunk/maven-i18n-plugin/src/it/parsers/withNewKeys/verify.groovy 2011-01-04 08:15:32 UTC (rev 1836)
@@ -47,6 +47,14 @@
assert content.contains( 'jspGetter.key1=' );
assert content.contains( 'jspGetter.key2=' );
+
+file = new File(basedir, 'target/generated-sources/i18n/tapestry.getter');
+assert file.exists();
+
+content = file.text;
+assert content.contains( 'tmlGetter.key1=' );
+assert content.contains( 'tmlGetter.key2=' );
+
file = new File(basedir, 'src/main/resources/i18n/parsers-withNewKeys_fr_FR.properties');
assert file.exists();
@@ -61,4 +69,7 @@
assert content.contains( 'jspGetter.key1=' );
assert content.contains( 'jspGetter.key2=' );
+assert content.contains( 'tmlGetter.key1=' );
+assert content.contains( 'tmlGetter.key2=' );
+
return true;
Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/AbstractFileParser.java
===================================================================
--- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/AbstractFileParser.java 2011-01-03 20:13:39 UTC (rev 1835)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/AbstractFileParser.java 2011-01-04 08:15:32 UTC (rev 1836)
@@ -137,7 +137,7 @@
* @param file the incoming file
* @return the real file to process
* @throws IOException if any IO problem while preparing file
- * @since 2.0.2
+ * @since 2.1
*/
protected File prepareFile(File file) throws IOException {
return file;
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-03 20:13:39 UTC (rev 1835)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserTapestryMojo.java 2011-01-04 08:15:32 UTC (rev 1836)
@@ -1,6 +1,29 @@
+/*
+ * #%L
+ * I18n :: Maven Plugin
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.i18n.plugin.parser.impl;
-import org.apache.commons.logging.LogFactory;
import org.apache.maven.plugin.logging.Log;
import org.nuiton.i18n.plugin.parser.AbstractFileParser;
import org.nuiton.i18n.plugin.parser.AbstractI18nParserMojo;
@@ -11,10 +34,6 @@
import org.nuiton.io.FileUpdater;
import org.nuiton.io.MirroredFileUpdater;
import org.nuiton.io.SortedProperties;
-import org.nuiton.processor.Processor;
-import org.nuiton.processor.ProcessorUtil;
-import org.nuiton.processor.filters.DefaultFilter;
-import org.nuiton.processor.filters.Filter;
import java.io.File;
import java.io.FileInputStream;
@@ -23,7 +42,9 @@
import java.io.LineNumberReader;
/**
- * To parse Tapestry templates to detect new I18n keys.
+ * To parse Tapestry templates to detect new I18n keys, says content of patterns :
+ * {@code ${message:XXX}} and {@code ${format:XXX=...}}.
+ *
* <p/>
* <b>Note: </b> this goal must always be invoked before the {@code process-resources}
* phase, otherwise all files will be considered as uptodate.
@@ -31,7 +52,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @goal parserTapestry
* @phase generate-resources
- * @since 2.0.2
+ * @since 2.1
*/
public class ParserTapestryMojo extends AbstractI18nParserMojo {
@@ -160,6 +181,7 @@
// don't care about it...
}
TapestryFileProcessor processor = new TapestryFileProcessor();
+ processor.setVerbose(isVerbose());
processor.process(file, result, getEncoding());
return result;
}
@@ -211,133 +233,4 @@
}
}
- /**
- * To Extract from tapestry template files, i18n keys.
- * <p/>
- * Says :
- * <ul>
- * <li>Keep content of {@code ${message:XXX}</li>
- * <li>Keep content of {@code ${format:XXX}</li>
- * </ul>
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0.2
- */
- public static class TapestryFileProcessor extends Processor {
-
- public TapestryFileProcessor() {
- setInputFilter(new Filter[]{
- new RemoveCommentFilter(),
- new ExtractMessageFilter()
- });
- }
-
- public void process(File filein,
- File fileout,
- String encoding) throws IOException {
- ProcessorUtil.doProcess(this, filein, fileout, encoding);
- }
-
- /**
- * To remove comments from tapestry template files.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0.2
- */
- public static class RemoveCommentFilter extends DefaultFilter {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- private static org.apache.commons.logging.Log log = LogFactory.getLog(ExtractMessageFilter.class);
-
- private String header = "<" + "!" + "-" + "-";
-
- private String footer = "-" + "-" + ">";
-
- @Override
- protected String performInFilter(String ch) {
- return EMPTY_STRING;
- }
-
- @Override
- protected String performOutFilter(String ch) {
- return ch;
- }
-
- protected String getHeader() {
- return header;
- }
-
- protected String getFooter() {
- return footer;
- }
- }
-
- /**
- * To obtain inside of {@code ${message:XXX}} from tapestry template files.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0.2
- */
- public static class ExtractMessageFilter extends DefaultFilter {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- private static org.apache.commons.logging.Log log = LogFactory.getLog(ExtractMessageFilter.class);
-
- private String header = "$" + "{" + "m" + "e" + "s" + "s" + "a" + "g" + "e" + ":";
-
- private String footer = "}";
-
- @Override
- protected String performInFilter(String ch) {
- if (log.isDebugEnabled()) {
- log.debug("Detected key " + ch);
- }
- return ch + "\n";
- }
-
- @Override
- protected String performOutFilter(String ch) {
- return EMPTY_STRING;
- }
-
- protected String getHeader() {
- return header;
- }
-
- protected String getFooter() {
- return footer;
- }
- }
-
- /**
- * To obtain inside of {@code ${format:XXX}} from tapestry template files.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.0.2
- */
- public static class ExtractFormatFilter extends DefaultFilter {
-
- private String header = "$" + "{" + "f" + "o" + "r" + "m" + "a" + "t" + ":";
-
- private String footer = "}";
-
- @Override
- protected String performInFilter(String ch) {
- return ch + "\n";
- }
-
- @Override
- protected String performOutFilter(String ch) {
- return "";
- }
-
- protected String getHeader() {
- return header;
- }
-
- protected String getFooter() {
- return footer;
- }
- }
- }
}
Property changes on: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserTapestryMojo.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Added: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/TapestryFileProcessor.java
===================================================================
--- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/TapestryFileProcessor.java (rev 0)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/TapestryFileProcessor.java 2011-01-04 08:15:32 UTC (rev 1836)
@@ -0,0 +1,192 @@
+/*
+ * #%L
+ * I18n :: Maven Plugin
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.i18n.plugin.parser.impl;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.processor.Processor;
+import org.nuiton.processor.ProcessorUtil;
+import org.nuiton.processor.filters.DefaultFilter;
+import org.nuiton.processor.filters.Filter;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * To Extract i18n keys from tapestry template files.
+ * <p/>
+ * Says :
+ * <ul>
+ * <li>Remove all xml comments</li>
+ * <li>Keep content of {@code ${message:XXX}}</li>
+ * <li>Keep content of {@code ${format:XXX}}}</li>
+ * </ul>
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+public class TapestryFileProcessor extends Processor {
+
+ /** Logger. */
+ static private final Log log =
+ LogFactory.getLog(TapestryFileProcessor.class);
+
+ protected boolean verbose;
+
+ public void setVerbose(boolean verbose) {
+ this.verbose = verbose;
+ }
+
+ public void process(File filein,
+ File fileout,
+ String encoding) throws IOException {
+ File fileTemp1 = new File(fileout.getAbsolutePath() + "~-message");
+ setInputFilter(new Filter[]{
+ new RemoveCommentFilter(),
+ new ExtractMessageFilter()
+ });
+ ProcessorUtil.doProcess(this, filein, fileTemp1, encoding);
+
+ File fileTemp2 = new File(fileout.getAbsolutePath() + "~-format");
+
+ setInputFilter(new Filter[]{
+ new RemoveCommentFilter(),
+ new ExtractFormatFilter()
+ });
+ ProcessorUtil.doProcess(this, filein, fileTemp2, encoding);
+
+ String tmp1 = FileUtils.readFileToString(fileTemp1).trim();
+ String tmp2 = FileUtils.readFileToString(fileTemp2).trim();
+ if (log.isDebugEnabled()) {
+ log.debug("Keys from message:\n" + tmp1);
+ log.debug("Keys from format:\n" + tmp2);
+ }
+ FileUtils.writeStringToFile(fileout, tmp1 + "\n" + tmp2);
+ }
+
+ /**
+ * To remove comments from tapestry template files.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+ public class RemoveCommentFilter extends DefaultFilter {
+
+ private String header = "<" + "!" + "-" + "-";
+
+ private String footer = "-" + "-" + ">";
+
+ @Override
+ protected String performInFilter(String ch) {
+ return EMPTY_STRING;
+ }
+
+ @Override
+ protected String performOutFilter(String ch) {
+ return ch;
+ }
+
+ protected String getHeader() {
+ return header;
+ }
+
+ protected String getFooter() {
+ return footer;
+ }
+ }
+
+ /**
+ * To obtain inside of {@code ${message:XXX}} from tapestry template files.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+ public class ExtractMessageFilter extends DefaultFilter {
+
+ private String header = "$" + "{" + "m" + "e" + "s" + "s" + "a" + "g" + "e" + ":";
+
+ private String footer = "}";
+
+ @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;
+ }
+
+ protected String getHeader() {
+ return header;
+ }
+
+ protected String getFooter() {
+ return footer;
+ }
+ }
+
+ /**
+ * To obtain {@code XXX} data {@code ${format:XXX=YYY}} from tapestry template files.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+ public class ExtractFormatFilter extends DefaultFilter {
+
+ private String header = "$" + "{" + "f" + "o" + "r" + "m" + "a" + "t" + ":";
+
+ private String footer = "}";
+
+ @Override
+ protected String performInFilter(String ch) {
+ int i = ch.indexOf('=');
+ if (verbose) {
+ log.info("Detected key " + ch);
+ }
+ if (i == -1) {
+ return "";
+ }
+ return ch.substring(0, i) + "\n";
+ }
+
+ @Override
+ protected String performOutFilter(String ch) {
+ return EMPTY_STRING;
+ }
+
+ protected String getHeader() {
+ return header;
+ }
+
+ protected String getFooter() {
+ return footer;
+ }
+ }
+}
Property changes on: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/TapestryFileProcessor.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/maven-i18n-plugin/src/site/apt/index.apt
===================================================================
--- trunk/maven-i18n-plugin/src/site/apt/index.apt 2011-01-03 20:13:39 UTC (rev 1835)
+++ trunk/maven-i18n-plugin/src/site/apt/index.apt 2011-01-04 08:15:32 UTC (rev 1836)
@@ -42,9 +42,9 @@
* {{{./parserValidation-mojo.html} i18n:parserValidation}} parse XWorks validation sources.
- * {{{./parserJavaActionConfig-mojo.html} i18n:parserJavaActionConfig}} parse actions jaxx.
+ * {{{./parserJsp-mojo.html} i18n:parserJsp}} parse JSP sources.
- * {{{./parserJavaTabConfig-mojo.html} i18n:parserJavaTabConfig}} parse tabs jaxx.
+ * {{{./parserTapestry-mojo.html} i18n:parserTapestry}} parse Tapestry templates sources.
* {{{./get-mojo.html} i18n:get}} assembly getter computed by parser-like goals.
Modified: trunk/maven-i18n-plugin/src/site/en/apt/index.apt
===================================================================
--- trunk/maven-i18n-plugin/src/site/en/apt/index.apt 2011-01-03 20:13:39 UTC (rev 1835)
+++ trunk/maven-i18n-plugin/src/site/en/apt/index.apt 2011-01-04 08:15:32 UTC (rev 1836)
@@ -42,9 +42,9 @@
* {{{./parserValidation-mojo.html} i18n:parserValidation}} parse XWorks validation sources.
- * {{{./parserJavaActionConfig-mojo.html} i18n:parserJavaActionConfig}} parse actions jaxx.
+ * {{{./parserJsp-mojo.html} i18n:parserJsp}} parse jsp sources.
- * {{{./parserJavaTabConfig-mojo.html} i18n:parserJavaTabConfig}} parse tabs jaxx.
+ * {{{./parserTapestry-mojo.html} i18n:parserTapestry}} parse Tapestry template sources.
* {{{./get-mojo.html} i18n:get}} assembly getter computed by parser-like goals.
Modified: trunk/maven-i18n-plugin/src/site/site_en.xml
===================================================================
--- trunk/maven-i18n-plugin/src/site/site_en.xml 2011-01-03 20:13:39 UTC (rev 1835)
+++ trunk/maven-i18n-plugin/src/site/site_en.xml 2011-01-04 08:15:32 UTC (rev 1836)
@@ -51,11 +51,9 @@
<item name="Usages" href="usages.html"/>
<item name="Parser Goals" href="plugin-info.html">
<item name="parserJava" href="parserJava-mojo.html"/>
- <item name="parserJaxx" href="parserJaxx-mojo.html"/>
- <item name="parserSwixat" href="parserSwixat-mojo.html"/>
- <item name="parserJavaActionConfig"
- href="parserJavaActionConfig-mojo.html"/>
- <item name="parserJavaTabConfig" href="parserJavaTabConfig-mojo.html"/>
+ <item name="parserXml" href="parserXml-mojo.html"/>
+ <item name="parserJsp" href="parserJsp-mojo.html"/>
+ <item name="parserTapestry" href="parserTapestry-mojo.html"/>
<item name="parserValidation" href="parserValidation-mojo.html"/>
<item name="get" href="get-mojo.html"/>
<item name="gen" href="gen-mojo.html"/>
Modified: trunk/maven-i18n-plugin/src/site/site_fr.xml
===================================================================
--- trunk/maven-i18n-plugin/src/site/site_fr.xml 2011-01-03 20:13:39 UTC (rev 1835)
+++ trunk/maven-i18n-plugin/src/site/site_fr.xml 2011-01-04 08:15:32 UTC (rev 1836)
@@ -49,11 +49,9 @@
<item name="Usages" href="usages.html"/>
<item name="Parser Goals" href="plugin-info.html">
<item name="parserJava" href="parserJava-mojo.html"/>
- <item name="parserJaxx" href="parserJaxx-mojo.html"/>
- <item name="parserSwixat" href="parserSwixat-mojo.html"/>
- <item name="parserJavaActionConfig"
- href="parserJavaActionConfig-mojo.html"/>
- <item name="parserJavaTabConfig" href="parserJavaTabConfig-mojo.html"/>
+ <item name="parserXml" href="parserXml-mojo.html"/>
+ <item name="parserJsp" href="parserJsp-mojo.html"/>
+ <item name="parserTapestry" href="parserTapestry-mojo.html"/>
<item name="parserValidation" href="parserValidation-mojo.html"/>
<item name="get" href="get-mojo.html"/>
<item name="gen" href="gen-mojo.html"/>
1
0
r1835 - in trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser: . impl
by tchemit@users.nuiton.org 03 Jan '11
by tchemit@users.nuiton.org 03 Jan '11
03 Jan '11
Author: tchemit
Date: 2011-01-03 21:13:39 +0100 (Mon, 03 Jan 2011)
New Revision: 1835
Url: http://nuiton.org/repositories/revision/i18n/1835
Log:
Evolution #1193: Introduce Tapestry Parser to grab i18n keys from tml files + clean some mojos + remove deprecated mojos
Added:
trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserTapestryMojo.java
Removed:
trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaActionConfigMojo.java
trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaTabConfigMojo.java
Modified:
trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/AbstractFileParser.java
trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/AbstractParserXmlMojo.java
trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/JspFileProcessor.java
Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/AbstractFileParser.java
===================================================================
--- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/AbstractFileParser.java 2010-12-23 09:00:04 UTC (rev 1834)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/AbstractFileParser.java 2011-01-03 20:13:39 UTC (rev 1835)
@@ -28,7 +28,10 @@
import org.apache.maven.plugin.logging.Log;
import org.nuiton.io.SortedProperties;
+import java.io.File;
+import java.io.IOException;
+
/**
* A abstract implementation of a {@link FileParser} with no logic.
*
@@ -125,4 +128,18 @@
protected void setTouched(boolean touched) {
this.touched = touched;
}
+
+ /**
+ * To prepare the file (if any thing to be done before scanning it).
+ * <p/>
+ * By default do nothing, use directly the input file.
+ *
+ * @param file the incoming file
+ * @return the real file to process
+ * @throws IOException if any IO problem while preparing file
+ * @since 2.0.2
+ */
+ protected File prepareFile(File file) throws IOException {
+ return file;
+ }
}
Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/AbstractParserXmlMojo.java
===================================================================
--- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/AbstractParserXmlMojo.java 2010-12-23 09:00:04 UTC (rev 1834)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/AbstractParserXmlMojo.java 2011-01-03 20:13:39 UTC (rev 1835)
@@ -368,6 +368,7 @@
* @throws IOException if any IO problem while preparing file
* @since 2.0
*/
+ @Override
public File prepareFile(File file) throws IOException {
// by default, do nothing
Modified: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/JspFileProcessor.java
===================================================================
--- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/JspFileProcessor.java 2010-12-23 09:00:04 UTC (rev 1834)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/JspFileProcessor.java 2011-01-03 20:13:39 UTC (rev 1835)
@@ -117,7 +117,7 @@
@Override
protected String performInFilter(String ch) {
- return "";
+ return EMPTY_STRING;
}
@Override
@@ -148,7 +148,7 @@
@Override
protected String performInFilter(String ch) {
- return "";
+ return EMPTY_STRING;
}
@Override
Deleted: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaActionConfigMojo.java
===================================================================
--- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaActionConfigMojo.java 2010-12-23 09:00:04 UTC (rev 1834)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaActionConfigMojo.java 2011-01-03 20:13:39 UTC (rev 1835)
@@ -1,90 +0,0 @@
-/*
- * #%L
- * I18n :: Maven Plugin
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2007 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.i18n.plugin.parser.impl;
-
-import org.nuiton.i18n.plugin.parser.FileParser;
-
-import java.io.File;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Un parseur java pour scanner les annotations ActionConfig
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @goal parserJavaActionConfig
- * @phase generate-resources
- * @deprecated since 2.0, will not be replaced (was used by {@code jaxx-swing-action} project which is dead...)
- */
-@Deprecated
-public class ParserJavaActionConfigMojo extends ParserJavaMojo {
-
- protected static final Pattern MATCH_PATTERN = Pattern.compile("(name|shortDescription|longDescription|name2|shortDescription2|longDescription2)\\s*=\\s*\"([\\w|\\.]+)\"(|\\s*|\\s*,\\s*$)");
-
- @Override
- protected String getOutGetter() {
- return "java-action-config.getter";
- }
-
- @Override
- public FileParser newFileParser() {
-
- return new JavaFileParser(
- getLog(),
- getEncoding(),
- oldParser,
- showTouchedFiles) {
-
- @Override
- public void parseLine(File srcFile, String line) {
- String key = extract(line);
- if (key != null) {
- setTouched(true);
- registerKey(key);
-
- }
- }
-
- String extract(String i18nString) {
- Matcher matcher = MATCH_PATTERN.matcher(i18nString.trim());
- if (matcher.matches()) {
- return matcher.group(2);
- }
- return null;
- }
- };
- }
-
- @Override
- protected String getKeyModifierStart() {
- return "[\\w|\\.]+\\s*=\\s*\"";
- }
-
- @Override
- protected String getKeyModifierEnd() {
- return "\"\\s*(\\)|,|\\+|$)";
- }
-}
Deleted: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaTabConfigMojo.java
===================================================================
--- trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaTabConfigMojo.java 2010-12-23 09:00:04 UTC (rev 1834)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserJavaTabConfigMojo.java 2011-01-03 20:13:39 UTC (rev 1835)
@@ -1,44 +0,0 @@
-/*
- * #%L
- * I18n :: Maven Plugin
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2007 - 2010 CodeLutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package org.nuiton.i18n.plugin.parser.impl;
-
-/**
- * Un parseur java pour scanner les annotations TabContentConfig.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @goal parserJavaTabConfig
- * @phase generate-resources
- * @deprecated since 2.0, will not be replaced (was used by {@code jaxx-swing-action} project which is dead...)
- */
-@Deprecated
-public class ParserJavaTabConfigMojo extends ParserJavaActionConfigMojo {
-
- @Override
- protected String getOutGetter() {
- return "java-tab-config.getter";
- }
-
-}
Added: 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 (rev 0)
+++ trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserTapestryMojo.java 2011-01-03 20:13:39 UTC (rev 1835)
@@ -0,0 +1,343 @@
+package org.nuiton.i18n.plugin.parser.impl;
+
+import org.apache.commons.logging.LogFactory;
+import org.apache.maven.plugin.logging.Log;
+import org.nuiton.i18n.plugin.parser.AbstractFileParser;
+import org.nuiton.i18n.plugin.parser.AbstractI18nParserMojo;
+import org.nuiton.i18n.plugin.parser.FileParser;
+import org.nuiton.i18n.plugin.parser.I18nSourceEntry;
+import org.nuiton.i18n.plugin.parser.ParserException;
+import org.nuiton.i18n.plugin.parser.SourceEntry;
+import org.nuiton.io.FileUpdater;
+import org.nuiton.io.MirroredFileUpdater;
+import org.nuiton.io.SortedProperties;
+import org.nuiton.processor.Processor;
+import org.nuiton.processor.ProcessorUtil;
+import org.nuiton.processor.filters.DefaultFilter;
+import org.nuiton.processor.filters.Filter;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+
+/**
+ * To parse Tapestry templates to detect new I18n keys.
+ * <p/>
+ * <b>Note: </b> this goal must always be invoked before the {@code process-resources}
+ * phase, otherwise all files will be considered as uptodate.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @goal parserTapestry
+ * @phase generate-resources
+ * @since 2.0.2
+ */
+public class ParserTapestryMojo extends AbstractI18nParserMojo {
+
+ /**
+ * Root directory of the default entry.
+ *
+ * @parameter expression="${i18n.defaultBasedir}" default-value="${basedir}/src/main/webapp"
+ */
+ protected File defaultBasedir;
+
+ /**
+ * Default included files to process (ant-like expression).
+ *
+ * @parameter expression="${i18n.defaultIncludes}" default-value="**\/*.tml"
+ */
+ protected String defaultIncludes;
+
+ /**
+ * Defines the file name of the getter where to put detected i18n keys
+ * while getter phase.
+ *
+ * @parameter expression="${i18n.outputGetter}" default-value="tapestry.getter"
+ * @since 2.0
+ */
+ protected String outputGetter;
+
+ /**
+ * Where to generated temporary processed files.
+ *
+ * @parameter expression="${i18n.workdir}" default-value="${basedir}/target/i18n-workdir"
+ * @since 2.0
+ */
+ protected File workdir;
+
+ protected MirroredFileUpdater entryUpdater;
+
+ @Override
+ public String[] getDefaultIncludes() {
+ return new String[]{defaultIncludes};
+ }
+
+ @Override
+ public String[] getDefaultExcludes() {
+ return I18nSourceEntry.EMPTY_STRING_ARRAY;
+ }
+
+ @Override
+ public File getDefaultBasedir() {
+ return defaultBasedir;
+ }
+
+ @Override
+ protected boolean onEnterEntry(I18nSourceEntry entry) {
+ boolean b = super.onEnterEntry(entry);
+ if (!b) {
+
+ // no skipped entry
+ // keep the file updater
+ entryUpdater = (MirroredFileUpdater) entry.getUpdater();
+ }
+ return b;
+ }
+
+ @Override
+ public FileUpdater newFileUpdater(SourceEntry entry) {
+ return new MirroredFileUpdater("", "", entry.getBasedir(), workdir) {
+
+ @Override
+ public File getMirrorFile(File f) {
+ String file =
+ f.getAbsolutePath().substring(prefixSourceDirecotory);
+ return new File(destinationDirectory + File.separator + file);
+ }
+ };
+ }
+
+ @Override
+ @Deprecated
+ protected String getKeyModifierStart() {
+ return "_\\(\\s*\"";
+ }
+
+ @Override
+ @Deprecated
+ protected String getKeyModifierEnd() {
+ return "\"\\s*(\\)|,|\\+|$)";
+ }
+
+ @Override
+ protected String getOutGetter() {
+ return outputGetter;
+ }
+
+ @Override
+ public FileParser newFileParser() {
+
+ return new TapestryFileParser(getLog(),
+ getEncoding(),
+ oldParser,
+ isShowTouchedFiles()
+ );
+ }
+
+ protected class TapestryFileParser extends AbstractFileParser {
+
+
+ public TapestryFileParser(Log log,
+ String encoding,
+ SortedProperties oldParser,
+ boolean showTouchedFiles) {
+ super(log, encoding, oldParser, showTouchedFiles);
+ }
+
+
+ protected File prepareFile(File file) throws IOException {
+
+ // clean the jsp to make it xml
+
+ File result = entryUpdater.getMirrorFile(file);
+ if (isVerbose()) {
+ getLog().info("Will process [" + file + "] to " + result);
+ }
+ try {
+ createDirectoryIfNecessary(result.getParentFile());
+ } catch (IOException e) {
+ // don't care about it...
+ }
+ TapestryFileProcessor processor = new TapestryFileProcessor();
+ processor.process(file, result, getEncoding());
+ return result;
+ }
+
+ @Override
+ public void parseFile(File file) throws IOException {
+
+ // clean the jsp to make it xml
+
+ File processedFile = prepareFile(file);
+
+ // process file to obtain
+ String line = null;
+ LineNumberReader lnr = new LineNumberReader(new InputStreamReader(
+ new FileInputStream(processedFile), getEncoding()));
+ try {
+ while ((line = lnr.readLine()) != null) {
+ parseLine(processedFile, line);
+ }
+ } catch (Exception e) {
+ if (line != null) {
+ getLog().error(
+ "could not parse line (" + lnr.getLineNumber() + ") '"
+ + line + "' of file " + file);
+ }
+ throw new ParserException(e);
+ } finally {
+ lnr.close();
+ }
+ }
+
+ @Override
+ public void parseLine(File file, String line) throws IOException {
+
+ String key = line.trim();
+
+ if (key.isEmpty()) {
+ // no key detected on this line
+ return;
+ }
+
+ // one key found in file, so file is marked as touched
+ setTouched(true);
+ // Found a i18n key, register it.
+ if (getLog().isDebugEnabled()) {
+ getLog().debug(file.getName() + " detected key = " + key);
+ }
+ registerKey(key);
+ }
+ }
+
+ /**
+ * To Extract from tapestry template files, i18n keys.
+ * <p/>
+ * Says :
+ * <ul>
+ * <li>Keep content of {@code ${message:XXX}</li>
+ * <li>Keep content of {@code ${format:XXX}</li>
+ * </ul>
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0.2
+ */
+ public static class TapestryFileProcessor extends Processor {
+
+ public TapestryFileProcessor() {
+ setInputFilter(new Filter[]{
+ new RemoveCommentFilter(),
+ new ExtractMessageFilter()
+ });
+ }
+
+ public void process(File filein,
+ File fileout,
+ String encoding) throws IOException {
+ ProcessorUtil.doProcess(this, filein, fileout, encoding);
+ }
+
+ /**
+ * To remove comments from tapestry template files.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0.2
+ */
+ public static class RemoveCommentFilter extends DefaultFilter {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static org.apache.commons.logging.Log log = LogFactory.getLog(ExtractMessageFilter.class);
+
+ private String header = "<" + "!" + "-" + "-";
+
+ private String footer = "-" + "-" + ">";
+
+ @Override
+ protected String performInFilter(String ch) {
+ return EMPTY_STRING;
+ }
+
+ @Override
+ protected String performOutFilter(String ch) {
+ return ch;
+ }
+
+ protected String getHeader() {
+ return header;
+ }
+
+ protected String getFooter() {
+ return footer;
+ }
+ }
+
+ /**
+ * To obtain inside of {@code ${message:XXX}} from tapestry template files.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0.2
+ */
+ public static class ExtractMessageFilter extends DefaultFilter {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static org.apache.commons.logging.Log log = LogFactory.getLog(ExtractMessageFilter.class);
+
+ private String header = "$" + "{" + "m" + "e" + "s" + "s" + "a" + "g" + "e" + ":";
+
+ private String footer = "}";
+
+ @Override
+ protected String performInFilter(String ch) {
+ if (log.isDebugEnabled()) {
+ log.debug("Detected key " + ch);
+ }
+ return ch + "\n";
+ }
+
+ @Override
+ protected String performOutFilter(String ch) {
+ return EMPTY_STRING;
+ }
+
+ protected String getHeader() {
+ return header;
+ }
+
+ protected String getFooter() {
+ return footer;
+ }
+ }
+
+ /**
+ * To obtain inside of {@code ${format:XXX}} from tapestry template files.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0.2
+ */
+ public static class ExtractFormatFilter extends DefaultFilter {
+
+ private String header = "$" + "{" + "f" + "o" + "r" + "m" + "a" + "t" + ":";
+
+ private String footer = "}";
+
+ @Override
+ protected String performInFilter(String ch) {
+ return ch + "\n";
+ }
+
+ @Override
+ protected String performOutFilter(String ch) {
+ return "";
+ }
+
+ protected String getHeader() {
+ return header;
+ }
+
+ protected String getFooter() {
+ return footer;
+ }
+ }
+ }
+}
Property changes on: trunk/maven-i18n-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserTapestryMojo.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
1
0
23 Dec '10
Author: sletellier
Date: 2010-12-23 10:00:04 +0100 (Thu, 23 Dec 2010)
New Revision: 1834
Url: http://nuiton.org/repositories/revision/i18n/1834
Log:
[maven-release-plugin] prepare for next development iteration
Modified:
trunk/maven-i18n-plugin/pom.xml
trunk/nuiton-i18n/pom.xml
trunk/pom.xml
Modified: trunk/maven-i18n-plugin/pom.xml
===================================================================
--- trunk/maven-i18n-plugin/pom.xml 2010-12-23 09:00:02 UTC (rev 1833)
+++ trunk/maven-i18n-plugin/pom.xml 2010-12-23 09:00:04 UTC (rev 1834)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>i18n</artifactId>
- <version>2.0.1</version>
+ <version>2.0.2-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.i18n</groupId>
Modified: trunk/nuiton-i18n/pom.xml
===================================================================
--- trunk/nuiton-i18n/pom.xml 2010-12-23 09:00:02 UTC (rev 1833)
+++ trunk/nuiton-i18n/pom.xml 2010-12-23 09:00:04 UTC (rev 1834)
@@ -34,7 +34,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>i18n</artifactId>
- <version>2.0.1</version>
+ <version>2.0.2-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.i18n</groupId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-12-23 09:00:02 UTC (rev 1833)
+++ trunk/pom.xml 2010-12-23 09:00:04 UTC (rev 1834)
@@ -37,7 +37,7 @@
</parent>
<artifactId>i18n</artifactId>
- <version>2.0.1</version>
+ <version>2.0.2-SNAPSHOT</version>
<modules>
<module>nuiton-i18n</module>
@@ -200,11 +200,11 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/i18n/tags/i18n-2.0.1</connection>
+ <connection>scm:svn:http://svn.nuiton.org/svn/i18n/trunk</connection>
<developerConnection>
- scm:svn:http://svn.nuiton.org/svn/i18n/tags/i18n-2.0.1
+ scm:svn:http://svn.nuiton.org/svn/i18n/trunk
</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/i18n/tags/i18n-2.0.1</url>
+ <url>http://www.nuiton.org/repositories/browse/i18n/trunk</url>
</scm>
<profiles>
1
0
Author: sletellier
Date: 2010-12-23 10:00:02 +0100 (Thu, 23 Dec 2010)
New Revision: 1833
Url: http://nuiton.org/repositories/revision/i18n/1833
Log:
[maven-release-plugin] copy for tag i18n-2.0.1
Added:
tags/i18n-2.0.1/
1
0
23 Dec '10
Author: sletellier
Date: 2010-12-23 09:59:59 +0100 (Thu, 23 Dec 2010)
New Revision: 1832
Url: http://nuiton.org/repositories/revision/i18n/1832
Log:
[maven-release-plugin] prepare release i18n-2.0.1
Modified:
trunk/maven-i18n-plugin/pom.xml
trunk/nuiton-i18n/pom.xml
trunk/pom.xml
Modified: trunk/maven-i18n-plugin/pom.xml
===================================================================
--- trunk/maven-i18n-plugin/pom.xml 2010-12-10 14:48:46 UTC (rev 1831)
+++ trunk/maven-i18n-plugin/pom.xml 2010-12-23 08:59:59 UTC (rev 1832)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>i18n</artifactId>
- <version>2.0.1-SNAPSHOT</version>
+ <version>2.0.1</version>
</parent>
<groupId>org.nuiton.i18n</groupId>
Modified: trunk/nuiton-i18n/pom.xml
===================================================================
--- trunk/nuiton-i18n/pom.xml 2010-12-10 14:48:46 UTC (rev 1831)
+++ trunk/nuiton-i18n/pom.xml 2010-12-23 08:59:59 UTC (rev 1832)
@@ -34,7 +34,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>i18n</artifactId>
- <version>2.0.1-SNAPSHOT</version>
+ <version>2.0.1</version>
</parent>
<groupId>org.nuiton.i18n</groupId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-12-10 14:48:46 UTC (rev 1831)
+++ trunk/pom.xml 2010-12-23 08:59:59 UTC (rev 1832)
@@ -37,7 +37,7 @@
</parent>
<artifactId>i18n</artifactId>
- <version>2.0.1-SNAPSHOT</version>
+ <version>2.0.1</version>
<modules>
<module>nuiton-i18n</module>
@@ -200,11 +200,11 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/i18n/trunk</connection>
+ <connection>scm:svn:http://svn.nuiton.org/svn/i18n/tags/i18n-2.0.1</connection>
<developerConnection>
- scm:svn:http://svn.nuiton.org/svn/i18n/trunk
+ scm:svn:http://svn.nuiton.org/svn/i18n/tags/i18n-2.0.1
</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/i18n/trunk</url>
+ <url>http://www.nuiton.org/repositories/browse/i18n/tags/i18n-2.0.1</url>
</scm>
<profiles>
1
0
10 Dec '10
Author: tchemit
Date: 2010-12-10 15:48:46 +0100 (Fri, 10 Dec 2010)
New Revision: 1831
Url: http://nuiton.org/repositories/revision/i18n/1831
Log:
use new LocaleConverter
Modified:
trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java
Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java
===================================================================
--- trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java 2010-11-29 20:10:23 UTC (rev 1830)
+++ trunk/nuiton-i18n/src/main/java/org/nuiton/i18n/I18nUtil.java 2010-12-10 14:48:46 UTC (rev 1831)
@@ -27,7 +27,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.LocaleConverter;
+import org.nuiton.util.converter.LocaleConverter;
import java.io.File;
import java.io.IOException;
1
0
r1830 - in trunk: ant-i18n-task/src/license nuiton-i18n/src/main/java/org/nuiton/util nuiton-i18n/src/main/java/org/nuiton/util/converter nuiton-i18n/src/main/resources/META-INF/services
by tchemit@users.nuiton.org 29 Nov '10
by tchemit@users.nuiton.org 29 Nov '10
29 Nov '10
Author: tchemit
Date: 2010-11-29 21:10:23 +0100 (Mon, 29 Nov 2010)
New Revision: 1830
Url: http://nuiton.org/repositories/revision/i18n/1830
Log:
Evolution #1120: Move LocaleConverter to the nuiton-utils correct pakcage (org.nuiton.util.converter)
Added:
trunk/nuiton-i18n/src/main/java/org/nuiton/util/converter/
trunk/nuiton-i18n/src/main/java/org/nuiton/util/converter/LocaleConverter.java
Modified:
trunk/ant-i18n-task/src/license/THIRD-PARTY.properties
trunk/nuiton-i18n/src/main/java/org/nuiton/util/LocaleConverter.java
trunk/nuiton-i18n/src/main/resources/META-INF/services/org.apache.commons.beanutils.Converter
Modified: trunk/ant-i18n-task/src/license/THIRD-PARTY.properties
===================================================================
--- trunk/ant-i18n-task/src/license/THIRD-PARTY.properties 2010-11-22 13:38:42 UTC (rev 1829)
+++ trunk/ant-i18n-task/src/license/THIRD-PARTY.properties 2010-11-29 20:10:23 UTC (rev 1830)
@@ -1,6 +1,7 @@
# Generated by org.nuiton.license.plugin.AddThirdPartyMojo
#-------------------------------------------------------------------------------
# Already used licenses in project :
+# - =The Apache Software License, Version 2.0
# - BSD License
# - Common Public License Version 1.0
# - Lesser General Public License (LGPL) v 3.0
@@ -9,6 +10,6 @@
# Please fill the missing licenses for dependencies :
#
#
-#Thu Nov 11 15:08:04 CET 2010
-org.apache.ant--ant--1.8.0==The Apache Software License, Version 2.0
-org.apache.ant--ant-launcher--1.8.0=The Apache Software License, Version 2.0
+#Mon Nov 22 14:38:26 CET 2010
+org.apache.ant--ant--1.8.0--jar=\=The Apache Software License, Version 2.0
+org.apache.ant--ant-launcher--1.8.0--jar=The Apache Software License, Version 2.0
Modified: trunk/nuiton-i18n/src/main/java/org/nuiton/util/LocaleConverter.java
===================================================================
--- trunk/nuiton-i18n/src/main/java/org/nuiton/util/LocaleConverter.java 2010-11-22 13:38:42 UTC (rev 1829)
+++ trunk/nuiton-i18n/src/main/java/org/nuiton/util/LocaleConverter.java 2010-11-29 20:10:23 UTC (rev 1830)
@@ -41,7 +41,9 @@
* classe pour convertir une chaine en un objet {@link Locale}.
*
* @author tchemit <chemit(a)codelutin.com>
+ * @deprecated since 2.0.1, use the {@link org.nuiton.util.converter.LocaleConverter} instead
*/
+@Deprecated
public class LocaleConverter implements Converter {
private static final Pattern FULL_SCOPE_PATTERN =
Copied: trunk/nuiton-i18n/src/main/java/org/nuiton/util/converter/LocaleConverter.java (from rev 1829, trunk/nuiton-i18n/src/main/java/org/nuiton/util/LocaleConverter.java)
===================================================================
--- trunk/nuiton-i18n/src/main/java/org/nuiton/util/converter/LocaleConverter.java (rev 0)
+++ trunk/nuiton-i18n/src/main/java/org/nuiton/util/converter/LocaleConverter.java 2010-11-29 20:10:23 UTC (rev 1830)
@@ -0,0 +1,148 @@
+/*
+ * #%L
+ * I18n :: Api
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+package org.nuiton.util.converter;
+
+import org.apache.commons.beanutils.ConversionException;
+import org.apache.commons.beanutils.Converter;
+import org.apache.commons.logging.Log;
+import org.nuiton.i18n.CountryEnum;
+import org.nuiton.i18n.LanguageEnum;
+
+import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static org.apache.commons.logging.LogFactory.getLog;
+
+/**
+ * classe pour convertir une chaine en un objet {@link Locale}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0.1
+ */
+public class LocaleConverter implements Converter {
+
+ private static final Pattern FULL_SCOPE_PATTERN =
+ Pattern.compile("([a-zA-Z]{2})_([a-zA-Z]{2})");
+
+ private static final Pattern MEDIUM_SCOPE_PATTERN =
+ Pattern.compile("([a-zA-Z]{2})");
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static Log log = getLog(LocaleConverter.class);
+
+ @Override
+ public Object convert(Class aClass, Object value) {
+ if (value == null) {
+ throw new ConversionException("can not convert null value in " +
+ this + " convertor");
+ }
+ if (isEnabled(aClass)) {
+ Object result;
+ if (isEnabled(value.getClass())) {
+ result = value;
+ return result;
+ }
+ if (value instanceof String) {
+ result = valueOf(((String) value).trim());
+ return result;
+ }
+ }
+ throw new ConversionException(
+ "could not find a convertor for type " + aClass.getName() +
+ " and value : " + value);
+ }
+
+ public Locale valueOf(String value) {
+ try {
+ Locale result = convertFullScope(value);
+
+ if (result == null) {
+ result = convertMediumScope(value);
+ }
+
+ if (result == null) {
+ throw new ConversionException("could not convert locale " +
+ value);
+ }
+
+ return result;
+ } catch (Exception e) {
+ throw new ConversionException("could not convert locale " + value +
+ " for reason " + e.getMessage());
+ }
+ }
+
+ private Locale convertFullScope(String value) {
+ Matcher m = FULL_SCOPE_PATTERN.matcher(value);
+ if (m.matches()) {
+ // found a full scope pattern (language + country)
+ LanguageEnum language =
+ LanguageEnum.valueOf(m.group(1).toLowerCase());
+ CountryEnum country = CountryEnum.valueOf(m.group(2).toUpperCase());
+ if (language == null || country == null) {
+ // not safe
+ throw new ConversionException("could not convert locale " +
+ value);
+ }
+ return new Locale(language.name(), country.name());
+ }
+ return null;
+ }
+
+ private Locale convertMediumScope(String value) {
+ Matcher m = MEDIUM_SCOPE_PATTERN.matcher(value);
+ if (m.matches()) {
+ // found a medium scope pattern (only language)
+ LanguageEnum language =
+ LanguageEnum.valueOf(m.group(1).toLowerCase());
+
+ if (language == null) {
+ // not safe
+ throw new ConversionException("could not convert locale " +
+ value);
+ }
+ return new Locale(language.name());
+ }
+ return null;
+ }
+
+
+ public LocaleConverter() {
+ if (log.isDebugEnabled()) {
+ log.debug(this);
+ }
+ }
+
+ protected boolean isEnabled(Class<?> aClass) {
+ return Locale.class.equals(aClass);
+ }
+
+ public Class<?> getType() {
+ return Locale.class;
+ }
+
+}
Modified: trunk/nuiton-i18n/src/main/resources/META-INF/services/org.apache.commons.beanutils.Converter
===================================================================
--- trunk/nuiton-i18n/src/main/resources/META-INF/services/org.apache.commons.beanutils.Converter 2010-11-22 13:38:42 UTC (rev 1829)
+++ trunk/nuiton-i18n/src/main/resources/META-INF/services/org.apache.commons.beanutils.Converter 2010-11-29 20:10:23 UTC (rev 1830)
@@ -1 +1 @@
-org.nuiton.util.LocaleConverter
\ No newline at end of file
+org.nuiton.util.converter.LocaleConverter
\ No newline at end of file
1
0
r1829 - in trunk: . ant-i18n-task maven-i18n-plugin nuiton-i18n
by tchemit@users.nuiton.org 22 Nov '10
by tchemit@users.nuiton.org 22 Nov '10
22 Nov '10
Author: tchemit
Date: 2010-11-22 14:38:42 +0100 (Mon, 22 Nov 2010)
New Revision: 1829
Url: http://nuiton.org/repositories/revision/i18n/1829
Log:
[maven-release-plugin] prepare for next development iteration
Modified:
trunk/ant-i18n-task/pom.xml
trunk/maven-i18n-plugin/pom.xml
trunk/nuiton-i18n/pom.xml
trunk/pom.xml
Modified: trunk/ant-i18n-task/pom.xml
===================================================================
--- trunk/ant-i18n-task/pom.xml 2010-11-22 13:38:39 UTC (rev 1828)
+++ trunk/ant-i18n-task/pom.xml 2010-11-22 13:38:42 UTC (rev 1829)
@@ -34,7 +34,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>i18n</artifactId>
- <version>2.0</version>
+ <version>2.0.1-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.i18n</groupId>
Modified: trunk/maven-i18n-plugin/pom.xml
===================================================================
--- trunk/maven-i18n-plugin/pom.xml 2010-11-22 13:38:39 UTC (rev 1828)
+++ trunk/maven-i18n-plugin/pom.xml 2010-11-22 13:38:42 UTC (rev 1829)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>i18n</artifactId>
- <version>2.0</version>
+ <version>2.0.1-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.i18n</groupId>
Modified: trunk/nuiton-i18n/pom.xml
===================================================================
--- trunk/nuiton-i18n/pom.xml 2010-11-22 13:38:39 UTC (rev 1828)
+++ trunk/nuiton-i18n/pom.xml 2010-11-22 13:38:42 UTC (rev 1829)
@@ -34,7 +34,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>i18n</artifactId>
- <version>2.0</version>
+ <version>2.0.1-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.i18n</groupId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-11-22 13:38:39 UTC (rev 1828)
+++ trunk/pom.xml 2010-11-22 13:38:42 UTC (rev 1829)
@@ -37,7 +37,7 @@
</parent>
<artifactId>i18n</artifactId>
- <version>2.0</version>
+ <version>2.0.1-SNAPSHOT</version>
<modules>
<module>nuiton-i18n</module>
@@ -200,11 +200,11 @@
<!-- Source control management. -->
<scm>
- <connection>scm:svn:http://svn.nuiton.org/svn/i18n/tags/i18n-2.0</connection>
+ <connection>scm:svn:http://svn.nuiton.org/svn/i18n/trunk</connection>
<developerConnection>
- scm:svn:http://svn.nuiton.org/svn/i18n/tags/i18n-2.0
+ scm:svn:http://svn.nuiton.org/svn/i18n/trunk
</developerConnection>
- <url>http://www.nuiton.org/repositories/browse/i18n/tags/i18n-2.0</url>
+ <url>http://www.nuiton.org/repositories/browse/i18n/trunk</url>
</scm>
<profiles>
1
0
Author: tchemit
Date: 2010-11-22 14:38:39 +0100 (Mon, 22 Nov 2010)
New Revision: 1828
Url: http://nuiton.org/repositories/revision/i18n/1828
Log:
[maven-release-plugin] copy for tag i18n-2.0
Added:
tags/i18n-2.0/
1
0