Search in sources :

Example 11 with DocumentSource

use of org.dom4j.io.DocumentSource in project zm-mailbox by Zimbra.

the class JaxbUtil method elementToJaxbUsingDom4j.

/**
 * Method left in place to discourage future attempts to use dom4j as a basis for Element to JAXB - unless the
 * underlying issue is understood and resolved.
 * This sometimes fails badly whether e is a JSONElement or an XMLElement - get:
 *    "javax.xml.bind.UnmarshalException: Namespace URIs and local names to the unmarshaller needs to be interned."
 * and that seems to make the unmarshaller unstable from then on :-(
 * Note that this method does NOT support Zimbra's greater flexibility for Xml structure.
 * Something similar to {@link fixupStructureForJaxb} would be needed to add such support.
 */
@Deprecated
@SuppressWarnings("unchecked")
public static <T> T elementToJaxbUsingDom4j(Element e) throws ServiceException {
    try {
        Unmarshaller unmarshaller = getContext().createUnmarshaller();
        org.dom4j.Element rootElem = e.toXML();
        DocumentSource docSrc = new DocumentSource(rootElem);
        return (T) unmarshaller.unmarshal(docSrc);
    } catch (JAXBException ex) {
        throw ServiceException.FAILURE("Unable to unmarshal response for " + e.getName(), ex);
    }
}
Also used : DocumentSource(org.dom4j.io.DocumentSource) JAXBException(javax.xml.bind.JAXBException) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 12 with DocumentSource

use of org.dom4j.io.DocumentSource in project tmdm-studio-se by Talend.

the class XmlUtil method styleDocument.

public static Document styleDocument(Document document, String stylesheet) throws Exception {
    // load the transformer using JAXP
    TransformerFactory factory = XmlUtils.getXmlSecureTransformerFactory();
    Transformer transformer = factory.newTransformer(new StreamSource(stylesheet));
    // now lets style the given document
    DocumentSource source = new DocumentSource(document);
    DocumentResult result = new DocumentResult();
    transformer.transform(source, result);
    // return the transformed document
    Document transformedDoc = result.getDocument();
    logger.info(Messages.XmlUtil_Loginfo2);
    return transformedDoc;
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) DocumentResult(org.dom4j.io.DocumentResult) DocumentSource(org.dom4j.io.DocumentSource) StreamSource(javax.xml.transform.stream.StreamSource) Document(org.dom4j.Document)

Aggregations

DocumentSource (org.dom4j.io.DocumentSource)12 Transformer (javax.xml.transform.Transformer)7 DocumentResult (org.dom4j.io.DocumentResult)6 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)4 TransformerException (javax.xml.transform.TransformerException)4 TransformerFactory (javax.xml.transform.TransformerFactory)4 StreamSource (javax.xml.transform.stream.StreamSource)4 Document (org.dom4j.Document)3 ShineRuntimeException (com.thoughtworks.studios.shine.ShineRuntimeException)2 Graph (com.thoughtworks.studios.shine.semweb.Graph)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 StringWriter (java.io.StringWriter)2 StreamResult (javax.xml.transform.stream.StreamResult)2 MethodInvocationException (org.apache.velocity.exception.MethodInvocationException)2 ParseErrorException (org.apache.velocity.exception.ParseErrorException)2 ResourceNotFoundException (org.apache.velocity.exception.ResourceNotFoundException)2 DOMDocument (org.dom4j.dom.DOMDocument)2 SAXReader (org.dom4j.io.SAXReader)2