List of usage examples for org.dom4j.io OutputFormat setNewlines
public void setNewlines(boolean newlines)
From source file:org.sipfoundry.sipxivr.MailboxPreferencesWriter.java
License:Contributor Agreement License
@Override public void writeObject(MailboxPreferences prefs, Writer output) { m_prefs = prefs;/*from w ww.j a va 2s .c o m*/ OutputFormat format = new OutputFormat(); format.setNewlines(true); format.setIndent(true); XMLWriter xmlWriter = new XMLWriter(output, format); try { xmlWriter.write(getDocument()); } catch (IOException e) { LOG.error("Error writing mailboxprefs.xml", e); throw new RuntimeException(e); } }
From source file:org.sipfoundry.voicemail.mailbox.MessageDescriptorWriter.java
License:Contributor Agreement License
@Override public void writeObject(MessageDescriptor messageDescriptor, Writer output) { m_messageDescriptor = messageDescriptor; OutputFormat format = new OutputFormat(); format.setNewlines(true); format.setIndent(true);/*from w ww . j a v a2 s. c o m*/ XMLWriter xmlWriter = new XMLWriter(output, format); try { xmlWriter.write(getDocument()); } catch (IOException e) { LOG.error("Error writing MessageDescriptor to " + output.toString(), e); throw new RuntimeException(e); } }
From source file:org.snipsnap.jsp.ContentTag.java
License:Open Source License
public int doStartTag() throws JspException { if (null != snip) { String content = snip.getXMLContent(); if (removeHtml) { Filter filter = new HtmlRemoveFilter(); content = filter.filter(content, null); if (extract) { if (content.length() > 40) { content = content.substring(0, 40); int ampIndex = content.lastIndexOf("&"); int colonIndex = content.lastIndexOf(";"); // did we cut a entity like &x1212; ? if (ampIndex > colonIndex) { content = content.substring(0, ampIndex - 1); }/*from ww w . j a va 2 s. co m*/ content = content + " ..."; } } } if (encodeHtml) { StringWriter stringWriter = new StringWriter(); try { OutputFormat outputFormat = new OutputFormat(); outputFormat.setNewlines(true); XMLWriter xmlWriter = new XMLWriter(stringWriter, outputFormat); xmlWriter.write(content); xmlWriter.flush(); } catch (IOException e) { Logger.warn("ContentTag: unable to write encoded content: " + e); } content = stringWriter.toString(); } try { JspWriter out = pageContext.getOut(); out.print(content); } catch (IOException e) { Logger.warn("doStartTag in ContentTag", e); } } return super.doStartTag(); }
From source file:org.snipsnap.snip.XMLSnipExport.java
License:Open Source License
public static void store(OutputStream out, List snips, List users, String filter, List ignoreElements, File fileStore) {/*from w w w . java2s . c om*/ try { OutputFormat outputFormat = new OutputFormat(); outputFormat.setEncoding("UTF-8"); outputFormat.setNewlines(true); XMLWriter xmlWriter = new XMLWriter(out, outputFormat); Element root = DocumentHelper.createElement("snipspace"); xmlWriter.writeOpen(root); storeUsers(xmlWriter, users); storeSnips(xmlWriter, snips, filter, ignoreElements, fileStore); xmlWriter.writeClose(root); xmlWriter.flush(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.snipsnap.util.JDBCDatabaseExport.java
License:Open Source License
/** * Store snips and users from the SnipSpace to an xml document into a stream. * @param out outputstream to write to//from www.j a va 2 s .co m */ public static void store(OutputStream out, String appOid, Connection connection) { try { OutputFormat outputFormat = new OutputFormat(); outputFormat.setEncoding("UTF-8"); outputFormat.setNewlines(true); XMLWriter xmlWriter = new XMLWriter(out, outputFormat); xmlWriter.startDocument(); Element root = DocumentHelper.createElement("snipspace"); xmlWriter.writeOpen(root); // storeUsers(xmlWriter, connection); storeSnips(xmlWriter, appOid, connection); xmlWriter.writeClose(root); xmlWriter.endDocument(); xmlWriter.flush(); xmlWriter.close(); } catch (Exception e) { System.err.println("JDBCDatabaseExport: error while writing document: " + e.getMessage()); } }
From source file:org.snipsnap.util.XMLSnipRepair.java
License:Open Source License
public static void repair(File input, File output, File webAppDir) { System.err.println("STEP 1: parsing input file ..."); Document document = null;/*from w ww.j av a 2 s . com*/ try { document = load(input); } catch (Exception e) { System.err.println("Unable to read input document: " + e); System.err.println( "This is usually the case for illegal XML characters, please manually edit the file and remove them."); System.exit(0); } System.err.println("STEP 2: checking SnipSpace consistency ..."); Document repaired = repair(document, webAppDir); System.err.println("STEP 3: writing output file ..."); OutputFormat outputFormat = new OutputFormat(); outputFormat.setEncoding("UTF-8"); outputFormat.setNewlines(true); try { XMLWriter xmlWriter = new XMLWriter( null == output ? System.out : (OutputStream) new FileOutputStream(output)); xmlWriter.write(repaired); xmlWriter.flush(); xmlWriter.close(); } catch (Exception e) { System.err.println("Error: unable to write data: " + e); } System.err.println("Finished."); }
From source file:org.talend.updates.runtime.nexus.component.ComponentIndexManager.java
License:Open Source License
public boolean createIndexFile(File indexFile, List<ComponentIndexBean> newIndexList) throws IOException { if (newIndexList == null || newIndexList.isEmpty() || indexFile == null) { return false; }//from ww w.j a va 2 s . c om XMLWriter xmlWriter = null; boolean created = false; try { // write to index final DocumentFactory docFactory = DocumentFactory.getInstance(); final Element components = docFactory.createElement(ELEM_COMPONENTS); Document newDoc = docFactory.createDocument(components); for (ComponentIndexBean b : newIndexList) { final Element elem = createXmlElement(b); if (elem != null) { components.add(elem); } } // 4 spaces OutputFormat format = new OutputFormat(); format.setEncoding("UTF-8"); //$NON-NLS-1$ format.setIndentSize(4); format.setNewlines(true); xmlWriter = new XMLWriter(new FileOutputStream(indexFile), format); xmlWriter.write(newDoc); created = true; return true; } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { // } } if (!created && indexFile.exists()) { indexFile.delete(); // remove the wrong file. } } }
From source file:org.withinsea.izayoi.cortile.template.html.parser.HTMLWriter.java
License:Mozilla Public License
@Override protected void writeElement(Element element) throws IOException { if (!HTMLConstants.ANONYMOUS_TAG_NAME.equals(element.getName())) { super.writeElement(element); return;/*from w ww .ja v a2 s . co m*/ } OutputFormat currentFormat = getOutputFormat(); boolean saveTrimText = currentFormat.isTrimText(); String currentIndent = currentFormat.getIndent(); currentFormat.setNewlines(false); currentFormat.setTrimText(false); currentFormat.setIndent(""); writePrintln(); indent(); writeElementContent(element); writePrintln(); indent(); currentFormat.setTrimText(saveTrimText); currentFormat.setIndent(currentIndent); }
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;//from ww w. ja va 2 s . 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); } }