Author: steve.ebersole(a)jboss.com
Date: 2007-06-24 01:32:19 -0400 (Sun, 24 Jun 2007)
New Revision: 11710
Added:
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/OLinkDBUpdater.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/util/NoOpWriter.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/util/StaleSourceChecker.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/TransformerFactory.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/resolve/BasicUrnResolver.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/resolve/CurrentVersionResolver.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/resolve/ExplicitUrnResolver.java
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/resolve/RelativeJarUriResolver.java
Log:
still more prep move to codehaus
Added:
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/OLinkDBUpdater.java
===================================================================
---
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/OLinkDBUpdater.java
(rev 0)
+++
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/OLinkDBUpdater.java 2007-06-24
05:32:19 UTC (rev 11710)
@@ -0,0 +1,277 @@
+/*
+ * maven-docbook-plugin - Copyright (C) 2005 OPEN input -
http://www.openinput.com/
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.codehaus.mojo.docbook;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.maven.plugin.logging.Log;
+import org.codehaus.mojo.docbook.gen.util.NoOpWriter;
+import org.codehaus.mojo.docbook.gen.util.ResourceHelper;
+import org.codehaus.mojo.docbook.gen.util.StandardDocBookFormatSpecification;
+import org.codehaus.plexus.compiler.util.scan.InclusionScanException;
+import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
+import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping;
+import org.codehaus.plexus.util.DirectoryScanner;
+
+/**
+ * @author jgonzalez
+ */
+public class OLinkDBUpdater
+{
+ // todo (steve) : make this a mojo, and assign it a phase in the lifecycle...
+ protected Log log;
+ protected File sourceDirectory;
+ protected File databaseDirectory;
+
+ public OLinkDBUpdater(Log log, File sourceDirectory, File databaseDirectory)
+ {
+ this.log = log;
+ this.sourceDirectory = sourceDirectory;
+ this.databaseDirectory = databaseDirectory;
+ }
+
+ public void update()
+ {
+ StaleSourceScanner scanner = new StaleSourceScanner( 0, Collections.singleton(
"**/*.xml" ),
+ Collections.EMPTY_SET );
+ scanner.addSourceMapping( new SuffixMapping( ".xml",
".xml.db" ) );
+
+ Set staleDocbookFiles;
+ try
+ {
+ staleDocbookFiles = scanner.getIncludedSources( this.sourceDirectory,
this.databaseDirectory );
+ }
+ catch ( InclusionScanException e )
+ {
+ throw new RuntimeException( "Error scanning sources in " +
sourceDirectory, e );
+ }
+
+ if ( !staleDocbookFiles.isEmpty() )
+ {
+ DirectoryScanner docbookScanner = new DirectoryScanner();
+ docbookScanner.setBasedir( this.sourceDirectory );
+ docbookScanner.setFollowSymlinks( true );
+ docbookScanner.setIncludes( new String[] { "**/*.xml" } );
+ docbookScanner.scan();
+ String[] docbookFiles = docbookScanner.getIncludedFiles();
+
+ this.prepareFileSystem( docbookFiles );
+ this.updateOLinkDatabase( staleDocbookFiles );
+ this.createMasterOLinkDatabase( docbookFiles );
+ }
+ else
+ {
+ this.log.info( "olink database up to date" );
+ }
+ }
+
+ protected void prepareFileSystem( String[] docbookFiles )
+ {
+ log.debug( "Creating database directories for the following files - "
+ + Arrays.asList( docbookFiles ).toString() );
+ // TODO: This should be a bit smarter also, shouldn't it?
+ for ( int fileIndex = 0; fileIndex < docbookFiles.length; fileIndex++ )
+ {
+ String docbookFile = docbookFiles[fileIndex];
+ int lastFileSeparator = docbookFile.lastIndexOf( File.separator );
+ if ( lastFileSeparator > 0 )
+ {
+ File directory = new File( this.databaseDirectory, docbookFile.substring(
0, lastFileSeparator ) );
+ directory.mkdirs();
+ }
+ }
+ }
+
+ protected void updateOLinkDatabase( Set docbookFiles )
+ {
+ this.log.info( "Loading olink database generation stylesheet" );
+ Source docbookStyleSheetSource = new StreamSource(
+ ResourceHelper.requireResource(
+ StandardDocBookFormatSpecification.XHTML.getStylesheetResource()
+ ).toString()
+ );
+ Transformer olinkDBGenerator;
+ try
+ {
+ TransformerFactory factory = TransformerFactory.newInstance();
+ olinkDBGenerator = factory.newTransformer( docbookStyleSheetSource );
+ }
+ catch ( TransformerException e )
+ {
+ throw new RuntimeException( "Unable to get a transformer instance from
source " + docbookStyleSheetSource.getSystemId(), e );
+ }
+ olinkDBGenerator.setParameter( "collect.xref.targets", "only"
);
+ olinkDBGenerator.setParameter( "generate.toc", "" );
+
+ this.log.info( "Creating olink database for " + docbookFiles.size() +
" Docbook stale file(s)" );
+ Iterator filesIterator = docbookFiles.iterator();
+ while ( filesIterator.hasNext() )
+ {
+ File docbookFile = (File) filesIterator.next();
+ this.log.debug( "Processing " + this.sourceDirectory +
File.separator + docbookFile );
+
+ String relativePath = docbookFile.getAbsolutePath().substring(
this.sourceDirectory.getAbsolutePath().length() );
+ File databaseFile = new File( this.databaseDirectory, relativePath +
".db" );
+ Source source = new StreamSource( docbookFile );
+ Result result = new StreamResult( new NoOpWriter() );
+
+ olinkDBGenerator.setParameter( "targets.filename",
databaseFile.getAbsolutePath() );
+
+ try
+ {
+ olinkDBGenerator.transform( source, result );
+ }
+ catch ( TransformerException e )
+ {
+ throw new RuntimeException( "Unable to transform from source "
+ source.getSystemId() + " into " + result.getSystemId(), e );
+ }
+
+ this.log.debug( "Generated " + this.databaseDirectory +
File.separator + docbookFile );
+ }
+ }
+
+ protected void createMasterOLinkDatabase( String[] docbookFiles )
+ {
+ File file = new File( this.databaseDirectory + System.getProperty(
"file.separator" ) + "olinkdb.xml" );
+ this.log.info( "Creating master olink database file " + file );
+ try
+ {
+ BufferedWriter masterOlinkDBFile = new BufferedWriter( new FileWriter( file
));
+
+ // Write header
+ masterOlinkDBFile.write( "<?xml version=\"1.0\"
encoding=\"utf-8\"?>" );
+ masterOlinkDBFile.newLine();
+ masterOlinkDBFile.write( "<!DOCTYPE targetset SYSTEM \""
);
+// masterOlinkDBFile.write( this.stylesheetLocation.resolve(
"common/targetdatabase.dtd" ).toString() );
+ masterOlinkDBFile.write( "\" >" );
+ masterOlinkDBFile.newLine();
+
+ masterOlinkDBFile.write( "<targetset>" );
+ masterOlinkDBFile.newLine();
+ masterOlinkDBFile.write( " <sitemap>" );
+ masterOlinkDBFile.newLine();
+ masterOlinkDBFile.write( " <dir name=\"root\">"
);
+ masterOlinkDBFile.newLine();
+
+ this.writeDirectoryTagBody( masterOlinkDBFile, 1, "", docbookFiles
);
+
+ masterOlinkDBFile.write( " </dir>" );
+ masterOlinkDBFile.newLine();
+ masterOlinkDBFile.write( " </sitemap>" );
+ masterOlinkDBFile.newLine();
+ masterOlinkDBFile.write( "</targetset>" );
+ masterOlinkDBFile.newLine();
+
+ masterOlinkDBFile.close();
+ }
+ catch ( IOException e )
+ {
+ throw new RuntimeException( "Error creating OLink database " +
file, e );
+ }
+ }
+
+ protected void writeDirectoryTagBody( BufferedWriter writer, int level, String
currentDirectory, String[] files )
+ throws IOException
+ {
+ int currentDirectoryLength = currentDirectory.length();
+ String lastRelativeDirectory = "";
+ List subdirectory = new LinkedList();
+
+ for ( int fileIndex = 0; fileIndex < files.length; fileIndex++ )
+ {
+ String file = files[fileIndex];
+ String relativeFile = file.substring( currentDirectoryLength );
+ if ( relativeFile.indexOf( File.separator ) == -1 )
+ {
+ String fileID = OLinkDBUpdater.computeFileID( file );
+ writer.write( OLinkDBUpdater.indenting( level ) + "<document
targetdoc=\"" );
+ writer.write( fileID );
+ writer.write( "\" baseuri=\"" );
+ writer.write( relativeFile.substring( 0, relativeFile.lastIndexOf(
"." ) ) + ".html\">" );
+ writer.write( "<xi:include
xmlns:xi=\"http://www.w3.org/2003/XInclude\" href=\"" );
+ writer.write( file.replace( File.separatorChar, '/' ) +
".db\"/>" );
+ writer.write( "</document>" );
+ writer.newLine();
+ }
+ else
+ {
+ String relativeDirectory = relativeFile.substring( 0,
relativeFile.indexOf( File.separator ) );
+ if ( !relativeDirectory.equals( lastRelativeDirectory ) )
+ {
+ if ( !subdirectory.isEmpty() )
+ {
+ writer.write( OLinkDBUpdater.indenting( level ) + "<dir
name=\"" + lastRelativeDirectory
+ + "\">" );
+ writer.newLine();
+ this.writeDirectoryTagBody( writer, level + 1, currentDirectory +
File.separator
+ + lastRelativeDirectory, (String[]) subdirectory.toArray( new
String[ subdirectory.size() ] ) );
+ writer.write( OLinkDBUpdater.indenting( level ) +
"</dir>" );
+ writer.newLine();
+ }
+ lastRelativeDirectory = relativeDirectory;
+ subdirectory.clear();
+ }
+ subdirectory.add( file );
+ }
+ }
+
+ if ( !subdirectory.isEmpty() )
+ {
+ writer.write( OLinkDBUpdater.indenting( level ) + "<dir
name=\"" + lastRelativeDirectory + "\">" );
+ writer.newLine();
+ this.writeDirectoryTagBody( writer, level + 1, currentDirectory +
File.separator + lastRelativeDirectory,
+ (String[]) subdirectory.toArray( new String[
subdirectory.size() ] ) );
+ writer.write( OLinkDBUpdater.indenting( level ) + "</dir>"
);
+ writer.newLine();
+ }
+ }
+
+ public static String computeFileID( String docbookFileName )
+ {
+ String fileID = docbookFileName;
+ if ( docbookFileName.indexOf( File.separator ) == 0 )
+ {
+ fileID = docbookFileName.substring( File.separator.length() );
+ }
+
+ return fileID.replace( File.separatorChar, '-' );
+ }
+
+ protected static String indenting( int level )
+ {
+ StringBuffer indent = new StringBuffer( " " );
+ for ( int currentLevel = 1; currentLevel < level; currentLevel++ )
+ {
+ indent.append( " " );
+ }
+ return indent.toString();
+ }
+
+}
Added:
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/util/NoOpWriter.java
===================================================================
---
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/util/NoOpWriter.java
(rev 0)
+++
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/util/NoOpWriter.java 2007-06-24
05:32:19 UTC (rev 11710)
@@ -0,0 +1,35 @@
+/*
+ * Copyright © 2007 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.codehaus.mojo.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/codehaus/mojo/docbook/gen/util/StaleSourceChecker.java
===================================================================
---
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/util/StaleSourceChecker.java
(rev 0)
+++
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/util/StaleSourceChecker.java 2007-06-24
05:32:19 UTC (rev 11710)
@@ -0,0 +1,30 @@
+package org.codehaus.mojo.docbook.gen.util;
+
+import java.io.File;
+import java.util.Collections;
+
+import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
+import org.codehaus.plexus.compiler.util.scan.InclusionScanException;
+import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping;
+
+/**
+ * Delegate used for checking sources for staleness.
+ *
+ * @author Steve Ebersole
+ */
+public class StaleSourceChecker {
+ public static boolean hasStaleSources(File sourceDirectory, File databaseDirectory) {
+ try {
+ StaleSourceScanner scanner = new StaleSourceScanner(
+ 0,
+ Collections.singleton( "**/*.xml" ),
+ Collections.EMPTY_SET
+ );
+ scanner.addSourceMapping( new SuffixMapping( ".xml", ".xml.db" )
);
+ return ! scanner.getIncludedSources( sourceDirectory, databaseDirectory ).isEmpty();
+ }
+ catch ( InclusionScanException e ) {
+ throw new RuntimeException( "Error scanning sources in " +
sourceDirectory, e );
+ }
+ }
+}
Added:
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/TransformerFactory.java
===================================================================
---
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/TransformerFactory.java
(rev 0)
+++
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/TransformerFactory.java 2007-06-24
05:32:19 UTC (rev 11710)
@@ -0,0 +1,139 @@
+/*
+ * Copyright © 2007 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.codehaus.mojo.docbook.gen.xslt;
+
+import java.io.IOException;
+import java.net.URL;
+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.icl.saxon.Controller;
+import org.apache.xml.resolver.tools.CatalogResolver;
+import org.codehaus.mojo.docbook.gen.XSLTException;
+import org.codehaus.mojo.docbook.gen.util.Formatting;
+import org.codehaus.mojo.docbook.gen.util.NoOpWriter;
+import org.codehaus.mojo.docbook.gen.util.ResourceHelper;
+import org.codehaus.mojo.docbook.gen.util.StandardDocBookFormatSpecification;
+import org.codehaus.mojo.docbook.gen.util.TransformerType;
+import org.codehaus.mojo.docbook.gen.xslt.resolve.CurrentVersionResolver;
+import org.codehaus.mojo.docbook.gen.xslt.resolve.ExplicitUrnResolver;
+import org.codehaus.mojo.docbook.gen.xslt.resolve.RelativeJarUriResolver;
+import org.codehaus.mojo.docbook.gen.xslt.resolve.ResolverChain;
+import org.codehaus.mojo.docbook.gen.xslt.resolve.VersionResolver;
+
+/**
+ * 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;
+ private final String docbookVersion;
+
+ public TransformerFactory(
+ TransformerType transformerType,
+ Properties transformerParameters,
+ CatalogResolver catalogResolver,
+ String docbookVersion) {
+ this.transformerType = transformerType;
+ this.transformerParameters = transformerParameters;
+ this.catalogResolver = catalogResolver;
+ this.docbookVersion = docbookVersion;
+ }
+
+ public Transformer buildTransformer(Formatting formatting, URL customStylesheet) throws
XSLTException {
+ URIResolver uriResolver = buildUriResolver( formatting.getStandardDocBookSpec() );
+
+ javax.xml.transform.TransformerFactory transformerFactory = buildTransformerFactory();
+ transformerFactory.setURIResolver( uriResolver );
+
+ URL xsltStylesheet = customStylesheet == null
+ ? ResourceHelper.requireResource( formatting.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() );
+ }
+ }
+
+ public URIResolver buildUriResolver(StandardDocBookFormatSpecification formatType)
throws XSLTException {
+ ResolverChain resolverChain = new ResolverChain();
+ if ( formatType != null ) {
+ resolverChain.addResolver( new ExplicitUrnResolver( formatType ) );
+ }
+ resolverChain.addResolver( new CurrentVersionResolver() );
+ if ( docbookVersion != null ) {
+ resolverChain.addResolver( new VersionResolver( docbookVersion ) );
+ }
+ resolverChain.addResolver( new RelativeJarUriResolver() );
+ resolverChain.addResolver( catalogResolver );
+ return resolverChain;
+ }
+}
Added:
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/resolve/BasicUrnResolver.java
===================================================================
---
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/resolve/BasicUrnResolver.java
(rev 0)
+++
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/resolve/BasicUrnResolver.java 2007-06-24
05:32:19 UTC (rev 11710)
@@ -0,0 +1,44 @@
+/*
+ * Copyright © 2007 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.codehaus.mojo.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/codehaus/mojo/docbook/gen/xslt/resolve/CurrentVersionResolver.java
===================================================================
---
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/resolve/CurrentVersionResolver.java
(rev 0)
+++
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/resolve/CurrentVersionResolver.java 2007-06-24
05:32:19 UTC (rev 11710)
@@ -0,0 +1,29 @@
+/*
+ * Copyright © 2007 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.codehaus.mojo.docbook.gen.xslt.resolve;
+
+/**
+ * Map hrefs starting with
<
tt>http://docbook.sourceforge.net/release/xsl/current/</tt>
+ * to classpath resource lookups.
+ *
+ * @author Steve Ebersole
+ */
+public class CurrentVersionResolver extends VersionResolver {
+
+ public CurrentVersionResolver() {
+ super( "current" );
+ }
+}
Added:
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/resolve/ExplicitUrnResolver.java
===================================================================
---
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/resolve/ExplicitUrnResolver.java
(rev 0)
+++
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/resolve/ExplicitUrnResolver.java 2007-06-24
05:32:19 UTC (rev 11710)
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 2007 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.codehaus.mojo.docbook.gen.xslt.resolve;
+
+import java.io.IOException;
+import java.net.URL;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.codehaus.mojo.docbook.gen.XSLTException;
+import org.codehaus.mojo.docbook.gen.util.ResourceHelper;
+import org.codehaus.mojo.docbook.gen.util.StandardDocBookFormatSpecification;
+
+
+/**
+ * Resolves an explicit <tt>urn:docbook:stylesheet</tt> URN against the
standard
+ * DocBook stylesheets.
+ *
+ * @author Steve Ebersole
+ */
+public class ExplicitUrnResolver extends BasicUrnResolver {
+ private final StandardDocBookFormatSpecification formatType;
+
+ public ExplicitUrnResolver(StandardDocBookFormatSpecification type) throws XSLTException
{
+ super( "urn:docbook:stylesheet", createSource( type ) );
+ this.formatType = type;
+ }
+
+ private static Source createSource(StandardDocBookFormatSpecification 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/codehaus/mojo/docbook/gen/xslt/resolve/RelativeJarUriResolver.java
===================================================================
---
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/resolve/RelativeJarUriResolver.java
(rev 0)
+++
trunk/sandbox/maven-poc/plugins/maven-jboss-docbook-plugin/src/main/java/org/codehaus/mojo/docbook/gen/xslt/resolve/RelativeJarUriResolver.java 2007-06-24
05:32:19 UTC (rev 11710)
@@ -0,0 +1,51 @@
+/*
+ * Copyright © 2007 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, v. 2.1. This program is distributed in the
+ * hope that it will be useful, but WITHOUT A WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details. You should have received a
+ * copy of the GNU Lesser General Public License, v.2.1 along with this
+ * distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Red Hat Author(s): Steve Ebersole
+ */
+package org.codehaus.mojo.docbook.gen.xslt.resolve;
+
+import java.net.URL;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.stream.StreamSource;
+
+/**
+ * Responsible for resolving relative references from jar base urls.
+ *
+ * @author Steve Ebersole
+ */
+public class RelativeJarUriResolver implements URIResolver {
+ public Source resolve(String href, String base) throws TransformerException {
+ // href need to be relative
+ if ( href.indexOf( "://" ) > 0 || href.startsWith( "/" ) ) {
+ return null;
+ }
+
+ // base would need to start with jar:
+ if ( !base.startsWith( "jar:" ) ) {
+ return null;
+ }
+
+ String fullHref = base.substring( 4, base.lastIndexOf( '/' ) + 1 )
+ + href;
+ try {
+ URL url = new URL( fullHref );
+ return new StreamSource( url.openStream(), url.toExternalForm() );
+ }
+ catch ( Throwable t ) {
+ return null;
+ }
+ }
+}