public void close() { for (Source source : sources) { Util.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; } }
private Object evaluateQueryString(List<?> tuple, QueryString queryString) throws ExpressionEvaluationException, BlockedException, TeiidComponentException { Evaluator.NameValuePair<Object>[] pairs = getNameValuePairs(tuple, queryString.getArgs(), false, true); String path = (String)internalEvaluate(queryString.getPath(), tuple); if (path == null) { path = ""; //$NON-NLS-1$ } boolean appendedAny = false; StringBuilder result = new StringBuilder(); for (Evaluator.NameValuePair<Object> nameValuePair : pairs) { if (nameValuePair.value == null) { continue; } if (appendedAny) { result.append('&'); } appendedAny = true; result.append(Util.httpURLEncode(nameValuePair.name)).append('=').append(Util.httpURLEncode((String)nameValuePair.value)); } if (!appendedAny) { return path; } result.insert(0, '?'); result.insert(0, path); return result.toString(); }
endpoint = WSConnection.Util.appendQueryString(endpoint, defaultQueryString);
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); Object o = expr.evaluateSingle(s); 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 { Util.closeSource(s); } }
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 { Util.closeSource(styleSource); Util.closeSource(xmlSource); } }