List of usage examples for org.dom4j.io OutputFormat createCompactFormat
public static OutputFormat createCompactFormat()
From source file:org.craftercms.cstudio.alfresco.transform.TaxonomyRendition.java
License:Open Source License
/** * Write renditionResult along with the flattened XML file to WCM * //from ww w . java2 s . c om * @param articleRef */ public InputStream generateOutputFile(NodeRef articleRef) throws ServiceException { InputStream retStream = null; try { Document document = retreiveXml(articleRef); String encoding = document.getXMLEncoding(); if (encoding == null) { encoding = "UTF-16"; } Writer stringOutputWriter = new StringWriter(); OutputFormat opf = OutputFormat.createCompactFormat(); opf.setSuppressDeclaration(true); XMLWriter writer = new XMLWriter(stringOutputWriter, opf); writer.write(document); writer.close(); retStream = new ByteArrayInputStream(stringOutputWriter.toString().getBytes(encoding)); } catch (ServiceException e) { if (LOGGER.isErrorEnabled()) { LOGGER.error("Cannot create output XML Document: " + e.getMessage(), e); } throw new ServiceException("Cannot create output XML Document: " + e.getMessage(), e); } catch (IOException e) { if (LOGGER.isErrorEnabled()) { LOGGER.error("Cannot create output XML Document: " + e.getMessage(), e); } throw new ServiceException("Cannot create output XML Document: " + e.getMessage(), e); } return retStream; }
From source file:org.craftercms.search.batch.impl.XmlFileBatchIndexer.java
License:Open Source License
protected String documentToString(Document document) { StringWriter stringWriter = new StringWriter(); OutputFormat format = OutputFormat.createCompactFormat(); XMLWriter xmlWriter = new XMLWriter(stringWriter, format); try {/*from www .ja v a2 s .c o m*/ xmlWriter.write(document); } catch (IOException e) { // Ignore, shouldn't happen. } return stringWriter.toString(); }
From source file:org.directwebremoting.convert.DOM4JConverter.java
License:Apache License
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws ConversionException { try {// w ww .j a va2s . co m // Using XSLT to convert to a stream. Setup the source if (!(data instanceof Node)) { throw new ConversionException(data.getClass()); } Node node = (Node) data; OutputFormat outformat = OutputFormat.createCompactFormat(); outformat.setEncoding("UTF-8"); // Setup the destination StringWriter xml = new StringWriter(); XMLWriter writer = new XMLWriter(xml, outformat); writer.write(node); writer.flush(); xml.flush(); String script; if (data instanceof Element) { script = EnginePrivate.xmlStringToJavascriptDomElement(xml.toString()); } else { script = EnginePrivate.xmlStringToJavascriptDomDocument(xml.toString()); } OutboundVariable ov = new NonNestedOutboundVariable(script); outctx.put(data, ov); return ov; } catch (ConversionException ex) { throw ex; } catch (Exception ex) { throw new ConversionException(data.getClass(), ex); } }
From source file:org.eclipse.jubula.client.core.businessprocess.HtmlResultReportWriter.java
License:Open Source License
/** * /*from w ww . j av a 2 s . c o m*/ * {@inheritDoc} */ public void write(Document document) { // write html, transformed by XSLT OutputFormat htmlFormat = OutputFormat.createCompactFormat(); htmlFormat.setEncoding(m_writer.getEncoding()); TransformerFactory factory = TransformerFactory.newInstance(); try { TestResultBP trbp = TestResultBP.getInstance(); final Transformer transformer = factory .newTransformer(new StreamSource(trbp.getXslFileURL().openStream())); DocumentSource source = new DocumentSource(document); DocumentResult result = new DocumentResult(); transformer.transform(source, result); Document transformedDoc = result.getDocument(); XMLWriter htmlWriter = new XMLWriter(m_writer, htmlFormat); htmlWriter.write(transformedDoc); } catch (TransformerConfigurationException e1) { LOG.error(Messages.ErrorFileWriting + StringConstants.DOT, e1); } catch (TransformerException e) { LOG.error(Messages.ErrorFileWriting + StringConstants.DOT, e); } catch (IOException e) { LOG.error(Messages.ErrorFileWriting + StringConstants.DOT, e); } }
From source file:org.efaps.webdav4vfs.handler.PropFindHandler.java
License:Apache License
/** * Handle a PROPFIND request.//from w ww . j a va 2s . com * * @param request the servlet request * @param response the servlet response * @throws IOException if there is an error that cannot be handled normally */ @Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { SAXReader saxReader = new SAXReader(); try { Document propDoc = saxReader.read(request.getInputStream()); logXml(propDoc); Element propFindEl = propDoc.getRootElement(); for (Object propElObject : propFindEl.elements()) { Element propEl = (Element) propElObject; if (VALID_PROPFIND_TAGS.contains(propEl.getName())) { FileObject object = VFSBackend.resolveFile(request.getPathInfo()); if (object.exists()) { // respond as XML encoded multi status response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); response.setStatus(SC_MULTI_STATUS); Document multiStatusResponse = getMultiStatusResponse(object, propEl, getBaseUrl(request), getDepth(request)); logXml(multiStatusResponse); // write the actual response XMLWriter writer = new XMLWriter(response.getWriter(), OutputFormat.createCompactFormat()); writer.write(multiStatusResponse); writer.flush(); writer.close(); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } break; } } } catch (DocumentException e) { LOG.error("invalid request: " + e.getMessage()); response.sendError(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:org.efaps.webdav4vfs.handler.PropPatchHandler.java
License:Apache License
/** * Handle a PROPPATCH request.//from www . ja v a 2 s. c o m * * @param request the servlet request * @param response the servlet response * @throws IOException if there is an error that cannot be handled normally */ @Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { FileObject object = VFSBackend.resolveFile(request.getPathInfo()); try { if (!LockManager.getInstance().evaluateCondition(object, getIf(request)).result) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } } catch (LockException e) { response.sendError(SC_LOCKED); return; } catch (ParseException e) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } if (object.exists()) { SAXReader saxReader = new SAXReader(); try { Document propDoc = saxReader.read(request.getInputStream()); logXml(propDoc); Element propUpdateEl = propDoc.getRootElement(); List<Element> requestedProperties = new ArrayList<Element>(); for (Object elObject : propUpdateEl.elements()) { Element el = (Element) elObject; String command = el.getName(); if (AbstractDavResource.TAG_PROP_SET.equals(command) || AbstractDavResource.TAG_PROP_REMOVE.equals(command)) { for (Object propElObject : el.elements()) { for (Object propNameElObject : ((Element) propElObject).elements()) { Element propNameEl = (Element) propNameElObject; requestedProperties.add(propNameEl); } } } } // respond as XML encoded multi status response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); response.setStatus(SC_MULTI_STATUS); Document multiStatusResponse = getMultiStatusResponse(object, requestedProperties, getBaseUrl(request)); logXml(multiStatusResponse); // write the actual response XMLWriter writer = new XMLWriter(response.getWriter(), OutputFormat.createCompactFormat()); writer.write(multiStatusResponse); writer.flush(); writer.close(); } catch (DocumentException e) { LOG.error("invalid request: " + e.getMessage()); response.sendError(HttpServletResponse.SC_BAD_REQUEST); } } else { LOG.error(object.getName().getPath() + " NOT FOUND"); response.sendError(HttpServletResponse.SC_NOT_FOUND); } }
From source file:org.gbif.portal.util.mhf.message.impl.xml.XMLMessage.java
License:Open Source License
/** * @see org.gbif.portal.util.mhf.Message#getRawData() *///from ww w . jav a 2 s . c o m public String getRawData() throws MessageAccessException { if (rawXml != null) return rawXml.toString(); else { // build a short string StringWriter writer = new StringWriter(); OutputFormat outformat = OutputFormat.createCompactFormat(); outformat.setSuppressDeclaration(true); XMLWriter xmlWriter = new XMLWriter(writer, outformat); try { xmlWriter.write(getDocument()); xmlWriter.flush(); String rawXml = writer.toString(); setRawData(rawXml); return rawXml; } catch (IOException e) { throw new MessageAccessException("Error writing the XML Document", e); } finally { try { xmlWriter.close(); } catch (IOException e) { } try { writer.close(); } catch (IOException e) { } } } }
From source file:org.infoglue.cms.applications.common.actions.SimpleXmlServiceAction.java
License:Open Source License
protected String getFormattedDocument(Document doc, boolean compact, boolean supressDecl) { OutputFormat format = compact ? OutputFormat.createCompactFormat() : OutputFormat.createPrettyPrint(); format.setSuppressDeclaration(supressDecl); format.setEncoding(ENCODING);/*from w w w . j a v a 2 s.com*/ format.setExpandEmptyElements(false); StringWriter stringWriter = new StringWriter(); XMLWriter writer = new XMLWriter(stringWriter, format); try { writer.write(doc); } catch (IOException e) { e.printStackTrace(); } return stringWriter.toString(); }
From source file:org.infoglue.cms.applications.contenttool.actions.ContentTreeXMLAction.java
License:Open Source License
private String getFormattedDocument(Document doc, boolean compact) { OutputFormat format = compact ? OutputFormat.createCompactFormat() : OutputFormat.createPrettyPrint(); // format.setEncoding("iso-8859-1"); format.setEncoding("UTF-8"); format.setExpandEmptyElements(false); StringWriter stringWriter = new StringWriter(); XMLWriter writer = new XMLWriter(stringWriter, format); try {//from w ww . j ava2 s . co m writer.write(doc); } catch (IOException e) { e.printStackTrace(); } return stringWriter.toString(); }
From source file:org.infoglue.cms.util.dom.DOMBuilder.java
License:Open Source License
/** * This method writes a document to file. */// ww w.j a v a2 s . c o m public void write(Document document, String fileName) throws Exception { OutputFormat format = OutputFormat.createCompactFormat(); format.setEncoding("UTF-8"); XMLWriter writer = new XMLWriter(new FileWriter(fileName), format); writer.write(document); writer.close(); }