use of org.jaxen.SimpleNamespaceContext in project webservices-axiom by apache.
the class XPathEvaluator method evaluateXpath.
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);
}
use of org.jaxen.SimpleNamespaceContext in project tdi-studio-se by Talend.
the class SoapExecutor method createXPath.
/**
* Constructs XPath query over the SOAP message
* @param query XPath query
* @param response SOAP message
* @return XPath query
* @throws SOAPException in case of SOAP issue
* @throws JaxenException XPath problem
*/
public XPath createXPath(String query, SOAPMessage response) throws SOAPException, JaxenException {
//Uses DOM to XPath mapping
XPath xpath = new DOMXPath(query);
//Define a namespaces used in response
SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
SOAPPart sp = response.getSOAPPart();
SOAPEnvelope env = sp.getEnvelope();
SOAPBody bdy = env.getBody();
//Add namespaces from SOAP envelope
addNamespaces(nsContext, env);
//Add namespaces of top body element
Iterator bodyElements = bdy.getChildElements();
while (bodyElements.hasNext()) {
SOAPElement element = (SOAPElement) bodyElements.next();
addNamespaces(nsContext, element);
}
xpath.setNamespaceContext(nsContext);
return xpath;
}
use of org.jaxen.SimpleNamespaceContext in project vcell by virtualcell.
the class SEDMLUtils method parseXPath.
/**
* Parses xPath string specified as arg1 in XML file specified as arg2 (using XOM and Jaxen)
* @param xPathExpr
* @param xmlFile
* @return
*/
private static String parseXPath(String xPathExpr, File xmlFile) {
try {
Builder builder = new Builder();
nu.xom.Document document = builder.build(xmlFile);
nu.xom.Element rootElement = document.getRootElement();
String defaultNamespaceURI = rootElement.getNamespaceURI();
String defaultNamespacePrefix = rootElement.getNamespacePrefix();
if ("".equals(defaultNamespacePrefix)) {
ToolSupport.nameSpaces_PrefixesHashMap.put("sbml", defaultNamespaceURI);
} else {
ToolSupport.nameSpaces_PrefixesHashMap.put(defaultNamespacePrefix, defaultNamespaceURI);
}
org.jaxen.XPath xpath = new XOMXPath(xPathExpr);
xpath.setNamespaceContext(new SimpleNamespaceContext(ToolSupport.nameSpaces_PrefixesHashMap));
Object node = xpath.selectSingleNode(document);
String elementId = ((nu.xom.Element) node).getAttributeValue("id");
log.debug("Returned node id : " + elementId);
return elementId;
} catch (JaxenException e) {
// An error occurred parsing or executing the XPath
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
} catch (IOException e) {
// An error occurred opening the document
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
} catch (ParsingException e) {
// An error occurred parsing the document
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
}
use of org.jaxen.SimpleNamespaceContext in project application by collectionspace.
the class XTmplTmpl method compileTemplate.
@SuppressWarnings("unchecked")
private void compileTemplate(Document template) throws InvalidXTmplException {
try {
Map<String, String> map = new HashMap<String, String>();
map.put("xtmpl", XTMPL_URI);
Dom4jXPath xpath = new Dom4jXPath("//.[@xtmpl:point]");
xpath.setNamespaceContext(new SimpleNamespaceContext(map));
List<Node> paths = xpath.selectNodes(template);
QName attr_qname = new QName("point", new Namespace("xtmpl", XTMPL_URI));
for (Node n : paths) {
if (!(n instanceof Element))
continue;
Element e = (Element) n;
Attribute attr = e.attribute(attr_qname);
String key = attr.getText();
String path = e.getPath();
e.remove(attr);
attach.put(key, path);
}
removeNamespaces(template.getDocument().getRootElement());
document = template;
} catch (JaxenException e) {
throw new InvalidXTmplException("Cannot parse template file", e);
}
}
use of org.jaxen.SimpleNamespaceContext in project pentaho-platform by pentaho.
the class PentahoObjectsConfig method getObjectScope.
public String getObjectScope(String objectId) {
try {
HashMap<String, String> map = new HashMap<String, String>();
// $NON-NLS-1$
map.put("default", DEFAULT_NAMESPACE);
Dom4jXPath xpath = new Dom4jXPath(BEAN_ID_XPATH);
xpath.setNamespaceContext(new SimpleNamespaceContext(map));
Element element = (Element) xpath.selectSingleNode(document);
return element.attributeValue(SCOPE_ATTRIBUTE);
} catch (JaxenException jex) {
return null;
}
}
Aggregations