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);
}
}
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;
}
Aggregations