/** * Get a new DOM Document object from parsing the specified InputStream. * * @param in * the InputStream to parse. * @return a new DOM Document object. * @throws ParserConfigurationException * if a DocumentBuilder cannot be created. * @throws SAXException * If any parse errors occur. * @throws IOException * If any IO errors occur. */ protected static Document getDocument(InputStream in) throws Exception { DocumentBuilder builder = XmlTransformUtility.borrowDocumentBuilder(); Document doc = null; try { doc = builder.parse(in); } finally { XmlTransformUtility.returnDocumentBuilder(builder); } return doc; } }
public static Document getDocumentFromBytes(byte[] data) throws Exception { Document doc = XmlTransformUtility.parseNamespaceAware(new ByteArrayInputStream(data)); return doc; }
public static Templates getTemplates(StreamSource source) throws TransformerException { TransformerFactory tf = null; Templates result = null; try { tf = borrowTransformerFactory(); result = tf.newTemplates(source); } catch (Exception e) { throw new TransformerException(e.getMessage(), e); } finally { if (tf != null) returnTransformerFactory(tf); } return result; }
public static Transformer getTransformer() throws Exception { return getTransformer(null); } public static Transformer getTransformer(Source src) throws Exception {
public static void parseWithoutValidating(InputStream in, DefaultHandler handler) throws SAXException, IOException { parseWithoutValidating(new InputSource(in), handler); }
XmlTransformUtility.getTransformer(preprocessorSource); ptransformer.setParameter("phase", phase); ptransformer.transform(rulesSource, new StreamResult(out)); return XmlTransformUtility.getTemplates( new StreamSource(out.toReader()));
public static Transformer getTransformer() throws Exception { return getTransformer(null); } public static Transformer getTransformer(Source src) throws Exception {
public static void parseWithoutValidating(InputStream in, DefaultHandler handler) throws SAXException, IOException { parseWithoutValidating(new InputSource(in), handler); }
XmlTransformUtility.getTransformer(preprocessorSource); ptransformer.setParameter("phase", phase); ptransformer.transform(rulesSource, new StreamResult(out)); return XmlTransformUtility.getTemplates( new StreamSource(out.toReader()));
/** * Get a new DOM Document object from parsing the specified InputStream. * * @param in * the InputStream to parse. * @return a new DOM Document object. * @throws ParserConfigurationException * if a DocumentBuilder cannot be created. * @throws SAXException * If any parse errors occur. * @throws IOException * If any IO errors occur. */ protected static Document getDocument(InputStream in) throws Exception { DocumentBuilder builder = XmlTransformUtility.borrowDocumentBuilder(); Document doc = null; try { doc = builder.parse(in); } finally { XmlTransformUtility.returnDocumentBuilder(builder); } return doc; } }
public static Templates getTemplates(StreamSource source) throws TransformerException { TransformerFactory tf = null; Templates result = null; try { tf = borrowTransformerFactory(); result = tf.newTemplates(source); } catch (Exception e) { throw new TransformerException(e.getMessage(), e); } finally { if (tf != null) returnTransformerFactory(tf); } return result; }
public static Document parseNamespaceAware(File src) throws Exception { return parseNamespaceAware(new FileInputStream(src)); }
public void serialize(OutputStream out) throws Exception { final Transformer idTransform = XmlTransformUtility.getTransformer(); Source input = new DOMSource(doc); Result output = new StreamResult(out); idTransform.transform(input, output); } }
public void parse(String username, String password) throws IOException, FinishedParsingException { this.username = username; this.password = password; try { value = new StringBuffer(); authenticated = null; namedAttributes = new Hashtable<String, Set<?>>(); foundUser = false; XmlTransformUtility.parseWithoutValidating(m_xmlStream, this); } catch (FinishedParsingException fpe) { throw fpe; } catch (Throwable e) { e.printStackTrace(); throw new IOException("Error parsing XML: " + e.getMessage()); } }
public static Document getDocumentFromFile(File file) throws Exception { byte[] document = loadFile(file); DocumentBuilder docBuilder = XmlTransformUtility.borrowDocumentBuilder(); Document doc = null; try { doc = docBuilder.parse(new ByteArrayInputStream(document)); } finally { XmlTransformUtility.returnDocumentBuilder(docBuilder); } return doc; }
/** * Try to cache parsed Templates, but check for changes on disk * @param src * @return Templates */ public static Templates getTemplates(File src) throws TransformerException { String key = src.getAbsolutePath(); TimestampedCacheEntry<Templates> entry = TEMPLATES_CACHE.get(key); // check to see if it is null or has changed if (entry == null || entry.timestamp() < src.lastModified()) { TransformerFactory factory = null; try { factory = borrowTransformerFactory(); Templates template = factory.newTemplates(new StreamSource(src)); entry = new TimestampedCacheEntry<Templates>(src.lastModified(), template); } catch (Exception e) { throw new TransformerException(e.getMessage(), e); } finally { if (factory != null) returnTransformerFactory(factory); } TEMPLATES_CACHE.put(key, entry); } return entry.value(); }
public static Document parseNamespaceAware(File src) throws Exception { return parseNamespaceAware(new FileInputStream(src)); }
public void serialize(OutputStream out) throws Exception { final Transformer idTransform = XmlTransformUtility.getTransformer(); Source input = new DOMSource(doc); Result output = new StreamResult(out); idTransform.transform(input, output); } }
public void parse(String username, String password) throws IOException, FinishedParsingException { this.username = username; this.password = password; try { value = new StringBuffer(); authenticated = null; namedAttributes = new Hashtable<String, Set<?>>(); foundUser = false; XmlTransformUtility.parseWithoutValidating(m_xmlStream, this); } catch (FinishedParsingException fpe) { throw fpe; } catch (Throwable e) { e.printStackTrace(); throw new IOException("Error parsing XML: " + e.getMessage()); } }
public static String format(byte[] document) throws Exception { DocumentBuilder builder = XmlTransformUtility.borrowDocumentBuilder(); Document doc = null; try { doc = builder.parse(new ByteArrayInputStream(document)); } finally { XmlTransformUtility.returnDocumentBuilder(builder); } return format(doc); }