Skip to content

Commit

Permalink
Merge pull request #102 from ndw/main
Browse files Browse the repository at this point in the history
Fixes for problems in 1.4.0, bug fixes
  • Loading branch information
ndw authored May 9, 2021
2 parents f5c8bd9 + 79e5599 commit 5216cef
Show file tree
Hide file tree
Showing 26 changed files with 723 additions and 498 deletions.
642 changes: 343 additions & 299 deletions build.gradle

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
}

repositories {
mavenLocal()
mavenCentral()
}

Expand Down
Binary file added libs/com.nwalsh.saxon-gradle-0.9.1-beta3.jar
Binary file not shown.
28 changes: 14 additions & 14 deletions properties.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// These are properties shared by the project and buildSrc
ext {
xslTNGtitle = "DocBook xslTNG"
xslTNGbaseName = "docbook-xslTNG"
xslTNGversion = "1.4.0"
guideVersion = "1.4.0"
xslTNGtitle = 'DocBook xslTNG'
xslTNGbaseName = 'docbook-xslTNG'
xslTNGversion = '1.4.1'
guideVersion = '1.4.1'

saxonVersion = "10.5"
saxonGroup = "net.sf.saxon"
saxonEdition = "Saxon-HE"
//saxonGroup = "com.saxonica"
//saxonEdition = "Saxon-EE"
saxonVersion = '10.5'
saxonGroup = 'net.sf.saxon'
saxonEdition = 'Saxon-HE'
//saxonGroup = 'com.saxonica'
//saxonEdition = 'Saxon-EE'

metadataExtractorVersion = "2.14.0"
jingVersion = "20181222"
xmlresolverVersion = "1.1.0"
sincludeVersion = "0.9.2"
slf4jVersion = "1.7.25"
metadataExtractorVersion = '2.15.0'
jingVersion = '20181222'
xmlresolverVersion = '2.1.0'
sincludeVersion = '1.1.0'
slf4jVersion = '1.7.30'
}
13 changes: 13 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pluginManagement {
// includeBuild "/Users/ndw/Projects/xml/saxon-gradle/"
buildscript {
repositories {
mavenCentral()
flatDir { dirs "libs" }
}
dependencies {
classpath "net.sf.saxon:Saxon-HE:10.5"
classpath ':com.nwalsh.saxon-gradle:0.9.1-beta3'
}
}
}
10 changes: 10 additions & 0 deletions src/guide/xml/ref-variables.xml
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,11 @@ element (local) names to placements. The placement is either
selected (see <parameter>verbatim-syntax-highlighter</parameter>), these elements are
added to the <tag namespace="http://www.w3.org/1999/xhtml">head</tag> element to
load and configure the highlighter.</para>
<para>Starting with the <citetitle>DocBook xslTNG Stylesheets</citetitle> version 1.4.1,
any <tag namespace="http://www.w3.org/1999/xhtml">link</tag> elements will be
added to the <tag namespace="http://www.w3.org/1999/xhtml">head</tag> element
<emphasis>before</emphasis> links to user-defined CSS files so that property overrides
may be specified.</para>
</refsection>
</refentry>

Expand Down Expand Up @@ -843,6 +848,11 @@ This variable contains the list of known ways, see
selected (see <parameter>verbatim-syntax-highlighter</parameter>), these elements are
added to the <tag namespace="http://www.w3.org/1999/xhtml">head</tag> element to
load and configure the highlighter.</para>
<para>Starting with the <citetitle>DocBook xslTNG Stylesheets</citetitle> version 1.4.1,
any <tag namespace="http://www.w3.org/1999/xhtml">link</tag> elements will be
added to the <tag namespace="http://www.w3.org/1999/xhtml">head</tag> element
<emphasis>before</emphasis> links to user-defined CSS files so that property overrides
may be specified.</para>
</refsection>
</refentry>

Expand Down
167 changes: 4 additions & 163 deletions src/main/java/org/docbook/xsltng/Main.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
package org.docbook.xsltng;

import net.sf.saxon.Transform;
import net.sf.saxon.s9api.DocumentBuilder;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.ValidationMode;
import net.sf.saxon.s9api.XdmAtomicValue;
import net.sf.saxon.s9api.XdmDestination;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
import net.sf.saxon.s9api.XsltTransformer;
import net.sf.saxon.trans.CommandLineOptions;
import org.docbook.xsltng.extensions.DebuggingLogger;
import org.xml.sax.InputSource;

import javax.xml.transform.sax.SAXSource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.JarURLConnection;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.security.CodeSource;
import java.util.Properties;
import java.util.Vector;

