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;
}
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);
}
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;
}
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);
}
}
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><service id="service1" inscribed="false" permission="true" type="urn" /></li>
* <li><service id="service2" inscribed="true" permission="false" type="doi" /></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");
}
Aggregations