List of usage examples for org.jdom2.output XMLOutputter XMLOutputter
public XMLOutputter(XMLOutputProcessor processor)
XMLOutputter
with the specified XMLOutputProcessor. From source file:org.kitodo.docket.ExportXmlLog.java
License:Open Source License
/** * This method exports the production metadata for al list of processes as a * single file to a given stream./*ww w.jav a 2 s. com*/ * * @param docketDataList * a list of Docket data * @param outputStream * The output stream, to write the docket to. */ void startMultipleExport(Iterable<DocketData> docketDataList, OutputStream outputStream) { Document answer = new Document(); Element root = new Element("processes"); answer.setRootElement(root); Namespace xmlns = Namespace.getNamespace(NAMESPACE); Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.addNamespaceDeclaration(xsi); root.setNamespace(xmlns); Attribute attSchema = new Attribute("schemaLocation", NAMESPACE + " XML-logfile.xsd", xsi); root.setAttribute(attSchema); for (DocketData docketData : docketDataList) { Document doc = createDocument(docketData, false); Element processRoot = doc.getRootElement(); processRoot.detach(); root.addContent(processRoot); } XMLOutputter outp = new XMLOutputter(Format.getPrettyFormat()); try { outp.output(answer, outputStream); } catch (IOException e) { logger.error("Generating XML Output failed.", e); } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { logger.error("Closing the output stream failed.", e); } } } }
From source file:org.mule.tools.apikit.Helper.java
License:Open Source License
public static String nonSpaceOutput(Element element) { XMLOutputter xout = new XMLOutputter(Format.getCompactFormat()); return xout.outputString(element); }
From source file:org.mule.tools.apikit.Helper.java
License:Open Source License
public static String nonSpaceOutput(Document doc) { XMLOutputter xout = new XMLOutputter(Format.getCompactFormat()); return xout.outputString(doc.getRootElement().getChildren()); }
From source file:org.mule.tools.apikit.output.MuleConfigGenerator.java
License:Open Source License
public void generate() { Map<API, Document> docs = new HashMap<API, Document>(); for (GenerationModel flowEntry : flowEntries) { Document doc;//from ww w. j a va 2s . co m API api = flowEntry.getApi(); try { doc = getOrCreateDocument(docs, api); } catch (Exception e) { log.error("Error generating xml for file: [" + api.getYamlFile() + "]", e); continue; } // Generate each of the APIKit flows doc.getRootElement().addContent(new APIKitFlowScope(flowEntry).generate()); } // Write everything to files for (Map.Entry<API, Document> yamlFileDescriptorDocumentEntry : docs.entrySet()) { Format prettyFormat = Format.getPrettyFormat(); prettyFormat.setIndent(INDENTATION); prettyFormat.setLineSeparator(System.getProperty("line.separator")); prettyFormat.setEncoding("UTF-8"); XMLOutputter xout = new XMLOutputter(prettyFormat); Document doc = yamlFileDescriptorDocumentEntry.getValue(); File xmlFile = yamlFileDescriptorDocumentEntry.getKey().getXmlFile(rootDirectory); try { FileOutputStream fileOutputStream = new FileOutputStream(xmlFile); xout.output(doc, fileOutputStream); fileOutputStream.close(); log.info("Updating file: [" + xmlFile + "]"); } catch (IOException e) { log.error("Error writing to file: [" + xmlFile + "]", e); } } // Generate mule deploy properties file new MuleDeployWriter(rootDirectory).generate(); }
From source file:org.mycore.common.content.MCRDOMContent.java
License:Open Source License
@Override public void sendTo(OutputStream out) throws IOException { org.jdom2.Document jdom;/* www . j a v a 2 s .c o m*/ try { jdom = asXML(); } catch (JDOMException ex) { throw new IOException(ex); } new XMLOutputter(format).output(jdom, out); }
From source file:org.mycore.common.content.MCRJDOMContent.java
License:Open Source License
@Override public void sendTo(OutputStream out) throws IOException { if (jdom == null) { throw new IOException("JDOM document is null and cannot be written to OutputStream"); }//from w ww . j av a 2 s . co m new XMLOutputter(format).output(jdom, out); }
From source file:org.mycore.common.MCRMailer.java
License:Open Source License
/** Outputs xml to the LOGGER for debugging */ private static void debug(Element xml) { XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); LOGGER.debug(delimiter + xout.outputString(xml) + delimiter); }
From source file:org.mycore.common.MCRUtils.java
License:Open Source License
/** * This method convert a JDOM tree to a byte array. * /*from w w w . ja va2s.c o m*/ * @param jdom * the JDOM tree format the JDOM output format * @return a byte array of the JDOM tree * @deprecated use {@link MCRJDOMContent#asByteArray()} */ @Deprecated public static byte[] getByteArray(org.jdom2.Document jdom, Format format) throws MCRPersistenceException { MCRConfiguration conf = MCRConfiguration.instance(); String mcr_encoding = conf.getString("MCR.Metadata.DefaultEncoding", DEFAULT_ENCODING); ByteArrayOutputStream outb = new ByteArrayOutputStream(); try { XMLOutputter outp = new XMLOutputter(format.setEncoding(mcr_encoding)); outp.output(jdom, outb); } catch (Exception e) { throw new MCRPersistenceException("Can't produce byte array."); } return outb.toByteArray(); }
From source file:org.mycore.common.MCRUtils.java
License:Open Source License
/** * The method write a given JDOM Document to a file. * // ww w .ja v a 2 s . c o m * @param jdom * the JDOM Document * @param xml * the File instance * @deprecated use {@link MCRJDOMContent#sendTo(Path, java.nio.file.CopyOption...)} */ @Deprecated public static void writeJDOMToFile(Document jdom, File xml) { try { XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(xml)); xout.output(jdom, out); out.close(); } catch (IOException ioe) { if (LOGGER.isDebugEnabled()) { ioe.printStackTrace(); } else { LOGGER.error("Can't write org.jdom2.Document to file " + xml.getName() + "."); } } }
From source file:org.mycore.common.MCRUtils.java
License:Open Source License
/** * The method write a given JDOM Document to the system output. * //from w w w .java 2 s . com * @param jdom * the JDOM Document * @deprecated use {@link MCRJDOMContent#sendTo(java.io.OutputStream)} */ @Deprecated public static void writeJDOMToSysout(Document jdom) { try { XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); BufferedOutputStream out = new BufferedOutputStream(System.out); xout.output(jdom, out); out.flush(); } catch (IOException ioe) { if (LOGGER.isDebugEnabled()) { ioe.printStackTrace(); } else { LOGGER.error("Can't write org.jdom2.Document to Sysout."); } } }