List of usage examples for org.dom4j.io SAXReader setMergeAdjacentText
public void setMergeAdjacentText(boolean mergeAdjacentText)
From source file:org.nuxeo.ecm.platform.webdav.servlet.WebDavRequestWrapper.java
License:Open Source License
private static Element getDocumentRoot(InputStream stream) { try {/* w w w.ja va2s.c om*/ SAXReader saxReader = new SAXReader(); //saxReader.setEntityResolver(new DTDEntityResolver()); saxReader.setMergeAdjacentText(true); return saxReader.read(stream).getRootElement(); } catch (DocumentException de) { log.error("Error while parsing XML request Body : " + de.getMessage()); try { int size = stream.available(); byte[] buffer = new byte[size]; stream.read(buffer); log.error("input stream = " + buffer); } catch (IOException e) { log.error("Unable to read input buffer : " + e.getMessage()); } return null; //throw new RuntimeException(de); } }
From source file:org.opencms.util.ant.CmsXmlUtils.java
License:Open Source License
/** * Helper to unmarshal (read) xml contents from an input source into a document.<p> * /* w w w .jav a 2 s . c o m*/ * Using this method ensures that the OpenCms XML entity resolver is used.<p> * * Important: The encoding provided will NOT be used during unmarshalling, * the XML parser will do this on the base of the information in the source String. * The encoding is used for initializing the created instance of the document, * which means it will be used when marshalling the document again later.<p> * * @param source the XML input source to use * @param resolver the XML entity resolver to use * @param validate if the reader should try to validate the xml code * * @return the unmarshalled XML document * * @throws Exception if something goes wrong */ public static Document unmarshalHelper(InputSource source, EntityResolver resolver, boolean validate) throws Exception { SAXReader reader = new SAXReader(); if (resolver != null) { reader.setEntityResolver(resolver); } reader.setMergeAdjacentText(true); reader.setStripWhitespaceText(true); if (!validate) { reader.setValidation(false); reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); } return reader.read(source); }
From source file:org.opencms.xml.CmsXmlUtils.java
License:Open Source License
/** * Helper to unmarshal (read) xml contents from an input source into a document.<p> * //from w w w . j a va 2 s. co m * Using this method ensures that the OpenCms XML entity resolver is used.<p> * * Important: The encoding provided will NOT be used during unmarshalling, * the XML parser will do this on the base of the information in the source String. * The encoding is used for initializing the created instance of the document, * which means it will be used when marshalling the document again later.<p> * * @param source the XML input source to use * @param resolver the XML entity resolver to use * @param validate if the reader should try to validate the xml code * * @return the unmarshalled XML document * * @throws CmsXmlException if something goes wrong */ public static Document unmarshalHelper(InputSource source, EntityResolver resolver, boolean validate) throws CmsXmlException { try { SAXReader reader = new SAXReader(); if (resolver != null) { reader.setEntityResolver(resolver); } reader.setMergeAdjacentText(true); reader.setStripWhitespaceText(true); if (!validate) { reader.setValidation(false); reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); } return reader.read(source); } catch (DocumentException e) { throw new CmsXmlException(Messages.get().container(Messages.ERR_UNMARSHALLING_XML_DOC_0), e); } catch (SAXException e) { throw new CmsXmlException(Messages.get().container(Messages.ERR_UNMARSHALLING_XML_DOC_0), e); } }
From source file:org.sapia.util.xml.confix.Dom4jProcessor.java
License:Open Source License
/** * This method takes an XML stream as input and returns an object * representation of the passed-in XML./*from w w w. jav a2 s.co m*/ * * @param is an XML stream * @return an object representation of the XML stream. * @exception ProcessingException */ public Object process(InputStream is) throws ProcessingException { try { // Build the document from the input stream SAXReader builder = new SAXReader(); builder.setStripWhitespaceText(false); builder.setMergeAdjacentText(false); Document doc = builder.read(is); // Process the document Object aResult = process(null, doc.getRootElement()); return aResult; } catch (DocumentException de) { String aMessage = "Error parsing the XML of the input stream."; throw new ProcessingException(aMessage, de); } finally { try { if (is != null) { is.close(); } } catch (IOException ioe) { String aMessage = "Error closing the input stream to process."; throw new ProcessingException(aMessage, ioe); } } }
From source file:org.xwiki.store.serialization.xml.internal.AbstractXMLSerializer.java
License:Open Source License
/** * {@inheritDoc}/*from www .j a va2s. c o m*/ * * @see org.xwiki.store.filesystem.internal.XMLSerializer#parse(InputStream) */ public P parse(final InputStream stream) throws IOException { final SAXReader reader = new SAXReader(); // Remove nodes generated by indentation. reader.setStripWhitespaceText(true); reader.setMergeAdjacentText(true); final Document domdoc; try { domdoc = reader.read(stream); } catch (DocumentException e) { throw new IOException("Failed to parse XML, probably malformed input."); } return this.parse(domdoc.getRootElement()); }