List of usage examples for org.jdom2.output Format setOmitDeclaration
public Format setOmitDeclaration(boolean omitDeclaration)
<?xml version="1.0"?>
) will be omitted or not. From source file:com.facebook.buck.ide.intellij.projectview.ProjectView.java
License:Apache License
private void saveDocument(String path, String filename, XML mode, Document document) { if (path != null) { filename = fileJoin(path, filename); }//from w w w. j a v a 2s. c om if (dryRun) { stderr("Writing %s\n", filename); return; } Format prettyFormat = Format.getPrettyFormat(); prettyFormat.setOmitDeclaration(mode == XML.NO_DECLARATION); XMLOutputter outputter = new XMLOutputter(prettyFormat); try (Writer writer = new FileWriter(filename)) { outputter.output(document, writer); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.googlecode.mipnp.mediaserver.cds.DidlLiteDocument.java
License:Open Source License
@Override public String toString() { Format format = Format.getRawFormat(); format.setOmitDeclaration(true); XMLOutputter outputter = new XMLOutputter(format); return outputter.outputString(document); }
From source file:devicemodel.conversions.XmlConversions.java
public static String document2XmlStringNoHeader(final Document doc) throws IOException { final StringWriter stringWriter = new StringWriter(); final XMLOutputter xmlOutput = new XMLOutputter(); final Format plainFormat = Format.getPrettyFormat(); plainFormat.setOmitDeclaration(true); xmlOutput.setFormat(plainFormat);/*ww w . ja va 2s. c om*/ xmlOutput.output(doc, stringWriter); return stringWriter.toString(); }
From source file:nl.colorize.util.xml.XMLHelper.java
License:Apache License
private static XMLOutputter getOutputter() { Format formatter = Format.getPrettyFormat(); formatter.setEncoding(Charsets.UTF_8.displayName()); formatter.setIndent(" "); formatter.setLineSeparator(Platform.getLineSeparator()); formatter.setExpandEmptyElements(false); formatter.setOmitDeclaration(false); formatter.setOmitEncoding(false);/* w ww . j a va2 s . c o m*/ XMLOutputter outputter = new XMLOutputter(formatter); outputter.setFormat(formatter); return outputter; }
From source file:org.jumpmind.metl.core.runtime.component.XsltProcessor.java
License:Open Source License
public static String getTransformedXml(String inputXml, String stylesheetXml, String xmlFormat, boolean omitXmlDeclaration) { StringWriter writer = new StringWriter(); SAXBuilder builder = new SAXBuilder(); builder.setXMLReaderFactory(XMLReaders.NONVALIDATING); builder.setFeature("http://xml.org/sax/features/validation", false); try {/*from w ww .j a va2 s .c o m*/ Document inputDoc = builder.build(new StringReader(inputXml)); StringReader reader = new StringReader(stylesheetXml); XSLTransformer transformer = new XSLTransformer(reader); Document outputDoc = transformer.transform(inputDoc); XMLOutputter xmlOutput = new XMLOutputter(); Format format = null; if (xmlFormat.equals(COMPACT_FORMAT)) { format = Format.getCompactFormat(); } else if (xmlFormat.equals(RAW_FORMAT)) { format = Format.getRawFormat(); } else { format = Format.getPrettyFormat(); } format.setOmitDeclaration(omitXmlDeclaration); xmlOutput.setFormat(format); xmlOutput.output(outputDoc, writer); writer.close(); } catch (Exception e) { throw new RuntimeException(e); } return writer.toString(); }
From source file:org.kdp.word.transformer.OPFTransformer.java
License:Apache License
private void writeOPFDocument(Context context, Document doc) { Options options = context.getOptions(); Path basedir = context.getBasedir(); Path filePath = options.getOpfTarget(); if (filePath == null) { String filename = context.getSource().getFileName().toString(); filename = filename.substring(0, filename.lastIndexOf('.')) + ".opf"; filePath = options.getBookDir().resolve(filename); }/*from w w w. ja v a 2s . co m*/ try { log.info("Writing OPF: {}", filePath); File outfile = basedir.resolve(filePath).toFile(); outfile.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(outfile); XMLOutputter xo = new XMLOutputter(); Format format = Format.getPrettyFormat(); xo.setFormat(format.setOmitDeclaration(false)); format.setEncoding("UTF-8"); xo.output(doc, fos); fos.close(); } catch (IOException ex) { throw new IllegalStateException("Cannot write OPF file: " + filePath, ex); } }
From source file:org.kdp.word.utils.IOUtils.java
License:Apache License
public static void writeDocument(Context context, Document doc, OutputStream out) throws IOException { Parser parser = context.getParser(); String outputEncoding = parser.getProperty(Parser.PROPERTY_OUTPUT_ENCODING); outputEncoding = outputEncoding != null ? outputEncoding : "UTF-8"; String outputFormat = parser.getProperty(Parser.PROPERTY_OUTPUT_FORMAT); boolean pretty = Parser.OUTPUT_FORMAT_PRETTY.equals(outputFormat); XMLOutputter xo = new XMLOutputter(); Format format = pretty ? Format.getPrettyFormat() : Format.getCompactFormat(); format.setEncoding(outputEncoding);// w ww . j a v a 2 s .co m EscapeStrategy strategy = new OutputEscapeStrategy(context, format.getEscapeStrategy()); format.setEscapeStrategy(strategy); xo.setFormat(format.setOmitDeclaration(true)); xo.output(doc, out); }
From source file:org.mycore.frontend.editor.MCREditorServlet.java
License:Open Source License
private void sendToDebug(HttpServletResponse res, Document unprocessed, MCREditorSubmission sub) throws IOException, UnsupportedEncodingException { res.setContentType("text/html; charset=UTF-8"); PrintWriter pw = res.getWriter(); pw.println("<html><body><p><pre>"); for (int i = 0; i < sub.getVariables().size(); i++) { MCREditorVariable var = (MCREditorVariable) sub.getVariables().get(i); pw.println(var.getPath() + " = " + var.getValue()); FileItem file = var.getFile(); if (file != null) { pw.println(" is uploaded file " + file.getContentType() + ", " + file.getSize() + " bytes"); }/*from w ww .j av a 2 s . c o m*/ } pw.println("</pre></p><p>"); XMLOutputter outputter = new XMLOutputter(); Format fmt = Format.getPrettyFormat(); fmt.setLineSeparator("\n"); fmt.setOmitDeclaration(true); outputter.setFormat(fmt); Element pre = new Element("pre"); pre.addContent(outputter.outputString(unprocessed)); outputter.output(pre, pw); pre = new Element("pre"); pre.addContent(outputter.outputString(sub.getXML())); outputter.output(pre, pw); pw.println("</p></body></html>"); pw.close(); }