use of javax.xml.xpath.XPath in project oxCore by GluuFederation.
the class XmlService method getNodeValue.
public String getNodeValue(Document xmlDocument, String xPathExpression, String attributeName) throws XPathExpressionException {
XPath xPath = XPathFactory.newInstance().newXPath();
XPathExpression formXPathExpression = xPath.compile(xPathExpression);
if (StringHelper.isEmpty(attributeName)) {
String nodeValue = (String) formXPathExpression.evaluate(xmlDocument, XPathConstants.STRING);
return nodeValue;
}
Node node = ((Node) formXPathExpression.evaluate(xmlDocument, XPathConstants.NODE));
if (node == null) {
return null;
}
Node attributeNode = node.getAttributes().getNamedItem(attributeName);
if (attributeNode == null) {
return null;
}
return attributeNode.getNodeValue();
}
use of javax.xml.xpath.XPath in project oxTrust by GluuFederation.
the class LogDir method readConfig.
private List<LogDir> readConfig(String source) {
List<LogDir> logDirs = new ArrayList<LogDir>();
try {
org.w3c.dom.Document document = xmlService.getXmlDocument(FileUtils.readFileToByteArray(new File(source)));
XPath xPath = XPathFactory.newInstance().newXPath();
XPathExpression entriesXPath = xPath.compile("/entries/entry");
NodeList list = (NodeList) entriesXPath.evaluate(document, XPathConstants.NODESET);
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
String prefix = null;
String location = null;
String extension = null;
NodeList subList = node.getChildNodes();
for (int j = 0; j < subList.getLength(); j++) {
Node subNode = subList.item(j);
String subNodeName = subNode.getNodeName();
String subNodeValue = subNode.getTextContent();
if (StringHelper.equalsIgnoreCase(subNodeName, "prefix")) {
prefix = subNodeValue;
} else if (StringHelper.equalsIgnoreCase(subNodeName, "location")) {
location = subNodeValue;
} else if (StringHelper.equalsIgnoreCase(subNodeName, "extension")) {
extension = subNodeValue;
}
}
if (extension == null || extension.trim().equals("")) {
extension = "log";
}
LogDir logDir = new LogDir(prefix, location, extension);
logDirs.add(logDir);
log.debug("Prefix: " + prefix + " Location: " + location);
}
} catch (Exception ex) {
log.debug("Exception while reading configuration file: " + ex);
}
return logDirs;
}
use of javax.xml.xpath.XPath in project oxTrust by GluuFederation.
the class FilterService method parseFilters.
public void parseFilters(GluuSAMLTrustRelationship trustRelationship) throws SAXException, IOException, ParserConfigurationException, FactoryConfigurationError, XPathExpressionException {
if (trustRelationship.getGluuSAMLMetaDataFilter() != null) {
XPath xPath = XPathFactory.newInstance().newXPath();
for (String filterXML : trustRelationship.getGluuSAMLMetaDataFilter()) {
Document xmlDocument = xmlService.getXmlDocument(filterXML.getBytes());
if (xmlDocument.getFirstChild().getAttributes().getNamedItem("xsi:type").getNodeValue().equals(VALIDATION_TYPE)) {
MetadataFilter filter = createMetadataFilter("validation");
XPathExpression contactCountXPath = xPath.compile("count(/MetadataFilter/ExtensionSchema)");
int schemasNumber = Integer.parseInt(contactCountXPath.evaluate(xmlDocument));
for (int i = 1; i <= schemasNumber; i++) {
contactCountXPath = xPath.compile("/MetadataFilter/ExtensionSchema[" + i + "]");
filter.getExtensionSchemas().add(contactCountXPath.evaluate(xmlDocument));
}
trustRelationship.getMetadataFilters().put("validation", filter);
continue;
}
if (xmlDocument.getFirstChild().getAttributes().getNamedItem("xsi:type").getNodeValue().equals(ENTITY_ROLE_WHITE_LIST_TYPE)) {
MetadataFilter filter = createMetadataFilter("entityRoleWhiteList");
filter.setRemoveRolelessEntityDescriptors(Boolean.parseBoolean(xmlDocument.getFirstChild().getAttributes().getNamedItem("removeRolelessEntityDescriptors").getNodeValue()));
filter.setRemoveEmptyEntitiesDescriptors(Boolean.parseBoolean(xmlDocument.getFirstChild().getAttributes().getNamedItem("removeEmptyEntitiesDescriptors").getNodeValue()));
XPathExpression contactCountXPath = xPath.compile("count(/MetadataFilter/RetainedRole)");
int schemasNumber = Integer.parseInt(contactCountXPath.evaluate(xmlDocument));
for (int i = 1; i <= schemasNumber; i++) {
contactCountXPath = xPath.compile("/MetadataFilter/RetainedRole[" + i + "]");
filter.getRetainedRoles().add(contactCountXPath.evaluate(xmlDocument));
}
trustRelationship.getMetadataFilters().put("entityRoleWhiteList", filter);
continue;
}
if (xmlDocument.getFirstChild().getAttributes().getNamedItem("xsi:type").getNodeValue().equals(VALID_UNTIL_REQUIRED_TYPE)) {
MetadataFilter filter = createMetadataFilter("requiredValidUntil");
filter.setMaxValidityInterval(Integer.parseInt(xmlDocument.getFirstChild().getAttributes().getNamedItem("maxValidityInterval").getNodeValue()));
trustRelationship.getMetadataFilters().put("requiredValidUntil", filter);
continue;
}
if (xmlDocument.getFirstChild().getAttributes().getNamedItem("xsi:type").getNodeValue().equals(SIGNATURE_VALIDATION_TYPE)) {
MetadataFilter filter = createMetadataFilter("signatureValidation");
filter.setFilterCertFileName(StringHelper.removePunctuation(trustRelationship.getInum()));
trustRelationship.getMetadataFilters().put("signatureValidation", filter);
continue;
}
}
}
}
use of javax.xml.xpath.XPath in project uPortal by Jasig.
the class SimpleLayout method getRootId.
@Override
public String getRootId() {
String rootNode = null;
try {
String expression = "/layout/folder";
XPathFactory fac = XPathFactory.newInstance();
XPath xpath = fac.newXPath();
Element rootNodeE = (Element) xpath.evaluate(expression, layout, XPathConstants.NODE);
rootNode = rootNodeE.getAttribute("ID");
} catch (Exception e) {
log.error("Error getting root id.", e);
}
return rootNode;
}
use of javax.xml.xpath.XPath in project sling by apache.
the class OsgiMetadataUtil method queryNodes.
private static NodeList queryNodes(Document metadata, String xpathQuery) {
try {
XPath xpath = XPATH_FACTORY.newXPath();
xpath.setNamespaceContext(NAMESPACE_CONTEXT);
return (NodeList) xpath.evaluate(xpathQuery, metadata, XPathConstants.NODESET);
} catch (XPathExpressionException ex) {
throw new RuntimeException("Error evaluating XPath: " + xpathQuery, ex);
}
}
Aggregations