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.retroduction.carma.eventlisteners.ReportEventListener.java

public void destroy() {

    this.log.info("Finishing XML report");

    this.runProcessingEnd = System.currentTimeMillis();

    new StatisticalReportAnalyzer().enhanceReport(this.run);

    try {//from w ww.j a  va  2  s.  c o  m
        if (this.writeTimingInfo) {
            ProcessingInfo info = this.createTimingInformation(this.runProcessingStart, this.runProcessingEnd);
            this.run.setProcessingInfo(info);
        }
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }

    try {
        JAXBContext context = JAXBContext.newInstance(MutationRun.class);
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(this.run, new FileOutputStream(new File(this.outputFile)));
    } catch (JAXBException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

}

From source file:de.intevation.test.irixservice.UploadReportTest.java

@Test(expected = UploadReportException.class)
public void testInvalidDokpool() throws UploadReportException, JAXBException {
    ReportType report = getReportFromFile(VALID_REPORT);
    DokpoolMeta meta = new DokpoolMeta();
    meta.setDokpoolContentType("Invalid doc");
    DOMResult res = new DOMResult();
    Element ele = null;/*  w  w w  .  ja  v a 2  s  .c o m*/
    JAXBContext jaxbContext = JAXBContext.newInstance(DokpoolMeta.class);
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
    jaxbMarshaller.marshal(meta, res);
    ele = ((Document) res.getNode()).getDocumentElement();

    report.getAnnexes().getAnnotation().get(0).getAny().add(ele);
    testObj.uploadReport(report);
}

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

private String buildXml(ReportJobModel reportJobModel) {
    try {//from w  w w  .ja  va 2  s .co  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:eu.learnpad.core.impl.cw.XwikiBridgeInterfaceRestResource.java

@Override
public void notifyScoreUpdate(ScoreRecord record) throws LpRestException {
    String contentType = "application/xml";
    HttpClient httpClient = this.getClient();
    String uri = String.format("%s/learnpad/cw/bridge/scores", DefaultRestResource.REST_URI);
    PostMethod postMethod = new PostMethod(uri);
    postMethod.addRequestHeader(HttpHeaders.CONTENT_TYPE, contentType);

    try {/*w w w .  j a  va  2  s.c o  m*/
        JAXBContext jc = JAXBContext.newInstance(ScoreRecord.class);
        Writer marshalledRecord = new StringWriter();

        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(record, marshalledRecord);

        postMethod.setRequestEntity(new StringRequestEntity(marshalledRecord.toString(), contentType, "UTF-8"));

        httpClient.executeMethod(postMethod);
    } catch (JAXBException e1) {
        e1.printStackTrace();
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

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 w w .j  av a 2  s.c  o m*/
    m.marshal(document, out);
}

From source file:com.manydesigns.mail.queue.FileSystemMailQueue.java

public String enqueue(Email email) throws QueueException {
    try {//from  ww w .  j a  v a  2  s  .  c o  m
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        String emailId = RandomUtil.createRandomId(20);
        File destinationFile = getEmailFile(emailId);
        checkDirectory(queuedDirectory);
        if (!email.getAttachments().isEmpty()) {
            File attachDir = getEmailAttachmentsDirectory(emailId);
            checkDirectory(attachDir);
            for (Attachment attachment : email.getAttachments()) {
                String attachmentId = RandomUtil.createRandomId(20);
                File attachmentFile = new File(attachDir, attachmentId + ".bin");
                FileOutputStream fos = new FileOutputStream(attachmentFile);
                IOUtils.copy(attachment.getInputStream(), fos);
                IOUtils.closeQuietly(fos);
                IOUtils.closeQuietly(attachment.getInputStream());
                attachment.setFilePath(attachmentFile.getAbsolutePath());
            }
        }
        marshaller.marshal(email, destinationFile);
        return emailId;
    } catch (Exception e) {
        throw new QueueException("Couldn't enqueue mail", e);
    }
}

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

private Element marshalTFD() throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);// w  w w.  j  a  v 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(CFDv32.PREFIXES));
    m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://www.sat.gob.mx/TimbreFiscalDigital http://www.sat.gob.mx/sitio_internet/TimbreFiscalDigital/TimbreFiscalDigital.xsd");
    m.marshal(tfd, doc);
    return doc.getDocumentElement();
}

From source file:net.sf.taverna.t2.maven.plugins.TavernaProfileGenerateMojo.java

/**
 * Generates the application profile file.
 *
 * @return the <code>File</code> that the application profile has been written to
 * @throws JAXBException//from ww  w .  j av a2  s . c o m
 *             if the application profile cannot be created
 * @throws MojoExecutionException
 */
private File createApplicationProfile() throws JAXBException, MojoExecutionException {
    String groupId = project.getGroupId();
    String artifactId = project.getArtifactId();
    String version = maven2OsgiConverter.getVersion(project.getVersion());
    if (version.endsWith("SNAPSHOT")) {
        version = version.substring(0, version.indexOf("SNAPSHOT")) + buildNumber;
    }

    tempDirectory.mkdirs();
    File applicationProfileFile = new File(tempDirectory, APPLICATION_PROFILE_FILE);

    ApplicationProfile applicationProfile = new ApplicationProfile();
    applicationProfile.setId(groupId + "." + artifactId);
    applicationProfile.setName(project.getName());
    applicationProfile.setVersion(version);

    Updates updates = new Updates();
    updates.setUpdateSite(updateSite);
    updates.setUpdatesFile(updatesFile);
    updates.setLibDirectory(libDirectory);
    updates.setPluginSite(pluginSite);
    updates.setPluginsFile(pluginsFile);
    applicationProfile.setUpdates(updates);

    List<FrameworkConfiguration> frameworkConfiguration = applicationProfile.getFrameworkConfiguration();
    for (FrameworkConfiguration configuration : frameworkConfigurations) {
        frameworkConfiguration.add(configuration);
    }

    Set<BundleArtifact> bundleDependencies = osgiUtils.getBundleDependencies(Artifact.SCOPE_COMPILE,
            Artifact.SCOPE_RUNTIME);
    List<BundleInfo> runtimeBundles = osgiUtils.getBundles(bundleDependencies);
    if (!runtimeBundles.isEmpty()) {
        List<BundleInfo> bundles = applicationProfile.getBundle();
        for (BundleInfo bundle : runtimeBundles) {
            bundles.add(bundle);
        }
    }

    JAXBContext jaxbContext = JAXBContext.newInstance(ApplicationProfile.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, SCHEMA_LOCATION);
    marshaller.marshal(applicationProfile, applicationProfileFile);

    return applicationProfileFile;
}

From source file:mx.bigdata.sat.cfd.CFDv2.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/2 " + "http://www.sat.gob.mx/sitio_internet/cfd/2/cfdv2.xsd");
    byte[] xmlHeaderBytes = XML_HEADER.getBytes("UTF8");
    out.write(xmlHeaderBytes);/*from w  w w.  ja va 2  s.c o  m*/
    m.marshal(document, out);
}

From source file:eu.learnpad.core.impl.cw.XwikiBridgeInterfaceRestResource.java

@Override
public void notifyRecommendations(String modelSetId, String simulationid, String userId, Recommendations rec)
        throws LpRestException {
    String contentType = "application/xml";

    HttpClient httpClient = this.getClient();
    String uri = String.format("%s/learnpad/cw/bridge/notify/%s", DefaultRestResource.REST_URI, modelSetId);

    PutMethod putMethod = new PutMethod(uri);
    putMethod.addRequestHeader("Accept", contentType);

    NameValuePair[] queryString = new NameValuePair[2];
    queryString[0] = new NameValuePair("simulationid", simulationid);
    queryString[1] = new NameValuePair("userid", userId);
    putMethod.setQueryString(queryString);

    try {/*from   w w  w  . ja v a  2  s .  co  m*/
        JAXBContext jc = JAXBContext.newInstance(Recommendations.class);
        Writer recWriter = new StringWriter();

        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(rec, recWriter);

        RequestEntity requestEntity = new StringRequestEntity(recWriter.toString(), contentType, "UTF-8");
        putMethod.setRequestEntity(requestEntity);

        httpClient.executeMethod(putMethod);
    } catch (JAXBException | IOException e) {
        throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause());
    }
}