use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class RecordXmlTransformer method getXml.
protected String getXml(List parsedRecord) {
XmlBuilder record = new XmlBuilder(getRootTag());
int ndx = 0;
for (Iterator it = outputFields.iterator(); it.hasNext(); ) {
// get tagname
String tagName = (String) it.next();
// get value
String value = "";
if (ndx < parsedRecord.size()) {
value = (String) parsedRecord.get(ndx++);
if (!it.hasNext() && !StringUtils.isEmpty(endOfRecord)) {
if (value.endsWith(endOfRecord)) {
int ei = value.length() - endOfRecord.length();
value = value.substring(0, ei);
}
}
}
// if tagname is empty, then it is not added to the XML
if (!StringUtils.isEmpty(tagName)) {
XmlBuilder field = new XmlBuilder(tagName);
field.setValue(value, true);
record.addSubElement(field);
}
}
return record.toXML();
}
use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class ExchangeMailListener method getStringFromRawMessage.
public String getStringFromRawMessage(Object rawMessage, Map threadContext) throws ListenerException {
Item item = (Item) rawMessage;
try {
XmlBuilder emailXml = new XmlBuilder("email");
EmailMessage emailMessage;
PropertySet ps;
if (isSimple()) {
ps = new PropertySet(EmailMessageSchema.Subject);
emailMessage = EmailMessage.bind(exchangeService, item.getId(), ps);
addEmailInfoSimple(emailMessage, emailXml);
} else {
ps = new PropertySet(EmailMessageSchema.DateTimeReceived, EmailMessageSchema.From, EmailMessageSchema.Subject, EmailMessageSchema.Body, EmailMessageSchema.DateTimeSent);
emailMessage = EmailMessage.bind(exchangeService, item.getId(), ps);
addEmailInfo(emailMessage, emailXml);
}
if (StringUtils.isNotEmpty(getStoreEmailAsStreamInSessionKey())) {
emailMessage.load(new PropertySet(ItemSchema.MimeContent));
MimeContent mc = emailMessage.getMimeContent();
ByteArrayInputStream bis = new ByteArrayInputStream(mc.getContent());
threadContext.put(getStoreEmailAsStreamInSessionKey(), bis);
}
return emailXml.toXML();
} catch (Exception e) {
throw new ListenerException(e);
}
}
use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class ExchangeMailListener method addEmailInfo.
private void addEmailInfo(EmailMessage emailMessage, XmlBuilder emailXml) throws Exception {
XmlBuilder recipientsXml = new XmlBuilder("recipients");
EmailAddressCollection eacTo = emailMessage.getToRecipients();
if (eacTo != null) {
for (Iterator it = eacTo.iterator(); it.hasNext(); ) {
XmlBuilder recipientXml = new XmlBuilder("recipient");
EmailAddress ea = (EmailAddress) it.next();
recipientXml.addAttribute("type", "to");
recipientXml.setValue(ea.getAddress());
recipientsXml.addSubElement(recipientXml);
}
}
EmailAddressCollection eacCc = emailMessage.getCcRecipients();
if (eacCc != null) {
for (Iterator it = eacCc.iterator(); it.hasNext(); ) {
XmlBuilder recipientXml = new XmlBuilder("recipient");
EmailAddress ea = (EmailAddress) it.next();
recipientXml.addAttribute("type", "cc");
recipientXml.setValue(ea.getAddress());
recipientsXml.addSubElement(recipientXml);
}
}
EmailAddressCollection eacBcc = emailMessage.getBccRecipients();
if (eacBcc != null) {
for (Iterator it = eacBcc.iterator(); it.hasNext(); ) {
XmlBuilder recipientXml = new XmlBuilder("recipient");
EmailAddress ea = (EmailAddress) it.next();
recipientXml.addAttribute("type", "bcc");
recipientXml.setValue(ea.getAddress());
recipientsXml.addSubElement(recipientXml);
}
}
emailXml.addSubElement(recipientsXml);
XmlBuilder fromXml = new XmlBuilder("from");
fromXml.setValue(emailMessage.getFrom().getAddress());
emailXml.addSubElement(fromXml);
XmlBuilder subjectXml = new XmlBuilder("subject");
subjectXml.setCdataValue(emailMessage.getSubject());
emailXml.addSubElement(subjectXml);
XmlBuilder messageXml = new XmlBuilder("message");
messageXml.setCdataValue(MessageBody.getStringFromMessageBody(emailMessage.getBody()));
emailXml.addSubElement(messageXml);
XmlBuilder attachmentsXml = new XmlBuilder("attachments");
AttachmentCollection ac = emailMessage.getAttachments();
if (ac != null) {
for (Iterator it = ac.iterator(); it.hasNext(); ) {
XmlBuilder attachmentXml = new XmlBuilder("attachment");
Attachment att = (Attachment) it.next();
att.load();
attachmentXml.addAttribute("name", att.getName());
if (att instanceof ItemAttachment) {
ItemAttachment ia = (ItemAttachment) att;
Item aItem = ia.getItem();
if (aItem instanceof EmailMessage) {
EmailMessage em;
em = (EmailMessage) aItem;
addEmailInfo(em, attachmentXml);
}
}
attachmentsXml.addSubElement(attachmentXml);
}
}
emailXml.addSubElement(attachmentsXml);
XmlBuilder headersXml = new XmlBuilder("headers");
InternetMessageHeaderCollection imhc = null;
try {
imhc = emailMessage.getInternetMessageHeaders();
} catch (Exception e) {
log.info("error occurred during getting internet message headers: " + e.getMessage());
}
if (imhc != null) {
for (Iterator it = imhc.iterator(); it.hasNext(); ) {
XmlBuilder headerXml = new XmlBuilder("header");
InternetMessageHeader imh = (InternetMessageHeader) it.next();
headerXml.addAttribute("name", imh.getName());
headerXml.setCdataValue(imh.getValue());
headersXml.addSubElement(headerXml);
}
}
emailXml.addSubElement(headersXml);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Date dateTimeSend = emailMessage.getDateTimeSent();
XmlBuilder dateTimeSentXml = new XmlBuilder("dateTimeSent");
dateTimeSentXml.setValue(sdf.format(dateTimeSend));
emailXml.addSubElement(dateTimeSentXml);
Date dateTimeReceived = emailMessage.getDateTimeReceived();
XmlBuilder dateTimeReceivedXml = new XmlBuilder("dateTimeReceived");
dateTimeReceivedXml.setValue(sdf.format(dateTimeReceived));
emailXml.addSubElement(dateTimeReceivedXml);
}
use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class SchedulerAdapter method getSchedulerMetaDataToXml.
public XmlBuilder getSchedulerMetaDataToXml(Scheduler theScheduler) {
XmlBuilder xbRoot = new XmlBuilder("schedulerMetaData");
try {
SchedulerMetaData smd = theScheduler.getMetaData();
xbRoot.addAttribute("schedulerName", smd.getSchedulerName());
xbRoot.addAttribute("schedulerInstanceId", smd.getSchedulerInstanceId().toString());
xbRoot.addAttribute("version", smd.getVersion());
xbRoot.addAttribute("isPaused", (smd.isInStandbyMode() ? "True" : "False"));
xbRoot.addAttribute("isSchedulerRemote", (smd.isSchedulerRemote() ? "True" : "False"));
xbRoot.addAttribute("isShutdown", (smd.isShutdown() ? "True" : "False"));
xbRoot.addAttribute("isStarted", (smd.isStarted() ? "True" : "False"));
xbRoot.addAttribute("jobStoreSupportsPersistence", (smd.jobStoreSupportsPersistence() ? "True" : "False"));
xbRoot.addAttribute("numJobsExecuted", Integer.toString(smd.getNumberOfJobsExecuted()));
try {
Date runningSince = smd.getRunningSince();
xbRoot.addAttribute("runningSince", (null == runningSince ? "unknown" : DateUtils.format(runningSince, DateUtils.FORMAT_GENERICDATETIME)));
} catch (Exception e) {
log.debug(e);
}
;
xbRoot.addAttribute("jobStoreClass", smd.getJobStoreClass().getName());
xbRoot.addAttribute("schedulerClass", smd.getSchedulerClass().getName());
xbRoot.addAttribute("threadPoolClass", smd.getThreadPoolClass().getName());
xbRoot.addAttribute("threadPoolSize", Integer.toString(smd.getThreadPoolSize()));
} catch (SchedulerException se) {
log.error(se);
}
return xbRoot;
}
use of nl.nn.adapterframework.util.XmlBuilder in project iaf by ibissource.
the class SchedulerAdapter method getJobMessages.
public XmlBuilder getJobMessages(JobDef jobdef) {
XmlBuilder jobMessages = new XmlBuilder("jobMessages");
if (jobdef != null) {
MessageKeeper jobMessageKeeper = jobdef.getMessageKeeper();
if (jobMessageKeeper != null) {
for (int t = 0; t < jobMessageKeeper.size(); t++) {
XmlBuilder jobMessage = new XmlBuilder("jobMessage");
jobMessage.setValue(jobMessageKeeper.getMessage(t).getMessageText(), true);
jobMessage.addAttribute("date", DateUtils.format(jobMessageKeeper.getMessage(t).getMessageDate(), DateUtils.FORMAT_FULL_GENERIC));
jobMessage.addAttribute("level", jobMessageKeeper.getMessage(t).getMessageLevel());
jobMessages.addSubElement(jobMessage);
}
}
}
return jobMessages;
}
Aggregations