use of org.exolab.castor.xml.MarshalException 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.xml.MarshalException 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