Skip to content

Commit

Permalink
Fixed issue #22. Added support for new option to request the saxon pr…
Browse files Browse the repository at this point in the history
…ocessor edition (independent of schema awareness)
  • Loading branch information
ndw committed Dec 2, 2011
1 parent 66ecbaa commit 4371dd6
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 20 deletions.
41 changes: 41 additions & 0 deletions docs/src/configuration.xml
Expand Up @@ -13,6 +13,47 @@ order.</para>
<para>This chapter summarizes the configuration options, irrespective of how they're
set.</para>

<section xml:id="cfg.saxon-processor">
<title>Saxon processor</title>

<para>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:
</para>

<informaltable frame="none" role="cfgprop">
<tgroup cols="2" colsep="0" rowsep="0">
<tbody>
<row>
<entry>Command line (long):</entry>
<entry><literal>--saxon-processor</literal>=<replaceable>edition</replaceable></entry>
</row>
<row>
<entry>Command line (short):</entry>
<entry><literal>-P</literal><replaceable>edition</replaceable></entry>
</row>
<row>
<entry>Java system property:</entry>
<entry><property>com.xmlcalabash.saxon-processor</property>=<replaceable>edition</replaceable></entry>
</row>
<row>
<entry>XML configuration:</entry>
<entry><tag class="starttag">cc:saxon-processor</tag><replaceable>edition</replaceable><tag class="endtag">cc:saxon-processor</tag></entry>
</row>
</tbody>
</tgroup>
</informaltable>

<para>Where <replaceable>edition</replaceable> is one of “<literal>he</literal>”,
“<literal>pe</literal>”, or “<literal>ee</literal>”. The actual edition that you get
will depend on where the Saxon jar files appear on your classpath. <citetitle>XML
Calabash</citetitle> 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.</para>

<para>Schema aware processing requires “enterprise edition”; if you
request schema aware processing, the processor option is treated as if you'd
requested “<literal>ee</literal>” irrespective of what you actually specified.</para>
</section>

<section xml:id="cfg.schema-aware">
<title>Schema aware processing</title>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/ref.xml
Expand Up @@ -21,7 +21,7 @@
<firstname>Norman</firstname><surname>Walsh</surname>
</personname>
</author>
<releaseinfo>0.3</releaseinfo>
<releaseinfo>0.4</releaseinfo>
<copyright>
<year>2011</year>
<holder>Norman Walsh</holder>
Expand Down
1 change: 1 addition & 0 deletions docs/src/running.xml
Expand Up @@ -39,6 +39,7 @@ will run Java with the correct class path and other arguments.</para>

<cmdsynopsis>
<command><replaceable>calabash</replaceable></command>
<arg>--saxon-processor <replaceable>processortype</replaceable></arg>
<arg>--schema-aware</arg>
<arg>--debug</arg>
<arg>--safe-mode</arg>
Expand Down
7 changes: 2 additions & 5 deletions docs/style/format.xpl
Expand Up @@ -4,11 +4,6 @@
xmlns:l="http://xproc.org/library">
<p:input port="source"/>
<p:input port="parameters" kind="parameter"/>
<p:output port="result">
<p:pipe step="xslt" port="result"/>
</p:output>

<p:serialization port="result" method="xhtml"/>

<p:declare-step type="cx:java-properties">
<p:output port="result"/>
Expand Down Expand Up @@ -57,6 +52,8 @@
<p:with-param name="base.dir" select="'/projects/github/calabash/docs/build/'"/>
</p:xslt>

<p:sink/>

<p:for-each>
<p:iteration-source>
<p:pipe step="xslt" port="secondary"/>
Expand Down
47 changes: 36 additions & 11 deletions src/com/xmlcalabash/core/XProcConfiguration.java
Expand Up @@ -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<String,String> nsBindings = new Hashtable<String,String> ();
public boolean debug = false;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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();

Expand Down
8 changes: 7 additions & 1 deletion src/com/xmlcalabash/drivers/Main.java
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/com/xmlcalabash/drivers/RunTestReport.java
Expand Up @@ -149,7 +149,7 @@ public static void main(String[] args) throws SaxonApiException, IOException, UR

public void runTests(Vector<String> 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();
Expand All @@ -164,7 +164,7 @@ public void runTests(Vector<String> tests) {
public void run(String testfile) {
Vector<TestResult> results = new Vector<TestResult> ();

XProcConfiguration config = new XProcConfiguration(schemaAware);
XProcConfiguration config = new XProcConfiguration("ee", schemaAware);
runtime = new XProcRuntime(config);
runtime.getConfiguration().debug = debug;

Expand Down
9 changes: 9 additions & 0 deletions src/com/xmlcalabash/util/ParseArgs.java
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4371dd6

Please sign in to comment.