List of usage examples for org.dom4j.io OutputFormat setOmitEncoding
public void setOmitEncoding(boolean omitEncoding)
This will set whether the XML declaration (<?xml version="1.0" encoding="UTF-8"?>
) includes the encoding of the document.
From source file:au.com.acegi.xmlformat.XmlFormatPlugin.java
License:Apache License
private OutputFormat buildFormatter() { final OutputFormat fmt = createPrettyPrint(); fmt.setAttributeQuoteCharacter(attributeQuoteChar); fmt.setEncoding(encoding);/*from ww w.j av a 2s. c o m*/ fmt.setExpandEmptyElements(expandEmptyElements); fmt.setIndentSize(indentSize); fmt.setLineSeparator(determineLineSeparator()); fmt.setNewLineAfterDeclaration(newLineAfterDeclaration); fmt.setNewLineAfterNTags(newLineAfterNTags); fmt.setNewlines(newlines); fmt.setOmitEncoding(omitEncoding); fmt.setPadText(padText); fmt.setSuppressDeclaration(suppressDeclaration); fmt.setTrimText(trimText); fmt.setXHTML(xhtml); return fmt; }
From source file:com.zimbra.cs.dav.client.DavRequest.java
License:Open Source License
public String getRequestMessageString() throws IOException { if (mDoc != null) { OutputFormat format = OutputFormat.createPrettyPrint(); format.setTrimText(false);/* w ww.j ava 2s . c o m*/ format.setOmitEncoding(false); ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(out, format); writer.write(mDoc); return new String(out.toByteArray(), "UTF-8"); } return ""; }
From source file:com.zimbra.cs.dav.DomUtil.java
License:Open Source License
public static void writeDocumentToStream(Document doc, OutputStream out) throws IOException { OutputFormat format = OutputFormat.createPrettyPrint(); format.setTrimText(false);//from w w w. j a v a 2 s . co m format.setOmitEncoding(false); XMLWriter writer = new XMLWriter(out, format); writer.write(doc); }
From source file:com.zimbra.cs.dav.resource.DavResource.java
License:Open Source License
protected String getPropertiesAsText(DavContext ctxt) throws IOException { Element e = org.dom4j.DocumentHelper.createElement(DavElements.E_PROP); for (ResourceProperty rp : mProps.values()) rp.toElement(ctxt, e, false);// ww w .j a v a 2 s . c o m OutputFormat format = OutputFormat.createPrettyPrint(); format.setTrimText(false); format.setOmitEncoding(false); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(baos, format); writer.write(e); return new String(baos.toByteArray()); }
From source file:org.apache.taglibs.xtags.xpath.OutputTag.java
License:Apache License
public int doStartTag() throws JspException { OutputFormat format = null; if (indent != null) { format = OutputFormat.createPrettyPrint(); format.setIndent(indent);//from w w w . jav a 2s .co m } else { format = new OutputFormat(); } format.setOmitEncoding(asBoolean(omitXmlDeclaration)); Writer out = pageContext.getOut(); if (method != null && method.equalsIgnoreCase("html")) { xmlWriter = new HTMLWriter(out, format); } else { xmlWriter = new XMLWriter(out, format); } return EVAL_BODY_INCLUDE; }
From source file:org.orbeon.oxf.processor.tamino.dom4j.TDOM4JAdapter.java
License:Open Source License
/** * Initializes the io output helpers. Here only output helpers are needed. * ATTENTION: org.dom4j.XMLWriter is used, if you have no IOHelper in your * specific object model, you have to create a *//*w w w . j av a 2 s. c o m*/ private void initializeIOHelpers() { try { OutputFormat outformat = new OutputFormat(); // Obtain the active encoding from the central preference instance. this.encoding = TPreference.getInstance().getEncoding(); // Set the encoding on the outputter. outformat.setEncoding(this.encoding); // For serialization encoding attribute shall be included. outformat.setOmitEncoding(false); this.outputter = new XMLWriter(outformat); } catch (UnsupportedEncodingException uee) { System.err.println("WARNING: " + uee.getMessage()); } }
From source file:org.sipfoundry.sipxconfig.conference.ConferenceConfiguration.java
License:Contributor Agreement License
@Override public OutputFormat createFormat() { OutputFormat format = OutputFormat.createPrettyPrint(); format.setOmitEncoding(true); format.setSuppressDeclaration(true); return format; }
From source file:org.youi.framework.util.Dom4jUtils.java
License:Apache License
/** * ?xml?//from w w w .j a v a2 s. c o m * @param doc * @param os * @param encoding */ public static void formatXml(Document doc, OutputStream os, String encoding) { if (os == null) return; OutputFormat format = null; XMLWriter output = null; try { format = OutputFormat.createPrettyPrint(); format.setEncoding(encoding); format.setOmitEncoding(false); output = new XMLWriter(new BufferedWriter(new OutputStreamWriter(os, "UTF-8")), format); output.write(doc); } catch (IOException e) { log.error("xmlIO:" + e.getMessage()); } finally { try { output.close(); } catch (IOException e) { log.info("" + e.getMessage()); } } }
From source file:pt.webdetails.cda.exporter.HtmlExporter.java
License:Open Source License
@Override public void export(OutputStream out, TableModel tableModel) throws ExporterException { final Document document = DocumentHelper.createDocument(); Element table = null;/*ww w . j a v a 2s . c o m*/ if (fullHtml) { final Element html = document.addElement("html"); final Element head = html.addElement("head"); head.addElement("title").addText(title); table = html.addElement("body").addElement("table"); } else { table = document.addElement("table"); } final int columnCount = tableModel.getColumnCount(); //table headers final Element headerRow = table.addElement("tr"); for (int i = 0; i < columnCount; i++) { String colName = tableModel.getColumnName(i); headerRow.addElement("th").addText(colName); } //table body for (int i = 0; i < tableModel.getRowCount(); i++) { Element row = table.addElement("tr"); for (int j = 0; j < columnCount; j++) { Element tableCell = row.addElement("td"); Object value = tableModel.getValueAt(i, j); tableCell.setText(valueToText(value)); if (value instanceof Date) { tableCell.setText(format.format(value)); } else if (value != null) { // numbers can be safely converted via toString, as they use a well-defined format there tableCell.setText(value.toString()); } } } try { document.setXMLEncoding("UTF-8"); OutputFormat outFormat = new OutputFormat(); outFormat.setOmitEncoding(true); outFormat.setSuppressDeclaration(true);//otherwise msexcel/oocalc may not recognize content outFormat.setNewlines(true); outFormat.setIndentSize(columnCount); final Writer writer = new BufferedWriter(new OutputStreamWriter(out)); XMLWriter xmlWriter = new XMLWriter(writer, outFormat); xmlWriter.write(document); xmlWriter.flush(); } catch (IOException e) { throw new ExporterException("IO Exception converting to utf-8", e); } }