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
January 2011
- 4 participants
- 41 discussions
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