List of usage examples for org.dom4j.io OutputFormat OutputFormat
public OutputFormat()
OutputFormat
with no additional whitespace (indent or new lines) added. From source file:org.mule.devkit.model.studio.StudioModel.java
License:Open Source License
private void serializeXml() throws JAXBException, IOException { JAXBContext jaxbContext = JAXBContext.newInstance(NamespaceType.class); Marshaller marshaller = jaxbContext.createMarshaller(); NamespaceFilter outFilter = new NamespaceFilter("mule", "http://www.mulesoft.org/schema/mule/core", true); OutputFormat format = new OutputFormat(); format.setIndent(true);/*from w w w .j av a 2 s . c o m*/ format.setNewlines(true); OutputStream schemaStream = codeWriter.openBinary(null, outputFileName); XMLWriter writer = new XMLWriter(schemaStream, format); outFilter.setContentHandler(writer); marshaller.marshal(namespaceType, outFilter); }
From source file:org.mule.module.extension.internal.capability.xml.schema.SchemaGenerator.java
License:Open Source License
private String renderSchema(Schema schema) { try {/*ww w.j a va2s. c o m*/ JAXBContext jaxbContext = JAXBContext.newInstance(Schema.class); Marshaller marshaller = jaxbContext.createMarshaller(); NamespaceFilter outFilter = new NamespaceFilter("mule", SchemaConstants.MULE_NAMESPACE, true); OutputFormat format = new OutputFormat(); format.setIndent(true); format.setNewlines(true); StringWriter sw = new StringWriter(); XMLWriter writer = new XMLWriter(sw, format); outFilter.setContentHandler(writer); marshaller.marshal(schema, outFilter); return sw.toString(); } catch (JAXBException e) { throw new RuntimeException(e); } }
From source file:org.nuxeo.ecm.jsf2.migration.impl.MigrationServiceImpl.java
License:Open Source License
/** * Create a file containing the migration done in the Document. * * @param input//from w w w . j a v a 2s. com * @param filePath * @throws Exception */ protected void createFile(Document input, String filePath, boolean createNewFile) throws Exception { // Create file File fileMigrated = new File(filePath); if (createNewFile) { fileMigrated.createNewFile(); } PrintWriter printWriter = new PrintWriter(fileMigrated); OutputFormat format = new OutputFormat(); format.setIndentSize(2); format.setNewlines(true); format.setTrimText(true); XMLWriter writer = new XMLWriter(printWriter, format); writer.write(input); printWriter.close(); }
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 *//* ww w .j a va 2 s . co 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.orbeon.oxf.xml.dom4j.Dom4jUtils.java
License:Open Source License
/** * Convert a dom4j document to a pretty string, for formatting/debugging purposes only. * * @param document document to convert/* w w w.j a v a2s . c om*/ * @return resulting string */ public static String domToPrettyString(final Document document) { final OutputFormat format = new OutputFormat(); format.setIndentSize(4); format.setNewlines(true); format.setTrimText(true); return domToString(document.getRootElement(), format); }
From source file:org.orbeon.oxf.xml.dom4j.Dom4jUtils.java
License:Open Source License
/** * Convert a dom4j document to a compact string, with all text being trimmed. * * @param document document to convert// ww w . j a v a 2s. co m * @return resulting string */ public static String domToCompactString(final Document document) { final OutputFormat format = new OutputFormat(); format.setIndent(false); format.setNewlines(false); format.setTrimText(true); return domToString(document.getRootElement(), format); }
From source file:org.orbeon.oxf.xml.dom4j.Dom4jUtils.java
License:Open Source License
private static String domToString(final Branch branch) { final OutputFormat format = new OutputFormat(); format.setIndent(false);// ww w .j a va 2 s.com format.setNewlines(false); return domToString(branch, format); }
From source file:org.projectforge.framework.xstream.XmlHelper.java
License:Open Source License
public static String toString(final Element el, final boolean prettyFormat) { if (el == null) { return ""; }/*ww w .j av a 2s . c o m*/ final StringWriter out = new StringWriter(); final OutputFormat format = new OutputFormat(); if (prettyFormat == true) { format.setNewlines(true); format.setIndentSize(2); } final XMLWriter writer = new XMLWriter(out, format); String result = null; try { writer.write(el); result = out.toString(); writer.close(); } catch (final IOException ex) { log.error(ex.getMessage(), ex); } return result; }
From source file:org.richie.codeGen.ui.util.XmlParse.java
License:Apache License
/** * xml?// w w w. j ava2 s. c o m * * @param document ? * @param outFile ? * @throws IOException */ public static void writeDocument(Document document, String outFile) throws IOException { XMLWriter xmlWriter = null; try { // ? OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"); // ? OutputFormat xmlFormat = new OutputFormat(); xmlFormat.setEncoding("UTF-8"); // xmlWriter = new XMLWriter(out, xmlFormat); // xmlWriter.write(document); } catch (IOException e) { throw e; } finally { // if (xmlWriter != null) xmlWriter.close(); } }
From source file:org.sipfoundry.sipxconfig.admin.dialplan.config.MappingRules.java
License:Contributor Agreement License
@Override protected void localizeDocument(Location location) { if (location == null) { return;/*from ww w . j a v a 2s . co m*/ } try { Document document = getDocument(); OutputFormat format = new OutputFormat(); StringWriter stringWriter = new StringWriter(); XMLWriter xmlWriter = new XMLWriter(stringWriter, format); xmlWriter.write(document); String rulesString = stringWriter.toString(); rulesString = rulesString.replace(SIPXCHANGE_DOMAIN_NAME, getDomainManager().getDomain().getName()); rulesString = rulesString.replace(MY_IP_ADDR, location.getAddress()); rulesString = rulesString.replace(MY_FULL_HOSTNAME, location.getFqdn()); rulesString = rulesString.replace(MY_HOSTNAME, location.getHostname()); SipxRlsService rlsService = (SipxRlsService) m_sipxServiceManager .getServiceByBeanId(SipxRlsService.BEAN_ID); String rlsServerSipSrvOrHostport = rlsService.getAddress() + ':' + rlsService.getRlsPort(); rulesString = rulesString.replace(RLS_SIP_SRV_OR_HOSTPORT, rlsServerSipSrvOrHostport); SipxParkService parkService = (SipxParkService) m_sipxServiceManager .getServiceByBeanId(SipxParkService.BEAN_ID); String parkServerSipSrvOrHostport = parkService.getAddress() + ':' + parkService.getParkServerSipPort(); rulesString = rulesString.replace(ORBIT_SERVER_SIP_SRV_OR_HOSTPORT, parkServerSipSrvOrHostport); SipxPageService pageService = (SipxPageService) m_sipxServiceManager .getServiceByBeanId(SipxPageService.BEAN_ID); rulesString = rulesString.replace("${PAGE_SERVER_ADDR}", pageService.getAddress()); rulesString = rulesString.replace("${PAGE_SERVER_SIP_PORT}", pageService.getSipPort()); StringReader stringReader = new StringReader(rulesString); SAXReader saxReader = new SAXReader(); m_doc = saxReader.read(stringReader); } catch (IOException ioe) { throw new RuntimeException(ioe); } catch (DocumentException de) { throw new RuntimeException(de); } }