01: package net.sf.saxon.jdom;
02:
03: import net.sf.saxon.Query;
04: import net.sf.saxon.trans.DynamicError;
05: import net.sf.saxon.trans.XPathException;
06: import org.jdom.JDOMException;
07: import org.jdom.input.SAXBuilder;
08:
09: import javax.xml.transform.sax.SAXSource;
10: import java.io.IOException;
11: import java.util.ArrayList;
12: import java.util.List;
13:
14: /**
15: * Variant of command line net.sf.saxon.Transform do build the source document
16: * in JDOM and then proceed with the transformation. This class is provided largely for
17: * testing purposes.
18: */
19:
20: public class JDOMQuery extends Query {
21:
22: public List preprocess(List sources) throws XPathException {
23: try {
24: ArrayList jdomSources = new ArrayList(sources.size());
25: for (int i = 0; i < sources.size(); i++) {
26: SAXSource ss = (SAXSource) sources.get(i);
27: SAXBuilder builder = new SAXBuilder();
28: org.jdom.Document doc = builder.build(ss
29: .getInputSource());
30: DocumentWrapper jdom = new DocumentWrapper(doc, ss
31: .getSystemId(), getConfiguration());
32: jdomSources.add(jdom);
33: }
34: return jdomSources;
35: } catch (JDOMException e) {
36: throw new DynamicError(e);
37: } catch (IOException e) {
38: throw new DynamicError(e);
39: }
40: }
41:
42: public static void main(String[] args) {
43: new JDOMQuery().doMain(args, "JDOMQuery");
44: }
45: }
46:
47: //
48: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
49: // you may not use this file except in compliance with the License. You may obtain a copy of the
50: // License at http://www.mozilla.org/MPL/
51: //
52: // Software distributed under the License is distributed on an "AS IS" basis,
53: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
54: // See the License for the specific language governing rights and limitations under the License.
55: //
56: // The Original Code is: all this file.
57: //
58: // The Initial Developer of the Original Code is Michael H. Kay
59: //
60: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
61: //
62: // Contributor(s): none
63: //
|