use of nl.nn.adapterframework.xml.SaxElementBuilder in project iaf by ibissource.
the class MailFileSystemTestBase method testExtractNormalMessageSimple.
// @Test
// public void testForward() throws Exception {
// M emailMessage = getFirstFileFromFolder(null);
// fileSystem.forwardMail(emailMessage, "xxx&yyy.nl");
// }
@Test
public void testExtractNormalMessageSimple() throws Exception {
M emailMessage = getFirstFileFromFolder(null);
SaxElementBuilder xml = new SaxElementBuilder("email");
MailFileSystemUtils.addEmailInfoSimple(fileSystem, emailMessage, xml);
xml.close();
String expected = TestFileUtils.getTestFile("/ExchangeMailNormalSimple.xml");
MatchUtils.assertXmlEquals(expected, xml.toString());
}
use of nl.nn.adapterframework.xml.SaxElementBuilder in project iaf by ibissource.
the class MailFileSystemTestBase method testExtractMessageWithProblematicAddress.
@Test
public void testExtractMessageWithProblematicAddress() throws Exception {
M emailMessage = getFirstFileFromFolder("FromAddressProblem");
SaxElementBuilder xml = new SaxElementBuilder("email");
fileSystem.extractEmail(emailMessage, xml);
xml.close();
String expected = TestFileUtils.getTestFile("/ExchangeMailFromAddressProblem.xml");
MatchUtils.assertXmlEquals(expected, xml.toString());
}
use of nl.nn.adapterframework.xml.SaxElementBuilder in project iaf by ibissource.
the class CsvParserPipe method doPipe.
@Override
public PipeRunResult doPipe(Message message, PipeLineSession session) throws PipeRunException {
try (MessageOutputStream target = getTargetStream(session)) {
try (Reader reader = message.asReader()) {
try (SaxDocumentBuilder document = new SaxDocumentBuilder("csv", target.asContentHandler())) {
CSVParser csvParser = format.parse(reader);
for (CSVRecord record : csvParser) {
try (SaxElementBuilder element = document.startElement("record")) {
for (Entry<String, String> entry : record.toMap().entrySet()) {
String key = entry.getKey();
if (getHeaderCase() != null) {
key = getHeaderCase() == HeaderCase.LOWERCASE ? key.toLowerCase() : key.toUpperCase();
}
element.addElement(key, entry.getValue());
}
} catch (SAXException e) {
throw new PipeRunException(this, "Exception caught at line [" + record.getRecordNumber() + "] pos [" + record.getCharacterPosition() + "]", e);
}
}
}
}
return target.getPipeRunResult();
} catch (Exception e) {
if (e instanceof PipeRunException) {
throw (PipeRunException) e;
}
throw new PipeRunException(this, "Cannot parse CSV", e);
}
}
use of nl.nn.adapterframework.xml.SaxElementBuilder in project iaf by ibissource.
the class DB2XMLWriter method getXML.
public void getXML(IDbmsSupport dbmsSupport, ResultSet rs, int maxlength, boolean includeFieldDefinition, ContentHandler handler) throws SAXException {
try (SaxDocumentBuilder root = new SaxDocumentBuilder(docname, handler)) {
if (null == rs) {
return;
}
if (maxlength < 0) {
maxlength = Integer.MAX_VALUE;
}
Statement stmt = null;
try {
stmt = rs.getStatement();
if (stmt != null) {
JdbcUtil.warningsToXml(stmt.getWarnings(), root);
}
} catch (SQLException e1) {
log.warn("exception obtaining statement warnings", e1);
}
int rowCounter = 0;
try {
ResultSetMetaData rsmeta = rs.getMetaData();
if (includeFieldDefinition) {
int nfields = rsmeta.getColumnCount();
try (SaxElementBuilder fields = root.startElement("fielddefinition")) {
for (int j = 1; j <= nfields; j++) {
try (SaxElementBuilder field = fields.startElement("field")) {
String columnName = "" + rsmeta.getColumnName(j);
if (convertFieldnamesToUppercase)
columnName = columnName.toUpperCase();
field.addAttribute("name", columnName);
// Not every JDBC implementation implements these attributes!
try {
field.addAttribute("type", "" + getFieldType(rsmeta.getColumnType(j)));
} catch (SQLException e) {
log.debug("Could not determine columnType", e);
}
try {
field.addAttribute("columnDisplaySize", "" + rsmeta.getColumnDisplaySize(j));
} catch (SQLException e) {
log.debug("Could not determine columnDisplaySize", e);
}
try {
field.addAttribute("precision", "" + rsmeta.getPrecision(j));
} catch (SQLException e) {
log.warn("Could not determine precision", e);
} catch (NumberFormatException e2) {
if (log.isDebugEnabled())
log.debug("Could not determine precision: " + e2.getMessage());
}
try {
field.addAttribute("scale", "" + rsmeta.getScale(j));
} catch (SQLException e) {
log.debug("Could not determine scale", e);
}
try {
field.addAttribute("isCurrency", "" + rsmeta.isCurrency(j));
} catch (SQLException e) {
log.debug("Could not determine isCurrency", e);
}
try {
String columnTypeName = "" + rsmeta.getColumnTypeName(j);
if (convertFieldnamesToUppercase)
columnTypeName = columnTypeName.toUpperCase();
field.addAttribute("columnTypeName", columnTypeName);
} catch (SQLException e) {
log.debug("Could not determine columnTypeName", e);
}
try {
field.addAttribute("columnClassName", "" + rsmeta.getColumnClassName(j));
} catch (SQLException e) {
log.debug("Could not determine columnClassName", e);
}
}
}
}
}
try (SaxElementBuilder queryresult = root.startElement(recordname)) {
while (rs.next() && rowCounter < maxlength) {
getRowXml(queryresult, dbmsSupport, rs, rowCounter, rsmeta, getBlobCharset(), decompressBlobs, nullValue, trimSpaces, getBlobSmart);
rowCounter++;
}
}
} catch (Exception e) {
log.error("Error occured at row [" + rowCounter + "]", e);
}
}
}
use of nl.nn.adapterframework.xml.SaxElementBuilder in project iaf by ibissource.
the class JdbcUtilTest method testWarningsToXml.
@Test
public void testWarningsToXml() throws SAXException {
String expected = getExpectedWarningXml();
XmlWriter writer = new XmlWriter();
PrettyPrintFilter ppf = new PrettyPrintFilter(writer);
try (SaxElementBuilder seb = new SaxElementBuilder(ppf)) {
JdbcUtil.warningsToXml(getWarnings(), seb);
MatchUtils.assertXmlEquals(expected, writer.toString());
}
}
Aggregations