use of org.apache.cxf.staxutils.transform.OutTransformWriter in project cxf by apache.
the class JAXRSBPNamespaceHandler method transformElement.
private Element transformElement(Element element) {
final Map<String, String> transformMap = Collections.singletonMap("{" + element.getNamespaceURI() + "}*", "{http://cxf.apache.org/blueprint/jaxrs-client}*");
W3CDOMStreamWriter domWriter = new W3CDOMStreamWriter();
OutTransformWriter transformWriter = new OutTransformWriter(domWriter, transformMap);
try {
StaxUtils.copy(element, transformWriter);
} catch (XMLStreamException e) {
throw new RuntimeException(e);
}
return domWriter.getDocument().getDocumentElement();
}
use of org.apache.cxf.staxutils.transform.OutTransformWriter in project cxf by apache.
the class JAXBExtensionHelper method marshall.
/* (non-Javadoc)
* @see javax.wsdl.extensions.ExtensionSerializer#marshall(java.lang.Class,
* javax.xml.namespace.QName, javax.wsdl.extensions.ExtensibilityElement,
* java.io.PrintWriter, javax.wsdl.Definition, javax.wsdl.extensions.ExtensionRegistry)
*/
public void marshall(@SuppressWarnings("rawtypes") Class parent, QName qname, ExtensibilityElement obj, PrintWriter pw, final Definition wsdl, ExtensionRegistry registry) throws WSDLException {
try {
Marshaller u = createMarshaller();
u.setProperty("jaxb.encoding", StandardCharsets.UTF_8.name());
u.setProperty("jaxb.fragment", Boolean.TRUE);
u.setProperty("jaxb.formatted.output", Boolean.TRUE);
Object mObj = obj;
Class<?> objectFactory = Class.forName(PackageUtils.getPackageName(typeClass) + ".ObjectFactory", true, obj.getClass().getClassLoader());
Method[] methods = objectFactory.getDeclaredMethods();
for (Method method : methods) {
if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(typeClass)) {
mObj = method.invoke(objectFactory.newInstance(), new Object[] { obj });
}
}
javax.xml.stream.XMLOutputFactory fact = javax.xml.stream.XMLOutputFactory.newInstance();
XMLStreamWriter writer = new PrettyPrintXMLStreamWriter(fact.createXMLStreamWriter(pw), 2, getIndentLevel(parent));
if (namespace != null && !namespace.equals(jaxbNamespace)) {
Map<String, String> outMap = new HashMap<>();
outMap.put("{" + jaxbNamespace + "}*", "{" + namespace + "}*");
writer = new OutTransformWriter(writer, outMap, Collections.<String, String>emptyMap(), Collections.<String>emptyList(), false, "");
}
Map<String, String> nspref = new HashMap<>();
for (Object ent : wsdl.getNamespaces().entrySet()) {
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) ent;
nspref.put((String) entry.getValue(), (String) entry.getKey());
}
JAXBUtils.setNamespaceMapper(nspref, u);
u.marshal(mObj, writer);
writer.flush();
} catch (Exception ex) {
throw new WSDLException(WSDLException.PARSER_ERROR, "", ex);
}
}
use of org.apache.cxf.staxutils.transform.OutTransformWriter in project cxf by apache.
the class MappingBeanDefinitionParser method transformElement.
private Element transformElement(Element element) {
W3CDOMStreamWriter domWriter = new W3CDOMStreamWriter();
OutTransformWriter transformWriter = new OutTransformWriter(domWriter, transformMap);
try {
StaxUtils.copy(element, transformWriter);
} catch (XMLStreamException e) {
throw new RuntimeException(e);
}
return domWriter.getDocument().getDocumentElement();
}
Aggregations