public class Main extends Transform {
Expand All @@ -38,12 +15,9 @@ public class Main extends Transform {
private boolean stylesheetReader = false;
private boolean init = false;

protected Processor processor = null;
protected DebuggingLogger logger = null;
protected String version = null;
protected String jarLoc = null;
protected String catalogFile = null;
protected Properties configProperties = null;
protected XslTNG xslTNG = null;

public static void main(String[] args) {
Main instance = new Main(args);
Expand All @@ -66,35 +40,9 @@ public Main(String[] args) {
}
}

processor = new Processor(false); // I need one for a bit...
logger = new DebuggingLogger(processor.getUnderlyingConfiguration().getLogger());
findJarLocation();
logger.debug("main", "jarLoc=" + jarLoc);
createCatalog(System.getProperty("org.docbook.xsltng.catalog-file"));
}

public void findJarLocation() {
CodeSource src = Main.class.getProtectionDomain().getCodeSource();
String classLoc = src.getLocation().toString();
logger.debug("main", "classLoc=" + classLoc);

if (classLoc.endsWith(".jar")) {
jarLoc = "jar:" + classLoc + "!";
} else {
// This is only supposed to happen on a dev box; if you're integrating this into some bigger
// application, well, sorry, it's all a bit of a hack if it's not in the jar. Override this
// method and do the right thing...
if (classLoc.indexOf("/build/") > 0) {
jarLoc = classLoc + "../../../stage/jar";
try {
loadProperties();
} catch (UnsupportedOperationException e) {
logger.warning("Jar location incomplete: " + jarLoc);
}
} else {
throw new RuntimeException("org.docbook.xsltng.Main cannot find root from " + classLoc);
}
}
xslTNG = new XslTNG();
logger = xslTNG.logger;
catalogFile = xslTNG.createCatalog(System.getProperty("org.docbook.xsltng.catalog-file"));
}

public void run() {
Expand Down Expand Up @@ -136,113 +84,6 @@ public void run() {
System.exit(0);
}

public String createCatalog(String catalogFilename) {
if (catalogFile != null) {
if (catalogFilename == null || catalogFile.equals(catalogFilename)) {
return catalogFile;
}
}

try {
Processor processor = new Processor(false);
DocumentBuilder builder = processor.newDocumentBuilder();
builder.setDTDValidation(false);
builder.setLineNumbering(true);

URL uris_url = new URL(jarLoc + "/etc/uris.xml");
URL xsl_url = new URL(jarLoc + "/etc/make-catalog.xsl");

InputSource uris_src = new InputSource(getStream(uris_url));
InputSource xsl_src = new InputSource(getStream(xsl_url));

uris_src.setSystemId(uris_url.toURI().toASCIIString());
xsl_src.setSystemId(xsl_url.toURI().toASCIIString());

XdmNode uris = builder.build(new SAXSource(uris_src));
XdmNode xsl = builder.build(new SAXSource(xsl_src));

XsltCompiler compiler = processor.newXsltCompiler();
compiler.setSchemaAware(false);
XsltExecutable exec = compiler.compile(xsl.asSource());
XsltTransformer transformer = exec.load();

transformer.setParameter(new QName("", "jarloc"), new XdmAtomicValue(jarLoc));
transformer.setParameter(new QName("", "version"), new XdmAtomicValue(version()));
transformer.setInitialContextNode(uris);

XdmDestination xresult = new XdmDestination();
transformer.setDestination(xresult);

transformer.setSchemaValidationMode(ValidationMode.DEFAULT);
transformer.transform();
XdmNode xformed = xresult.getXdmNode();

File tempcat = null;
if (catalogFilename == null) {
tempcat = File.createTempFile("dbcat", ".xml");
tempcat.deleteOnExit();
} else {
tempcat = new File(catalogFilename);
}

logger.debug("main", "Transient catalog file: " + tempcat.getAbsolutePath());

PrintStream catstream = new PrintStream(tempcat);
catstream.print(xformed.toString());
catstream.close();

catalogFile = tempcat.getAbsolutePath();
return catalogFile;
} catch (SaxonApiException | IOException | URISyntaxException sae) {
logger.info("org.docbook.XSLT20 failed to create catalog: " + sae.getMessage());
throw new RuntimeException(sae);
}
}

protected InputStream getStream(URL url) {
URLConnection conn = null;
try {
try {
conn = (JarURLConnection) url.openConnection();
} catch (ClassCastException cce) {
conn = url.openConnection();
}

return conn.getInputStream();
} catch (IOException ioe) {
throw new RuntimeException("Cannot read: " + url.toString());
}
}

protected String version() {
if (version != null) {
return version;
}

loadProperties();
version = configProperties.getProperty("version");
if (version == null) {
throw new UnsupportedOperationException("No version property in version.properties!?");
}
return version;
}

private void loadProperties() {
if (configProperties != null) {
return;
}

configProperties = new Properties();
InputStream stream = null;
try {
URL version_url = new URL(jarLoc + "/etc/version.properties");
stream = getStream(version_url);
configProperties.load(stream);
} catch (IOException ioe) {
throw new UnsupportedOperationException("Failed to load version.properties file from JAR!?");
}
}

@Override
protected void badUsage(String message) {
if (!"".equals(message)) {
Expand Down
Loading

0 comments on commit 5216cef

Please sign in to comment.