Example usage for javax.xml.bind Marshaller JAXB_FORMATTED_OUTPUT

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

Introduction

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

Prototype

String JAXB_FORMATTED_OUTPUT

To view the source code for javax.xml.bind Marshaller JAXB_FORMATTED_OUTPUT.

Click Source Link

Document

The name of the property used to specify whether or not the marshalled XML data is formatted with linefeeds and indentation.

Usage

From source file:com.cognifide.aet.rest.XUnitServlet.java

private Marshaller prepareJaxbMarshaller() throws JAXBException {
    JAXBContext jaxbContext = JAXBContext.newInstance(Testsuites.class);
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
    return jaxbMarshaller;
}

From source file:gov.nih.nci.coppa.services.client.ClientUtils.java

private static void printXml(Object obj) throws JAXBException {
    JAXBContext jaxbContext = MAP.get(obj.getClass().getPackage().getName());
    if (jaxbContext == null) {
        jaxbContext = JAXBContext.newInstance(obj.getClass().getPackage().getName());
        MAP.put(obj.getClass().getPackage().getName(), jaxbContext);
    }/*from www  .  j  a v a2 s .co  m*/
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.marshal(obj, System.out);
}

From source file:dk.statsbiblioteket.doms.licensemodule.integrationtest.LicenseModuleRestWSTester.java

@SuppressWarnings("all")
private static void testCheckAccessForIds() throws Exception {
    CheckAccessForIdsInputDTO input = new CheckAccessForIdsInputDTO();
    input.setPresentationType("Search");
    input.setAttributes(createUserObjAttributeDTO());
    ArrayList<String> ids = new ArrayList<String>();
    ids.add("doms_radioTVCollection:uuid:371157ee-b120-4504-bfaf-364c15a4137c");//radio TV        
    ids.add("doms_radioTVCollection:uuid:c3386ed5-9b79-47a2-a648-8de53569e630");//radio TV
    ids.add("doms_reklamefilm:uuid:35a1aa76-97a1-4f1b-b5aa-ad2a246eeeec"); //reklame
    ids.add("doms_newspaperCollection:uuid:18709dea-802c-4bd7-98e6-32ca3b285774-segment_6"); //aviser      
    input.setIds(ids);/*from w  w w.j a v  a  2s .c  o  m*/

    JAXBContext context = JAXBContext.newInstance(CheckAccessForIdsInputDTO.class);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    m.marshal(input, outputStream);

    // serialize to XML
    String inputXML = outputStream.toString();
    System.out.println(inputXML);
    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    WebResource service = client
            .resource(UriBuilder.fromUri("http://devel06:9612/licensemodule/services/").build());

    // Call with XML
    CheckAccessForIdsOutputDTO output = service.path("checkAccessForIds").type(MediaType.TEXT_XML)
            .accept(MediaType.TEXT_XML).entity(inputXML).post(CheckAccessForIdsOutputDTO.class);
    context = JAXBContext.newInstance(CheckAccessForIdsOutputDTO.class);
    outputStream = new ByteArrayOutputStream();
    m = context.createMarshaller();

    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    m.marshal(output, outputStream);

    // serialize to XML
    String outputXML = outputStream.toString();
    System.out.println(outputXML);

    System.out.println("query:" + output.getQuery());
    System.out.println("presentationtype:" + output.getPresentationType());
    System.out.println("number of IDs:" + output.getAccessIds().size());
}

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

public void guardar(OutputStream out) throws Exception {
    Marshaller m = CONTEXT.createMarshaller();
    m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(CFDv32.PREFIXES));
    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 "
            + CFDv32.getComplementosNameSpaceAndSchema()
            + "http://www.sat.gob.mx/TimbreFiscalDigital http://www.sat.gob.mx/sitio_internet/TimbreFiscalDigital/TimbreFiscalDigital.xsd ");
    byte[] xmlHeaderBytes = XML_HEADER.getBytes("UTF8");
    out.write(xmlHeaderBytes);/*from w ww .j a  v  a 2 s  .c  om*/
    m.marshal(document, out);
}

From source file:vitro.vgw.communication.idas.IdasProxyImpl.java

