[jboss-svn-commits] JBL Code SVN: r27035 - in labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin: src/main/java/org/jboss/jdocbook and 4 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Jun 19 14:40:19 EDT 2009


Author: steve.ebersole at jboss.com
Date: 2009-06-19 14:40:18 -0400 (Fri, 19 Jun 2009)
New Revision: 27035

Added:
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/ValueInjection.java
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/Injection.java
Modified:
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/pom.xml
   labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Environment.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/profile/ProfilerImpl.java
   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/util/FileUtils.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/maven/plugins/jdocbook/AbstractDocBookMojo.java
Log:
MPJDOCBOOK-30 - Allow injection of information into docbook sources;
prep 2.2.0 release


Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/pom.xml
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/pom.xml	2009-06-19 16:21:36 UTC (rev 27034)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/pom.xml	2009-06-19 18:40:18 UTC (rev 27035)
@@ -28,7 +28,7 @@
     <parent>
         <groupId>org.jboss</groupId>
         <artifactId>jboss-parent</artifactId>
-        <version>3</version>
+        <version>5-beta-1</version>
     </parent>
 
     <groupId>org.jboss.maven.plugins</groupId>
@@ -122,18 +122,6 @@
         </plugins>
     </reporting>
 
-<!--
-    TEMPORARY!!!!  = see FOP dependencies...
--->
-<repositories>
-    <repository>
-        <id>docx4j</id>
-        <name>docx4j Maven 2 repository</name>
-        <url>http://dev.plutext.org/svn/docx4j/trunk/docx4j/m2</url>
-    </repository>
-</repositories>
-
-
     <dependencies>
         <dependency>
             <!-- DocBook (this is the version used, unless user project imports one...) -->
@@ -154,6 +142,12 @@
             <version>1.0</version>
         </dependency>
 
+        <dependency>
+            <groupId>net.socialchange.doctype</groupId>
+            <artifactId>doctype-changer</artifactId>
+            <version>1.1</version>
+        </dependency>
+
         <!-- XML APIs -->
         <dependency>
             <groupId>xml-resolver</groupId>
@@ -229,36 +223,8 @@
         <dependency>
             <groupId>org.apache.xmlgraphics</groupId>
             <artifactId>fop</artifactId>
-<!--
-            <version>0.95</version>
--->
-            <version>svn-trunk</version>
+            <version>svn-r784789</version>
         </dependency>
-<!--
-<dependency>
-<groupId>docx4j</groupId>
-<artifactId>fop-patched</artifactId>
-<version>0.95.756434</version>
-</dependency>
-
-<dependency>
-<groupId>org.apache.xmlgraphics</groupId>
-<artifactId>xmlgraphics-commons</artifactId>
-<version>1.3.757686</version>
-</dependency>
-
-<dependency>
-<groupId>commons-logging</groupId>
-<artifactId>commons-logging</artifactId>
-<version>1.1.1</version>
-</dependency>
-
-<dependency>
-<groupId>commons-io</groupId>
-<artifactId>commons-io</artifactId>
-<version>1.3.1</version>
-</dependency>
--->
         <dependency>
             <groupId>org.apache.avalon.framework</groupId>
             <artifactId>avalon-framework-impl</artifactId>

Modified: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Environment.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Environment.java	2009-06-19 16:21:36 UTC (rev 27034)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Environment.java	2009-06-19 18:40:18 UTC (rev 27035)
@@ -25,6 +25,7 @@
 
 import java.net.URL;
 import java.io.File;
+import java.util.List;
 
 import org.jboss.jdocbook.xslt.TransformerBuilder;
 import org.jboss.jdocbook.util.ResourceHelper;
@@ -52,6 +53,8 @@
 	 */
 	public Options getOptions();
 
+	public List<ValueInjection> getValueInjections();
+
 	/**
 	 * Get the transformer builder for this environment..
 	 *

Modified: 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	2009-06-19 16:21:36 UTC (rev 27034)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/Options.java	2009-06-19 18:40:18 UTC (rev 27035)
@@ -33,6 +33,8 @@
  * @author Steve Ebersole
  */
 public class Options {
+	public static final String DEFAULT_STANDARD_DATE_INJECTION_FORMAT = "MMMM d, yyyy";
+
     private boolean xincludeSupported;
 	private String[] catalogs;
 	private String xmlTransformerType;
@@ -42,6 +44,8 @@
 	private char localeSeparator = '-';
 	private boolean autoDetectFonts;
 	private boolean useFopFontCache = true;
+	private boolean applyStandardInjectionValues = true;
+	private String injectionDateFormat;
 
 	protected Options() {
 	}
@@ -123,4 +127,22 @@
 	public void setUseFopFontCache(boolean useFopFontCache) {
 		this.useFopFontCache = useFopFontCache;
 	}
+
+	public boolean isApplyStandardInjectionValues() {
+		return applyStandardInjectionValues;
+	}
+
+	public void setApplyStandardInjectionValues(boolean applyStandardInjectionValues) {
+		this.applyStandardInjectionValues = applyStandardInjectionValues;
+	}
+
+	public String getInjectionDateFormat() {
+		return injectionDateFormat == null
+				? DEFAULT_STANDARD_DATE_INJECTION_FORMAT
+				: injectionDateFormat;
+	}
+
+	public void setInjectionDateFormat(String injectionDateFormat) {
+		this.injectionDateFormat = injectionDateFormat;
+	}
 }
