Example usage for javax.xml.bind Marshaller setProperty

List of usage examples for javax.xml.bind Marshaller setProperty

Introduction

In this page you can find the example usage for javax.xml.bind Marshaller setProperty.

Prototype

public void setProperty(String name, Object value) throws PropertyException;

Source Link

Document

Set the particular property in the underlying implementation of Marshaller .

Usage

From source file:com.mgmtp.perfload.loadprofiles.ui.ctrl.ConfigController.java

public void saveActiveSettings() {
    checkState(activeSettingsFile != null, "No active settings file set.");

    Writer wr = null;/*from  ww  w.  j  av  a  2s . co  m*/
    File file = new File(settingsDir, activeSettingsFile);
    file.getParentFile().mkdir();

    try {
        wr = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
        JAXBContext context = JAXBContext.newInstance(Settings.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        m.marshal(getActiveSettings(), wr);
    } catch (JAXBException ex) {
        String msg = "Error marshalling contents to file: " + file;
        throw new LoadProfileException(msg, ex);
    } catch (IOException ex) {
        throw new LoadProfileException(ex.getMessage(), ex);
    } finally {
        Closeables.closeQuietly(wr);
    }
}

From source file:esg.node.components.registry.ShardsListGleaner.java

public synchronized boolean saveShardsList(Shards shardlist) {
    boolean success = false;
    if (shardlist == null) {
        log.error("shardlist is null ? [" + shardlist + "]");
        return success;
    }/*from   w ww  .j  av  a 2  s.c  o m*/
    log.trace("Saving SHARDS list information to " + shardsListPath + shardsListFile);
    try {
        JAXBContext jc = JAXBContext.newInstance(Shards.class);
        Marshaller m = jc.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(shardlist, new FileOutputStream(shardsListPath + shardsListFile));
        success = true;
    } catch (Exception e) {
        log.error(e);
    }

    return success;
}

From source file:mx.bigdata.sat.cfdi.CFDv3.java

public void guardar(OutputStream out) throws Exception {
    Marshaller m = context.createMarshaller();
    m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(localPrefixes));
    m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://www.sat.gob.mx/cfd/3  " + "http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv3.xsd");
    byte[] xmlHeaderBytes = XML_HEADER.getBytes("UTF8");
    out.write(xmlHeaderBytes);//from  w w w.j  ava2  s . c  o  m
    m.marshal(document, out);
}

From source file:mx.bigdata.sat.cfdi.CFDv32.java

public void guardar(OutputStream out) throws Exception {
    Marshaller m = context.createMarshaller();
    m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(localPrefixes));
    m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://www.sat.gob.mx/cfd/3  " + "http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv32.xsd");
    byte[] xmlHeaderBytes = XML_HEADER.getBytes("UTF8");
    out.write(xmlHeaderBytes);/* w  w  w . ja v  a 2 s . c  om*/
    m.marshal(document, out);
}

From source file:ejava.projects.edmv.bl.DataGen.java

public void generate(Writer writer) throws JAXBException, DatatypeConfigurationException {
    dtf = DatatypeFactory.newInstance();
    JAXBContext jaxbc = JAXBContext.newInstance(Dmv.class);
    Marshaller m = jaxbc.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    Dmv dmvDoc = new Dmv();
    dmvDoc.setPeople(new PersonsType());
    dmvDoc.setVehicleRegistrations(new VehicleRegistrationsType());

    //get all people
    int index = 0;
    List<DMVPerson> people;
    do {/*from   w  w w .  j a  v  a  2  s.  c  om*/
        people = personDAO.getPeople(index, 10);
        for (DMVPerson p : people) {
            dmvDoc.getPeople().getPerson().add(createXMLPerson(p));
        }
        index += people.size();
    } while (people.size() > 0);
    log.debug("found " + index + " total people");

    //get all vehicle registrations
    index = 0;
    List<DMVVehicleRegistration> vRegs;
    do {
        vRegs = vehicleDAO.getRegistrations(index, 10);
        for (DMVVehicleRegistration vReg : vRegs) {
            dmvDoc.getVehicleRegistrations().getVehicleRegistration()
                    .add(createXMLRegistration(vReg, dmvDoc.getPeople()));
        }
        index += vRegs.size();
    } while (vRegs.size() > 0);
    log.debug("found " + index + " total registrations");

    m.marshal(dmvDoc, writer);
}

From source file:edu.htwm.vsp.phoebook.rest.client.RestClient.java

