Java Code Examples for org.jdom2.output.DOMOutputter#output()
The following examples show how to use
org.jdom2.output.DOMOutputter#output() .
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: 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 2
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 3
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 4
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 5
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); } }