[jboss-svn-commits] JBL Code SVN: r16158 - in labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin: src/main/java/org/jboss and 20 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Oct 30 09:40:37 EDT 2007
Author: steve.ebersole at jboss.com
Date: 2007-10-30 09:40:37 -0400 (Tue, 30 Oct 2007)
New Revision: 16158
Added:
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Action.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/JDocBookProcessException.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Log.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Options.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/ActionException.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/TranslateXmlAction.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/UpdatePoAction.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/UpdatePotAction.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/ExecutionException.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/Executor.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/ProcessOutputManager.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/StreamBridge.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/PortableObject.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/SourceTextTokenizer.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/SourceTokenProcessor.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/io/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/io/PortableObjectWriter.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/package.html
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/xml/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/xml/Mode.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/xml/XmlSourceTokenizer.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/profile/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/profile/Profiler.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/profile/ProfilerFactory.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/profile/ProfilerImpl.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/Renderer.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/RenderingException.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/FormatPlan.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/StandardDocBookFormatDescriptor.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/StandardDocBookFormatDescriptors.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/TargetNamingStrategy.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/UserFormatConfiguration.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/impl/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/impl/BasicRenderer.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/impl/PDFRenderer.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/impl/RendererFactory.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/Constants.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/DocBookProfilingStrategy.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/FileUtils.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/I18nUtils.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/LocaleUtils.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/NoOpWriter.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/ResourceHelper.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/TransformerType.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/VCSDirectoryExclusionFilter.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/XIncludeHelper.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/TransformerBuilder.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/XSLTException.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/catalog/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/catalog/AbstractCatalogManager.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/catalog/ExplicitCatalogManager.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/catalog/ImplicitCatalogManager.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/BasicUrnResolver.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/CurrentVersionResolver.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/ExplicitUrnResolver.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/RelativeJarUriResolver.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/ResolverChain.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/VersionResolver.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/CleanPoMojo.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/CleanPotMojo.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/TranslationMojo.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/UpdatePoMojo.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/UpdatePotMojo.java
Removed:
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/gen/
Modified:
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/pom.xml
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/AbstractDocBookMojo.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/Format.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/GenerationMojo.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/Options.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/PackageMojo.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/ResourceMojo.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/CompositeMavenProjectProperties.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/PropertiesException.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceDelegate.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceException.java
labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/resources/META-INF/plexus/components.xml
Log:
partitioned packages; added support for profiling; added support for gnu-gettext-based translations
Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/pom.xml
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/pom.xml 2007-10-30 12:49:06 UTC (rev 16157)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/pom.xml 2007-10-30 13:40:37 UTC (rev 16158)
@@ -13,7 +13,7 @@
<groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-jdocbook-plugin</artifactId>
<packaging>maven-plugin</packaging>
- <version>2.0.1-SNAPSHOT</version>
+ <version>2.1.0-SNAPSHOT</version>
<name>jDocBook Maven Plugin</name>
<description>This plugin adds support for Docbook transformations to Maven.</description>
@@ -58,8 +58,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
- <source>1.4</source>
- <target>1.4</target>
+ <source>1.5</source>
+ <target>1.5</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
@@ -111,13 +111,11 @@
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.8.0</version>
- <scope>runtime</scope>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xmlParserAPIs</artifactId>
<version>2.6.2</version>
- <scope>runtime</scope>
</dependency>
<!-- depending upon which transformer factory you want to use -->
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Action.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Action.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Action.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook;
+
+/**
+ * An action defines a small piece of executable funtionality.
+ *
+ * @author Steve Ebersole
+ */
+public interface Action {
+ /**
+ * Perform the underlying functionality.
+ */
+ public void perform();
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/JDocBookProcessException.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/JDocBookProcessException.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/JDocBookProcessException.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook;
+
+/**
+ * Indicates problem performing JDocBook-related processing.
+ *
+ * @author Steve Ebersole
+ */
+public class JDocBookProcessException extends RuntimeException {
+ public JDocBookProcessException(String message) {
+ super( message );
+ }
+
+ public JDocBookProcessException(String message, Throwable cause) {
+ super( message, cause );
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Log.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Log.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Log.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook;
+
+/**
+ * A general 'log bridge' contract.
+ *
+ * @author Steve Ebersole
+ */
+public interface Log {
+ public void trace(String message);
+ public void trace(String message, Object... args);
+
+ public void info(String message);
+ public void info(String message, Object... args);
+ public void info(String message, Throwable exception);
+ public void info(String message, Throwable exception, Object... args);
+
+ public void error(String message);
+ public void error(String message, Object... args);
+ public void error(String message, Throwable exception);
+ public void error(String message, Throwable exception, Object... args);
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Options.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Options.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Options.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook;
+
+import java.util.Properties;
+
+import org.apache.xml.resolver.CatalogManager;
+import org.apache.xml.resolver.tools.CatalogResolver;
+import org.jboss.jdocbook.util.TransformerType;
+import org.jboss.jdocbook.xslt.TransformerBuilder;
+import org.jboss.jdocbook.xslt.catalog.ExplicitCatalogManager;
+import org.jboss.jdocbook.xslt.catalog.ImplicitCatalogManager;
+
+/**
+ * A (detachable) representation of the user configuration.
+ *
+ * @author Steve Ebersole
+ */
+public class Options {
+ private boolean xincludeSupported;
+ private String[] catalogs;
+ private String xmlTransformerType;
+ private Properties transformerParameters;
+ private boolean useRelativeImageUris = true;
+ private String docbookVersion;
+ private char localeSeparator = '-';
+
+ private CatalogResolver catalogResolver;
+ private TransformerBuilder transformerBuilder;
+
+ private Log log = new NoOpLog();
+
+ protected Options() {
+ }
+
+ public Options(char localeSeparator) {
+ this.localeSeparator = localeSeparator;
+ }
+
+ public Options(
+ boolean xincludeSupported,
+ String[] catalogs,
+ String xmlTransformerType,
+ Properties transformerParameters,
+ boolean useRelativeImageUris,
+ String docBookVersion,
+ char localeSeparator) {
+ this.xincludeSupported = xincludeSupported;
+ this.catalogs = catalogs;
+ this.xmlTransformerType = xmlTransformerType;
+ this.transformerParameters = transformerParameters;
+ this.useRelativeImageUris = useRelativeImageUris;
+ this.docbookVersion = docBookVersion;
+ this.localeSeparator = localeSeparator;
+ }
+
+ public boolean isXincludeSupported() {
+ return xincludeSupported;
+ }
+
+ public String[] getCatalogs() {
+ return catalogs;
+ }
+
+ public String getXmlTransformerType() {
+ return xmlTransformerType;
+ }
+
+ public TransformerType resolveXmlTransformerType() {
+ return TransformerType.parse( getXmlTransformerType() );
+ }
+
+ public Properties getTransformerParameters() {
+ if ( transformerParameters == null ) {
+ transformerParameters = new Properties();
+ }
+ return transformerParameters;
+ }
+
+ public boolean isUseRelativeImageUris() {
+ return useRelativeImageUris;
+ }
+
+ public String getDocbookVersion() {
+ return docbookVersion;
+ }
+
+ public void setDocbookVersion(String docbookVersion) {
+ this.docbookVersion = docbookVersion;
+ }
+
+ public char getLocaleSeparator() {
+ return localeSeparator;
+ }
+
+ public CatalogResolver getCatalogResolver() {
+ if ( catalogResolver == null ) {
+ CatalogManager catalogManager;
+ if ( getCatalogs() == null || getCatalogs().length == 0 ) {
+ catalogManager = new ImplicitCatalogManager();
+ }
+ else {
+ catalogManager = new ExplicitCatalogManager( getCatalogs() );
+ }
+ catalogResolver = new CatalogResolver( catalogManager );
+ }
+ return catalogResolver;
+ }
+
+ public TransformerBuilder getTransformerBuilder() {
+ if ( transformerBuilder == null ) {
+ transformerBuilder = new TransformerBuilder(
+ resolveXmlTransformerType(),
+ getTransformerParameters(),
+ getCatalogResolver(),
+ getDocbookVersion()
+ );
+ }
+ return transformerBuilder;
+ }
+
+ public void setLog(Log log) {
+ this.log = log;
+ }
+
+ public Log getLog() {
+ return log;
+ }
+
+ private static class NoOpLog implements Log {
+
+ public void trace(String message) {
+ }
+
+ public void trace(String message, Object... args) {
+ }
+
+ public void info(String message) {
+ }
+
+ public void info(String message, Object... args) {
+ }
+
+ public void info(String message, Throwable exception) {
+ }
+
+ public void info(String message, Throwable exception, Object... args) {
+ }
+
+ public void error(String message) {
+ }
+
+ public void error(String message, Object... args) {
+ }
+
+ public void error(String message, Throwable exception) {
+ }
+
+ public void error(String message, Throwable exception, Object... args) {
+ }
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/ActionException.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/ActionException.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/ActionException.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.i18n.actions;
+
+import org.jboss.jdocbook.JDocBookProcessException;
+
+/**
+ * Used to indicate an error performing an {@link org.jboss.jdocbook.Action}.
+ *
+ * @author Steve Ebersole
+ */
+public class ActionException extends JDocBookProcessException {
+ private static final long serialVersionUID = 5590768273066409640L;
+
+ public ActionException(String message) {
+ super( message );
+ }
+
+ public ActionException(String message, Throwable cause) {
+ super( message, cause );
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/TranslateXmlAction.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/TranslateXmlAction.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/TranslateXmlAction.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.i18n.actions;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.jboss.jdocbook.Action;
+import org.jboss.jdocbook.Options;
+import org.jboss.jdocbook.i18n.actions.process.Executor;
+import org.jboss.jdocbook.util.I18nUtils;
+import org.jboss.jdocbook.util.XIncludeHelper;
+import org.jboss.jdocbook.util.FileUtils;
+
+/**
+ * Action to render the translators work back into XML in preparation for XSLT processing.
+ * <p/>
+ * NOTE : The processing here is based on po2xml from the poxml library.
+ *
+ * @author Steve Ebersole
+ */
+public class TranslateXmlAction implements Action {
+ private final File masterFile;
+ private final File poDirectory;
+ private final File targetDirectory;
+ private final Options options;
+
+ public TranslateXmlAction(File masterFile, File poDirectory, File targetDirectory, Options options) {
+ this.masterFile = masterFile;
+ this.poDirectory = poDirectory;
+ this.targetDirectory = targetDirectory;
+ this.options = options;
+ }
+
+ public void perform() {
+ po2xml( masterFile, poDirectory, targetDirectory );
+ }
+
+ protected void po2xml(File masterFile, File translationDirectory, File translatedWorkDirectory) {
+ options.getLog().trace( "starting translation [" + masterFile + "]" );
+ if ( !masterFile.exists() ) {
+ options.getLog().info( "skipping translation; master file did not exist : {0}", masterFile );
+ return;
+ }
+
+ final String poFileName = I18nUtils.determinePoFileName( masterFile );
+ final File poFile = new File( translationDirectory, poFileName );
+ if ( !poFile.exists() ) {
+ throw new ActionException( "Unable to locate PO file for [" + masterFile.getName() + "] in [" + translationDirectory.getName() + "]" );
+ }
+ final File translatedFile = new File( translatedWorkDirectory, masterFile.getName() );
+ generateTranslatedXML( masterFile, poFile, translatedFile );
+
+ // Note : recursion below accounts for inclusions within inclusions
+ final File sourceBasedir = masterFile.getParentFile();
+ for ( File inclusion : XIncludeHelper.locateInclusions( masterFile ) ) {
+ options.getLog().trace( "starting translation of inclusion [" + inclusion + "]" );
+ final String relativity = FileUtils.determineRelativity( inclusion, sourceBasedir );
+ options.getLog().trace( "determined relativity : " + relativity );
+ final File relativeTranslationDir = ( relativity == null )
+ ? translationDirectory
+ : new File( translationDirectory, relativity );
+ final File relativeWorkDir = ( relativity == null )
+ ? translatedWorkDirectory
+ : new File( translatedWorkDirectory, relativity );
+ po2xml( inclusion, relativeTranslationDir, relativeWorkDir );
+ }
+ }
+
+ private void generateTranslatedXML(File sourceFile, File poFile, File translatedFile) {
+ if ( !sourceFile.exists() ) {
+ options.getLog().trace( "skipping translation; source file did not exist : {0}", sourceFile );
+ return;
+ }
+ if ( !poFile.exists() ) {
+ options.getLog().trace( "skipping translation; PO file did not exist : {0}", poFile );
+ return;
+ }
+
+ if ( translatedFile.exists()
+ && translatedFile.lastModified() >= sourceFile.lastModified()
+ && translatedFile.lastModified() >= poFile.lastModified() ) {
+ options.getLog().trace( "skipping translation; up-to-date : {0}", translatedFile );
+ return;
+ }
+
+ translatedFile.getParentFile().mkdirs();
+ final String cmd = "po2xml " + FileUtils.resolveFullPathName( sourceFile ) + " " + FileUtils.resolveFullPathName( poFile );
+ try {
+ final FileOutputStream xmlStream = new FileOutputStream( translatedFile );
+ try {
+ options.getLog().trace( "<execute>" + cmd + "</execution>" );
+ Executor.execute( cmd, xmlStream );
+ }
+ finally {
+ try {
+ xmlStream.flush();
+ xmlStream.close();
+ }
+ catch ( IOException ignore ) {
+ // intentionally empty...
+ }
+ }
+ }
+ catch ( IOException e ) {
+ throw new ActionException( "unable to open output stream for translated XML file [" + translatedFile + "]" );
+ }
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/UpdatePoAction.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/UpdatePoAction.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/UpdatePoAction.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.i18n.actions;
+
+import java.io.File;
+import java.util.Locale;
+
+import org.jboss.jdocbook.Action;
+import org.jboss.jdocbook.Options;
+import org.jboss.jdocbook.i18n.actions.process.Executor;
+import org.jboss.jdocbook.util.VCSDirectoryExclusionFilter;
+import org.jboss.jdocbook.util.I18nUtils;
+import org.jboss.jdocbook.util.FileUtils;
+
+/**
+ * Update translatable entries in a translation's PO files based on the state of the POT files.
+ * <p/>
+ * NOTE : The processing here is based on either the msgmerge or msginit commands from the GNU gettext package.
+ *
+ * @author Steve Ebersole
+ */
+public class UpdatePoAction implements Action {
+ private final File potDirectory;
+ private final File translationDirectory;
+ private final Locale translationLocale;
+ private final Options options;
+
+ /**
+ * Construct an action ready to perform updates to the PO files for a given translation corresponding to the POT
+ * templates in the given POT-directory.
+ *
+ * @param potDirectory The directory containing the POT files.
+ * @param translationDirectory The directory containing the translation PO files.
+ * @param translationLocale The locale of the translation
+ * @param options The user options
+ */
+ public UpdatePoAction(File potDirectory, File translationDirectory, Locale translationLocale, Options options) {
+ this.potDirectory = potDirectory;
+ this.translationDirectory = translationDirectory;
+ this.translationLocale = translationLocale;
+ this.options = options;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void perform() {
+ msgmerge( potDirectory, translationDirectory, translationLocale );
+ }
+
+ /**
+ * Update the PO files contained in the given translation-directory based on their corresponding POT file
+ * from the template-directory.
+ *
+ * @param templateDirectory The directory containind POT files.
+ * @param translationDirectory The PO files directory.
+ * @param locale The translation locale.
+ */
+ protected void msgmerge(File templateDirectory, File translationDirectory, Locale locale) {
+ if ( !templateDirectory.exists() ) {
+ options.getLog().info( "skipping PO updates; POT directory did not exist : {0}", potDirectory );
+ return;
+ }
+ File[] files = templateDirectory.listFiles( new VCSDirectoryExclusionFilter() );
+ for ( int i = 0, X = files.length; i < X; i++) {
+ if ( files[i].isDirectory() ) {
+ msgmerge(
+ new File( templateDirectory, files[i].getName() ),
+ new File( translationDirectory, files[i].getName() ),
+ translationLocale
+ );
+ }
+ else {
+ if ( I18nUtils.isPotFile( files[i] ) ) {
+ File translation = new File( translationDirectory, I18nUtils.determinePoFileName( files[i] ) );
+ updateTranslation( files[i], translation, locale );
+ }
+ }
+ }
+ }
+
+ private void updateTranslation(File template, File translation, Locale locale) {
+ if ( !template.exists() ) {
+ options.getLog().trace( "skipping PO updates; POT file did not exist : {0}", template );
+ return;
+ }
+
+ if ( translation.lastModified() >= template.lastModified() ) {
+ options.getLog().trace( "skipping PO updates; up-to-date : {0}", translation );
+ return;
+ }
+
+ final String cmd;
+ if ( translation.exists() ) {
+ cmd = "msgmerge --quiet --backup=none --update " + FileUtils.resolveFullPathName( translation )
+ + " " + FileUtils.resolveFullPathName( template );
+ }
+ else {
+ translation.getParentFile().mkdirs();
+ cmd = "msginit --no-translator -l " + locale
+ + " -i " + FileUtils.resolveFullPathName( template )
+ + " -o " + FileUtils.resolveFullPathName( translation );
+ }
+ Executor.execute( cmd );
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/UpdatePotAction.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/UpdatePotAction.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/UpdatePotAction.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.i18n.actions;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.jboss.jdocbook.Action;
+import org.jboss.jdocbook.Options;
+import org.jboss.jdocbook.i18n.actions.process.Executor;
+import org.jboss.jdocbook.util.I18nUtils;
+import org.jboss.jdocbook.util.XIncludeHelper;
+import org.jboss.jdocbook.util.FileUtils;
+
+/**
+ * Update the PortableObjectTemplate (POT) file(s) from a given master source file.
+ * <p/>
+ * Any XIncludes contained in the master source file are followed and processed as well.
+ *
+ * @author Steve Ebersole
+ */
+public class UpdatePotAction implements Action {
+ private final File master;
+ private final File templateDirectory;
+ private final Options options;
+
+ /**
+ * Construct an action ready to perform updates on the POT files pertaining to a given master DocBook source.
+ *
+ * @param master The DocBook source
+ * @param templateDirectory The directory where POT files are contained.
+ * @param options The user options
+ */
+ public UpdatePotAction(File master, File templateDirectory, Options options) {
+ this.templateDirectory = templateDirectory;
+ this.master = master;
+ this.options = options;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void perform() throws ActionException {
+ xml2pot( master, templateDirectory );
+ }
+
+ void xml2pot(File masterFile, File templateDirectory) throws ActionException {
+ if ( !masterFile.exists() ) {
+ options.getLog().info( "skipping POT updates; master file did not exist : {0}", masterFile );
+ return;
+ }
+ final File sourceBasedir = masterFile.getParentFile();
+ final String potFileName = I18nUtils.determinePotFileName( masterFile );
+ final File potFile = new File( templateDirectory, potFileName );
+ updatePortableObjectTemplate( masterFile, potFile );
+
+ // Note : recursion below accounts for inclusions within inclusions
+ for ( File inclusion : XIncludeHelper.locateInclusions( masterFile ) ) {
+ final String relativity = FileUtils.determineRelativity( inclusion, sourceBasedir );
+ final File relativeTemplateDir = ( relativity == null ) ? templateDirectory : new File(
+ templateDirectory,
+ relativity
+ );
+ xml2pot( inclusion, relativeTemplateDir );
+ }
+ }
+
+ private void updatePortableObjectTemplate(File sourceFile, File template) {
+ if ( !sourceFile.exists() ) {
+ options.getLog().trace( "skipping POT update; source file did not exist : {0}", sourceFile );
+ return;
+ }
+
+ if ( template.exists() && template.lastModified() >= sourceFile.lastModified() ) {
+ options.getLog().trace( "skipping POT update; up-to-date : {0}", template );
+ return;
+ }
+
+ template.getParentFile().mkdirs();
+// supposedly the RH DocBot stuff uses xml2pot...
+// executeXml2po( sourceFile, template );
+ executeXml2pot( sourceFile, template );
+ }
+
+// private void executeXml2po(File sourceFile, File template) {
+// final String cmd = "xml2po -o " + I18nUtils.resolveFullPathName( template ) + " " + I18nUtils.resolveFullPathName( sourceFile );
+// Executor.execute( cmd );
+// }
+
+ private void executeXml2pot(File sourceFile, File template) {
+ final String cmd = "xml2pot " + FileUtils.resolveFullPathName( sourceFile );
+
+ try {
+ final FileOutputStream xmlStream = new FileOutputStream( template );
+ try {
+ options.getLog().trace( "updating POT file {0}", template );
+ Executor.execute( cmd, xmlStream );
+ }
+ finally {
+ try {
+ xmlStream.flush();
+ xmlStream.close();
+ }
+ catch ( IOException ignore ) {
+ // intentionally empty...
+ }
+ }
+ }
+ catch ( IOException e ) {
+ throw new ActionException( "unable to open output stream for POT file [" + template + "]" );
+ }
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/ExecutionException.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/ExecutionException.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/ExecutionException.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.i18n.actions.process;
+
+/**
+ * Used to indicate problems performing an execution (sys call).
+ *
+ * @author Steve Ebersole
+ */
+public class ExecutionException extends RuntimeException {
+ private static final long serialVersionUID = -8773360957835742679L;
+
+ public ExecutionException(String message) {
+ super( message );
+ }
+
+ public ExecutionException(String message, Throwable cause) {
+ super( message, cause );
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/Executor.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/Executor.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/Executor.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.i18n.actions.process;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Responsible for performing system call executions and coordinating error checking, process I/O, etc.
+ *
+ * @author Steve Ebersole
+ */
+public class Executor {
+ /**
+ * Shorthand for {@link #execute(String, java.io.OutputStream, java.io.OutputStream)} using
+ * {@link System#out} and {@link System#err} for the process's stdout and errout, respectively.
+ *
+ * @param cmd The command to execute.
+ */
+ public static void execute(String cmd) {
+ execute( cmd, System.out, System.err );
+ }
+
+ /**
+ * Shorthand for {@link #execute(String, java.io.OutputStream, java.io.OutputStream)} using
+ * {@link System#err} for the process's errout and the given <tt>out</tt> for its stdout.
+ *
+ * @param cmd The command to execute.
+ * @param out The stream to which to pipe the process's stdout.
+ */
+ public static void execute(String cmd, OutputStream out) {
+ execute( cmd, out, System.err );
+ }
+
+ /**
+ * Perform the given cmd as a System call, piping the {@link Process#getOutputStream() input} of the resulting
+ * process to our {@link System#in}, its {@link Process#getOutputStream() stdout} to the given <tt>out</tt> stream
+ * and its {@link Process#getOutputStream() errout} to the given <tt>err</tt> stream.
+ *
+ * @param cmd The command to execute.
+ * @param out The stream to which to pipe the process's stdout.
+ * @param err The stream to which to pipe the process's errout.
+ */
+ public static void execute(String cmd, OutputStream out, OutputStream err) {
+ ProcessOutputManager outputManager = null;
+ try {
+ Process cmdProcess = Runtime.getRuntime().exec( cmd );
+ outputManager = new ProcessOutputManager( cmdProcess, out, err );
+ try {
+ cmdProcess.waitFor();
+ }
+ catch ( InterruptedException e ) {
+ throw new ExecutionException( "unable to obtain appropriate runtime environment", e );
+ }
+ if ( cmdProcess.exitValue() != 0 ) {
+ // assume problem...
+ throw new ExecutionException( "there was a problem executing command; check output" );
+ }
+ }
+ catch ( IOException e ) {
+ throw new ExecutionException( "unable to obtain appropriate runtime environment", e );
+ }
+ finally {
+ if ( outputManager != null ) {
+ outputManager.stop();
+ }
+ }
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/ProcessOutputManager.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/ProcessOutputManager.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/ProcessOutputManager.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.i18n.actions.process;
+
+import java.io.OutputStream;
+
+/**
+ * ProcessOutputManager implementation
+ *
+ * @author Steve Ebersole
+ */
+public class ProcessOutputManager {
+ private final StreamBridge outputBridge;
+ private StreamBridge errorBridge;
+
+ public ProcessOutputManager(Process process, OutputStream out, OutputStream err) {
+ outputBridge = new StreamBridge( process.getInputStream(), out );
+ errorBridge = new StreamBridge( process.getErrorStream(), err );
+
+ Thread outputStreamThread = new Thread( outputBridge );
+ outputStreamThread.setDaemon( true );
+ outputStreamThread.start();
+
+ Thread errorStreamThread = new Thread( errorBridge );
+ errorStreamThread.setDaemon( true );
+ errorStreamThread.start();
+ }
+
+ public void stop() {
+ outputBridge.stop();
+ errorBridge.stop();
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/StreamBridge.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/StreamBridge.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/actions/process/StreamBridge.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.i18n.actions.process;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Bridges an input stream to an output stream.
+ * <p/>
+ * This is used in system call handling because the output of the created process is actually represented as an input
+ * stream to our java process. Generally we need to 'pipe' this to an output stream (the console for example).
+ *
+ * @author Steve Ebersole
+ */
+public class StreamBridge implements Runnable {
+ private static final int DEF_BUFFER_SIZE = 512;
+
+ private final InputStream inputStream;
+ private final OutputStream outputStream;
+ private final int bufferSize;
+
+ private boolean stopped = false;
+
+ public StreamBridge(InputStream inputStream, OutputStream outputStream) {
+ this( inputStream, outputStream, DEF_BUFFER_SIZE );
+ }
+
+ public StreamBridge(InputStream inputStream, OutputStream outputStream, int bufferSize) {
+ this.inputStream = inputStream;
+ this.outputStream = outputStream;
+ this.bufferSize = bufferSize;
+ }
+
+ public void run() {
+ final byte[] buf = new byte[bufferSize];
+ int length;
+ try {
+ while ( true ) {
+ length = inputStream.read( buf );
+ if ( ( length <= 0 ) || stopped ) {
+ break;
+ }
+ outputStream.write( buf, 0, length );
+ outputStream.flush();
+ }
+ outputStream.flush();
+ }
+ catch ( IOException ignore ) {
+ // ???
+ }
+ finally {
+ synchronized (this) {
+ notifyAll();
+ }
+ }
+ }
+
+ synchronized void stop() {
+ stopped = true;
+ notifyAll();
+ }
+
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/PortableObject.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/PortableObject.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/PortableObject.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.i18n.gettext.port;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * Models the structure of both Portable Object (PO) and Portable Object Template (POT) files.
+ * <p/>
+ * For the time being I only care about non-pluralized translatables...
+ *
+ * @author Steve Ebersole
+ */
+public class PortableObject {
+ private final String sourceFileName;
+ private final Locale translationLocale;
+ private final Map<String,Entry> entries = new LinkedHashMap<String,Entry>();
+
+ public PortableObject(String sourceFileName, Locale translationLocale) {
+ this.sourceFileName = sourceFileName;
+ this.translationLocale = translationLocale;
+ }
+
+ public String getSourceFileName() {
+ return sourceFileName;
+ }
+
+ public Locale getTranslationLocale() {
+ return translationLocale;
+ }
+
+ public Iterator iterateEntries() {
+ return entries.values().iterator();
+ }
+
+ /**
+ * Models a translatable message.
+ */
+ public class Entry {
+ // msgctxt in gettext documentation
+ private final String messageContext;
+ // msgid in gettext documentation
+ private final String messageId;
+ // msgstr in gettext documentation
+ private String translation;
+ // reference in gettext documentation (along with filename)
+ private List<Integer> lineNumberOccurences = new ArrayList<Integer>();
+ private List<String> extractedComments;
+
+ public Entry(String messageContext, String messageId) {
+ this.messageContext = messageContext;
+ this.messageId = messageId;
+ }
+
+ public Entry(String messageId) {
+ this( null, messageId );
+ }
+
+ public void addOccurence(int line, String comment) {
+ lineNumberOccurences.add( line );
+ addComment( comment );
+ }
+
+ private void addComment(String comment) {
+ if ( extractedComments == null ) {
+ extractedComments = new ArrayList<String>();
+ }
+ extractedComments.add( comment );
+ }
+
+ public String getMessageContext() {
+ return messageContext;
+ }
+
+ public String getMessageId() {
+ return messageId;
+ }
+
+ public String getTranslation() {
+ return translation;
+ }
+
+ public List getLineNumberOccurences() {
+ return lineNumberOccurences;
+ }
+
+ public List getExtractedComments() {
+ return extractedComments;
+ }
+ }
+
+ public void handleEntry(String text, int line, String comment) {
+ if ( text == null || "".equals( text.trim() ) ) {
+ return;
+ }
+
+ Entry entry = entries.get( text );
+ if ( entry == null ) {
+ entry = new Entry( text );
+ entries.put( text, entry );
+ }
+ entry.addOccurence( line, comment );
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/SourceTextTokenizer.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/SourceTextTokenizer.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/SourceTextTokenizer.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.i18n.gettext.port;
+
+/**
+ * Tokenizes a source into translatable text (msgids).
+ *
+ * @author Steve Ebersole
+ */
+public interface SourceTextTokenizer {
+ public void tokenize(SourceTokenProcessor tokenProcessor);
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/SourceTokenProcessor.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/SourceTokenProcessor.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/SourceTokenProcessor.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.i18n.gettext.port;
+
+/**
+ * Contract for processing or handling translatable tokens.
+ *
+ * @author Steve Ebersole
+ */
+public interface SourceTokenProcessor {
+ public void process(String token);
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/io/PortableObjectWriter.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/io/PortableObjectWriter.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/io/PortableObjectWriter.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.i18n.gettext.port.io;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.nio.charset.Charset;
+import java.text.SimpleDateFormat;
+import java.util.Iterator;
+
+import org.jboss.jdocbook.i18n.gettext.port.PortableObject;
+
+/**
+ * PortableObjectWriter implementation
+ *
+ * @author Steve Ebersole
+ */
+public class PortableObjectWriter {
+ private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat( "MMM dd, YYYY" );
+
+ private final PortableObject portableObject;
+
+ public PortableObjectWriter(PortableObject portableObject) {
+ this.portableObject = portableObject;
+ }
+
+ public void write(File target) throws IOException {
+ Charset charset = Charset.forName( "UTF-8" );
+ FileOutputStream fileOutputStream = new FileOutputStream( target );
+ OutputStreamWriter outputStreamWriter = new OutputStreamWriter( fileOutputStream, charset );
+ BufferedWriter bufferedWriter = new BufferedWriter( outputStreamWriter );
+
+ if ( portableObject.getTranslationLocale() == null ) {
+ bufferedWriter.write( "# Master translation template (" + portableObject.getSourceFileName() + ")" );
+ bufferedWriter.write( "\n" );
+ }
+ else {
+ bufferedWriter.write( "# " + portableObject.getTranslationLocale().getDisplayName() + " translations (" + portableObject.getSourceFileName() + ")" );
+ bufferedWriter.write( "\n" );
+ }
+ bufferedWriter.write( "# Automatically generated : " + DATE_FORMAT.format( new java.util.Date() ) );
+ bufferedWriter.write( '\n' );
+ if ( portableObject.getTranslationLocale() == null ) {
+ bufferedWriter.write( "#, fuzzy" );
+ bufferedWriter.write( '\n' );
+ }
+ bufferedWriter.write( '\n' );
+
+ Iterator itr = portableObject.iterateEntries();
+ while ( itr.hasNext() ) {
+ final PortableObject.Entry entry = ( PortableObject.Entry ) itr.next();
+
+ // first, we write out comments...
+ Iterator comments = entry.getExtractedComments().iterator();
+ int count = 0;
+ while ( comments.hasNext() ) {
+ final String comment = ( ( String ) comments.next() ).replace( "\n", "\n#. " );
+ count++;
+ bufferedWriter.write( "#. (" + count + ") " );
+ bufferedWriter.write( comment );
+ bufferedWriter.write( "\n" );
+ }
+
+ // next write line occurences
+ Iterator linenos = entry.getLineNumberOccurences().iterator();
+ bufferedWriter.write( "#: ");
+ while ( linenos.hasNext() ) {
+ final Integer line = ( Integer ) linenos.next();
+ bufferedWriter.write( portableObject.getSourceFileName() + ":" + line + " " );
+ }
+ bufferedWriter.write( "\n" );
+
+ // finally, write the translation key (text) + empty translation
+ bufferedWriter.write( "msgid \"" + entry.getMessageId() + "\"\n" );
+ bufferedWriter.write( "msgstr \"\"\n\n" );
+
+ }
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/package.html
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/package.html (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/package.html 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,16 @@
+<!--
+ ~ Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, v. 2.1. This program is distributed in the
+ ~ hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ ~ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ ~ Lesser General Public License for more details. You should have received a
+ ~ copy of the GNU Lesser General Public License, v.2.1 along with this
+ ~ distribution; if not, write to the Free Software Foundation, Inc.,
+ ~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ ~
+ ~ Red Hat Author(s): Steve Ebersole
+ -->
+Intended as a port of the GNU gettext library. Not yet complete!!!
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/xml/Mode.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/xml/Mode.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/xml/Mode.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.i18n.gettext.port.xml;
+
+import java.util.List;
+
+/**
+ * Mode contract
+ *
+ * @author Steve Ebersole
+ */
+public interface Mode {
+ public List getIgnoredTags();
+ public List getFinalTags();
+ public List getSpacePreserveTags();
+ public String getStringForTranslators();
+ public String getCommentForTranslators();
+
+// public void preProcessXml(Document document, PortableObject messageOutput);
+// public void postProcessXmlTranslation(Document document, String language, String translators);
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/xml/XmlSourceTokenizer.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/xml/XmlSourceTokenizer.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/i18n/gettext/port/xml/XmlSourceTokenizer.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.i18n.gettext.port.xml;
+
+import java.io.File;
+
+import org.jboss.jdocbook.i18n.gettext.port.SourceTextTokenizer;
+import org.jboss.jdocbook.i18n.gettext.port.SourceTokenProcessor;
+
+/**
+ * XmlSourceTokenizer implementation
+ *
+ * @author Steve Ebersole
+ */
+public class XmlSourceTokenizer implements SourceTextTokenizer {
+ private final File xml;
+ private final Mode mode;
+
+ public XmlSourceTokenizer(File xml, Mode mode) {
+ this.xml = xml;
+ this.mode = mode;
+ }
+
+ public void tokenize(SourceTokenProcessor tokenProcessor) {
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/profile/Profiler.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/profile/Profiler.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/profile/Profiler.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.profile;
+
+import java.io.File;
+
+/**
+ * Contract for applying DocBook profiling based on the approach they term 'two-pass'.
+ *
+ * @author Steve Ebersole
+ */
+public interface Profiler {
+ /**
+ * Given a source file, create its profiled equivalent.
+ *
+ * @param source The source file to be profiled.
+ * @return The profiling output.
+ */
+ public File applyProfiling(File source);
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/profile/ProfilerFactory.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/profile/ProfilerFactory.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/profile/ProfilerFactory.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.profile;
+
+import java.io.File;
+
+import org.jboss.jdocbook.Options;
+
+/**
+ * A factory for {@link Profiler} instances.
+ *
+ * @author Steve Ebersole
+ */
+public class ProfilerFactory {
+
+ private final File outputDirectory;
+ private final Options options;
+
+ /**
+ * Constructs a factory capable of producing {@link Profiler} instances writing to the given directory.
+ *
+ * @param outputDirectory The directory where profiling output should be written.
+ * @param options The options.
+ */
+ public ProfilerFactory(File outputDirectory, Options options) {
+ this.options = options;
+ this.outputDirectory = outputDirectory;
+ }
+
+ /**
+ * Builds a profiler.
+ *
+ * @return The profiler.
+ */
+ public Profiler buildProfiler() {
+ return new ProfilerImpl( outputDirectory, options );
+ }
+
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/profile/ProfilerImpl.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/profile/ProfilerImpl.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/profile/ProfilerImpl.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.profile;
+
+import java.io.File;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.Source;
+import javax.xml.transform.Result;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.jboss.jdocbook.Options;
+import org.jboss.jdocbook.render.RenderingException;
+import org.jboss.jdocbook.xslt.XSLTException;
+import org.jboss.jdocbook.util.Constants;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.XMLReader;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.apache.xerces.jaxp.SAXParserFactoryImpl;
+
+/**
+ * Implementation of the {@link Profiler} contract.
+ *
+ * @author Steve Ebersole
+ */
+class ProfilerImpl implements Profiler {
+ private final File outputDirectory;
+ private final Options options;
+
+ ProfilerImpl(File outputDirectory, Options options) {
+ this.outputDirectory = outputDirectory;
+ this.options = options;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public File applyProfiling(File sourceFile) {
+ try {
+ if ( !outputDirectory.exists() ) {
+ outputDirectory.mkdirs();
+ }
+ File targetFile = new File( outputDirectory, sourceFile.getName() );
+ options.getLog().info( "applying DocBook profiling [" + targetFile.getAbsolutePath() + "]" );
+
+ Transformer xslt = options.getTransformerBuilder()
+ .buildStandardTransformer( Constants.MAIN_PROFILE_XSL_RESOURCE );
+ xslt.transform( buildSource( sourceFile ), buildResult( targetFile ) );
+ return targetFile;
+ }
+ catch ( TransformerException e ) {
+ throw new XSLTException( "error performing translation [" + e.getLocationAsString() + "] : " + e.getMessage(), e );
+ }
+ }
+
+ private Source buildSource(File sourceFile) throws RenderingException {
+ try {
+ EntityResolver resolver = options.getCatalogResolver();
+ SAXParserFactory factory = createParserFactory();
+ XMLReader reader = factory.newSAXParser().getXMLReader();
+ reader.setEntityResolver( resolver );
+
+ // Disable DTD loading and validation
+ reader.setFeature( Constants.DTD_LOADING_FEATURE, false );
+ reader.setFeature( Constants.DTD_VALIDATION_FEATURE, false );
+
+ // my attempts at buffering the input stream here failed with issues
+ // resolving XIncludes... :(
+ return new SAXSource( reader, new InputSource( sourceFile.getAbsolutePath() ) );
+ }
+ catch ( ParserConfigurationException e ) {
+ throw new RenderingException( "unable to build SAX Parser", e );
+ }
+ catch ( SAXException e ) {
+ throw new RenderingException( "unable to build SAX Parser", e );
+ }
+ }
+
+ protected final SAXParserFactory createParserFactory() {
+ SAXParserFactory parserFactory = new SAXParserFactoryImpl();
+ parserFactory.setXIncludeAware( options.isXincludeSupported() );
+ return parserFactory;
+ }
+
+ protected Result buildResult(File targetFile) throws RenderingException, XSLTException {
+ return new StreamResult( targetFile );
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/Renderer.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/Renderer.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/Renderer.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.render;
+
+import java.io.File;
+
+import org.jboss.jdocbook.render.format.FormatPlan;
+import org.jboss.jdocbook.xslt.XSLTException;
+
+/**
+ * Renderer contract
+ *
+ * @author Steve Ebersole
+ */
+public interface Renderer {
+
+ /**
+ * Performs the actual rendering or transforming of the DocBook sources into
+ * the respective output format.
+ *
+ * @param source The source DocBook file.
+ * @param plan The formatting plan.
+ * @param renderingDirectory The directory into which to render
+ * @param stagingDirectory The directory where images resources were staged
+ * @throws RenderingException Problem writing the output file(s).
+ * @throws XSLTException Problem performing XSL transformation.
+ */
+ public void render(File source, FormatPlan plan, File renderingDirectory, File stagingDirectory) throws RenderingException, XSLTException;
+
+ public File getAttachableBundle(File source);
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/RenderingException.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/RenderingException.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/RenderingException.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.render;
+
+import org.jboss.jdocbook.JDocBookProcessException;
+
+/**
+ * Indicates issues performing rendering.
+ *
+ * @author Steve Ebersole
+ */
+public class RenderingException extends JDocBookProcessException {
+ private static final long serialVersionUID = -3442815604126090861L;
+
+ public RenderingException(String message) {
+ super( message );
+ }
+
+ public RenderingException(String message, Throwable cause) {
+ super( message, cause );
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/FormatPlan.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/FormatPlan.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/FormatPlan.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.render.format;
+
+import java.io.File;
+
+import org.codehaus.plexus.util.FileUtils;
+import org.jboss.jdocbook.util.DocBookProfilingStrategy;
+
+/**
+ * Merging of DocBook standard information and user specifics. The combination represents the information that will
+ * control the format processing.
+ *
+ * @author Steve Ebersole
+ */
+public class FormatPlan {
+ private final String name;
+ private final String stylesheetResource;
+ private final String correspondingDocBookStylesheetResource;
+ private final boolean imagePathSettingRequired;
+ private final boolean imageCopyingRequired;
+ private final boolean doingChunking;
+ private final DocBookProfilingStrategy profiling;
+ private final TargetNamingStrategy targetNamingStrategy;
+
+ public FormatPlan(
+ final UserFormatConfiguration userFormatConfiguration,
+ final StandardDocBookFormatDescriptor docBookFormatDescriptor) {
+ this(
+ userFormatConfiguration,
+ docBookFormatDescriptor,
+ new TargetNamingStrategy() {
+ public String determineTargetFileName(File source) {
+ return userFormatConfiguration.getFinalName() == null
+ ? FileUtils.basename( source.getAbsolutePath() ) + docBookFormatDescriptor.getStandardFileExtension()
+ : userFormatConfiguration.getFinalName();
+ }
+ }
+ );
+ }
+
+ public FormatPlan(
+ UserFormatConfiguration userFormatConfiguration,
+ StandardDocBookFormatDescriptor docBookFormatDescriptor,
+ TargetNamingStrategy targetNamingStrategy) {
+ this.name = userFormatConfiguration.getFormatName();
+
+ this.profiling = DocBookProfilingStrategy.parse( userFormatConfiguration.getProfilingTypeName() );
+ this.stylesheetResource = userFormatConfiguration.getStylesheetResource() != null
+ ? userFormatConfiguration.getStylesheetResource()
+ : DocBookProfilingStrategy.SINGLE_PASS == profiling
+ ? docBookFormatDescriptor.getProfiledStylesheetResource()
+ : docBookFormatDescriptor.getStylesheetResource();
+ this.correspondingDocBookStylesheetResource = DocBookProfilingStrategy.SINGLE_PASS == profiling
+ ? docBookFormatDescriptor.getProfiledStylesheetResource()
+ : docBookFormatDescriptor.getStylesheetResource();
+
+ this.imagePathSettingRequired = userFormatConfiguration.getImagePathSettingRequired() == null
+ ? docBookFormatDescriptor.isImagePathSettingRequired()
+ : userFormatConfiguration.getImagePathSettingRequired();
+ this.imageCopyingRequired = userFormatConfiguration.getImageCopyingRequired() == null
+ ? docBookFormatDescriptor.isImageCopyingRequired()
+ : userFormatConfiguration.getImageCopyingRequired();
+ this.doingChunking = userFormatConfiguration.getDoingChunking() == null
+ ? docBookFormatDescriptor.isDoingChunking()
+ : userFormatConfiguration.getDoingChunking();
+ this.targetNamingStrategy = targetNamingStrategy;
+ }
+
+ public FormatPlan(
+ String name,
+ String stylesheetResource,
+ String correspondingDocBookStylesheetResource,
+ boolean imagePathSettingRequired,
+ boolean imageCopyingRequired,
+ boolean doingChunking,
+ DocBookProfilingStrategy profiling,
+ TargetNamingStrategy targetNamingStrategy) {
+ this.name = name;
+ this.stylesheetResource = stylesheetResource;
+ this.correspondingDocBookStylesheetResource = correspondingDocBookStylesheetResource;
+ this.imagePathSettingRequired = imagePathSettingRequired;
+ this.imageCopyingRequired = imageCopyingRequired;
+ this.doingChunking = doingChunking;
+ this.profiling = profiling;
+ this.targetNamingStrategy = targetNamingStrategy;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getStylesheetResource() {
+ return stylesheetResource;
+ }
+
+ public String getCorrespondingDocBookStylesheetResource() {
+ return correspondingDocBookStylesheetResource;
+ }
+
+ public boolean isImagePathSettingRequired() {
+ return imagePathSettingRequired;
+ }
+
+ public boolean isImageCopyingRequired() {
+ return imageCopyingRequired;
+ }
+
+ public boolean isDoingChunking() {
+ return doingChunking;
+ }
+
+ public TargetNamingStrategy getTargetNamingStrategy() {
+ return targetNamingStrategy;
+ }
+
+ public DocBookProfilingStrategy getProfiling() {
+ return profiling;
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/StandardDocBookFormatDescriptor.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/StandardDocBookFormatDescriptor.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/StandardDocBookFormatDescriptor.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.render.format;
+
+/**
+ * Contract for descriptors about standard DocBook formats.
+ *
+ * @author Steve Ebersole
+ */
+public interface StandardDocBookFormatDescriptor {
+ /**
+ * The name of this format.
+ *
+ * @return The format name.
+ */
+ public String getName();
+
+ /**
+ * The standard file extension used for this format.
+ *
+ * @return The file extension
+ */
+ public String getStandardFileExtension();
+
+ /**
+ * The standard DocBook stylesheet for this format (as a classpath-relative resource name).
+ *
+ * @return The DocBook stylesheet resource name
+ */
+ public String getStylesheetResource();
+
+ /**
+ * The standard DocBook stylesheet for this format for 'profiling' (as a classpath-relative resource name).
+ *
+ * @return The DocBook 'profiling' stylesheet resource name
+ */
+ public String getProfiledStylesheetResource();
+
+ /**
+ * Does this format require setting the 'img.src.path' DocBook XSLT parameter?
+ *
+ * @return Is setting 'img.src.path' required?
+ */
+ public boolean isImagePathSettingRequired();
+
+ /**
+ * Does this format require copying the images over to the target directory?
+ *
+ * @return Is copying images to the target directory required?
+ */
+ public boolean isImageCopyingRequired();
+
+ /**
+ * Is this format doing chunking?
+ *
+ * @return Doing chunking?
+ */
+ public boolean isDoingChunking();
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/StandardDocBookFormatDescriptors.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/StandardDocBookFormatDescriptors.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/StandardDocBookFormatDescriptors.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.render.format;
+
+/**
+ * Descriptors of the bundled DocBook styles in which we are interested.
+ *
+ * @author Steve Ebersole
+ */
+public class StandardDocBookFormatDescriptors {
+
+ public static final StandardDocBookFormatDescriptor PDF = new BasicDescriptor()
+ .setName( "pdf" )
+ .setStandardFileExtension( "pdf" )
+ .setImagePathSettingRequired( true )
+ .setImageCopyingRequired( false )
+ .setDoingChunking( false )
+ .setStylesheetResource( "/fo/docbook.xsl" )
+ .setProfiledStylesheetResource( "/fo/profile-docbook.xsl" );
+
+ public static final StandardDocBookFormatDescriptor XHTML = new BasicDescriptor()
+ .setName( "xhtml" )
+ .setStandardFileExtension( "xhtml" )
+ .setImagePathSettingRequired( false )
+ .setImageCopyingRequired( true )
+ .setDoingChunking( false )
+ .setStylesheetResource( "/xhtml/docbook.xsl" )
+ .setProfiledStylesheetResource( "/xhtml/profile-docbook.xsl" );
+
+ public static final StandardDocBookFormatDescriptor ECLIPSE = new HtmlBasedDescriptor()
+ .setName( "eclipse" )
+ .setStylesheetResource( "/eclipse/eclipse.xsl" );
+
+ public static final StandardDocBookFormatDescriptor HTML = new HtmlBasedDescriptor()
+ .setName( "html" )
+ .setStylesheetResource( "/html/chunk.xsl" )
+ .setProfiledStylesheetResource( "/html/profile-chunk.xsl" );
+
+ public static final StandardDocBookFormatDescriptor HTML_SINGLE = new HtmlBasedDescriptor()
+ .setName( "html_single" )
+ .setDoingChunking( false )
+ .setStylesheetResource( "/html/docbook.xsl" )
+ .setProfiledStylesheetResource( "/html/profile-docbook.xsl" );
+
+ public static final StandardDocBookFormatDescriptor HTMLHELP = new HtmlBasedDescriptor()
+ .setName( "htmlhelp" )
+ .setStylesheetResource( "/htmlhelp/htmlhelp.xsl" )
+ .setProfiledStylesheetResource( "/htmlhelp/profile-htmlhelp.xsl" );
+
+ public static final StandardDocBookFormatDescriptor JAVAHELP = new HtmlBasedDescriptor()
+ .setName( "javahelp" )
+ .setStylesheetResource( "/javahelp/javahelp.xsl" )
+ .setProfiledStylesheetResource( "/javahelp/profile-javahelp.xsl" );
+
+ public static final StandardDocBookFormatDescriptor MAN = new HtmlBasedDescriptor()
+ .setName( "man" )
+ .setDoingChunking( false )
+ .setStylesheetResource( "/manpages/docbook.xsl" );
+
+ public static final StandardDocBookFormatDescriptor WEBSITE = new HtmlBasedDescriptor()
+ .setName( "website" )
+ .setDoingChunking( false )
+ .setStylesheetResource( "/website/website.xsl" );
+
+ private static class HtmlBasedDescriptor extends BasicDescriptor {
+ private HtmlBasedDescriptor() {
+ doingChunking = true;
+ standardFileExtension = "html";
+ imagePathSettingRequired = false;
+ imageCopyingRequired = true;
+ }
+ }
+
+ private static class BasicDescriptor implements StandardDocBookFormatDescriptor {
+ protected String name;
+ protected String standardFileExtension;
+ protected String stylesheetResource;
+ protected String profiledStylesheetResource;
+ protected boolean imagePathSettingRequired;
+ protected boolean imageCopyingRequired;
+ protected boolean doingChunking;
+
+ public String getName() {
+ return name;
+ }
+
+ public BasicDescriptor setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public String getStandardFileExtension() {
+ return standardFileExtension;
+ }
+
+ public BasicDescriptor setStandardFileExtension(String standardFileExtension) {
+ this.standardFileExtension = standardFileExtension;
+ return this;
+ }
+
+ public String getStylesheetResource() {
+ return stylesheetResource;
+ }
+
+ public BasicDescriptor setStylesheetResource(String stylesheetResource) {
+ this.stylesheetResource = stylesheetResource;
+ // default :
+ this.profiledStylesheetResource = stylesheetResource;
+ return this;
+ }
+
+ public String getProfiledStylesheetResource() {
+ return profiledStylesheetResource;
+ }
+
+ public BasicDescriptor setProfiledStylesheetResource(String profiledStylesheetResource) {
+ this.profiledStylesheetResource = profiledStylesheetResource;
+ return this;
+ }
+
+ public boolean isImagePathSettingRequired() {
+ return imagePathSettingRequired;
+ }
+
+ public BasicDescriptor setImagePathSettingRequired(boolean imagePathSettingRequired) {
+ this.imagePathSettingRequired = imagePathSettingRequired;
+ return this;
+ }
+
+ public boolean isImageCopyingRequired() {
+ return imageCopyingRequired;
+ }
+
+ public BasicDescriptor setImageCopyingRequired(boolean imageCopyingRequired) {
+ this.imageCopyingRequired = imageCopyingRequired;
+ return this;
+ }
+
+ public boolean isDoingChunking() {
+ return doingChunking;
+ }
+
+ public BasicDescriptor setDoingChunking(boolean doingChunking) {
+ this.doingChunking = doingChunking;
+ return this;
+ }
+ }
+
+ public static StandardDocBookFormatDescriptor getDescriptor(String name) {
+ if ( ECLIPSE.getName().equals( name ) ) {
+ return ECLIPSE;
+ }
+ else if ( HTML.getName().equals( name ) ) {
+ return HTML;
+ }
+ else if ( HTML_SINGLE.getName().equals( name ) ) {
+ return HTML_SINGLE;
+ }
+ else if ( HTMLHELP.getName().equals( name ) ) {
+ return HTMLHELP;
+ }
+ else if ( JAVAHELP.getName().equals( name ) ) {
+ return JAVAHELP;
+ }
+ else if ( MAN.getName().equals( name ) ) {
+ return MAN;
+ }
+ else if ( PDF.getName().equals( name ) ) {
+ return PDF;
+ }
+ else if ( WEBSITE.getName().equals( name ) ) {
+ return WEBSITE;
+ }
+ else if ( XHTML.getName().equals( name ) ) {
+ return XHTML;
+ }
+ else {
+ return null;
+ }
+ }
+
+ /**
+ * Disallow external instantiation of StandardDocBookFormatDescriptors.
+ */
+ private StandardDocBookFormatDescriptors() {
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/TargetNamingStrategy.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/TargetNamingStrategy.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/TargetNamingStrategy.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.render.format;
+
+import java.io.File;
+
+/**
+ * Strategy for naming target files based on the source file.
+ *
+ * @author Steve Ebersole
+ */
+public interface TargetNamingStrategy {
+ /**
+ * Give a source file, determine the appropriate target file name.
+ *
+ * @param source The source file.
+ * @return The target file name.
+ */
+ public String determineTargetFileName(File source);
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/UserFormatConfiguration.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/UserFormatConfiguration.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/format/UserFormatConfiguration.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.render.format;
+
+/**
+ * Models configuration choices of a user in regards to a particular rendering format.
+ *
+ * @author Steve Ebersole
+ */
+public class UserFormatConfiguration {
+ protected String formatName;
+
+ protected String targetFileExtension;
+ protected String finalName;
+ protected String stylesheetResource;
+ protected Boolean imagePathSettingRequired;
+ protected Boolean imageCopyingRequired;
+ protected Boolean doingChunking;
+ protected String profilingTypeName;
+
+ /**
+ * Do not use! Needed by Maven :(
+ */
+ public UserFormatConfiguration() {
+ }
+
+ public UserFormatConfiguration(
+ String formatName,
+ String targetFileExtension,
+ String finalName,
+ String stylesheetResource,
+ Boolean imagePathSettingRequired,
+ Boolean imageCopyingRequired,
+ Boolean doingChunking,
+ String profilingTypeName) {
+ this.formatName = formatName;
+ this.targetFileExtension = targetFileExtension;
+ this.finalName = finalName;
+ this.stylesheetResource = stylesheetResource;
+ this.imagePathSettingRequired = imagePathSettingRequired;
+ this.imageCopyingRequired = imageCopyingRequired;
+ this.doingChunking = doingChunking;
+ this.profilingTypeName = profilingTypeName;
+ }
+
+ public String getFormatName() {
+ return formatName;
+ }
+
+ public String getTargetFileExtension() {
+ return targetFileExtension;
+ }
+
+ public String getFinalName() {
+ return finalName;
+ }
+
+ public String getStylesheetResource() {
+ return stylesheetResource;
+ }
+
+ public Boolean getImagePathSettingRequired() {
+ return imagePathSettingRequired;
+ }
+
+ public Boolean getImageCopyingRequired() {
+ return imageCopyingRequired;
+ }
+
+ public Boolean getDoingChunking() {
+ return doingChunking;
+ }
+
+ public String getProfilingTypeName() {
+ return profilingTypeName;
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/impl/BasicRenderer.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/impl/BasicRenderer.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/impl/BasicRenderer.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.render.impl;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.xerces.jaxp.SAXParserFactoryImpl;
+import org.codehaus.plexus.util.FileUtils;
+import org.jboss.jdocbook.Options;
+import org.jboss.jdocbook.render.Renderer;
+import org.jboss.jdocbook.render.RenderingException;
+import org.jboss.jdocbook.render.format.FormatPlan;
+import org.jboss.jdocbook.util.ResourceHelper;
+import org.jboss.jdocbook.util.Constants;
+import org.jboss.jdocbook.xslt.XSLTException;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
+/**
+ * The basic implementation of the {@link Renderer} contract.
+ *
+ * @author Steve Ebersole
+ */
+public class BasicRenderer implements Renderer {
+ protected final Options options;
+
+ /**
+ * Construct a renderer instance using the given <tt>options</tt>.
+ *
+ * @param options The options.
+ */
+ public BasicRenderer(Options options) {
+ this.options = options;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public File getAttachableBundle(File source) {
+ // todo : we need to figure out how we are going to handle attachments...
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void render(File sourceFile, FormatPlan formatPlan, File renderingDirectory, File stagingDirectory) throws RenderingException, XSLTException {
+ File targetDirectory = new File( renderingDirectory, formatPlan.getName() );
+ if ( ! targetDirectory.exists() ) {
+ FileUtils.mkdir( targetDirectory.getAbsolutePath() );
+ }
+
+ if ( formatPlan.isImageCopyingRequired() ) {
+ if ( stagingDirectory.exists() ) {
+ File imageBase = new File( stagingDirectory, "images" );
+ if ( imageBase.exists() ) {
+ try {
+ FileUtils.copyDirectoryStructure( imageBase, targetDirectory );
+ }
+ catch ( IOException e ) {
+ throw new RenderingException( "unable to copy images", e );
+ }
+ }
+ File cssBase = new File( stagingDirectory, "css" );
+ if ( cssBase.exists() ) {
+ try {
+ FileUtils.copyDirectoryStructure( cssBase, targetDirectory );
+ }
+ catch ( IOException e ) {
+ throw new RenderingException( "unable to copy css", e );
+ }
+ }
+ }
+ }
+
+ File targetFile = new File( targetDirectory, deduceTargetFileName( sourceFile, formatPlan ) );
+ if ( targetFile.exists() ) {
+ targetFile.delete();
+ }
+ if ( !targetFile.exists() ) {
+ try {
+ targetFile.createNewFile();
+ }
+ catch ( IOException e ) {
+ throw new RenderingException( "unable to create output file [" + targetFile.getAbsolutePath() + "]", e );
+ }
+ }
+
+ performRendering( sourceFile, formatPlan, stagingDirectory, targetFile );
+ }
+
+ private void performRendering(File sourceFile, FormatPlan formatPlan, File stagingDirectory, File targetFile) {
+ Transformer transformer = buildTransformer( targetFile, formatPlan, stagingDirectory );
+ Source transformationSource = buildSource( sourceFile );
+ Result transformationResult = buildResult( targetFile );
+ try {
+ transformer.transform( transformationSource, transformationResult );
+ }
+ catch ( TransformerException e ) {
+ throw new XSLTException( "error performing translation [" + e.getLocationAsString() + "] : " + e.getMessage(), e );
+ }
+ finally {
+ releaseResult( transformationResult );
+ }
+ }
+
+ private String deduceTargetFileName(File source, FormatPlan formatPlan) {
+ return formatPlan.getTargetNamingStrategy().determineTargetFileName( source );
+ }
+
+ protected Transformer buildTransformer(File targetFile, FormatPlan formatPlan, File stagingDirectory) throws RenderingException, XSLTException {
+ final URL transformationStylesheet = ResourceHelper.requireResource( formatPlan.getStylesheetResource() );
+ Transformer transformer = options.getTransformerBuilder().buildTransformer( formatPlan, transformationStylesheet );
+ if ( formatPlan.isImagePathSettingRequired() ) {
+ try {
+ String imgSrcPath = new File( stagingDirectory, "images" ).toURL().toString();
+ if ( !imgSrcPath.endsWith( "/" ) ) {
+ imgSrcPath += '/';
+ }
+ options.getLog().trace( "setting 'img.src.path' xslt parameter [" + imgSrcPath + "]" );
+ transformer.setParameter( "img.src.path", imgSrcPath );
+ }
+ catch ( MalformedURLException e ) {
+ throw new XSLTException( "unable to prepare 'img.src.path' xslt parameter", e );
+ }
+ }
+ transformer.setParameter( "keep.relative.image.uris", options.isUseRelativeImageUris() ? "1" : "0" );
+ if ( formatPlan.isDoingChunking() ) {
+ String rootFilename = targetFile.getName();
+ rootFilename = rootFilename.substring( 0, rootFilename.lastIndexOf( '.' ) );
+ transformer.setParameter( "root.filename", rootFilename );
+ transformer.setParameter( "base.dir", targetFile.getParent() + File.separator );
+ transformer.setParameter( "manifest.in.base.dir", "1" );
+ }
+ return transformer;
+ }
+
+ private Source buildSource(File sourceFile) throws RenderingException {
+ try {
+ EntityResolver resolver = options.getCatalogResolver();
+ SAXParserFactory factory = createParserFactory();
+ XMLReader reader = factory.newSAXParser().getXMLReader();
+ reader.setEntityResolver( resolver );
+
+ // Disable DTD loading and validation
+ reader.setFeature( Constants.DTD_LOADING_FEATURE, false );
+ reader.setFeature( Constants.DTD_VALIDATION_FEATURE, false );
+
+ return new SAXSource( reader, new InputSource( new BufferedInputStream( new FileInputStream( sourceFile ) ) ) );
+ }
+ catch ( ParserConfigurationException e ) {
+ throw new RenderingException( "unable to build SAX Parser", e );
+ }
+ catch ( SAXException e ) {
+ throw new RenderingException( "unable to build SAX Parser", e );
+ }
+ catch ( FileNotFoundException e ) {
+ throw new RenderingException( "unable to locate source file", e );
+ }
+ }
+
+ protected final SAXParserFactory createParserFactory() {
+ SAXParserFactory parserFactory = new SAXParserFactoryImpl();
+ parserFactory.setXIncludeAware( options.isXincludeSupported() );
+ return parserFactory;
+ }
+
+ protected Result buildResult(File targetFile) throws RenderingException, XSLTException {
+ return new StreamResult( targetFile );
+ }
+
+ protected void releaseResult(Result transformationResult) {
+ // typically nothing to do...
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/impl/PDFRenderer.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/impl/PDFRenderer.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/impl/PDFRenderer.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.render.impl;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import javax.xml.transform.Result;
+import javax.xml.transform.sax.SAXResult;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.MimeConstants;
+import org.jboss.jdocbook.Options;
+import org.jboss.jdocbook.render.RenderingException;
+
+/**
+ * Implementation of the {@link org.jboss.jdocbook.render.Renderer} contract specifically for dealing with PDF generation.
+ *
+ * @author Steve Ebersole
+ */
+public class PDFRenderer extends BasicRenderer {
+ public PDFRenderer(Options options) {
+ super( options );
+ }
+
+ protected Result buildResult(File targetFile) throws RenderingException {
+ return new ResultImpl( targetFile );
+ }
+
+ protected void releaseResult(Result transformationResult) {
+ ( ( ResultImpl ) transformationResult ).release();
+ }
+
+ private class ResultImpl extends SAXResult {
+ private OutputStream outputStream;
+
+ public ResultImpl(File targetFile) throws RenderingException {
+ try {
+ FopFactory fopFactory = FopFactory.newInstance();
+// fopFactory.getRendererFactory().addRendererMaker(
+// new PDFRendererMaker() {
+//
+// }
+// );
+
+ outputStream = new BufferedOutputStream( new FileOutputStream( targetFile ) );
+
+ FOUserAgent fopUserAgent = fopFactory.newFOUserAgent();
+ fopUserAgent.setProducer( "jDocBook Plugin for Maven" );
+// fopUserAgent.setRendererOverride(
+// new org.apache.fop.render.pdf.PDFRenderer() {
+// public void setupFontInfo(FontInfo inFontInfo) {
+//
+// }
+// }
+// );
+
+ Fop fop = fopFactory.newFop( MimeConstants.MIME_PDF, fopUserAgent, outputStream );
+ setHandler( fop.getDefaultHandler() );
+ }
+ catch ( Throwable t ) {
+ throw new RenderingException( "error building transformation result [" + targetFile.getAbsolutePath() + "]", t );
+ }
+ }
+
+ private void release() {
+ if ( outputStream == null ) {
+ return;
+ }
+ try {
+ outputStream.flush();
+ outputStream.close();
+ }
+ catch ( IOException ignore ) {
+ }
+ }
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/impl/RendererFactory.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/impl/RendererFactory.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/impl/RendererFactory.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.render.impl;
+
+import org.jboss.jdocbook.Options;
+import org.jboss.jdocbook.render.format.StandardDocBookFormatDescriptors;
+import org.jboss.jdocbook.render.Renderer;
+
+/**
+ * A factory for building {@link Renderer} instances.
+ *
+ * @author Steve Ebersole
+ */
+public class RendererFactory {
+ private final Options options;
+
+ public RendererFactory(Options options) {
+ this.options = options;
+ }
+
+ /**
+ * Build an appropriate renderer for the given <tt>formatName</tt>
+ *
+ * @param formatName The name of the formatting in which we want to perform rendering.
+ * @return The renderer.
+ */
+ public Renderer buildRenderer(String formatName) {
+ if ( formatName.equals( StandardDocBookFormatDescriptors.PDF.getName() ) ) {
+ return new PDFRenderer( options );
+ }
+ else {
+ return new BasicRenderer( options );
+ }
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/Constants.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/Constants.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/Constants.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.util;
+
+/**
+ * Various string constants.
+ *
+ * @author Steve Ebersole
+ */
+public class Constants {
+ /**
+ * The DocBook-supplied XSL for profiling in (what it terms) the two-pass approach.
+ */
+ public static final String MAIN_PROFILE_XSL_RESOURCE = "profiling/profile.xsl";
+
+ /**
+ * The name of the XML DTD validation feature.
+ */
+ public static final String DTD_VALIDATION_FEATURE = "http://xml.org/sax/features/validation";
+
+ /**
+ * The name of the XML DTD loading feature.
+ */
+ public static final String DTD_LOADING_FEATURE = "http://apache.org/xml/features/nonvalidating/load-external-dtd";
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/DocBookProfilingStrategy.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/DocBookProfilingStrategy.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/DocBookProfilingStrategy.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.util;
+
+/**
+ * Enumeration of the different strategies defined by the DocBook reference manual for applying profiling.
+ *
+ * @author Steve Ebersole
+ */
+public class DocBookProfilingStrategy {
+ public static final DocBookProfilingStrategy NONE = new DocBookProfilingStrategy( "none" );
+ public static final DocBookProfilingStrategy SINGLE_PASS = new DocBookProfilingStrategy( "single_pass" );
+ public static final DocBookProfilingStrategy TWO_PASS = new DocBookProfilingStrategy( "two_pass" );
+
+ private final String name;
+
+ public DocBookProfilingStrategy(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static DocBookProfilingStrategy parse(String text) {
+ if ( SINGLE_PASS.name.equalsIgnoreCase( text ) ) {
+ return SINGLE_PASS;
+ }
+ else if ( TWO_PASS.name.equalsIgnoreCase( text ) ) {
+ return TWO_PASS;
+ }
+ else {
+ // default...
+ return NONE;
+ }
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/FileUtils.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/FileUtils.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/FileUtils.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.util;
+
+import java.io.File;
+import java.io.FileFilter;
+
+/**
+ * Various {@link java.io.File file} and {@link java.io.File directory} related utilities.
+ *
+ * @author Steve Ebersole
+ */
+public class FileUtils extends org.codehaus.plexus.util.FileUtils {
+ /**
+ * A filter which simply accepts any file about which it is asked.
+ */
+ public static final FileFilter ACCEPT_ALL = new FileFilter() {
+ /**
+ * {@inheritDoc}
+ */
+ public boolean accept(File pathname) {
+ return true;
+ }
+ };
+
+ /**
+ * Determine the 'relativity' of a file in relation to the given basedir. 'relativity', is the relative path
+ * from the basedir to the file's parent (directory).
+ * <p/>
+ * For example, a file <tt>/home/steve/hibernate/tmp/Test.java</tt> would have a relativity of <tt>hibernate/tmp</tt>
+ * relative to <tt>/home/steve</tt> as the basedir.
+ *
+ * @param file The file for which to determine relativity.
+ * @param basedir The directory from which to base the relativity.
+ * @return The relativity.
+ * @throws RuntimeException Indicates that the given file was not found to be relative to basedir.
+ */
+ public static String determineRelativity(File file, File basedir) {
+ String basedirPath = resolveFullPathName( basedir );
+ String directory = resolveFullPathName( file.getParentFile() );
+ if ( basedirPath.equals( directory ) ) {
+ return null;
+ }
+ int baseStart = directory.indexOf( basedirPath );
+ if ( baseStart < 0 ) {
+ throw new RuntimeException( "Included file did not seem to be relative to basedir!" );
+ }
+ String relativity = directory.substring( basedirPath.length() + 1 );
+ while ( relativity.startsWith( "/" ) ) {
+ relativity = relativity.substring( 1 );
+ }
+ return relativity;
+ }
+
+ /**
+ * (recursively) find the most recent timestamp in said directory.
+ *
+ * @param directory The directory to check.
+ * @param acceptor A filter telling which files to consider.
+ * @return The most recent {@link File#lastModified() timestamp} found.
+ */
+ public static long findMostRecentTimestamp(File directory, FileFilter acceptor) {
+ return findMostRecentTimestamp( 0L, directory, acceptor );
+ }
+
+ private static long findMostRecentTimestamp(long current, File directory, FileFilter acceptor) {
+ long local = 0L;
+ for ( File subPath : directory.listFiles() ) {
+ final long temp;
+ if ( subPath.isDirectory() ) {
+ temp = findMostRecentTimestamp( current, directory, acceptor );
+ }
+ else if ( acceptor.accept( subPath ) ) {
+ temp = subPath.lastModified();
+ }
+ else {
+ temp = local;
+ }
+
+ if ( temp > local ) {
+ local = temp;
+ }
+ }
+ return local > current ? local : current;
+ }
+
+ /**
+ * (recursively) find the least recent timestamp in said directory.
+ *
+ * @param directory The directory to check.
+ * @param acceptor A filter telling which files to consider.
+ * @return The least recent {@link File#lastModified() timestamp} found.
+ */
+ public static long findLeastRecentTimestamp(File directory, FileFilter acceptor) {
+ return findLeastRecentTimestamp( Long.MAX_VALUE, directory, acceptor );
+ }
+
+ public static long findLeastRecentTimestamp(long current, File directory, FileFilter acceptor) {
+ long local = Long.MAX_VALUE;
+ for ( File subPath : directory.listFiles() ) {
+ final long temp;
+ if ( subPath.isDirectory() ) {
+ temp = findLeastRecentTimestamp( current, directory, acceptor );
+ }
+ else if ( acceptor.accept( subPath ) ) {
+ temp = subPath.lastModified();
+ }
+ else {
+ temp = local;
+ }
+
+ if ( temp < local ) {
+ local = temp;
+ }
+ }
+ return local < current ? local : current;
+ }
+
+ /**
+ * Here for consistent handling of full path names.
+ *
+ * @param path The path
+ * @return The full path name.
+ */
+ public static String resolveFullPathName(File path) {
+ return path.getAbsolutePath();
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/I18nUtils.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/I18nUtils.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/I18nUtils.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.util;
+
+import java.io.File;
+
+/**
+ * Collection of utilities for dealing with i18n support, as defined by GNU gettext.
+ *
+ * @author Steve Ebersole
+ */
+public class I18nUtils {
+ /**
+ * Is the given file a GNU gettext POT file?
+ * <p/>
+ * The determination here is made solely upon the file extension currently.
+ *
+ * @param file The file to check.
+ * @return True if it is considered a POT file; false otherwise.
+ */
+ public static boolean isPotFile(File file) {
+ return "pot".equals( FileUtils.getExtension( file.getName() ) );
+ }
+
+ /**
+ * Given a source file, determine its correspnding GNU gettext POT file name.
+ *
+ * @param source The source file.
+ * @return The corresponding POT file name.
+ */
+ public static String determinePotFileName(File source) {
+ return FileUtils.removeExtension( source.getName() ) + ".pot";
+ }
+
+ /**
+ * Given a source file (or a POT file), determine its correspnding GNU gettext PO file name.
+ *
+ * @param template The source (or POT) file.
+ * @return The corresponding PO file name.
+ */
+ public static String determinePoFileName(File template) {
+ return FileUtils.removeExtension( template.getName() ) + ".po";
+ }
+
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/LocaleUtils.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/LocaleUtils.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/LocaleUtils.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.util;
+
+import java.util.Comparator;
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+/**
+ * Collection of utlities for dealing with {@link Locale locales}.
+ *
+ * @author Steve Ebersole
+ */
+public class LocaleUtils {
+
+ public static final LocaleComparator LOCALE_COMPARATOR_INST = new LocaleComparator();
+
+ public static class LocaleComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ return render( ( Locale ) o1, '-' ).compareTo( render( ( Locale ) o2, '-' ) );
+ }
+ }
+
+ public static Locale parse(String locale) {
+ return parse( locale, '-' );
+ }
+
+ public static Locale parse(String locale, char sep) {
+ StringTokenizer tokens = new StringTokenizer( locale, "" + sep );
+ int tokencount = tokens.countTokens();
+ switch ( tokencount ) {
+ case 3 :
+ return new Locale( tokens.nextToken(), tokens.nextToken(), tokens.nextToken() );
+ case 2 :
+ return new Locale( tokens.nextToken(), tokens.nextToken() );
+ case 1 :
+ return new Locale( tokens.nextToken() );
+ default:
+ return new Locale( "tbd" );
+ }
+ }
+
+ public static String render(Locale locale, char sep) {
+ boolean l = locale.getLanguage().length() != 0;
+ boolean c = locale.getCountry().length() != 0;
+ boolean v = locale.getVariant().length() != 0;
+ StringBuffer result = new StringBuffer( locale.getLanguage() );
+ if (c||(l&&v)) {
+ result.append( sep ).append( locale.getCountry() );
+ }
+ if (v&&(l||c)) {
+ result.append( sep ).append( locale.getVariant() );
+ }
+ return result.toString();
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/NoOpWriter.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/NoOpWriter.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/NoOpWriter.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.util;
+
+import java.io.Writer;
+
+/**
+ * A writer which does no writing :)
+ *
+ * @author Steve Ebersole
+ */
+public class NoOpWriter extends Writer {
+
+ public void write(char cbuf[], int off, int len) {
+ }
+
+ public void flush() {
+ }
+
+ public void close() {
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/ResourceHelper.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/ResourceHelper.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/ResourceHelper.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.util;
+
+import java.net.URL;
+import java.net.MalformedURLException;
+
+/**
+ * Simple helpers for locating and handling classpath and file URL resource
+ * lookups.
+ *
+ * @author Steve Ebersole
+ */
+public class ResourceHelper {
+ /**
+ * Locate said resource, throwing an exception if it could not be found.
+ *
+ * @param name The resource name.
+ * @return The resource's URL.
+ * @throws IllegalArgumentException If the resource could not be found.
+ */
+ public static URL requireResource(String name) {
+ URL resource = locateResource( name );
+ if ( resource == null ) {
+ throw new IllegalArgumentException( "could not locate resource [" + name + "]" );
+ }
+ return resource;
+ }
+
+ /**
+ * Locate said resource.
+ *
+ * @param name The resource name.
+ * @return The resource's URL.
+ */
+ public static URL locateResource(String name) {
+ if ( name.startsWith( "classpath:" ) ) {
+ return locateClassPathResource( name.substring( 10 ) );
+ }
+ else if ( name.startsWith( "file:" ) ) {
+ try {
+ return new URL( name );
+ }
+ catch ( MalformedURLException e ) {
+ throw new IllegalArgumentException( "malformed explicit file url [" + name + "]");
+ }
+ }
+ else {
+ // assume a classpath resource (backwards compatibility)
+ return locateClassPathResource( name );
+ }
+ }
+
+ private static URL locateClassPathResource(String name) {
+ while ( name.startsWith( "/" ) ) {
+ name = name.substring( 1 );
+ }
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if ( loader == null ) {
+ loader = ResourceHelper.class.getClassLoader();
+ }
+ URL result = loader.getResource( name );
+ if ( result == null ) {
+ result = loader.getResource( "/" + name );
+ }
+ return result;
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/TransformerType.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/TransformerType.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/TransformerType.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.util;
+
+import javax.xml.transform.sax.SAXTransformerFactory;
+
+/**
+ * Enumeration of supported XSLT transformers.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class TransformerType {
+ public static final TransformerType SAXON = new SaxonTransformerType();
+ public static final TransformerType XALAN = new XalanTransformerType();
+
+ private final String name;
+
+ private SAXTransformerFactory factory;
+
+ private TransformerType(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public SAXTransformerFactory getSAXTransformerFactory() {
+ if ( factory == null ) {
+ factory = buildSAXTransformerFactory();
+ }
+ return factory;
+ }
+
+ protected abstract SAXTransformerFactory buildSAXTransformerFactory();
+
+ public static TransformerType parse(String name) {
+ if ( XALAN.name.equals( name ) ) {
+ return XALAN;
+ }
+ else {
+ // default
+ return SAXON;
+ }
+ }
+
+ /**
+ * The SAXON transformer type...
+ */
+ public static class SaxonTransformerType extends TransformerType {
+ public SaxonTransformerType() {
+ super( "saxon" );
+ }
+
+ public SAXTransformerFactory buildSAXTransformerFactory() {
+ return new com.icl.saxon.TransformerFactoryImpl();
+ }
+ }
+
+ public static class XalanTransformerType extends TransformerType {
+ public XalanTransformerType() {
+ super( "xalan" );
+ }
+
+ public SAXTransformerFactory buildSAXTransformerFactory() {
+ return new org.apache.xalan.processor.TransformerFactoryImpl();
+ }
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/VCSDirectoryExclusionFilter.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/VCSDirectoryExclusionFilter.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/VCSDirectoryExclusionFilter.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.util;
+
+import java.io.FileFilter;
+import java.io.File;
+
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.SelectorUtils;
+
+/**
+ * A {@link FileFilter} which excludes VCS metadata directories...
+ *
+ * @author Steve Ebersole
+ */
+public class VCSDirectoryExclusionFilter implements FileFilter {
+ /**
+ * {@inheritDoc}
+ */
+ public boolean accept(File path) {
+ if ( path.isDirectory() ) {
+ if ( isVCSDirectory( path ) ) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean isVCSDirectory(File path) {
+ final String absolutePath = path.getAbsolutePath();
+ for ( int i = 0, X = DirectoryScanner.DEFAULTEXCLUDES.length; i < X; i++ ) {
+ if ( SelectorUtils.matchPath( DirectoryScanner.DEFAULTEXCLUDES[i], absolutePath, true ) ) {
+ // do not accept file on match against an exclude
+ return true;
+ }
+ }
+ return false;
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/XIncludeHelper.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/XIncludeHelper.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/XIncludeHelper.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Set;
+import java.util.TreeSet;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.xerces.jaxp.SAXParserFactoryImpl;
+import org.jboss.jdocbook.JDocBookProcessException;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
+/**
+ * A helper for dealing with XIncludes.
+ *
+ * @author Steve Ebersole
+ */
+public class XIncludeHelper {
+ /**
+ * Given a file which defining an XML document containing XInclude elements, collect all the referenced XInclude
+ * files.
+ *
+ * @param root The file which (potentially) contains XIncludes.
+ * @return The set of files references via XIncludes.
+ */
+ public static Set<File> locateInclusions(File root) {
+ final Set<File> includes = new TreeSet<File>();
+ try {
+ SAXParserFactory parserFactory = new SAXParserFactoryImpl();
+ parserFactory.setXIncludeAware( true );
+
+ XMLReader reader = parserFactory.newSAXParser().getXMLReader();
+ EntityResolver resolver = new EntityResolver() {
+ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
+ if ( publicId == null && systemId != null && systemId.startsWith( "file:/" ) ) {
+ try {
+ includes.add( new File( new URL( systemId ).getFile() ) );
+ }
+ catch ( MalformedURLException e ) {
+ // should never happen...
+ throw new JDocBookProcessException( "Unable to convert reported XInclude href into URL instance [" + systemId + "]" );
+ }
+ }
+ return null;
+ }
+ };
+ reader.setEntityResolver( resolver );
+ // Disable DTD loading and validation
+ reader.setFeature( Constants.DTD_LOADING_FEATURE, false );
+ reader.setFeature( Constants.DTD_VALIDATION_FEATURE, false );
+
+ Source transformationSource = new SAXSource( reader, new InputSource( FileUtils.resolveFullPathName( root ) ) );
+ Result transformationResult = new StreamResult( new NoOpWriter() );
+
+ javax.xml.transform.TransformerFactory transformerFactory = new com.icl.saxon.TransformerFactoryImpl();
+ transformerFactory.newTransformer().transform( transformationSource, transformationResult );
+ }
+ catch ( SAXException e ) {
+ throw new JDocBookProcessException( "Problem processing SAX events", e );
+ }
+ catch ( ParserConfigurationException e ) {
+ throw new JDocBookProcessException( "SAX factory condifiguration problem", e );
+ }
+ catch ( TransformerException e ) {
+ throw new JDocBookProcessException( "Problem performing 'transformation'", e );
+ }
+
+ return includes;
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/TransformerBuilder.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/TransformerBuilder.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/TransformerBuilder.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.xslt;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Properties;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.stream.StreamSource;
+
+import com.icl.saxon.Controller;
+import org.apache.xml.resolver.tools.CatalogResolver;
+import org.jboss.jdocbook.render.format.FormatPlan;
+import org.jboss.jdocbook.util.NoOpWriter;
+import org.jboss.jdocbook.util.ResourceHelper;
+import org.jboss.jdocbook.util.TransformerType;
+import org.jboss.jdocbook.xslt.resolve.CurrentVersionResolver;
+import org.jboss.jdocbook.xslt.resolve.ExplicitUrnResolver;
+import org.jboss.jdocbook.xslt.resolve.RelativeJarUriResolver;
+import org.jboss.jdocbook.xslt.resolve.ResolverChain;
+import org.jboss.jdocbook.xslt.resolve.VersionResolver;
+
+/**
+ * A builder of {@link javax.xml.transform.Transformer} instances, configurable
+ * to return either SAXON or XALAN based transformers.
+ *
+ * @author Steve Ebersole
+ */
+public class TransformerBuilder {
+ private final TransformerType transformerType;
+ private final Properties transformerParameters;
+ private final CatalogResolver catalogResolver;
+ private final String docbookVersion;
+
+ public TransformerBuilder(
+ TransformerType transformerType,
+ Properties transformerParameters,
+ CatalogResolver catalogResolver,
+ String docbookVersion) {
+ this.transformerType = transformerType;
+ this.transformerParameters = transformerParameters;
+ this.catalogResolver = catalogResolver;
+ this.docbookVersion = docbookVersion;
+ }
+
+ public Transformer buildStandardTransformer(URL xslt) {
+ URIResolver uriResolver = buildStandardUriResolver();
+ return buildTransformer( xslt, uriResolver );
+ }
+
+ public Transformer buildStandardTransformer(String xsltResource) {
+ URIResolver uriResolver = buildStandardUriResolver();
+ return buildTransformer( ResourceHelper.requireResource( xsltResource ), uriResolver );
+ }
+
+ public Transformer buildTransformer(FormatPlan formatPlan, URL customStylesheet) throws XSLTException {
+ URIResolver uriResolver = buildUriResolver( formatPlan );
+ URL xsltStylesheet = customStylesheet == null
+ ? ResourceHelper.requireResource( formatPlan.getStylesheetResource() )
+ : customStylesheet;
+ return buildTransformer( xsltStylesheet, uriResolver );
+ }
+
+ protected Transformer buildTransformer(URL xslt, URIResolver uriResolver) throws XSLTException {
+ javax.xml.transform.TransformerFactory transformerFactory = transformerType.getSAXTransformerFactory();
+ transformerFactory.setURIResolver( uriResolver );
+
+ Transformer transformer;
+ try {
+ Source source = new StreamSource( xslt.openStream(), xslt.toExternalForm() );
+ transformer = transformerFactory.newTransformer( source );
+ }
+ catch ( IOException e ) {
+ throw new XSLTException( "problem opening stylesheet", e );
+ }
+ catch ( TransformerConfigurationException e ) {
+ throw new XSLTException( "unable to build transformer", e );
+ }
+
+ configureTransformer( transformer, uriResolver, transformerParameters );
+
+ return transformer;
+
+ }
+
+ public void configureTransformer(Transformer transformer, FormatPlan formatPlan) {
+ configureTransformer( transformer, buildUriResolver( formatPlan ), transformerParameters );
+ }
+
+ public static void configureTransformer(Transformer transformer, URIResolver uriResolver, Properties transformerParameters) {
+ if ( transformer instanceof Controller ) {
+ Controller controller = ( Controller ) transformer;
+ try {
+ controller.makeMessageEmitter();
+ controller.getMessageEmitter().setWriter( new NoOpWriter() );
+ }
+ catch ( TransformerException te ) {
+ // intentionally empty
+ }
+ }
+
+ transformer.setURIResolver( uriResolver );
+ transformer.setParameter( "fop.extensions", "0" );
+ transformer.setParameter( "fop1.extensions", "1" );
+
+ if ( transformerParameters == null ) {
+ return;
+ }
+ for ( Map.Entry<Object, Object> entry : transformerParameters.entrySet() ) {
+ transformer.setParameter( ( String ) entry.getKey(), entry.getValue() );
+ }
+ }
+
+ public ResolverChain buildUriResolver(FormatPlan formatPlan) throws XSLTException {
+ return buildUriResolver( formatPlan.getName(), formatPlan.getCorrespondingDocBookStylesheetResource() );
+ }
+
+ public ResolverChain buildStandardUriResolver() {
+ ResolverChain resolverChain = new ResolverChain();
+ resolverChain.addResolver( new CurrentVersionResolver() );
+ if ( docbookVersion != null ) {
+ resolverChain.addResolver( new VersionResolver( docbookVersion ) );
+ }
+ resolverChain.addResolver( new RelativeJarUriResolver() );
+ resolverChain.addResolver( catalogResolver );
+ return resolverChain;
+ }
+
+ public ResolverChain buildUriResolver(String formatName, String docBookstyleSheet) throws XSLTException {
+ ResolverChain resolverChain = buildStandardUriResolver();
+ resolverChain.addResolver( new ExplicitUrnResolver( formatName, docBookstyleSheet ) );
+ return resolverChain;
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/XSLTException.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/XSLTException.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/XSLTException.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.xslt;
+
+import org.jboss.jdocbook.JDocBookProcessException;
+
+/**
+ * Indicates problems either building XSLT transformers or performing
+ * transformations.
+ *
+ * @author Steve Ebersole
+ */
+public class XSLTException extends JDocBookProcessException {
+ private static final long serialVersionUID = -8042140232571503488L;
+
+ public XSLTException(String message) {
+ super( message );
+ }
+
+ public XSLTException(String message, Throwable cause) {
+ super( message, cause );
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/catalog/AbstractCatalogManager.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/catalog/AbstractCatalogManager.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/catalog/AbstractCatalogManager.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.xslt.catalog;
+
+import java.util.List;
+
+import org.apache.xml.resolver.CatalogManager;
+
+/**
+ * Basic support for our notion of CatalogManagers.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractCatalogManager extends CatalogManager {
+ public AbstractCatalogManager(List<String> catalogNames) {
+ super();
+ setIgnoreMissingProperties( true );
+ if ( catalogNames != null && !catalogNames.isEmpty() ) {
+ StringBuffer buffer = new StringBuffer();
+ boolean first = true;
+ for ( String catalogName : catalogNames ) {
+ if ( catalogName != null ) {
+ if ( first ) {
+ first = false;
+ }
+ else {
+ buffer.append( ';' );
+ }
+ buffer.append( catalogName );
+ }
+ }
+ setCatalogFiles( buffer.toString() );
+ }
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/catalog/ExplicitCatalogManager.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/catalog/ExplicitCatalogManager.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/catalog/ExplicitCatalogManager.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.xslt.catalog;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Utilizes explicit, user-supplied catalog names to build a
+ * CatalogManager.
+ *
+ * @author Steve Ebersole
+ */
+public class ExplicitCatalogManager extends AbstractCatalogManager {
+ public ExplicitCatalogManager(List<String> catalogNames) {
+ super( catalogNames );
+ }
+ public ExplicitCatalogManager(String[] catalogNames) {
+ this( Arrays.asList( catalogNames ) );
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/catalog/ImplicitCatalogManager.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/catalog/ImplicitCatalogManager.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/catalog/ImplicitCatalogManager.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.xslt.catalog;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+
+/**
+ * CatalogManager which resolves its catalogs internally via classpath
+ * resource lookups. Its looks for resources named '/catalog.xml' on the
+ * classpath.
+ *
+ * @author Steve Ebersole
+ */
+public class ImplicitCatalogManager extends AbstractCatalogManager {
+ public ImplicitCatalogManager() {
+ super( resolveCatalogNames() );
+ }
+
+ private static ArrayList<String> resolveCatalogNames() {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ if ( classLoader == null ) {
+ classLoader = ImplicitCatalogManager.class.getClassLoader();
+ }
+ ArrayList<String> names = new ArrayList<String>();
+ try {
+ Enumeration enumeration = classLoader.getResources( "/catalog.xml" );
+ while ( enumeration.hasMoreElements() ) {
+ final URL resource = ( URL ) enumeration.nextElement();
+ final String resourcePath = resource.toExternalForm();
+ if ( resourcePath != null ) {
+ names.add( resourcePath );
+ }
+ }
+ }
+ catch ( IOException ignore ) {
+ // intentionally empty
+ }
+ return names;
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/BasicUrnResolver.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/BasicUrnResolver.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/BasicUrnResolver.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.xslt.resolve;
+
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+
+/**
+ * Basic support for URIResolvers which map a URN unto a single replacement
+ * {@link javax.xml.transform.Source}.
+ *
+ * @author Steve Ebersole
+ */
+public class BasicUrnResolver implements URIResolver {
+ private final String urn;
+ private final Source source;
+
+ /**
+ * Constructs a {@link URIResolver} which maps occurences of the given <tt>urn</tt> onto the given
+ * <tt>source</tt>
+ *
+ * @param urn The urn to be replaced.
+ * @param source The value to return instead of the urn.
+ */
+ public BasicUrnResolver(String urn, Source source) {
+ this.urn = urn;
+ this.source = source;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Source resolve(String href, String base) throws TransformerException {
+ return urn.equals( href ) ? source : null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString() {
+ return super.toString() + " [URN:" + urn + "]";
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/CurrentVersionResolver.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/CurrentVersionResolver.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/CurrentVersionResolver.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.xslt.resolve;
+
+/**
+ * Map hrefs starting with <tt>http://docbook.sourceforge.net/release/xsl/current/</tt>
+ * to classpath resource lookups.
+ *
+ * @author Steve Ebersole
+ */
+public class CurrentVersionResolver extends VersionResolver {
+ /**
+ * Constructs a new CurrentVersionResolver instance.
+ */
+ public CurrentVersionResolver() {
+ super( "current" );
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/ExplicitUrnResolver.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/ExplicitUrnResolver.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/ExplicitUrnResolver.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.xslt.resolve;
+
+import java.io.IOException;
+import java.net.URL;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.jboss.jdocbook.xslt.XSLTException;
+import org.jboss.jdocbook.util.ResourceHelper;
+
+
+/**
+ * Resolves an explicit <tt>urn:docbook:stylesheet</tt> URN against the standard
+ * DocBook stylesheets.
+ *
+ * @author Steve Ebersole
+ */
+public class ExplicitUrnResolver extends BasicUrnResolver {
+ private final String name;
+
+ public ExplicitUrnResolver(String name, String stylesheetResource) throws XSLTException {
+ super( "urn:docbook:stylesheet", createSource( name, stylesheetResource ) );
+ this.name = name;
+ }
+
+ private static Source createSource(String name, String stylesheetResource) throws XSLTException {
+ URL stylesheet = ResourceHelper.requireResource( stylesheetResource );
+ try {
+ return new StreamSource( stylesheet.openStream(), stylesheet.toExternalForm() );
+ }
+ catch ( IOException e ) {
+ throw new XSLTException( "could not locate DocBook stylesheet [" + name + "]", e );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString() {
+ return super.toString() + " [" + name + "]";
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/RelativeJarUriResolver.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/RelativeJarUriResolver.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/RelativeJarUriResolver.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.xslt.resolve;
+
+import java.net.URL;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.stream.StreamSource;
+
+/**
+ * Responsible for resolving relative references from jar base urls.
+ *
+ * @author Steve Ebersole
+ */
+public class RelativeJarUriResolver implements URIResolver {
+ /**
+ * {@inheritDoc}
+ */
+ public Source resolve(String href, String base) throws TransformerException {
+ // href need to be relative
+ if ( href.indexOf( "://" ) > 0 || href.startsWith( "/" ) ) {
+ return null;
+ }
+
+ // base would need to start with jar:
+ if ( !base.startsWith( "jar:" ) ) {
+ return null;
+ }
+
+ String fullHref = base.substring( 4, base.lastIndexOf( '/' ) + 1 ) + href;
+ try {
+ URL url = new URL( fullHref );
+ return new StreamSource( url.openStream(), url.toExternalForm() );
+ }
+ catch ( Throwable t ) {
+ return null;
+ }
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/ResolverChain.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/ResolverChain.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/ResolverChain.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.xslt.resolve;
+
+import java.util.List;
+import java.util.ArrayList;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+
+/**
+ * Allows chaining a series of {@link javax.xml.transform.URIResolver resolvers} together.
+ * <p/>
+ * "Precedence" of the resolvers is determined by the order in which
+ * they are {@link #addResolver added}.
+ *
+ * @author Steve Ebersole
+ */
+public class ResolverChain implements URIResolver {
+ private final List<URIResolver> resolvers = new ArrayList<URIResolver>();
+
+ public ResolverChain() {
+ }
+
+ public ResolverChain(URIResolver resolver) {
+ this();
+ addResolver( resolver );
+ }
+
+ /**
+ * Adds a resolver to the chain.
+ *
+ * @param resolver The resolver to add.
+ */
+ public void addResolver(URIResolver resolver) {
+ resolvers.add( resolver );
+ }
+
+ /**
+ * Here we iterate over all the chained resolvers and delegate to them
+ * until we find one which can handle the resolve request (if any).
+ *
+ * {@inheritDoc}
+ */
+ public Source resolve(String href, String base) throws TransformerException {
+ Source result = null;
+ for ( URIResolver resolver : resolvers ) {
+ result = resolver.resolve( href, base );
+ if ( result != null ) {
+ break;
+ }
+ }
+ return result;
+ }
+}
\ No newline at end of file
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/VersionResolver.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/VersionResolver.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/xslt/resolve/VersionResolver.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.jdocbook.xslt.resolve;
+
+import java.io.IOException;
+import java.net.URL;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.stream.StreamSource;
+
+import org.jboss.jdocbook.util.ResourceHelper;
+
+/**
+ * Maps docbook-version based URIs to local classpath lookups. These URIs are in the form
+ * 'http://docbook.sourceforge.net/release/xsl/{version}'
+ *
+ * @author Steve Ebersole
+ */
+public class VersionResolver implements URIResolver {
+ public static final String BASE_HREF = "http://docbook.sourceforge.net/release/xsl/";
+
+ private final String version;
+ private final String versionHref;
+
+ /**
+ * Constructs a VersionResolver instance using the given <tt>version</tt>.
+ *
+ * @param version The version.
+ */
+ public VersionResolver(String version) {
+ this.version = version;
+ this.versionHref = BASE_HREF + version;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Source resolve(String href, String base) throws TransformerException {
+ if ( href.startsWith( versionHref ) ) {
+ return resolve( href );
+ }
+ else if ( base.startsWith( versionHref ) ) {
+ return resolve( base + "/" + href );
+ }
+ return null;
+ }
+
+ private Source resolve(String href) {
+ String resource = href.substring( versionHref.length() );
+ try {
+ URL resourceURL = ResourceHelper.requireResource( resource );
+ return new StreamSource( resourceURL.openStream(), resourceURL.toExternalForm() );
+ }
+ catch ( IllegalArgumentException e ) {
+ return null;
+ }
+ catch ( IOException e ) {
+ return null;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString() {
+ return super.toString() + " [version=" + version + "]";
+ }
+}
\ No newline at end of file
Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/AbstractDocBookMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/AbstractDocBookMojo.java 2007-10-30 12:49:06 UTC (rev 16157)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/AbstractDocBookMojo.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -16,11 +16,14 @@
package org.jboss.maven.plugins.jdocbook;
import java.io.File;
+import java.text.MessageFormat;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
import java.util.Set;
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -28,10 +31,13 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
-import org.jboss.maven.plugins.jdocbook.gen.RenderingException;
-import org.jboss.maven.plugins.jdocbook.gen.XSLTException;
-import org.jboss.maven.plugins.jdocbook.gen.util.Formatting;
-import org.jboss.maven.plugins.jdocbook.gen.util.StandardDocBookFormatSpecification;
+import org.jboss.jdocbook.JDocBookProcessException;
+import org.jboss.jdocbook.Log;
+import org.jboss.jdocbook.render.RenderingException;
+import org.jboss.jdocbook.render.format.FormatPlan;
+import org.jboss.jdocbook.render.format.StandardDocBookFormatDescriptors;
+import org.jboss.jdocbook.util.LocaleUtils;
+import org.jboss.jdocbook.xslt.XSLTException;
/**
* Basic support for the various DocBook mojos in this packaging plugin.
@@ -119,31 +125,40 @@
*/
protected Resource cssResource;
-// /**
-// * The directory containing local fonts
-// *
-// * @parameter expression="${basedir}/src/main/fonts"
-// */
-// protected File fontsDirectory;
+ /**
+ * The directory containing local fonts
+ *
+ * @parameter expression="${basedir}/src/main/fonts"
+ */
+ protected File fontsDirectory;
/**
* The directory where the output will be written.
*
- * @parameter expression="${basedir}/target/docbook"
+ * @parameter expression="${basedir}/target/docbook/publish"
*/
- protected File targetDirectory;
+ protected File publishDirectory;
/**
* The directory where we can perform some staging staging occurs. Mainly
* this is used for (1) image/css staging; (2) font staging.
*
- * @parameter expression="${basedir}/target/staging"
+ * @parameter expression="${basedir}/target/docbook/staging"
* @required
* @readonly
*/
protected File stagingDirectory;
/**
+ * A directory used for general transient work.
+ *
+ * @parameter expression="${basedir}/target/docbook/work"
+ * @required
+ * @readonly
+ */
+ protected File workDirectory;
+
+ /**
* The formats in which to perform rendering.
*
* @parameter
@@ -152,62 +167,105 @@
protected Format[] formats;
/**
- * The artifactId of the master translation (unless, of course, this is the
- * master translation). It is assumed that the master translation:<ol>
- * <li>is part of the same groupId</li>
- * <li>has its source defined as a dependency (classifier = source)</li>
- * </ol>
+ * Whether or not to perform the attching of the format
+ * outputs as classified attachments.
*
* @parameter
*/
- protected String masterTranslationArtifactId;
+ protected boolean attach = true;
/**
- * Local path to the master translation to use for diff reporting.
+ * Configurable options
*
* @parameter
*/
- protected File masterTranslationFile;
+ protected Options options;
+
+ // translation-specific config setting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
/**
- * The relative path font configuration to use.
+ * The locale of the master translation.
*
- * @parameter
+ * @parameter default-value="en-US"
*/
- protected String fontConfig;
+ protected String masterTranslation;
/**
- * Whether or not to perform the attching of the format
- * outputs as classified attachments.
+ * The path (relative to the sourceDirectory) to the directory containing the master sources. By default the
+ * master-translation's locale (en-US) will be used if such a directory exists <b>if translations are specified</b>.
+ * Users can explicitly specify such a relative path here.
*
- * @parameter
+ * @parameter default-value=""
*/
- protected boolean attach = true;
+ protected String relativeMasterTranslationPath;
/**
- * Configurable options
+ * The directory for POT translations files.
*
- * @parameter
+ * @parameter expression="${basedir}/src/main/docbook/pot"
*/
- protected Options options;
-
+ protected File potDirectory;
/**
+ * The locales of all non-master translations.
+ *
+ * @parameter
+ */
+ protected String[] translations;
+
+ /**
+ * The directory which contains the translations. The assumed strategy here is that each translation would
+ * have a directory under the directory named here which would contain the PO sources for that particular
+ * language translation. The default here is to use sourceDirectory itself.
+ *
+ * @parameter
+ */
+ protected File translationBaseDirectory;
+
+ private File resolvedMasterSourceDirectory;
+
+ /**
* The override method to perform the actual processing of the
* mojo.
*
- * @param formattings The fomattings configured for render
+ * @param formatPlans The format plans
* @throws RenderingException Indicates problem performing rendering
* @throws XSLTException Indicates problem building or executing XSLT transformer
*/
- protected abstract void process(Formatting[] formattings) throws RenderingException, XSLTException;
+ protected void process(FormatPlan[] formatPlans) throws JDocBookProcessException {
+ }
+ protected void doExecute() throws JDocBookProcessException {
+ process( determineFormatPlans() );
+ }
+
public final void execute() throws MojoExecutionException, MojoFailureException {
if ( options == null ) {
options = new Options();
}
+ options.setLog( new MavenLogBridge() );
+
+ if ( translationBaseDirectory == null ) {
+ translationBaseDirectory = sourceDirectory;
+ }
+
+ if ( translations != null && translations.length != 0 ) {
+ if ( relativeMasterTranslationPath == null || "".equals( relativeMasterTranslationPath ) ) {
+ // see if we have a directory named according to the master translation within the sourceDorectory...
+ File test = new File( sourceDirectory, masterTranslation );
+ if ( test.exists() ) {
+ relativeMasterTranslationPath = masterTranslation;
+ }
+ }
+ }
+ resolvedMasterSourceDirectory = sourceDirectory;
+ if ( relativeMasterTranslationPath != null && !"".equals( relativeMasterTranslationPath ) ) {
+ resolvedMasterSourceDirectory = new File( resolvedMasterSourceDirectory, relativeMasterTranslationPath );
+ }
+
try {
- process( buildFormattings() );
+ doExecute();
}
catch ( XSLTException e ) {
throw new MojoExecutionException( "XSLT problem", e );
@@ -217,16 +275,39 @@
}
}
- private Formatting[] buildFormattings() {
- Formatting[] formattings = new Formatting[ formats.length ];
+ private FormatPlan[] determineFormatPlans() {
+ FormatPlan[] plans = new FormatPlan[ formats.length ];
for ( int i = 0; i < formats.length; i++ ) {
- formattings[i] = new Formatting( StandardDocBookFormatSpecification.parse( formats[i].getFormatName() ), formats[i] );
+ plans[i] = new FormatPlan( formats[i], StandardDocBookFormatDescriptors.getDescriptor( formats[i].getFormatName() ) );
}
- return formattings;
+ return plans;
}
+ protected MasterTranslationDescriptor getMasterTranslationDescriptor() {
+ return new MasterTranslationDescriptor( parseLocale( masterTranslation ) );
+ }
+
+ protected List<PublishingSource> getPublishingSources() {
+ ArrayList<PublishingSource> descriptors = new ArrayList<PublishingSource>();
+ descriptors.add( getMasterTranslationDescriptor() );
+
+ for ( String locale : translations ) {
+ descriptors.add( new TranslationDescriptor( parseLocale( locale ) ) );
+ }
+
+ return descriptors;
+ }
+
+ protected List<I18nSource> getI18nSources() {
+ ArrayList<I18nSource> descriptors = new ArrayList<I18nSource>();
+ for ( String locale : translations ) {
+ descriptors.add( new TranslationDescriptor( parseLocale( locale ) ) );
+ }
+ return descriptors;
+ }
+
protected static interface ArtifactProcessor {
- public void process(org.apache.maven.artifact.Artifact artifact);
+ public void process(Artifact artifact);
}
protected void processArtifacts(ArtifactProcessor processor) {
@@ -243,9 +324,128 @@
}
private void processArtifacts(ArtifactProcessor processor, Collection artifacts) {
- Iterator itr = artifacts.iterator();
- while ( itr.hasNext() ) {
- processor.process( ( org.apache.maven.artifact.Artifact ) itr.next() );
+ for ( Object artifact : artifacts ) {
+ processor.process( ( Artifact ) artifact );
}
}
+
+ protected Locale parseLocale(String locale) {
+ return LocaleUtils.parse( locale, options.getLocaleSeparator() );
+ }
+
+ protected String stringify(Locale locale) {
+ return LocaleUtils.render( locale, options.getLocaleSeparator() );
+ }
+
+ protected static interface PublishingSource {
+ public Locale getLocale();
+ public File resolveDocumentFile();
+ public File resolvePublishingDirectory();
+ }
+
+ protected static interface I18nSource {
+ public Locale getLocale();
+ public File resolvePoDirectory();
+ public File resolveTranslatedXmlDirectory();
+ }
+
+ protected class MasterTranslationDescriptor implements PublishingSource {
+ private final Locale locale;
+
+ public MasterTranslationDescriptor(Locale locale) {
+ this.locale = locale;
+ }
+
+ public Locale getLocale() {
+ return locale;
+ }
+
+ public File resolveDocumentFile() {
+ return new File( resolvedMasterSourceDirectory, sourceDocumentName );
+ }
+
+ public File resolvePublishingDirectory() {
+ return new File( publishDirectory, stringify( locale ) );
+ }
+ }
+
+ protected class TranslationDescriptor implements PublishingSource, I18nSource {
+ private final Locale locale;
+
+ public TranslationDescriptor(Locale locale) {
+ this.locale = locale;
+ }
+
+ public Locale getLocale() {
+ return locale;
+ }
+
+ public File resolvePoDirectory() {
+ return new File( translationBaseDirectory, stringify( locale ) );
+ }
+
+ public File resolveTranslatedXmlDirectory() {
+ return new File( new File( workDirectory, "xml" ), stringify( locale ) );
+ }
+
+ public File resolveDocumentFile() {
+ return new File( resolveTranslatedXmlDirectory(), sourceDocumentName );
+ }
+
+ public File resolvePublishingDirectory() {
+ return new File( publishDirectory, stringify( locale ) );
+ }
+ }
+
+ private class MavenLogBridge implements Log {
+ public void trace(String message) {
+ getLog().debug( message );
+ }
+
+ public void trace(String message, Object... args) {
+ if ( getLog().isDebugEnabled() ) {
+ getLog().debug( MessageFormat.format( message, args ) );
+ }
+ }
+
+ public void info(String message) {
+ getLog().info( message );
+ }
+
+ public void info(String message, Object... args) {
+ if ( getLog().isInfoEnabled() ) {
+ getLog().info( MessageFormat.format( message, args ) );
+ }
+ }
+
+ public void info(String message, Throwable exception) {
+ getLog().info( message, exception );
+ }
+
+ public void info(String message, Throwable exception, Object... args) {
+ if ( getLog().isInfoEnabled() ) {
+ getLog().info( MessageFormat.format( message, args ), exception );
+ }
+ }
+
+ public void error(String message) {
+ getLog().error( message );
+ }
+
+ public void error(String message, Object... args) {
+ if ( getLog().isErrorEnabled() ) {
+ getLog().error( MessageFormat.format( message, args ) );
+ }
+ }
+
+ public void error(String message, Throwable exception) {
+ getLog().error( message, exception );
+ }
+
+ public void error(String message, Throwable exception, Object... args) {
+ if ( getLog().isErrorEnabled() ) {
+ getLog().error( MessageFormat.format( message, args ), exception );
+ }
+ }
+ }
}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/CleanPoMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/CleanPoMojo.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/CleanPoMojo.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.maven.plugins.jdocbook;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Locale;
+
+import org.jboss.jdocbook.JDocBookProcessException;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * CleanPoMojo implementation
+ *
+ * @goal clean-po
+ * @requiresDependencyResolution
+ *
+ * @author Steve Ebersole
+ */
+public class CleanPoMojo extends AbstractDocBookMojo {
+ protected void doExecute() throws JDocBookProcessException {
+ String requestedTranslation = project.getProperties().getProperty( "jdocbook.po.lang" );
+ Locale requestedLocale = requestedTranslation == null ? null : parseLocale( requestedTranslation );
+
+ for ( I18nSource source : getI18nSources() ) {
+ if ( requestedLocale != null && !requestedLocale.equals( source.getLocale() ) ) {
+ continue;
+ }
+ final File poDirectory = source.resolvePoDirectory();
+ if ( poDirectory.exists() ) {
+ try {
+ FileUtils.cleanDirectory( poDirectory );
+ }
+ catch ( IOException e ) {
+ getLog().warn( "unable to cleanup POT directory [" + poDirectory + "]", e );
+ }
+ }
+ }
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/CleanPotMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/CleanPotMojo.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/CleanPotMojo.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.maven.plugins.jdocbook;
+
+import java.io.IOException;
+
+import org.codehaus.plexus.util.FileUtils;
+import org.jboss.jdocbook.JDocBookProcessException;
+
+/**
+ * Cleanup the POT files.
+ *
+ * @goal clean-pot
+ * @requiresDependencyResolution
+ *
+ * @author Steve Ebersole
+ */
+public class CleanPotMojo extends AbstractDocBookMojo {
+ protected void doExecute() throws JDocBookProcessException {
+ if ( potDirectory.exists() ) {
+ try {
+ FileUtils.cleanDirectory( potDirectory );
+ }
+ catch ( IOException e ) {
+ getLog().warn( "unable to cleanup POT directory [" + potDirectory + "]", e );
+ }
+ }
+ }
+}
Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/Format.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/Format.java 2007-10-30 12:49:06 UTC (rev 16157)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/Format.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -15,66 +15,12 @@
*/
package org.jboss.maven.plugins.jdocbook;
+import org.jboss.jdocbook.render.format.UserFormatConfiguration;
+
/**
- * Represents a user format specification.
+ * Maven non-sense. Simply pulls UserFormatConfiguration into the namespace in regards to plugin config.
*
* @author Steve Ebersole
*/
-public class Format {
- private String formatName;
-
- private String targetFileExtension;
- private String finalName;
- private String stylesheetResource;
- private Boolean imagePathSettingRequired;
- private Boolean imageCopyingRequired;
- private Boolean doingChunking;
-
- public Format() {
- }
-
- public Format(
- String formatName,
- String targetFileExtension,
- String finalName,
- String stylesheetResource,
- Boolean imagePathSettingRequired,
- Boolean imageCopyingRequired,
- Boolean doingChunking) {
- this.formatName = formatName;
- this.targetFileExtension = targetFileExtension;
- this.finalName = finalName;
- this.stylesheetResource = stylesheetResource;
- this.imagePathSettingRequired = imagePathSettingRequired;
- this.imageCopyingRequired = imageCopyingRequired;
- this.doingChunking = doingChunking;
- }
-
- public String getFormatName() {
- return formatName;
- }
-
- public String getTargetFileExtension() {
- return targetFileExtension;
- }
-
- public String getFinalName() {
- return finalName;
- }
-
- public String getStylesheetResource() {
- return stylesheetResource;
- }
-
- public Boolean getImagePathSettingRequired() {
- return imagePathSettingRequired;
- }
-
- public Boolean getImageCopyingRequired() {
- return imageCopyingRequired;
- }
-
- public Boolean getDoingChunking() {
- return doingChunking;
- }
+public class Format extends UserFormatConfiguration {
}
Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/GenerationMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/GenerationMojo.java 2007-10-30 12:49:06 UTC (rev 16157)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/GenerationMojo.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -16,13 +16,15 @@
package org.jboss.maven.plugins.jdocbook;
import java.io.File;
+import java.util.List;
-import org.codehaus.plexus.util.FileUtils;
-import org.jboss.maven.plugins.jdocbook.gen.util.Formatting;
-import org.jboss.maven.plugins.jdocbook.gen.format.FormatHandlerFactory;
-import org.jboss.maven.plugins.jdocbook.gen.RenderingException;
-import org.jboss.maven.plugins.jdocbook.gen.XSLTException;
import org.apache.maven.artifact.Artifact;
+import org.jboss.jdocbook.profile.ProfilerFactory;
+import org.jboss.jdocbook.render.RenderingException;
+import org.jboss.jdocbook.render.format.FormatPlan;
+import org.jboss.jdocbook.render.impl.RendererFactory;
+import org.jboss.jdocbook.util.DocBookProfilingStrategy;
+import org.jboss.jdocbook.xslt.XSLTException;
/**
* This mojo's responsibility within the plugin/packaging is actually performing
@@ -37,19 +39,14 @@
*/
public class GenerationMojo extends AbstractDocBookMojo {
- protected void process(Formatting[] formattings) throws XSLTException, RenderingException {
+ protected void process(FormatPlan[] plans) throws XSLTException, RenderingException {
if ( !sourceDirectory.exists() ) {
getLog().info( "sourceDirectory [" + sourceDirectory.getAbsolutePath() + "] did not exist" );
return;
}
- File source = new File( sourceDirectory, sourceDocumentName );
- if ( !source.exists() ) {
- getLog().info( "source [" + source.getAbsolutePath() + "] did not exist" );
- return;
- }
- if ( !targetDirectory.exists() ) {
- FileUtils.mkdir( targetDirectory.getAbsolutePath() );
+ if ( !workDirectory.exists() ) {
+ workDirectory.mkdirs();
}
if ( options.getDocbookVersion() == null ) {
@@ -69,30 +66,34 @@
);
}
- File fontConfigFile = null;
- if ( fontConfig != null ) {
- getLog().debug( "checking for fontConfig existence [" + fontConfig + "]" );
- if ( stagingDirectory != null ) {
- File tmp = new File( stagingDirectory, fontConfig );
- if ( tmp.exists() ) {
- getLog().info( "using font configuration : " + tmp.getAbsolutePath() );
- fontConfigFile = tmp;
- }
+ RendererFactory rendererFactory = new RendererFactory( options );
+
+ List<PublishingSource> sources = getPublishingSources();
+ for ( PublishingSource source : sources ) {
+ File sourceFile = source.resolveDocumentFile();
+ if ( !sourceFile.exists() ) {
+ getLog().info( "Source document [" + sourceFile.getAbsolutePath() + "] did not exist; skipping" );
+ continue;
}
- }
- FormatHandlerFactory formatHandlerFactory = new FormatHandlerFactory(
- options,
- source,
- targetDirectory,
- stagingDirectory,
- fontConfigFile,
- project,
- getLog()
- );
+ File publishingDirectory = source.resolvePublishingDirectory();
+ if ( !publishingDirectory.exists() ) {
+ publishingDirectory.mkdirs();
+ }
- for ( int i = 0; i < formattings.length; i++ ) {
- formatHandlerFactory.buildFormatHandler( formattings[i] ).render( source );
+ final String lang = stringify( source.getLocale() );
+ options.getTransformerParameters().setProperty( "l10n.gentext.language", lang );
+ options.getTransformerParameters().setProperty( "profile.lang", lang );
+
+ boolean hasBeenProfiled = false;
+ for ( FormatPlan plan : plans ) {
+ if ( plan.getProfiling() == DocBookProfilingStrategy.TWO_PASS && !hasBeenProfiled ) {
+ hasBeenProfiled = true;
+ File profileOutputDir = new File( new File( workDirectory, "profile" ), lang );
+ sourceFile = new ProfilerFactory( profileOutputDir, options ).buildProfiler().applyProfiling( sourceFile );
+ }
+ rendererFactory.buildRenderer( plan.getName() ).render( sourceFile, plan, publishingDirectory, stagingDirectory );
+ }
}
}
Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/Options.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/Options.java 2007-10-30 12:49:06 UTC (rev 16157)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/Options.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -15,64 +15,10 @@
*/
package org.jboss.maven.plugins.jdocbook;
-import java.util.Properties;
-
/**
- * A (detachable) representation of the user configuration.
+ * Maven non-sense. Simply pulls Options into the namespace in regards to plugin config.
*
* @author Steve Ebersole
*/
-public class Options {
- private boolean xincludeSupported;
- private String[] catalogs;
- private String xmlTransformerType;
- private Properties transformerParameters;
- private boolean useRelativeImageUris = true;
- private String docbookVersion;
-
- public Options() {
- }
-
- public Options(
- boolean xincludeSupported,
- String[] catalogs,
- String xmlTransformerType,
- Properties transformerParameters,
- boolean useRelativeImageUris,
- String docBookVersion) {
- this.xincludeSupported = xincludeSupported;
- this.catalogs = catalogs;
- this.xmlTransformerType = xmlTransformerType;
- this.transformerParameters = transformerParameters;
- this.useRelativeImageUris = useRelativeImageUris;
- this.docbookVersion = docBookVersion;
- }
-
- public boolean isXincludeSupported() {
- return xincludeSupported;
- }
-
- public String[] getCatalogs() {
- return catalogs;
- }
-
- public String getXmlTransformerType() {
- return xmlTransformerType;
- }
-
- public Properties getTransformerParameters() {
- return transformerParameters;
- }
-
- public boolean isUseRelativeImageUris() {
- return useRelativeImageUris;
- }
-
- public String getDocbookVersion() {
- return docbookVersion;
- }
-
- void setDocbookVersion(String docbookVersion) {
- this.docbookVersion = docbookVersion;
- }
+public class Options extends org.jboss.jdocbook.Options {
}
Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/PackageMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/PackageMojo.java 2007-10-30 12:49:06 UTC (rev 16157)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/PackageMojo.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -18,11 +18,11 @@
import java.io.File;
import java.io.IOException;
-import org.jboss.maven.plugins.jdocbook.gen.util.Formatting;
-import org.jboss.maven.plugins.jdocbook.gen.RenderingException;
-import org.jboss.maven.plugins.jdocbook.gen.format.FormatHandlerFactory;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.jar.JarArchiver;
+import org.jboss.jdocbook.render.RenderingException;
+import org.jboss.jdocbook.render.format.FormatPlan;
+import org.jboss.jdocbook.xslt.XSLTException;
/**
* This mojo's responsibility within the plugin/packaging is to bundle the
@@ -38,30 +38,25 @@
* @author Steve Ebersole
*/
public class PackageMojo extends AbstractDocBookMojo {
- protected void process(Formatting[] formattings) throws RenderingException {
- File source = new File( sourceDirectory, sourceDocumentName );
- FormatHandlerFactory formatHandlerFactory = new FormatHandlerFactory(
- options,
- source,
- targetDirectory,
- stagingDirectory,
- null,
- project,
- getLog()
- );
-
- File projectArtifactFile = new File( targetDirectory, project.getBuild().getFinalName() + ".war" );
+ /**
+ * {@inheritDoc}
+ */
+ protected void process(FormatPlan[] formatPlans) throws RenderingException, XSLTException {
+ File projectArtifactFile = new File( project.getBuild().getOutputDirectory(), project.getBuild().getFinalName() + ".war" );
JarArchiver archiver = new JarArchiver();
archiver.setDestFile( projectArtifactFile );
+// RendererFactory rendererFactory = new RendererFactory( options );
try {
- for ( int i = 0; i < formattings.length; i++ ) {
- archiver.addDirectory(
- new File( targetDirectory, formattings[i].getFormatName() ),
- formattings[i].getFormatName() + "/"
- );
- if ( attach ) {
- formatHandlerFactory.buildFormatHandler( formattings[i] ).attachOutput( source, projectHelper );
+ for ( PublishingSource source : getPublishingSources() ) {
+ for ( FormatPlan formatPlan : formatPlans ) {
+ archiver.addDirectory(
+ new File( source.resolvePublishingDirectory(), formatPlan.getName() ),
+ formatPlan.getName() + "/"
+ );
+// if ( attach ) {
+// File bundle = rendererFactory.buildRenderer( formatPlan.getName() ).getAttachableBundle( )
+// }
}
}
archiver.createArchive();
Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/ResourceMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/ResourceMojo.java 2007-10-30 12:49:06 UTC (rev 16157)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/ResourceMojo.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -18,16 +18,15 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.UnArchiver;
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
-import org.jboss.maven.plugins.jdocbook.gen.RenderingException;
-import org.jboss.maven.plugins.jdocbook.gen.XSLTException;
-import org.jboss.maven.plugins.jdocbook.gen.util.Formatting;
+import org.jboss.jdocbook.render.RenderingException;
+import org.jboss.jdocbook.render.format.FormatPlan;
+import org.jboss.jdocbook.xslt.XSLTException;
import org.jboss.maven.shared.resource.ResourceDelegate;
/**
@@ -45,7 +44,7 @@
*/
public class ResourceMojo extends AbstractDocBookMojo {
- protected void process(Formatting[] formattings) throws RenderingException, XSLTException {
+ protected void process(FormatPlan[] formattings) throws RenderingException, XSLTException {
// allow project local style artifacts to override imported ones...
processDependencySupportArtifacts( collectDocBookStyleDependentArtifacts() );
processProjectResources();
@@ -60,14 +59,13 @@
if ( cssResource != null ) {
new ResourceDelegate( project, new File( stagingDirectory, "css" ), getLog() ).process( cssResource );
}
-// copySource( fontsDirectory, new File( stagingDirectory, "fonts" ) );
}
// dependency support resources ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- private List collectDocBookStyleDependentArtifacts() {
- final ArrayList rtn = new ArrayList();
+ private List<Artifact> collectDocBookStyleDependentArtifacts() {
+ final ArrayList<Artifact> rtn = new ArrayList<Artifact>();
processArtifacts(
new ArtifactProcessor() {
public void process(Artifact artifact) {
@@ -80,11 +78,9 @@
return rtn;
}
- private void processDependencySupportArtifacts(List artifacts) throws RenderingException {
- Iterator itr = artifacts.iterator();
- while ( itr.hasNext() ) {
- final Artifact supportArtifact = ( Artifact ) itr.next();
- processDependencySupportArtifact( supportArtifact.getFile(), stagingDirectory );
+ private void processDependencySupportArtifacts(List<Artifact> artifacts) throws RenderingException {
+ for ( Artifact artifact : artifacts ) {
+ processDependencySupportArtifact( artifact.getFile(), stagingDirectory );
}
}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/TranslationMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/TranslationMojo.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/TranslationMojo.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.maven.plugins.jdocbook;
+
+import java.util.Locale;
+
+import org.jboss.jdocbook.JDocBookProcessException;
+import org.jboss.jdocbook.i18n.actions.TranslateXmlAction;
+
+/**
+ * Responsible for translating the DocBook source based on the translator's PO files.
+ *
+ * @goal translate
+ * @requiresDependencyResolution
+ *
+ * @author Steve Ebersole
+ */
+public class TranslationMojo extends AbstractDocBookMojo {
+ protected void doExecute() throws JDocBookProcessException {
+ String requestedTranslation = project.getProperties().getProperty( "jdocbook.po.lang" );
+ Locale requestedLocale = requestedTranslation == null ? null : parseLocale( requestedTranslation );
+
+ MasterTranslationDescriptor masterTranslationDescriptor = getMasterTranslationDescriptor();
+
+ for ( I18nSource source : getI18nSources() ) {
+ if ( requestedLocale == null || requestedLocale.equals( source.getLocale() ) ) {
+ getLog().info( "Processing translation [" + stringify( source.getLocale() ) + "]" );
+ new TranslateXmlAction(
+ masterTranslationDescriptor.resolveDocumentFile(),
+ source.resolvePoDirectory(),
+ source.resolveTranslatedXmlDirectory(),
+ options
+ ).perform();
+ }
+ }
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/UpdatePoMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/UpdatePoMojo.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/UpdatePoMojo.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.maven.plugins.jdocbook;
+
+import java.util.List;
+import java.util.Locale;
+
+import org.jboss.jdocbook.JDocBookProcessException;
+import org.jboss.jdocbook.i18n.actions.UpdatePoAction;
+import org.jboss.jdocbook.util.LocaleUtils;
+
+/**
+ * UpdatePoMojo implementationslatable strings from the master translation source into the POT files.
+ *
+ * @goal update-po
+ * @requiresDependencyResolution
+ *
+ * @author Steve Ebersole
+ */
+public class UpdatePoMojo extends AbstractDocBookMojo {
+ protected void doExecute() throws JDocBookProcessException {
+ String requestedTranslation = project.getProperties().getProperty( "jdocbook.po.lang" );
+ Locale translationLocale = requestedTranslation == null ? null : LocaleUtils.parse( requestedTranslation, options.getLocaleSeparator() );
+
+ List<I18nSource> sources = getI18nSources();
+ for ( I18nSource source : sources ) {
+ if ( translationLocale == null || translationLocale.equals( source.getLocale() ) ) {
+ getLog().info( "Updating PO file [" + LocaleUtils.render( source.getLocale(), options.getLocaleSeparator() ) + "]" );
+ new UpdatePoAction( potDirectory, source.resolvePoDirectory(), source.getLocale(), options ).perform();
+ }
+ }
+ }
+}
Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/UpdatePotMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/UpdatePotMojo.java (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/UpdatePotMojo.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2007, Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.jboss.maven.plugins.jdocbook;
+
+import org.jboss.jdocbook.JDocBookProcessException;
+import org.jboss.jdocbook.i18n.actions.UpdatePotAction;
+
+
+/**
+ * Manages pushing translatable strings from the master translation source into the POT files.
+ *
+ * @goal update-pot
+ * @requiresDependencyResolution
+ *
+ * @author Steve Ebersole
+ */
+public class UpdatePotMojo extends AbstractDocBookMojo {
+ protected void doExecute() throws JDocBookProcessException {
+ MasterTranslationDescriptor master = getMasterTranslationDescriptor();
+ new UpdatePotAction( master.resolveDocumentFile(), potDirectory, options ).perform();
+ }
+}
Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/CompositeMavenProjectProperties.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/CompositeMavenProjectProperties.java 2007-10-30 12:49:06 UTC (rev 16157)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/CompositeMavenProjectProperties.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -18,7 +18,6 @@
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;
-import java.util.Iterator;
import java.util.Set;
import java.io.File;
@@ -38,16 +37,14 @@
private final MavenProject project;
private final Map values;
+ @SuppressWarnings("unchecked")
public CompositeMavenProjectProperties(MavenProject project) {
this.project = project;
values = new HashMap( System.getProperties() );
values.putAll( project.getProperties() );
- Iterator itr = project.getBuild().getFilters().iterator();
- while ( itr.hasNext() ) {
- String filtersfile = ( String ) itr.next();
- values.putAll(
- PropertiesHelper.loadPropertyFile( new File( filtersfile ) )
- );
+ for ( Object o : project.getBuild().getFilters() ) {
+ String filtersfile = ( String ) o;
+ values.putAll( PropertiesHelper.loadPropertyFile( new File( filtersfile ) ) );
}
}
Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/PropertiesException.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/PropertiesException.java 2007-10-30 12:49:06 UTC (rev 16157)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/properties/PropertiesException.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -21,6 +21,8 @@
* @author Steve Ebersole
*/
public class PropertiesException extends RuntimeException {
+ private static final long serialVersionUID = 5200535349269107151L;
+
public PropertiesException(String message) {
super( message );
}
Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceDelegate.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceDelegate.java 2007-10-30 12:49:06 UTC (rev 16157)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceDelegate.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -87,8 +87,8 @@
}
public void process(Resource[] resources) throws ResourceException {
- for ( int i = 0; i < resources.length; i++ ) {
- process( resources[i] );
+ for ( Resource resource : resources ) {
+ process( resource );
}
}
@@ -107,11 +107,11 @@
destination.mkdirs();
}
- for ( int i = 0; i < fileNames.length; i++ ) {
+ for ( String fileName : fileNames ) {
if ( resource.isFiltering() ) {
copyFilteredFile(
- new File( resource.getDirectory(), fileNames[i] ),
- new File( destination, fileNames[i] ),
+ new File( resource.getDirectory(), fileName ),
+ new File( destination, fileName ),
null,
getFilterWrappers(),
filterProperties
@@ -119,8 +119,8 @@
}
else {
copyFileIfModified(
- new File( resource.getDirectory(), fileNames[i] ),
- new File( destination, fileNames[i] )
+ new File( resource.getDirectory(), fileName ),
+ new File( destination, fileName )
);
}
}
@@ -143,10 +143,12 @@
return scanner.getIncludedFiles();
}
+ @SuppressWarnings("unchecked")
private String[] determineIncludes(Resource resource) {
return toStringArray( resource.getIncludes(), defaultIncludes );
}
+ @SuppressWarnings("unchecked")
private String[] determineExcludes(Resource resource) {
return toStringArray( resource.getExcludes(), defaultExcludes );
}
@@ -204,8 +206,7 @@
}
Reader reader = fileReader;
- for ( int i = 0; i < wrappers.length; i++ ) {
- FilterWrapper wrapper = wrappers[i];
+ for ( FilterWrapper wrapper : wrappers ) {
reader = wrapper.getReader( reader, filterProperties );
}
@@ -236,12 +237,12 @@
return log;
}
- private static String[] toStringArray(List list, String[] defaultArray) {
+ private static String[] toStringArray(List<String> list, String[] defaultArray) {
if ( list == null || list.isEmpty() ) {
return defaultArray;
}
else {
- return ( String[] ) list.toArray( new String[ list.size() ] );
+ return list.toArray( new String[ list.size() ] );
}
}
}
Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceException.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceException.java 2007-10-30 12:49:06 UTC (rev 16157)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/shared/resource/ResourceException.java 2007-10-30 13:40:37 UTC (rev 16158)
@@ -21,6 +21,8 @@
* @author Steve Ebersole
*/
public class ResourceException extends RuntimeException {
+ private static final long serialVersionUID = -5047838607221369662L;
+
public ResourceException(String message) {
super( message );
}
Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/resources/META-INF/plexus/components.xml
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/resources/META-INF/plexus/components.xml 2007-10-30 12:49:06 UTC (rev 16157)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/resources/META-INF/plexus/components.xml 2007-10-30 13:40:37 UTC (rev 16158)
@@ -19,17 +19,6 @@
</configuration>
</component>
- <!-- Defines the 'diff' reporting goal -->
-
- <component>
- <role>org.apache.maven.reporting.MavenReport</role>
- <role-hint>diff</role-hint>
- <implementation>
- org.jboss.maven.plugins.jdocbook.TranslationDiffReport
- </implementation>
- <instantiation-strategy>per-lookup</instantiation-strategy>
- </component>
-
</components>
</component-set>
\ No newline at end of file
More information about the jboss-svn-commits
mailing list