[hibernate-commits] Hibernate SVN: r11555 - in trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src: main/java/org/jboss/maven and 9 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Thu May 24 04:05:05 EDT 2007
Author: steve.ebersole at jboss.com
Date: 2007-05-24 04:05:05 -0400 (Thu, 24 May 2007)
New Revision: 11555
Added:
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/Format.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/GenerationMojo.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/Options.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/Settings.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/BasicRenderer.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/HtmlRenderer.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/PdfRenderer.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/Renderer.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/RendererFactory.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/RenderingException.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/FormatType.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/NoOpWriter.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/ResourceHelper.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/TransformerType.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/TransformerFactory.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/XSLTException.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/AbstractCatalogManager.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/BasicUrnResolver.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/DocBookStylesheetResolver.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/ExplicitCatalogManager.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/ResolverChain.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/StandardCatalogManager.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/BaselineHandler.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/ContentItem.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/ContentItemDescriptor.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/Diff.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/DiffCreator.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/GenerationException.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/IndexReportGenerator.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/TranslationDiffReport.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/TranslationHandler.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/TranslationReportGenerator.java
Removed:
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/docbook/
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/test/
Modified:
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/resources/META-INF/plexus/components.xml
Log:
second rev; the diff plugin is out of whack now though
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/Format.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/Format.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/Format.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,39 @@
+package org.jboss.maven.plugin.docbook.gen;
+
+import org.jboss.maven.plugin.docbook.gen.util.FormatType;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class Format {
+ private String formatName;
+ private String stylesheetResource;
+ private String finalName;
+
+ public Format() {
+ }
+
+ public Format(String formatName, String stylesheetResource, String finalName) {
+ this.formatName = formatName;
+ this.stylesheetResource = stylesheetResource;
+ this.finalName = finalName;
+ }
+
+ public String getFormatName() {
+ return formatName;
+ }
+
+ public String getStylesheetResource() {
+ return stylesheetResource;
+ }
+
+ public String getFinalName() {
+ return finalName;
+ }
+
+ public FormatType getFormatType() {
+ return FormatType.parse( formatName );
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/GenerationMojo.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/GenerationMojo.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/GenerationMojo.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,91 @@
+package org.jboss.maven.plugin.docbook.gen;
+
+import java.io.File;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.util.FileUtils;
+import org.jboss.maven.plugin.docbook.gen.xslt.XSLTException;
+import org.jboss.maven.plugin.docbook.gen.render.RendererFactory;
+import org.jboss.maven.plugin.docbook.gen.render.RenderingException;
+
+/**
+ * A DocBook plugin based on the excellent docbkx-maven-plugin, but which
+ * specifically handles language translations in a more transparent way.
+ *
+ * @goal generate
+ * @phase package
+ *
+ * @author Steve Ebersole
+ */
+public class GenerationMojo extends AbstractMojo {
+
+ /**
+ * The directory where the sources are located.
+ *
+ * @parameter expression="${basedir}/src/main/docbook"
+ */
+ private File sourceDirectory;
+
+ /**
+ * The directory where the output will be written.
+ *
+ * @parameter expression="${basedir}/target/docbook"
+ */
+ private File targetDirectory;
+
+ /**
+ * The name of the document (relative to sourceDirectory) which is the
+ * document to be rendered.
+ *
+ * @parameter
+ * @required
+ */
+ private String sourceDocumentName;
+
+ /**
+ * The formats in which to perform rendering.
+ *
+ * @parameter
+ * @required
+ */
+ private Format[] formats;
+
+ /**
+ * Configurable options
+ *
+ * @parameter
+ */
+ private Options options;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if ( !sourceDirectory.exists() ) {
+ getLog().info( "sourceDirectory [" + sourceDirectory.getAbsolutePath() + "] did not exist" );
+ return;
+ }
+ File source = new File( sourceDirectory, sourceDocumentName );
+ if ( !source.exists() ) {
+ getLog().info( "source [" + source.getAbsolutePath() + "] did not exist" );
+ return;
+ }
+
+ if ( !targetDirectory.exists() ) {
+ FileUtils.mkdir( targetDirectory.getAbsolutePath() );
+ }
+
+ RendererFactory rendererFactory = new RendererFactory( options, source, targetDirectory, getLog() );
+ try {
+ for ( int i = 0; i < formats.length; i++ ) {
+ rendererFactory.buildRenderer( formats[i] ).render( source );
+ }
+ }
+ catch ( XSLTException e ) {
+ throw new MojoExecutionException( "XSLT problem", e );
+ }
+ catch ( RenderingException e ) {
+ throw new MojoExecutionException( "Rendering problem", e );
+ }
+
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/Options.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/Options.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/Options.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,46 @@
+package org.jboss.maven.plugin.docbook.gen;
+
+import java.util.Properties;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class Options {
+ private boolean xincludeSupported;
+ private String[] catalogs;
+ private String xmlTransformerType;
+ private Properties transformerParameters;
+
+ public Options() {
+ }
+
+ public Options(
+ boolean xincludeSupported,
+ String[] catalogs,
+ String xmlTransformerType,
+ Properties transformerParameters) {
+ this.xincludeSupported = xincludeSupported;
+ this.catalogs = catalogs;
+ this.xmlTransformerType = xmlTransformerType;
+ this.transformerParameters = transformerParameters;
+ }
+
+ public boolean isXincludeSupported() {
+ return xincludeSupported;
+ }
+
+ public String[] getCatalogs() {
+ return catalogs;
+ }
+
+ public String getXmlTransformerType() {
+ return xmlTransformerType;
+ }
+
+ public Properties getTransformerParameters() {
+ return transformerParameters;
+ }
+
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/Settings.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/Settings.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/Settings.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,60 @@
+package org.jboss.maven.plugin.docbook.gen;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.xml.resolver.CatalogManager;
+import org.apache.maven.plugin.logging.Log;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class Settings {
+ private final boolean xincludeSupported;
+ private final File sourceDocument;
+ private final File targetDirectory;
+ private final List entities;
+ private final CatalogManager catalogManager;
+ private final Log log;
+
+ public Settings(
+ boolean xincludeSupported,
+ File sourceDocument,
+ File targetDirectory,
+ List entities,
+ CatalogManager catalogManager,
+ Log log) {
+ this.xincludeSupported = xincludeSupported;
+ this.sourceDocument = sourceDocument;
+ this.targetDirectory = targetDirectory;
+ this.entities = entities;
+ this.catalogManager = catalogManager;
+ this.log = log;
+ }
+
+ public boolean isXincludeSupported() {
+ return xincludeSupported;
+ }
+
+ public File getSourceDocument() {
+ return sourceDocument;
+ }
+
+ public File getTargetDirectory() {
+ return targetDirectory;
+ }
+
+ public List getEntities() {
+ return entities;
+ }
+
+ public CatalogManager getCatalogManager() {
+ return catalogManager;
+ }
+
+ public Log getLog() {
+ return log;
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/BasicRenderer.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/BasicRenderer.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/BasicRenderer.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,149 @@
+package org.jboss.maven.plugin.docbook.gen.render;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import javax.xml.transform.Transformer;
+import javax.xml.transform.Source;
+import javax.xml.transform.Result;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.jboss.maven.plugin.docbook.gen.Format;
+import org.jboss.maven.plugin.docbook.gen.xslt.XSLTException;
+import org.jboss.maven.plugin.docbook.gen.util.ResourceHelper;
+import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.util.FileUtils;
+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;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class BasicRenderer implements Renderer {
+ 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";
+
+ protected final RendererFactory factory;
+ protected final Format format;
+
+ public BasicRenderer(RendererFactory factory, Format format) {
+ this.factory = factory;
+ this.format = format;
+ }
+
+ public final void render(File source) throws RenderingException, XSLTException {
+ getLog().debug( "starting formatting [" + format.getFormatName() + "]" );
+
+ File target = prepareTarget( source );
+
+ Transformer transformer = buildTransformer( target );
+ Source transformationSource = buildSource( source );
+ Result transformationResult = buildResult( target );
+ try {
+ transformer.transform( transformationSource, transformationResult );
+ }
+ catch ( TransformerException e ) {
+ throw new RenderingException( "unable to perform transformation", e );
+ }
+ finally {
+ releaseResult( transformationResult );
+ }
+
+ }
+
+ private File prepareTarget(File source) throws RenderingException {
+ String targetFileName = deduceTargetFileName( source );
+ File target = new File( factory.getTargetDirectory(), targetFileName );
+ if ( target.exists() ) {
+ if ( !target.delete() ) {
+ getLog().warn( "unable to clean up previous output file [" + target.getAbsolutePath() + "]" );
+ }
+ }
+ if ( !target.exists() ) {
+ try {
+ target.createNewFile();
+ }
+ catch ( IOException e ) {
+ throw new RenderingException( "unable to create output file [" + target.getAbsolutePath() + "]", e );
+ }
+ }
+ return target;
+ }
+
+ private String deduceTargetFileName(File source) {
+ return format.getFinalName() == null
+ ? FileUtils.basename( source.getAbsolutePath() ) + format.getFormatType().getStandardFileExtension()
+ : format.getFinalName();
+ }
+
+ protected Transformer buildTransformer(File targetFile)
+ throws RenderingException, XSLTException {
+ final URL transformationStylesheet = resolveTransformationStylesheet();
+ Transformer transformer = factory.getTransformerFactory()
+ .buildTransformer( format.getFormatType(), transformationStylesheet );
+ // "inclusion" of graphics in html is much different than other formats
+ // REF: http://sagehill.net/docbookxsl/GraphicsLocations.html
+ if ( format.getFormatType().isImagePathNeeded() ) {
+ String imgSrcPath = factory.getTargetDirectory().getAbsolutePath() + "/";
+ getLog().debug( "setting 'img.src.path' [" + imgSrcPath + "]" );
+ transformer.setParameter( "img.src.path", imgSrcPath );
+ }
+ return transformer;
+ }
+
+ protected final URL resolveTransformationStylesheet() throws RenderingException {
+ return format.getStylesheetResource() != null
+ ? ResourceHelper.requireResource( format.getStylesheetResource() )
+ : ResourceHelper.requireResource( format.getFormatType().getStylesheetResource() );
+ }
+
+ private Source buildSource(File sourceFile) throws RenderingException {
+ try {
+ EntityResolver resolver = factory.getCatalogResolver();
+ 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 final SAXParserFactory createParserFactory() {
+ SAXParserFactory parserFactory = new SAXParserFactoryImpl();
+ parserFactory.setXIncludeAware( factory.getOptions().isXincludeSupported() );
+ return parserFactory;
+ }
+
+ protected Result buildResult(File targetFile) throws RenderingException {
+ return new StreamResult( targetFile );
+ }
+
+ protected void releaseResult(Result transformationResult) {
+ // typically nothing to do...
+ }
+
+ protected Log getLog() {
+ return factory.getLog();
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/HtmlRenderer.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/HtmlRenderer.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/HtmlRenderer.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,32 @@
+package org.jboss.maven.plugin.docbook.gen.render;
+
+import java.io.File;
+import javax.xml.transform.Transformer;
+
+import org.jboss.maven.plugin.docbook.gen.Format;
+import org.jboss.maven.plugin.docbook.gen.util.FormatType;
+import org.jboss.maven.plugin.docbook.gen.xslt.XSLTException;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class HtmlRenderer extends BasicRenderer {
+ public HtmlRenderer(RendererFactory factory, Format format) {
+ super( factory, format );
+ }
+
+ protected Transformer buildTransformer(File targetFile)
+ throws RenderingException, XSLTException {
+ Transformer transformer = super.buildTransformer( targetFile );
+ if ( format.getFormatType() == FormatType.HTML ) {
+ 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;
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/PdfRenderer.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/PdfRenderer.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/PdfRenderer.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,116 @@
+package org.jboss.maven.plugin.docbook.gen.render;
+
+import java.io.File;
+import java.io.OutputStream;
+import java.io.FileNotFoundException;
+import javax.xml.transform.Result;
+import javax.xml.transform.sax.SAXResult;
+
+import org.jboss.maven.plugin.docbook.gen.Format;
+import org.apache.fop.apps.Driver;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.maven.plugin.logging.Log;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class PdfRenderer extends BasicRenderer {
+ public PdfRenderer(RendererFactory factory, Format format) {
+ super( factory, format );
+ }
+
+ protected Result buildResult(File targetFile) throws RenderingException {
+ getLog().info( "building formatting result [" + targetFile.getAbsolutePath() + "]" );
+ Driver driver = new Driver();
+ driver.setLogger( new LoggingBridge( 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()
+ );
+ }
+ }
+
+ private static class LoggingBridge implements Logger {
+
+ private Log mavenLog;
+
+ public LoggingBridge(Log mavenLog) {
+ this.mavenLog = mavenLog;
+ }
+
+ public void debug(String arg0) {
+ mavenLog.debug( arg0 );
+ }
+
+ public void debug(String arg0, Throwable arg1) {
+ mavenLog.debug( arg0, arg1 );
+ }
+
+ public void error(String arg0) {
+ mavenLog.error( arg0 );
+ }
+
+ public void error(String arg0, Throwable arg1) {
+ mavenLog.error( arg0, arg1 );
+ }
+
+ public void fatalError(String arg0) {
+ mavenLog.error( arg0 );
+ }
+
+ public void fatalError(String arg0, Throwable arg1) {
+ mavenLog.error( arg0, arg1 );
+ }
+
+ public Logger getChildLogger(String arg0) {
+ return null;
+ }
+
+ public void info(String arg0) {
+ mavenLog.info( arg0 );
+ }
+
+ public void info(String arg0, Throwable arg1) {
+ mavenLog.info( arg0, arg1 );
+ }
+
+ public boolean isDebugEnabled() {
+ return mavenLog.isDebugEnabled();
+ }
+
+ public boolean isErrorEnabled() {
+ return mavenLog.isErrorEnabled();
+ }
+
+ public boolean isFatalErrorEnabled() {
+ return mavenLog.isErrorEnabled();
+ }
+
+ public boolean isInfoEnabled() {
+ return mavenLog.isInfoEnabled();
+ }
+
+ public boolean isWarnEnabled() {
+ return mavenLog.isWarnEnabled();
+ }
+
+ public void warn(String arg0) {
+ mavenLog.warn( arg0 );
+ }
+
+ public void warn(String arg0, Throwable arg1) {
+ mavenLog.warn( arg0, arg1 );
+ }
+
+ }
+
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/Renderer.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/Renderer.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/Renderer.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,14 @@
+package org.jboss.maven.plugin.docbook.gen.render;
+
+import java.io.File;
+
+import org.jboss.maven.plugin.docbook.gen.xslt.XSLTException;
+
+/**
+ * Responsible for rendering a given source document in a particular format.
+ *
+ * @author Steve Ebersole
+ */
+public interface Renderer {
+ public void render(File source) throws RenderingException, XSLTException;
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/RendererFactory.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/RendererFactory.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/RendererFactory.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,89 @@
+package org.jboss.maven.plugin.docbook.gen.render;
+
+import java.io.File;
+
+import org.jboss.maven.plugin.docbook.gen.Format;
+import org.jboss.maven.plugin.docbook.gen.Options;
+import org.jboss.maven.plugin.docbook.gen.util.TransformerType;
+import org.jboss.maven.plugin.docbook.gen.util.FormatType;
+import org.jboss.maven.plugin.docbook.gen.xslt.XSLTException;
+import org.jboss.maven.plugin.docbook.gen.xslt.TransformerFactory;
+import org.jboss.maven.plugin.docbook.gen.xslt.resolve.StandardCatalogManager;
+import org.jboss.maven.plugin.docbook.gen.xslt.resolve.ExplicitCatalogManager;
+import org.apache.xml.resolver.CatalogManager;
+import org.apache.xml.resolver.tools.CatalogResolver;
+import org.apache.maven.plugin.logging.Log;
+
+/**
+ * Builds a renderer for the given format
+ *
+ * @author Steve Ebersole
+ */
+public class RendererFactory {
+ private final Options options;
+ private final File source;
+ private final File targetDirectory;
+ private final Log log;
+ private final CatalogResolver catalogResolver;
+ private final TransformerFactory transformerFactory;
+
+ public RendererFactory(Options options, File source, File targetDirectory, Log log) {
+ this.options = options;
+ this.source = source;
+ this.targetDirectory = targetDirectory;
+ this.log = log;
+ CatalogManager catalogManager;
+ // todo : add a "recommended catalog manager" based on discussion at http://sagehill.net/docbookxsl/Catalogs.html
+ // especially the part at http://sagehill.net/docbookxsl/WriteCatalog.html#MapManyWithRewrite
+ if ( options.getCatalogs() == null || options.getCatalogs().length == 0 ) {
+ catalogManager = new StandardCatalogManager();
+ }
+ else {
+ catalogManager = new ExplicitCatalogManager( options.getCatalogs() );
+ }
+ catalogResolver = new CatalogResolver( catalogManager );
+ transformerFactory = new TransformerFactory(
+ TransformerType.parse( options.getXmlTransformerType() ),
+ options.getTransformerParameters(),
+ catalogResolver
+ );
+ }
+
+
+ public Options getOptions() {
+ return options;
+ }
+
+ public File getSource() {
+ return source;
+ }
+
+ public File getTargetDirectory() {
+ return targetDirectory;
+ }
+
+ public Log getLog() {
+ return log;
+ }
+
+ public CatalogResolver getCatalogResolver() {
+ return catalogResolver;
+ }
+
+ public TransformerFactory getTransformerFactory() {
+ return transformerFactory;
+ }
+
+ public Renderer buildRenderer(Format format) throws XSLTException {
+ FormatType type = format.getFormatType();
+ if ( type == FormatType.PDF ) {
+ return new PdfRenderer( this, format );
+ }
+ else if ( type == FormatType.HTML || type == FormatType.HTML_SINGLE ) {
+ return new HtmlRenderer( this, format );
+ }
+ else {
+ return new BasicRenderer( this, format );
+ }
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/RenderingException.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/RenderingException.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/render/RenderingException.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,17 @@
+package org.jboss.maven.plugin.docbook.gen.render;
+
+/**
+ * {@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/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/FormatType.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/FormatType.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/FormatType.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,67 @@
+package org.jboss.maven.plugin.docbook.gen.util;
+
+/**
+ * An enumeration of the various types of formatting supported in this plugin.
+ * <p/>
+ * DocBook does define some other output formatting support (like HTML Help),
+ * but those are not covered nor supported by this plugin.
+ *
+ * @author Steve Ebersole
+ */
+public class FormatType {
+ public static final FormatType PDF = new FormatType( "pdf", "/fo/docbook.xsl" );
+ public static final FormatType HTML = new FormatType( "html", "html", "/html/chunk.xsl", false );
+ public static final FormatType HTML_SINGLE = new FormatType( "html_single", "html", "/html/docbook.xsl", false );
+ public static final FormatType MAN = new FormatType( "man", "/manpages/docbook.xsl" );
+
+ private final String name;
+ private final String standardFileExtension;
+ private final String stylesheetResource;
+ private final boolean imagePathNeeded;
+
+
+ public FormatType(String name, String stylesheetResource) {
+ this( name, name, stylesheetResource, true );
+ }
+
+ private FormatType(String name, String standardFileExtension, String stylesheetResource, boolean imagePathNeeded) {
+ this.name = name;
+ this.standardFileExtension = standardFileExtension;
+ this.stylesheetResource = stylesheetResource;
+ this.imagePathNeeded = imagePathNeeded;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getStandardFileExtension() {
+ return standardFileExtension;
+ }
+
+ public String getStylesheetResource() {
+ return stylesheetResource;
+ }
+
+ public boolean isImagePathNeeded() {
+ return imagePathNeeded;
+ }
+
+ public static FormatType parse(String name) {
+ if ( PDF.name.equals( name ) ) {
+ return PDF;
+ }
+ else if ( HTML.name.equals( name ) ) {
+ return HTML;
+ }
+ else if ( HTML_SINGLE.name.equals( name ) ) {
+ return HTML_SINGLE;
+ }
+ else if ( MAN.name.equals( name ) ) {
+ return MAN;
+ }
+ else {
+ throw new IllegalArgumentException( "unknown format type [" + name + "]" );
+ }
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/NoOpWriter.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/NoOpWriter.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/NoOpWriter.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,20 @@
+package org.jboss.maven.plugin.docbook.gen.util;
+
+import java.io.Writer;
+
+/**
+ * A writer which does no writing :)
+ *
+ * @author Steve Ebersole
+ */
+public class NoOpWriter extends Writer {
+
+ public void write(char cbuf[], int off, int len) {
+ }
+
+ public void flush() {
+ }
+
+ public void close() {
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/ResourceHelper.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/ResourceHelper.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/ResourceHelper.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,26 @@
+package org.jboss.maven.plugin.docbook.gen.util;
+
+import java.net.URL;
+
+/**
+ * Simple helpers for locating and handling classpath resource lookups.
+ *
+ * @author Steve Ebersole
+ */
+public class ResourceHelper {
+ public static URL requireResource(String name) {
+ URL resource = locateResource( name );
+ if ( resource == null ) {
+ throw new IllegalArgumentException( "could not locate resource [" + name + "]" );
+ }
+ return resource;
+ }
+
+ public static URL locateResource(String name) {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if ( loader == null ) {
+ loader = ResourceHelper.class.getClassLoader();
+ }
+ return loader.getResource( name );
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/TransformerType.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/TransformerType.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/util/TransformerType.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,37 @@
+package org.jboss.maven.plugin.docbook.gen.util;
+
+/**
+ * Enumeration of supported XSLT transformers.
+ *
+ * @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;
+ }
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/TransformerFactory.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/TransformerFactory.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/TransformerFactory.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,110 @@
+package org.jboss.maven.plugin.docbook.gen.xslt;
+
+import java.util.Properties;
+import java.util.Iterator;
+import java.util.Map;
+import java.net.URL;
+import java.io.IOException;
+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.jboss.maven.plugin.docbook.gen.util.TransformerType;
+import org.jboss.maven.plugin.docbook.gen.xslt.resolve.DocBookStylesheetResolver;
+import org.jboss.maven.plugin.docbook.gen.xslt.resolve.ResolverChain;
+import org.jboss.maven.plugin.docbook.gen.util.FormatType;
+import org.jboss.maven.plugin.docbook.gen.util.ResourceHelper;
+import org.jboss.maven.plugin.docbook.gen.util.NoOpWriter;
+import com.icl.saxon.Controller;
+
+/**
+ * A factory for {@link javax.xml.transform.Transformer} instances, configurable
+ * to return either SAXON or XALAN based transformers.
+ *
+ * @author Steve Ebersole
+ */
+public class TransformerFactory {
+ private final TransformerType transformerType;
+ private final Properties transformerParameters;
+ private final CatalogResolver catalogResolver;
+
+ public TransformerFactory(
+ TransformerType transformerType,
+ Properties transformerParameters,
+ CatalogResolver catalogResolver) {
+ this.transformerType = transformerType;
+ this.transformerParameters = transformerParameters;
+ this.catalogResolver = catalogResolver;
+ }
+
+ public Transformer buildTransformer(FormatType formatType, URL customStylesheet) throws XSLTException {
+ URIResolver uriResolver = buildUriResolver( formatType );
+
+ javax.xml.transform.TransformerFactory transformerFactory = buildTransformerFactory();
+ transformerFactory.setURIResolver( uriResolver );
+
+ URL xsltStylesheet = customStylesheet == null
+ ? ResourceHelper.requireResource( formatType.getStylesheetResource() )
+ : customStylesheet;
+
+ Transformer transformer;
+ try {
+ Source source = new StreamSource( xsltStylesheet.openStream(), xsltStylesheet.toExternalForm() );
+ transformer = transformerFactory.newTransformer( source );
+ }
+ catch ( IOException e ) {
+ throw new XSLTException( "problem opening stylesheet", e );
+ }
+ catch ( TransformerConfigurationException e ) {
+ throw new XSLTException( "unable to build transformer", e );
+ }
+
+ transformer.setURIResolver( uriResolver );
+ applyParameters( transformer );
+
+ if ( transformer instanceof Controller ) {
+ Controller controller = ( Controller ) transformer;
+ try {
+ controller.makeMessageEmitter();
+ controller.getMessageEmitter().setWriter( new NoOpWriter() );
+ }
+ catch ( TransformerException te ) {
+ // intentionally empty
+ }
+ }
+ return transformer;
+ }
+
+ private javax.xml.transform.TransformerFactory buildTransformerFactory() {
+ if ( transformerType == TransformerType.XALAN ) {
+ return new com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl();
+ }
+ else {
+ // saxon as default...
+ return new com.icl.saxon.TransformerFactoryImpl();
+ }
+ }
+
+ 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 URIResolver buildUriResolver(FormatType formatType)
+ throws XSLTException {
+ ResolverChain resolverChain = new ResolverChain();
+ resolverChain.addResolver( catalogResolver );
+ resolverChain.addResolver( new DocBookStylesheetResolver( formatType ) );
+ return resolverChain;
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/XSLTException.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/XSLTException.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/XSLTException.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,18 @@
+package org.jboss.maven.plugin.docbook.gen.xslt;
+
+/**
+ * Indicates problems either building XSLT transformers or performing
+ * transformations.
+ *
+ * @author Steve Ebersole
+ */
+public class XSLTException extends Exception {
+
+ public XSLTException(String message) {
+ super( message );
+ }
+
+ public XSLTException(String message, Throwable cause) {
+ super( message, cause );
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/AbstractCatalogManager.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/AbstractCatalogManager.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/AbstractCatalogManager.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,31 @@
+package org.jboss.maven.plugin.docbook.gen.xslt.resolve;
+
+import org.apache.xml.resolver.CatalogManager;
+
+/**
+ * Basic support for our notion of CatalogManagers.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractCatalogManager extends CatalogManager {
+ public AbstractCatalogManager(String[] catalogNames) {
+ super();
+ setIgnoreMissingProperties( true );
+ if ( catalogNames != null && catalogNames.length != 0 ) {
+ StringBuffer buffer = new StringBuffer();
+ boolean first = true;
+ for ( int i = 0; i < catalogNames.length; i++ ) {
+ if ( catalogNames[i] != null ) {
+ if ( first ) {
+ first = false;
+ }
+ else {
+ buffer.append( ';' );
+ }
+ }
+ buffer.append( catalogNames[i] );
+ }
+ setCatalogFiles( buffer.toString() );
+ }
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/BasicUrnResolver.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/BasicUrnResolver.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/BasicUrnResolver.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,29 @@
+package org.jboss.maven.plugin.docbook.gen.xslt.resolve;
+
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+
+/**
+ * Basic support for URIResolvers which map a URN unto a single replacement
+ * {@link Source}.
+ *
+ * @author Steve Ebersole
+ */
+public class BasicUrnResolver implements URIResolver {
+ private final String urn;
+ private final Source source;
+
+ public BasicUrnResolver(String urn, Source source) {
+ this.urn = urn;
+ this.source = source;
+ }
+
+ public Source resolve(String href, String base) throws TransformerException {
+ return urn.equals( href ) ? source : null;
+ }
+
+ public String toString() {
+ return super.toString() + " [URN:" + urn + "]";
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/DocBookStylesheetResolver.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/DocBookStylesheetResolver.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/DocBookStylesheetResolver.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,38 @@
+package org.jboss.maven.plugin.docbook.gen.xslt.resolve;
+
+import java.net.URL;
+import java.io.IOException;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.jboss.maven.plugin.docbook.gen.util.FormatType;
+import org.jboss.maven.plugin.docbook.gen.util.ResourceHelper;
+import org.jboss.maven.plugin.docbook.gen.xslt.XSLTException;
+
+/**
+ * Resolves against the set of standard DocBook stylesheets
+ *
+ * @author Steve Ebersole
+ */
+public class DocBookStylesheetResolver extends BasicUrnResolver {
+ private final FormatType formatType;
+
+ public DocBookStylesheetResolver(FormatType type) throws XSLTException {
+ super( "urn:docbook:stylesheet", createSource( type ) );
+ this.formatType = type;
+ }
+
+ private static Source createSource(FormatType type) throws XSLTException {
+ URL stylesheet = ResourceHelper.requireResource( type.getStylesheetResource() );
+ try {
+ return new StreamSource( stylesheet.openStream(), stylesheet.toExternalForm() );
+ }
+ catch ( IOException e ) {
+ throw new XSLTException( "could not locate DocBook stylesheet [" + type.getName() + "]", e );
+ }
+ }
+
+ public String toString() {
+ return super.toString() + " [" + formatType.getName() + "]";
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/ExplicitCatalogManager.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/ExplicitCatalogManager.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/ExplicitCatalogManager.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,14 @@
+package org.jboss.maven.plugin.docbook.gen.xslt.resolve;
+
+
+/**
+ * Utilizes explicit, user-supplied catalog names to build a
+ * CatalogManager.
+ *
+ * @author Steve Ebersole
+ */
+public class ExplicitCatalogManager extends AbstractCatalogManager {
+ public ExplicitCatalogManager(String[] catalogNames) {
+ super( catalogNames );
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/ResolverChain.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/ResolverChain.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/ResolverChain.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,55 @@
+package org.jboss.maven.plugin.docbook.gen.xslt.resolve;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+
+/**
+ * Allows chaining a series of {@link URIResolver resolvers} together.
+ * <p/>
+ * "Precedence" of the resolvers is determined by the order in which
+ * they are {@link #addResolver added}.
+ *
+ * @author Steve Ebersole
+ */
+public class ResolverChain implements URIResolver {
+ private List resolvers = new ArrayList();
+
+ public ResolverChain() {
+ }
+
+ public ResolverChain(URIResolver resolver) {
+ this();
+ addResolver( resolver );
+ }
+
+ /**
+ * Adds a resolver to the chain.
+ *
+ * @param resolver The resolver to add.
+ */
+ public void addResolver(URIResolver resolver) {
+ resolvers.add( resolver );
+ }
+
+ /**
+ * Here we iterate over all the chained resolvers and delegate to them
+ * until we find one which can handle the resolve request (if any).
+ *
+ * {@inheritDoc}
+ */
+ public Source resolve(String href, String base) throws TransformerException {
+ Source result = null;
+ Iterator itr = resolvers.iterator();
+ while ( itr.hasNext() ) {
+ result = ( ( URIResolver ) itr.next() ).resolve( href, base );
+ if ( result != null ) {
+ break;
+ }
+ }
+ return result;
+ }
+}
Added: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/StandardCatalogManager.java
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/StandardCatalogManager.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/gen/xslt/resolve/StandardCatalogManager.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,41 @@
+package org.jboss.maven.plugin.docbook.gen.xslt.resolve;
+
+import java.util.Enumeration;
+import java.util.ArrayList;
+import java.net.URL;
+import java.io.IOException;
+
+/**
+ * CatalogManager which resolves its catalogs internally via classpath
+ * resource lookups. Its looks for resources named '/catalog.xml' on the
+ * classpath.
+ *
+ * @author Steve Ebersole
+ */
+public class StandardCatalogManager extends AbstractCatalogManager {
+ public StandardCatalogManager() {
+ super( resolveCatalogNames() );
+ }
+
+ private static String[] resolveCatalogNames() {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ if ( classLoader == null ) {
+ classLoader = StandardCatalogManager.class.getClassLoader();
+ }
+ ArrayList names = new ArrayList();
+ try {
+ Enumeration enumeration = classLoader.getResources( "/catalog.xml" );
+ while ( enumeration.hasMoreElements() ) {
+ final URL resource = ( URL ) enumeration.nextElement();
+ final String resourcePath = resource.toExternalForm();
+ if ( resourcePath != null ) {
+ names.add( resourcePath );
+ }
+ }
+ }
+ catch ( IOException ignore ) {
+ // intentionally empty
+ }
+ return ( String[] ) names.toArray( new String[ names.size() ] );
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/BaselineHandler.java (from rev 11551, trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/docbook/revdiff/BaselineHandler.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/BaselineHandler.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/BaselineHandler.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,59 @@
+package org.jboss.maven.plugin.docbook.revdiff;
+
+import java.util.Map;
+
+import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+/**
+ * An XML parse handler used to create a catalog of baseline elements.
+ * <p/>
+ * Typically this would be used against the master translation to create
+ * a baseline against which particular translations would be checked.
+ *
+ * @author Christian Bauer
+ * @author Steve Ebersole
+ */
+public class BaselineHandler extends DefaultHandler {
+ private final Map catalog;
+ private Locator docLocator;
+
+ public void setDocumentLocator(Locator locator) {
+ this.docLocator = locator;
+ }
+
+ public BaselineHandler(Map catalog) {
+ this.catalog = catalog;
+ }
+
+ public void startElement(
+ String namespaceURI,
+ String localName,
+ String qualifiedName,
+ Attributes atts) throws SAXException {
+
+ // Only add ModuleElements that have an identifier
+ String identifier = atts.getValue( "id" );
+ if ( identifier != null ) {
+ // The default revision is 0
+ int revision = 0;
+ if ( atts.getValue( "revision" ) != null ) {
+ revision = new Integer( atts.getValue( "revision" ) ).intValue();
+ }
+
+ // Generate new ContentItem and new original state
+ ContentItem contentItem = new ContentItem( identifier );
+ ContentItemDescriptor descriptor = new ContentItemDescriptor(
+ docLocator.getSystemId(),
+ qualifiedName,
+ revision,
+ docLocator.getLineNumber(),
+ docLocator.getColumnNumber()
+ );
+ contentItem.setMasterDescriptor( descriptor );
+ catalog.put( identifier, contentItem );
+ }
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/ContentItem.java (from rev 11551, trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/docbook/revdiff/ContentItem.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/ContentItem.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/ContentItem.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,59 @@
+package org.jboss.maven.plugin.docbook.revdiff;
+
+/**
+ * Describes a particular piece of content, including descriptors
+ * from both the master and a particular translation
+ *
+ * @author Christian Bauer
+ */
+public class ContentItem {
+ private final String identifier;
+ private ContentItemDescriptor masterDescriptor;
+ private ContentItemDescriptor translationDescriptor;
+
+ public ContentItem(String identifier) {
+ this.identifier = identifier;
+ }
+
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ public ContentItemDescriptor getMasterDescriptor() {
+ return masterDescriptor;
+ }
+
+ public void setMasterDescriptor(ContentItemDescriptor masterDescriptor) {
+ this.masterDescriptor = masterDescriptor;
+ }
+
+ public ContentItemDescriptor getTranslationDescriptor() {
+ return translationDescriptor;
+ }
+
+ public void setTranslationDescriptor(ContentItemDescriptor translationDescriptor) {
+ this.translationDescriptor = translationDescriptor;
+ }
+
+
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ ContentItem that = ( ContentItem ) o;
+
+ if ( !identifier.equals( that.identifier ) ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode() {
+ return identifier.hashCode();
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/ContentItemDescriptor.java (from rev 11551, trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/docbook/revdiff/ContentItemDescriptor.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/ContentItemDescriptor.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/ContentItemDescriptor.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,44 @@
+package org.jboss.maven.plugin.docbook.revdiff;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Christian Bauer
+ */
+public class ContentItemDescriptor {
+ public static int REVISION_IGNORE = -1;
+
+ private final String sourceSystemId;
+ private final String elementName;
+ private final int revision;
+ private final int row;
+ private final int column;
+
+ public ContentItemDescriptor(String sourceSystemId, String elementName, int revision, int row, int column) {
+ this.sourceSystemId = sourceSystemId;
+ this.elementName = elementName;
+ this.revision = revision;
+ this.row = row;
+ this.column = column;
+ }
+
+ public int getRevision() {
+ return revision;
+ }
+
+ public String getElementName() {
+ return elementName;
+ }
+
+ public String getSourceSystemId() {
+ return sourceSystemId;
+ }
+
+ public int getRow() {
+ return row;
+ }
+
+ public int getColumn() {
+ return column;
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/Diff.java (from rev 11551, trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/docbook/revdiff/Diff.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/Diff.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/Diff.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,39 @@
+package org.jboss.maven.plugin.docbook.revdiff;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Iterator;
+
+/**
+ * Represents the difference between two sources.
+ *
+ * @author Steve Ebersole
+ */
+public class Diff {
+ private Set elementsOnlyInMaster = new HashSet();
+ private Set elementsOnlyInTranslation = new HashSet();
+ private Set elementsDiffRevision = new HashSet();
+
+ public void addOnlyInMaster(ContentItem element) {
+ elementsOnlyInMaster.add( element );
+ }
+
+ public void addOnlyInTranslation(ContentItem element) {
+ elementsOnlyInTranslation.add( element );
+ }
+
+ public void addDiffRevision(ContentItem element) {
+ elementsDiffRevision.add( element );
+ }
+
+ public Iterator getElementsOnlyInMaster() {
+ return elementsOnlyInMaster.iterator();
+ }
+
+ public Iterator getElementsOnlyInTranslation() {
+ return elementsOnlyInTranslation.iterator();
+ }
+ public Iterator getElementsDiffRevision() {
+ return elementsDiffRevision.iterator();
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/DiffCreator.java (from rev 11551, trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/docbook/revdiff/DiffCreator.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/DiffCreator.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/DiffCreator.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,100 @@
+package org.jboss.maven.plugin.docbook.revdiff;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+
+import com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.XMLReader;
+import org.apache.maven.plugin.logging.Log;
+
+/**
+ * Responsible for creating a diff description.
+ *
+ * @author Steve Ebersole
+ */
+public class DiffCreator {
+
+ private final XMLReader parser;
+ private final Log log;
+
+ public DiffCreator(boolean xincludeSupport, Log log) throws GenerationException {
+ this.parser = generateParser( xincludeSupport );
+ this.log = log;
+ }
+
+ public synchronized Diff findDiff(File master, File translation) throws GenerationException {
+ Map catalog = new HashMap();
+
+ // Parse master file
+ BaselineHandler baselineHandler = new BaselineHandler( catalog );
+ parser.setContentHandler( baselineHandler );
+ try {
+ parser.parse( master.getAbsolutePath() );
+ }
+ catch( IOException e ) {
+ throw new GenerationException( "unable to locate specified master [" + master.getAbsolutePath() + "]", e );
+ }
+ catch ( SAXException e ) {
+ throw new GenerationException( "error parsing master [" + master.getAbsolutePath() + "]", e );
+ }
+
+ log.debug( "encountered [" + catalog.size() + "] master content elements" );
+
+ Diff diff = new Diff();
+
+ // Parse translation
+ TranslationHandler translationHandler = new TranslationHandler( catalog, diff );
+ parser.setContentHandler( translationHandler );
+ try {
+ parser.parse( translation.getAbsolutePath() );
+ }
+ catch ( IOException e ) {
+ throw new GenerationException( "unable to locate specified translation [" + translation.getAbsolutePath() + "]", e );
+ }
+ catch ( SAXException e ) {
+ throw new GenerationException( "error parsing translation [" + translation.getAbsolutePath() + "]", e );
+ }
+
+ // as a final step, allow translation handler to finish up
+ translationHandler.finish();
+
+ return diff;
+ }
+
+ private XMLReader generateParser(boolean xincludeSupport) throws GenerationException {
+ try {
+ XMLReader parser = createParserFactory( xincludeSupport ).newSAXParser().getXMLReader();
+// 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 GenerationException( "unable to generate SAX Parser", e );
+ }
+ catch ( SAXNotRecognizedException e ) {
+ throw new GenerationException( "unable to generate SAX Parser", e );
+ }
+ catch ( ParserConfigurationException e ) {
+ throw new GenerationException( "unable to generate SAX Parser", e );
+ }
+ catch ( SAXException e ) {
+ throw new GenerationException( "unable to generate SAX Parser", e );
+ }
+ }
+
+ private SAXParserFactory createParserFactory(boolean xincludeSupport) {
+ SAXParserFactory factory = new SAXParserFactoryImpl();
+ factory.setXIncludeAware( xincludeSupport );
+ return factory;
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/GenerationException.java (from rev 11551, trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/docbook/revdiff/GenerationException.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/GenerationException.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/GenerationException.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,16 @@
+package org.jboss.maven.plugin.docbook.revdiff;
+
+/**
+ * Indicates problems generating the diff report
+ *
+ * @author Steve Ebersole
+ */
+public class GenerationException extends Exception {
+ public GenerationException(String message) {
+ super( message );
+ }
+
+ public GenerationException(String message, Throwable cause) {
+ super( message, cause );
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/IndexReportGenerator.java (from rev 11551, trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/docbook/revdiff/IndexReportGenerator.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/IndexReportGenerator.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/IndexReportGenerator.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,70 @@
+package org.jboss.maven.plugin.docbook.revdiff;
+
+import java.util.Locale;
+import java.util.List;
+import java.util.Iterator;
+import java.util.ResourceBundle;
+
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.reporting.MavenReportException;
+
+/**
+ * {@inheritDoc}
+ *
+ * @author Steve Ebersole
+ */
+public class IndexReportGenerator {
+ private final ResourceBundle bundle;
+ private final Sink sink;
+ private final Log log;
+
+ public static class TranslationReportDescriptor {
+ private final Locale translation;
+ private final String reportPath;
+
+ public TranslationReportDescriptor(Locale translation, String reportPath) {
+ this.translation = translation;
+ this.reportPath = reportPath;
+ }
+ }
+
+ public IndexReportGenerator(ResourceBundle bundle, Sink sink, Log log) {
+ this.bundle = bundle;
+ this.sink = sink;
+ this.log = log;
+ }
+
+ public void generate(List reportDescriptors) throws MavenReportException {
+ log.debug( "writing index report via provided sink" );
+ sink.head();
+ sink.text( bundle.getString( "report.name" ) );
+ sink.head_();
+
+ sink.body();
+ sink.sectionTitle1();
+ sink.anchor( bundle.getString( "report.header" ) );
+ sink.anchor_();
+ sink.text( bundle.getString( "report.header" ) );
+ sink.sectionTitle1_();
+
+ sink.table();
+ Iterator itr = reportDescriptors.iterator();
+ while ( itr.hasNext() ) {
+ final TranslationReportDescriptor descriptor = ( TranslationReportDescriptor ) itr.next();
+ sink.tableRow();
+ sink.tableCell();
+ sink.link( descriptor.reportPath );
+ sink.text( descriptor.translation.getDisplayName( Locale.ENGLISH ) + " (" + descriptor.translation.toString() + ")" );
+ sink.link_();
+ sink.tableCell_();
+ sink.tableRow_();
+ }
+ sink.table_();
+
+ sink.body_();
+ sink.flush();
+ sink.close();
+ log.debug( "index report sink flushed and closed" );
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/TranslationDiffReport.java (from rev 11551, trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/docbook/revdiff/TranslationDiffReport.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/TranslationDiffReport.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/TranslationDiffReport.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,271 @@
+package org.jboss.maven.plugin.docbook.revdiff;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import org.apache.maven.doxia.siterenderer.Renderer;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.reporting.AbstractMavenReport;
+import org.apache.maven.reporting.MavenReportException;
+import org.codehaus.plexus.util.DirectoryScanner;
+
+/**
+ * A plugin for generating a "translation diff" report across different
+ * translations of the same document. This is useful for the translators to
+ * know what changes exist between their translation and the master.
+ *
+ * @goal diff
+ *
+ * @author Christian Bauer
+ * @author Steve Ebersole
+ */
+public class TranslationDiffReport extends AbstractMavenReport {
+
+ public static final String NAME = "translation-diff-report";
+
+ /**
+ * The directory containing the translated DocBook sources.
+ *
+ * @parameter expression="${basedir}/src/main/docbook/translations"
+ * @required
+ */
+ private File translationsDirectory;
+
+ /**
+ * Directory where reports will go.
+ *
+ * @parameter expression="${project.reporting.outputDirectory}"
+ * @required
+ * @readonly
+ */
+ private File reportingDirectory;
+
+ /**
+ * Which translation is considered the master.
+ *
+ * @parameter default-value="en"
+ */
+ private String masterTranslation;
+
+ /**
+ * (non master) translations to be included in the report.
+ *
+ * @parameter
+ */
+ private String[] translationIncludes;
+
+ /**
+ * Patternsets of sources (relative to translationsDirectory) to include
+ * in reporting.
+ *
+ * @parameter
+ */
+ private String[] sourceIncludes;
+
+ /**
+ * A boolean, indicating if XInclude should be supported.
+ *
+ * @parameter default-value="false"
+ */
+ private boolean xincludeSupported;
+
+ /**
+ * Whether to build an aggregated report at the root, or build individual reports.
+ *
+ * @parameter expression="${aggregate}" default-value="false"
+ */
+ protected boolean aggregate;
+
+ /**
+ * @parameter expression="${project}"
+ * @required
+ * @readonly
+ */
+ private MavenProject project;
+
+ private File reportOutputDirectory;
+
+ /**
+ * @parameter expression="${component.org.apache.maven.doxia.siterenderer.Renderer}"
+ * @required
+ * @readonly
+ */
+ private Renderer siteRenderer;
+
+ protected Renderer getSiteRenderer() {
+ return siteRenderer;
+ }
+
+ protected MavenProject getProject() {
+ return project;
+ }
+
+ public String getCategoryName() {
+ return CATEGORY_PROJECT_REPORTS;
+ }
+
+ protected String getOutputDirectory() {
+ return getReportOutputDirectory().getAbsolutePath();
+ }
+
+ public String getOutputName() {
+ return "index";
+ }
+
+ public String getName(Locale locale) {
+ return getBundle( locale ).getString( "report.name" );
+ }
+
+ public String getDescription(Locale locale) {
+ return getBundle( locale ).getString( "report.description" );
+ }
+
+ private ResourceBundle getBundle(Locale locale) {
+ return ResourceBundle.getBundle( NAME, locale, this.getClass().getClassLoader() );
+ }
+
+ public void setReportOutputDirectory(File dir) {
+ if ( NAME.equals( dir.getName() ) ) {
+ this.reportOutputDirectory = dir;
+ }
+ else {
+ this.reportOutputDirectory = new File( dir, NAME );
+ }
+ }
+
+ public File getReportOutputDirectory() {
+ if ( reportOutputDirectory == null ) {
+ reportOutputDirectory = new File( reportingDirectory, NAME );
+ }
+ return reportOutputDirectory;
+ }
+
+ public boolean isExternalReport() {
+ return false;
+ }
+
+ public boolean canGenerateReport() {
+ return true;
+ }
+
+ protected void executeReport(Locale locale) throws MavenReportException {
+ getLog().debug( "starting docbook:diff goal execution [masterTranslation=" + masterTranslation + "]" );
+
+ if ( ! translationsDirectory.exists() ) {
+ getLog().debug( "translations directory [" + translationsDirectory.getAbsolutePath() + "] did not exist" );
+ return;
+ }
+
+ File masterTranslationDirectory = new File( translationsDirectory, masterTranslation );
+ if ( ! masterTranslationDirectory.exists() ) {
+ getLog().info( "master translation directory [" + masterTranslationDirectory.getAbsolutePath() + "] did not exist" );
+ return;
+ }
+
+ if ( translationIncludes == null || translationIncludes.length == 0 ) {
+ // use all translations...
+ ArrayList includes = new ArrayList();
+ File[] subdirs = translationsDirectory.listFiles();
+ for ( int i = 0; i < subdirs.length; i++ ) {
+ includes.add( subdirs[i].getName() );
+ }
+ translationIncludes = ( String[] ) includes.toArray( new String[ includes.size() ] );
+ }
+
+ if ( sourceIncludes == null || sourceIncludes.length == 0 ) {
+ sourceIncludes = new String[] { "*.xml" };
+ }
+
+ List reports = new ArrayList();
+ for ( int i = 0; i < translationIncludes.length; i++ ) {
+ if ( masterTranslation.equals( translationIncludes[i] ) ) {
+ continue;
+ }
+ final File translationDirectory = new File( translationsDirectory, translationIncludes[i] );
+ if ( ! translationDirectory.exists() ) {
+ getLog().info( "translation directory [" + translationDirectory.getAbsolutePath() + "] did not exist" );
+ continue;
+ }
+
+ if ( generateTranslationReport( masterTranslationDirectory, translationDirectory, translationIncludes[i] ) ) {
+ reports.add(
+ new IndexReportGenerator.TranslationReportDescriptor(
+ new Locale( translationIncludes[i] ),
+ NAME + "/" + buildTranslationReportName( translationIncludes[i] )
+ )
+ );
+ }
+ }
+
+ new IndexReportGenerator( getBundle( locale ), getSink(), getLog() ).generate( reports );
+ }
+
+ private void prepReportFile(File reportFile) throws MavenReportException {
+ if ( reportFile.exists() ) {
+ reportFile.delete();
+ }
+ if ( !reportFile.exists() ) {
+ try {
+ reportFile.createNewFile();
+ }
+ catch ( IOException e ) {
+ throw new MavenReportException( "unable to prep report file [" + reportFile.getAbsolutePath() + "]" );
+ }
+ }
+ }
+
+ private String buildTranslationReportName(String translationName) {
+ return "report-" + translationName + ".html";
+ }
+
+ private boolean generateTranslationReport(
+ File masterTranslationDirectory,
+ File translationDirectory,
+ String translationName) throws MavenReportException {
+ getLog().debug( "starting docbook:diff processing [translation=" + translationName + "]" );
+
+ DirectoryScanner scanner = new DirectoryScanner();
+ scanner.setBasedir( masterTranslationDirectory );
+ scanner.setIncludes( sourceIncludes );
+ scanner.scan();
+ String[] masterSources = scanner.getIncludedFiles();
+
+ scanner = new DirectoryScanner();
+ scanner.setBasedir( translationDirectory );
+ scanner.setIncludes( sourceIncludes );
+ scanner.scan();
+ String[] translationSources = scanner.getIncludedFiles();
+
+ if ( ! Arrays.equals( masterSources, translationSources ) ) {
+ getLog().warn( "includes returned different master and translation sets" );
+ return false;
+ }
+
+ Locale locale = new Locale( translationName );
+ File output = new File( getReportOutputDirectory(), buildTranslationReportName( translationName ) );
+ prepReportFile( output );
+
+ try {
+ DiffCreator diffCreator = new DiffCreator( xincludeSupported, getLog() );
+ TranslationReportGenerator generator = new TranslationReportGenerator( translationsDirectory, getBundle( locale ), getLog() );
+
+ for ( int i = 0; i < masterSources.length; i++ ) {
+ getLog().debug( "processing source [" + masterSources[i] + "]" );
+ final File master = new File( masterTranslationDirectory, masterSources[i] );
+ final File translation = new File( translationDirectory, translationSources[i] );
+ final Diff diff = diffCreator.findDiff( master, translation );
+ generator.generate( diff, output, locale.toString() );
+ }
+ }
+ catch ( GenerationException e ) {
+ throw new MavenReportException( "unable to generate report", e );
+ }
+ return true;
+ }
+
+}
Copied: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/TranslationHandler.java (from rev 11551, trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/docbook/revdiff/TranslationHandler.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/TranslationHandler.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/TranslationHandler.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,91 @@
+package org.jboss.maven.plugin.docbook.revdiff;
+
+import java.util.Map;
+import java.util.Iterator;
+
+import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+/**
+ * Handles actually discerning diffs between the translations based on the
+ * revision numbers of the content elements.
+ *
+ * @author Christian Bauer
+ * @author Steve Ebersole
+ */
+public class TranslationHandler extends DefaultHandler {
+ private final Map catalog;
+ private final Diff diff;
+ private Locator docLocator;
+
+ public TranslationHandler(Map catalog, Diff diff) {
+ this.catalog = catalog;
+ this.diff = diff;
+ }
+
+ public void setDocumentLocator(Locator locator) {
+ this.docLocator = locator;
+ }
+
+ public void startElement(
+ String namespaceURI,
+ String localName,
+ String qualifiedName,
+ Attributes atts) throws SAXException {
+
+ String identifier = atts.getValue( "id" );
+ if ( identifier != null ) {
+ int revision = 0;
+ if ( atts.getValue( "revision" ) != null ) {
+ revision = new Integer( atts.getValue( "revision" ) ).intValue();
+ }
+
+ ContentItemDescriptor translationState = new ContentItemDescriptor(
+ docLocator.getSystemId(),
+ qualifiedName,
+ revision,
+ docLocator.getLineNumber(),
+ docLocator.getColumnNumber()
+ );
+
+ // Locate the corresponding ContentItem from the master
+ //
+ // NOTE: we use remove to keep track of the fact that the transation
+ // has used that element; that way, afterwards, we know all the
+ // "unused" ones which would indicate elements recently added to
+ // the master...
+ ContentItem contentItem = ( ContentItem ) catalog.remove( identifier );
+ if ( contentItem == null ) {
+ // we have encountered an element in the translation which
+ // is not present in the master. This *should indicate that we
+ // have a section that was removed from the master, but not yet
+ // removed from the translation...
+ if ( revision != ContentItemDescriptor.REVISION_IGNORE ) {
+ contentItem = new ContentItem( identifier );
+ contentItem.setTranslationDescriptor( translationState );
+ diff.addOnlyInTranslation( contentItem );
+ }
+ }
+ else {
+ // the element is present in both; check the revisions
+ if ( revision != contentItem.getMasterDescriptor().getRevision() && revision != ContentItemDescriptor.REVISION_IGNORE ) {
+ contentItem.setTranslationDescriptor( translationState );
+ diff.addDiffRevision( contentItem );
+ }
+ }
+ }
+ }
+
+ public void finish() {
+ // anything left in the catalog at this point is stuff that is present
+ // in the master but absent from the translation...
+ Iterator itr = catalog.entrySet().iterator();
+ while ( itr.hasNext() ) {
+ final ContentItem contentItem = ( ContentItem ) ( ( Map.Entry ) itr.next() ).getValue();
+ itr.remove();
+ diff.addOnlyInMaster( contentItem );
+ }
+ }
+}
Copied: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/TranslationReportGenerator.java (from rev 11551, trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/docbook/revdiff/TranslationReportGenerator.java)
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/TranslationReportGenerator.java (rev 0)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/jboss/maven/plugin/docbook/revdiff/TranslationReportGenerator.java 2007-05-24 08:05:05 UTC (rev 11555)
@@ -0,0 +1,187 @@
+package org.jboss.maven.plugin.docbook.revdiff;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.ResourceBundle;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * Generate a diff report.
+ *
+ * @author Christian Bauer
+ * @author Steve Ebersole
+ */
+public class TranslationReportGenerator {
+ // todo : use templating...
+ private final String base;
+ private final ResourceBundle bundle;
+ private final Log log;
+
+ public TranslationReportGenerator(File basedir, ResourceBundle bundle, Log log) {
+ try {
+ this.base = basedir.toURL().toExternalForm();
+ }
+ catch ( MalformedURLException e ) {
+ throw new IllegalArgumentException( "basedir was a malformed url" );
+ }
+ log.debug( "constructing docbook diff report generator [base=" + base + "]" );
+ this.bundle = bundle;
+ this.log = log;
+ }
+
+ public void generate(Diff diff, File output, String translation) throws GenerationException {
+ if ( output.exists() ) {
+ log.debug( "cleaning up previous translation-diff report output [" + output.getAbsolutePath() + "]" );
+ output.delete();
+ }
+
+ File outputDirectory = output.getParentFile();
+ if ( !outputDirectory.exists() ) {
+ String outputDirectoryPath = outputDirectory.getAbsolutePath();
+ log.debug( "creating translation-diff report directory [" + outputDirectoryPath + "]" );
+ FileUtils.mkdir( outputDirectoryPath );
+ }
+
+ try {
+ output.createNewFile();
+ }
+ catch ( IOException e ) {
+ throw new GenerationException( "unable to create output file [" + output.getAbsolutePath() + "]", e );
+ }
+
+ try {
+ FileWriter writer = new FileWriter( output );
+ writer.write( pageHead( translation ) );
+
+ writer.write( "<table cellpadding=4>" );
+
+ writer.write( generateNewInMaster( diff ) );
+ writer.write( "<tr><td> </td></tr>" );
+ writer.write( generateDiffRevision( diff ) );
+ writer.write( "<tr><td> </td></tr>" );
+ writer.write( generateNewInTranslation( diff ) );
+
+ writer.write( "</table>" );
+ writer.write( pageFoot() );
+ writer.close();
+ }
+ catch ( IOException e ) {
+ throw new GenerationException( "error writing report [" + output.getAbsolutePath() + "]", e );
+ }
+ }
+
+ private String pageHead(String translation) {
+ StringBuffer buf = new StringBuffer( 256 );
+ buf.append( "<html><head><title>" ).append( bundle.getString( "report.name" ) ).append( "</title></head><body><div align=\"center\">" );
+ buf.append( "<h3>" ).append( bundle.getString( "report.header") ).append( " - " ).append( translation ).append( "</h3>" );
+ return buf.toString();
+ }
+
+ private String pageFoot() {
+ StringBuffer buf = new StringBuffer( 256 );
+ buf.append( "</div></body></html>" );
+ return buf.toString();
+ }
+
+ private String generateNewInMaster(Diff diff) {
+ StringBuffer buf = new StringBuffer();
+ Iterator itr = diff.getElementsOnlyInMaster();
+ while ( itr.hasNext() ) {
+ final ContentItem contentItem = ( ContentItem ) itr.next();
+ buf.append( "<tr><td bgcolor=#eeeeee>ID: " ).append( contentItem.getIdentifier() ).append( "</td></tr>" );
+ buf.append( "<tr><td>" );
+ buf.append( "<b>" ).append( formatReference( contentItem.getMasterDescriptor() ) ).append( "</b>" );
+ buf.append( "</td></tr>" );
+ }
+
+ String result = "";
+ if ( buf.length() > 0 ) {
+ result = "<tr bgcolor=#cccccc><td><b>New in master:</b></td></tr>";
+ }
+ return result + buf.toString();
+ }
+
+ private String generateDiffRevision(Diff diff) {
+ StringBuffer buf = new StringBuffer();
+ Iterator itr = diff.getElementsDiffRevision();
+ while ( itr.hasNext() ) {
+ final ContentItem contentItem = ( ContentItem ) itr.next();
+ buf.append( "<tr><td bgcolor=#eeeeee>ID: " ).append( contentItem.getIdentifier() ).append( "</td></tr>" );
+ if ( !contentItem.getMasterDescriptor().getElementName().equals( contentItem.getTranslationDescriptor().getElementName() ) ) {
+ buf.append( "<tr><td bgcolor=#ee6666>" );
+ buf.append( "Element names differ: " )
+ .append( contentItem.getMasterDescriptor().getElementName() )
+ .append( "/" )
+ .append( contentItem.getTranslationDescriptor().getElementName() );
+ buf.append( "</td></tr>" );
+ }
+ buf.append( "<tr><td>" );
+ buf.append( "Master: <b>" ).append( formatReference( contentItem.getMasterDescriptor() ) ).append( "</b>" );
+ buf.append( "</td></tr>" );
+ buf.append( "<tr><td>" );
+ buf.append( "Translation: <b>" ).append( formatReference( contentItem.getTranslationDescriptor() ) ).append( "</b>" );
+ buf.append( "</td></tr>" );
+ buf.append( "<tr><td>" );
+ buf.append( "Master Revision: " ).append( contentItem.getMasterDescriptor().getRevision() );
+ buf.append( "</td></tr>" );
+ buf.append( "<tr><td>" );
+ buf.append( "Translation Revision: " ).append( contentItem.getTranslationDescriptor().getRevision() );
+ buf.append( "</td></tr>" );
+ }
+
+ String result = "";
+ if ( buf.length() > 0 ) {
+ result = "<tr bgcolor=#cccccc><td><b>Translation needs update:</b></td></tr>";
+ }
+ return result + buf.toString();
+ }
+
+ private String generateNewInTranslation(Diff diff) {
+ StringBuffer buf = new StringBuffer();
+ Iterator itr = diff.getElementsOnlyInTranslation();
+ while ( itr.hasNext() ) {
+ final ContentItem contentItem = ( ContentItem ) itr.next();
+ buf.append( "<tr><td bgcolor=#eeeeee>ID: " ).append( contentItem.getIdentifier() ).append( "</td></tr>" );
+ buf.append( "<tr><td>" );
+ buf.append( "<b>" ).append( formatReference( contentItem.getTranslationDescriptor() ) ).append( "</b>" );
+ buf.append( "</td></tr>" );
+ }
+ String result = "";
+ if ( buf.length() > 0 ) {
+ result = "<tr bgcolor=#cccccc><td><b>Only present in translation:</b></td></tr>";
+ }
+ return result + buf.toString();
+ }
+
+ private String formatReference(ContentItemDescriptor descriptor) {
+ return makeSystemIdRelative( descriptor.getSourceSystemId() ) +
+ ":" + descriptor.getElementName() +
+ " (" + descriptor.getRow() + "," + descriptor.getColumn() + ")";
+ }
+
+ private String makeSystemIdRelative(String systemId) {
+ String systemIdUrl = toURL( systemId ).toExternalForm();
+ log.debug( "checking source [" + systemIdUrl + "] against base [" + base + "]" );
+ if ( systemIdUrl.startsWith( base ) ) {
+ return systemIdUrl.substring( base.length() );
+ }
+ else {
+ return systemIdUrl;
+ }
+ }
+
+ private URL toURL(String systemId) {
+ try {
+ return new URL( systemId );
+ }
+ catch ( MalformedURLException e ) {
+ throw new UnsupportedOperationException( "unable to parse systemId [" + systemId + "] as URL" );
+ }
+ }
+}
Modified: trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/resources/META-INF/plexus/components.xml
===================================================================
--- trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/resources/META-INF/plexus/components.xml 2007-05-24 04:31:40 UTC (rev 11554)
+++ trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/resources/META-INF/plexus/components.xml 2007-05-24 08:05:05 UTC (rev 11555)
@@ -3,7 +3,7 @@
<component>
<role>org.apache.maven.reporting.MavenReport</role>
<role-hint>diff</role-hint>
- <implementation>org.jboss.maven.docbook.revdiff.TranslationDiffReport</implementation>
+ <implementation>org.jboss.maven.plugin.docbook.revdiff.TranslationDiffReport</implementation>
<instantiation-strategy>per-lookup</instantiation-strategy>
</component>
</components>
More information about the hibernate-commits
mailing list