Search in sources :

Example 1 with DataBindingException

use of javax.xml.bind.DataBindingException in project pmd-eclipse-plugin by pmd.

the class ProjectPropertiesManagerImpl method convertProjectPropertiesFromString.

public ProjectPropertiesTO convertProjectPropertiesFromString(String properties) {
    try {
        Source source = new StreamSource(new StringReader(properties));
        JAXBElement<ProjectPropertiesTO> element = JAXB_CONTEXT.createUnmarshaller().unmarshal(source, ProjectPropertiesTO.class);
        return element.getValue();
    } catch (JAXBException e) {
        throw new DataBindingException(e);
    }
}
Also used : StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(javax.xml.bind.JAXBException) StringReader(java.io.StringReader) DataBindingException(javax.xml.bind.DataBindingException) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Example 2 with DataBindingException

use of javax.xml.bind.DataBindingException in project pmd-eclipse-plugin by pmd.

the class ProjectPropertiesManagerImpl method convertProjectPropertiesToString.

public String convertProjectPropertiesToString(ProjectPropertiesTO projectProperties) {
    try {
        Marshaller marshaller = JAXB_CONTEXT.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        StringWriter writer = new StringWriter();
        writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        marshaller.marshal(projectProperties, writer);
        writer.write("\n");
        return writer.toString();
    } catch (JAXBException e) {
        throw new DataBindingException(e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBException(javax.xml.bind.JAXBException) DataBindingException(javax.xml.bind.DataBindingException)

Aggregations

DataBindingException (javax.xml.bind.DataBindingException)2 JAXBException (javax.xml.bind.JAXBException)2 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Marshaller (javax.xml.bind.Marshaller)1 Source (javax.xml.transform.Source)1 StreamSource (javax.xml.transform.stream.StreamSource)1