[hibernate-commits] Hibernate SVN: r11460 - in trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook: gen and 3 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Thu May 3 03:24:48 EDT 2007
Author: steve.ebersole at jboss.com
Date: 2007-05-03 03:24:48 -0400 (Thu, 03 May 2007)
New Revision: 11460
Added:
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Entity.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Format.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/GenerationMojo.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Settings.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Translation.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/Formatter.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/FormatterFactory.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/FormatterSupport.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/HtmlFormatter.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/MainRenderer.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/PdfFormatter.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/RenderingException.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/StandardDocBookFormatType.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/StandardFormatterFactory.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/TranslationRenderer.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/xslt/
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/xslt/ResolverContext.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/xslt/TransformerFactory.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/xslt/TransformerType.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/RevisionDiffMojo.java
Removed:
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Entity.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Format.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/GenerationMojo.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Rendition.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/RevisionDiffMojo.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Translation.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Configuration.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Formatter.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/FormatterFactory.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/FormatterSupport.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/HtmlFormatter.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/PdfFormatter.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Renderer.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/RenderingException.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/StandardFormatterFactory.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/TransformerFactory.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/TransformerType.java
trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Translator.java
Log:
refactoring
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Entity.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Entity.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Entity.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,19 +0,0 @@
-package org.jboss.maven.docbook;
-
-/**
- * {@inheritDoc}
- *
- * @author Steve Ebersole
- */
-public class Entity extends com.agilejava.docbkx.maven.Entity {
-
- public Entity() {
- super();
- }
-
- public Entity(String name, String value) {
- super();
- setName( name );
- setValue( value );
- }
-}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Format.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Format.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Format.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,57 +0,0 @@
-package org.jboss.maven.docbook;
-
-/**
- * {@inheritDoc}
- *
- * @author Steve Ebersole
- */
-public class Format {
- private String type;
- private String stylesheet;
- private boolean styleSheetRelativeToTranslation;
- private boolean chunkedOutput;
- private String formatDirectory; // relative to translationDirectory...
- private String finalName;
-
- public Format() {
- }
-
- public Format(
- String type,
- String stylesheet,
- boolean styleSheetRelativeToTranslation,
- boolean chunkedOutput,
- String formatDirectory,
- String finalName) {
- this.type = type;
- this.stylesheet = stylesheet;
- this.styleSheetRelativeToTranslation = styleSheetRelativeToTranslation;
- this.chunkedOutput = chunkedOutput;
- this.formatDirectory = formatDirectory;
- this.finalName = finalName;
- }
-
- public String getType() {
- return type;
- }
-
- public String getStylesheet() {
- return stylesheet;
- }
-
- public boolean isStyleSheetRelativeToTranslation() {
- return styleSheetRelativeToTranslation;
- }
-
- public boolean isChunkedOutput() {
- return chunkedOutput;
- }
-
- public String getFormatDirectory() {
- return formatDirectory;
- }
-
- public String getFinalName() {
- return finalName;
- }
-}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/GenerationMojo.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/GenerationMojo.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/GenerationMojo.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,194 +0,0 @@
-package org.jboss.maven.docbook;
-
-import java.io.File;
-import java.util.Properties;
-
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.jboss.maven.docbook.gen.Configuration;
-import org.jboss.maven.docbook.gen.Renderer;
-import org.jboss.maven.docbook.gen.RenderingException;
-import org.jboss.maven.docbook.gen.FormatterFactory;
-import org.jboss.maven.docbook.gen.StandardFormatterFactory;
-import org.jboss.maven.docbook.gen.TransformerType;
-
-/**
- * A DocBook plugin based on the excellent docbkx-maven-plugin, but which
- * specifically handles language translations in a more transparent way.
- *
- * @goal generate
- *
- * @author Steve Ebersole
- */
-public class GenerationMojo extends AbstractMojo {
-
- /**
- * The directory where the DocBook sources and translations can be found.
- * <b>This should be a directory containing the different translations as
- * subdirectories</b>.
- *
- * @parameter expression="${basedir}/src/main/docbkx"
- */
- private String sourceDirectory;
-
- /**
- * The name of the DocBook source file, relative to the translation
- * directories.
- *
- * @parameter
- * @required
- */
- private String sourceFile;
-
- /**
- * The directory where the image sources can be found.
- * </p>
- * If relative, it is assumed to be relative to sourceDirectory.
- * </p>
- * This names the directory for images for translations which do
- * not define a custom image source directory.
- *
- * @parameter
- */
- private String imageSourceDirectory;
-
- /**
- * The directory where the output will be written. The renditions and
- * translations will be written to directories relative to this parameter
- * using ${targetDirectory}/${language}/${rendition}/
- *
- * @parameter expression="${basedir}/target/docbkx"
- */
- private String targetDirectory;
-
- /**
- * The directory where image are to be copied.
- * <p/>
- * Unspecified means to perform to copying.
- * <p/>
- * If relative, it is assumed to be relative to the output directory for
- * the current translation
- *
- * @parameter
- */
- private String imageTargetDirectory;
-
- /**
- * The translations to be rendered.
- *
- * @parameter
- * @required
- */
- private Translation[] translations;
-
- /**
- * The formats in which to perform rendering.
- *
- * @parameter
- * @required
- */
- private Format[] formats;
-
- /**
- * The configured entity injections.
- *
- * @parameter
- */
- private Entity[] entities;
-
- /**
- * A boolean, indicating if XInclude should be supported.
- *
- * @parameter default="false"
- */
- private boolean xincludeSupported;
-
- /**
- * The implementation of {@link org.jboss.maven.docbook.gen.FormatterFactory}
- * to use.
- *
- * @parameter
- */
- private String formatterFactoryClassName;
-
- /**
- * Which XML transformation library should be used. Both saxon and xalan
- * are supported. saxon is the default as it is generally more robust;
- * also I have problems trying to run either the hibernate or standard
- * docbook stylesheets through xalan...
- *
- * @parameter default="saxon"
- */
- private String xmlTransformerType;
-
- /**
- * Any parameters (DocBook or custom) to be passed to the XSLT transformer.
- *
- * @parameter
- */
- private Properties transformerParameters;
-
-
- public void execute() throws MojoExecutionException, MojoFailureException {
- Configuration configuration = new Configuration(
- new File( sourceDirectory ),
- sourceFile,
- new File( imageSourceDirectory ),
- new File( targetDirectory ),
- new File( imageTargetDirectory ),
- xincludeSupported,
- entities,
- buildFormatterFactory(),
- TransformerType.parse( xmlTransformerType ),
- transformerParameters,
- getLog()
- );
-
- try {
- new Renderer( configuration ).render( translations, formats );
- }
- catch ( RenderingException e ) {
- throw new MojoExecutionException( "error performing DocBook rendering", e );
- }
- }
-
- private FormatterFactory buildFormatterFactory() throws MojoExecutionException {
- if ( formatterFactoryClassName != null ) {
- Class formatterFactoryClass = locateCustomFormatterFactoryClass();
- try {
- return ( FormatterFactory ) formatterFactoryClass.newInstance();
- }
- catch( ClassCastException cce ) {
- throw new MojoExecutionException( "custom formatter factory [" + formatterFactoryClass + "] did not implement factory interface [" + FormatterFactory.class.getName() + "]" );
- }
- catch ( Throwable t ) {
- throw new MojoExecutionException( "could not instantiate custom formatter factory [" + formatterFactoryClass + "]" );
- }
- }
- else {
- return new StandardFormatterFactory();
- }
- }
-
- private Class locateCustomFormatterFactoryClass() throws MojoExecutionException {
- Class formatterFactoryClass = null;
- try {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if ( cl == null ) {
- cl = getClass().getClassLoader();
- }
- formatterFactoryClass = cl.loadClass( formatterFactoryClassName );
- }
- catch( Throwable t ) {
- try {
- formatterFactoryClass = Class.forName( formatterFactoryClassName );
- }
- catch ( Throwable t2 ) {
- throw new MojoExecutionException( "could not locate custom formatter factory [" + formatterFactoryClass + "]" );
- }
- }
- return formatterFactoryClass;
- }
-
-}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Rendition.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Rendition.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Rendition.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,62 +0,0 @@
-package org.jboss.maven.docbook;
-
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * {@inheritDoc}
- *
- * @author Steve Ebersole
- */
-public class Rendition {
- private String type;
- private String stylesheet;
- private boolean chunkedOutput;
- private String renditionDirectory;
- private String fileExtension;
- private Map finalNameMap = new HashMap();
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getStylesheet() {
- return stylesheet;
- }
-
- public void setStylesheet(String stylesheet) {
- this.stylesheet = stylesheet;
- }
-
- public boolean isChunkedOutput() {
- return chunkedOutput;
- }
-
- public void setChunkedOutput(boolean chunkedOutput) {
- this.chunkedOutput = chunkedOutput;
- }
-
- public String getRenditionDirectory() {
- return renditionDirectory;
- }
-
- public void setRenditionDirectory(String renditionDirectory) {
- this.renditionDirectory = renditionDirectory;
- }
-
- public String getFileExtension() {
- return fileExtension;
- }
-
- public void setFileExtension(String fileExtension) {
- this.fileExtension = fileExtension;
- }
-
- public Map getFinalNameMap() {
- return finalNameMap;
- }
-}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/RevisionDiffMojo.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/RevisionDiffMojo.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/RevisionDiffMojo.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,101 +0,0 @@
-package org.jboss.maven.docbook;
-
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Properties;
-import java.io.IOException;
-
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.xerces.parsers.SAXParser;
-import org.xml.sax.XMLReader;
-import org.xml.sax.SAXNotSupportedException;
-import org.xml.sax.SAXNotRecognizedException;
-import org.jboss.maven.docbook.revdiff.ModuleElementsExtractor;
-import org.jboss.maven.docbook.revdiff.ModuleElementsComparator;
-import org.jboss.maven.docbook.revdiff.ModuleReportHTML;
-import org.jboss.maven.docbook.revdiff.ModuleReport;
-
-/**
- * A plugin for generating a "revision diff" report across different
- * translations of the same document. This is useful for the translators to
- * know what changes exist between their translation and another.
- *
- * @goal revision-diff
- *
- * @author Christian Bauer
- * @author Steve Ebersole
- */
-public class RevisionDiffMojo extends AbstractMojo {
- /**
- * The translation against which to baseline the diff.
- *
- * @parameter
- * @required
- */
- private String original;
-
- /**
- * The translation to be compared to the master.
- *
- * @parameter
- * @required
- */
- private String copy;
-
- /**
- * The file where the diff report should be written.
- *
- * @parameter default="${build.outputDirectory}/docbkx/revdiff
- * @required
- */
- private String reportFile;
-
- public void execute() throws MojoExecutionException, MojoFailureException {
- Set moduleElements = new HashSet();
- XMLReader parser = generateParser();
- try {
- // Parse original file
- parser.setContentHandler( new ModuleElementsExtractor( moduleElements ) );
- parser.parse( original );
-
- // Parse copy
- parser.setContentHandler( new ModuleElementsComparator( moduleElements ) );
- parser.parse( copy );
-
- // Set properties for HTML report
- Properties props = new Properties();
- props.setProperty( ModuleReportHTML.DESTINATION_FILE, reportFile );
-
- // Generate HTML report
- ModuleReport report = new ModuleReportHTML();
- report.runReport( moduleElements, props );
- }
- catch ( IOException e ) {
- throw new MojoExecutionException( "Files not found : " + original + " or " + copy, e );
-
- }
- catch ( Exception e ) {
- throw new MojoExecutionException( "unable to run revdiff report", e );
- }
-
- }
-
- private XMLReader generateParser() throws MojoExecutionException {
- try {
- SAXParser parser = new SAXParser();
- // Disable validation against DTD
- parser.setFeature( "http://xml.org/sax/features/validation", false );
- // Disable DTD loading in Xerces
- parser.setFeature( "http://apache.org/xml/features/nonvalidating/load-external-dtd", false );
- return parser;
- }
- catch ( SAXNotSupportedException e ) {
- throw new MojoExecutionException( "unable to generate SAX Parser", e );
- }
- catch ( SAXNotRecognizedException e ) {
- throw new MojoExecutionException( "unable to generate SAX Parser", e );
- }
- }
-}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Translation.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Translation.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Translation.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,33 +0,0 @@
-package org.jboss.maven.docbook;
-
-/**
- * {@inheritDoc}
- *
- * @author Steve Ebersole
- */
-public class Translation {
- private String language;
- private String stylesheet;
- private String imageSourceDirectory;
-
- public Translation() {
- }
-
- public Translation(String language, String stylesheet, String imageSourceDirectory) {
- this.language = language;
- this.stylesheet = stylesheet;
- this.imageSourceDirectory = imageSourceDirectory;
- }
-
- public String getLanguage() {
- return language;
- }
-
- public String getStylesheet() {
- return stylesheet;
- }
-
- public String getImageSourceDirectory() {
- return imageSourceDirectory;
- }
-}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Configuration.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Configuration.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Configuration.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,90 +0,0 @@
-package org.jboss.maven.docbook.gen;
-
-import java.io.File;
-import java.util.Properties;
-
-import org.jboss.maven.docbook.Entity;
-import org.apache.maven.plugin.logging.Log;
-
-/**
- * {@inheritDoc}
- *
- * @author Steve Ebersole
- */
-public class Configuration {
- private final File sourceDirectory;
- private final String source;
- private final File imageSourceDirectory;
- private final File targetDirectory;
- private final File imageTargetDirectory;
- private boolean xincludeSupported;
- private final Entity[] entities;
- private final FormatterFactory formatterFactory;
- private final TransformerFactory transformerFactory;
- private final Log log;
-
-
- public Configuration(
- File sourceDirectory,
- String source,
- File imageSourceDirectory,
- File targetDirectory,
- File imageTargetDirectory,
- boolean xincludeSupported,
- Entity[] entities,
- FormatterFactory formatterFactory,
- TransformerType transformerType,
- Properties transformerParameters,
- Log log) {
- this.sourceDirectory = sourceDirectory;
- this.source = source;
- this.imageSourceDirectory = imageSourceDirectory;
- this.targetDirectory = targetDirectory;
- this.imageTargetDirectory = imageTargetDirectory;
- this.xincludeSupported = xincludeSupported;
- this.entities = entities;
- this.formatterFactory = formatterFactory;
- this.transformerFactory = new TransformerFactory( transformerType, transformerParameters );
- this.log = log;
- }
-
- public File getSourceDirectory() {
- return sourceDirectory;
- }
-
- public String getSource() {
- return source;
- }
-
- public File getImageSourceDirectory() {
- return imageSourceDirectory;
- }
-
- public File getTargetDirectory() {
- return targetDirectory;
- }
-
- public File getImageTargetDirectory() {
- return imageTargetDirectory;
- }
-
- public boolean isXincludeSupported() {
- return xincludeSupported;
- }
-
- public Entity[] getEntities() {
- return entities;
- }
-
- public FormatterFactory getFormatterFactory() {
- return formatterFactory;
- }
-
- public TransformerFactory getTransformerFactory() {
- return transformerFactory;
- }
-
- public Log getLog() {
- return log;
- }
-}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Entity.java (from rev 11433, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Entity.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Entity.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Entity.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,19 @@
+package org.jboss.maven.docbook.gen;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class Entity extends com.agilejava.docbkx.maven.Entity {
+
+ public Entity() {
+ super();
+ }
+
+ public Entity(String name, String value) {
+ super();
+ setName( name );
+ setValue( value );
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Format.java (from rev 11433, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Format.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Format.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Format.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,52 @@
+package org.jboss.maven.docbook.gen;
+
+import java.util.Map;
+
+/**
+ * Defines a format in which to render DocBook source.
+ *
+ * @author Steve Ebersole
+ */
+public class Format {
+ private String formatName;
+ private String stylesheet;
+ private boolean chunkedOutput;
+ private String relativeFormatDirectory;
+ private Map finalNameMap;
+
+ public Format() {
+ }
+
+ public Format(
+ String formatName,
+ String stylesheet,
+ boolean chunkedOutput,
+ String relativeFormatDirectory,
+ Map finalNameMap) {
+ this.formatName = formatName;
+ this.stylesheet = stylesheet;
+ this.chunkedOutput = chunkedOutput;
+ this.relativeFormatDirectory = relativeFormatDirectory;
+ this.finalNameMap = finalNameMap;
+ }
+
+ public String getFormatName() {
+ return formatName;
+ }
+
+ public String getStylesheet() {
+ return stylesheet;
+ }
+
+ public boolean isChunkedOutput() {
+ return chunkedOutput;
+ }
+
+ public String getRelativeFormatDirectory() {
+ return relativeFormatDirectory;
+ }
+
+ public Map getFinalNameMap() {
+ return finalNameMap;
+ }
+}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Formatter.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Formatter.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Formatter.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,10 +0,0 @@
-package org.jboss.maven.docbook.gen;
-
-/**
- * {@inheritDoc}
- *
- * @author Steve Ebersole
- */
-public interface Formatter {
- public void apply() throws RenderingException;
-}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/FormatterFactory.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/FormatterFactory.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/FormatterFactory.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,12 +0,0 @@
-package org.jboss.maven.docbook.gen;
-
-import org.jboss.maven.docbook.Format;
-
-/**
- * {@inheritDoc}
- *
- * @author Steve Ebersole
- */
-public interface FormatterFactory {
- public Formatter buildFormatter(Translator translator, Format format) throws RenderingException;
-}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/FormatterSupport.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/FormatterSupport.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/FormatterSupport.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,222 +0,0 @@
-package org.jboss.maven.docbook.gen;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.net.MalformedURLException;
-import java.util.Enumeration;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.Source;
-import javax.xml.transform.Result;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.parsers.SAXParserFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.jboss.maven.docbook.Format;
-import org.codehaus.plexus.util.FileUtils;
-import org.apache.xml.resolver.tools.CatalogResolver;
-import org.apache.xml.resolver.CatalogManager;
-import org.apache.maven.plugin.logging.Log;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.XMLReader;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl;
-import com.agilejava.docbkx.maven.InjectingEntityResolver;
-
-/**
- * {@inheritDoc}
- *
- * @author Steve Ebersole
- */
-public abstract class FormatterSupport implements Formatter {
- public static final String DTD_VALIDATION_FEATURE = "http://xml.org/sax/features/validation";
- public static final String DTD_LOADING_FEATURE = "http://apache.org/xml/features/nonvalidating/load-external-dtd";
-
- private final CatalogResolver catalogResolver;
- private final Translator translator;
- private final Format format;
-
- public FormatterSupport(Translator translator, Format format) {
- this.translator = translator;
- this.format = format;
- catalogResolver = new CatalogResolver( createCatalogManager() );
- }
-
- public Translator getTranslator() {
- return translator;
- }
-
- public Format getFormat() {
- return format;
- }
-
- protected Log getLog() {
- return translator.getRenderer().getConfiguration().getLog();
- }
-
- protected abstract String getType();
-
- protected abstract Result buildResult(File taretFile) throws RenderingException;
-
- protected abstract URL getDefaultStylesheetUrl();
-
- protected URL getChunkedStyleSheetUrl() {
- return getDefaultStylesheetUrl();
- }
-
- public final void apply() throws RenderingException {
- getLog().debug( "starting formatting [format=" + format.getType() + ", translation=" + translator.getTranslation() + "]" );
-
- String formatDirectoryName = format.getFormatDirectory() != null
- ? format.getFormatDirectory()
- : getType();
-
- String targetFileName = format.getFinalName() != null
- ? format.getFinalName()
- : FileUtils.basename( translator.getTranslationSource().getAbsolutePath() ) + getType();
-
- File formatTargetDirectory = new File( translator.getTranslationTargetDirectory(), formatDirectoryName );
- if ( !formatTargetDirectory.exists() ) {
- FileUtils.mkdir( formatTargetDirectory.getAbsolutePath() );
- }
- File targetFile = new File( formatTargetDirectory, targetFileName );
- if ( targetFile.exists() ) {
- if ( ! targetFile.delete() ) {
- getLog().warn( "unable to clean up previous output file [" + targetFile.getAbsolutePath() + "]" );
- }
- }
- if ( !targetFile.exists() ) {
- try {
- targetFile.createNewFile();
- }
- catch ( IOException e ) {
- throw new RenderingException( "unable to create output file [" + targetFile.getAbsolutePath() + "]", e );
- }
- }
-
- Transformer transformer = buildTransformer( targetFile );
- Source transformationSource = buildSource( translator.getTranslationSource() );
- Result transformationResult = buildResult( targetFile );
- try {
- transformer.transform( transformationSource, transformationResult );
- }
- catch ( TransformerException e ) {
- throw new RenderingException( "unable to perform transformation", e );
- }
- finally {
- releaseResult( transformationResult );
- }
- }
-
- protected void releaseResult(Result transformationResult) {
- // typically nothing to do...
- }
-
- protected Transformer buildTransformer(File targetFile) throws RenderingException {
- URL docbookStyleSheet = format.isChunkedOutput() ? getChunkedStyleSheetUrl() : getDefaultStylesheetUrl();
- URL xsltStyleSheet = getStylesheetURL();
- File imageDirectory = new File( translator.getTranslationSourceDirectory(), "images" ); // todo : configurable
- return translator.getRenderer().getConfiguration()
- .getTransformerFactory()
- .buildTransformer( docbookStyleSheet, xsltStyleSheet, imageDirectory );
- }
-
- private Source buildSource(File sourceFile) throws RenderingException {
- try {
- EntityResolver resolver = catalogResolver;
- if ( translator.getRenderer().getConfiguration().getEntities() != null ) {
- resolver = new InjectingEntityResolver(
- java.util.Arrays.asList( translator.getRenderer().getConfiguration().getEntities() ),
- resolver,
- format.getType(),
- translator.getRenderer().getConfiguration().getLog()
- );
- }
- SAXParserFactory factory = createParserFactory();
- XMLReader reader = factory.newSAXParser().getXMLReader();
- reader.setEntityResolver( resolver );
-
- // Disable DTD loading and validation
- reader.setFeature( DTD_LOADING_FEATURE, false );
- reader.setFeature( DTD_VALIDATION_FEATURE, false );
-
- 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 URL getStylesheetURL() throws RenderingException {
- if ( format.getStylesheet() != null ) {
- try {
- File styleSheetFile = null;
- if ( format.isStyleSheetRelativeToTranslation() ) {
- styleSheetFile = new File( translator.getTranslationSourceDirectory(), format.getStylesheet() );
- getLog().info( "trying to locate custom xslt stylesheet [" + styleSheetFile.getAbsolutePath() + "]" );
- }
- if ( styleSheetFile == null || !styleSheetFile.exists() ) {
- styleSheetFile = new File( format.getStylesheet() );
- getLog().info( "trying to locate custom xslt stylesheet [" + styleSheetFile.getAbsolutePath() + "]" );
- }
- if ( ! styleSheetFile.exists() ) {
- throw new RenderingException( "unable to locate custom stylesheet [" + format.getStylesheet() + "]" );
- }
- return styleSheetFile.toURL();
- }
- catch ( MalformedURLException e ) {
- throw new RenderingException( "unable to locate custom stylesheet [" + format.getStylesheet() + "]", e );
- }
- }
- else {
- return format.isChunkedOutput()
- ? getChunkedStyleSheetUrl()
- : getDefaultStylesheetUrl();
- }
- }
-
- protected CatalogManager createCatalogManager() {
- CatalogManager manager = new CatalogManager();
- manager.setIgnoreMissingProperties(true);
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- StringBuffer builder = new StringBuffer();
- boolean first = true;
- try {
- Enumeration enumeration = classLoader.getResources( "/catalog.xml" );
- while ( enumeration.hasMoreElements() ) {
- if ( !first ) {
- builder.append( ';' );
- }
- else {
- first = false;
- }
- URL resource = ( URL ) enumeration.nextElement();
- builder.append( resource.toExternalForm() );
- }
- }
- catch ( IOException ioe ) {
- // Let's be a little tolerant here.
- getLog().warn( "Failed to search for catalog files." );
- }
- String catalogFiles = builder.toString();
- if ( catalogFiles.length() == 0 ) {
- getLog().warn( "Failed to find catalog files." );
- }
- else {
- manager.setCatalogFiles( catalogFiles );
- }
- return manager;
- }
-
-
- private SAXParserFactory createParserFactory() {
- SAXParserFactory factory = new SAXParserFactoryImpl();
- factory.setXIncludeAware( translator.getRenderer().getConfiguration().isXincludeSupported() );
- return factory;
- }
-}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/GenerationMojo.java (from rev 11433, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/GenerationMojo.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/GenerationMojo.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/GenerationMojo.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,190 @@
+package org.jboss.maven.docbook.gen;
+
+import java.io.File;
+import java.util.Properties;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.jboss.maven.docbook.gen.Settings;
+import org.jboss.maven.docbook.gen.rendering.MainRenderer;
+import org.jboss.maven.docbook.gen.rendering.RenderingException;
+import org.jboss.maven.docbook.gen.rendering.FormatterFactory;
+import org.jboss.maven.docbook.gen.rendering.StandardFormatterFactory;
+import org.jboss.maven.docbook.gen.xslt.TransformerType;
+import org.jboss.maven.docbook.gen.xslt.TransformerFactory;
+
+/**
+ * A DocBook plugin based on the excellent docbkx-maven-plugin, but which
+ * specifically handles language translations in a more transparent way.
+ *
+ * @goal generate
+ * @phase generate-sources
+ *
+ * @author Steve Ebersole
+ */
+public class GenerationMojo extends AbstractMojo {
+
+ /**
+ * The directory where the DocBook sources and translations can be found.
+ *
+ * @parameter expression="${basedir}/src/main/docbook"
+ */
+ private File sourcesDirectory;
+
+ /**
+ * The directory containing default (i.e. language-agnostic) shared resources.
+ *
+ * @parameter expression="${sourcesDirectory}/standard/resources"
+ */
+ private File standardResourcesDirectory;
+
+ /**
+ * The directory containing the default (i.e. language-agnostic) XSLT stylesheets.
+ *
+ * @parameter expression="${sourcesDirectory}/standard/style"
+ */
+ private File standardStylesheetDirectory;
+
+ /**
+ * The directory containing the translated DocBook sources.
+ *
+ * @parameter expression="${sourcesDirectory}/translations"
+ */
+ private File translationsDirectory;
+
+ /**
+ * Patternsets of sources (relative to translationsDirectory) to include
+ * in formatting.
+ *
+ * @parameter
+ * @required
+ */
+ private String[] sourceIncludes;
+
+ /**
+ * The directory where the output will be written. The formats and
+ * translations will be written to directories relative to this parameter
+ * using ${targetDirectory}/${language}/${format}/
+ *
+ * @parameter expression="${basedir}/target/docbook"
+ */
+ private File targetDirectory;
+
+ /**
+ * The translations to be rendered.
+ *
+ * @parameter
+ * @required
+ */
+ private Translation[] translations;
+
+ /**
+ * The formats in which to perform rendering.
+ *
+ * @parameter
+ * @required
+ */
+ private Format[] formats;
+
+ /**
+ * The configured entity injections.
+ *
+ * @parameter
+ */
+ private Entity[] entities;
+
+ /**
+ * A boolean, indicating if XInclude should be supported.
+ *
+ * @parameter default="false"
+ */
+ private boolean xincludeSupported;
+
+ /**
+ * The implementation of {@link org.jboss.maven.docbook.gen.rendering.FormatterFactory}
+ * to use.
+ *
+ * @parameter
+ */
+ private String formatterFactoryClassName;
+
+ /**
+ * Which XML transformation library should be used. Both saxon and xalan
+ * are supported. saxon is the default as it is generally more robust;
+ * also I have problems trying to run either the hibernate or standard
+ * docbook stylesheets through xalan...
+ *
+ * @parameter default="saxon"
+ */
+ private String xmlTransformerType;
+
+ /**
+ * Any parameters (DocBook or custom) to be passed to the XSLT transformer.
+ *
+ * @parameter
+ */
+ private Properties transformerParameters;
+
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ Settings settings = new Settings(
+ translationsDirectory,
+ sourceIncludes,
+ standardResourcesDirectory,
+ standardStylesheetDirectory,
+ targetDirectory,
+ xincludeSupported,
+ entities,
+ buildFormatterFactory(),
+ new TransformerFactory( TransformerType.parse( xmlTransformerType ), transformerParameters ),
+ getLog()
+ );
+
+ try {
+ new MainRenderer( settings ).render( translations, formats );
+ }
+ catch ( RenderingException e ) {
+ throw new MojoExecutionException( "error performing DocBook rendering", e );
+ }
+ }
+
+ private FormatterFactory buildFormatterFactory() throws MojoExecutionException {
+ if ( formatterFactoryClassName != null ) {
+ Class formatterFactoryClass = locateCustomFormatterFactoryClass();
+ try {
+ return ( FormatterFactory ) formatterFactoryClass.newInstance();
+ }
+ catch( ClassCastException cce ) {
+ throw new MojoExecutionException( "custom formatter factory [" + formatterFactoryClass + "] did not implement factory interface [" + FormatterFactory.class.getName() + "]" );
+ }
+ catch ( Throwable t ) {
+ throw new MojoExecutionException( "could not instantiate custom formatter factory [" + formatterFactoryClass + "]" );
+ }
+ }
+ else {
+ return new StandardFormatterFactory();
+ }
+ }
+
+ private Class locateCustomFormatterFactoryClass() throws MojoExecutionException {
+ Class formatterFactoryClass = null;
+ try {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if ( cl == null ) {
+ cl = getClass().getClassLoader();
+ }
+ formatterFactoryClass = cl.loadClass( formatterFactoryClassName );
+ }
+ catch( Throwable t ) {
+ try {
+ formatterFactoryClass = Class.forName( formatterFactoryClassName );
+ }
+ catch ( Throwable t2 ) {
+ throw new MojoExecutionException( "could not locate custom formatter factory [" + formatterFactoryClass + "]" );
+ }
+ }
+ return formatterFactoryClass;
+ }
+
+}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/HtmlFormatter.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/HtmlFormatter.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/HtmlFormatter.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,53 +0,0 @@
-package org.jboss.maven.docbook.gen;
-
-import java.io.File;
-import java.net.URL;
-import javax.xml.transform.Result;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.stream.StreamResult;
-
-import org.jboss.maven.docbook.Format;
-
-/**
- * {@inheritDoc}
- *
- * @author Steve Ebersole
- */
-public class HtmlFormatter extends FormatterSupport {
- public static final String TYPE = "html";
- public static final String DEF_STYLESHEET = "/META-INF/docbkx/html/docbook.xsl";
- public static final String CHUNK_STYLESHEET = "/META-INF/docbkx/html/chunk.xsl";
-
- public HtmlFormatter(Translator translator, Format format) {
- super( translator, format );
- }
-
- protected String getType() {
- return TYPE;
- }
-
- protected URL getDefaultStylesheetUrl() {
- return this.getClass().getResource( DEF_STYLESHEET );
- }
-
- protected URL getChunkedStyleSheetUrl() {
- return this.getClass().getResource( CHUNK_STYLESHEET );
- }
-
-
- protected Transformer buildTransformer(File targetFile) throws RenderingException {
- Transformer transformer = super.buildTransformer( targetFile );
- if ( getFormat().isChunkedOutput() ) {
- getLog().debug("Chunking output.");
- String rootFilename = targetFile.getName();
- rootFilename = rootFilename.substring(0, rootFilename.lastIndexOf('.'));
- transformer.setParameter("root.filename", rootFilename);
- transformer.setParameter("base.dir", targetFile.getParent() + File.separator);
- }
- return transformer;
- }
-
- protected Result buildResult(File targetFile) throws RenderingException {
- return new StreamResult( targetFile );
- }
-}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/PdfFormatter.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/PdfFormatter.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/PdfFormatter.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,50 +0,0 @@
-package org.jboss.maven.docbook.gen;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.OutputStream;
-import java.net.URL;
-import javax.xml.transform.Result;
-import javax.xml.transform.sax.SAXResult;
-
-import com.agilejava.docbkx.maven.AvalonMavenBridgeLogger;
-import org.apache.fop.apps.Driver;
-import org.jboss.maven.docbook.Format;
-
-/**
- * {@inheritDoc}
- *
- * @author Steve Ebersole
- */
-public class PdfFormatter extends FormatterSupport {
- public static final String TYPE = "pdf";
- public static final String STYLESHEET = "/META-INF/docbkx/fo/docbook.xsl";
-
- public PdfFormatter(Translator translator, Format format) {
- super( translator, format );
- }
-
- protected String getType() {
- return TYPE;
- }
-
- protected URL getDefaultStylesheetUrl() {
- return this.getClass().getResource( STYLESHEET );
- }
-
- protected Result buildResult(File targetFile) throws RenderingException {
- getLog().info( "building formatting result [" + targetFile.getAbsolutePath() + "]" );
- Driver driver = new Driver();
- driver.setLogger( new AvalonMavenBridgeLogger( getLog() ) );
- driver.setRenderer( Driver.RENDER_PDF );
-
- try {
- OutputStream out = new java.io.FileOutputStream( targetFile );
- driver.setOutputStream( out );
- return new SAXResult( driver.getContentHandler() );
- }
- catch ( FileNotFoundException e ) {
- throw new RenderingException( "unable to access target file " + targetFile.getAbsolutePath() );
- }
- }
-}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Renderer.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Renderer.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Renderer.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,42 +0,0 @@
-package org.jboss.maven.docbook.gen;
-
-import org.codehaus.plexus.util.FileUtils;
-import org.jboss.maven.docbook.Format;
-import org.jboss.maven.docbook.Translation;
-import org.apache.maven.plugin.logging.Log;
-
-/**
- * {@inheritDoc}
- *
- * @author Steve Ebersole
- */
-public class Renderer {
-
- private final Configuration configuration;
-
- /*package*/Configuration getConfiguration() {
- return configuration;
- }
-
- public Renderer(Configuration configuration) {
- this.configuration = configuration;
- }
-
- public void render(Translation[] translations, Format[] formats) throws RenderingException {
- if ( ! configuration.getSourceDirectory().exists() ) {
- getLog().info( "sourceDirectory [" + configuration.getSourceDirectory().getAbsolutePath() + "] did not exist" );
- return; // No sources, so there is nothing to render.
- }
- if ( ! configuration.getTargetDirectory().exists() ) {
- FileUtils.mkdir( configuration.getTargetDirectory().getAbsolutePath() );
- }
-
- for ( int i = 0; i < translations.length; i++ ) {
- new Translator( this, translations[i] ).translate( formats );
- }
- }
-
- private Log getLog() {
- return configuration.getLog();
- }
-}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/RenderingException.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/RenderingException.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/RenderingException.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,17 +0,0 @@
-package org.jboss.maven.docbook.gen;
-
-/**
- * {@inheritDoc}
- *
- * @author Steve Ebersole
- */
-public class RenderingException extends Exception {
-
- public RenderingException(String message) {
- super( message );
- }
-
- public RenderingException(String message, Throwable cause) {
- super( message, cause );
- }
-}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Settings.java (from rev 11433, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Configuration.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Settings.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Settings.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,90 @@
+package org.jboss.maven.docbook.gen;
+
+import java.io.File;
+import java.util.List;
+import java.util.Arrays;
+
+import org.jboss.maven.docbook.gen.xslt.TransformerFactory;
+import org.jboss.maven.docbook.gen.rendering.FormatterFactory;
+import org.apache.maven.plugin.logging.Log;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class Settings {
+ private final File translationsDirectory;
+ private final String[] sourceIncludes;
+ private final File standardResourcesDirectory;
+ private final File standardStylesheetDirectory;
+ private final File targetDirectory;
+ private final boolean xincludeSupported;
+ private final List entities;
+ private final FormatterFactory formatterFactory;
+ private final TransformerFactory transformerFactory;
+ private final Log log;
+
+ public Settings(
+ File translationsDirectory,
+ String[] sourceIncludes,
+ File standardResourcesDirectory,
+ File standardStylesheetDirectory,
+ File targetDirectory,
+ boolean xincludeSupported,
+ Entity[] entities,
+ FormatterFactory formatterFactory,
+ TransformerFactory transformerFactory,
+ Log log) {
+ this.translationsDirectory = translationsDirectory;
+ this.sourceIncludes = sourceIncludes;
+ this.standardResourcesDirectory = standardResourcesDirectory;
+ this.standardStylesheetDirectory = standardStylesheetDirectory;
+ this.targetDirectory = targetDirectory;
+ this.xincludeSupported = xincludeSupported;
+ this.entities = Arrays.asList( entities );
+ this.formatterFactory = formatterFactory;
+ this.transformerFactory = transformerFactory;
+ this.log = log;
+ }
+
+ public File getTranslationsDirectory() {
+ return translationsDirectory;
+ }
+
+ public String[] getSourceIncludes() {
+ return sourceIncludes;
+ }
+
+ public File getStandardResourcesDirectory() {
+ return standardResourcesDirectory;
+ }
+
+ public File getStandardStylesheetDirectory() {
+ return standardStylesheetDirectory;
+ }
+
+ public File getTargetDirectory() {
+ return targetDirectory;
+ }
+
+ public boolean isXincludeSupported() {
+ return xincludeSupported;
+ }
+
+ public List getEntities() {
+ return entities;
+ }
+
+ public FormatterFactory getFormatterFactory() {
+ return formatterFactory;
+ }
+
+ public TransformerFactory getTransformerFactory() {
+ return transformerFactory;
+ }
+
+ public Log getLog() {
+ return log;
+ }
+}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/StandardFormatterFactory.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/StandardFormatterFactory.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/StandardFormatterFactory.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,22 +0,0 @@
-package org.jboss.maven.docbook.gen;
-
-import org.jboss.maven.docbook.Format;
-
-/**
- * {@inheritDoc}
- *
- * @author Steve Ebersole
- */
-public class StandardFormatterFactory implements FormatterFactory {
- public Formatter buildFormatter(Translator translator, Format format) throws RenderingException {
- if ( HtmlFormatter.TYPE.equals( format.getType() ) ) {
- return new HtmlFormatter( translator, format );
- }
- else if ( PdfFormatter.TYPE.equals( format.getType() ) ) {
- return new PdfFormatter( translator, format );
- }
- else {
- throw new RenderingException( "unknown format type [" + format.getType() + "]" );
- }
- }
-}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/TransformerFactory.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/TransformerFactory.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/TransformerFactory.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,137 +0,0 @@
-package org.jboss.maven.docbook.gen;
-
-import java.util.Enumeration;
-import java.util.Properties;
-import java.util.Iterator;
-import java.util.Map;
-import java.net.URL;
-import java.io.IOException;
-import java.io.File;
-
-import javax.xml.transform.Transformer;
-import javax.xml.transform.URIResolver;
-import javax.xml.transform.Source;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.stream.StreamSource;
-
-import org.apache.xml.resolver.tools.CatalogResolver;
-import org.apache.xml.resolver.CatalogManager;
-import com.agilejava.docbkx.maven.StylesheetResolver;
-import com.agilejava.docbkx.maven.NullWriter;
-import com.icl.saxon.Controller;
-
-/**
- * A factory for {@link Transformer} instances, configurable to return either
- * SAXON or XALAN based transformers.
- * <p/>
- * Note: the transformers are cached, being reset upon "re acquitions". However,
- * that means that the transformers generated from this class should not be used
- * concurrently.
- *
- * @author Steve Ebersole
- */
-public class TransformerFactory {
- private final CatalogResolver catalogResolver = new CatalogResolver( createCatalogManager() );
-
- private final TransformerType transformerType;
- private final Properties transformerParameters;
-
- public TransformerFactory(TransformerType transformerType, Properties transformerParameters) {
- this.transformerType = transformerType;
- this.transformerParameters = transformerParameters;
- }
-
- public synchronized Transformer buildTransformer(URL docbookStylesheet, URL xsltStylesheet, File imageDirectory) throws RenderingException {
- if ( docbookStylesheet == null ) {
- throw new RenderingException( "docbook stylesheet was null" );
- }
- if ( xsltStylesheet == null ) {
- throw new RenderingException( "xslt stylesheet was null" );
- }
-
- try {
- URIResolver uriResolver = new StylesheetResolver(
- "urn:docbkx:stylesheet",
- new StreamSource( docbookStylesheet.openStream(), docbookStylesheet.toExternalForm() ),
- catalogResolver
- );
- return createTransformer( uriResolver, xsltStylesheet, imageDirectory );
- }
- catch ( IOException ioe) {
- throw new RenderingException( "Failed to read docbook stylesheet.", ioe );
- }
- }
-
- /*package*/ Transformer createTransformer(URIResolver uriResolver, URL xsltStylesheet, File imageDirectory) throws RenderingException {
- if ( xsltStylesheet == null ) {
- throw new RenderingException( "xslt stylesheet was null" );
- }
-
- try {
- javax.xml.transform.TransformerFactory transformerFactory = transformerType == TransformerType.XALAN
- ? new com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl()
- : new com.icl.saxon.TransformerFactoryImpl();
- transformerFactory.setURIResolver( uriResolver );
- Source source = new StreamSource( xsltStylesheet.openStream(), xsltStylesheet.toExternalForm() );
- Transformer transformer = transformerFactory.newTransformer( source );
- transformer.setURIResolver( uriResolver );
- applyParameters( transformer );
- Controller controller = ( Controller ) transformer;
- try {
- controller.makeMessageEmitter();
- controller.getMessageEmitter().setWriter( new NullWriter() );
- }
- catch ( TransformerException te ) {
-// getLog().error( "Failed to redirect xsl:message output.", te );
- }
- return transformer;
- }
- catch ( IOException ioe ) {
- throw new RenderingException( "Failed to read stylesheet from " + xsltStylesheet.toExternalForm(), ioe );
- }
- catch ( TransformerConfigurationException tce ) {
- throw new RenderingException( "Failed to build Transformer from " + xsltStylesheet.toExternalForm(), tce );
- }
- }
-
- private void applyParameters(Transformer transformer) {
- if ( transformerParameters == null ) {
- return;
- }
- Iterator itr = transformerParameters.entrySet().iterator();
- while ( itr.hasNext() ) {
- final Map.Entry entry = ( Map.Entry ) itr.next();
- transformer.setParameter( ( String ) entry.getKey(), entry.getValue() );
- }
- }
-
- /*package*/ CatalogManager createCatalogManager() {
- CatalogManager manager = new CatalogManager();
- manager.setIgnoreMissingProperties(true);
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- StringBuffer builder = new StringBuffer();
- boolean first = true;
- try {
- Enumeration enumeration = classLoader.getResources( "/catalog.xml" );
- while ( enumeration.hasMoreElements() ) {
- if ( !first ) {
- builder.append( ';' );
- }
- else {
- first = false;
- }
- URL resource = ( URL ) enumeration.nextElement();
- builder.append( resource.toExternalForm() );
- }
- }
- catch ( IOException ignore ) {
- // intentionally empty
- }
- String catalogFiles = builder.toString();
- if ( catalogFiles.length() != 0 ) {
- manager.setCatalogFiles( catalogFiles );
- }
- return manager;
- }
-}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/TransformerType.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/TransformerType.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/TransformerType.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,37 +0,0 @@
-package org.jboss.maven.docbook.gen;
-
-/**
- * {@inheritDoc}
- *
- * @author Steve Ebersole
- */
-public class TransformerType {
- public static final TransformerType SAXON = new TransformerType( "saxon", false );
- public static final TransformerType XALAN = new TransformerType( "xalan", true );
-
- private final String name;
- private final boolean supportsReset;
-
- public TransformerType(String name, boolean supportsReset) {
- this.name = name;
- this.supportsReset = supportsReset;
- }
-
- public String getName() {
- return name;
- }
-
- public boolean supportsReset() {
- return supportsReset;
- }
-
- public static TransformerType parse(String name) {
- if ( XALAN.name.equals( name ) ) {
- return XALAN;
- }
- else {
- // default
- return SAXON;
- }
- }
-}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Translation.java (from rev 11433, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/Translation.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Translation.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Translation.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,36 @@
+package org.jboss.maven.docbook.gen;
+
+/**
+ * Defines a particular translation and any translation specific configuration.
+ *
+ * @author Steve Ebersole
+ */
+public class Translation {
+ private String language;
+ private String specializedResourcesDirectory;
+ private String specializedStylesheetDirectory;
+
+ public Translation() {
+ }
+
+ public Translation(
+ String language,
+ String specializedResourcesDirectory,
+ String specializedStylesheetDirectory) {
+ this.language = language;
+ this.specializedResourcesDirectory = specializedResourcesDirectory;
+ this.specializedStylesheetDirectory = specializedStylesheetDirectory;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public String getSpecializedResourcesDirectory() {
+ return specializedResourcesDirectory;
+ }
+
+ public String getSpecializedStylesheetDirectory() {
+ return specializedStylesheetDirectory;
+ }
+}
Deleted: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Translator.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Translator.java 2007-05-02 07:38:01 UTC (rev 11459)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Translator.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -1,75 +0,0 @@
-package org.jboss.maven.docbook.gen;
-
-import java.io.File;
-
-import org.jboss.maven.docbook.Format;
-import org.jboss.maven.docbook.Translation;
-import org.codehaus.plexus.util.FileUtils;
-import org.apache.maven.plugin.logging.Log;
-
-/**
- * {@inheritDoc}
- *
- * @author Steve Ebersole
- */
-public class Translator {
- private final Renderer renderer;
- private final Translation translation;
-
- private final File translationSourceDirectory;
- private final File translationTargetDirectory;
- private final File translationSource;
-
- public Translator(Renderer renderer, Translation translation) {
- this.renderer = renderer;
- this.translation = translation;
-
- this.translationSourceDirectory = new File( renderer.getConfiguration().getSourceDirectory(), translation.getLanguage() );
- this.translationTargetDirectory = new File( renderer.getConfiguration().getTargetDirectory(), translation.getLanguage() );
- this.translationSource = new File( translationSourceDirectory, renderer.getConfiguration().getSource() );
- }
-
- public Renderer getRenderer() {
- return renderer;
- }
-
- public Translation getTranslation() {
- return translation;
- }
-
- public File getTranslationSourceDirectory() {
- return translationSourceDirectory;
- }
-
- public File getTranslationTargetDirectory() {
- return translationTargetDirectory;
- }
-
- public File getTranslationSource() {
- return translationSource;
- }
-
- public void translate(Format[] formats) throws RenderingException {
- getLog().debug( "starting translation : " + translation );
- if ( ! translationSourceDirectory.exists() ) {
- getLog().info( "translation directory [" + translationSourceDirectory.getAbsolutePath() + "did not exist; skipping" );
- return;
- }
- if ( ! translationSource.exists() ) {
- getLog().info( "translation source [" + translationSource.getAbsolutePath() + "did not exist; skipping" );
- return;
- }
- if ( ! translationTargetDirectory.exists() ) {
- FileUtils.mkdir( translationTargetDirectory.getAbsolutePath() );
- }
-
-
- for ( int i = 0; i < formats.length; i++ ) {
- renderer.getConfiguration().getFormatterFactory().buildFormatter( this, formats[i] ).apply();
- }
- }
-
- private Log getLog() {
- return renderer.getConfiguration().getLog();
- }
-}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/Formatter.java (from rev 11433, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Formatter.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/Formatter.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/Formatter.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,12 @@
+package org.jboss.maven.docbook.gen.rendering;
+
+import java.io.File;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public interface Formatter {
+ public void format(File source) throws RenderingException;
+}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/FormatterFactory.java (from rev 11433, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/FormatterFactory.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/FormatterFactory.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/FormatterFactory.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,12 @@
+package org.jboss.maven.docbook.gen.rendering;
+
+import org.jboss.maven.docbook.gen.Format;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public interface FormatterFactory {
+ public Formatter buildFormatter(TranslationRenderer translationRenderer, Format format) throws RenderingException;
+}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/FormatterSupport.java (from rev 11433, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/FormatterSupport.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/FormatterSupport.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/FormatterSupport.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,205 @@
+package org.jboss.maven.docbook.gen.rendering;
+
+import java.io.File;
+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 com.agilejava.docbkx.maven.InjectingEntityResolver;
+import com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl;
+import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.util.FileUtils;
+import org.jboss.maven.docbook.gen.Format;
+import org.jboss.maven.docbook.gen.Settings;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public abstract class FormatterSupport implements Formatter {
+ public static final String DTD_VALIDATION_FEATURE = "http://xml.org/sax/features/validation";
+ public static final String DTD_LOADING_FEATURE = "http://apache.org/xml/features/nonvalidating/load-external-dtd";
+
+ private final TranslationRenderer translationRenderer;
+ private final Format format;
+
+ public FormatterSupport(TranslationRenderer translationRenderer, Format format) {
+ this.translationRenderer = translationRenderer;
+ this.format = format;
+ }
+
+ public TranslationRenderer getTranslator() {
+ return translationRenderer;
+ }
+
+ public Format getFormat() {
+ return format;
+ }
+
+ protected Settings getSettings() {
+ return translationRenderer.getMainRenderer().getSettings();
+ }
+
+ protected Log getLog() {
+ return getSettings().getLog();
+ }
+
+ protected abstract String getType();
+
+ protected abstract Result buildResult(File taretFile) throws RenderingException;
+
+ protected abstract URL getDefaultStylesheetUrl();
+
+ protected URL getChunkedStyleSheetUrl() {
+ return getDefaultStylesheetUrl();
+ }
+
+ public final void format(File source) throws RenderingException {
+ getLog().debug( "starting formatting [format=" + format.getFormatName() + ", translation=" + translationRenderer.getTranslation() + "]" );
+
+ String formatDirectoryName = format.getRelativeFormatDirectory() != null
+ ? format.getRelativeFormatDirectory()
+ : getType();
+
+ String targetFileName = deduceTargetFileName( source );
+
+ File formatTargetDirectory = new File( translationRenderer.getTranslationTargetDirectory(), formatDirectoryName );
+ if ( !formatTargetDirectory.exists() ) {
+ FileUtils.mkdir( formatTargetDirectory.getAbsolutePath() );
+ }
+
+ File targetFile = new File( formatTargetDirectory, targetFileName );
+ if ( targetFile.exists() ) {
+ if ( ! targetFile.delete() ) {
+ getLog().warn( "unable to clean up previous output file [" + targetFile.getAbsolutePath() + "]" );
+ }
+ }
+ if ( !targetFile.exists() ) {
+ try {
+ targetFile.createNewFile();
+ }
+ catch ( IOException e ) {
+ throw new RenderingException( "unable to create output file [" + targetFile.getAbsolutePath() + "]", e );
+ }
+ }
+
+ Transformer transformer = buildTransformer( targetFile );
+ Source transformationSource = buildSource( source );
+ Result transformationResult = buildResult( targetFile );
+ try {
+ transformer.transform( transformationSource, transformationResult );
+ }
+ catch ( TransformerException e ) {
+ throw new RenderingException( "unable to perform transformation", e );
+ }
+ finally {
+ releaseResult( transformationResult );
+ }
+ }
+
+ private String deduceTargetFileName(File source) {
+ if ( format.getFinalNameMap() != null ) {
+ String supplied = ( String ) format.getFinalNameMap().get( source.getName() );
+ if ( supplied != null ) {
+ return supplied;
+ }
+ }
+ return FileUtils.basename( source.getAbsolutePath() ) + getType();
+ }
+
+ protected void releaseResult(Result transformationResult) {
+ // typically nothing to do...
+ }
+
+ protected Transformer buildTransformer(File targetFile) throws RenderingException {
+ final URL docbookStylesheet = format.isChunkedOutput() ? getChunkedStyleSheetUrl() : getDefaultStylesheetUrl();
+ final URL transformationStylesheet = resolveTransformationStylesheet();
+ return getSettings().getTransformerFactory().buildTransformer( docbookStylesheet, transformationStylesheet );
+ }
+
+ private Source buildSource(File sourceFile) throws RenderingException {
+ try {
+ EntityResolver resolver = getSettings().getTransformerFactory().getCatalogResolver();
+ if ( getSettings().getEntities() != null ) {
+ resolver = new InjectingEntityResolver(
+ java.util.Arrays.asList( getSettings().getEntities() ),
+ resolver,
+ format.getFormatName(),
+ translationRenderer.getMainRenderer().getSettings().getLog()
+ );
+ }
+ SAXParserFactory factory = createParserFactory();
+ XMLReader reader = factory.newSAXParser().getXMLReader();
+ reader.setEntityResolver( resolver );
+
+ // Disable DTD loading and validation
+ reader.setFeature( DTD_LOADING_FEATURE, false );
+ reader.setFeature( DTD_VALIDATION_FEATURE, false );
+
+ 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 );
+ }
+ }
+
+ private URL resolveTransformationStylesheet() throws RenderingException {
+ if ( format.getStylesheet() != null ) {
+ try {
+ return resolveCustomTransformationStylesheetFile().toURL();
+ }
+ catch ( MalformedURLException e ) {
+ throw new RenderingException( "unable to locate custom stylesheet [" + format.getStylesheet() + "]", e );
+ }
+ }
+ else {
+ return format.isChunkedOutput() ? getChunkedStyleSheetUrl() : getDefaultStylesheetUrl();
+ }
+ }
+
+ private File resolveCustomTransformationStylesheetFile() throws RenderingException {
+ // the custom stylesheet could be relative to either:
+ // 1) the translation dir
+ // 2) the standard stylesheet dir
+ // #1 takes precedence
+ String translationSpecificStyleDirectoryName = translationRenderer.getTranslation().getSpecializedStylesheetDirectory() == null
+ ? getSettings().getStandardStylesheetDirectory().getName()
+ : translationRenderer.getTranslation().getSpecializedStylesheetDirectory();
+ File translationSpecificStyleDirectory = new File( translationRenderer.getTranslationSourceDirectory(), translationSpecificStyleDirectoryName );
+ if ( translationSpecificStyleDirectory.exists() ) {
+ File stylesheet = new File( translationSpecificStyleDirectory, format.getStylesheet() );
+ if ( stylesheet.exists() ) {
+ return stylesheet;
+ }
+ getLog().info( "translation-specific style directory [" + translationSpecificStyleDirectory.getAbsolutePath() + "] did not contain specified style override [" + format.getStylesheet() + "]" );
+ }
+
+ File stylesheet = new File( translationRenderer.getMainRenderer().getSettings().getStandardStylesheetDirectory(), format.getStylesheet() );
+ if ( stylesheet.exists() ) {
+ return stylesheet;
+ }
+
+ throw new RenderingException( "unable to locate custom stylesheet [" + format.getStylesheet() + "]" );
+ }
+
+ private SAXParserFactory createParserFactory() {
+ SAXParserFactory factory = new SAXParserFactoryImpl();
+ factory.setXIncludeAware( translationRenderer.getMainRenderer().getSettings().isXincludeSupported() );
+ return factory;
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/HtmlFormatter.java (from rev 11433, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/HtmlFormatter.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/HtmlFormatter.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/HtmlFormatter.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,50 @@
+package org.jboss.maven.docbook.gen.rendering;
+
+import java.io.File;
+import java.net.URL;
+import javax.xml.transform.Result;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.stream.StreamResult;
+
+import org.jboss.maven.docbook.gen.Format;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class HtmlFormatter extends FormatterSupport {
+
+ public HtmlFormatter(TranslationRenderer translationRenderer, Format format) {
+ super( translationRenderer, format );
+ }
+
+ protected String getType() {
+ return StandardDocBookFormatType.HTML.getName();
+ }
+
+ protected URL getDefaultStylesheetUrl() {
+ return this.getClass().getResource( StandardDocBookFormatType.HTML.getNormalStylesheet() );
+ }
+
+ protected URL getChunkedStyleSheetUrl() {
+ return this.getClass().getResource( StandardDocBookFormatType.HTML.getChunkedStylesheet() );
+ }
+
+
+ protected Transformer buildTransformer(File targetFile) throws RenderingException {
+ Transformer transformer = super.buildTransformer( targetFile );
+ if ( getFormat().isChunkedOutput() ) {
+ getLog().debug("Chunking output.");
+ String rootFilename = targetFile.getName();
+ rootFilename = rootFilename.substring(0, rootFilename.lastIndexOf('.'));
+ transformer.setParameter("root.filename", rootFilename);
+ transformer.setParameter("base.dir", targetFile.getParent() + File.separator);
+ }
+ return transformer;
+ }
+
+ protected Result buildResult(File targetFile) throws RenderingException {
+ return new StreamResult( targetFile );
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/MainRenderer.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/MainRenderer.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/MainRenderer.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,45 @@
+package org.jboss.maven.docbook.gen.rendering;
+
+import org.codehaus.plexus.util.FileUtils;
+import org.jboss.maven.docbook.gen.Format;
+import org.jboss.maven.docbook.gen.Translation;
+import org.jboss.maven.docbook.gen.Settings;
+import org.apache.maven.plugin.logging.Log;
+
+/**
+ * Coordinates rendering of DocBook sources in the requested translations and
+ * formats.
+ *
+ * @author Steve Ebersole
+ */
+public class MainRenderer {
+
+ private final Settings settings;
+
+ /*package*/Settings getSettings() {
+ return settings;
+ }
+
+ public MainRenderer(Settings settings) {
+ this.settings = settings;
+ }
+
+ public void render(Translation[] translations, Format[] formats) throws RenderingException {
+ if ( ! settings.getTranslationsDirectory().exists() ) {
+ getLog().info( "translationsDirectory [" + settings.getTranslationsDirectory().getAbsolutePath() + "] did not exist" );
+ return; // No sources, so there is nothing to render.
+ }
+ if ( ! settings.getTargetDirectory().exists() ) {
+ FileUtils.mkdir( settings.getTargetDirectory().getAbsolutePath() );
+ }
+
+ // for each requested translation, delegate to the TranslationRenderer
+ for ( int i = 0; i < translations.length; i++ ) {
+ new TranslationRenderer( this, translations[i] ).translate( formats );
+ }
+ }
+
+ private Log getLog() {
+ return settings.getLog();
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/PdfFormatter.java (from rev 11433, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/PdfFormatter.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/PdfFormatter.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/PdfFormatter.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,48 @@
+package org.jboss.maven.docbook.gen.rendering;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.OutputStream;
+import java.net.URL;
+import javax.xml.transform.Result;
+import javax.xml.transform.sax.SAXResult;
+
+import com.agilejava.docbkx.maven.AvalonMavenBridgeLogger;
+import org.apache.fop.apps.Driver;
+import org.jboss.maven.docbook.gen.Format;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class PdfFormatter extends FormatterSupport {
+
+ public PdfFormatter(TranslationRenderer translationRenderer, Format format) {
+ super( translationRenderer, format );
+ }
+
+ protected String getType() {
+ return StandardDocBookFormatType.PDF.getName();
+ }
+
+ protected URL getDefaultStylesheetUrl() {
+ return this.getClass().getResource( StandardDocBookFormatType.PDF.getNormalStylesheet() );
+ }
+
+ protected Result buildResult(File targetFile) throws RenderingException {
+ getLog().info( "building formatting result [" + targetFile.getAbsolutePath() + "]" );
+ Driver driver = new Driver();
+ driver.setLogger( new AvalonMavenBridgeLogger( getLog() ) );
+ driver.setRenderer( Driver.RENDER_PDF );
+
+ try {
+ OutputStream out = new java.io.FileOutputStream( targetFile );
+ driver.setOutputStream( out );
+ return new SAXResult( driver.getContentHandler() );
+ }
+ catch ( FileNotFoundException e ) {
+ throw new RenderingException( "unable to access target file " + targetFile.getAbsolutePath() );
+ }
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/RenderingException.java (from rev 11433, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/RenderingException.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/RenderingException.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/RenderingException.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,17 @@
+package org.jboss.maven.docbook.gen.rendering;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class RenderingException extends Exception {
+
+ public RenderingException(String message) {
+ super( message );
+ }
+
+ public RenderingException(String message, Throwable cause) {
+ super( message, cause );
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/StandardDocBookFormatType.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/StandardDocBookFormatType.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/StandardDocBookFormatType.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,49 @@
+package org.jboss.maven.docbook.gen.rendering;
+
+/**
+ * Enum of DocBook formats given special meaning/attention
+ *
+ * @author Steve Ebersole
+ */
+public class StandardDocBookFormatType {
+ public static final StandardDocBookFormatType HTML = new StandardDocBookFormatType( "html", "/META-INF/docbkx/html/docbook.xsl", "/META-INF/docbkx/html/chunk.xsl" );
+ public static final StandardDocBookFormatType PDF = new StandardDocBookFormatType( "pdf", "/META-INF/docbkx/fo/docbook.xsl", "/META-INF/docbkx/fo/docbook.xsl" );
+
+ private final String name;
+ private final String normalStylesheet;
+ private final String chunkedStylesheet;
+
+ public StandardDocBookFormatType(String name, String normalStylesheet, String chunkedStylesheet) {
+ this.name = name;
+ this.normalStylesheet = normalStylesheet;
+ this.chunkedStylesheet = chunkedStylesheet;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getNormalStylesheet() {
+ return normalStylesheet;
+ }
+
+ public String getChunkedStylesheet() {
+ return chunkedStylesheet;
+ }
+
+ public String getCommonFileExtension() {
+ return name;
+ }
+
+ public static StandardDocBookFormatType parse(String name) throws RenderingException {
+ if ( HTML.name.equals( name ) ) {
+ return HTML;
+ }
+ else if ( PDF.name.equals( name ) ) {
+ return PDF;
+ }
+ else {
+ throw new RenderingException( "unknown format type [" + name + "]" );
+ }
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/StandardFormatterFactory.java (from rev 11433, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/StandardFormatterFactory.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/StandardFormatterFactory.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/StandardFormatterFactory.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,22 @@
+package org.jboss.maven.docbook.gen.rendering;
+
+import org.jboss.maven.docbook.gen.Format;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class StandardFormatterFactory implements FormatterFactory {
+ public Formatter buildFormatter(TranslationRenderer translationRenderer, Format format) throws RenderingException {
+ if ( StandardDocBookFormatType.HTML.getName().equals( format.getFormatName() ) ) {
+ return new HtmlFormatter( translationRenderer, format );
+ }
+ else if ( StandardDocBookFormatType.PDF.getName().equals( format.getFormatName() ) ) {
+ return new PdfFormatter( translationRenderer, format );
+ }
+ else {
+ throw new RenderingException( "unknown format type [" + format.getFormatName() + "]" );
+ }
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/TranslationRenderer.java (from rev 11433, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/Translator.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/TranslationRenderer.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/rendering/TranslationRenderer.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,106 @@
+package org.jboss.maven.docbook.gen.rendering;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.jboss.maven.docbook.gen.Format;
+import org.jboss.maven.docbook.gen.Translation;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.apache.maven.plugin.logging.Log;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class TranslationRenderer {
+ private final MainRenderer mainRenderer;
+ private final Translation translation;
+
+ private final File translationSourceDirectory;
+ private final File translationTargetDirectory;
+
+ public TranslationRenderer(MainRenderer mainRenderer, Translation translation) {
+ this.mainRenderer = mainRenderer;
+ this.translation = translation;
+
+ this.translationSourceDirectory = new File( mainRenderer.getSettings().getTranslationsDirectory(), translation.getLanguage() );
+ this.translationTargetDirectory = new File( mainRenderer.getSettings().getTargetDirectory(), translation.getLanguage() );
+ }
+
+ public MainRenderer getMainRenderer() {
+ return mainRenderer;
+ }
+
+ public Translation getTranslation() {
+ return translation;
+ }
+
+ public File getTranslationSourceDirectory() {
+ return translationSourceDirectory;
+ }
+
+ public File getTranslationTargetDirectory() {
+ return translationTargetDirectory;
+ }
+
+ public void translate(Format[] formats) throws RenderingException {
+ getLog().debug( "starting translation : " + translation );
+ if ( ! translationSourceDirectory.exists() ) {
+ getLog().info( "translation directory [" + translationSourceDirectory.getAbsolutePath() + "did not exist; skipping" );
+ return;
+ }
+
+ DirectoryScanner scanner = new DirectoryScanner();
+ scanner.setBasedir( translationSourceDirectory );
+ scanner.setIncludes( mainRenderer.getSettings().getSourceIncludes() );
+ scanner.scan();
+ String[] matched = scanner.getIncludedFiles();
+
+ if ( matched == null || matched.length == 0 ) {
+ getLog().info( "translation directory [" + translationSourceDirectory.getAbsolutePath() + "contained no included sources; skipping" );
+ return;
+ }
+
+ if ( ! translationTargetDirectory.exists() ) {
+ FileUtils.mkdir( translationTargetDirectory.getAbsolutePath() );
+ }
+
+ copyResources();
+
+ for ( int i = 0; i < matched.length; i++ ) {
+ final File source = new File( translationSourceDirectory, matched[i] );
+ mainRenderer.getSettings().getFormatterFactory().buildFormatter( this, formats[i] ).format( source );
+ }
+ }
+
+ private void copyResources() throws RenderingException {
+ File source = mainRenderer.getSettings().getStandardResourcesDirectory();
+ if ( source != null && source.exists() && source.isDirectory() ) {
+ // first, copy over any standard resources...
+ copyResources( source, translationTargetDirectory );
+ // then translation-specific resources
+ String translationSpecificResourcesDirectoryName = translation.getSpecializedResourcesDirectory() == null
+ ? source.getName()
+ : translation.getSpecializedResourcesDirectory();
+ File translationSpecificResourcesDir = new File( translationSourceDirectory, translationSpecificResourcesDirectoryName );
+ if ( translationSpecificResourcesDir.exists() ) {
+ copyResources( translationSpecificResourcesDir, translationTargetDirectory );
+ }
+ }
+ }
+
+ private void copyResources(File source, File target) throws RenderingException {
+ try {
+ FileUtils.copyDirectoryStructure( source, target );
+ }
+ catch ( IOException e ) {
+ throw new RenderingException( "could not copy resources [" + source.getAbsolutePath() + " -> " + target.getAbsolutePath() + "]" );
+ }
+ }
+
+ private Log getLog() {
+ return mainRenderer.getSettings().getLog();
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/xslt/ResolverContext.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/xslt/ResolverContext.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/xslt/ResolverContext.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,14 @@
+package org.jboss.maven.docbook.gen.xslt;
+
+import javax.xml.transform.URIResolver;
+
+import org.jboss.maven.docbook.gen.rendering.RenderingException;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public interface ResolverContext {
+ public URIResolver buildResolver(URIResolver root) throws RenderingException;
+}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/xslt/TransformerFactory.java (from rev 11433, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/TransformerFactory.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/xslt/TransformerFactory.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/xslt/TransformerFactory.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,136 @@
+package org.jboss.maven.docbook.gen.xslt;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Iterator;
+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.agilejava.docbkx.maven.NullWriter;
+import com.agilejava.docbkx.maven.StylesheetResolver;
+import com.icl.saxon.Controller;
+import org.apache.xml.resolver.CatalogManager;
+import org.apache.xml.resolver.tools.CatalogResolver;
+import org.jboss.maven.docbook.gen.rendering.RenderingException;
+
+/**
+ * A factory for {@link Transformer} instances, configurable to return either
+ * SAXON or XALAN based transformers.
+ *
+ * @author Steve Ebersole
+ */
+public class TransformerFactory {
+ private final CatalogResolver catalogResolver = new CatalogResolver( createCatalogManager() );
+
+ private final TransformerType transformerType;
+ private final Properties transformerParameters;
+
+ public TransformerFactory(TransformerType transformerType, Properties transformerParameters) {
+ this.transformerType = transformerType;
+ this.transformerParameters = transformerParameters;
+ }
+
+ public CatalogResolver getCatalogResolver() {
+ return catalogResolver;
+ }
+
+ public synchronized Transformer buildTransformer(URL docbookStylesheet, URL xsltStylesheet) throws RenderingException {
+ if ( docbookStylesheet == null ) {
+ throw new RenderingException( "docbook stylesheet was null" );
+ }
+ if ( xsltStylesheet == null ) {
+ throw new RenderingException( "xslt stylesheet was null" );
+ }
+
+ try {
+ URIResolver uriResolver = new StylesheetResolver(
+ "urn:docbkx:stylesheet",
+ new StreamSource( docbookStylesheet.openStream(), docbookStylesheet.toExternalForm() ),
+ catalogResolver
+ );
+ return createTransformer( uriResolver, xsltStylesheet );
+ }
+ catch ( IOException ioe) {
+ throw new RenderingException( "Failed to read docbook stylesheet.", ioe );
+ }
+ }
+
+ /*package*/ Transformer createTransformer(URIResolver uriResolver, URL xsltStylesheet) throws RenderingException {
+ if ( xsltStylesheet == null ) {
+ throw new RenderingException( "xslt stylesheet was null" );
+ }
+
+ try {
+ javax.xml.transform.TransformerFactory transformerFactory = transformerType == TransformerType.XALAN
+ ? new com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl()
+ : new com.icl.saxon.TransformerFactoryImpl();
+ transformerFactory.setURIResolver( uriResolver );
+ Source source = new StreamSource( xsltStylesheet.openStream(), xsltStylesheet.toExternalForm() );
+ Transformer transformer = transformerFactory.newTransformer( source );
+ transformer.setURIResolver( uriResolver );
+ applyParameters( transformer );
+ Controller controller = ( Controller ) transformer;
+ try {
+ controller.makeMessageEmitter();
+ controller.getMessageEmitter().setWriter( new NullWriter() );
+ }
+ catch ( TransformerException te ) {
+// getLog().error( "Failed to redirect xsl:message output.", te );
+ }
+ return transformer;
+ }
+ catch ( IOException ioe ) {
+ throw new RenderingException( "Failed to read stylesheet from " + xsltStylesheet.toExternalForm(), ioe );
+ }
+ catch ( TransformerConfigurationException tce ) {
+ throw new RenderingException( "Failed to build Transformer from " + xsltStylesheet.toExternalForm(), tce );
+ }
+ }
+
+ private void applyParameters(Transformer transformer) {
+ if ( transformerParameters == null ) {
+ return;
+ }
+ Iterator itr = transformerParameters.entrySet().iterator();
+ while ( itr.hasNext() ) {
+ final Map.Entry entry = ( Map.Entry ) itr.next();
+ transformer.setParameter( ( String ) entry.getKey(), entry.getValue() );
+ }
+ }
+
+ private CatalogManager createCatalogManager() {
+ CatalogManager manager = new CatalogManager();
+ manager.setIgnoreMissingProperties(true);
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ StringBuffer builder = new StringBuffer();
+ boolean first = true;
+ try {
+ Enumeration enumeration = classLoader.getResources( "/catalog.xml" );
+ while ( enumeration.hasMoreElements() ) {
+ if ( !first ) {
+ builder.append( ';' );
+ }
+ else {
+ first = false;
+ }
+ URL resource = ( URL ) enumeration.nextElement();
+ builder.append( resource.toExternalForm() );
+ }
+ }
+ catch ( IOException ignore ) {
+ // intentionally empty
+ }
+ String catalogFiles = builder.toString();
+ if ( catalogFiles.length() != 0 ) {
+ manager.setCatalogFiles( catalogFiles );
+ }
+ return manager;
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/xslt/TransformerType.java (from rev 11433, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/TransformerType.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/xslt/TransformerType.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/gen/xslt/TransformerType.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,37 @@
+package org.jboss.maven.docbook.gen.xslt;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class TransformerType {
+ public static final TransformerType SAXON = new TransformerType( "saxon", false );
+ public static final TransformerType XALAN = new TransformerType( "xalan", true );
+
+ private final String name;
+ private final boolean supportsReset;
+
+ private TransformerType(String name, boolean supportsReset) {
+ this.name = name;
+ this.supportsReset = supportsReset;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean supportsReset() {
+ return supportsReset;
+ }
+
+ public static TransformerType parse(String name) {
+ if ( XALAN.name.equals( name ) ) {
+ return XALAN;
+ }
+ else {
+ // default
+ return SAXON;
+ }
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/RevisionDiffMojo.java (from rev 11433, trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/RevisionDiffMojo.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/RevisionDiffMojo.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/docbook/src/main/java/org/jboss/maven/docbook/revdiff/RevisionDiffMojo.java 2007-05-03 07:24:48 UTC (rev 11460)
@@ -0,0 +1,101 @@
+package org.jboss.maven.docbook.revdiff;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Properties;
+import java.io.IOException;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.xerces.parsers.SAXParser;
+import org.xml.sax.XMLReader;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.jboss.maven.docbook.revdiff.ModuleElementsExtractor;
+import org.jboss.maven.docbook.revdiff.ModuleElementsComparator;
+import org.jboss.maven.docbook.revdiff.ModuleReportHTML;
+import org.jboss.maven.docbook.revdiff.ModuleReport;
+
+/**
+ * A plugin for generating a "revision diff" report across different
+ * translations of the same document. This is useful for the translators to
+ * know what changes exist between their translation and another.
+ *
+ * @goal revision-diff
+ *
+ * @author Christian Bauer
+ * @author Steve Ebersole
+ */
+public class RevisionDiffMojo extends AbstractMojo {
+ /**
+ * The translation against which to baseline the diff.
+ *
+ * @parameter
+ * @required
+ */
+ private String original;
+
+ /**
+ * The translation to be compared to the master.
+ *
+ * @parameter
+ * @required
+ */
+ private String copy;
+
+ /**
+ * The file where the diff report should be written.
+ *
+ * @parameter default="${build.outputDirectory}/docbkx/revdiff
+ * @required
+ */
+ private String reportFile;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ Set moduleElements = new HashSet();
+ XMLReader parser = generateParser();
+ try {
+ // Parse original file
+ parser.setContentHandler( new ModuleElementsExtractor( moduleElements ) );
+ parser.parse( original );
+
+ // Parse copy
+ parser.setContentHandler( new ModuleElementsComparator( moduleElements ) );
+ parser.parse( copy );
+
+ // Set properties for HTML report
+ Properties props = new Properties();
+ props.setProperty( ModuleReportHTML.DESTINATION_FILE, reportFile );
+
+ // Generate HTML report
+ ModuleReport report = new ModuleReportHTML();
+ report.runReport( moduleElements, props );
+ }
+ catch ( IOException e ) {
+ throw new MojoExecutionException( "Files not found : " + original + " or " + copy, e );
+
+ }
+ catch ( Exception e ) {
+ throw new MojoExecutionException( "unable to run revdiff report", e );
+ }
+
+ }
+
+ private XMLReader generateParser() throws MojoExecutionException {
+ try {
+ SAXParser parser = new SAXParser();
+ // Disable validation against DTD
+ parser.setFeature( "http://xml.org/sax/features/validation", false );
+ // Disable DTD loading in Xerces
+ parser.setFeature( "http://apache.org/xml/features/nonvalidating/load-external-dtd", false );
+ return parser;
+ }
+ catch ( SAXNotSupportedException e ) {
+ throw new MojoExecutionException( "unable to generate SAX Parser", e );
+ }
+ catch ( SAXNotRecognizedException e ) {
+ throw new MojoExecutionException( "unable to generate SAX Parser", e );
+ }
+ }
+}
More information about the hibernate-commits
mailing list