Search in sources :

Example 1 with MappingException

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());
    }
}
Also used : RulesPostImportContainer(org.akaza.openclinica.domain.rule.RulesPostImportContainer) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) XMLContext(org.exolab.castor.xml.XMLContext) FileNotFoundException(java.io.FileNotFoundException) Mapping(org.exolab.castor.mapping.Mapping) FileReader(java.io.FileReader) IOException(java.io.IOException) Unmarshaller(org.exolab.castor.xml.Unmarshaller) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) MappingException(org.exolab.castor.mapping.MappingException)

Example 2 with MappingException

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());
    }
}
Also used : Marshaller(org.exolab.castor.xml.Marshaller) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) StringWriter(java.io.StringWriter) XMLContext(org.exolab.castor.xml.XMLContext) FileNotFoundException(java.io.FileNotFoundException) Mapping(org.exolab.castor.mapping.Mapping) IOException(java.io.IOException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) FileNotFoundException(java.io.FileNotFoundException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) MappingException(org.exolab.castor.mapping.MappingException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) IOException(java.io.IOException) MappingException(org.exolab.castor.mapping.MappingException)

Example 3 with MappingException

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());
    }
}
Also used : Marshaller(org.exolab.castor.xml.Marshaller) MarshalException(org.exolab.castor.xml.MarshalException) ValidationException(org.exolab.castor.xml.ValidationException) XMLContext(org.exolab.castor.xml.XMLContext) FileNotFoundException(java.io.FileNotFoundException) Mapping(org.exolab.castor.mapping.Mapping) IOException(java.io.IOException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) MappingException(org.exolab.castor.mapping.MappingException) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) MappingException(org.exolab.castor.mapping.MappingException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)3 Mapping (org.exolab.castor.mapping.Mapping)3 MappingException (org.exolab.castor.mapping.MappingException)3 MarshalException (org.exolab.castor.xml.MarshalException)3 ValidationException (org.exolab.castor.xml.ValidationException)3 XMLContext (org.exolab.castor.xml.XMLContext)3 Marshaller (org.exolab.castor.xml.Marshaller)2 FileReader (java.io.FileReader)1 StringWriter (java.io.StringWriter)1 RulesPostImportContainer (org.akaza.openclinica.domain.rule.RulesPostImportContainer)1 InsufficientPermissionException (org.akaza.openclinica.web.InsufficientPermissionException)1 Unmarshaller (org.exolab.castor.xml.Unmarshaller)1