Skip to content

Commit

Permalink
Fix issue #137; make base URI and static base URI configurable for be…
Browse files Browse the repository at this point in the history
…tter integration into eXist
  • Loading branch information
ndw committed Feb 9, 2014
1 parent 88f7dd1 commit 86b7e86
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 57 deletions.
43 changes: 18 additions & 25 deletions src/com/xmlcalabash/core/XProcRuntime.java
Expand Up @@ -71,30 +71,6 @@
import org.xml.sax.EntityResolver; import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Vector;
import java.util.logging.Logger;

import javax.xml.transform.URIResolver;
import javax.xml.transform.sax.SAXSource;

import com.xmlcalabash.config.XProcConfigurer; import com.xmlcalabash.config.XProcConfigurer;
import com.xmlcalabash.functions.BaseURI; import com.xmlcalabash.functions.BaseURI;
import com.xmlcalabash.functions.Cwd; import com.xmlcalabash.functions.Cwd;
Expand Down Expand Up @@ -146,6 +122,7 @@ public class XProcRuntime {
private static String episode = null; private static String episode = null;
private Hashtable<String,Vector<XdmNode>> collections = null; private Hashtable<String,Vector<XdmNode>> collections = null;
private URI staticBaseURI = null; private URI staticBaseURI = null;
private URI baseURI = null;
private boolean allowGeneralExpressions = true; private boolean allowGeneralExpressions = true;
private boolean allowXPointerOnText = true; private boolean allowXPointerOnText = true;
private boolean transparentJSON = false; private boolean transparentJSON = false;
Expand Down Expand Up @@ -346,6 +323,18 @@ public URI getStaticBaseURI() {
return staticBaseURI; return staticBaseURI;
} }


public void setStaticBaseURI(URI staticBaseURI) {
this.staticBaseURI = staticBaseURI;
}

public URI getBaseURI() {
return baseURI;
}

public void setBaseURI(URI baseURI) {
this.baseURI = baseURI;
}

public String getSendmailHost() { public String getSendmailHost() {
return config.mailHost; return config.mailHost;
} }
Expand Down Expand Up @@ -589,7 +578,11 @@ private XPipeline _load(Input pipelineInput) throws SaxonApiException, IOExcepti
configurer.getXMLCalabashConfigurer().configRuntime(this); configurer.getXMLCalabashConfigurer().configRuntime(this);
switch (pipelineInput.getKind()) { switch (pipelineInput.getKind()) {
case URI: case URI:
pipeline = parser.loadPipeline(pipelineInput.getUri()); if (baseURI == null) {
pipeline = parser.loadPipeline(pipelineInput.getUri());
} else {
pipeline = parser.loadPipeline(pipelineInput.getUri(), baseURI.toASCIIString());
}
break; break;


case INPUT_STREAM: case INPUT_STREAM:
Expand Down
6 changes: 5 additions & 1 deletion src/com/xmlcalabash/model/Parser.java
Expand Up @@ -86,7 +86,11 @@ public DeclareStep loadPipeline(InputStream inputStream) throws SaxonApiExceptio
} }


public DeclareStep loadPipeline(String uri) throws SaxonApiException { public DeclareStep loadPipeline(String uri) throws SaxonApiException {
XdmNode doc = runtime.parse(uri, URIUtils.cwdAsURI().toASCIIString()); return loadPipeline(uri, URIUtils.cwdAsURI().toASCIIString());
}

public DeclareStep loadPipeline(String uri, String base) throws SaxonApiException {
XdmNode doc = runtime.parse(uri, base);
return loadPipeline(doc); return loadPipeline(doc);
} }


