Search in sources :

Example 1 with DOMOutputter

use of org.jdom2.output.DOMOutputter in project mycore by MyCoRe-Org.

the class PagesMatcher method buildExtentPagesNodeSet.

public static NodeSet buildExtentPagesNodeSet(String input) throws JDOMException {
    Element extent = buildExtentPages(input);
    org.w3c.dom.Element domElement = new DOMOutputter().output(extent);
    NodeSet nodeSet = new NodeSet();
    nodeSet.addNode(domElement);
    return nodeSet;
}
Also used : NodeSet(org.apache.xpath.NodeSet) DOMOutputter(org.jdom2.output.DOMOutputter) Element(org.jdom2.Element)

Example 2 with DOMOutputter

use of org.jdom2.output.DOMOutputter in project mycore by MyCoRe-Org.

the class MCRXEditorValidatorTest method addRule.

private void addRule(MCREditorSession session, String baseXPath, String... attributes) throws JDOMException {
    Element rule = new Element("validation-rule");
    for (int i = 0; i < attributes.length; ) {
        rule.setAttribute(attributes[i++], attributes[i++]);
    }
    new Document(rule);
    org.w3c.dom.Element ruleAsDOMElement = new DOMOutputter().output(rule);
    session.getValidator().addRule(baseXPath, ruleAsDOMElement);
}
Also used : DOMOutputter(org.jdom2.output.DOMOutputter) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 3 with DOMOutputter

use of org.jdom2.output.DOMOutputter in project mycore by MyCoRe-Org.

the class MCRLayoutUtilities method getPersonalNavigation.

public static org.w3c.dom.Document getPersonalNavigation() throws JDOMException, XPathExpressionException {
    Document navi = getNavi();
    DOMOutputter accessCleaner = new DOMOutputter(new AccessCleaningDOMOutputProcessor());
    org.w3c.dom.Document personalNavi = accessCleaner.output(navi);
    XPath xpath = javax.xml.xpath.XPathFactory.newInstance().newXPath();
    NodeList emptyGroups = (NodeList) xpath.evaluate("/navigation/menu/group[not(item)]", personalNavi, XPathConstants.NODESET);
    for (int i = 0; i < emptyGroups.getLength(); ++i) {
        org.w3c.dom.Element group = (org.w3c.dom.Element) emptyGroups.item(i);
        group.getParentNode().removeChild(group);
    }
    NodeList emptyMenu = (NodeList) xpath.evaluate("/navigation/menu[not(item or group)]", personalNavi, XPathConstants.NODESET);
    for (int i = 0; i < emptyMenu.getLength(); ++i) {
        org.w3c.dom.Element menu = (org.w3c.dom.Element) emptyMenu.item(i);
        menu.getParentNode().removeChild(menu);
    }
    NodeList emptyNodes = (NodeList) xpath.evaluate("//text()[normalize-space(.) = '']", personalNavi, XPathConstants.NODESET);
    for (int i = 0; i < emptyNodes.getLength(); ++i) {
        Node emptyTextNode = emptyNodes.item(i);
        emptyTextNode.getParentNode().removeChild(emptyTextNode);
    }
    personalNavi.normalizeDocument();
    if (LOGGER.isDebugEnabled()) {
        try {
            String encoding = "UTF-8";
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer();
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            transformer.transform(new DOMSource(personalNavi), new StreamResult(bout));
            LOGGER.debug("personal navigation: {}", bout.toString(encoding));
        } catch (IllegalArgumentException | TransformerFactoryConfigurationError | TransformerException | UnsupportedEncodingException e) {
            LOGGER.warn("Error while getting debug information.", e);
        }
    }
    return personalNavi;
}
Also used : XPath(javax.xml.xpath.XPath) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) DOMOutputter(org.jdom2.output.DOMOutputter) StreamResult(javax.xml.transform.stream.StreamResult) NodeList(org.w3c.dom.NodeList) Element(org.jdom2.Element) Node(org.w3c.dom.Node) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.jdom2.Document) TransformerException(javax.xml.transform.TransformerException)

Example 4 with DOMOutputter

use of org.jdom2.output.DOMOutputter in project mycore by MyCoRe-Org.

the class MCRWebsiteWriteProtection method getMessage.

