KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > jdom > JDOMQuery


1 package net.sf.saxon.jdom;
2
3 import net.sf.saxon.Query;
4 import net.sf.saxon.trans.DynamicError;
5 import net.sf.saxon.trans.XPathException;
6 import org.jdom.JDOMException;
7 import org.jdom.input.SAXBuilder;
8
9 import javax.xml.transform.sax.SAXSource JavaDoc;
10 import java.io.IOException JavaDoc;
11 import java.util.ArrayList JavaDoc;
12 import java.util.List JavaDoc;
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 JavaDoc preprocess(List JavaDoc sources) throws XPathException {
23         try {
24             ArrayList JavaDoc jdomSources = new ArrayList JavaDoc(sources.size());
25             for (int i=0; i<sources.size(); i++) {
26                 SAXSource JavaDoc ss = (SAXSource JavaDoc)sources.get(i);
27                 SAXBuilder builder = new SAXBuilder();
28                 org.jdom.Document doc = builder.build(ss.getInputSource());
29                 DocumentWrapper jdom = new DocumentWrapper(doc, ss.getSystemId(), getConfiguration());
30                 jdomSources.add(jdom);
31             }
32             return jdomSources;
33         } catch (JDOMException e) {
34             throw new DynamicError(e);
35         } catch (IOException JavaDoc e) {
36             throw new DynamicError(e);
37         }
38     }
39
40     public static void main(String JavaDoc[] args) {
41         new JDOMQuery().doMain(args, "JDOMQuery");
42     }
43 }
44
45 //
46
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
47
// you may not use this file except in compliance with the License. You may obtain a copy of the
48
// License at http://www.mozilla.org/MPL/
49
//
50
// Software distributed under the License is distributed on an "AS IS" basis,
51
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
52
// See the License for the specific language governing rights and limitations under the License.
53
//
54
// The Original Code is: all this file.
55
//
56
// The Initial Developer of the Original Code is Michael H. Kay
57
//
58
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
59
//
60
// Contributor(s): none
61
//
Popular Tags