List of usage examples for org.dom4j.io OutputFormat OutputFormat
public OutputFormat(String indent, boolean newlines)
OutputFormat
with the given indent added with optional newlines between the Elements. From source file:com.dockingsoftware.dockingpreference.PreferenceProcessor.java
License:Apache License
/** * Store user preference information to a specified file. * // ww w . j a v a 2 s.c om * @param obj * @param fullPath Specified the full path of the configuration file. */ public void store(Object obj, String fullPath) { try { FileWriter out; Document document = DocumentHelper.createDocument(); Element root = document.addElement(getName(obj.getClass())); root.addAttribute(GlobalConstant.CLASS, obj.getClass().getName()); List<Field> pFields = getPreferenceFieldList(obj.getClass()); for (int i = 0; i < pFields.size(); i++) { store(obj, pFields.get(i), root); } OutputFormat format = new OutputFormat(" ", true); out = new FileWriter(new File(fullPath)); XMLWriter w = new XMLWriter(out, format); w.write(document); w.close(); out.close(); } catch (IOException ex) { Logger.getLogger(PreferenceProcessor.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalArgumentException ex) { Logger.getLogger(PreferenceProcessor.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(PreferenceProcessor.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.itextpdf.rups.model.XfaFile.java
License:Open Source License
/** * Writes a formatted XML file to the OutputStream. * @see com.itextpdf.rups.io.OutputStreamResource#writeTo(java.io.OutputStream) *//*from w w w. j av a2s . co m*/ public void writeTo(OutputStream os) throws IOException { if (xfaDocument == null) return; OutputFormat format = new OutputFormat(" ", true); XMLWriter writer = new XMLWriter(os, format); writer.write(xfaDocument); }
From source file:com.xpn.xwiki.objects.BaseCollection.java
License:Open Source License
public String toXMLString() { Document doc = new DOMDocument(); doc.setRootElement(toXML(null));/*from w w w .jav a2s . co m*/ OutputFormat outputFormat = new OutputFormat("", true); StringWriter out = new StringWriter(); XMLWriter writer = new XMLWriter(out, outputFormat); try { writer.write(doc); return out.toString(); } catch (IOException e) { e.printStackTrace(); return ""; } }
From source file:com.xpn.xwiki.objects.BaseProperty.java
License:Open Source License
public String toXMLString() { Document doc = new DOMDocument(); doc.setRootElement(toXML());/* www . jav a2 s. c o m*/ OutputFormat outputFormat = new OutputFormat("", true); StringWriter out = new StringWriter(); XMLWriter writer = new XMLWriter(out, outputFormat); try { writer.write(doc); return out.toString(); } catch (IOException e) { e.printStackTrace(); return ""; } }
From source file:com.xpn.xwiki.pdf.impl.PdfExportImpl.java
License:Open Source License
/** * Apply a CSS style sheet to an XHTML document and return the document with the resulting style properties inlined * in <tt>style</tt> attributes. * //from w ww . jav a2 s .co m * @param html the valid XHTML document to style * @param css the style sheet to apply * @param context the current request context * @return the document with inlined style */ private String applyCSS(String html, String css, XWikiContext context) { try { // Prepare the input Reader re = new StringReader(html); InputSource source = new InputSource(re); SAXReader reader = new SAXReader(XHTMLDocumentFactory.getInstance()); reader.setEntityResolver(new DefaultEntityResolver()); XHTMLDocument document = (XHTMLDocument) reader.read(source); // Apply the style sheet document.setDefaultStyleSheet(new DOM4JCSSStyleSheet(null, null, null)); document.addStyleSheet(new org.w3c.css.sac.InputSource(new StringReader(css))); applyInlineStyle(document.getRootElement()); OutputFormat outputFormat = new OutputFormat("", false); if ((context == null) || (context.getWiki() == null)) { outputFormat.setEncoding("UTF-8"); } else { outputFormat.setEncoding(context.getWiki().getEncoding()); } StringWriter out = new StringWriter(); XMLWriter writer = new XMLWriter(out, outputFormat); writer.write(document); String result = out.toString(); // Debug output if (LOG.isDebugEnabled()) { LOG.debug("HTML with CSS applied: " + result); } return result; } catch (Exception ex) { LOG.warn("Failed to apply CSS: " + ex.getMessage(), ex); return html; } }
From source file:com.xpn.xwiki.tool.xar.XarMojo.java
License:Open Source License
/** * Create and add package configuration file to the package. * //from w w w . j ava 2 s .c o m * @param packageFile the package when to add configuration file. * @param files the files in the package. * @throws Exception error when writing the configuration file. */ private void generatePackageXml(File packageFile, Collection<ArchiveEntry> files) throws Exception { getLog().info("Generating package.xml descriptor at [" + packageFile.getPath() + "]"); OutputFormat outputFormat = new OutputFormat("", true); outputFormat.setEncoding(this.encoding); OutputStream out = new FileOutputStream(packageFile); XMLWriter writer = new XMLWriter(out, outputFormat); writer.write(toXML(files)); writer.close(); out.close(); }
From source file:controllers.ServiceController.java
License:Apache License
private boolean writeBodyToFile(String filename) { String xmlFile = filename + ".xml"; String jsonFile = filename + ".shape.json"; try {/*from w w w . j a va 2 s. co m*/ BufferedReader br = request.getReader(); boolean hasJson = false; StringBuffer buf = new StringBuffer(); //Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(xmlFile),"utf-8")); String inputLine; while ((inputLine = br.readLine()) != null) { if (inputLine.equals("===boundary===")) { /*?shapes*/ //writer.close(); //writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(jsonFile),"utf-8")); SAXReader reader = new SAXReader(); reader.setEntityResolver(new DTDEntityResolver()); Document document = reader.read(new StringReader(buf.toString())); OutputFormat format = new OutputFormat(" ", true); XMLWriter writer = new XMLWriter( new BufferedWriter(new OutputStreamWriter(new FileOutputStream(xmlFile), "utf-8")), format); writer.write(document); writer.flush(); writer.close(); hasJson = true; buf = new StringBuffer(); continue; } buf.append(inputLine).append("\n"); //writer.write(inputLine); //writer.write("\n"); } //writer.close(); br.close(); if (!hasJson) { Trace.write(Trace.Error, "write osworkflow: no json-shape define!"); return false; } String jsonString = buf.toString(); jsonString = formatJsonStrings(jsonString); if (jsonString == null) { Trace.write(Trace.Error, "write osworkflow[json]: " + buf.toString()); return false; } Writer jsonWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(jsonFile), "utf-8")); jsonWriter.write(jsonString); jsonWriter.close(); return true; } catch (DocumentException de) { Trace.write(Trace.Error, de, "write osworkflow[xml]."); } catch (IOException e) { Trace.write(Trace.Error, e, "write osworkflow."); } return false; }
From source file:de.hasait.eclipse.common.xml.XDocument.java
License:Apache License
public String asFormattedXml(final String lineSeparator, final String indent, final boolean newlines, final boolean trimText) { StringWriter sw = new StringWriter(); try {//from www. j a v a 2 s . c o m OutputFormat outputFormat = new OutputFormat(indent, newlines); outputFormat.setTrimText(trimText); outputFormat.setLineSeparator(lineSeparator); new XMLWriter(sw, outputFormat).write(_document); } catch (IOException e) { // Should not happen for StringWriter throw new RuntimeException(e); } return sw.getBuffer().toString(); }
From source file:de.hasait.eclipse.common.xml.XElement.java
License:Apache License
public String asFormattedXml(final String lineSeparator, final String indent, final boolean newlines, final boolean trimText) { StringWriter sw = new StringWriter(); try {// w ww . ja v a 2 s. c om OutputFormat outputFormat = new OutputFormat(indent, newlines); outputFormat.setTrimText(trimText); outputFormat.setLineSeparator(lineSeparator); new XMLWriter(sw, outputFormat).write(_element); } catch (IOException e) { // Should not happen for StringWriter throw new RuntimeException(e); } return sw.getBuffer().toString(); }
From source file:gr.abiss.calipso.util.XmlUtils.java
License:Open Source License
/** * Override that accepts an XML DOM Document * @param document XML as DOM Document/* ww w . j ava 2 s .c o m*/ */ public static String getAsPrettyXml(Document document) { OutputFormat format = new OutputFormat(" ", true); format.setSuppressDeclaration(true); StringWriter out = new StringWriter(); XMLWriter writer = new XMLWriter(out, format); try { try { writer.write(document); } finally { writer.close(); } } catch (IOException ioe) { throw new RuntimeException(ioe); } return out.toString().trim(); }