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(WSUtil.httpURLEncode(nameValuePair.name)).append('=').append(WSUtil.httpURLEncode((String)nameValuePair.value)); } if (!appendedAny) { return path; } result.insert(0, '?'); result.insert(0, path); return result.toString(); }
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; } }
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(WSUtil.httpURLEncode(nameValuePair.name)).append('=').append(WSUtil.httpURLEncode((String)nameValuePair.value)); } if (!appendedAny) { return path; } result.insert(0, '?'); result.insert(0, path); return result.toString(); }
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); } }
private String getURLValue(Literal value) { if (value.getValue() == null) { throw new TeiidRuntimeException("Null is not supported"); //$NON-NLS-1$ } return WSUtil.httpURLEncode(value.getValue().toString()); }
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); } }
static String getQueryParameters(Call obj) throws EdmPrimitiveTypeException { StringBuilder sb = new StringBuilder(); final List<Argument> params = obj.getArguments(); if (params != null && params.size() != 0) { Argument param = null; for (int i = 0; i < params.size(); i++) { param = params.get(i); if (param.getDirection() == Direction.IN || param.getDirection() == Direction.INOUT) { if (i != 0) { sb.append("&"); //$NON-NLS-1$ } sb.append(WSUtil.httpURLEncode(param.getMetadataObject().getName())); sb.append(Tokens.EQ); sb.append(WSUtil.httpURLEncode(ODataTypeManager.convertToODataURIValue(param.getArgumentValue().getValue(), ODataTypeManager.odataType(param.getType()).getFullQualifiedName() .getFullQualifiedNameAsString()))); } } } return sb.toString(); }
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); } }
this.buffer.append("&"); //$NON-NLS-1$ this.buffer.append(WSUtil.httpURLEncode(param.getMetadataObject().getName())); this.buffer.append(Tokens.EQ); this.executionFactory.convertToODataInput(param.getArgumentValue(), temp); this.buffer.append(WSUtil.httpURLEncode(temp.toString())); temp.setLength(0);
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); } }
param = params.get(i); ProcedureParameter metadata = param.getMetadataObject(); String argName = WSUtil.httpURLEncode(param.getMetadataObject().getName()); if (param.getDirection() == Direction.IN || param.getDirection() == Direction.INOUT) { String in = metadata.getProperty(RestMetadataExtension.PARAMETER_TYPE, false);