1 50 51 package org.openlaszlo.iv.flash.xml; 52 53 import java.io.*; 54 import java.net.*; 55 import java.util.*; 56 57 import java.io.FileInputStream ; 58 import java.io.FileNotFoundException ; 59 import java.util.Properties ; 60 61 import org.w3c.dom.*; 62 import org.w3c.dom.traversal.*; 63 import org.xml.sax.SAXException ; 64 import org.xml.sax.InputSource ; 65 66 import javax.xml.parsers.*; 67 import javax.xml.transform.*; 68 69 import org.openlaszlo.iv.flash.api.*; 70 import org.openlaszlo.iv.flash.url.*; 71 import org.openlaszlo.iv.flash.util.*; 72 73 import org.openlaszlo.iv.flash.cache.*; 74 75 import org.xml.sax.EntityResolver ; 76 import org.xml.sax.InputSource ; 77 78 85 public class XMLHelper { 86 87 private static XMLFactory factory = XMLFactory.getFactory(); 88 89 94 public static XMLFactory getXMLFactory() { 95 return factory; 96 } 97 98 103 public static DocumentBuilder getDocumentBuilder() { 104 try { 105 return factory.getDocumentBuilder(); 106 } catch( ParserConfigurationException e ) { 107 Log.logRB(e); 108 return null; 109 } 110 } 111 112 117 public static Document newDocument() { 118 return getDocumentBuilder().newDocument(); 119 } 120 121 129 public static Document parse( InputStream is ) throws IOException, SAXException { 130 return parse( new InputSource (is) ); 131 } 132 133 141 public static Document parse( InputSource isrc ) throws IOException, SAXException { 142 return getDocumentBuilder().parse( isrc ); 143 } 144 145 156 public static Document getDocument( IVUrl url ) throws IOException, SAXException { 157 Document doc = XMLCache.getXMLDocument( url ); 158 if( doc != null ) return doc; 159 doc = parse( url.getInputStream() ); 160 XMLCache.addXMLDocument( url, doc ); 161 return doc; 162 } 163 164 180 public static Node getNode( IVUrl url ) throws IOException, SAXException { 181 Document doc = getDocument( url ); 182 String ref = url.getRef(); 183 if( ref == null ) return doc; 184 Node node; 185 try { 186 node = getXMLFactory().getXPathProcessor().selectSingleNode(ref, doc); 187 } catch( TransformerException e ) { 188 throw new SAXException (e); 189 } 190 return node; 191 } 192 193 } 194 | Popular Tags |