use of org.jdom2.xpath.XPath in project mycore by MyCoRe-Org.
the class MCRSimpleModelXMLConverterTest method testToXML.
@Test
public void testToXML() throws Exception {
Document document = MCRSimpleModelXMLConverter.toXML(metsSimpleModel);
XPathFactory xPathFactory = XPathFactory.instance();
String documentAsString = new XMLOutputter(Format.getPrettyFormat()).outputString(document);
Arrays.asList(PATHS_TO_CHECK.split(";")).stream().map((String xpath) -> xPathFactory.compile(xpath, Filters.fboolean(), Collections.emptyMap(), Namespace.getNamespace("mets", "http://www.loc.gov/METS/"))).forEachOrdered(xPath -> {
Boolean evaluate = xPath.evaluateFirst(document);
Assert.assertTrue(String.format("The xpath : %s is not true! %s %s", xPath, System.lineSeparator(), documentAsString), evaluate);
});
}
use of org.jdom2.xpath.XPath in project jspwiki by apache.
the class WebContainerAuthorizer method getRoles.
/**
* Protected method that extracts the roles from JSPWiki's web application
* deployment descriptor. Each Role is constructed by using the String
* representation of the Role, for example
* <code>new Role("Administrator")</code>.
* @param webxml the web application deployment descriptor
* @return an array of Role objects
* @throws JDOMException if elements cannot be parsed correctly
*/
protected Role[] getRoles(Document webxml) throws JDOMException {
Set<Role> roles = new HashSet<Role>();
Element root = webxml.getRootElement();
// Get roles referred to by constraints
String selector = "//j:web-app/j:security-constraint/j:auth-constraint/j:role-name";
XPath xpath = XPath.newInstance(selector);
xpath.addNamespace("j", J2EE_SCHEMA_25_NAMESPACE);
List<?> nodes = xpath.selectNodes(root);
for (Iterator<?> it = nodes.iterator(); it.hasNext(); ) {
String role = ((Element) it.next()).getTextTrim();
roles.add(new Role(role));
}
// Get all defined roles
selector = "//j:web-app/j:security-role/j:role-name";
xpath = XPath.newInstance(selector);
xpath.addNamespace("j", J2EE_SCHEMA_25_NAMESPACE);
nodes = xpath.selectNodes(root);
for (Iterator<?> it = nodes.iterator(); it.hasNext(); ) {
String role = ((Element) it.next()).getTextTrim();
roles.add(new Role(role));
}
return roles.toArray(new Role[roles.size()]);
}
use of org.jdom2.xpath.XPath in project mycore by MyCoRe-Org.
the class MCRXEditorTransformer method createRootElement.
private Element createRootElement(String xPath) throws JaxenException {
BaseXPath baseXPath = new BaseXPath(xPath, new DocumentNavigator());
LocationPath lp = (LocationPath) (baseXPath.getRootExpr());
NameStep nameStep = (NameStep) (lp.getSteps().get(0));
String prefix = nameStep.getPrefix();
Namespace ns = prefix.isEmpty() ? Namespace.NO_NAMESPACE : MCRConstants.getStandardNamespace(prefix);
return new Element(nameStep.getLocalName(), ns);
}
use of org.jdom2.xpath.XPath in project mycore by MyCoRe-Org.
the class MCRSubselectReturnTarget method getBaseXPathForSubselect.
private String getBaseXPathForSubselect(MCREditorSession session) throws JaxenException, JDOMException {
Document doc = session.getEditedXML();
MCRChangeData change = session.getChangeTracker().findLastChange(doc);
String text = change.getText();
String xPath = text.substring(text.lastIndexOf(" ") + 1).trim();
return bindsFirstOrMoreThanOneElement(xPath, session) ? xPath + "[1]" : xPath;
}
use of org.jdom2.xpath.XPath in project mycore by MyCoRe-Org.
the class MCRLayoutUtilities method getAncestorLabels.
/**
* Returns all labels of the ancestor axis for the given item within
* navigation.xml
*
* @param item a navigation item
* @return Label as String, like "labelRoot > labelChild >
* labelChildOfChild"
*/
public static String getAncestorLabels(Element item) {
StringBuilder label = new StringBuilder();
String lang = MCRSessionMgr.getCurrentSession().getCurrentLanguage().trim();
XPathExpression<Element> xpath;
Element ic = null;
xpath = XPATH_FACTORY.compile("//.[@href='" + getWebpageID(item) + "']", Filters.element());
ic = xpath.evaluateFirst(getNavi());
while (ic.getName().equals("item")) {
ic = ic.getParentElement();
String webpageID = getWebpageID(ic);
Element labelEl = null;
xpath = XPATH_FACTORY.compile("//.[@href='" + webpageID + "']/label[@xml:lang='" + lang + "']", Filters.element());
labelEl = xpath.evaluateFirst(getNavi());
if (labelEl != null) {
if (label.length() == 0) {
label = new StringBuilder(labelEl.getTextTrim());
} else {
label.insert(0, labelEl.getTextTrim() + " > ");
}
}
}
return label.toString();
}
Aggregations