use of org.jdom2.xpath.XPathExpression in project mycore by MyCoRe-Org.
the class MCRURNObjectXPathMetadataManager method removeIdentifier.
@Override
public void removeIdentifier(MCRDNBURN identifier, MCRBase obj, String additional) {
String xpath = getProperties().get("Xpath");
Document xml = obj.createXML();
XPathFactory xPathFactory = XPathFactory.instance();
XPathExpression<Element> xp = xPathFactory.compile(xpath, Filters.element());
List<Element> elements = xp.evaluate(xml);
elements.stream().filter(element -> element.getTextTrim().equals(identifier.asString())).forEach(Element::detach);
}
use of org.jdom2.xpath.XPathExpression in project mycore by MyCoRe-Org.
the class MCRURNUtils method getDNBRegisterDate.
public static Date getDNBRegisterDate(String identifier) throws MCRIdentifierUnresolvableException, ParseException {
Document document = MCRDNBPIDefProvider.get(identifier);
XPathExpression<Element> xp = XPathFactory.instance().compile(".//pidef:created[contains(../pidef:identifier, '" + identifier + "')]", Filters.element(), null, MCRConstants.PIDEF_NAMESPACE);
Element element = xp.evaluateFirst(document);
if (element == null) {
return null;
}
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.GERMAN).parse(element.getText());
}
use of org.jdom2.xpath.XPathExpression in project mycore by MyCoRe-Org.
the class MCRAclEditorResource method transform.
protected InputStream transform(String xmlFile) throws Exception {
InputStream guiXML = getClass().getResourceAsStream(xmlFile);
if (guiXML == null) {
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).build());
}
SAXBuilder saxBuilder = new SAXBuilder();
Document webPage = saxBuilder.build(guiXML);
XPathExpression<Object> xpath = XPathFactory.instance().compile("/MyCoReWebPage/section/div[@id='mycore-acl-editor2']");
Object node = xpath.evaluateFirst(webPage);
MCRSession mcrSession = MCRSessionMgr.getCurrentSession();
String lang = mcrSession.getCurrentLanguage();
if (node != null) {
Element mainDiv = (Element) node;
mainDiv.setAttribute("lang", lang);
String bsPath = CONFIG.getString("MCR.bootstrap.path", "");
if (!bsPath.equals("")) {
bsPath = MCRFrontendUtil.getBaseURL() + bsPath;
Element item = new Element("link").setAttribute("href", bsPath).setAttribute("rel", "stylesheet").setAttribute("type", "text/css");
mainDiv.addContent(0, item);
}
}
MCRContent content = MCRJerseyUtil.transform(webPage, request);
return content.getInputStream();
}
use of org.jdom2.xpath.XPathExpression in project mycore by MyCoRe-Org.
the class MCRLayoutUtilities method getItem.
/**
* Returns a Element presentation of an item[@href=$webpageID]
*
* @param webpageID
* @return Element
*/
private static Element getItem(String webpageID) {
Element item = itemStore.get(webpageID);
if (item == null) {
XPathExpression<Element> xpath = XPATH_FACTORY.compile("//.[@href='" + webpageID + "']", Filters.element());
item = xpath.evaluateFirst(getNavi());
itemStore.put(webpageID, item);
}
return item;
}
use of org.jdom2.xpath.XPathExpression in project mycore by MyCoRe-Org.
the class MCRClassificationMappingEventHandler method createMapping.
private void createMapping(MCRObject obj) {
MCRMetaElement mappings = obj.getMetadata().getMetadataElement("mappings");
if (mappings != null) {
oldMappings = mappings.clone();
obj.getMetadata().removeMetadataElement("mappings");
}
Element currentClassElement = null;
try {
Document doc = new Document(obj.getMetadata().createXML().detach());
XPathExpression<Element> classElementPath = XPathFactory.instance().compile("//*[@categid]", Filters.element());
List<Element> classList = classElementPath.evaluate(doc);
if (classList.size() > 0) {
mappings = new MCRMetaElement();
mappings.setTag("mappings");
mappings.setClass(MCRMetaClassification.class);
mappings.setHeritable(false);
mappings.setNotInherit(true);
obj.getMetadata().setMetadataElement(mappings);
}
for (Element classElement : classList) {
currentClassElement = classElement;
MCRCategory categ = DAO.getCategory(new MCRCategoryID(classElement.getAttributeValue("classid"), classElement.getAttributeValue("categid")), 0);
addMappings(mappings, categ);
}
} catch (Exception je) {
if (currentClassElement == null) {
LOGGER.error("Error while finding classification elements", je);
} else {
LOGGER.error("Error while finding classification elements for {}", new XMLOutputter().outputString(currentClassElement), je);
}
} finally {
if (mappings == null || mappings.size() == 0) {
obj.getMetadata().removeMetadataElement("mappings");
}
}
}
Aggregations