From 4371dd6818a87c8de0c7230eba1fdf061dfcff62 Mon Sep 17 00:00:00 2001 From: Norman Walsh Date: Fri, 2 Dec 2011 08:57:52 -0500 Subject: [PATCH] Fixed issue #22. Added support for new option to request the saxon processor edition (independent of schema awareness) --- docs/src/configuration.xml | 41 ++++++++++++++++ docs/src/ref.xml | 2 +- docs/src/running.xml | 1 + docs/style/format.xpl | 7 +-- .../xmlcalabash/core/XProcConfiguration.java | 47 ++++++++++++++----- src/com/xmlcalabash/drivers/Main.java | 8 +++- .../xmlcalabash/drivers/RunTestReport.java | 4 +- src/com/xmlcalabash/util/ParseArgs.java | 9 ++++ 8 files changed, 99 insertions(+), 20 deletions(-) diff --git a/docs/src/configuration.xml b/docs/src/configuration.xml index 03f6ab97..f44335c5 100644 --- a/docs/src/configuration.xml +++ b/docs/src/configuration.xml @@ -13,6 +13,47 @@ order. This chapter summarizes the configuration options, irrespective of how they're set. +
+Saxon processor + +There are three classes of Saxon processor: “home edition”, “professional edition”, +and “enterprise edition”. There are four ways to select the edition you wish to use: + + + + + + + Command line (long): + --saxon-processor=edition + + + Command line (short): + -Pedition + + + Java system property: + com.xmlcalabash.saxon-processor=edition + + + XML configuration: + cc:saxon-processoreditioncc:saxon-processor + + + + + +Where edition is one of “he”, +“pe”, or “ee”. The actual edition that you get +will depend on where the Saxon jar files appear on your classpath. XML +Calabash will proceed even if it cannot obtain the requested edition, +but dynamic errors will occur if you attempt to use features not available in the +edition actually used. + +Schema aware processing requires “enterprise edition”; if you +request schema aware processing, the processor option is treated as if you'd +requested “ee” irrespective of what you actually specified. +
Schema aware processing diff --git a/docs/src/ref.xml b/docs/src/ref.xml index 5492d27c..20cdde4a 100644 --- a/docs/src/ref.xml +++ b/docs/src/ref.xml @@ -21,7 +21,7 @@ NormanWalsh - 0.3 + 0.4 2011 Norman Walsh diff --git a/docs/src/running.xml b/docs/src/running.xml index ad41cf0f..c9b66858 100644 --- a/docs/src/running.xml +++ b/docs/src/running.xml @@ -39,6 +39,7 @@ will run Java with the correct class path and other arguments. calabash + --saxon-processor processortype --schema-aware --debug --safe-mode diff --git a/docs/style/format.xpl b/docs/style/format.xpl index 882bf53f..e417ce2d 100644 --- a/docs/style/format.xpl +++ b/docs/style/format.xpl @@ -4,11 +4,6 @@ xmlns:l="http://xproc.org/library"> - - - - - @@ -57,6 +52,8 @@ + + diff --git a/src/com/xmlcalabash/core/XProcConfiguration.java b/src/com/xmlcalabash/core/XProcConfiguration.java index cc9cee36..e4f9c68a 100644 --- a/src/com/xmlcalabash/core/XProcConfiguration.java +++ b/src/com/xmlcalabash/core/XProcConfiguration.java @@ -60,6 +60,7 @@ public class XProcConfiguration { public static final QName _value = new QName("", "value"); public static final QName _exclude_inline_prefixes = new QName("", "exclude-inline-prefixes"); + public String saxonProcessor = "he"; public boolean schemaAware = false; public Hashtable nsBindings = new Hashtable (); public boolean debug = false; @@ -100,7 +101,7 @@ public XProcConfiguration() { cfgProcessor = new Processor(false); loadConfiguration(); - if (schemaAware) { + if (schemaAware || !"he".equals(saxonProcessor)) { // Bugger. We have to restart with a schema-aware processor nsBindings.clear(); inputs.clear(); @@ -111,22 +112,28 @@ public XProcConfiguration() { extensionFunctions.clear(); cfgProcessor = new Processor(true); + + String actualtype = cfgProcessor.getUnderlyingConfiguration().softwareEdition; + if (!"he".equals(saxonProcessor) && (!actualtype.toLowerCase().equals(saxonProcessor))) { + System.err.println("Failed to obtain " + saxonProcessor.toUpperCase() + " processor; using " + actualtype + " instead."); + } + loadConfiguration(); } } - public XProcConfiguration(boolean schemaAware) { - cfgProcessor = new Processor(schemaAware); - boolean sa = cfgProcessor.isSchemaAware(); + public XProcConfiguration(String proctype, boolean schemaAware) { + if (schemaAware) { + proctype = "ee"; + } + boolean licensed = schemaAware || !"he".equals(proctype); - /* - Properties prop = System.getProperties(); - System.err.println(prop.getProperty("java.class.path", null)); - System.err.println(cfgProcessor.getUnderlyingConfiguration().getClass().getName()); - */ + cfgProcessor = new Processor(licensed); + boolean sa = cfgProcessor.isSchemaAware(); - if (schemaAware && !sa) { - System.err.println("Failed to obtain schema-aware processor."); + String actualtype = cfgProcessor.getUnderlyingConfiguration().softwareEdition; + if ((proctype != null) && !"he".equals(proctype) && (!actualtype.toLowerCase().equals(proctype))) { + System.err.println("Failed to obtain " + proctype.toUpperCase() + " processor; using " + actualtype + " instead."); } loadConfiguration(); @@ -190,6 +197,12 @@ private void loadConfiguration() { } // What about properties? + saxonProcessor = System.getProperty("com.xmlcalabash.saxon-processor", saxonProcessor); + + if ( !("he".equals(saxonProcessor) || "pe".equals(saxonProcessor) || "ee".equals(saxonProcessor)) ) { + throw new XProcException("Invalid Saxon processor specified in com.xmlcalabash.saxon-processor property."); + } + schemaAware = "true".equals(System.getProperty("com.xmlcalabash.schema-aware", ""+schemaAware)); debug = "true".equals(System.getProperty("com.xmlcalabash.debug", ""+debug)); extensionValues = "true".equals(System.getProperty("com.xmlcalabash.general-values", ""+extensionValues)); @@ -271,6 +284,8 @@ public void parse(XdmNode doc) { || XProcConstants.NS_EXPROC_CONFIG.equals(uri)) { if ("implementation".equals(localName)) { parseImplementation(node); + } else if ("saxon-processor".equals(localName)) { + parseSaxonProcessor(node); } else if ("schema-aware".equals(localName)) { parseSchemaAware(node); } else if ("namespace-binding".equals(localName)) { @@ -359,6 +374,16 @@ public XProcStep newStep(XProcRuntime runtime,XAtomicStep step){ } } + private void parseSaxonProcessor(XdmNode node) { + String value = node.getStringValue().trim(); + + if ( !("he".equals(value) || "pe".equals(value) || "ee".equals(value)) ) { + throw new XProcException(node, "Invalid Saxon processor: " + value + ". Must be 'he', 'pe', or 'ee'."); + } + + saxonProcessor = value; + } + private void parseSchemaAware(XdmNode node) { String value = node.getStringValue().trim(); diff --git a/src/com/xmlcalabash/drivers/Main.java b/src/com/xmlcalabash/drivers/Main.java index 408c4b67..660e1e09 100644 --- a/src/com/xmlcalabash/drivers/Main.java +++ b/src/com/xmlcalabash/drivers/Main.java @@ -93,9 +93,15 @@ public void run(String[] args) throws SaxonApiException, IOException, URISyntaxE try { XProcConfiguration config = null; + // Blech try { + String proc = cmd.saxonProcessor; if (cmd.schemaAware) { - config = new XProcConfiguration(cmd.schemaAware); + proc = "ee"; + } + + if (proc != null) { + config = new XProcConfiguration(proc, cmd.schemaAware); } else { config = new XProcConfiguration(); } diff --git a/src/com/xmlcalabash/drivers/RunTestReport.java b/src/com/xmlcalabash/drivers/RunTestReport.java index d35ab5a1..8526c7de 100644 --- a/src/com/xmlcalabash/drivers/RunTestReport.java +++ b/src/com/xmlcalabash/drivers/RunTestReport.java @@ -149,7 +149,7 @@ public static void main(String[] args) throws SaxonApiException, IOException, UR public void runTests(Vector tests) { // We create this runtime for startReport(), I know it never actually gets used... - XProcConfiguration config = new XProcConfiguration(schemaAware); + XProcConfiguration config = new XProcConfiguration("ee", schemaAware); runtime = new XProcRuntime(config); startReport(); @@ -164,7 +164,7 @@ public void runTests(Vector tests) { public void run(String testfile) { Vector results = new Vector (); - XProcConfiguration config = new XProcConfiguration(schemaAware); + XProcConfiguration config = new XProcConfiguration("ee", schemaAware); runtime = new XProcRuntime(config); runtime.getConfiguration().debug = debug; diff --git a/src/com/xmlcalabash/util/ParseArgs.java b/src/com/xmlcalabash/util/ParseArgs.java index f61c63fd..a9334575 100644 --- a/src/com/xmlcalabash/util/ParseArgs.java +++ b/src/com/xmlcalabash/util/ParseArgs.java @@ -26,6 +26,7 @@ public class ParseArgs { public boolean debugExplicit = false; public boolean debug = false; + public String saxonProcessor = null; public boolean schemaAwareExplicit = false; public boolean schemaAware = false; @@ -66,6 +67,14 @@ public void parse(String[] args) { arg = args[argpos]; } + if (arg.startsWith("-P") || arg.startsWith("--saxon-processor")) { + saxonProcessor = parseString("P","saxon-processor"); + if ( !("he".equals(saxonProcessor) || "pe".equals(saxonProcessor) || "ee".equals(saxonProcessor)) ) { + throw new XProcException("Invalid Saxon processor option: " + saxonProcessor + ". Must be 'he', 'pe', or 'ee'."); + } + continue; + } + if (arg.startsWith("-a") || arg.startsWith("--schema-aware")) { schemaAware = parseBoolean("a","schema-aware"); schemaAwareExplicit = true;