\ No newline at end of file

Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/ValueInjection.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/ValueInjection.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/ValueInjection.java	2009-06-19 18:40:18 UTC (rev 27035)
@@ -0,0 +1,58 @@
+/*
+ * jDocBook, processing of DocBook sources as a Maven plugin
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.jboss.jdocbook;
+
+/**
+ * Models an injected value which needs to be made available to the DocBook source.
+ *
+ * @author Steve Ebersole
+ */
+public class ValueInjection {
+	private String name;
+	private String value;
+
+	public ValueInjection() {
+	}
+
+	public ValueInjection(String name, String value) {
+		this.name = name;
+		this.value = value;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getValue() {
+		return value;
+	}
+
+	public void setValue(String value) {
+		this.value = value;
+	}
+}

Modified: 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	2009-06-19 16:21:36 UTC (rev 27034)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/profile/ProfilerImpl.java	2009-06-19 18:40:18 UTC (rev 27035)
@@ -95,7 +95,8 @@
 		return FileUtils.createSAXSource(
 				sourceFile,
 				environment.getCatalogResolver(),
-				environment.getOptions().isXincludeSupported()
+				environment.getOptions().isXincludeSupported(),
+				environment.getValueInjections()
 		);
 	}
 

Modified: 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	2009-06-19 16:21:36 UTC (rev 27034)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/render/impl/BasicRenderer.java	2009-06-19 18:40:18 UTC (rev 27035)
@@ -228,7 +228,16 @@
 	}
 
 	protected Source buildSource(File sourceFile) throws RenderingException {
-		return FileUtils.createSAXSource( sourceFile, entityResolver, environment.getOptions().isXincludeSupported() );
+		// IMPL NOTE : if profiling is enabled, we do not need to perform the value injections
+		//		here because they were already applied during profiling...
+		return FileUtils.createSAXSource(
+				sourceFile,
+				entityResolver,
+				environment.getOptions().isXincludeSupported(),
+				environment.getProfilingConfiguration().isEnabled()
+						? null
+						: environment.getValueInjections()
+		);
     }
 
 	protected Result buildResult(File targetFile) throws RenderingException, XSLTException {

Modified: 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	2009-06-19 16:21:36 UTC (rev 27034)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/FileUtils.java	2009-06-19 18:40:18 UTC (rev 27035)
@@ -28,17 +28,24 @@
 import java.io.FileFilter;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.InputStream;
 import java.net.MalformedURLException;
+import java.util.List;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParserFactory;
 import javax.xml.transform.sax.SAXSource;
 
 import org.apache.xerces.jaxp.SAXParserFactoryImpl;
 import org.jboss.jdocbook.JDocBookProcessException;
+import org.jboss.jdocbook.ValueInjection;
 import org.xml.sax.EntityResolver;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
+import net.socialchange.doctype.DoctypeChangerStream;
+import net.socialchange.doctype.DoctypeGenerator;
+import net.socialchange.doctype.Doctype;
+import net.socialchange.doctype.DoctypeImpl;
 
 /**
  * Various {@link java.io.File file} and {@link java.io.File directory} related utilities.
@@ -66,16 +73,21 @@
 	 * @param file The file from which to generate a SAXSource
 	 * @param resolver An entity resolver to apply to the file reader.
 	 * @param xincludeAware Should we handle XIncludes?
+	 * @param valueInjections The values to be injected
 	 *
 	 * @return An appropriate SAXSource
 	 */
 	public static SAXSource createSAXSource(
 			File file,
 			EntityResolver resolver,
-			boolean xincludeAware) {
+			boolean xincludeAware,
+			final List<ValueInjection> valueInjections) {
 		try {
+			final boolean injectionsDefined = valueInjections != null && ! valueInjections.isEmpty();
+
         	SAXParserFactory factory = new SAXParserFactoryImpl();
         	factory.setXIncludeAware( xincludeAware  );
+
 			XMLReader reader = factory.newSAXParser().getXMLReader();
 			reader.setEntityResolver( resolver );
 
@@ -84,7 +96,28 @@
 			reader.setFeature( Constants.DTD_VALIDATION_FEATURE, false );
 
 			try {
-				InputSource source = new InputSource( new BufferedInputStream( new FileInputStream( file ) ) );
+				InputStream inputStream = new BufferedInputStream( new FileInputStream( file ) );
+				if ( injectionsDefined ) {
+					DoctypeChangerStream changerStream = new DoctypeChangerStream( inputStream );
+					changerStream.setGenerator(
+							new DoctypeGenerator() {
+								public Doctype generate(final Doctype doctype) {
+									final String root = doctype == null ? null : doctype.getRootElement();
+									final String pubId = doctype == null ? null : doctype.getPublicId();
+									final String sysId = doctype == null ? null : doctype.getSystemId();
+
+									StringBuffer internalSubset = new StringBuffer();
+									buildInjectedInternalEntitySubset( internalSubset, valueInjections );
+									if ( doctype != null && doctype.getInternalSubset() != null ) {
+										internalSubset.append( doctype.getInternalSubset() ).append( '\n' );
+									}
+									return new DoctypeImpl( root, pubId, sysId, internalSubset.toString() );
+								}
+							}
+					);
+					inputStream = changerStream;
+				}
+				InputSource source = new InputSource( inputStream );
 				source.setSystemId( file.toURI().toURL().toString() );
 				return new SAXSource( reader, source );
 			}
@@ -206,4 +239,15 @@
 	public static String resolveFullPathName(File path) {
 		return path.getAbsolutePath();
 	}
+
+	private static void buildInjectedInternalEntitySubset(StringBuffer buffer, List<ValueInjection> valueInjections) {
+		for ( ValueInjection injection : valueInjections ) {
+			buffer.append( "<!ENTITY " )
+					.append( injection.getName() )
+					.append( " \"" )
+					.append( injection.getValue() )
+					.append( "\">\n" );
+		}
+	}
+
 }

Modified: 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	2009-06-19 16:21:36 UTC (rev 27034)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/jdocbook/util/XIncludeHelper.java	2009-06-19 18:40:18 UTC (rev 27035)
@@ -76,7 +76,7 @@
 			SAXParserFactory parserFactory = new SAXParserFactoryImpl();
     	    parserFactory.setXIncludeAware( true  );
 
-			Source transformationSource = FileUtils.createSAXSource( root, entityResolver, true );
+			Source transformationSource = FileUtils.createSAXSource( root, entityResolver, true, null );
 			Result transformationResult = new StreamResult( new NoOpWriter() );
 
 			javax.xml.transform.TransformerFactory transformerFactory = new com.icl.saxon.TransformerFactoryImpl();

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	2009-06-19 16:21:36 UTC (rev 27034)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/AbstractDocBookMojo.java	2009-06-19 18:40:18 UTC (rev 27035)
@@ -27,11 +27,14 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.text.MessageFormat;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 import java.util.Set;
+import java.util.Arrays;
+import java.util.Date;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
@@ -56,6 +59,7 @@
 import org.codehaus.plexus.archiver.manager.ArchiverManager;
 import org.jboss.jdocbook.JDocBookProcessException;
 import org.jboss.jdocbook.Log;
+import org.jboss.jdocbook.ValueInjection;
 import org.jboss.jdocbook.i18n.Factory;
 import org.jboss.jdocbook.i18n.I18nEnvironment;
 import org.jboss.jdocbook.i18n.I18nSource;
@@ -258,7 +262,15 @@
 	 */
 	protected Options options;
 
+	/**
+	 * The injection entities.
+	 *
+     * @parameter
+	 */
+	protected Injection[] injections;
 
+
+
 	// translation-specific config setting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 	/**
@@ -468,6 +480,23 @@
 		return options;
 	}
 
+	private List<ValueInjection> valueInjections;
+
+	public List<ValueInjection> getValueInjections() {
+		if ( valueInjections == null ) {
+			valueInjections = new ArrayList<ValueInjection>();
+			if ( injections != null ) {
+				valueInjections.addAll( Arrays.asList( injections ) );
+			}
+			if ( options.isApplyStandardInjectionValues() ) {
+				valueInjections.add( new ValueInjection( "version", project.getVersion() ) );
+				SimpleDateFormat dateFormat = new SimpleDateFormat( options.getInjectionDateFormat() );
+				valueInjections.add( new ValueInjection( "today", dateFormat.format( new Date() ) ) );
+			}
+		}
+		return valueInjections;
+	}
+
 	private TransformerBuilder transformerBuilder;
 
 	public TransformerBuilder getTransformerBuilder() {

Added: labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/Injection.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/Injection.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jdocbook-plugin/src/main/java/org/jboss/maven/plugins/jdocbook/Injection.java	2009-06-19 18:40:18 UTC (rev 27035)
@@ -0,0 +1,34 @@
+/*
+ * jDocBook, processing of DocBook sources as a Maven plugin
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors.  All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * 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, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA  02110-1301  USA
+ */
+package org.jboss.maven.plugins.jdocbook;
+
+import org.jboss.jdocbook.ValueInjection;
+
+/**
+ * Maven non-sense.  Simply pulls {@link ValueInjection} into the namespace in regards to plugin config.
+ *
+ * @author Steve Ebersole
+ */
+public class Injection extends ValueInjection {
+}




More information about the jboss-svn-commits mailing list