private Object sendRequest(Object request) throws VitroGatewayException {

    Object result = null;//  w  w w  . j  av  a2s  .  c o m

    InputStream instream = null;

    try {
        HttpPost httpPost = new HttpPost(endPoint);

        JAXBContext jaxbContext = Utils.getJAXBContext();

        Marshaller mar = jaxbContext.createMarshaller();
        mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        mar.marshal(request, baos);

        String requestXML = baos.toString(HTTP.UTF_8);

        StringEntity entityPar = new StringEntity(requestXML, "application/xml", HTTP.UTF_8);

        httpPost.setEntity(entityPar);

        HttpResponse response = httpclient.execute(httpPost);
        HttpEntity entity = response.getEntity();
        if (entity != null) {

            instream = entity.getContent();

            Unmarshaller unmarshaller = Utils.getJAXBContext().createUnmarshaller();
            Object idasResponse = unmarshaller.unmarshal(instream);

            if (idasResponse instanceof ExceptionReport) {
                throw Utils.parseException((ExceptionReport) idasResponse);
            }

            result = idasResponse;

        } else {
            throw new VitroGatewayException("Server response does not contain any body");
        }
    } catch (VitroGatewayException e) {
        throw e;
    } catch (Exception e) {
        throw new VitroGatewayException(e);
    } finally {
        if (instream != null) {
            try {
                instream.close();
            } catch (IOException e) {
                logger.error("Error while closing server response stream", e);
            }
        }
    }

    return result;

}

From source file:ee.ria.xroad.opmonitordaemon.QueryRequestHandler.java

static Marshaller createMarshaller(AttachmentMarshaller attachmentMarshaller) throws Exception {
    Marshaller marshaller = JAXB_CTX.createMarshaller();

    marshaller.setAttachmentMarshaller(attachmentMarshaller);
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);

    return marshaller;
}

From source file:hermes.impl.DefaultXMLHelper.java

public void saveContent(MessageSet messages, OutputStream ostream) throws Exception {
    JAXBContext jc = JAXBContext.newInstance("hermes.xml");
    Marshaller m = jc.createMarshaller();

    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.marshal(new JAXBElement<MessageSet>(new QName("", "content"), MessageSet.class, messages), ostream);
    ostream.flush();/*  w ww .  j a v  a 2s. com*/
}

From source file:de.thorstenberger.examServer.service.impl.ConfigManagerImpl.java

private void save() {
    try {/*from   w w w  .  j a va  2s. c  om*/

        final Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
        final BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(this.configFile));
        marshaller.marshal(config, bos);

        bos.close();

    } catch (final JAXBException e) {
        throw new RuntimeException(e);
    } catch (final IOException e1) {
        throw new RuntimeException(e1);
    }

}

From source file:fr.cls.atoll.motu.processor.iso19139.ServiceMetadata.java

/**
 * Inits the jaxb iso19139.//from w  w  w  . ja  v  a 2 s.  co m
 * 
 * @throws MotuException the motu exception
 */
private static void initJAXBIso19139() throws MotuException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("initJAXBIso19139() - entering");
    }
    if (ServiceMetadata.jaxbContextIso19139 != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("initJAXBIso19139() - exiting");
        }
        return;
    }

    try {
        ServiceMetadata.jaxbContextIso19139 = JAXBContext
                .newInstance(new Class[] { org.isotc211.iso19139.d_2006_05_04.gmd.ObjectFactory.class });

        ServiceMetadata.marshallerIso19139 = ServiceMetadata.jaxbContextIso19139.createMarshaller();
        ServiceMetadata.marshallerIso19139.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        ServiceMetadata.unmarshallerIso19139 = ServiceMetadata.jaxbContextIso19139.createUnmarshaller();

    } catch (JAXBException e) {
        LOG.error("initJAXBIso19139()", e);
        throw new MotuException("Error in ServiceMetadata - initJAXBIso19139 ", e);

    }

    // objectFactoryIso19139 = new ObjectFactory();

    if (LOG.isDebugEnabled()) {
        LOG.debug("initJAXBIso19139() - exiting");
    }
}

From source file:org.n52.youngs.harvest.PoxCswSource.java

private Marshaller getMarshaller() throws JAXBException {
    if (!marshaller.isPresent()) {
        marshaller = Optional.of(context.createMarshaller());
        marshaller.get().setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    }//from w  w w  .j a va2s.c  om
    return marshaller.get();
}