1 package org.exoplatform.services.xml.querying.impl.xtas; 2 3 import java.io.IOException ; 4 import java.io.FileInputStream ; 5 import java.io.ByteArrayInputStream ; 6 import java.net.URL ; 7 import java.io.InputStream ; 8 9 import org.xml.sax.SAXException ; 10 11 import org.exoplatform.services.xml.querying.InvalidStatementException; 12 import org.w3c.dom.Node ; 13 import org.w3c.dom.NodeList ; 14 import org.w3c.dom.Document ; 15 16 import org.xml.sax.XMLReader ; 17 import org.xml.sax.InputSource ; 18 19 25 public class XTASMLStatement extends BaseStatement 26 27 { 28 31 public XTASMLStatement(String fileName) throws IOException , InvalidStatementException, SAXException 32 { 33 this( new FileInputStream ( fileName ) ); 34 } 35 36 39 public XTASMLStatement(URL url) throws IOException , InvalidStatementException, SAXException 40 { 41 this( url.openStream() ); 42 } 43 44 48 public XTASMLStatement(InputStream statStream) throws InvalidStatementException, SAXException 49 { 50 51 XMLReader reader = null; 52 53 try { 54 javax.xml.parsers.SAXParserFactory factory= 55 javax.xml.parsers.SAXParserFactory.newInstance(); 56 factory.setNamespaceAware( true ); 57 javax.xml.parsers.SAXParser jaxpParser= 58 factory.newSAXParser(); 59 reader=jaxpParser.getXMLReader(); 60 61 } catch( javax.xml.parsers.ParserConfigurationException ex ) { 62 throw new org.xml.sax.SAXException ( ex ); 63 } catch( javax.xml.parsers.FactoryConfigurationError ex1 ) { 64 throw new org.xml.sax.SAXException ( ex1.toString() ); 65 } catch( NoSuchMethodError ex2 ) { 66 } 67 68 XTASMLContentHandler handler = new XTASMLContentHandler(); 69 reader.setContentHandler( handler ); 70 71 72 try { 73 74 reader.parse( new InputSource (statStream) ); 75 76 } catch( IOException e ) { 77 78 throw new org.xml.sax.SAXException ( e ); 79 } 80 try { 81 82 sourceId = handler.getSourceId(); 83 destinationId = handler.getDestinationId(); 84 85 UniFormTreeFragment nv = new UniFormTreeFragment(); 86 nv.init( new ByteArrayInputStream (handler.getNewValue().getBytes()) ); 87 addInstruction( handler.getType(), handler.getMatch(), nv); 88 89 } catch( Exception e ) { 90 91 throw new InvalidStatementException( "XTASMLStatement Create ERROR:"+e ); 92 } 93 94 } 95 96 public XTASMLStatement(byte[] stat) throws InvalidStatementException, SAXException 97 { 98 this( new ByteArrayInputStream ( stat ) ); 99 } 100 } 101 | Popular Tags |