use of org.jdom2.xpath.XPathExpression in project pwm by pwm-project.
the class StoredConfigurationImpl method readLocaleBundleMap.
public Map<String, String> readLocaleBundleMap(final String bundleName, final String keyName) {
domModifyLock.readLock().lock();
try {
final XPathExpression xp = XPathBuilder.xpathForLocaleBundleSetting(bundleName, keyName);
final Element localeBundleElement = (Element) xp.evaluateFirst(document);
if (localeBundleElement != null) {
final Map<String, String> bundleMap = new LinkedHashMap<>();
for (final Element valueElement : localeBundleElement.getChildren("value")) {
final String localeStrValue = valueElement.getAttributeValue("locale");
bundleMap.put(localeStrValue == null ? "" : localeStrValue, valueElement.getText());
}
if (!bundleMap.isEmpty()) {
return bundleMap;
}
}
} finally {
domModifyLock.readLock().unlock();
}
return Collections.emptyMap();
}
use of org.jdom2.xpath.XPathExpression in project pwm by pwm-project.
the class PwmSettingXml method readSettingXml.
static Element readSettingXml(final PwmSetting setting) {
final XPathFactory xpfac = XPathFactory.instance();
final XPathExpression xp = xpfac.compile("/settings/setting[@key=\"" + setting.getKey() + "\"]");
return (Element) xp.evaluateFirst(readXml());
}
use of org.jdom2.xpath.XPathExpression in project tutorials by eugenp.
the class JDomParser method getNodeById.
public Element getNodeById(String id) {
try {
SAXBuilder builder = new SAXBuilder();
Document document = (Document) builder.build(file);
String filter = "//*[@tutId='" + id + "']";
XPathFactory xFactory = XPathFactory.instance();
XPathExpression<Element> expr = xFactory.compile(filter, Filters.element());
List<Element> node = expr.evaluate(document);
return node.get(0);
} catch (JDOMException | IOException e) {
e.printStackTrace();
return null;
}
}
use of org.jdom2.xpath.XPathExpression 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();
}
use of org.jdom2.xpath.XPathExpression in project mycore by MyCoRe-Org.
the class MCRDerivate method getUrnMap.
/**
* Reads all files and urns from the derivate.
*
* @return A {@link Map} which contains the files as key and the urns as value. If no URN assigned the map will be empty.
*/
public Map<String, String> getUrnMap() {
Map<String, String> fileUrnMap = new HashMap<>();
XPathExpression<Element> filesetPath = XPathFactory.instance().compile("./mycorederivate/derivate/fileset", Filters.element());
Element result = filesetPath.evaluateFirst(this.createXML());
if (result == null) {
return fileUrnMap;
}
String urn = result.getAttributeValue("urn");
if (urn != null) {
XPathExpression<Element> filePath = XPathFactory.instance().compile("./mycorederivate/derivate/fileset[@urn='" + urn + "']/file", Filters.element());
List<Element> files = filePath.evaluate(this.createXML());
for (Element currentFileElement : files) {
String currentUrn = currentFileElement.getChildText("urn");
String currentFile = currentFileElement.getAttributeValue("name");
fileUrnMap.put(currentFile, currentUrn);
}
}
return fileUrnMap;
}
Aggregations