use of org.kie.dmn.backend.marshalling.CustomStaxWriter in project drools by kiegroup.
the class XStreamMarshaller method marshal.
@Override
public String marshal(Object o) {
try (Writer writer = new StringWriter();
CustomStaxWriter hsWriter = (CustomStaxWriter) staxDriver.createWriter(writer)) {
XStream xStream = newXStream();
if (o instanceof DMNModelInstrumentedBase) {
DMNModelInstrumentedBase base = (DMNModelInstrumentedBase) o;
String dmnPrefix = base.getNsContext().entrySet().stream().filter(kv -> DMNModelInstrumentedBase.URI_DMN.equals(kv.getValue())).findFirst().map(Map.Entry::getKey).orElse("");
hsWriter.getQNameMap().setDefaultPrefix(dmnPrefix);
}
extensionRegisters.forEach(r -> r.beforeMarshal(o, hsWriter.getQNameMap()));
xStream.marshal(o, hsWriter);
hsWriter.flush();
return writer.toString();
} catch (Exception e) {
logger.error("Error marshalling DMN model to XML.", e);
}
return null;
}
use of org.kie.dmn.backend.marshalling.CustomStaxWriter in project drools by kiegroup.
the class QNameConverter method marshal.
@Override
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext context) {
QName qname = (QName) object;
if (!XMLConstants.NULL_NS_URI.equals(qname.getNamespaceURI()) && !XMLConstants.DEFAULT_NS_PREFIX.equals(qname.getPrefix())) {
CustomStaxWriter staxWriter = ((CustomStaxWriter) writer.underlyingWriter());
try {
staxWriter.writeNamespace(qname.getPrefix(), qname.getNamespaceURI());
} catch (XMLStreamException e) {
// TODO what to do?
e.printStackTrace();
}
}
writer.setValue(MarshallingUtils.formatQName(qname));
}
use of org.kie.dmn.backend.marshalling.CustomStaxWriter in project drools by kiegroup.
the class DMNModelInstrumentedBaseConverter method writeAttributes.
@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
DMNModelInstrumentedBase mib = (DMNModelInstrumentedBase) parent;
CustomStaxWriter staxWriter = ((CustomStaxWriter) writer.underlyingWriter());
for (Entry<String, String> kv : mib.getNsContext().entrySet()) {
try {
if (DMNModelInstrumentedBase.URI_DMN.equals(kv.getValue())) {
// skip as that is the default namespace xmlns<:prefix>=DMN is handled by the stax driver.
} else {
staxWriter.writeNamespace(kv.getKey(), kv.getValue());
}
} catch (Exception e) {
// TODO what to do?
e.printStackTrace();
}
}
for (Entry<QName, String> kv : mib.getAdditionalAttributes().entrySet()) {
staxWriter.addAttribute(kv.getKey().getPrefix() + ":" + kv.getKey().getLocalPart(), kv.getValue());
}
}
Aggregations