Permalink
Browse files

Resolved issue #64, added com.xmlcalabash.config.{global,user,local}

system properties.

If the global property is set, its value is treated as a filename and
the global configuration will be read from that file instead of from
the configuration stored in the jar file. (This is not recommended.)
The global property value is resolved relative to the current working
directory.

If the user property is set, its value is treated as a filename and
the user configuration will be read from that file. If it is not set,
the value ".calabash" is assumed. The user property value is resolved
relative to the user's home directory. If the user property is the
empty string, no user configuration is loaded.

The local property is interpreted the same way as the user property
except that it is resolved relative to the current working directory.
  • Loading branch information...
ndw committed Jan 30, 2013
1 parent f345da0 commit c0b8c407206c6148deaaccf1e6783f1ee12c3c23
Showing with 42 additions and 25 deletions.
  1. +42 −25 src/com/xmlcalabash/core/XProcConfiguration.java
@@ -194,40 +194,57 @@ private void loadConfiguration() {
cfgProcessor.getUnderlyingConfiguration().setStripsAllWhiteSpace(false);
cfgProcessor.getUnderlyingConfiguration().setStripsWhiteSpace(Whitespace.NONE);
String cfg = System.getProperty("com.xmlcalabash.config.global");
try {
InputStream instream = getClass().getResourceAsStream("/etc/configuration.xml");
if (instream == null) {
throw new UnsupportedOperationException("Failed to load configuration from JAR file");
InputStream instream = null;
if (cfg == null) {
instream = getClass().getResourceAsStream("/etc/configuration.xml");
if (instream == null) {
throw new UnsupportedOperationException("Failed to load configuration from JAR file");
}
// No resolver, we don't have one yet
SAXSource source = new SAXSource(new InputSource(instream));
DocumentBuilder builder = cfgProcessor.newDocumentBuilder();
builder.setLineNumbering(true);
builder.setBaseURI(puri);
parse(builder.build(source));
} else {
parse(readXML(cfg, cwd.toASCIIString()));
}
// No resolver, we don't have one yet
SAXSource source = new SAXSource(new InputSource(instream));
DocumentBuilder builder = cfgProcessor.newDocumentBuilder();
builder.setLineNumbering(true);
builder.setBaseURI(puri);
parse(builder.build(source));
} catch (SaxonApiException sae) {
throw new XProcException(sae);
}
try {
XdmNode cnode = readXML(".calabash", home.toASCIIString());
parse(cnode);
} catch (XProcException xe) {
if (XProcConstants.dynamicError(11).equals(xe.getErrorCode())) {
// nop; file not found is ok
} else {
throw xe;
cfg = System.getProperty("com.xmlcalabash.config.user", ".calabash");
if ("".equals(cfg)) {
// skip loading the user configuration
} else {
try {
XdmNode cnode = readXML(cfg, home.toASCIIString());
parse(cnode);
} catch (XProcException xe) {
if (XProcConstants.dynamicError(11).equals(xe.getErrorCode())) {
// nop; file not found is ok
} else {
throw xe;
}
}
}
try {
XdmNode cnode = readXML(".calabash", cwd.toASCIIString());
parse(cnode);
} catch (XProcException xe) {
if (XProcConstants.dynamicError(11).equals(xe.getErrorCode())) {
// nop; file not found is ok
} else {
throw xe;
cfg = System.getProperty("com.xmlcalabash.config.local", ".calabash");
if ("".equals(cfg)) {
// skip loading the local configuration
} else {
try {
XdmNode cnode = readXML(cfg, cwd.toASCIIString());
parse(cnode);
} catch (XProcException xe) {
if (XProcConstants.dynamicError(11).equals(xe.getErrorCode())) {
// nop; file not found is ok
} else {
throw xe;
}
}
}

0 comments on commit c0b8c40

Please sign in to comment.