use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.
the class XmlSchemaValidationHelper method validateAgainstSchema.
public void validateAgainstSchema(String xml, File xsdFile) {
try {
// parse an XML document into a DOM tree
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(true);
DocumentBuilder parser = builderFactory.newDocumentBuilder();
Document document = parser.parse(xml);
// create a SchemaFactory capable of understanding WXS schemas
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// load a WXS schema, represented by a Schema instance
Source schemaFile = new StreamSource(xsdFile);
Schema schema = factory.newSchema(schemaFile);
// create a Validator instance, which can be used to validate an
// instance document
Validator validator = schema.newValidator();
// validate the DOM tree
validator.validate(new DOMSource(document));
} catch (FileNotFoundException ex) {
throw new OpenClinicaSystemException("File was not found", ex.getCause());
} catch (IOException ioe) {
throw new OpenClinicaSystemException("IO Exception", ioe.getCause());
} catch (SAXParseException spe) {
//spe.printStackTrace();
throw new OpenClinicaSystemException("Line : " + spe.getLineNumber() + " - " + spe.getMessage(), spe.getCause());
} catch (SAXException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
} catch (ParserConfigurationException pce) {
throw new OpenClinicaSystemException(pce.getMessage(), pce.getCause());
}
}
use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.
the class XmlSchemaValidationHelper method validateAgainstSchema.
public void validateAgainstSchema(String xml, InputStream xsdFile) {
try {
// parse an XML document into a DOM tree
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(true);
DocumentBuilder parser = builderFactory.newDocumentBuilder();
Document document = parser.parse(new InputSource(new StringReader(xml)));
// create a SchemaFactory capable of understanding WXS schemas
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// load a WXS schema, represented by a Schema instance
Source schemaFile = new StreamSource(xsdFile);
Schema schema = factory.newSchema(schemaFile);
// create a Validator instance, which can be used to validate an
// instance document
Validator validator = schema.newValidator();
// validate the DOM tree
validator.validate(new DOMSource(document));
} catch (FileNotFoundException ex) {
throw new OpenClinicaSystemException("File was not found", ex.getCause());
} catch (IOException ioe) {
// ioe.printStackTrace();
throw new OpenClinicaSystemException("IO Exception", ioe.getCause());
} catch (SAXParseException spe) {
// spe.printStackTrace();
throw new OpenClinicaSystemException("Line : " + spe.getLineNumber() + " - " + spe.getMessage(), spe.getCause());
} catch (SAXException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
} catch (ParserConfigurationException pce) {
throw new OpenClinicaSystemException(pce.getMessage(), pce.getCause());
}
}
use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.
the class XmlSchemaValidationHelper method validateAgainstSchema.
public void validateAgainstSchema(File xmlFile, File xsdFile) {
try {
// parse an XML document into a DOM tree
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(true);
DocumentBuilder parser = builderFactory.newDocumentBuilder();
Document document = parser.parse(xmlFile);
// create a SchemaFactory capable of understanding WXS schemas
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// load a WXS schema, represented by a Schema instance
Source schemaFile = new StreamSource(xsdFile);
Schema schema = factory.newSchema(schemaFile);
// create a Validator instance, which can be used to validate an
// instance document
Validator validator = schema.newValidator();
// validate the DOM tree
validator.validate(new DOMSource(document));
} catch (FileNotFoundException ex) {
throw new OpenClinicaSystemException("File was not found", ex.getCause());
} catch (IOException ioe) {
throw new OpenClinicaSystemException("IO Exception", ioe.getCause());
} catch (SAXParseException spe) {
//spe.printStackTrace();
throw new OpenClinicaSystemException("Line : " + spe.getLineNumber() + " - " + spe.getMessage(), spe.getCause());
} catch (SAXException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
} catch (ParserConfigurationException pce) {
throw new OpenClinicaSystemException(pce.getMessage(), pce.getCause());
}
}
use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.
the class EmailHandler method convertUponSet.
/**
* This method is used to convert the value when the setValue method is called. The setValue method will call this method to obtain the converted value. The converted value will then be used as
* the value to set for the field.
*
* @param value
* the object value to convert before performing a set operation
* @return the converted value.
*/
@Override
public Object convertUponSet(Object value) {
Boolean areEmailsValid = true;
String[] emails = ((String) value).split(",");
for (String str : emails) {
if (str.trim().startsWith("$") && !str.trim().equals("${participant}")) {
throw new OpenClinicaSystemException("The \"" + value + " \" you provided is not Valid, Please provide valid comma separated addresses.");
} else if (!str.trim().startsWith("$")) {
areEmailsValid = EmailValidator.getInstance().isValid(str.trim());
if (!areEmailsValid) {
throw new OpenClinicaSystemException("Email Address : \"" + str.trim() + " \" you provided is not Valid, Please provide valid comma separated addresses.");
}
}
}
return value;
}
use of org.akaza.openclinica.exception.OpenClinicaSystemException in project OpenClinica by OpenClinica.
the class ImportRuleServlet method processRequest.
@Override
public void processRequest() throws Exception {
String action = request.getParameter("action");
request.setAttribute("contextPath", getContextPath());
request.setAttribute("hostPath", getHostPath());
copyFiles();
if (StringUtil.isBlank(action)) {
forwardPage(Page.IMPORT_RULES);
}
if ("downloadrulesxsd".equalsIgnoreCase(action)) {
// File xsdFile = new File(SpringServletAccess.getPropertiesDir(context) + "rules.xsd");
File xsdFile = getCoreResources().getFile("rules.xsd", "rules" + File.separator);
dowloadFile(xsdFile, "text/xml");
}
if ("downloadtemplate".equalsIgnoreCase(action)) {
// File file = new File(SpringServletAccess.getPropertiesDir(context) + "rules_template.xml");
File file = getCoreResources().getFile("rules_template.xml", "rules" + File.separator);
dowloadFile(file, "text/xml");
}
if ("downloadtemplateWithNotes".equalsIgnoreCase(action)) {
// File file = new File(SpringServletAccess.getPropertiesDir(context) + "rules_template_with_notes.xml");
File file = getCoreResources().getFile("rules_template_with_notes.xml", "rules" + File.separator);
dowloadFile(file, "text/xml");
}
if ("confirm".equalsIgnoreCase(action)) {
try {
File f = uploadHelper.returnFiles(request, context, getDirToSaveUploadedFileIn()).get(0);
// File xsdFile = new File(getServletContext().getInitParameter("propertiesDir") + "rules.xsd");
// File xsdFile = new File(SpringServletAccess.getPropertiesDir(context) + "rules.xsd");
InputStream xsdFile = getCoreResources().getInputStream("rules.xsd");
schemaValidator.validateAgainstSchema(f, xsdFile);
RulesPostImportContainer importedRules = handleLoadCastor(f);
logger.info(ub.getFirstName());
importedRules = getRulesPostImportContainerService().validateRuleDefs(importedRules);
importedRules = getRulesPostImportContainerService().validateRuleSetDefs(importedRules);
session.setAttribute("importedData", importedRules);
provideMessage(importedRules);
forwardPage(Page.VERIFY_RULES_IMPORT_SERVLET);
} catch (OpenClinicaSystemException re) {
// re.printStackTrace();
MessageFormat mf = new MessageFormat("");
mf.applyPattern(re.getErrorCode() == null ? respage.getString("OCRERR_0016") : respage.getString(re.getErrorCode()));
Object[] arguments = { re.getMessage() };
if (re.getErrorCode() != null) {
arguments = re.getErrorParams();
}
addPageMessage(mf.format(arguments));
forwardPage(Page.IMPORT_RULES);
}
}
}
Aggregations