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:mx.bigdata.sat.cfdi.TFDv11c33.java

private Element marshalTFD() throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);/*from w  w  w . j av a  2 s .c o m*/
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    Marshaller m = CONTEXT.createMarshaller();
    m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(CFDv3.PREFIXES));
    m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://www.sat.gob.mx/TimbreFiscalDigital TimbreFiscalDigitalv11.xsd");
    m.marshal(tfd, doc);
    return doc.getDocumentElement();
}

From source file:mx.bigdata.cfdi.TFDv1.java

private Element marshalTFD() throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);// w  ww. ja v a2s . c o m
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    Marshaller m = CONTEXT.createMarshaller();
    m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl());
    m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://www.sat.gob.mx/TimbreFiscalDigital TimbreFiscalDigital.xsd");
    m.marshal(tfd, doc);
    return doc.getDocumentElement();
}

From source file:de.qucosa.dissemination.epicur.servlet.EpicurDisseminationServlet.java

@Override
public void init() {
    httpClient = HttpClientBuilder.create().setConnectionManager(new PoolingHttpClientConnectionManager())
            .build();/*www  . ja  va  2 s. c  om*/

    marshallerPool = new GenericObjectPool<>(new BasePooledObjectFactory<Marshaller>() {
        @Override
        public Marshaller create() throws Exception {
            Marshaller marshaller = JAXBContext.newInstance(Epicur.class).createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, XEPICUR_SCHEMA_LOCATION);
            return marshaller;
        }

        @Override
        public PooledObject<Marshaller> wrap(Marshaller marshaller) {
            return new DefaultPooledObject<>(marshaller);
        }
    });
}

From source file:hydrograph.ui.graph.debugconverter.DebugConverter.java

