use of org.exolab.castor.mapping.MappingException in project OpenClinica by OpenClinica.
the class ImportRuleServlet method handleLoadCastor.
private RulesPostImportContainer handleLoadCastor(File xmlFile) {
RulesPostImportContainer ruleImport = null;
try {
// create an XMLContext instance
XMLContext xmlContext = new XMLContext();
// create and set a Mapping instance
Mapping mapping = xmlContext.createMapping();
// mapping.loadMapping(SpringServletAccess.getPropertiesDir(context) + "mapping.xml");
mapping.loadMapping(getCoreResources().getURL("mapping.xml"));
xmlContext.addMapping(mapping);
// create a new Unmarshaller
Unmarshaller unmarshaller = xmlContext.createUnmarshaller();
unmarshaller.setWhitespacePreserve(false);
unmarshaller.setClass(RulesPostImportContainer.class);
// Create a Reader to the file to unmarshal from
FileReader reader = new FileReader(xmlFile);
ruleImport = (RulesPostImportContainer) unmarshaller.unmarshal(reader);
ruleImport.initializeRuleDef();
logRuleImport(ruleImport);
return ruleImport;
} catch (FileNotFoundException ex) {
throw new OpenClinicaSystemException(ex.getMessage(), ex.getCause());
} catch (IOException ex) {
throw new OpenClinicaSystemException(ex.getMessage(), ex.getCause());
} catch (MarshalException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
} catch (ValidationException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
} catch (MappingException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
}
}
use of org.exolab.castor.mapping.MappingException in project OpenClinica by OpenClinica.
the class MetaDataReportBean method handleLoadCastor.
private String handleLoadCastor(RulesPostImportContainer rpic) {
try {
// Create Mapping
Mapping mapping = new Mapping();
mapping.loadMapping(getCoreResources().getURL("mappingMarshallerMetadata.xml"));
// Create XMLContext
XMLContext xmlContext = new XMLContext();
xmlContext.setProperty(XMLConfiguration.NAMESPACES, "true");
xmlContext.addMapping(mapping);
StringWriter writer = new StringWriter();
Marshaller marshaller = xmlContext.createMarshaller();
// marshaller.setNamespaceMapping("castor", "http://castor.org/sample/mapping/");
marshaller.setWriter(writer);
marshaller.marshal(rpic);
String result = writer.toString();
String newResult = result.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
return newResult;
} catch (FileNotFoundException ex) {
throw new OpenClinicaSystemException(ex.getMessage(), ex.getCause());
} catch (IOException ex) {
throw new OpenClinicaSystemException(ex.getMessage(), ex.getCause());
} catch (MarshalException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
} catch (ValidationException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
} catch (MappingException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
} catch (Exception e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
}
}
use of org.exolab.castor.mapping.MappingException in project OpenClinica by OpenClinica.
the class DownloadRuleSetXmlServlet method handleLoadCastor.
private FileWriter handleLoadCastor(FileWriter writer, RulesPostImportContainer rpic) {
try {
// Create Mapping
Mapping mapping = new Mapping();
mapping.loadMapping(getCoreResources().getURL("mappingMarshaller.xml"));
// Create XMLContext
XMLContext xmlContext = new XMLContext();
xmlContext.addMapping(mapping);
Marshaller marshaller = xmlContext.createMarshaller();
marshaller.setWriter(writer);
marshaller.marshal(rpic);
return writer;
} catch (FileNotFoundException ex) {
throw new OpenClinicaSystemException(ex.getMessage(), ex.getCause());
} catch (IOException ex) {
throw new OpenClinicaSystemException(ex.getMessage(), ex.getCause());
} catch (MarshalException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
} catch (ValidationException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
} catch (MappingException e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
} catch (Exception e) {
throw new OpenClinicaSystemException(e.getMessage(), e.getCause());
}
}
Aggregations