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:net.ageto.gyrex.impex.persistence.cassandra.storage.CassandraRepositoryImpl.java

/**
 * Persist process configuration./*from   w w  w . jav  a  2  s. co m*/
 * 
 * @param process
 */
public void insertOrUpdateProcess(IProcessConfig process) {

    JAXBContext context;
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    try {
        context = JAXBContext.newInstance(ProcessConfig.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        // process / process step configuration xml formatted
        m.marshal(process, outputStream);

    } catch (JAXBException e) {
        throw new IllegalArgumentException(e.getMessage());
    }

    Mutator<String> mutator = HFactory.createMutator(getImpexKeyspace(), StringSerializer.get());
    // insert process configuration
    mutator.insert(process.getId(), columnFamilyProcesses,
            HFactory.createStringColumn(columnNameProcess, outputStream.toString()));
}

From source file:de.xirp.profile.ProfileGenerator.java

/**
 * Generates a BOT file with the given path from the given 
 * {@link de.xirp.profile.CommunicationSpecification comm-spec} 
 * bean./*from w  ww  . j a v a 2s. com*/
 * 
 * @param commSpec
 *          The comm-spec to generate the XML for. 
 * @param cmsFile
 *          The file to write the result to. Must be the full path.
 * 
 * @throws JAXBException if the given comm-spec was null, or something 
 *                    went wrong generating the xml.
 * @throws FileNotFoundException if something went wrong generating the xml.
 */
public static void generateCMS(CommunicationSpecification commSpec, File cmsFile)
        throws JAXBException, FileNotFoundException {

    if (commSpec == null) {
        throw new JAXBException(I18n.getString("ProfileGenerator.exception.comSpecNull")); //$NON-NLS-1$
    }

    String fileName = FilenameUtils.getBaseName(cmsFile.getName());

    JAXBContext jc = JAXBContext.newInstance(CommunicationSpecification.class);
    Marshaller m = jc.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.marshal(commSpec, new FileOutputStream(
            Constants.CONF_COMMSPECS_DIR + File.separator + fileName + Constants.COMM_SPEC_POSTFIX));
}

From source file:dk.dma.epd.common.prototype.communication.webservice.ShoreHttp.java

public void setXmlMarshalContent(String contextPath, Object obj)
        throws JAXBException, UnsupportedEncodingException {
    JAXBContext jc = JAXBContext.newInstance(contextPath);
    Marshaller m = jc.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_ENCODING, ENCODING);
    StringWriter sw = new StringWriter();
    m.marshal(obj, sw);//w  ww .ja v  a2s. c om
    String req = sw.toString();
    LOG.debug("XML request: " + req);
    setRequestBody(sw.toString().getBytes(ENCODING), ENCODING);
}

From source file:de.iteratec.iteraplan.businesslogic.service.SavedQueryXmlHelper.java

private static Marshaller getMarshaller(Class<?> clazz, String schemaName) throws JAXBException, SAXException {
    JAXBContext context = JAXBContext.newInstance(clazz);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.setSchema(getSchema(schemaName));//from www .  j  a  va 2  s  .c  o  m
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, SCHEMA_URI + " " + SCHEMA_URI + schemaName);

    return m;
}

From source file:org.javelin.sws.ext.bind.jaxb.JaxbTest.java

@Test(expected = IllegalAnnotationsException.class)
public void marshalMixed() throws Exception {
    JAXBContext ctx = JAXBContext.newInstance(org.javelin.sws.ext.bind.jaxb.context4.MyClassJ4.class);
    Marshaller m = ctx.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

    org.javelin.sws.ext.bind.jaxb.context4.MyClassJ4 mc4 = new org.javelin.sws.ext.bind.jaxb.context4.MyClassJ4();
    m.marshal(new JAXBElement<org.javelin.sws.ext.bind.jaxb.context4.MyClassJ4>(new QName("a", "a"),
            org.javelin.sws.ext.bind.jaxb.context4.MyClassJ4.class, mc4), System.out);
}

