try {
document = new XMLReader().parse(xml);
} catch (Exception e) {
throw new MalformedFormDataException("Form data was malformed: " + xml);
}
Node formData = document.getRootNode();
String id = null;
try {
id = formData.getAttribute("id");
} catch (IllegalArgumentException e) {
id = "undefined";
}
Map<String, String> formDataMap = new HashMap<String, String>();
if (formData.hasChildNodes("data")) {
for (Node node : formData.getNode("data")) {
if (node.hasContents()) {
formDataMap.put(node.getName(), node.getContents());
}
}
}
FormData form = new FormData(id, systemId).setData(formDataMap);
if (formData.hasAttribute("returned-empty")) {
String attrValue = formData.getAttribute("returned-empty");
if (attrValue.equalsIgnoreCase("yes")) {
form.setReturnedEmpty(true);
}
}
if (document.getRootNode().hasChildNodes("log")) {
for (Node node : document.getRootNode().getNode("log")) {
String user = node.getAttribute("owner");
Double time = Double.valueOf(node.getAttribute("time"));
String action = node.getContents();
form.addLogEntry(new FormData.LogEntry(user, time, action));
}
}
if (formData.hasChildNodes("message")) {
for (Node node : document.getRootNode().getChildNodes("message")) {
String contents = node.getContents().trim();
if (contents.length() > 0) {
form.addMessage(node.getContents());
}
}
}
List<String> owners = new ArrayList<String>();
if (formData.hasChildNodes("owners")) {
for (Node owner : formData.getNode("owners")) {
owners.add(owner.getContents());
}
form.setOwners(owners);
}