List of usage examples for javax.xml.xpath XPathConstants STRING
QName STRING
To view the source code for javax.xml.xpath XPathConstants STRING.
Click Source Link
The XPath 1.0 string data type.
Maps to Java String .
From source file:org.apache.camel.builder.xml.XPathBuilder.java
/** * Sets the expression result type to boolean * * @return the current builder//from w w w.j a v a 2s .co m */ public XPathBuilder stringResult() { resultQName = XPathConstants.STRING; return this; }
From source file:org.apache.cxf.systest.rest.RestClientServerBookTest.java
@Test public void testGetBookWrappedUsingURL() throws Exception { String endpointAddress = "http://localhost:9080/xmlwrapped/books/123"; URL url = new URL(endpointAddress); InputStream in = url.openStream(); assertNotNull(in);// w w w .ja v a 2 s .c o m Map<String, String> ns = new HashMap<String, String>(); ns.put("a1", "http://book.acme.com"); ns.put("a2", "http://book.customer.cxf.apache.org/"); Document doc = XMLUtils.parse(in); XPathUtils xp = new XPathUtils(ns); assertTrue(xp.isExist("/a2:getBookResponse", doc.getDocumentElement(), XPathConstants.NODE)); assertTrue(xp.isExist("/a2:getBookResponse/a2:Book", doc.getDocumentElement(), XPathConstants.NODE)); assertTrue(xp.isExist("/a2:getBookResponse/a2:Book/a1:id", doc.getDocumentElement(), XPathConstants.NODE)); assertEquals("123", xp.getValue("/a2:getBookResponse/a2:Book/a1:id", doc.getDocumentElement(), XPathConstants.STRING)); assertEquals("CXF in Action", xp.getValue("/a2:getBookResponse/a2:Book/a1:name", doc.getDocumentElement(), XPathConstants.STRING)); }
From source file:org.apache.hadoop.hive.ql.udf.xml.TestUDFXPathUtil.java
@Test public void testEvalIllegalArgs() { UDFXPathUtil util = new UDFXPathUtil(); // null args: assertNull(util.eval(null, "a/text()", XPathConstants.STRING)); assertNull(util.eval("<a><b>b1</b><b>b2</b><b>b3</b><c>c1</c><c>c2</c></a>", null, XPathConstants.STRING)); assertNull(util.eval("<a><b>b1</b><b>b2</b><b>b3</b><c>c1</c><c>c2</c></a>", "a/text()", null)); // empty String args: assertNull(util.eval("", "a/text()", XPathConstants.STRING)); assertNull(util.eval("<a><b>b1</b><b>b2</b><b>b3</b><c>c1</c><c>c2</c></a>", "", XPathConstants.STRING)); // wrong expression: assertNull(util.eval("<a><b>b1</b><b>b2</b><b>b3</b><c>c1</c><c>c2</c></a>", "a/text(", XPathConstants.STRING)); }
From source file:org.apache.hadoop.hive.ql.udf.xml.TestUDFXPathUtil.java
@Test public void testEvalPositive() { UDFXPathUtil util = new UDFXPathUtil(); Object result = util.eval("<a><b>b1</b><b>b2</b><b>b3</b><c>c1</c><c>c2</c></a>", "a/c[2]/text()", XPathConstants.STRING); assertEquals("c2", result); result = util.evalBoolean("<a><b>true</b><b>false</b><b>b3</b><c>c1</c><c>c2</c></a>", "a/b[1]/text()"); assertEquals(Boolean.TRUE, result); result = util.evalBoolean("<a><b>true</b><b>false</b><b>b3</b><c>c1</c><c>c2</c></a>", "a/b[4]"); assertEquals(Boolean.FALSE, result); result = util.evalString("<a><b>true</b><b>false</b><b>b3</b><c>c1</c><c>c2</c></a>", "a/b[3]/text()"); assertEquals("b3", result); result = util.evalString("<a><b>true</b><b>false</b><b>b3</b><c>c1</c><c>c2</c></a>", "a/b[4]/text()"); assertEquals("", result); result = util.evalString("<a><b>true</b><b k=\"foo\">FALSE</b><b>b3</b><c>c1</c><c>c2</c></a>", "a/b[2]/@k"); assertEquals("foo", result); result = util.evalNumber("<a><b>true</b><b>false</b><b>b3</b><c>c1</c><c>-77</c></a>", "a/c[2]"); assertEquals(-77.0d, result);/* w w w .j a va 2 s . c o m*/ result = util.evalNumber("<a><b>true</b><b k=\"foo\">FALSE</b><b>b3</b><c>c1</c><c>c2</c></a>", "a/b[2]/@k"); assertEquals(Double.NaN, result); result = util.evalNode("<a><b>true</b><b>false</b><b>b3</b><c>c1</c><c>-77</c></a>", "a/c[2]"); assertNotNull(result); assertTrue(result instanceof Node); result = util.evalNodeList("<a><b>true</b><b>false</b><b>b3</b><c>c1</c><c>-77</c></a>", "a/*"); assertNotNull(result); assertTrue(result instanceof NodeList); assertEquals(5, ((NodeList) result).getLength()); }
From source file:org.apache.nifi.minifi.bootstrap.util.ConfigTransformerTest.java
@Test public void testQueuePrioritizerWritten() throws ConfigurationChangeException, XPathExpressionException { Map<String, Object> map = new HashMap<>(); map.put(ConnectionSchema.QUEUE_PRIORITIZER_CLASS_KEY, "org.apache.nifi.prioritizer.FirstInFirstOutPrioritizer"); ConfigTransformer.addConnection(config, new ConnectionSchema(map), new ParentGroupIdResolver( new ProcessGroupSchema(Collections.emptyMap(), ConfigSchema.TOP_LEVEL_NAME))); XPath xpath = xPathFactory.newXPath(); String expression = "connection/queuePrioritizerClass/text()"; assertEquals("org.apache.nifi.prioritizer.FirstInFirstOutPrioritizer", xpath.evaluate(expression, config, XPathConstants.STRING)); }
From source file:org.apache.nifi.minifi.bootstrap.util.ConfigTransformerTest.java
private String getText(Element element, String path) throws XPathExpressionException { return (String) xPathFactory.newXPath().evaluate(path + "/text()", element, XPathConstants.STRING); }
From source file:org.apache.ode.bpel.elang.xpath20.runtime.XPath20ExpressionRuntime.java
/** * @see org.apache.ode.bpel.explang.ExpressionLanguageRuntime#evaluateAsString(org.apache.ode.bpel.o.OExpression, org.apache.ode.bpel.explang.EvaluationContext) *//*from w w w . j a v a2s.co m*/ public String evaluateAsString(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException { return (String) evaluate(cexp, ctx, XPathConstants.STRING); }
From source file:org.apache.ode.bpel.elang.xpath20.runtime.XPath20ExpressionRuntime.java
/** * @see org.apache.ode.bpel.explang.ExpressionLanguageRuntime#evaluate(org.apache.ode.bpel.o.OExpression, org.apache.ode.bpel.explang.EvaluationContext) *///from ww w . j a v a2 s . c o m @SuppressWarnings("unchecked") public List evaluate(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException { List result; Object someRes = null; try { someRes = evaluate(cexp, ctx, XPathConstants.NODESET); } catch (Exception e) { someRes = evaluate(cexp, ctx, XPathConstants.STRING); } if (someRes instanceof List) { result = (List) someRes; if (__log.isDebugEnabled()) { __log.debug("Returned list of size " + result.size()); } if ((result.size() == 1) && !(result.get(0) instanceof Node)) { // Dealing with a Java class Object simpleType = result.get(0); // Dates get a separate treatment as we don't want to call toString on them String textVal; if (simpleType instanceof Date) { textVal = ISO8601DateParser.format((Date) simpleType); } else if (simpleType instanceof DurationValue) { textVal = ((DurationValue) simpleType).getStringValue(); } else { textVal = simpleType.toString(); } // Wrapping in a document Document document = DOMUtils.newDocument(); // Giving our node a parent just in case it's an LValue expression Element wrapper = document.createElement("wrapper"); Text text = document.createTextNode(textVal); wrapper.appendChild(text); document.appendChild(wrapper); result = Collections.singletonList(text); } } else if (someRes instanceof NodeList) { NodeList retVal = (NodeList) someRes; if (__log.isDebugEnabled()) { __log.debug("Returned node list of size " + retVal.getLength()); } result = new ArrayList(retVal.getLength()); for (int m = 0; m < retVal.getLength(); ++m) { Node val = retVal.item(m); if (val.getNodeType() == Node.DOCUMENT_NODE) { val = ((Document) val).getDocumentElement(); } result.add(val); } } else if (someRes instanceof String) { // Wrapping in a document Document document = DOMUtils.newDocument(); Element wrapper = document.createElement("wrapper"); Text text = document.createTextNode((String) someRes); wrapper.appendChild(text); document.appendChild(wrapper); result = Collections.singletonList(text); } else { result = null; } return result; }
From source file:org.apache.ode.bpel.elang.xquery10.runtime.XQuery10ExpressionRuntime.java
/** * Cast XQuery sequence into an opaque list * * @param type type/*from w w w .j a va 2 s . c om*/ * @param result result * * @return value * * @throws XQException XQException */ private Object getResultValue(QName type, XQResultSequence result) throws XQException { Document document = DOMUtils.newDocument(); Object resultValue = null; if (XPathConstants.NODESET.equals(type)) { List list = new ArrayList(); while (result.next()) { Object itemValue = getItemValue(result.getItem()); if (itemValue instanceof Document) { itemValue = DOMUtils.cloneNode(document, ((Document) itemValue).getDocumentElement()); } else if (itemValue instanceof Node) { itemValue = DOMUtils.cloneNode(document, (Node) itemValue); } if (itemValue != null) { list.add(itemValue); } } resultValue = list; } else if (XPathConstants.NODE.equals(type)) { XQItem item = null; if (result.count() > 0) { result.first(); if (result.isOnItem()) { item = result.getItem(); } } if (item != null) { resultValue = getItemValue(item); if (resultValue instanceof Node) { resultValue = DOMUtils.cloneNode(document, (Node) resultValue); } } } else if (XPathConstants.STRING.equals(type)) { resultValue = result.getSequenceAsString(new Properties()); } else if (XPathConstants.NUMBER.equals(type)) { resultValue = result.getSequenceAsString(new Properties()); resultValue = Integer.parseInt((String) resultValue); } else if (XPathConstants.BOOLEAN.equals(type)) { resultValue = result.getSequenceAsString(new Properties()); resultValue = Boolean.parseBoolean((String) resultValue); } return resultValue; }
From source file:org.apache.ode.bpel.rtrep.v1.xpath10.jaxp.JaxpXPath10ExpressionRuntime.java
public String evaluateAsString(OExpression cexp, EvaluationContext ctx) throws FaultException { return (String) evaluate(cexp, ctx, XPathConstants.STRING); }