Skip to content

Commit

Permalink
Rework Java initialization to support the -catalog option
Browse files Browse the repository at this point in the history
  • Loading branch information
ndw committed Oct 9, 2024
1 parent 7688aa3 commit 8fa6280
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
10 changes: 10 additions & 0 deletions src/guide/xml/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ development continues.</para>
“<code>portrait</code>” in their <att>class</att> attribute. At present, this has no
effect in the browser presentation.</para>
</listitem>
<listitem>
<para>Reworked Java initialization;
fixed <link xlink:href="https://github.com/docbook/xslTNG/issues/504">#504</link>. The
only way to specify a catalog file is with the <code>-catalog</code> option, and only one
catalog can be specified. (You can work around this limitation by making a catalog that
includes other catalogs.)</para>
<para>This change in behavior is a consequence of how Saxon initializes the XML Resolver.
</para>
</listitem>

</itemizedlist>
</section>

Expand Down
33 changes: 10 additions & 23 deletions src/main/java/org/docbook/xsltng/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@

public class Main extends Transform {
Vector<String> userArgs = new Vector<>();
private Vector<String> userCatalogFiles = new Vector<> ();
private boolean userStylesheet = false;
private boolean uriResolver = false;
private boolean sourceReader = false;
private boolean stylesheetReader = false;
private boolean init = false;
private int catalogCount = 0;

protected DebuggingLogger logger = null;
protected String catalogFile = null;
protected XslTNG xslTNG = null;

public static void main(String[] args) {
Expand All @@ -25,43 +24,32 @@ public static void main(String[] args) {
}

public Main(String[] args) {
int pos = 0;
for (String arg : args) {
uriResolver = uriResolver || arg.startsWith("-r:");
sourceReader = sourceReader || arg.startsWith("-x:");
stylesheetReader = stylesheetReader || arg.startsWith("-y:");
userStylesheet = userStylesheet || arg.startsWith("-xsl:");
init = init || arg.startsWith("-init:");
if (arg.startsWith("-catalog:")) {
pos = arg.indexOf(":");
userCatalogFiles.add(arg.substring(pos+1));
} else {
uriResolver = uriResolver || arg.startsWith("-r:");
sourceReader = sourceReader || arg.startsWith("-x:");
stylesheetReader = stylesheetReader || arg.startsWith("-y:");
userStylesheet = userStylesheet || arg.startsWith("-xsl:");
init = init || arg.startsWith("-init:");
userArgs.add(arg);
catalogCount = catalogCount + 1;
}
userArgs.add(arg);
}

xslTNG = new XslTNG();
logger = xslTNG.logger;
catalogFile = xslTNG.createCatalog(System.getProperty("org.docbook.xsltng.catalog-file"));
}

public void run() {
if (uriResolver || sourceReader || stylesheetReader || init) {
if (uriResolver || sourceReader || stylesheetReader || init | catalogCount > 1) {
if (uriResolver) logger.error("The -r: option is not supported");
if (sourceReader) logger.error("The -x: option is not supported");
if (stylesheetReader) logger.error("The -y: option is not supported");
if (init) logger.error("The -init: option is not supported");
if (catalogCount > 1) logger.error("At most one -catalog: option can be specified");
System.exit(1);
}

StringBuilder catBuilder = new StringBuilder();
catBuilder.append(catalogFile);
for (String cat : userCatalogFiles) {
catBuilder.append(";");
catBuilder.append(cat);
}

System.setProperty("xml.catalog.files", catBuilder.toString());
userArgs.add("-init:org.docbook.xsltng.extensions.Register");
if (!userStylesheet) {
userArgs.add("-xsl:https://cdn.docbook.org/release/xsltng/current/xslt/docbook.xsl");
Expand All @@ -71,7 +59,6 @@ public void run() {
userArgs.toArray(args);

if (logger.getFlag("java-args")) {
logger.debug("java-args", "xml.catalog.files=" + System.getProperty("xml.catalog.files"));
for (String arg : args) {
logger.debug("java-args", arg);
}
Expand Down

0 comments on commit 8fa6280

Please sign in to comment.