String name = inv.getString("name");
String script = inv.getString("script");
String template = inv.getString("template");
if (!inv.isValid()) {
throw new UserException();
}
script = script.replace("\r", "").replace("\t", " ");
template = template.length() == 0 ? null : template.replace("\r",
"").replace("\t", " ");
Document doc = MonadUtils.newSourceDocument();
Element source = doc.getDocumentElement();
Element scriptElement = doc.createElement("script");
source.appendChild(scriptElement);
scriptElement.setTextContent(script);
source.setAttribute("script", script);
if (template != null) {
Element templateElement = doc.createElement("template");
source.appendChild(templateElement);
templateElement.setTextContent(template);
}
if (!inv.isValid()) {
Element reportElement = toXml(doc);
source.appendChild(reportElement);
throw new UserException(doc);
}
try {
update(name, script, template);
} catch (UserException e) {
e.setDocument(doc);