From source file:cool.pandora.modeller.DocManifestBuilder.java

/**
 * marshal./*w  w  w  .  j a v  a 2s  .  c  o m*/
 *
 * @param hocr File
 * @return hocr
 * @throws JAXBException Exception
 */
private static ByteArrayOutputStream marshal(final File hocr) throws JAXBException {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final JAXBContext jaxbContext = JAXBContext.newInstance(File.class);
    final Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    jaxbMarshaller.marshal(hocr, out);
    return out;
}

From source file:mx.bigdata.sat.cfdi.TFDv11c33.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/cfdv33.xsd");
    m.marshal(document.getComprobante(), out);
}

From source file:com.jaspersoft.jasperserver.jaxrs.client.apiadapters.jobs.BatchJobsOperationsAdapter.java

private String buildXml(ReportJobModel reportJobModel) {
    try {//w  w  w. ja  va2 s.  c  o  m
        StringWriter writer = new StringWriter();
        JAXBContext jaxbContext = JAXBContext.newInstance(ReportJobModel.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        jaxbMarshaller.marshal(reportJobModel, writer);
        return writer.toString();
    } catch (JAXBException e) {
        log.warn("Can't marshal report job model.");
        throw new RuntimeException("Failed inFolder build report job model xml.", e);
    }
}

From source file:at.ac.tuwien.dsg.comot.orchestrator.interraction.rsybl.rSYBLInterraction.java

public void sendInitialConfigToRSYBL(CloudService serviceTemplate, DeploymentDescription deploymentDescription,
        CompositionRulesConfiguration compositionRulesConfiguration, String effectsJSON) {

    deploymentDescription = enrichWithElasticityCapabilities(deploymentDescription, serviceTemplate);

    HttpHost endpoint = new HttpHost(rSYBL_BASE_IP, rSYBL_BASE_PORT);

    {//from   w  w w.j  a v  a 2  s.c  o m
        DefaultHttpClient httpClient = new DefaultHttpClient();
        URI prepareConfigURI = UriBuilder
                .fromPath(rSYBL_BASE_URL + "/" + serviceTemplate.getId() + "/prepareControl").build();
        HttpPut prepareConfig = new HttpPut(prepareConfigURI);

        try {
            HttpResponse httpResponse = httpClient.execute(endpoint, prepareConfig);
            EntityUtils.consume(httpResponse.getEntity());

        } catch (IOException ex) {
            log.error(ex.getMessage(), ex);
        }
    }
    {
        DefaultHttpClient httpClient = new DefaultHttpClient();

        try {

            JAXBContext jAXBContext = JAXBContext.newInstance(DeploymentDescription.class);
            Marshaller marshaller = jAXBContext.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

            StringWriter sw = new StringWriter();

            log.info("Sending deployment description to rSYBL");
            marshaller.marshal(deploymentDescription, sw);
            log.info(sw.toString());

            URI putDeploymentStructureURL = UriBuilder
                    .fromPath(rSYBL_BASE_URL + "/" + serviceTemplate.getId() + "/deployment").build();
            HttpPut putDeployment = new HttpPut(putDeploymentStructureURL);

            StringEntity entity = new StringEntity(sw.getBuffer().toString());

            entity.setContentType("application/xml");
            entity.setChunked(true);

            putDeployment.setEntity(entity);

            log.info("Executing request " + putDeployment.getRequestLine());
            HttpResponse response = httpClient.execute(endpoint, putDeployment);
            HttpEntity resEntity = response.getEntity();

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            if (response.getStatusLine().getStatusCode() == 200) {

            }
            if (resEntity != null) {
                System.out.println("Response content length: " + resEntity.getContentLength());
                System.out.println("Chunked?: " + resEntity.isChunked());
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

    }

    {
        DefaultHttpClient httpClient = new DefaultHttpClient();

        try {

            JAXBContext jAXBContext = JAXBContext.newInstance(CloudServiceXML.class);
            CloudServiceXML cloudServiceXML = toRSYBLRepresentation(serviceTemplate);
            Marshaller marshaller = jAXBContext.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            StringWriter sw = new StringWriter();
            log.info("Sending service description description to rSYBL");
            marshaller.marshal(cloudServiceXML, sw);
            log.info(sw.toString());

            URI putDeploymentStructureURL = UriBuilder
                    .fromPath(rSYBL_BASE_URL + "/" + serviceTemplate.getId() + "/description").build();
            HttpPut putDeployment = new HttpPut(putDeploymentStructureURL);

            StringEntity entity = new StringEntity(sw.getBuffer().toString());

            entity.setContentType("application/xml");
            entity.setChunked(true);

            putDeployment.setEntity(entity);

            log.info("Executing request " + putDeployment.getRequestLine());
            HttpResponse response = httpClient.execute(endpoint, putDeployment);
            HttpEntity resEntity = response.getEntity();

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            if (response.getStatusLine().getStatusCode() == 200) {

            }
            if (resEntity != null) {
                System.out.println("Response content length: " + resEntity.getContentLength());
                System.out.println("Chunked?: " + resEntity.isChunked());
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

    }

    {
        DefaultHttpClient httpClient = new DefaultHttpClient();

        try {

            JAXBContext jAXBContext = JAXBContext.newInstance(CompositionRulesConfiguration.class);
            Marshaller marshaller = jAXBContext.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

            StringWriter sw = new StringWriter();
            log.info("Sending  updated composition rules");
            marshaller.marshal(compositionRulesConfiguration, sw);
            log.info(sw.toString());

            URI putDeploymentStructureURL = UriBuilder
                    .fromPath(rSYBL_BASE_URL + "/" + serviceTemplate.getId() + "/compositionRules").build();
            HttpPut putDeployment = new HttpPut(putDeploymentStructureURL);

            StringEntity entity = new StringEntity(sw.getBuffer().toString());

            entity.setContentType("application/xml");
            entity.setChunked(true);

            putDeployment.setEntity(entity);

            log.info("Executing request " + putDeployment.getRequestLine());
            HttpResponse response = httpClient.execute(endpoint, putDeployment);
            HttpEntity resEntity = response.getEntity();

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            if (response.getStatusLine().getStatusCode() == 200) {

            }
            if (resEntity != null) {
                System.out.println("Response content length: " + resEntity.getContentLength());
                System.out.println("Chunked?: " + resEntity.isChunked());
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

    }

    {
        DefaultHttpClient httpClient = new DefaultHttpClient();

        try {

            URI putDeploymentStructureURL = UriBuilder
                    .fromPath(rSYBL_BASE_URL + "/" + serviceTemplate.getId() + "/elasticityCapabilitiesEffects")
                    .build();
            HttpPut putDeployment = new HttpPut(putDeploymentStructureURL);

            String jsonEffectsDescription = capabilitiesToJSON(serviceTemplate);

            StringEntity entity = new StringEntity(jsonEffectsDescription);

            entity.setContentType("application/json");
            entity.setChunked(true);

            putDeployment.setEntity(entity);

            log.info("Send updated Effects");
            log.info(effectsJSON);

            HttpResponse response = httpClient.execute(endpoint, putDeployment);

            HttpEntity resEntity = response.getEntity();

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            if (response.getStatusLine().getStatusCode() == 200) {

            }
            if (resEntity != null) {
                System.out.println("Response content length: " + resEntity.getContentLength());
                System.out.println("Chunked?: " + resEntity.isChunked());
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

    }

    {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        URI prepareConfigURI = UriBuilder
                .fromPath(rSYBL_BASE_URL + "/" + serviceTemplate.getId() + "/startControl").build();
        HttpPut prepareConfig = new HttpPut(prepareConfigURI);

        try {
            HttpResponse httpResponse = httpClient.execute(endpoint, prepareConfig);
            EntityUtils.consume(httpResponse.getEntity());

        } catch (IOException ex) {
            log.error(ex.getMessage(), ex);
        }
    }

}

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;//w ww. j av a 2 s . com
    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);
    }
}