public void close() { for (Source source : sources) { WSUtil.closeSource(source); if (source instanceof StAXSource) { StAXSource ss = (StAXSource)source; if (ss.getXMLEventReader() != null) { try { ss.getXMLEventReader().close(); } catch (XMLStreamException e) { } } else { try { ss.getXMLStreamReader().close(); } catch (XMLStreamException e) { } } } } if (iter != null) { iter.close(); } sources.clear(); iter = null; } }
public void close() { for (Source source : sources) { WSUtil.closeSource(source); if (source instanceof StAXSource) { StAXSource ss = (StAXSource)source; if (ss.getXMLEventReader() != null) { try { ss.getXMLEventReader().close(); } catch (XMLStreamException e) { } } else { try { ss.getXMLStreamReader().close(); } catch (XMLStreamException e) { } } } } if (iter != null) { iter.close(); } sources.clear(); iter = null; } }
public static ClobType xslTransform(CommandContext context, Object xml, Object styleSheet) throws Exception { Source styleSource = null; Source xmlSource = null; try { styleSource = convertToSource(styleSheet); xmlSource = convertToSource(xml); final Source xmlParam = xmlSource; TransformerFactory factory = StandardXMLTranslator.getThreadLocalTransformerFactory(); final Transformer transformer = factory.newTransformer(styleSource); //this creates a non-validated sqlxml - it may not be valid xml/root-less xml SQLXMLImpl result = XMLSystemFunctions.saveToBufferManager(context.getBufferManager(), new XMLTranslator() { @Override public void translate(Writer writer) throws TransformerException { //transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$ // Feed the resultant I/O stream into the XSLT processor transformer.transform(xmlParam, new StreamResult(writer)); } }, context); return new ClobType(new ClobImpl(result.getStreamFactory(), -1)); } finally { WSUtil.closeSource(styleSource); WSUtil.closeSource(xmlSource); } }
public static ClobType xslTransform(CommandContext context, Object xml, Object styleSheet) throws Exception { Source styleSource = null; Source xmlSource = null; try { styleSource = convertToSource(styleSheet); xmlSource = convertToSource(xml); final Source xmlParam = xmlSource; TransformerFactory factory = StandardXMLTranslator.getThreadLocalTransformerFactory(); final Transformer transformer = factory.newTransformer(styleSource); //this creates a non-validated sqlxml - it may not be valid xml/root-less xml SQLXMLImpl result = XMLSystemFunctions.saveToBufferManager(context.getBufferManager(), new XMLTranslator() { @Override public void translate(Writer writer) throws TransformerException { //transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$ // Feed the resultant I/O stream into the XSLT processor transformer.transform(xmlParam, new StreamResult(writer)); } }, context); return new ClobType(new ClobImpl(result.getStreamFactory(), -1)); } finally { WSUtil.closeSource(styleSource); WSUtil.closeSource(xmlSource); } }
public static String xpathValue(Object doc, String xpath) throws XPathException, TeiidProcessingException { Source s = null; try { s = convertToSource(doc); XPathEvaluator eval = new XPathEvaluator(); // Wrap the string() function to force a string return XPathExpression expr = eval.createExpression(xpath); XPathDynamicContext context = expr.createDynamicContext(eval.getConfiguration().buildDocumentTree(s).getRootNode()); Object o = expr.evaluateSingle(context); if(o == null) { return null; } // Return string value of node type if(o instanceof Item) { Item i = (Item)o; if (isNull(i)) { return null; } return i.getStringValue(); } // Return string representation of non-node value return o.toString(); } finally { WSUtil.closeSource(s); } }
public static String xpathValue(Object doc, String xpath) throws XPathException, TeiidProcessingException { Source s = null; try { s = convertToSource(doc); XPathEvaluator eval = new XPathEvaluator(); // Wrap the string() function to force a string return XPathExpression expr = eval.createExpression(xpath); XPathDynamicContext context = expr.createDynamicContext(eval.getConfiguration().buildDocumentTree(s).getRootNode()); Object o = expr.evaluateSingle(context); if(o == null) { return null; } // Return string value of node type if(o instanceof Item) { Item i = (Item)o; if (isNull(i)) { return null; } return i.getStringValue(); } // Return string representation of non-node value return o.toString(); } finally { WSUtil.closeSource(s); } }