@Override protected void initializeExpressionQuery() { if (this.xpath == null) { this.xpath = XPathFactory.newInstance().newXPath(); } else { this.xpath.reset(); } this.exprCache = new HashMap<String, XPathExpression>(); }
public String getProperty(String path) throws XPathExpressionException, IOException { String propName = null; int last = path.lastIndexOf("."); if(last!=-1) { propName = path.substring(last+1); } else { propName = path; } xpath.reset(); return xpath.evaluate("//" + propName + "/text()", new InputSource(new StringReader(propXML))); }
public void reset() { if (xPath != null) { getXPath().reset(); } }
/** * Method releases a XPath back in the pool. * * @param xPath the transformer. */ public void release(final XPath xPath) { xPath.reset(); this.release(xPath, null); }
public String getPropertyAsString(String path) throws IOException, XPathExpressionException { String propName = null; String doName = ""; int last = path.lastIndexOf("."); if(last!=-1) { doName = path.substring(0, last); propName = path.substring(last+1); }else { propName = path; } String doXml = getPropertyDO(doName); xpath.reset(); return xpath.evaluate("//" + propName + "/text()", new InputSource(new StringReader(doXml))); }
/** * Evaluate the xPath expression on the given node. * * @param expression the expression to evaluate. * @param node the node on which the xpath should be performed. * @param type the return type of the expression. * @return the resulting object from the xpath query * @throws StageException If <code>expression</code> cannot be evaluated. */ private Object evaluateXPath(String expression, Node node, QName type) throws StageException { try { xpath.reset(); return xpath.evaluate(expression, node, type); } catch (XPathExpressionException ex) { throw new StageException("Could not evaluate xPath expression (" + expression + ')', ex); } }
public static void runRestLevel(RestClient rc) throws Exception { String contentXml = rc.get("moid=ServiceInstance&doPath=content"); System.out.println(contentXml); XPath xpath = XPathFactory.newInstance().newXPath(); String emMOR = xpath.evaluate("//eventManager/text()", new InputSource(new StringReader(contentXml))); System.out.println("view:" + emMOR); String lastEventXml = rc.get("moid=" + emMOR + "&doPath=latestEvent"); xpath.reset(); String eMessage = xpath.evaluate("//fullFormattedMessage/text()", new InputSource(new StringReader(lastEventXml))); System.out.println("Latest Event: " + eMessage); System.out.println(rc.get(null)); System.out.println(rc.get("?moid=ServiceInstance&doPath=content%2eabout")); long start = System.currentTimeMillis(); System.out.println(rc.get("?moid=48")); long end = System.currentTimeMillis(); System.out.println("time taken:" + (end-start)); Map<String, String> para = new Hashtable<String, String>(); para.put("newName", "Melody_SuSe"); System.out.println(rc.post("moid=48&method=rename", para)); Map<String, String> para1 = new Hashtable<String, String>(); System.out.println(rc.post("http://10.20.143.205/mob/?moid=48&method=acquireMksTicket", para1)); } }