/**
 * Example code for serializing a PhoneUser via JAXB.
 *///from  w  w w .j  a v a 2  s.c  o  m
public void marshalPhoneUserToXML(PhoneUser user, Writer out) throws JAXBException {

    JAXBContext jc = JAXBContext.newInstance(PhoneUser.class);
    assertNotNull(jc);
    Marshaller marshaller = jc.createMarshaller();

    assertNotNull(marshaller);

    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
    marshaller.marshal(user, out);
}

From source file:eu.impress.repository.service.BedAvailabilityServiceImpl.java

@Override
public String getBedAvailablityHAVE(String hospitalname) {

    String hospitalstatushave;/*from ww w  .ja va 2s .  com*/
    BedStats bedStats = bedService.getHospitalAvailableBeds(hospitalname);
    HospitalStatus hospitalStatus = beansTransformation.BedStatstoHAVE(bedStats);

    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(HospitalStatus.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

        //jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        StringWriter sw = new StringWriter();
        //marshal the envelope 
        jaxbMarshaller.marshal(hospitalStatus, sw);
        hospitalstatushave = sw.toString();

    } catch (JAXBException e) {
        e.printStackTrace();
        return "Error Marshalling XML Object";
    }

    return hospitalstatushave;

}

From source file:esg.node.components.registry.AtsWhitelistGleaner.java

public synchronized boolean saveAtsWhitelist(AtsWhitelist atss) {
    boolean success = false;
    if (atss == null) {
        log.error("atss (whitelist) is null ? [" + atss + "]");
        return success;
    }//from   w ww .j  a  va2s .  co m
    log.trace("Saving ATS Whitelist information to " + atsWhitelistPath + atsWhitelistFile);
    try {
        JAXBContext jc = JAXBContext.newInstance(AtsWhitelist.class);
        Marshaller m = jc.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(atss, new FileOutputStream(atsWhitelistPath + atsWhitelistFile));
        success = true;
    } catch (Exception e) {
        log.error(e);
    }

    return success;
}

From source file:com.uttesh.pdfngreport.handler.PdfReportHandler.java

/**
 * This method generate the XML data file required by the apache fo to
 * generate the PDF report. XML data file is generated by using the java
 * JAXB./*from   w  w w.j a va2 s. c  o m*/
 *
 * @param reportData
 * @return UUID which is used as the file name.
 *
 * {@link com.uttesh.pdfngreport.util.xml.ReportData#member ReportData}
 * @see JAXBException
 */
public int generateXmlData(ReportData reportData) {
    JAXBContext jc;
    int fileName = UUID.randomUUID().toString().substring(0, 3).hashCode();
    File file = null;
    try {
        jc = JAXBContext.newInstance(ReportData.class);
        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        if (reportData.getOsName().equalsIgnoreCase("w")) {
            file = new File(reportLocation + Constants.BACKWARD_SLASH + fileName + Constants.XML_EXTENSION);
        } else {
            file = new File(reportLocation + Constants.FORWARD_SLASH + fileName + Constants.XML_EXTENSION);
        }
        marshaller.marshal(reportData, file);
    } catch (JAXBException ex) {
        Logger.getLogger(PdfReportHandler.class.getName()).log(Level.SEVERE, null, ex);
        //new File(reportLocation + Constants.FORWARD_SLASH + fileName + Constants.XML_EXTENSION).delete();
    }
    return fileName;
}

From source file:eu.impress.repository.service.BedAvailabilityServiceImpl.java

@Override
public String createBedAvailabilityDE() throws DatatypeConfigurationException {

    String DEmessageenvelope = "";
    String DEmessage = "";

    EDXLDistribution ed = EDXLlib.createEDXLEnvelope();

    try {//from w  ww .  ja  va 2s .  com
        JAXBContext jaxbContext = JAXBContext.newInstance(EDXLDistribution.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

        //jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        StringWriter sw = new StringWriter();
        //marshal the envelope 
        jaxbMarshaller.marshal(ed, sw);
        DEmessageenvelope = sw.toString();

        //could not unescape characters no matter what!
        //encapsulate the edxl have message into DE by avoiding jaxb 
        //DEmessage = EDXLlib.DEEncapsulation(DEmessageenvelope, edxlhave);
        DEmessage = DEmessageenvelope;

    } catch (JAXBException e) {
        e.printStackTrace();
        return "Error Marshalling XML Object";
    }

    return DEmessage;

}