- From: Florent Georges <fgeorges@gmail.com>
- Date: Thu, 23 Jul 2009 10:44:58 +0200
- To: Leif Warner <abimelech@gmail.com>
- Cc: XProc Dev <xproc-dev@w3.org>
2009/7/22 Leif Warner wrote:
> You could use the interface to Calabash I made for my online processor.
> The API is just something like:
> PipelineRunner piperunner = new PipelineRunner();
> piperunner.run(InputStream in, OutputStream out)
> where "in" is the xproc document, and out will be the "results" port.
> The only modification I made to WritableDocument was to pass in the
> OutputStream in the constructor
I am interested to see how you pass the InputStream. In order to do
that, I had to apply the following changes to Calabash:
georgfl@bxl-x79 ~/nbprj/calabash
$ svn diff
Index: src/com/xmlcalabash/model/Parser.java
===================================================================
--- src/com/xmlcalabash/model/Parser.java (revision 429)
+++ src/com/xmlcalabash/model/Parser.java (working copy)
@@ -24,6 +24,7 @@
import com.xmlcalabash.util.S9apiUtils;
import com.xmlcalabash.core.XProcConstants;
import com.xmlcalabash.core.XProcException;
+import javax.xml.transform.Source;
/**
*
@@ -48,6 +49,15 @@
public DeclareStep loadPipeline(String uri) throws SaxonApiException {
XdmNode doc = runtime.parse(uri, URIUtils.cwdAsURI().toASCIIString());
+ return doLoadPipeline(doc);
+ }
+
+ public DeclareStep loadPipeline(Source src) throws SaxonApiException {
+ XdmNode doc = runtime.parse(src);
+ return doLoadPipeline(doc);
+ }
+
+ public DeclareStep doLoadPipeline(XdmNode doc) throws SaxonApiException {
XdmNode root = S9apiUtils.getDocumentElement(doc);
if (!XProcConstants.p_declare_step.equals(root.getNodeName())
Index: src/com/xmlcalabash/core/XProcRuntime.java
===================================================================
--- src/com/xmlcalabash/core/XProcRuntime.java (revision 429)
+++ src/com/xmlcalabash/core/XProcRuntime.java (working copy)
@@ -48,6 +48,7 @@
import com.xmlcalabash.runtime.*;
+import javax.xml.transform.Source;
import javax.xml.transform.URIResolver;
import org.xml.sax.EntityResolver;
@@ -260,6 +261,16 @@
public XPipeline load(String pipelineURI) throws SaxonApiException {
reset();
pipeline = parser.loadPipeline(pipelineURI);
+ return doLoad();
+ }
+
+ public XPipeline load(Source src) throws SaxonApiException {
+ reset();
+ pipeline = parser.loadPipeline(src);
+ return doLoad();
+ }
+
+ private XPipeline doLoad() throws SaxonApiException {
if (errorCode != null) {
throw new XProcException(errorCode, errorMessage);
}
@@ -354,6 +365,22 @@
return doc;
}
+ public XdmNode parse(Source src) {
+ return parse(src, false);
+ }
+
+ public XdmNode parse(Source src, boolean validate) {
+ DocumentBuilder builder = getProcessor().newDocumentBuilder();
+ builder.setDTDValidation(validate);
+ builder.setLineNumbering(true);
+ try {
+ return builder.build(src);
+ }
+ catch ( SaxonApiException ex ) {
+ throw new XProcException(XProcConstants.dynamicError(11), ex);
+ }
+ }
+
public void declareStep(QName name, DeclareStep step) {
if (declaredSteps.containsKey(name)) {
throw new XProcException("Duplicate declaration for " + name);
georgfl@bxl-x79 ~/nbprj/calabash
$
PS: Maybe we begin to be far off topic here. I don't feel
comfortable to post Calabash Java code here. But there's nowhere else
to post that, sorry guys. Maybe it's time to get a product-related
list?
Regards,
--
Florent Georges
http://www.fgeorges.org/
Received on Thursday, 23 July 2009 08:45:43 UTC