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);
}
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);
}
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());
}
}
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;
}
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());
}
}
Aggregations