public static void outputDocument( final Document document, final OutputStream outputStream ) throws IOException { final Format format = Format.getPrettyFormat(); format.setEncoding( STORAGE_CHARSET.toString() ); final XMLOutputter outputter = new XMLOutputter(); outputter.setFormat( format ); try ( Writer writer = new OutputStreamWriter( outputStream, STORAGE_CHARSET ) ) { outputter.output( document, writer ); } }
/** * Writes an NcML element to a Writer. * * @param elem an NcML element. * @param writer the Writer to write the NcML document to. Will be closed at end of the method. * @throws IOException if there's any problem writing. */ public void writeToWriter(Element elem, Writer writer) throws IOException { xmlOutputter.setFormat(xmlFormat); elem.detach(); // In case this element had previously been added to a Document. xmlOutputter.output(new Document(elem), writer); }
public static String xmlString(Document doc) { XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); return outputter.outputString(doc); }
/** * Writes the specified JDOM element to the XML file specified by filename. * The file will use UTF-8 encoding and has 4-space indentation. * * @param eRoot root element of the XML document * @param filename filename of the XML file to create * @throws IOException */ public static void writeXMLFile(Element eRoot, String filename) throws IOException { Document document = new Document(eRoot); XMLOutputter outputter = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setLineSeparator(System.getProperty("line.separator")); format.setIndent(" "); outputter.setFormat(format); // FileWriter can't be used here, because default encoding on Win32 isn't UTF-8 try (OutputStreamWriter osWriter = new OutputStreamWriter(new FileOutputStream(filename), "UTF-8")) { outputter.output(document, osWriter); osWriter.flush(); } } }
public void logDebug(String message, Element element) { if (logger.isDebugEnabled()) { XMLOutputter out = new XMLOutputter(); out.setFormat(Format.getPrettyFormat()); element = element.clone(); if (!Strings.isNullOrEmpty(element.getAttributeValue("outCookie"))) { element.setAttribute("outCookie", "**********"); } if (!Strings.isNullOrEmpty(element.getAttributeValue("cookie"))) { element.setAttribute("cookie", "**********"); } logger.debug(message + "\n{}", out.outputString(element)); } }
public void logInfo(String message, Element element) { XMLOutputter out = new XMLOutputter(); out.setFormat(Format.getPrettyFormat()); element = element.clone(); if (!Strings.isNullOrEmpty(element.getAttributeValue("outCookie"))) { element.setAttribute("outCookie", "**********"); } if (!Strings.isNullOrEmpty(element.getAttributeValue("cookie"))) { element.setAttribute("cookie", "**********"); } logger.info(message + "\n{}", out.outputString(element)); }
/** * Write to root Element to a writer. * * @param root Root Element to write. * @param writer Writer to write to. * @throws IOException if the writer fails to write. */ protected void write(Element root, Writer writer) throws IOException { XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); outputter.output(new Document(root), writer); }
/** * Write to root Element to a writer. * * @param root Root Element to write. * @param writer Writer to write to. * @throws IOException if the writer fails to write. */ protected void writeDocument(Element root, Writer writer) throws IOException { XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); Document document = new Document(root); outputter.output(document, writer); }
/** * Write to root Element to a writer. * * @param root Root Element to write. * @param writer Writer to write to. * @throws IOException if the writer fails to write. */ @SuppressWarnings("unchecked") protected void write(Element root, Writer writer) throws IOException { XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); Document document = new Document(root); outputter.output(document, writer); }
/** * Write to root Element to a writer. * * @param root Root Element to write. * @param writer Writer to write to. * @throws IOException if the writer fails to write. */ protected void writeDocument(Element root, Writer writer) throws IOException { XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); Document document = new Document(root); outputter.output(document, writer); }
public void writeParametersDoc(List<Parameter> params, Writer writer) throws IOException { Element root = getParametersRootElement(params); XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); Document document = new Document(root); outputter.output(document, writer); }
public void writeResultsDoc(List<Result> results, Writer writer) throws IOException { Element root = getResultsRootElement(results); XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); Document document = new Document(root); outputter.output(document, writer); }
/** * {@inheritDoc} */ public String getString() throws IOException { m_document.setContext( m_context ); CustomXMLOutputProcessor processor = new CustomXMLOutputProcessor(); XMLOutputter output = new XMLOutputter(processor); StringWriter out = new StringWriter(); Format fmt = Format.getRawFormat(); fmt.setExpandEmptyElements( false ); fmt.setLineSeparator( LINEBREAK ); output.setFormat( fmt ); output.outputElementContent( m_document.getRootElement(), out ); String result = out.toString(); return result; } }
/** * Write the job list to our streaming xml writer. * * @param jobs * @param writer Writer to write to. * @throws IOException if the writer fails to write. */ public void write(Iterator<JobRef> jobs, Writer writer) throws IOException { Element root = getRootElement(jobs); XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); Document document = new Document(root); outputter.output(document, writer); }
/** * Method write * * @param project * @param jdomFormat * @param writer * @param document */ public void write( Model project, Document document, Writer writer, Format jdomFormat ) throws java.io.IOException { updateModel( project, "project", new Counter( 0 ), document.getRootElement() ); XMLOutputter outputter = new XMLOutputter(); outputter.setFormat( jdomFormat ); outputter.output( document, writer ); } // -- void write(Model, Document, Writer, Format)
/** * Write the job to a writer. * * @param job * @param writer Writer to write to. * @throws IOException if the writer fails to write. */ public void write(Job job, Writer writer) throws IOException { Element root = getRootElement(job); XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); Document document = new Document(root); outputter.output(document, writer); }
/** * {@inheritDoc} */ public String getString() throws IOException { Element rootElement = m_document.getRootElement(); processChildren( rootElement ); m_document.setContext( m_context ); XMLOutputter output = new XMLOutputter(); StringWriter out = new StringWriter(); Format fmt = Format.getRawFormat(); fmt.setExpandEmptyElements( false ); fmt.setLineSeparator( LINEBREAK ); output.setFormat( fmt ); output.outputElementContent( m_document.getRootElement(), out ); return out.toString(); } }
/** * Method write * * @param project * @param stream * @param document * @deprecated */ public void write( Model project, Document document, OutputStream stream ) throws java.io.IOException { updateModel( project, "project", new Counter( 0 ), document.getRootElement() ); XMLOutputter outputter = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setIndent( " " ).setLineSeparator( System.getProperty( "line.separator" ) ); outputter.setFormat( format ); outputter.output( document, stream ); } // -- void write(Model, Document, OutputStream)
/** * Generate a default LoLStatus that can later be modified and be used to * change the current LolStatus ({@link LolChat#setStatus(LolStatus)}). * */ public LolStatus() { outputter .setFormat(outputter.getFormat().setExpandEmptyElements(false)); doc = new Document(new Element("body")); for (final XMLProperty p : XMLProperty.values()) { doc.getRootElement().addContent(new Element(p.toString())); } }
public static ContentPayload getMetadataPayload(TransferredResource transferredResource) { try { 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(""); } }