if (validationNode != null && validationNode.getNodeType() == Node.ELEMENT_NODE
&& validationNode.getNodeName().equals(FORM_VALIDATESET_ELEMENT)) {
Properties props = XMLUtils.createPropertiesForXML(false);
props.put(OutputKeys.ENCODING, "ISO-8859-1");
String validationXML = XMLUtils.serializeNode(validationNode, props);
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
conf = builder.build(new ByteArrayInputStream(validationXML.getBytes()));
session.setAttribute(this.formName + "constraint-set", conf);
}
}
} catch (SourceException se) {
throw new ProcessingException("Cannot resolve" + source, se);
} catch (ConfigurationException ce) {
throw new ProcessingException("Error building Configuration out of constraint-set element", ce);
}
} else if (validationDoc != null) {
//validationDoc contains the validation rules inline
try {
validationDoc.normalize();
Node validationNode = validationDoc.getFirstChild();
while (validationNode.getNodeType() != Node.ELEMENT_NODE) {
validationNode = validationNode.getNextSibling();
if (validationNode == null) {
break;
}
}
if (validationNode != null && validationNode.getNodeType() == Node.ELEMENT_NODE
&& validationNode.getNodeName().equals("root")) {
Properties props = XMLUtils.createPropertiesForXML(false);
props.put(OutputKeys.ENCODING, "ISO-8859-1");
String validationXML = XMLUtils.serializeNode(validationNode, props);
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
Configuration conf = builder.build(new ByteArrayInputStream(validationXML.getBytes()));
Session session = this.getSessionManager().getSession(true);
session.setAttribute(this.formName, conf);
//the constraint-set to validate is the first and single one
session.setAttribute(this.formName + "constraint-set", conf.getChildren("constraint-set")[0]);