List of usage examples for org.dom4j.io OutputFormat setSuppressDeclaration
public void setSuppressDeclaration(boolean suppressDeclaration)
This will set whether the XML declaration (<?xml version="1.0" encoding="UTF-8"?>
) is included or not.
From source file:org.opencms.util.ant.CmsXmlUtils.java
License:Open Source License
/** * Marshals (writes) an XML node into an output stream using XML pretty-print formatting.<p> * /* w w w . java 2s . c o m*/ * @param node the XML node to marshal * @param encoding the encoding to use * * @return the string with the xml content * * @throws Exception if something goes wrong */ public static String marshal(Node node, String encoding) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(encoding); format.setSuppressDeclaration(true); XMLWriter writer = new XMLWriter(out, format); writer.setEscapeText(false); writer.write(node); writer.close(); return new String(out.toByteArray()); }
From source file:org.opencms.xml.CmsXmlUtils.java
License:Open Source License
/** * Marshals (writes) an XML node into an output stream using XML pretty-print formatting.<p> * /*from w ww .ja v a2 s . co m*/ * @param node the XML node to marshal * @param encoding the encoding to use * * @return the string with the xml content * * @throws CmsXmlException if something goes wrong */ public static String marshal(Node node, String encoding) throws CmsXmlException { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(encoding); format.setSuppressDeclaration(true); XMLWriter writer = new XMLWriter(out, format); writer.setEscapeText(false); writer.write(node); writer.close(); } catch (Exception e) { throw new CmsXmlException(Messages.get().container(Messages.ERR_MARSHALLING_XML_DOC_0), e); } return new String(out.toByteArray()); }
From source file:org.pentaho.platform.util.xml.dom4j.XmlDom4JHelper.java
License:Open Source License
public static void saveDom(final Document doc, final OutputStream outputStream, String encoding, boolean suppressDeclaration, boolean prettyPrint) throws IOException { OutputFormat format = prettyPrint ? OutputFormat.createPrettyPrint() : OutputFormat.createCompactFormat(); format.setSuppressDeclaration(suppressDeclaration); if (encoding != null) { format.setEncoding(encoding.toLowerCase()); if (!suppressDeclaration) { doc.setXMLEncoding(encoding.toUpperCase()); }/*from w w w. j a va 2s .c o m*/ } XMLWriter writer = new XMLWriter(outputStream, format); writer.write(doc); writer.flush(); }
From source file:org.pentaho.platform.web.http.api.resources.XactionUtil.java
License:Open Source License
@SuppressWarnings({ "unchecked", "rawtypes" }) public static String executeXml(RepositoryFile file, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, IPentahoSession userSession) throws Exception { try {//from w ww. j a v a2 s.co m HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider(userSession); HttpRequestParameterProvider requestParameters = new HttpRequestParameterProvider(httpServletRequest); Map parameterProviders = new HashMap(); parameterProviders.put("request", requestParameters); //$NON-NLS-1$ parameterProviders.put("session", sessionParameters); //$NON-NLS-1$ List messages = new ArrayList(); IParameterProvider requestParams = new HttpRequestParameterProvider(httpServletRequest); httpServletResponse.setContentType("text/xml"); //$NON-NLS-1$ httpServletResponse.setCharacterEncoding(LocaleHelper.getSystemEncoding()); boolean forcePrompt = "true".equalsIgnoreCase(requestParams.getStringParameter("prompt", "false")); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ OutputStream contentStream = new ByteArrayOutputStream(); SimpleOutputHandler outputHandler = new SimpleOutputHandler(contentStream, false); IRuntimeContext runtime = null; try { runtime = executeInternal(file, requestParams, httpServletRequest, outputHandler, parameterProviders, userSession, forcePrompt, messages); Document responseDoc = SoapHelper.createSoapResponseDocument(runtime, outputHandler, contentStream, messages); OutputFormat format = OutputFormat.createCompactFormat(); format.setSuppressDeclaration(true); format.setEncoding("utf-8"); //$NON-NLS-1$ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(outputStream, format); writer.write(responseDoc); writer.flush(); return outputStream.toString("utf-8"); //$NON-NLS-1$ } finally { if (runtime != null) { runtime.dispose(); } } } catch (Exception e) { logger.warn(Messages.getInstance().getString("XactionUtil.XML_OUTPUT_NOT_SUPPORTED")); //$NON-NLS-1$ throw e; } }
From source file:org.pentaho.platform.web.http.api.resources.XactionUtil.java
License:Open Source License
@SuppressWarnings({ "unchecked", "rawtypes" }) public static String doParameter(final RepositoryFile file, IParameterProvider parameterProvider, final IPentahoSession userSession) throws IOException { ActionSequenceJCRHelper helper = new ActionSequenceJCRHelper(); final IActionSequence actionSequence = helper.getActionSequence(file.getPath(), PentahoSystem.loggingLevel, RepositoryFilePermission.READ); final Document document = DocumentHelper.createDocument(); try {/* w w w. jav a 2 s .c o m*/ final Element parametersElement = document.addElement("parameters"); // noinspection unchecked final Map<String, IActionParameter> params = actionSequence .getInputDefinitionsForParameterProvider(IParameterProvider.SCOPE_REQUEST); for (final Map.Entry<String, IActionParameter> entry : params.entrySet()) { final String paramName = entry.getKey(); final IActionParameter paramDef = entry.getValue(); final String value = paramDef.getStringValue(); final Class type; // yes, the actual type-code uses equals-ignore-case and thus allows the user // to specify type information in a random case. sTrInG is equal to STRING is equal to the value // defined as constant (string) if (IActionParameter.TYPE_LIST.equalsIgnoreCase(paramDef.getType())) { type = String[].class; } else { type = String.class; } final String label = paramDef.getSelectionDisplayName(); final String[] values; if (StringUtils.isEmpty(value)) { values = new String[0]; } else { values = new String[] { value }; } createParameterElement(parametersElement, paramName, type, label, "user", "parameters", values); } createParameterElement(parametersElement, "path", String.class, null, "system", "system", new String[] { file.getPath() }); createParameterElement(parametersElement, "prompt", String.class, null, "system", "system", new String[] { "yes", "no" }); createParameterElement(parametersElement, "instance-id", String.class, null, "system", "system", new String[] { parameterProvider.getStringParameter("instance-id", null) }); // no close, as far as I know tomcat does not like it that much .. OutputFormat format = OutputFormat.createCompactFormat(); format.setSuppressDeclaration(true); format.setEncoding("utf-8"); //$NON-NLS-1$ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(outputStream, format); writer.write(document); writer.flush(); return outputStream.toString("utf-8"); } catch (Exception e) { logger.warn(Messages.getInstance().getString("HttpWebService.ERROR_0003_UNEXPECTED"), e); return null; } }
From source file:org.sipfoundry.sipxconfig.conference.ConferenceConfiguration.java
License:Contributor Agreement License
@Override public OutputFormat createFormat() { OutputFormat format = OutputFormat.createPrettyPrint(); format.setOmitEncoding(true);//www. jav a 2 s . c o m format.setSuppressDeclaration(true); return format; }
From source file:org.springframework.extensions.webscripts.AbstractStore.java
License:Apache License
public void createDocuments(List<Pair<String, Document>> pathContents) throws IOException { for (Pair<String, Document> pathContent : pathContents) { OutputFormat format = OutputFormat.createPrettyPrint(); format.setSuppressDeclaration(false); StringBuilderWriter writer = new StringBuilderWriter(1024); XMLWriter xmlWriter = new XMLWriter(writer, format); xmlWriter.write(pathContent.getSecond()); xmlWriter.flush();//from w w w .j a va 2 s .c om writer.close(); createDocument(pathContent.getFirst(), writer.toString()); } }
From source file:org.springframework.extensions.webscripts.RemoteStore.java
License:Apache License
@Override public void createDocuments(List<Pair<String, Document>> pathContents) throws IOException { Document master = DocumentHelper.createDocument(); Element docEl = master.addElement("master"); for (Pair<String, Document> pathContent : pathContents) { Element document = docEl.addElement("document"); final String storePath = getStorePath(); document.addAttribute("path", (storePath.equals("/") ? storePath : '/' + storePath) + pathContent.getFirst()); document.add(pathContent.getSecond().getRootElement().createCopy()); }//from w w w . jav a 2s . c o m ByteArrayOutputStream out = new ByteArrayOutputStream(4096); OutputFormat format = OutputFormat.createPrettyPrint(); format.setSuppressDeclaration(false); XMLWriter xmlWriter = new XMLWriter(out, format); xmlWriter.write(master); xmlWriter.flush(); out.close(); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); Response res = callPost(buildEncodeCall(API_CREATE_MULTI, ""), in); if (logger.isDebugEnabled()) logger.debug( "RemoteStore.createDocuments() " + pathContents.size() + " = " + res.getStatus().getCode()); if (Status.STATUS_OK != res.getStatus().getCode()) { throw new IOException("Unable to create documents in remote store: " + this.getEndpoint() + " due to error: " + res.getStatus().getCode() + " " + res.getStatus().getMessage()); } }
From source file:org.zenonpagetemplates.twoPhasesImpl.ZPTOutputFormat.java
License:Open Source License
public OutputFormat getOutputFormat() { OutputFormat result = new OutputFormat(); result.setEncoding(this.encoding); //result.setOmitEncoding(true); result.setSuppressDeclaration(this.suppressDeclaration); //result.setExpandEmptyElements(expandEmptyElements) return result; }
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 w w w . j ava 2 s . co 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); } }