List of usage examples for org.jdom2.output XMLOutputter outputString
public final String outputString(EntityRef entity)
From source file:org.mycore.oai.MCROAIObjectManager.java
License:Open Source License
protected Element getURI(String uri) { Element e = MCRURIResolver.instance().resolve(uri).detach(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("get " + uri); XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); LOGGER.debug(out.outputString(e)); }//from ww w. j av a 2 s. c o m return e; }
From source file:org.onosproject.provider.netconf.device.impl.NetconfDevice.java
License:Apache License
private void printPrettyXML(String xmlstring) { try {/*from w ww . j ava2 s .c o m*/ Document doc = new SAXBuilder().build(new StringReader(xmlstring)); XMLOutputter xmOut = new XMLOutputter(Format.getPrettyFormat()); String outputString = xmOut.outputString(doc); log.debug(outputString); } catch (Exception e) { log.error("ERROR while parsing the XML " + xmlstring, e); } }
From source file:org.onosproject.provider.netconf.flow.impl.XmlBuilder.java
License:Apache License
public String buildAclRequestXml(AccessList accessList) { Document doc = new Document(); Namespace namespaceRpc = Namespace.getNamespace("urn:ietf:params:xml:ns:netconf:base:1.0"); Namespace accessNamespaceRpc = Namespace.getNamespace("urn:ietf:params:xml:ns:yang:ietf-acl"); doc.setRootElement(new Element("rpc", namespaceRpc).setAttribute("message-id", "101")); /**//ww w . j ava 2 s . c o m * Access list elements of given ACL model. */ Element access = new Element("access-list", accessNamespaceRpc); access.addContent(new Element("acl-name", accessNamespaceRpc).setText(accessList.getAclName())); // access.addContent(accessEntries); if (!accessList.getAccessListEntries().isEmpty() && accessList.getAccessListEntries() != null) { for (int accessEntryIntVlu = 0; accessEntryIntVlu < accessList.getAccessListEntries() .size(); accessEntryIntVlu++) { access.addContent(getAccessEntries(accessEntryIntVlu, accessList, accessNamespaceRpc)); } } /** * edit-config operation for given ACL model. */ Element editConfig = new Element("edit-config", namespaceRpc); editConfig.addContent(new Element("target", namespaceRpc).addContent(new Element("running", namespaceRpc))); editConfig .addContent(new Element("config", Namespace.getNamespace("urn:ietf:params:xml:ns:netconf:base:1.0")) .addContent(access)); doc.getRootElement().addContent(editConfig); XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat()); String outputString = xmlOutputter.outputString(doc); return outputString; }
From source file:org.openmrs.module.dataaggregation.web.controller.DataAggregationManageController.java
License:Open Source License
private String convertToXML(String csvString) { String[] rows = csvString.split("\n"); Element table = new Element("table"); Document doc = new Document(table); int i = 0;//www . java2 s .com while (i < rows.length) { Element row = new Element("row" + i); String[] cols = rows[i].split(":"); int j = 0; for (String rowS : cols) { row.setAttribute(new Attribute("col" + j, rowS)); j++; } doc.getRootElement().addContent(row); i++; } XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); return xmlOutput.outputString(doc); }
From source file:org.roda.core.common.MetadataFileUtils.java
public static ContentPayload getMetadataPayload(TransferredResource transferredResource) { try {//from ww w. j av a 2 s .c om Element root = new Element("metadata"); org.jdom2.Document doc = new org.jdom2.Document(); Element child = new Element("field"); child.setAttribute("name", "title"); child.addContent(transferredResource.getName()); root.addContent(child); doc.setRootElement(root); XMLOutputter outter = new XMLOutputter(); outter.setFormat(Format.getPrettyFormat()); outter.outputString(doc); return new StringContentPayload(outter.outputString(doc)); } catch (IllegalDataException e) { LOGGER.debug("Error generating TransferredResource metadata file {}", e.getMessage()); return new StringContentPayload(""); } }
From source file:org.roda.core.plugins.plugins.characterization.TikaFullTextPluginUtils.java
private static String generateMetadataFile(Metadata metadata) throws IOException { try {/*from w w w . java 2 s . c om*/ String[] names = metadata.names(); Element root = new Element("metadata"); org.jdom2.Document doc = new org.jdom2.Document(); for (String name : names) { String[] values = metadata.getValues(name); if (values != null && values.length > 0) { for (String value : values) { Element child = new Element("field"); child.setAttribute("name", MetadataFileUtils.escapeAttribute(name)); child.addContent(MetadataFileUtils.escapeContent(value)); root.addContent(child); } } } doc.setRootElement(root); XMLOutputter outter = new XMLOutputter(); outter.setFormat(Format.getPrettyFormat()); outter.outputString(doc); return outter.outputString(doc); } catch (IllegalDataException e) { LOGGER.debug("Error generating Tika metadata file {}", e.getMessage()); return ""; } }
From source file:org.roda_project.commons_ip.model.impl.bagit.BagitUtils.java
public static String generateMetadataFile(Path metadataPath) throws IllegalDataException { Map<String, String> bagInfo = getBagitInfo(metadataPath); Element root = new Element(IPConstants.BAGIT_METADATA); org.jdom2.Document doc = new org.jdom2.Document(); for (Map.Entry<String, String> entry : bagInfo.entrySet()) { if (!IPConstants.BAGIT_PARENT.equalsIgnoreCase(entry.getKey())) { Element child = new Element(IPConstants.BAGIT_FIELD); child.setAttribute(IPConstants.BAGIT_NAME, XmlEscapers.xmlAttributeEscaper().escape(entry.getKey())); child.addContent(entry.getValue()); root.addContent(child);// ww w . ja v a 2 s . co m } } doc.setRootElement(root); XMLOutputter outter = new XMLOutputter(); outter.setFormat(Format.getPrettyFormat()); return outter.outputString(doc); }
From source file:org.rometools.feed.module.content.io.ContentModuleParser.java
License:Open Source License
protected String getXmlInnerText(Element e) { StringBuffer sb = new StringBuffer(); XMLOutputter xo = new XMLOutputter(); List children = e.getContent(); sb.append(xo.outputString(children)); return sb.toString(); }
From source file:org.yawlfoundation.yawl.swingWorklist.YWorklistModel.java
License:Open Source License
private JPanel createCentrePanel(YDataStateException exception) { XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); JPanel centrePanel = new JPanel(new GridLayout(1, 2)); JPanel schemaPanel = new JPanel(new BorderLayout()); schemaPanel.setBackground(YAdminGUI._apiColour); schemaPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Schema for completing task"), BorderFactory.createEmptyBorder(10, 10, 10, 10))); JTextPane schemaTextPane = new JTextPane(); schemaTextPane.setContentType("text/xml"); schemaTextPane.setFont(new Font("courier", Font.PLAIN, 12)); String schemaXML = xmlOut.outputString(exception.getSchema()); /**//from w w w. j a va 2 s .c o m * AJH: Trap various XML format errors gracefully. */ try { String xml = schemaXML.substring(schemaXML.indexOf('<'), schemaXML.lastIndexOf("</xsd:schema>") + 13); schemaTextPane.setText(xml); } catch (Exception e) { schemaTextPane.setText(schemaXML); } schemaTextPane.setEditable(false); schemaTextPane.setBackground(Color.LIGHT_GRAY); JPanel noWrapPanel = new JPanel(); noWrapPanel.setLayout(new BorderLayout()); noWrapPanel.add(schemaTextPane); schemaPanel.add(new JScrollPane(noWrapPanel)); JPanel rightPanel = new JPanel(new GridLayout(2, 1)); JPanel dataPanel = new JPanel(new BorderLayout()); dataPanel.setBackground(YAdminGUI._apiColour); dataPanel .setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "The data that failed to validate"), BorderFactory.createEmptyBorder(10, 10, 10, 10))); JTextPane dataTextPane = new JTextPane(); dataTextPane.setContentType("text/xml"); dataTextPane.setFont(new Font("courier", Font.PLAIN, 12)); String data = xmlOut.outputString(exception.get_dataInput()); /** * AJH: Trap various XML format errors gracefully. */ try { String temp = data.substring(data.lastIndexOf("<?xml"), data.lastIndexOf('>')); dataTextPane.setText(temp); } catch (Exception e) { dataTextPane.setText(data); } dataTextPane.setEditable(false); dataTextPane.setBackground(Color.LIGHT_GRAY); JPanel noWrapPanel2 = new JPanel(); noWrapPanel2.setLayout(new BorderLayout()); noWrapPanel2.add(dataTextPane); dataPanel.add(new JScrollPane(noWrapPanel2)); JPanel errorPanel = new JPanel(new BorderLayout()); errorPanel.setBackground(YAdminGUI._apiColour); errorPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "The error message from validation engine"), BorderFactory.createEmptyBorder(10, 10, 10, 10))); JTextPane errorTextPane = new JTextPane(); errorTextPane.setContentType("text/plain"); errorTextPane.setFont(new Font("courier", Font.PLAIN, 12)); /** * AJH: Trap various XML format errors gracefully. */ try { String error = schemaXML.substring(schemaXML.lastIndexOf("ERRORS ="), schemaXML.length()); errorTextPane.setText(error); } catch (Exception e) { // null action ! } errorTextPane.setText(exception.getErrors()); errorTextPane.setEditable(false); errorTextPane.setBackground(Color.LIGHT_GRAY); JPanel noWrapPanel3 = new JPanel(); noWrapPanel3.setLayout(new BorderLayout()); noWrapPanel3.add(errorTextPane); errorPanel.add(new JScrollPane(noWrapPanel3)); rightPanel.add(dataPanel); rightPanel.add(errorPanel); centrePanel.add(schemaPanel, BorderLayout.NORTH); centrePanel.add(rightPanel, BorderLayout.CENTER); return centrePanel; }
From source file:org.yawlfoundation.yawl.util.JDOMUtil.java
License:Open Source License
/****************************************************************************/ public static String documentToString(Document doc) { if (doc == null) return null; XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); return out.outputString(doc); }