Expand Down
6 changes: 5 additions & 1 deletion src/com/xmlcalabash/runtime/XAtomicStep.java
Expand Up @@ -786,7 +786,11 @@ protected Vector<XdmItem> evaluateXPath(XdmNode doc, Hashtable<String,String> ns
try { try {
XPathCompiler xcomp = runtime.getProcessor().newXPathCompiler(); XPathCompiler xcomp = runtime.getProcessor().newXPathCompiler();
URI baseURI = step.getNode().getBaseURI(); URI baseURI = step.getNode().getBaseURI();
if (!"".equals(baseURI.toASCIIString())) { if (baseURI == null || !baseURI.isAbsolute()) {
if (runtime.getBaseURI() != null) {
xcomp.setBaseURI(runtime.getBaseURI().resolve(baseURI));
}
} else {
xcomp.setBaseURI(baseURI); xcomp.setBaseURI(baseURI);
} }


Expand Down
60 changes: 30 additions & 30 deletions src/com/xmlcalabash/util/UserArgs.java
Expand Up @@ -64,38 +64,38 @@
import static net.sf.saxon.s9api.QName.fromClarkName; import static net.sf.saxon.s9api.QName.fromClarkName;


public class UserArgs { public class UserArgs {
private boolean needsCheck = false; protected boolean needsCheck = false;
private Boolean debug = null; protected Boolean debug = null;
private Output profile = null; protected Output profile = null;
private boolean showVersion = false; protected boolean showVersion = false;
private String saxonProcessor = null; protected String saxonProcessor = null;
private Input saxonConfig = null; protected Input saxonConfig = null;
private boolean schemaAware = false; protected boolean schemaAware = false;
private Boolean safeMode = null; protected Boolean safeMode = null;
private Input config = null; protected Input config = null;
private String logStyle = null; protected String logStyle = null;
private String entityResolverClass = null; protected String entityResolverClass = null;
private String uriResolverClass = null; protected String uriResolverClass = null;
private Input pipeline = null; protected Input pipeline = null;
private List<Input> libraries = new ArrayList<Input>(); protected List<Input> libraries = new ArrayList<Input>();
private Map<String, Output> outputs = new HashMap<String, Output>(); protected Map<String, Output> outputs = new HashMap<String, Output>();
private Map<String, String> bindings = new HashMap<String, String>(); protected Map<String, String> bindings = new HashMap<String, String>();
private List<StepArgs> steps = new ArrayList<StepArgs>(); protected List<StepArgs> steps = new ArrayList<StepArgs>();
private StepArgs curStep = new StepArgs(); protected StepArgs curStep = new StepArgs();
private StepArgs lastStep = null; protected StepArgs lastStep = null;
private boolean extensionValues = false; protected boolean extensionValues = false;
private boolean allowXPointerOnText = false; protected boolean allowXPointerOnText = false;
private boolean useXslt10 = false; protected boolean useXslt10 = false;
private boolean transparentJSON = false; protected boolean transparentJSON = false;
private String jsonFlavor = null; protected String jsonFlavor = null;
private Integer piperackPort = null; protected Integer piperackPort = null;
private Integer piperackExpires = null; protected Integer piperackExpires = null;


public void setDebug(boolean debug) { public void setDebug(boolean debug) {
this.debug = debug; this.debug = debug;
} }


private void setProfile(Output profile) { protected void setProfile(Output profile) {
needsCheck = true; needsCheck = true;
if ((this.profile != null) && (profile != null)) { if ((this.profile != null) && (profile != null)) {
throw new XProcException("Multiple profile are not supported."); throw new XProcException("Multiple profile are not supported.");
Expand Down Expand Up @@ -139,7 +139,7 @@ public void setSaxonProcessor(String saxonProcessor) {
} }
} }


private void setSaxonConfig(Input saxonConfig) { protected void setSaxonConfig(Input saxonConfig) {
needsCheck = true; needsCheck = true;
if ((this.saxonConfig != null) && (saxonConfig != null)) { if ((this.saxonConfig != null) && (saxonConfig != null)) {
throw new XProcException("Multiple saxonConfig are not supported."); throw new XProcException("Multiple saxonConfig are not supported.");
Expand Down Expand Up @@ -168,7 +168,7 @@ public void setSafeMode(boolean safeMode) {
this.safeMode = safeMode; this.safeMode = safeMode;
} }


private void setConfig(Input config) { protected void setConfig(Input config) {
if ((this.config != null) && (config != null)) { if ((this.config != null) && (config != null)) {
throw new XProcException("Multiple config are not supported."); throw new XProcException("Multiple config are not supported.");
} }
Expand Down Expand Up @@ -208,7 +208,7 @@ public Input getPipeline() {
return pipeline; return pipeline;
} }


private void setPipeline(Input pipeline) { protected void setPipeline(Input pipeline) {
needsCheck = true; needsCheck = true;
if ((this.pipeline != null) && (pipeline != null)) { if ((this.pipeline != null) && (pipeline != null)) {
throw new XProcException("Multiple pipelines are not supported."); throw new XProcException("Multiple pipelines are not supported.");
Expand Down

0 comments on commit 86b7e86

Please sign in to comment.