List of usage examples for org.dom4j.io OutputFormat setNewLineAfterDeclaration
public void setNewLineAfterDeclaration(boolean newLineAfterDeclaration)
This will set whether a new line is printed after the XML declaration (assuming it is not supressed.)
From source file:org.alfresco.module.vti.web.fp.LockMethod.java
License:Open Source License
/** * @see org.alfresco.repo.webdav.WebDAVMethod#createXMLWriter() *//* ww w . jav a 2 s . c om*/ @Override protected OutputFormat getXMLOutputFormat() { OutputFormat outputFormat = new OutputFormat(); outputFormat.setNewLineAfterDeclaration(false); outputFormat.setNewlines(false); outputFormat.setIndent(false); return outputFormat; }
From source file:org.alfresco.repo.admin.patch.util.ImportFileUpdater.java
License:Open Source License
/** * Get the writer for the import file/* ww w.ja v a 2 s . c o m*/ * * @param destination the destination XML import file * @return the XML writer */ private XMLWriter getWriter(String destination) { try { // Define output format OutputFormat format = OutputFormat.createPrettyPrint(); format.setNewLineAfterDeclaration(false); format.setIndentSize(INDENT_SIZE); format.setEncoding(this.fileEncoding); return new XMLWriter(new FileOutputStream(destination), format); } catch (Exception exception) { throw new AlfrescoRuntimeException("Unable to create XML writer.", exception); } }
From source file:org.alfresco.repo.exporter.ExporterComponent.java
License:Open Source License
/** * Create an XML Exporter that exports repository information to the specified * output stream in xml format./*from ww w. ja va 2s . c om*/ * * @param viewWriter the output stream to write to * @param referenceType the format of references to export * @return the xml exporter */ private Exporter createXMLExporter(OutputStream viewWriter, ReferenceType referenceType) { // Define output format OutputFormat format = OutputFormat.createPrettyPrint(); format.setNewLineAfterDeclaration(false); format.setIndentSize(indentSize); format.setEncoding("UTF-8"); // Construct an XML Exporter try { XMLWriter writer = new XMLWriter(viewWriter, format); ViewXMLExporter exporter = new ViewXMLExporter(namespaceService, nodeService, searchService, dictionaryService, permissionService, 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:org.alfresco.repo.importer.ExportSourceImporter.java
License:Open Source License
private XMLWriter createXMLExporter(Writer writer) { // Define output format OutputFormat format = OutputFormat.createPrettyPrint(); format.setNewLineAfterDeclaration(false); format.setIndentSize(3);// ww w. j a v a 2 s . c o m format.setEncoding("UTF-8"); // Construct an XML Exporter XMLWriter xmlWriter = new XMLWriter(writer, format); return xmlWriter; }
From source file:org.alfresco.repo.transfer.report.XMLTransferReportWriter.java
License:Open Source License
/** * Start the transfer report//from www.j a va2 s . c o m */ public void startTransferReport(String encoding, Writer writer) throws SAXException { OutputFormat format = OutputFormat.createPrettyPrint(); format.setNewLineAfterDeclaration(false); format.setIndentSize(3); format.setEncoding(encoding); this.writer = new XMLWriter(writer, format); this.writer.startDocument(); this.writer.startPrefixMapping(PREFIX, TransferReportModel2.TRANSFER_REPORT_MODEL_2_0_URI); // Start Transfer Manifest // uri, name, prefix this.writer.startElement(TransferReportModel2.TRANSFER_REPORT_MODEL_2_0_URI, TransferReportModel.LOCALNAME_TRANSFER_REPORT, PREFIX + ":" + TransferReportModel.LOCALNAME_TRANSFER_REPORT, EMPTY_ATTRIBUTES); }
From source file:org.alfresco.repo.transfer.reportd.XMLTransferDestinationReportWriter.java
License:Open Source License
/** * Start the transfer report// ww w .j a v a 2 s .c o m */ public void startTransferReport(String encoding, Writer writer) { OutputFormat format = OutputFormat.createPrettyPrint(); format.setNewLineAfterDeclaration(false); format.setIndentSize(3); format.setEncoding(encoding); try { this.writer = new XMLWriter(writer, format); this.writer.startDocument(); this.writer.startPrefixMapping(PREFIX, TransferDestinationReportModel.TRANSFER_REPORT_MODEL_1_0_URI); // Start Transfer Manifest // uri, name, prefix this.writer.startElement(TransferDestinationReportModel.TRANSFER_REPORT_MODEL_1_0_URI, TransferDestinationReportModel.LOCALNAME_TRANSFER_DEST_REPORT, PREFIX + ":" + TransferDestinationReportModel.LOCALNAME_TRANSFER_DEST_REPORT, EMPTY_ATTRIBUTES); } catch (SAXException se) { se.printStackTrace(); } }
From source file:org.alfresco.repo.transfer.requisite.XMLTransferRequsiteWriter.java
License:Open Source License
public XMLTransferRequsiteWriter(Writer out) { OutputFormat format = OutputFormat.createPrettyPrint(); format.setNewLineAfterDeclaration(false); format.setIndentSize(3);/* w w w.j a v a 2 s. c o m*/ format.setEncoding("UTF-8"); this.writer = new XMLWriter(out, format); }
From source file:org.alfresco.repo.transfer.XMLWriter.java
License:Open Source License
public XMLWriter(OutputStream outputStream, boolean prettyPrint, String encoding) throws UnsupportedEncodingException { OutputFormat format = prettyPrint ? OutputFormat.createPrettyPrint() : OutputFormat.createCompactFormat(); format.setNewLineAfterDeclaration(false); format.setIndentSize(3);//from w w w . j a va2 s . co m format.setEncoding(encoding); output = outputStream; this.dom4jWriter = new org.dom4j.io.XMLWriter(outputStream, format); }
From source file:org.hightides.annotations.util.SpringXMLUtil.java
License:Apache License
/** * Private helper to save XML document.// w w w .j av a2 s . c o m * @param filename * @param doc * @param backup * @return */ private static boolean saveXMLDocument(String filename, Document doc, boolean backup) { // copy the target to backup folder if (backup) FileUtil.backupFile(filename); // overwrite the target OutputFormat format = OutputFormat.createPrettyPrint(); format.setExpandEmptyElements(false); format.setIndentSize(4); format.setNewLineAfterDeclaration(true); XMLWriter out; try { out = new XMLWriter(new FileWriter(filename), format); out.write(doc); out.flush(); out.close(); return true; } catch (IOException e) { _log.info("Failed to write to output filename [" + filename + "]", e); return false; } }
From source file:org.talend.mdm.webapp.base.server.util.XmlUtil.java
License:Open Source License
public static String format(Document document, OutputFormat format, String encoding) { StringWriter writer = new StringWriter(); format.setEncoding(encoding);// w w w . j a v a 2 s. co m format.setNewLineAfterDeclaration(false); XMLWriter xmlwriter = new XMLWriter(writer, format); try { xmlwriter.write(document); } catch (Exception e) { logger.error(e.getMessage(), e); } return writer.toString().replaceAll("<\\?xml.*?\\?>", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$ }