Running Calabash XML From Code

419 views Asked by At

I downloaded Calabash XML a couple of days back and got it working easily enough from the command prompt. I then tried to run it from Java code I noticed there was no API (e.g. the Calabash main method is massive with code calls to everywhere). To get it working was very messy as I had to copy huge chunks from the main method to a wrapper class, and divert from the System.out to a byte array output stream (and eventually into a String) i.e.

...

ByteArrayOutputStream baos = new ByteArrayOutputStream ();  // declare at top

...

WritableDocument wd = null;
if (uri != null) {
    URI furi = new URI(uri);
    String filename = furi.getPath();
    FileOutputStream outfile = new FileOutputStream(filename);
    wd = new WritableDocument(runtime,filename,serial,outfile);
} else {
    wd = new WritableDocument(runtime,uri,serial, baos);    // new "baos" parameter
}

The performance seems really, really slow e.g. i ran a simple filter 1000 times ...

<p:filter>
    <p:with-option name="select" select="'/result/meta-data/neighbors/document/title'"  />
</p:filter>

On average each time took 17ms which doesn't seem like much but my spring REST controller with calls to Mongo DB and encryption calls etc take on average 3/4 ms.

Has anyone encountered this when running Calabash from code? Is there something I can do to speed things up?

For example, I this is being called each time -

XProcRuntime runtime = new XProcRuntime(config);

Can this be created once and reused? Any help is appreciated as I don't want to have to pay money to use Calamet but really want to get Xproc working from code to an acceptable performance.

1

There are 1 answers

1
grtjn On BEST ANSWER

For examples on how you could integrate XMLCalabash in a framework, I can mention Servlex by Florent Georges. You'd have to browse the code to find the relevant bit, but last time I looked it shouldn't be too hard to find:

http://servlex.net/

XMLCalabash wasn't build for speed unfortunately. I am sure that if you run profile, and can find some hotspots, Norm Walsh would be interested to hear about it.

Alternative is to look into Quixprox, which is derived from XMLCalabash:

https://code.google.com/p/quixproc/

I am also very sure that if you can send Norm a patch to improve the main class for better integration, he'd be interested to hear about it. In fact, the code should be on github, just fork it, fix it, and do a pull request..

HTH!