Search in sources :

Example 11 with Marshaller

use of org.exolab.castor.xml.Marshaller in project spring-framework by spring-projects.

the class CastorMarshaller method marshalSaxHandlers.

@Override
protected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler) throws XmlMappingException {
    Marshaller marshaller = xmlContext.createMarshaller();
    marshaller.setContentHandler(contentHandler);
    doMarshal(graph, marshaller);
}
Also used : AbstractMarshaller(org.springframework.oxm.support.AbstractMarshaller) Marshaller(org.exolab.castor.xml.Marshaller)

Example 12 with Marshaller

use of org.exolab.castor.xml.Marshaller in project spring-framework by spring-projects.

the class CastorMarshaller method marshalWriter.

@Override
protected void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException {
    Marshaller marshaller = xmlContext.createMarshaller();
    marshaller.setWriter(writer);
    doMarshal(graph, marshaller);
}
Also used : AbstractMarshaller(org.springframework.oxm.support.AbstractMarshaller) Marshaller(org.exolab.castor.xml.Marshaller)

Example 13 with Marshaller

use of org.exolab.castor.xml.Marshaller 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 14 with Marshaller

use of org.exolab.castor.xml.Marshaller in project OpenClinica by OpenClinica.

the class XformParser method marshall.

/*
     * public XformParser() throws Exception { try { xmlContext = new XMLContext(); Mapping mapping =
     * xmlContext.createMapping(); mapping.loadMapping(coreResources.getURL("openRosaXFormMapping.xml"));
     * xmlContext.addMapping(mapping); } catch (Exception e) { log.error(e.getMessage());
     * log.error(ExceptionUtils.getStackTrace(e)); throw new Exception(e); } }
     */
public String marshall(Html html) throws Exception {
    StringWriter writer = new StringWriter();
    xmlContext = new XMLContext();
    Mapping mapping = xmlContext.createMapping();
    mapping.loadMapping(coreResources.getURL("openRosaXFormMapping.xml"));
    xmlContext.addMapping(mapping);
    Marshaller marshaller = xmlContext.createMarshaller();
    marshaller.setNamespaceMapping("h", "http://www.w3.org/1999/xhtml");
    marshaller.setNamespaceMapping("jr", "http://openrosa.org/javarosa");
    marshaller.setNamespaceMapping("xsd", "http://www.w3.org/2001/XMLSchema");
    marshaller.setNamespaceMapping("ev", "http://www.w3.org/2001/xml-events");
    marshaller.setNamespaceMapping("", "http://www.w3.org/2002/xforms");
    marshaller.setWriter(writer);
    marshaller.marshal(html);
    String xform = writer.toString();
    return xform;
}
Also used : Marshaller(org.exolab.castor.xml.Marshaller) StringWriter(java.io.StringWriter) XMLContext(org.exolab.castor.xml.XMLContext) Mapping(org.exolab.castor.mapping.Mapping)

Example 15 with Marshaller

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

Marshaller (org.exolab.castor.xml.Marshaller)23 StringWriter (java.io.StringWriter)13 IOException (java.io.IOException)10 MarshalException (org.exolab.castor.xml.MarshalException)7 ValidationException (org.exolab.castor.xml.ValidationException)7 Mapping (org.exolab.castor.mapping.Mapping)5 XMLContext (org.exolab.castor.xml.XMLContext)5 LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)4 File (java.io.File)4 FileWriter (java.io.FileWriter)3 MalformedURLException (java.net.MalformedURLException)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 FaultFamily (alma.acs.alarmsystem.generated.FaultFamily)2 CDBRecordDoesNotExistEx (alma.cdbErrType.CDBRecordDoesNotExistEx)2 BufferedWriter (java.io.BufferedWriter)2 FileNotFoundException (java.io.FileNotFoundException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 Vector (java.util.Vector)2