KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > xml > querying > impl > xtas > XTASMLStatement


1 package org.exoplatform.services.xml.querying.impl.xtas;
2
3 import java.io.IOException JavaDoc;
4 import java.io.FileInputStream JavaDoc;
5 import java.io.ByteArrayInputStream JavaDoc;
6 import java.net.URL JavaDoc;
7 import java.io.InputStream JavaDoc;
8
9 import org.xml.sax.SAXException JavaDoc;
10
11 import org.exoplatform.services.xml.querying.InvalidStatementException;
12 import org.w3c.dom.Node JavaDoc;
13 import org.w3c.dom.NodeList JavaDoc;
14 import org.w3c.dom.Document JavaDoc;
15
16 import org.xml.sax.XMLReader JavaDoc;
17 import org.xml.sax.InputSource JavaDoc;
18
19 /**
20  * Native (XTAS query syntax) Statement
21  * See 'xtas-query.dtd' for more info
22  *
23  * @version $Id: XTASMLStatement.java 566 2005-01-25 12:50:49Z kravchuk $
24  */

25 public class XTASMLStatement extends BaseStatement
26
27 {
28     /**
29      * Builds query from the local file
30      */

31     public XTASMLStatement(String JavaDoc fileName) throws IOException JavaDoc, InvalidStatementException, SAXException JavaDoc
32     {
33          this( new FileInputStream JavaDoc( fileName ) );
34     }
35
36     /**
37      * Builds query from the URI resource
38      */

39     public XTASMLStatement(URL JavaDoc url) throws IOException JavaDoc, InvalidStatementException, SAXException JavaDoc
40     {
41          this( url.openStream() );
42     }
43
44     /**
45      * Builds query from the input stream (main constructor for
46      * the query builded from the *external source* like file,URI )
47      */

48     public XTASMLStatement(InputStream JavaDoc statStream) throws InvalidStatementException, SAXException JavaDoc
49     {
50
51         XMLReader JavaDoc reader = null;
52
53         try {
54       javax.xml.parsers.SAXParserFactory JavaDoc factory=
55           javax.xml.parsers.SAXParserFactory.newInstance();
56       factory.setNamespaceAware( true );
57       javax.xml.parsers.SAXParser JavaDoc jaxpParser=
58           factory.newSAXParser();
59       reader=jaxpParser.getXMLReader();
60       
61         } catch( javax.xml.parsers.ParserConfigurationException JavaDoc ex ) {
62       throw new org.xml.sax.SAXException JavaDoc( ex );
63         } catch( javax.xml.parsers.FactoryConfigurationError JavaDoc ex1 ) {
64       throw new org.xml.sax.SAXException JavaDoc( ex1.toString() );
65         } catch( NoSuchMethodError JavaDoc ex2 ) {
66         }
67
68         XTASMLContentHandler handler = new XTASMLContentHandler();
69         reader.setContentHandler( handler );
70
71
72         try {
73
74             reader.parse( new InputSource JavaDoc(statStream) );
75
76         } catch( IOException JavaDoc e ) {
77
78            throw new org.xml.sax.SAXException JavaDoc( e );
79         }
80         try {
81
82            sourceId = handler.getSourceId();
83            destinationId = handler.getDestinationId();
84
85            UniFormTreeFragment nv = new UniFormTreeFragment();
86            nv.init( new ByteArrayInputStream JavaDoc(handler.getNewValue().getBytes()) );
87            addInstruction( handler.getType(), handler.getMatch(), nv);
88
89         } catch( Exception JavaDoc e ) {
90
91            throw new InvalidStatementException( "XTASMLStatement Create ERROR:"+e );
92         }
93
94     }
95
96     public XTASMLStatement(byte[] stat) throws InvalidStatementException, SAXException JavaDoc
97     {
98        this( new ByteArrayInputStream JavaDoc( stat ) );
99     }
100 }
101
Popular Tags