public void marshall(Debug debug, IFile outPutFile) throws JAXBException, IOException, CoreException {

    JAXBContext jaxbContext = JAXBContext.newInstance(Debug.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    marshaller.marshal(debug, out);//from  w  ww . j a  va 2s.c  o m

    if (outPutFile.exists())
        outPutFile.setContents(new ByteArrayInputStream(out.toByteArray()), true, false, null);
    else
        outPutFile.create(new ByteArrayInputStream(out.toByteArray()), true, null);
    out.close();
}

From source file:org.opennms.features.vaadin.pmatrix.manual.PmatrixDpdCalculatorSimpleMovingAverageImplMarshalTest.java

public void testMarshalData() {
    System.out.println("start of test:testMarshalData()");

    // check slf4j settings
    LOG.debug("debug message");
    LOG.warn("warn message");
    LOG.info("info message");

    try {/*from   w w w .j a va2  s . c  om*/
        String testFileName = this.getClass().getSimpleName() + "_File.xml";
        File file = new File("target/" + testFileName);
        PrintWriter writer = new PrintWriter(file, "UTF-8");
        writer.close();
        System.out.println("file location:" + file.getAbsolutePath());

        JAXBContext jaxbContext = JAXBContext.newInstance("org.opennms.features.vaadin.pmatrix.calculator");

        // *****************
        // create calculator
        // *****************
        PmatrixDpdCalculatorSimpleMovingAvgImpl simpleMovingAvgCalc = new PmatrixDpdCalculatorSimpleMovingAvgImpl();

        simpleMovingAvgCalc.setLatestDataValue(1010d);
        simpleMovingAvgCalc.setLatestTimestamp(new Date().getTime());
        simpleMovingAvgCalc.setPrevDataValue(3040d);
        simpleMovingAvgCalc.setPreviousTimestamp(new Date().getTime());

        NameValuePair property = new NameValuePair(
                PmatrixDpdCalculatorSimpleMovingAvgImpl.MAX_SAMPLE_NO_PROPERTY_NAME, "10");
        simpleMovingAvgCalc.getConfiguration().add(property);

        for (int i = 1; i < 15; i++) {
            Double latestDataValue = Double.valueOf(i);
            Long latestTimestamp = new Date().getTime() + i; // adding to show small increment in time
            simpleMovingAvgCalc.updateCalculation(latestDataValue, latestTimestamp);
        }

        // **********************
        // marshal test file
        // **********************

        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");

        // output pretty printed
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        jaxbMarshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
                "http://xmlns.opennms.org/xsd/config/pmatrix pmatrixConfig.xsd");

        jaxbMarshaller.marshal(simpleMovingAvgCalc, file);
        //jaxbMarshaller.marshal(pmatrixSpecificationList_context, file);

        // **********************
        // unmarshal test file
        // **********************

        Unmarshaller jaxbUnMarshaller = jaxbContext.createUnmarshaller();

        //Object o = jaxbUnMarshaller.unmarshal( new StringReader( marshalledXml )  );

        Object o = jaxbUnMarshaller.unmarshal(file);

        System.out.println("o.tostring:" + o.toString());
        if (o instanceof PmatrixDpdCalculatorSimpleMovingAvgImpl) {
            System.out.println("unmarshalled list:");
            System.out.println((PmatrixDpdCalculatorSimpleMovingAvgImpl) o);
        } else
            System.out.println("cant unmarshal object:");

    } catch (JAXBException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    System.out.println("end of test:testMarshalData()");

}

From source file:com.hp.octane.integrations.uft.items.UftTestDiscoveryResult.java

public void writeToFile(File fileToWriteTo) throws JAXBException {

    JAXBContext jaxbContext = JAXBContext.newInstance(UftTestDiscoveryResult.class);
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    jaxbMarshaller.marshal(this, fileToWriteTo);
}

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

public synchronized boolean saveAzsWhitelist(AzsWhitelist azss) {
    boolean success = false;
    if (azss == null) {
        log.error("azss (whitelist) is null ? [" + azss + "]");
        return success;
    }/*from  w w w  . j av  a  2s.  c  o m*/
    log.trace("Saving AZS Whitelist information to " + azsWhitelistPath + azsWhitelistFile);
    try {
        JAXBContext jc = JAXBContext.newInstance(AzsWhitelist.class);
        Marshaller m = jc.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(azss, new FileOutputStream(azsWhitelistPath + azsWhitelistFile));
        success = true;
    } catch (Exception e) {
        log.error(e);
    }

    return success;
}

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

public synchronized boolean saveIdpWhitelist(IdpWhitelist idps) {
    boolean success = false;
    if (idps == null) {
        log.error("idps (whitelist) is null ? [" + idps + "]");
        return success;
    }//from   w  w  w .j  a  v a  2  s  .  c  o  m
    log.trace("Saving IDP Whitelist information to " + idpWhitelistPath + idpWhitelistFile);
    try {
        JAXBContext jc = JAXBContext.newInstance(IdpWhitelist.class);
        Marshaller m = jc.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(idps, new FileOutputStream(idpWhitelistPath + idpWhitelistFile));
        success = true;
    } catch (Exception e) {
        log.error(e);
    }

    return success;
}

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

public synchronized boolean saveLasServers(LasServers servers) {
    boolean success = false;
    if (servers == null) {
        log.error("LasServers is [" + servers + "]");
        return success;
    }//from   w ww .j av  a 2 s . co  m
    log.trace("Saving LAS LasServers information to " + sistersPath + sistersFile);
    try {
        JAXBContext jc = JAXBContext.newInstance(LasServers.class);
        Marshaller m = jc.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(servers, new FileOutputStream(sistersPath + sistersFile));
        success = true;
    } catch (Exception e) {
        log.error(e);
    }

    return success;
}

From source file:com.floreantpos.model.PosPrinters.java

public void save() {
    try {//from   ww w  .  j ava  2s  . c  o m
        getDefaultKitchenPrinter();

        populatePrinterMaps();

        File file = new File("config", "printers.xml"); //$NON-NLS-1$ //$NON-NLS-2$

        JAXBContext jaxbContext = JAXBContext.newInstance(PosPrinters.class);
        Marshaller m = jaxbContext.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        StringWriter writer = new StringWriter();
        m.marshal(this, writer);

        FileUtils.write(file, writer.toString());

    } catch (Exception e) {
        PosLog.error(getClass(), e);
    }
}