public static org.w3c.dom.Document getMessage() throws JDOMException, IOException {
    Element config = getConfiguration();
    if (config == null) {
        return new DOMOutputter().output(new Document());
    } else {
        Element messageElem = config.getChild("message");
        Document message = new Document(messageElem.clone());
        return new DOMOutputter().output(message);
    }
}
Also used : DOMOutputter(org.jdom2.output.DOMOutputter) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 5 with DOMOutputter

use of org.jdom2.output.DOMOutputter in project mycore by MyCoRe-Org.

the class MCRIdentifierXSLUtils method getPIServiceInformation.

/**
 * Gets all available services which are configured.
 * e.g.
 *   <ul>
 *     <li>&lt;service id="service1" inscribed="false" permission="true" type="urn" /&gt;</li>
 *     <li>&lt;service id="service2" inscribed="true" permission="false" type="doi" /&gt;</li>
 *   </ul>
 *
 * @param objectID the object
 * @return a Nodelist
 * @throws JDOMException
 */
public static NodeList getPIServiceInformation(String objectID) throws JDOMException {
    Element e = new Element("list");
    MCRBase obj = MCRMetadataManager.retrieve(MCRObjectID.getInstance(objectID));
    MCRConfiguration.instance().getPropertiesMap("MCR.PI.Registration.").keySet().stream().map(s -> s.substring("MCR.PI.Registration.".length())).filter(id -> !id.contains(".")).map((serviceID) -> MCRPIRegistrationServiceManager.getInstance().getRegistrationService(serviceID)).map((rs -> {
        Element service = new Element("service");
        service.setAttribute("id", rs.getRegistrationServiceID());
        // Check if the inscriber of this service can read a PI
        try {
            if (rs.getMetadataManager().getIdentifier(obj, "").isPresent()) {
                service.setAttribute("inscribed", "true");
            } else {
                service.setAttribute("inscribed", "false");
            }
        } catch (MCRPersistentIdentifierException e1) {
            LOGGER.warn("Error happened while try to read PI from object: {}", objectID, e1);
            service.setAttribute("inscribed", "false");
        }
        // rights
        String permission = "register-" + rs.getRegistrationServiceID();
        Boolean canRegister = MCRAccessManager.checkPermission(objectID, "writedb") && MCRAccessManager.checkPermission(obj.getId(), permission);
        service.setAttribute("permission", canRegister.toString().toLowerCase(Locale.ROOT));
        // add the type
        service.setAttribute("type", rs.getType());
        return service;
    })).forEach(e::addContent);
    return new DOMOutputter().output(e).getElementsByTagName("service");
}
Also used : MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRMetadataManager(org.mycore.datamodel.metadata.MCRMetadataManager) NodeList(org.w3c.dom.NodeList) DOMOutputter(org.jdom2.output.DOMOutputter) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) MCRConfiguration(org.mycore.common.config.MCRConfiguration) MCRPersistentIdentifier(org.mycore.pi.MCRPersistentIdentifier) MCRAccessManager(org.mycore.access.MCRAccessManager) MCRPIRegistrationService(org.mycore.pi.MCRPIRegistrationService) Logger(org.apache.logging.log4j.Logger) JDOMException(org.jdom2.JDOMException) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) Locale(java.util.Locale) MCRPersistentIdentifierManager(org.mycore.pi.MCRPersistentIdentifierManager) LogManager(org.apache.logging.log4j.LogManager) MCRPIRegistrationServiceManager(org.mycore.pi.MCRPIRegistrationServiceManager) Element(org.jdom2.Element) DOMOutputter(org.jdom2.output.DOMOutputter) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRPIRegistrationService(org.mycore.pi.MCRPIRegistrationService) Locale(java.util.Locale) Element(org.jdom2.Element) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException)

Aggregations

DOMOutputter (org.jdom2.output.DOMOutputter)7 Element (org.jdom2.Element)5 Document (org.jdom2.Document)3 TransformerException (javax.xml.transform.TransformerException)2 NodeList (org.w3c.dom.NodeList)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Locale (java.util.Locale)1 Transformer (javax.xml.transform.Transformer)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 TransformerFactoryConfigurationError (javax.xml.transform.TransformerFactoryConfigurationError)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 XPath (javax.xml.xpath.XPath)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 NodeSet (org.apache.xpath.NodeSet)1 JDOMException (org.jdom2.JDOMException)1 MCRAccessManager (org.mycore.access.MCRAccessManager)1 MCRConfiguration (org.mycore.common.config.MCRConfiguration)1