Skip to content

Commit

Permalink
Fixed Python; improved Java initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ndw committed Oct 9, 2024
1 parent 8fa6280 commit a1352fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
7 changes: 4 additions & 3 deletions src/bin/docbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def __init__(self, args):

self._parse_args(args)

self.catalogs.append(f"{self.root}/xslt/catalog.xml")
if not self.stylesheet:
self.stylesheet = f"-xsl:{self.root}/xslt/docbook.xsl"
self._app_args.append(self.stylesheet)
Expand Down Expand Up @@ -577,8 +576,10 @@ def run(self):
"""Run the process."""
cp = self.classpath()
args = self.args()
jopt = ["-Dxml.catalog.files=" + ";".join(self.catalogs)]
jopt = jopt + self.config.get("java-options", [])
if self.catalogs:
args.append(f"-catalog:{";".join(self.catalogs)}")

jopt = self.config.get("java-options", [])
if self.debug:
print(self._java)
for item in jopt:
Expand Down
7 changes: 2 additions & 5 deletions src/guide/xml/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ development continues.</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.
fixed <link xlink:href="https://github.com/docbook/xslTNG/issues/504">#504</link>.
This change is a consequence of how Saxon initializes the XML Resolver.
</para>
</listitem>

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

public class Main extends Transform {
Vector<String> userArgs = new Vector<>();
private final 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 @@ -24,32 +25,43 @@ 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:")) {
catalogCount = catalogCount + 1;
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);
}
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 | catalogCount > 1) {
if (uriResolver || sourceReader || stylesheetReader || init) {
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);
}
userArgs.add("-catalog:" + catBuilder);

userArgs.add("-init:org.docbook.xsltng.extensions.Register");
if (!userStylesheet) {
userArgs.add("-xsl:https://cdn.docbook.org/release/xsltng/current/xslt/docbook.xsl");
Expand Down

0 comments on commit a1352fe

Please sign in to comment.