use of com.adaptris.util.XmlUtils in project interlok by adaptris.
the class XmlPayloadTranslator method toDocument.
private DocumentWrapper toDocument(JdbcResult rs, AdaptrisMessage msg) throws Exception {
XmlUtils xu = createXmlUtils(msg);
DocumentWrapper wrapper = createWrapper(msg);
Document doc = wrapper.document;
ColumnStyle elementNameStyle = getColumnNameStyle();
Element results = doc.createElement(elementNameStyle.format(ELEMENT_NAME_RESULTS));
doc.appendChild(results);
if (isPreserveOriginalMessage()) {
Element originalMessage = doc.createElement(elementNameStyle.format(ORIGINAL_MESSAGE_ELEMENT));
if (xu.isDocumentValid()) {
Node n = xu.getSingleNode("/").getFirstChild();
originalMessage.appendChild(doc.importNode(n, true));
} else {
// Not XML, so let's add it in as a CDATA node.
originalMessage.appendChild(createTextNode(doc, msg.getContent(), true));
wrapper.hasCDATA = true;
}
results.appendChild(originalMessage);
}
for (JdbcResultSet rSet : rs.getResultSets()) {
List<Element> elements = createListFromResultSet(wrapper, rSet);
for (Element element : elements) {
results.appendChild(element);
}
wrapper.resultSetCount += elements.size();
}
return wrapper;
}
use of com.adaptris.util.XmlUtils in project interlok by adaptris.
the class XmlPayloadTranslatorImpl method createXmlUtils.
protected static XmlUtils createXmlUtils(AdaptrisMessage msg) {
XmlUtils xu = null;
try {
NamespaceContext ctx = (NamespaceContext) msg.getObjectHeaders().get(JdbcDataQueryService.KEY_NAMESPACE_CTX);
DocumentBuilderFactoryBuilder builder = (DocumentBuilderFactoryBuilder) msg.getObjectHeaders().get(JdbcDataQueryService.KEY_DOCBUILDER_FAC);
xu = XmlHelper.createXmlUtils(msg, ctx, builder);
} catch (CoreException e) {
xu = new XmlUtils();
}
return xu;
}
use of com.adaptris.util.XmlUtils in project interlok by adaptris.
the class InsertNode method merge.
@Override
public Document merge(Document original, Document newDoc) throws Exception {
if (StringUtils.isEmpty(getXpathToParentNode())) {
throw new Exception("No parent node configured");
}
Document resultDoc = original;
XmlUtils xml = create(resultDoc);
Node parent = resolve(xml, getXpathToParentNode());
if (parent.getOwnerDocument() == null) {
throw new Exception("Invalid xpath-to-parent-node [" + getXpathToParentNode() + "]");
}
xml.appendNode(newDoc.getDocumentElement(), parent);
return resultDoc;
}
use of com.adaptris.util.XmlUtils in project interlok by adaptris.
the class XpathMergeImpl method create.
protected XmlUtils create(Document doc) throws Exception {
DocumentBuilderFactoryBuilder builder = documentFactoryBuilder();
XmlUtils xml = new XmlUtils(builder.getEntityResolver(), SimpleNamespaceContext.create(getNamespaceContext()), builder.build());
xml.setSource(doc);
return xml;
}
use of com.adaptris.util.XmlUtils in project interlok by adaptris.
the class ExceptionReportServiceTest method testReplaceNode.
@Test
public void testReplaceNode() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg.addObjectHeader(CoreConstants.OBJ_METADATA_EXCEPTION, new Exception("This is the exception"));
ExceptionReportService service = new ExceptionReportService(new ExceptionAsXml().withExceptionGenerator(new SimpleExceptionReport()).withDocumentMerge(new ReplaceNode(XPATH_ORIGINAL_NODE)).withDocumentFactoryConfig(DocumentBuilderFactoryBuilder.newInstance()));
execute(service, msg);
assertNotSame(XML_PAYLOAD, msg.getContent());
XmlUtils xml = XmlHelper.createXmlUtils(msg);
assertNotSame(RAW_DATA, xml.getSingleNode(XPATH_ORIGINAL_NODE));
assertEquals("UTF-8", msg.getContentEncoding());
}
Aggregations