use of javax.xml.xpath.XPath in project cayenne by apache.
the class UpgradeHandler_V7 method processProjectDom.
@Override
public void processProjectDom(UpgradeUnit upgradeUnit) {
Element domain = upgradeUnit.getDocument().getDocumentElement();
domain.setAttribute("project-version", getVersion());
XPath xpath = XPathFactory.newInstance().newXPath();
Node node;
try {
node = (Node) xpath.evaluate("/domain/property[@name='cayenne.DataDomain.usingExternalTransactions']", upgradeUnit.getDocument(), XPathConstants.NODE);
} catch (Exception ex) {
return;
}
if (node != null) {
domain.removeChild(node);
}
}
use of javax.xml.xpath.XPath in project oxTrust by GluuFederation.
the class Shibboleth3ConfService method isFederationMetadata.
public boolean isFederationMetadata(String spMetaDataFN) {
if (spMetaDataFN == null) {
return false;
}
File spMetaDataFile = new File(getSpMetadataFilePath(spMetaDataFN));
InputStream is = null;
InputStreamReader isr = null;
Document xmlDocument = null;
try {
is = FileUtils.openInputStream(spMetaDataFile);
isr = new InputStreamReader(is, "UTF-8");
try {
xmlDocument = xmlService.getXmlDocument(new InputSource(isr));
} catch (Exception ex) {
log.error("Failed to parse metadata file '{}'", spMetaDataFile.getAbsolutePath(), ex);
ex.printStackTrace();
}
} catch (IOException ex) {
log.error("Failed to read metadata file '{}'", spMetaDataFile.getAbsolutePath(), ex);
ex.printStackTrace();
} finally {
IOUtils.closeQuietly(isr);
IOUtils.closeQuietly(is);
}
if (xmlDocument == null) {
return false;
}
XPathFactory factory = XPathFactory.newInstance();
XPath xPath = factory.newXPath();
String federationTag = null;
try {
federationTag = xPath.compile("count(//*[local-name() = 'EntitiesDescriptor'])").evaluate(xmlDocument);
} catch (XPathExpressionException ex) {
log.error("Failed to find IDP metadata file in relaying party file '{}'", spMetaDataFile.getAbsolutePath(), ex);
ex.printStackTrace();
}
return Integer.parseInt(federationTag) > 0;
}
use of javax.xml.xpath.XPath in project oxCore by GluuFederation.
the class Response method getAttributes.
public Map<String, List<String>> getAttributes() throws XPathExpressionException {
Map<String, List<String>> result = new HashMap<String, List<String>>();
XPath xPath = XPathFactory.newInstance().newXPath();
xPath.setNamespaceContext(NAMESPACES);
XPathExpression query = xPath.compile("/samlp:Response/saml:Assertion/saml:AttributeStatement/saml:Attribute");
NodeList nodes = (NodeList) query.evaluate(xmlDoc, XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
Node nameNode = node.getAttributes().getNamedItem("Name");
if (nameNode == null) {
continue;
}
String attributeName = nameNode.getNodeValue();
List<String> attributeValues = new ArrayList<String>();
NodeList nameChildNodes = node.getChildNodes();
for (int j = 0; j < nameChildNodes.getLength(); j++) {
Node nameChildNode = nameChildNodes.item(j);
if ("urn:oasis:names:tc:SAML:2.0:assertion".equalsIgnoreCase(nameChildNode.getNamespaceURI()) && "AttributeValue".equals(nameChildNode.getLocalName())) {
NodeList valueChildNodes = nameChildNode.getChildNodes();
for (int k = 0; k < valueChildNodes.getLength(); k++) {
Node valueChildNode = valueChildNodes.item(k);
attributeValues.add(valueChildNode.getNodeValue());
}
}
}
result.put(attributeName, attributeValues);
}
return result;
}
use of javax.xml.xpath.XPath in project oxCore by GluuFederation.
the class Response method isAuthnFailed.
public boolean isAuthnFailed() throws Exception {
XPath xPath = XPathFactory.newInstance().newXPath();
xPath.setNamespaceContext(NAMESPACES);
XPathExpression query = xPath.compile("/samlp:Response/samlp:Status/samlp:StatusCode");
NodeList nodes = (NodeList) query.evaluate(xmlDoc, XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getAttributes().getNamedItem("Value") == null) {
continue;
}
String statusCode = node.getAttributes().getNamedItem("Value").getNodeValue();
if (SAML_RESPONSE_STATUS_SUCCESS.equalsIgnoreCase(statusCode)) {
return false;
} else if (SAML_RESPONSE_STATUS_AUTHNFAILED.equalsIgnoreCase(statusCode)) {
return true;
} else if (SAML_RESPONSE_STATUS_RESPONDER.equalsIgnoreCase(statusCode)) {
// nothing?
continue;
}
}
return false;
}
use of javax.xml.xpath.XPath in project knime-core by knime.
the class AbstractInjector method run.
/**
* {@inheritDoc}
*/
@Override
public final void run() {
try {
prepareData();
m_introFileLock.lock();
try {
DocumentBuilder parser = m_parserFactory.newDocumentBuilder();
parser.setEntityResolver(EmptyDoctypeResolver.INSTANCE);
Document doc = parser.parse(m_templateFile);
XPath xpath = m_xpathFactory.newXPath();
injectData(doc, xpath);
processIntroProperties(doc, xpath);
writeFile(doc);
refreshIntroEditor();
} finally {
m_introFileLock.unlock();
}
} catch (Exception ex) {
NodeLogger.getLogger(getClass()).warn("Could not modify intro page: " + ex.getMessage(), ex);
}
}
Aggregations