Initial custom dookbook.xsl
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package com.rackspace.cloud.api.docs;
|
||||
|
||||
import java.io.IOException;
|
||||
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;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
/**
|
||||
We are adding a customization layer ontop of the docbook one, so we
|
||||
need to distinguish when we wish to visit the original docbook
|
||||
entries or our entries.
|
||||
|
||||
The resolver helps us do this:
|
||||
|
||||
urn:docbkx:stylesheet-orig : will always point to the original
|
||||
stylesheets.
|
||||
**/
|
||||
public class DocBookResolver implements URIResolver {
|
||||
private URIResolver originalResolver;
|
||||
private String type;
|
||||
private static final Pattern urnPattern = Pattern.compile ("urn:docbkx:stylesheet\\-orig(/.*)?");
|
||||
|
||||
public DocBookResolver (URIResolver original, String type) {
|
||||
this.originalResolver = original;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Source resolve (String href, String base) throws TransformerException {
|
||||
Matcher m = urnPattern.matcher (href);
|
||||
if (m.matches()) {
|
||||
String grpMatch = m.group(1);
|
||||
String file = (m.group(1) == null) ? "/docbook.xsl" : grpMatch;
|
||||
String filePath = "docbook/"+type+file;
|
||||
|
||||
URL url = this.getClass().getClassLoader().getResource(filePath);
|
||||
|
||||
if (url != null) {
|
||||
try {
|
||||
return new StreamSource (url.openStream(), url.toExternalForm());
|
||||
}catch (IOException ioe) {
|
||||
throw new TransformerException ("Can't get docbook refrence "+href+"->"+filePath, ioe);
|
||||
}
|
||||
} else {
|
||||
throw new TransformerException ("Can't resolve docbook link: "+href+"->"+filePath+" Docbook missing in classpath?");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// We can't resolve, maybe the next resolver in the chain
|
||||
// can.
|
||||
//
|
||||
if (originalResolver != null) {
|
||||
return originalResolver.resolve (href, base);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,15 @@ package com.rackspace.cloud.api.docs;
|
||||
import java.io.File;
|
||||
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.URIResolver;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
|
||||
import com.agilejava.docbkx.maven.TransformerBuilder;
|
||||
import com.agilejava.docbkx.maven.AbstractPdfMojo;
|
||||
|
||||
import com.rackspace.cloud.api.docs.FileUtils;
|
||||
import com.rackspace.cloud.api.docs.DocBookResolver;
|
||||
|
||||
public abstract class PDFMojo extends AbstractPdfMojo {
|
||||
private File imageDirectory;
|
||||
@@ -19,9 +24,11 @@ public abstract class PDFMojo extends AbstractPdfMojo {
|
||||
return this.imageDirectory;
|
||||
}
|
||||
|
||||
/*
|
||||
Setup..
|
||||
*/
|
||||
protected String getNonDefaultStylesheetLocation() {
|
||||
return "cloud/fo/dookbook.xsl";
|
||||
}
|
||||
|
||||
|
||||
public void preProcess() throws MojoExecutionException {
|
||||
super.preProcess();
|
||||
|
||||
@@ -39,6 +46,10 @@ public abstract class PDFMojo extends AbstractPdfMojo {
|
||||
setImageDirectory (new File (imageParentDirectory, "images"));
|
||||
}
|
||||
|
||||
protected TransformerBuilder createTransformerBuilder(URIResolver resolver) {
|
||||
return super.createTransformerBuilder (new DocBookResolver (resolver, getType()));
|
||||
}
|
||||
|
||||
public void adjustTransformer(Transformer transformer, String sourceFilename, File targetFile) {
|
||||
super.adjustTransformer(transformer, sourceFilename, targetFile);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user