Search in sources :

Example 6 with XPath

use of org.jdom2.xpath.XPath in project mycore by MyCoRe-Org.

the class MCRAndOthersTransformer method buildField.

void buildField(BibtexPerson person, Element parent) {
    Element modsName = buildElement(xPath, null, parent);
    buildElement("mods:etAl", null, modsName);
}
Also used : Element(org.jdom2.Element)

Example 7 with XPath

use of org.jdom2.xpath.XPath in project mycore by MyCoRe-Org.

the class MCRPagesTransformer method buildField.

void buildField(BibtexAbstractValue value, Element parent) {
    String pages = ((BibtexString) value).getContent();
    pages = normalizeValue(pages);
    Element part = buildElement(xPath, null, parent);
    part.addContent(MCRMODSPagesHelper.buildExtentPages(pages));
}
Also used : Element(org.jdom2.Element) BibtexString(bibtex.dom.BibtexString) BibtexString(bibtex.dom.BibtexString)

Example 8 with XPath

use of org.jdom2.xpath.XPath 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);
}
Also used : MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRMetadataManager(org.mycore.datamodel.metadata.MCRMetadataManager) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) XPathFactory(org.jdom2.xpath.XPathFactory) MCRPersistentIdentifier(org.mycore.pi.MCRPersistentIdentifier) MCRException(org.mycore.common.MCRException) Text(org.jdom2.Text) XPathExpression(org.jdom2.xpath.XPathExpression) Document(org.jdom2.Document) List(java.util.List) MCRObject(org.mycore.datamodel.metadata.MCRObject) Optional(java.util.Optional) MCRPersistentIdentifierMetadataManager(org.mycore.pi.MCRPersistentIdentifierMetadataManager) Filters(org.jdom2.filter.Filters) MCRNodeBuilder(org.mycore.common.xml.MCRNodeBuilder) Element(org.jdom2.Element) XPathFactory(org.jdom2.xpath.XPathFactory) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 9 with XPath

use of org.jdom2.xpath.XPath 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();
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) MCRSession(org.mycore.common.MCRSession) WebApplicationException(javax.ws.rs.WebApplicationException) InputStream(java.io.InputStream) Element(org.jdom2.Element) JsonObject(com.google.gson.JsonObject) Document(org.jdom2.Document) MCRContent(org.mycore.common.content.MCRContent)

Example 10 with XPath

use of org.jdom2.xpath.XPath 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;
}
Also used : Element(org.jdom2.Element)

Aggregations

Element (org.jdom2.Element)24 Document (org.jdom2.Document)11 IOException (java.io.IOException)4 Attribute (org.jdom2.Attribute)4 JDOMException (org.jdom2.JDOMException)4 MCRException (org.mycore.common.MCRException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 URISyntaxException (java.net.URISyntaxException)3 Text (org.jdom2.Text)3 XPath (org.jdom2.xpath.XPath)3 XPathFactory (org.jdom2.xpath.XPathFactory)3 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)3 MCRObject (org.mycore.datamodel.metadata.MCRObject)3 XmlException (gov.cms.qpp.conversion.xml.XmlException)2 List (java.util.List)2 TransformerException (javax.xml.transform.TransformerException)2 XPath (javax.xml.xpath.XPath)2 MCRPersistenceException (org.mycore.common.MCRPersistenceException)2 MCRPath (org.mycore.datamodel.niofs.MCRPath)2 MCRPersistentIdentifierException (org.mycore.pi.exceptions.MCRPersistentIdentifierException)2