private static List<OMElement> evaluateXPathToElements(String expression, OMElement root) throws Exception { String[] nsPrefixes = wsdlPrefixes; AXIOMXPath xpathExpression = new AXIOMXPath(expression); for (int j = 0; j < nsPrefixes.length; j ++) { xpathExpression.addNamespace(nsPrefixes[j++], nsPrefixes[j]); } return (List<OMElement>)xpathExpression.selectNodes(root); }
XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(new StringBufferInputStream(responseXML)); OMElement documentElement = new StAXOMBuilder(parser).getDocumentElement(); AXIOMXPath oTA_HotelAvailRSXPath = new AXIOMXPath("/soap:Envelope/soap:Body/wmHotelAvailResponse/OTA_HotelAvailRS"); oTA_HotelAvailRSXPath.addNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/"); oTA_HotelAvailRSXPath.addNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); oTA_HotelAvailRSXPath.addNamespace("xsd", "http://www.w3.org/2001/XMLSchema"); OMElement oTA_HotelAvailRSOmElement = (OMElement)oTA_HotelAvailRSXPath.selectSingleNode(documentElement); OMElement errorsOmElement = (OMElement)new AXIOMXPath("Errors").selectSingleNode(oTA_HotelAvailRSOmElement); String strType = (String) new AXIOMXPath("string(Text/@Type)").selectSingleNode(errorsOmElement); String strCode = (String) new AXIOMXPath("string(Text/@Code)").selectSingleNode(errorsOmElement); String strDescription = (String) new AXIOMXPath("string(Text)").selectSingleNode(errorsOmElement);
public List evaluateXpath(String xpathExpression, Object element, String nsURI) throws Exception { AXIOMXPath xpath = new AXIOMXPath(xpathExpression); if (nsURI != null) { SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); nsContext.addNamespace(null, nsURI); xpath.setNamespaceContext(nsContext); } return xpath.selectNodes(element); }
private String hl7Time(OMElement rootEl) throws Exception { AXIOMXPath xpathEx = new AXIOMXPath("//TestResults//Time"); OMElement selectEl = (OMElement) xpathEx.selectSingleNode(rootEl); return selectEl.getText(); }
OMElement documentElement = new StAXOMBuilder(inStreamToXML).getDocumentElement(); AXIOMXPath xpathExpression = new AXIOMXPath ("/demo"); List nodeList = (OMNode)xpathExpression.selectNodes(documentElement);
public OMElement getSection(String sectionName) throws XdsInternalException { AXIOMXPath xpathExpression; try { xpathExpression = new AXIOMXPath("//*[local-name()='" + sectionName + "']"); List <OMElement> y = (List <OMElement>) xpathExpression.selectNodes(root); OMElement x = (OMElement) xpathExpression.selectSingleNode(root); return x; } catch (JaxenException e) { throw new XdsInternalException("Error extracting section " + sectionName + " from log output", e); } }
/** * Execute xPath expression and return value as object. * * @param element OMElement which requires to evaluate * @param xPathExp String xPath expression * @param nameSpaceMap name value pair containing namespace and prefixes * @return the Object which evaluated from OMElement * @throws JaxenException when having an issue with xPath expression */ protected Object xPathEvaluate(OMElement element, String xPathExp, Map<String, String> nameSpaceMap) throws JaxenException { AXIOMXPath xpath = new AXIOMXPath(element, xPathExp); xpath.addNamespaces(element); if (nameSpaceMap != null) { for (String prefix : nameSpaceMap.keySet()) { xpath.addNamespace(prefix, nameSpaceMap.get(prefix)); } } return xpath.evaluate(element); }
private static OMElement updateWSDLImports(OMElement omElement,boolean isMasterArtifact) throws JaxenException { AXIOMXPath xPath = new AXIOMXPath("//wsd:import[@location]"); xPath.addNamespace("wsd", "http://schemas.xmlsoap.org/wsdl/"); Object result = xPath.evaluate(omElement); if(!(result instanceof ArrayList)){ return omElement; } List list = (ArrayList) result; for (Object obj : list) { OMElement _import = (OMElement) obj; OMAttribute attribute = _import.getAttribute(new QName("location")); String newValue = isMasterArtifact ? "dependencies" + attribute.getAttributeValue().substring(attribute.getAttributeValue().lastIndexOf("/")) :attribute.getAttributeValue().substring(attribute.getAttributeValue().lastIndexOf("/")+1); attribute.setAttributeValue(newValue); } return omElement; }
/** * Create an instance of EvaluatableSegment. * * @param name Name of segment. * @param expression Expression that needs evaluating to retrieve the value of segment. * @throws JaxenException on expression evalution error. */ protected EvaluatableSegment(String name, String expression) throws JaxenException { super(name); xpathProcessor = new AXIOMXPath(getNormalizedExpression(expression)); xpathProcessor.addNamespace(NAMESPACE_PREFIX, NAMESPACE_URL); }
private String evaluateXACMLResponse(String xacmlResponse) throws FrameworkException { try { AXIOMXPath axiomxPath = new AXIOMXPath(DECISION_XPATH); axiomxPath.addNamespace(XACML_NS_PREFIX, XACML_NS); OMElement rootElement = new StAXOMBuilder(new ByteArrayInputStream(xacmlResponse.getBytes(StandardCharsets.UTF_8))) .getDocumentElement(); return axiomxPath.stringValueOf(rootElement); } catch (JaxenException | XMLStreamException e) { throw new FrameworkException("Exception occurred when getting decision from xacml response.", e); } } }
/** * Returns the Axiom xpath. * * @param expression Xpath expression * @return Axiom xpath is returned */ public AXIOMXPath getXpathResult(String expression) throws JaxenException { return new AXIOMXPath(expression); }
void evalTestPlan(File testplan, String expectedTestLabel) throws XdsInternalException, FactoryConfigurationError, JaxenException { testPlanCount++; OMElement tplan = Util.parse_xml(testplan); AXIOMXPath xpathExpression = new AXIOMXPath ("//TestPlan/Test"); String test = xpathExpression.stringValueOf(tplan); if (test == null || test.equals("")) { logger.info(testplan.toString() + ": No Test element"); errors++; } else if (!test.equals(expectedTestLabel)) { logger.info(testplan.toString() + ": expected " + expectedTestLabel + " found " + test); errors++; } }
private AXIOMXPath getAXIOMXPath( XPath xpath ) throws JaxenException { AXIOMXPath compiledXPath = new AXIOMXPath( xpath.getXPath() ); compiledXPath.setNamespaceContext( xpath.getNamespaceContext() ); return compiledXPath; }
@Override public String evaluate(OMElement message) throws JaxenException { String value = ""; OMElement element = (OMElement)xpathProcessor.selectSingleNode(message); if (element != null) { value = element.getText(); } return value; } }
/** * This method is used to get history item node list while reading history file. * * @param targetStateXpath xPath to the history item node list. * @param documentElement history file document element. * @param historyResourcePath history file resource path. * @return list of history items nodes. * @throws GovernanceException Throws when an error occurs to when getting history items while evaluating the * xPath. */ private static List getTransitionNodeList(AXIOMXPath targetStateXpath, OMElement documentElement, String historyResourcePath) throws GovernanceException{ try { return targetStateXpath.selectNodes(documentElement); } catch (JaxenException e) { throw new GovernanceException("Error while selecting nodes relevant to Xpath: " + LifecycleConstants.HISTORY_ITEM_TARGET_STATE_XPATH + " from document element " + "generated from " + historyResourcePath, e); } }
private List<OMElement> splitToRecords(String recordsSrc) { OMXMLParserWrapper records = OMXMLBuilderFactory.createOMBuilder(new StringReader(recordsSrc)); OMElement element = records.getDocumentElement(); AXIOMXPath xpath = null; try { xpath = new AXIOMXPath("//PubmedArticle"); List<OMElement> recordsList = xpath.selectNodes(element); return recordsList; } catch (JaxenException e) { return null; } }
private String site(OMElement rootEl) throws Exception { AXIOMXPath xpathEx = new AXIOMXPath("//TestResults//Site"); OMElement selectEl = (OMElement) xpathEx.selectSingleNode(rootEl); return selectEl.getText(); }
/** * Execute xPath expression and return value as object. * * @param element OMElement which requires to evaluate * @param xPathExp String xPath expression * @param nameSpaceMap name value pair containing namespace and prefixes * @return the Object which evaluated from OMElement * @throws JaxenException when having an issue with xPath expression */ protected Object xPathEvaluate(OMElement element, String xPathExp, Map<String, String> nameSpaceMap) throws JaxenException { AXIOMXPath xpath = new AXIOMXPath(element, xPathExp); xpath.addNamespaces(element); if (nameSpaceMap != null) { for (String prefix : nameSpaceMap.keySet()) { xpath.addNamespace(prefix, nameSpaceMap.get(prefix)); } } return xpath.evaluate(element); }
private static OMElement updateSchemaImports(OMElement omElement, boolean isMasterArtifact, String xpath) throws JaxenException { AXIOMXPath xPath = new AXIOMXPath(xpath); // "http://schemas.xmlsoap.org/wsdl/" xPath.addNamespace("xs", "http://www.w3.org/2001/XMLSchema"); Object result = xPath.evaluate(omElement); if(!(result instanceof ArrayList)){ return omElement; } List list = (ArrayList)result; for (Object obj : list) { OMElement _import = (OMElement) obj; OMAttribute attribute = _import.getAttribute(new QName("schemaLocation")); String newValue = isMasterArtifact ? "dependencies" + attribute.getAttributeValue().substring(attribute.getAttributeValue().lastIndexOf("/")) :attribute.getAttributeValue().substring(attribute.getAttributeValue().lastIndexOf("/")+1); attribute.setAttributeValue(newValue); } return omElement; }
private AXIOMXPath compile(String xpathExpression) { try { AXIOMXPath xp = new AXIOMXPath(xpathExpression); for (QName qName : qnames) { xp.addNamespace(qName.getPrefix(), qName.getNamespaceURI()); } return xp; } catch (JaxenException e) { Utility.getLog().error(Utility.getEM(e)); } return null; }