throw new RuntimeException(e);
}
}
protected NamespaceHelper buildXml() throws ParserConfigurationException {
NamespaceHelper helper = new NamespaceHelper(Notifier.NAMESPACE, "", "inbox");
InboxMessage[] messages = getMessages();
for (int i = 0; i < messages.length; i++) {
Message message = messages[i].getMessage();
Element messageElement = helper.createElement("message");
helper.getDocument().getDocumentElement().appendChild(messageElement);
User sender = (User) message.getSender();
messageElement.setAttribute("sender", sender.getId());
Element recipientsElement = helper.createElement("recipients");
messageElement.appendChild(recipientsElement);
Identifiable[] recipients = message.getRecipients();
for (int r = 0; r < recipients.length; r++) {
if (recipients[r] instanceof User) {
Element userElement = helper.createElement("user");
userElement.setAttribute("id", ((User) recipients[r]).getId());
recipientsElement.appendChild(userElement);
} else if (recipients[r] instanceof Group) {
Element groupElement = helper.createElement("group");
groupElement.setAttribute("id", ((Group) recipients[r]).getId());
recipientsElement.appendChild(groupElement);
}
}
Element subjectElement = helper.createElement("subject");
messageElement.appendChild(subjectElement);
Element subjectTextElement = helper.createElement("text", message.getSubject());
subjectElement.appendChild(subjectTextElement);
String[] subjectParams = message.getSubjectParameters();
for (int p = 0; p < subjectParams.length; p++) {
Element paramElement = helper.createElement("param", subjectParams[p]);
subjectElement.appendChild(paramElement);
}
Element bodyElement = helper.createElement("body");
messageElement.appendChild(bodyElement);
Element bodyTextElement = helper.createElement("text", message.getBody());
bodyElement.appendChild(bodyTextElement);
String[] bodyParams = message.getBodyParameters();
for (int p = 0; p < bodyParams.length; p++) {
Element paramElement = helper.createElement("param", bodyParams[p]);
bodyElement.appendChild(paramElement);
}
messageElement.setAttribute("read", Boolean.toString(messages[i].isMarkedAsRead()));
messageElement.setAttribute("id", messages[i].getId());