Author: tchemit Date: 2012-08-14 19:41:30 +0200 (Tue, 14 Aug 2012) New Revision: 1967 Url: http://nuiton.org/repositories/revision/i18n/1967 Log: fixes #2175: Updates to mavenpom 3.3.6 fixes #2242: Error on validation compilation using nuiton-validator when no internet connection refs #928: Use maven-plugin-plugin 3 api (no need to have annotation in compile scope) Removed: trunk/i18n-maven-plugin/src/main/resources/xwork-validator-1.0.2.dtd trunk/i18n-maven-plugin/src/main/resources/xwork-validator-1.0.3.dtd Modified: trunk/i18n-maven-plugin/pom.xml trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/AbstractParserXmlMojo.java trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserValidationMojo.java trunk/pom.xml Modified: trunk/i18n-maven-plugin/pom.xml =================================================================== --- trunk/i18n-maven-plugin/pom.xml 2012-08-07 07:50:14 UTC (rev 1966) +++ trunk/i18n-maven-plugin/pom.xml 2012-08-14 17:41:30 UTC (rev 1967) @@ -97,6 +97,12 @@ <artifactId>maven-plugin-annotations</artifactId> </dependency> + <!-- pour parser les fichiers de validation --> + <dependency> + <groupId>org.apache.struts.xwork</groupId> + <artifactId>xwork-core</artifactId> + </dependency> + <!-- FIXME si on ne le rajoute pas, on se retrouve avec la version 1.1 qui ne convient pas --> <dependency> <groupId>org.codehaus.plexus</groupId> Modified: trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/AbstractParserXmlMojo.java =================================================================== --- trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/AbstractParserXmlMojo.java 2012-08-07 07:50:14 UTC (rev 1966) +++ trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/AbstractParserXmlMojo.java 2012-08-14 17:41:30 UTC (rev 1967) @@ -37,6 +37,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; import javax.xml.namespace.NamespaceContext; import javax.xml.parsers.DocumentBuilder; @@ -385,7 +386,7 @@ if (verbose) { getLog().info("Start parsing file " + fileToProcess); } - Document doc = builder.parse(fileToProcess.getAbsolutePath()); + Document doc = fileToDocument(fileToProcess); XPathExpression expression = xpath.compile(rules); NodeList list = (NodeList) expression.evaluate(doc, XPathConstants.NODESET); @@ -411,5 +412,9 @@ registerKey(key); } } + + protected Document fileToDocument(File fileToProcess) throws SAXException, IOException { + return builder.parse(fileToProcess.getAbsolutePath()); + } } } Modified: trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserValidationMojo.java =================================================================== --- trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserValidationMojo.java 2012-08-07 07:50:14 UTC (rev 1966) +++ trunk/i18n-maven-plugin/src/main/java/org/nuiton/i18n/plugin/parser/impl/ParserValidationMojo.java 2012-08-14 17:41:30 UTC (rev 1967) @@ -25,6 +25,8 @@ package org.nuiton.i18n.plugin.parser.impl; +import com.opensymphony.xwork2.util.DomHelper; +import org.apache.commons.io.FileUtils; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -32,16 +34,16 @@ import org.nuiton.i18n.plugin.parser.SourceEntry; import org.nuiton.io.FileUpdater; import org.nuiton.io.MirroredFileUpdater; -import org.xml.sax.EntityResolver; +import org.w3c.dom.Document; import org.xml.sax.InputSource; +import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; import javax.xml.xpath.XPath; import java.io.File; import java.io.IOException; -import java.net.SocketTimeoutException; -import java.net.URL; -import java.net.URLConnection; +import java.util.HashMap; +import java.util.Map; /** * Find i18n keys from xworks xml validation files. @@ -56,8 +58,6 @@ public static final String DEFAULT_INCLUDES = "**/*-validation.xml"; - final URL xworksResource = getClass().getResource("/xwork-validator-1.0.2.dtd"); - /** Root directory of the default entry. */ @Parameter(property = "i18n.defaultBasedir", defaultValue = "${basedir}/src/main/resources", required = true) protected File defaultBasedir; @@ -83,7 +83,7 @@ protected String coreRuleFile; /** - * Always use the local xowrks dtd to increase performance. + * Always use the local xworks dtd to increase performance. * * @since 1.6.0 */ @@ -99,7 +99,17 @@ @Parameter(property = "i18n.outputGetter", defaultValue = "validation.getter", required = true) protected String outputGetter; + private Map<String, String> dtdMappings; + public ParserValidationMojo() { + + dtdMappings = new HashMap<String, String>(); + dtdMappings.put("-//Apache Struts//XWork Validator 1.0//EN", "xwork-validator-1.0.dtd"); + dtdMappings.put("-//Apache Struts//XWork Validator 1.0.2//EN", "xwork-validator-1.0.2.dtd"); + dtdMappings.put("-//Apache Struts//XWork Validator 1.0.3//EN", "xwork-validator-1.0.3.dtd"); + } + + @Override public String[] getDefaultIncludes() { return new String[]{defaultIncludes}; @@ -141,9 +151,6 @@ protected XmlFileParser newXmlFileParser(final XPath xpath, final DocumentBuilder builder) { - // add cached entity resolver - builder.setEntityResolver(getEntityResolver()); - return new XmlFileParser(getLog(), encoding, oldParser, @@ -153,7 +160,15 @@ builder, namespaces, isVerbose()) { + @Override + protected Document fileToDocument(File fileToProcess) throws SAXException, IOException { + InputSource in = new InputSource(FileUtils.openInputStream(fileToProcess)); + Document doc = DomHelper.parse(in, dtdMappings); + return doc; + } + + @Override public String extract(String i18nString) { String s = null; if (!i18nString.trim().isEmpty()) { @@ -172,50 +187,4 @@ }; } - protected EntityResolver getEntityResolver() { - - return new EntityResolver() { - - public static final String XWORK_PUBLIC_ID = - "-//Apache Struts//XWork Validator 1.0.3//EN"; - - boolean useLocal = useLocalResolver; - - @Override - public InputSource resolveEntity(String publicId, - String systemId) throws IOException { - if (getLog().isDebugEnabled()) { - getLog().debug("publicID:" + publicId + ", systemId:" + - systemId); - } - if (XWORK_PUBLIC_ID.equals(publicId)) { - if (!useLocal) { - URL uri = new URL(systemId); - if (verbose) { - getLog().info("try to connect to " + uri); - } - URLConnection openConnection = uri.openConnection(); - openConnection.setUseCaches(true); - openConnection.setConnectTimeout(1000); - try { - openConnection.connect(); - return new InputSource( - openConnection.getInputStream()); - } catch (SocketTimeoutException e) { - useLocal = true; - } catch (IOException e) { - useLocal = true; - } - } - - // use directly local resource - InputSource inputSource = - new InputSource(xworksResource.openStream()); - return inputSource; - } - // use the default behaviour - return null; - } - }; - } } Deleted: trunk/i18n-maven-plugin/src/main/resources/xwork-validator-1.0.2.dtd =================================================================== --- trunk/i18n-maven-plugin/src/main/resources/xwork-validator-1.0.2.dtd 2012-08-07 07:50:14 UTC (rev 1966) +++ trunk/i18n-maven-plugin/src/main/resources/xwork-validator-1.0.2.dtd 2012-08-14 17:41:30 UTC (rev 1967) @@ -1,67 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - #%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% - --> - - -<!-- - XWork Validators DTD. - Used the following DOCTYPE. - - <!DOCTYPE validators PUBLIC - "-//OpenSymphony Group//XWork Validator 1.0.2//EN" - "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> ---> - - -<!ELEMENT validators (field|validator)+> - -<!ELEMENT field (field-validator+)> -<!ATTLIST field - name CDATA #REQUIRED -> - -<!ELEMENT field-validator (param*, message)> -<!ATTLIST field-validator - type CDATA #REQUIRED - short-circuit (true|false) "false" -> - -<!ELEMENT validator (param*, message)> -<!ATTLIST validator - type CDATA #REQUIRED - short-circuit (true|false) "false" -> - -<!ELEMENT param (#PCDATA)> -<!ATTLIST param - name CDATA #REQUIRED -> - -<!ELEMENT message (#PCDATA)> -<!ATTLIST message - key CDATA #IMPLIED -> - - Deleted: trunk/i18n-maven-plugin/src/main/resources/xwork-validator-1.0.3.dtd =================================================================== --- trunk/i18n-maven-plugin/src/main/resources/xwork-validator-1.0.3.dtd 2012-08-07 07:50:14 UTC (rev 1966) +++ trunk/i18n-maven-plugin/src/main/resources/xwork-validator-1.0.3.dtd 2012-08-14 17:41:30 UTC (rev 1967) @@ -1,42 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- - XWork Validators DTD. - Used the following DOCTYPE. - - <!DOCTYPE validators PUBLIC - "-//Apache Struts//XWork Validator 1.0.3//EN" - "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd"> ---> - - -<!ELEMENT validators (field|validator)+> - -<!ELEMENT field (field-validator+)> -<!ATTLIST field - name CDATA #REQUIRED -> - -<!ELEMENT field-validator (param*, message)> -<!ATTLIST field-validator - type CDATA #REQUIRED - short-circuit (true|false) "false" -> - -<!ELEMENT validator (param*, message)> -<!ATTLIST validator - type CDATA #REQUIRED - short-circuit (true|false) "false" -> - -<!ELEMENT param (#PCDATA)> -<!ATTLIST param - name CDATA #REQUIRED -> - -<!ELEMENT message (#PCDATA|param)*> -<!ATTLIST message - key CDATA #IMPLIED -> - - Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-08-07 07:50:14 UTC (rev 1966) +++ trunk/pom.xml 2012-08-14 17:41:30 UTC (rev 1967) @@ -33,7 +33,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>mavenpom4redmineAndCentral</artifactId> - <version>3.3.5</version> + <version>3.3.6</version> </parent> <artifactId>i18n</artifactId> @@ -154,9 +154,15 @@ <groupId>org.apache.maven.plugin-tools</groupId> <artifactId>maven-plugin-annotations</artifactId> <version>${pluginPluginVersion}</version> - <scope>compile</scope> + <scope>provided</scope> </dependency> + <dependency> + <groupId>org.apache.struts.xwork</groupId> + <artifactId>xwork-core</artifactId> + <version>2.3.4</version> + </dependency> + <!-- FIXME si on ne le rajoute pas, on se retrouve avec la version 1.1 qui ne convient pas --> <dependency> <groupId>org.codehaus.plexus</groupId>