List of usage examples for org.dom4j.io OutputFormat setIndentSize
public void setIndentSize(int indentSize)
String
's size; an indentSize of 4 would result in the indention being equivalent to the String
" " (four space characters). 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 www . ja v a 2 s . c om*/ 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.alibaba.citrus.springext.support.SchemaUtil.java
License:Open Source License
/** DOM */ public static void writeDocument(Document doc, Writer writer, String charset) throws IOException { charset = defaultIfEmpty(trimToNull(charset), "UTF-8"); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(charset);//from www. ja va2 s . c o m format.setIndent(true); format.setIndentSize(4); XMLWriter xmlWriter = new XMLWriter(writer, format); xmlWriter.write(doc); xmlWriter.flush(); }
From source file:com.amalto.workbench.utils.XmlUtil.java
License:Open Source License
public static String formatXmlSource(String xmlSource) { SAXReader reader = new SAXReader(); StringReader stringReader = new StringReader(xmlSource); StringWriter writer = null;/*from ww w .j a va2 s .c om*/ XMLWriter xmlwriter = null; String result = xmlSource; try { Document document = reader.read(stringReader); writer = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8");//$NON-NLS-1$ format.setIndentSize(4); format.setSuppressDeclaration(true); xmlwriter = new XMLWriter(writer, format); xmlwriter.write(document); result = writer.toString(); } catch (Exception e) { } finally { try { if (stringReader != null) stringReader.close(); if (xmlwriter != null) xmlwriter.close(); if (writer != null) writer.close(); } catch (Exception e) { } } return result; }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * XMLDocumentjava.io.Writer?//from w w w.jav a 2 s .co m * * * * ??Schema * * * * @param document * XML * @param outStream * * * * * @param encoding * ? * @throws XMLDocException * * * * @throws BaseException * */ public static void toXML(Document document, java.io.OutputStream outStream, String encoding) throws BaseException { // OutputFormat outformat = new OutputFormat(); outformat.setIndentSize(0); outformat.setNewlines(true); outformat.setTrimText(true); // OutputFormat outformat = OutputFormat.createPrettyPrint(); if (encoding == null || encoding.trim().equals("")) { encoding = DEFAULT_ENCODING; } // ? outformat.setEncoding(encoding); XMLWriter xmlWriter = null; try { xmlWriter = new XMLWriter(new OutputStreamWriter(outStream), outformat); xmlWriter.write(document); xmlWriter.flush(); } catch (IOException ex) { throw new BaseException("UTIL-0001", ex); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException ex) { } } } }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
public static void element2XML(Element element, java.io.OutputStream outStream, String encoding) throws BaseException { ///*w w w .j a v a2 s . c om*/ OutputFormat outformat = new OutputFormat(); outformat.setIndentSize(0); outformat.setNewlines(false); outformat.setTrimText(true); // OutputFormat outformat = OutputFormat.createPrettyPrint(); if (encoding == null || encoding.trim().equals("")) { encoding = DEFAULT_ENCODING; } // ? outformat.setEncoding(encoding); XMLWriter xmlWriter = null; try { xmlWriter = new XMLWriter(new OutputStreamWriter(outStream), outformat); xmlWriter.write(element); xmlWriter.flush(); } catch (IOException ex) { throw new BaseException("UTIL-0001", ex); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException ex) { } } } }
From source file:com.davis.bluefolder.BlueUtils.java
public String formatXML(String input) { try {/*from w ww.j a v a 2s. com*/ org.dom4j.Document doc = DocumentHelper.parseText(input); StringWriter sw = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setIndent(true); format.setIndentSize(3); XMLWriter xw = new XMLWriter(sw, format); xw.write(doc); return sw.toString(); } catch (Exception e) { e.printStackTrace(); return input; } }
From source file:com.eufar.asmm.server.DownloadFunction.java
License:EUPL
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("DownloadFunction - the function started"); ServletContext context = getServletConfig().getServletContext(); request.setCharacterEncoding("UTF-8"); String dir = context.getRealPath("/tmp"); ;//from ww w . j av a2 s . co m String filename = ""; File fileDir = new File(dir); try { System.out.println("DownloadFunction - create the file on server"); filename = request.getParameterValues("filename")[0]; String xmltree = request.getParameterValues("xmltree")[0]; // format xml code to pretty xml code Document doc = DocumentHelper.parseText(xmltree); StringWriter sw = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setIndent(true); format.setIndentSize(4); XMLWriter xw = new XMLWriter(sw, format); xw.write(doc); Writer out = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(dir + "/" + filename), "UTF-8")); out.append(sw.toString()); out.flush(); out.close(); } catch (Exception ex) { System.out.println("ERROR during rendering: " + ex); } try { System.out.println("DownloadFunction - send file to user"); ServletOutputStream out = response.getOutputStream(); File file = new File(dir + "/" + filename); String mimetype = context.getMimeType(filename); response.setContentType((mimetype != null) ? mimetype : "application/octet-stream"); response.setContentLength((int) file.length()); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); response.setHeader("Pragma", "private"); response.setHeader("Cache-Control", "private, must-revalidate"); DataInputStream in = new DataInputStream(new FileInputStream(file)); int length; while ((in != null) && ((length = in.read(bbuf)) != -1)) { out.write(bbuf, 0, length); } in.close(); out.flush(); out.close(); FileUtils.cleanDirectory(fileDir); } catch (Exception ex) { System.out.println("ERROR during downloading: " + ex); } System.out.println("DownloadFunction - file ready to be donwloaded"); }
From source file:com.nokia.helium.core.ant.filters.PrettyPrintXmlFilter.java
License:Open Source License
/** * Filter the input string.//w w w .j a v a 2 s.co m * * @param string * the string to filter * @return the modified string */ public String filter(String token) { String output = token; XMLWriter writer = null; if (token.length() > 0) { try { Document doc = DocumentHelper.parseText(token); StringWriter out = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setIndentSize(4); writer = new XMLWriter(out, format); writer.write(doc); output = out.toString(); } catch (org.dom4j.DocumentException exc) { throw new BuildException(exc.getMessage(), exc); } catch (IOException exc) { throw new BuildException(exc.getMessage(), exc); } finally { try { if (writer != null) { writer.close(); } } catch (IOException exc) { throw new BuildException(exc.getMessage(), exc); } } } return output; }
From source file:it.doqui.index.ecmengine.business.foundation.repository.ExportSvcBean.java
License:Open Source License
private Exporter createXMLExporter(OutputStream viewWriter, ReferenceType referenceType) { // Define output format OutputFormat format = OutputFormat.createPrettyPrint(); format.setNewLineAfterDeclaration(false); format.setIndentSize(2); format.setEncoding("UTF-8"); // Construct an XML Exporter try {// ww w . j a v a 2s .co m XMLWriter writer = new XMLWriter(viewWriter, format); ECMEngineExporter exporter = new ECMEngineExporter(serviceRegistry.getNamespaceService(), serviceRegistry.getNodeService(), serviceRegistry.getSearchService(), serviceRegistry.getDictionaryService(), serviceRegistry.getPermissionService(), writer); exporter.setReferenceType(referenceType); return exporter; } catch (UnsupportedEncodingException e) { throw new ExporterException("Failed to create XML Writer for export", e); } catch (Exception e) { throw new ExporterException("Failed to create XML Writer for export", e); } }
From source file:net.bpfurtado.ljcolligo.util.Util.java
License:Open Source License
public static void save(Element root, File file) { OutputFormat format = OutputFormat.createPrettyPrint(); format.setIndentSize(4); format.setEncoding("UTF-8"); format.setNewlines(true);/*from w w w. ja v a 2 s .c o m*/ format.setLineSeparator(System.getProperty("line.separator")); XMLWriter writer; try { writer = new XMLWriter(new FileWriter(file), format); writer.startDocument(); writer.write(root); writer.close(); logger.debug("All entries saved to file [" + file.getAbsolutePath() + "]"); } catch (Exception e) { throw new LJColligoException("File [" + file.getAbsolutePath() + "]", e); } }