List of usage examples for org.dom4j.io OutputFormat OutputFormat
public OutputFormat(String indent, boolean newlines, String encoding)
OutputFormat
with the given indent added with optional newlines between the Elements and the given encoding format. From source file:com.xpn.xwiki.plugin.packaging.Package.java
License:Open Source License
/** * Write the package.xml file to an OutputStream * /* w w w .j av a2s . com*/ * @param out the OutputStream to write to * @param context curent XWikiContext * @throws IOException when an error occurs during streaming operation * @since 2.3M2 */ public void toXML(OutputStream out, XWikiContext context) throws IOException { XMLWriter wr = new XMLWriter(out, new OutputFormat("", true, context.getWiki().getEncoding())); Document doc = new DOMDocument(); wr.writeDocumentStart(doc); toXML(wr); wr.writeDocumentEnd(doc); }
From source file:mesquite.lib.XMLUtil.java
License:Open Source License
public static String getDocumentAsXMLString(Document doc, boolean escapeText) { try {/*from w ww .j a va 2 s . c o m*/ String encoding = doc.getXMLEncoding(); if (encoding == null) encoding = "UTF-8"; Writer osw = new StringWriter(); OutputFormat opf = new OutputFormat(" ", true, encoding); XMLWriter writer = new XMLWriter(osw, opf); writer.setEscapeText(escapeText); writer.write(doc); writer.close(); return osw.toString(); } catch (IOException e) { MesquiteMessage.warnProgrammer("XML Document could not be returned as string."); } return null; }
From source file:mesquite.lib.XMLUtil.java
License:Open Source License
public static String getElementAsXMLString(Element doc, String encoding, boolean escapeText) { try {//from w ww. j a va 2s . c om Writer osw = new StringWriter(); OutputFormat opf = new OutputFormat(" ", true, encoding); XMLWriter writer = new XMLWriter(osw, opf); writer.setEscapeText(escapeText); writer.write(doc); writer.close(); return osw.toString(); } catch (IOException e) { MesquiteMessage.warnProgrammer("XML Document could not be returned as string."); } return null; }
From source file:net.unicon.toro.installer.tools.MergeConfiguration.java
License:Open Source License
private void saveXml(Document doc, File saveTo) throws IOException { String xmlEncoding = doc.getXMLEncoding(); OutputFormat format = new OutputFormat(" ", true, xmlEncoding); format.setTrimText(true);/*from ww w. j a v a2 s. c o m*/ XMLWriter writer = new XMLWriter(new FileWriter(saveTo), format); writer.write(doc); writer.close(); }
From source file:nl.knaw.dans.common.fedora.fox.DatastreamVersion.java
License:Apache License
public String getXmlContentString() { Element xmlEl = xmlContent.getElement(); Document doc = xmlEl.getDocument(); String encoding = "UTF-8"; if (doc != null) doc.getXMLEncoding();/*from w w w . ja va 2 s .co m*/ Writer osw = new StringWriter(); OutputFormat opf = new OutputFormat(" ", true, encoding); XMLWriter writer = new XMLWriter(osw, opf); try { writer.write(xmlEl); writer.close(); } catch (IOException e) { return ""; } return osw.toString(); }
From source file:org.modelibra.persistency.xml.XmlEntities.java
License:Apache License
/** * Saves a document to the XML data file using the given encoding. * /*from w w w . j a v a2s. co m*/ * @param document * XML document * @param dataFilePath * XML data file path * @param encoding * text encoding */ private void save(Document document, String dataFilePath, String encoding) { XMLWriter writer; try { writer = new XMLWriter(new FileOutputStream(dataFilePath), new OutputFormat(" ", true, encoding)); } catch (FileNotFoundException e) { String message = "=== Problem with XmlEntities.save(Document, String, String) === " + e.getMessage(); throw new PersistencyRuntimeException(message, e); } catch (UnsupportedEncodingException e) { String message = "=== Problem with XmlEntities.save(Document, String, String) === " + e.getMessage(); throw new PersistencyRuntimeException(message, e); } try { writer.write(document); writer.close(); } catch (IOException e) { String message = "=== Problem with XmlEntities.save(Document, String, String) === " + e.getMessage(); throw new PersistencyRuntimeException(message, e); } }
From source file:org.xwiki.store.serialization.xml.internal.AbstractXMLSerializer.java
License:Open Source License
/** * {@inheritDoc}/*from w w w. java2s . c om*/ * * @see org.xwiki.store.filesystem.internal.XMLSerializer#serialize(T) */ public InputStream serialize(final R object) throws IOException { // This puts everything on the heap for now. // if size becomes a major problem, the alternitive is to fork over another thread // and use a PipedInputStream. final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final XMLWriter writer; try { // This should always be UTF-8 because it is a property of the serializer. final OutputFormat of = new OutputFormat(" ", true, "UTF-8"); writer = new XMLWriter(baos, of); writer.startDocument(); } catch (SAXException e) { throw new IOException("Could not open the XML writer."); } this.serialize(object, writer); try { writer.endDocument(); } catch (SAXException e) { throw new IOException("Could not close the XML writer."); } return new ByteArrayInputStream(baos.toByteArray()); }
From source file:org.xwiki.tool.xar.FormatMojo.java
License:Open Source License
private void format(File file, String defaultLanguage) throws Exception { SAXReader reader = new SAXReader(); Document domdoc = reader.read(file); format(file.getName(), domdoc, defaultLanguage); XMLWriter writer;/* w w w. j a v a2 s .co m*/ if (this.pretty) { OutputFormat format = new OutputFormat(" ", true, "UTF-8"); format.setExpandEmptyElements(false); writer = new XWikiXMLWriter(new FileOutputStream(file), format); } else { writer = new XWikiXMLWriter(new FileOutputStream(file)); } writer.write(domdoc); writer.close(); String parentName = file.getParentFile().getName(); getLog().info(String.format(" Formatting [%s/%s]... ok", parentName, file.getName())); }