org.jdom2.output.DOMOutputter Java Examples
The following examples show how to use
org.jdom2.output.DOMOutputter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MCRXEditorValidatorTest.java From mycore with GNU General Public License v3.0 | 5 votes |
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); }
Example #2
Source File: MCRMODSPagesHelper.java From mycore with GNU General Public License v3.0 | 5 votes |
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; }
Example #3
Source File: MCRIdentifierXSLUtils.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * 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)); MCRPIServiceManager.getInstance().getServiceList() .stream() .map((rs -> { Element service = new Element("service"); service.setAttribute("id", rs.getServiceID()); // Check if the inscriber of this service can read a PI try { if (rs.getMetadataService().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.getServiceID(); 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"); }
Example #4
Source File: MCRWebsiteWriteProtection.java From mycore with GNU General Public License v3.0 | 5 votes |
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); } }
Example #5
Source File: MCRXMLFunctions.java From mycore with GNU General Public License v3.0 | 5 votes |
public static Node document(String uri) throws JDOMException, IOException, SAXException, TransformerException { MCRSourceContent sourceContent = MCRSourceContent.getInstance(uri); if (sourceContent == null) { throw new TransformerException("Could not load document: " + uri); } DOMOutputter out = new DOMOutputter(); return out.output(sourceContent.asXML()); }
Example #6
Source File: MCRXMLFunctions.java From mycore with GNU General Public License v3.0 | 5 votes |
/** * @param uri the uri to resolve */ public static NodeList resolve(String uri) throws JDOMException { org.jdom2.Element element = MCRURIResolver.instance().resolve(uri); element.detach(); org.jdom2.Document document = new org.jdom2.Document(element); return new DOMOutputter().output(document).getDocumentElement().getChildNodes(); }
Example #7
Source File: DigitalSignature.java From yawl with GNU Lesser General Public License v3.0 | 5 votes |
public String PrepareDocumentToBeSign(Element element) { try{ //extract the Document to sign and transform it in a valid XML DOM Element rootElement = new Element(element.getName()); rootElement.setContent(element.cloneContent()); //convert the Element in a JDOM Document Document xdoc = new Document( rootElement ); //create a DOMOutputter to write the content of the JDOM document in a DOM document DOMOutputter outputter = new DOMOutputter(); org.w3c.dom.Document Doctosign = outputter.output(xdoc); // Show the document before being sign System.out.println("xml to Sign:"); XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat()); sortie.output(xdoc, System.out); //Transform the XML DOM in a String using the xml transformer DOMSource domSource = new DOMSource(Doctosign); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.transform(domSource, result); String StringTobeSign = writer.toString(); return StringTobeSign; } catch (Exception e) { e.printStackTrace(); return null; } }
Example #8
Source File: MCRLayoutUtilities.java From mycore with GNU General Public License v3.0 | 4 votes |
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; }
Example #9
Source File: ExportToWordService.java From isis-app-todoapp with Apache License 2.0 | 4 votes |
private org.w3c.dom.Document asInputW3cDocument(final List<ToDoItem> items) throws JDOMException { final Document jdomDoc = asInputDocument(items); final DOMOutputter domOutputter = new DOMOutputter(); return domOutputter.output(jdomDoc); }
Example #10
Source File: WireFeedOutput.java From rome with Apache License 2.0 | 3 votes |
/** * Creates a W3C DOM document for the given WireFeed. * <p> * This method does not use the feed encoding property. * <p> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. * <p> * * @param feed Abstract feed to create W3C DOM document from. The type of the WireFeed must * match the type given to the FeedOuptut constructor. * @return the W3C DOM document for the given WireFeed. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed * don't match. * @throws FeedException thrown if the W3C DOM document for the feed could not be created. * */ public org.w3c.dom.Document outputW3CDom(final WireFeed feed) throws IllegalArgumentException, FeedException { final Document doc = outputJDom(feed); final DOMOutputter outputter = new DOMOutputter(); try { return outputter.output(doc); } catch (final JDOMException jdomEx) { throw new FeedException("Could not create DOM", jdomEx); } }