use of javax.xml.xpath.XPath in project jangaroo-tools by CoreMedia.
the class PomConverter method addDependencyType.
public void addDependencyType(String dependencyType) throws MojoExecutionException {
try {
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xPath = xPathFactory.newXPath();
NodeList dependencyNodes = (NodeList) xPath.evaluate("/project/dependencies/dependency", document, NODESET);
for (int i = 0; i < dependencyNodes.getLength(); i++) {
Node dependencyNode = dependencyNodes.item(i);
Element typeNode = document.createElement("type");
typeNode.appendChild(document.createTextNode(dependencyType));
insertChildWithWhitespace(dependencyNode, typeNode, null);
}
} catch (XPathException e) {
throw new MojoExecutionException("error while trying to add dependency type to POM", e);
}
}
use of javax.xml.xpath.XPath in project verify-hub by alphagov.
the class SoapMessageManager method unwrapSoapMessage.
public Element unwrapSoapMessage(Element soapElement) {
XPath xpath = XPathFactory.newInstance().newXPath();
NamespaceContextImpl context = new NamespaceContextImpl();
context.startPrefixMapping("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
context.startPrefixMapping("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
context.startPrefixMapping("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
context.startPrefixMapping("ds", "http://www.w3.org/2000/09/xmldsig#");
xpath.setNamespaceContext(context);
try {
final String expression = "/soapenv:Envelope/soapenv:Body/samlp:Response";
Element element = (Element) xpath.evaluate(expression, soapElement, XPathConstants.NODE);
if (element == null) {
String errorMessage = format("Document{0}{1}{0}does not have element {2} inside it.", NEW_LINE, writeToString(soapElement), expression);
LOG.error(errorMessage);
throw new IllegalArgumentException(errorMessage);
}
return element;
} catch (XPathExpressionException e) {
throw propagate(e);
}
}
use of javax.xml.xpath.XPath in project verify-hub by alphagov.
the class SoapMessageManagerTest method getAttributeQuery.
private Element getAttributeQuery(Document document) throws XPathExpressionException {
XPath xpath = XPathFactory.newInstance().newXPath();
NamespaceContextImpl context = new NamespaceContextImpl();
context.startPrefixMapping("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
context.startPrefixMapping("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
xpath.setNamespaceContext(context);
return (Element) xpath.evaluate("//samlp:Response", document, XPathConstants.NODE);
}
use of javax.xml.xpath.XPath in project oxTrust by GluuFederation.
the class AsimbaXMLConfigurationService method parse.
/**
* Parse Asimba XML configuration file.
*/
private void parse() {
try {
// check for asimba config availability
File configFile = new File(getConfigurationFilePath());
if (!configFile.exists())
return;
// parse XML
Document document = xmlService.getXmlDocument(FileUtils.readFileToByteArray(configFile));
XPath xPath = XPathFactory.newInstance().newXPath();
keystoreFilePath = xPath.evaluate("/asimba-server/crypto/signing/signingfactory/keystore/file", document);
log.info("AsimbaXMLConfig keystoreFilePath: " + keystoreFilePath);
keystoreType = xPath.evaluate("/asimba-server/crypto/signing/signingfactory/keystore/type", document);
if (keystoreType == null || "".equals(keystoreType))
keystoreType = KeyStore.getDefaultType();
log.info("AsimbaXMLConfig keystoreType: " + keystoreType);
keystorePassword = xPath.evaluate("/asimba-server/crypto/signing/signingfactory/keystore/keystore_password", document);
asimbaAias = xPath.evaluate("/asimba-server/crypto/signing/signingfactory/keystore/alias", document);
asimbaAiasPassword = xPath.evaluate("/asimba-server/crypto/signing/signingfactory/keystore/password", document);
} catch (Exception e) {
log.error("parse() exception", e);
keystoreFilePath = null;
keystoreType = null;
asimbaAias = null;
asimbaAiasPassword = null;
}
}
use of javax.xml.xpath.XPath in project cayenne by apache.
the class DefaultUpgradeService method getAdditionalDatamapResources.
List<Resource> getAdditionalDatamapResources(UpgradeUnit upgradeUnit) {
List<Resource> resources = new ArrayList<>();
try {
XPath xpath = XPathFactory.newInstance().newXPath();
NodeList nodes = (NodeList) xpath.evaluate("/domain/map/@name", upgradeUnit.getDocument(), XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
Node mapNode = nodes.item(i);
// in version 3.0.0.1 and earlier map tag had attribute location,
// but it was always equal to data map name + ".map.xml"
Resource mapResource = upgradeUnit.getResource().getRelativeResource(mapNode.getNodeValue() + ".map.xml");
resources.add(mapResource);
}
} catch (Exception ex) {
logger.warn("Can't get additional dataMap resources: ", ex);
}
return resources;
}
Aggregations