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.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  a v  a 2s  .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: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 w  w .j  a  va  2s . c  o 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: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 w w  . j  a  va 2s  .  co 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:edu.harvard.hms.dbmi.i2b2.api.pm.PMCell.java

/**
 * Sets up the system without any parameters of the Project Management Cell
 * /*from  www  .  j av a  2 s .  c om*/
 * @throws JAXBException
 */
public void setup() throws JAXBException {
    // Setup System
    pmOF = new ObjectFactory();
    pmJC = JAXBContext.newInstance("edu.harvard.hms.dbmi.i2b2.api.pm.xml");
    pmMarshaller = pmJC.createMarshaller();
    pmMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
}

From source file:br.gov.frameworkdemoiselle.behave.integration.alm.objects.util.GenerateXMLString.java

public static String getExecutionworkitemString(String urlServer, String projectAreaAlias, String encoding,
        String testCaseId, String testPlanId) throws JAXBException {

    // Workitem/*from  w  w  w.j a v  a  2 s .  c  o  m*/
    com.ibm.rqm.xml.bind.Executionworkitem.Testcase workTest = new com.ibm.rqm.xml.bind.Executionworkitem.Testcase();
    workTest.setHref(urlServer + "resources/" + projectAreaAlias + "/testcase/" + testCaseId);

    // Testplan
    com.ibm.rqm.xml.bind.Executionworkitem.Testplan testPlan = new com.ibm.rqm.xml.bind.Executionworkitem.Testplan();
    testPlan.setHref(
            urlServer + "resources/" + projectAreaAlias + "/testplan/urn:com.ibm.rqm:testplan:" + testPlanId);

    // Criao do Execution Work Item
    Executionworkitem work = new Executionworkitem();
    work.setFrequency("Once");
    work.setRegression(false);
    work.setTitle("Registro de Execuo Automatizado - Plano de Teste " + testPlanId);
    work.setWeight(100);
    work.setTestcase(workTest);
    work.setTestplan(testPlan);

    JAXBContext jaxb = JAXBContext.newInstance(Executionworkitem.class);
    Marshaller marshaller = jaxb.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);
    StringWriter resourceString = new StringWriter();
    marshaller.marshal(work, resourceString);

    return resourceString.toString();
}

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

/**
 * Example code for serializing a PhoneUser via JAXB.
 *///from   ww w  .  j a v  a 2s.co  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:com.sarm.lonelyplanet.process.DestinationProcessorTest.java

/**
 * This method is not a JUnit test method. This is used to create an XML
 * file of 30000 destinations and to regressively test the UnMarshalling
 * technique used in the LPUnMarshaller. This is called by the test method :
 * testProcessDestinationByStAXfor30000 to test the 30000 destinations.
 *
 * @param destinationFileName//from   w  w w  .  ja  v  a2s .c o m
 * @throws JAXBException
 * @throws FileNotFoundException
 * @throws XMLStreamException
 * @throws UnsupportedEncodingException
 */
public static void testMarshall(String destinationFileName)
        throws JAXBException, FileNotFoundException, XMLStreamException, UnsupportedEncodingException {
    DestinationProcessor destinationProcessor = new DestinationProcessor();
    List<Destination> destinations = destinationProcessor.processDestinationByStAX(destinationFileName);
    List<Destination> tempDestinations = new ArrayList<>();
    for (int i = 0; i < 1500; i++) {
        for (Destination destination : destinations) {
            Destination temp = new Destination();
            temp = destination.clone();
            temp.setTitle(temp.getTitle() + i);
            tempDestinations.add(temp);
        }
    }
    Destinations destinationList = new Destinations();
    destinationList.setDestinations(tempDestinations);
    logger.info(" destinationList " + destinationList.getDestinations().size());

    JAXBContext jc = JAXBContext.newInstance(Destinations.class);
    logger.debug(jc.getClass());
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(destinationList, new File(regressDestinationfile));
    logger.info("Successfully created regressDestinationfile " + regressDestinationfile);

}

From source file:hydrograph.ui.engine.util.ConverterUtil.java

/**
 * Store file into local file system./*w ww.  j a  v a  2s . c  o  m*/
 *
 * @param graph
 * @param externalOutputFile
 * @param out
 * @throws CoreException the core exception
 * @throws JAXBException the JAXB exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
private void storeFileIntoLocalFileSystem(Graph graph, boolean validate, IFileStore externalOutputFile,
        ByteArrayOutputStream out) throws CoreException, JAXBException, IOException {

    File externalFile = externalOutputFile.toLocalFile(0, null);
    OutputStream outputStream = new FileOutputStream(externalFile.getAbsolutePath().replace(".job", ".xml"));

    JAXBContext jaxbContext = JAXBContext.newInstance(graph.getClass());
    Marshaller marshaller = jaxbContext.createMarshaller();
    out = new ByteArrayOutputStream();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(graph, out);
    out = ComponentXpath.INSTANCE.addParameters(out);
    out.writeTo(outputStream);
    outputStream.close();
}

From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.ApplicationManagement.java

/**
 * <p>/*from w w  w.  j a  v  a  2 s  .c  o m*/
 * This will marshall the object back to the XML file.
 * </p>
 * 
 * @throws JAXBException
 */
public void save() throws JAXBException {
    Marshaller m = jaxbContext.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    m.marshal(application, xmlFile);
}

From source file:com.comcast.cats.service.util.HttpClientUtil.java

public static synchronized byte[] getPayload(Object domain, boolean prettyPrint) {
    byte[] payload = null;

    String xml = null;//from w ww  .  j a  v  a2s.com

    StringWriter writer = new StringWriter();

    try {
        JAXBContext context = JAXBContext.newInstance(domain.getClass());

        Marshaller marshaller = context.createMarshaller();

        if (prettyPrint) {
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        }

        marshaller.marshal(domain, writer);
        xml = writer.toString();
    } catch (JAXBException e) {
        logger.error("[ JAXBException   ] " + e.getMessage());
    }

    logger.trace("[ PAYLOAD  ] " + xml);

    if (null != xml) {
        payload = xml.getBytes();
    }

    return payload;
}