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:esg.common.security.PolicyGleaner.java

public synchronized boolean savePolicyAs(Policies policy, String policyFileLocation) {
    boolean success = false;
    if (policy == null) {
        log.error("Sorry internal policy representation is null ? [" + policy
                + "] perhaps you need to load policy file first?");
        return success;
    }//from w  w  w. ja v a2  s  .c om
    log.info("Saving policy information to " + policyFileLocation);
    try {
        JAXBContext jc = JAXBContext.newInstance(Policies.class);
        Marshaller m = jc.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(policy, new FileOutputStream(policyFileLocation));
        success = true;
    } catch (Exception e) {
        log.error(e);
    }
    return success;
}

From source file:org.eclipse.winery.repository.client.WineryRepositoryClient.java

/**
 * Creates a marshaller/*from  w w  w . j av a2  s  .  c  om*/
 *
 * @throws IllegalStateException if marshaller could not be instantiated
 */
private static Marshaller createMarshaller() {
    // code copied+adapted from JAXBSupport
    Marshaller m;
    try {
        m = WineryRepositoryClient.context.createMarshaller();
        // pretty printed output is required as the XML is sent 1:1 to the browser for editing
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        // not possible here: m.setProperty("com.sun.xml.bind.namespacePrefixMapper", JAXBSupport.prefixMapper);
    } catch (JAXBException e) {
        LOGGER.error("Could not instantiate marshaller", e);
        throw new IllegalStateException(e);
    }
    return m;
}

From source file:io.mapzone.arena.csw.CswRequest.java

protected void writeObject(JAXBElement jaxb) throws Exception {
    Marshaller marshaller = jaxbContext.get().createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);

    marshaller.marshal(jaxb, out());// w  ww .  j  a v a2 s. com
}

From source file:org.restsql.core.impl.AbstractSqlResourceMetaData.java

/** Returns XML representation. */
@Override/*  ww  w.ja  v  a 2  s.  c o m*/
public String toXml() {
    // Build extended metadata for serialization if first time through
    if (!extendedMetadataIsBuilt) {
        parentTableName = getQualifiedTableName(parentTable);
        childTableName = getQualifiedTableName(childTable);
        joinTableName = getQualifiedTableName(joinTable);
        parentPlusExtTableNames = getQualifiedTableNames(parentPlusExtTables);
        childPlusExtTableNames = getQualifiedTableNames(childPlusExtTables);
        allReadColumnNames = getQualifiedColumnNames(allReadColumns);
        childReadColumnNames = getQualifiedColumnNames(childReadColumns);
        parentReadColumnNames = getQualifiedColumnNames(parentReadColumns);
        extendedMetadataIsBuilt = true;
    }

    try {
        final JAXBContext context = JAXBContext.newInstance(AbstractSqlResourceMetaData.class);
        final Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        final StringWriter writer = new StringWriter();
        marshaller.marshal(this, writer);
        return writer.toString();
    } catch (final JAXBException exception) {
        return exception.toString();
    }
}

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;/*from ww  w. j  a  v  a  2 s  . co  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:edu.harvard.hms.dbmi.i2b2.api.crc.CRCCell.java

/**
 * Sets up the system without any parameters of the Data Repository Cell
 * //w w w .  j  a  v a  2s .  c o m
 * @throws JAXBException
 */
public void setup() throws JAXBException {
    // Setup PDO
    pdoOF = new ObjectFactory();
    pdoJC = JAXBContext.newInstance("edu.harvard.hms.dbmi.i2b2.api.crc.xml.pdo");
    pdoMarshaller = pdoJC.createMarshaller();
    pdoMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    // Setup PSM
    psmOF = new edu.harvard.hms.dbmi.i2b2.api.crc.xml.psm.ObjectFactory();
    psmJC = JAXBContext.newInstance("edu.harvard.hms.dbmi.i2b2.api.crc.xml.psm");
    psmMarshaller = psmJC.createMarshaller();
    psmMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    // Setup Loader
    //      loaderOF = new edu.harvard.hms.dbmi.i2b2.api.crc.xml.loader.ObjectFactory();
    //      loaderJC = JAXBContext
    //            .newInstance("edu.harvard.hms.dbmi.i2b2.api.crc.xml.loader");
    //      loaderMarshaller = loaderJC.createMarshaller();
    //      loaderMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
}

From source file:net.ageto.gyrex.impex.console.internal.ImpexConsoleCommands.java

/**
 *
 * List process configurations./*from ww  w .  jav a2 s .co  m*/
 *
 * @param interpreter
 * @return
 */
public Object _impexListProcesses(final CommandInterpreter interpreter) {
    final String instanceShortcut = interpreter.nextArgument();
    IRuntimeContext context = getContext(instanceShortcut);
    if (context == null) {
        interpreter.println(INSTANCE_MISSING);
        return null;
    }

    // determine process from database
    final IProcessConfigManager processManager = context.get(IProcessConfigManager.class);
    ArrayList<IProcessConfig> processes = (ArrayList<IProcessConfig>) processManager.findAllProcesses();

    JAXBContext jaxbContext;

    try {
        for (IProcessConfig process : processes) {
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            jaxbContext = JAXBContext.newInstance(ProcessConfig.class);
            Marshaller m = jaxbContext.createMarshaller();
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            m.marshal(process, outputStream);

            final StringBuilder sb = new StringBuilder();
            sb.append("=========== " + process.getId() + " ===========\n");
            sb.append("\n");
            sb.append(outputStream.toString() + "\n");
            sb.append("\n");
            sb.append("=========== " + process.getId() + " ===========\n");
            interpreter.print(sb);

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

    return null;
}

From source file:be.fedict.eid.applet.service.signer.facets.XAdESXLSignatureFacet.java

/**
 * Main constructor.//w ww.  java 2s. com
 * 
 * @param timeStampService
 *            the time-stamp service used for XAdES-T and XAdES-X.
 * @param revocationDataService
 *            the optional revocation data service used for XAdES-C and
 *            XAdES-X-L. When <code>null</code> the signature will be
 *            limited to XAdES-T only.
 * @param digestAlgorithm
 *            the digest algorithm to be used for construction of the
 *            XAdES-X-L elements.
 */
public XAdESXLSignatureFacet(TimeStampService timeStampService, RevocationDataService revocationDataService,
        DigestAlgo digestAlgorithm) {
    this.objectFactory = new ObjectFactory();
    this.c14nAlgoId = CanonicalizationMethod.EXCLUSIVE;
    this.digestAlgorithm = digestAlgorithm;
    this.timeStampService = timeStampService;
    this.revocationDataService = revocationDataService;
    this.xmldsigObjectFactory = new be.fedict.eid.applet.service.signer.jaxb.xmldsig.ObjectFactory();
    this.xades141ObjectFactory = new be.fedict.eid.applet.service.signer.jaxb.xades141.ObjectFactory();

    try {
        JAXBContext context = JAXBContext
                .newInstance(be.fedict.eid.applet.service.signer.jaxb.xades141.ObjectFactory.class);
        this.marshaller = context.createMarshaller();
        this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        this.marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new XAdESNamespacePrefixMapper());
    } catch (JAXBException e) {
        throw new RuntimeException("JAXB error: " + e.getMessage(), e);
    }

    try {
        this.certificateFactory = CertificateFactory.getInstance("X.509");
    } catch (CertificateException e) {
        throw new RuntimeException("X509 JCA error: " + e.getMessage(), e);
    }

    try {
        this.datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException("datatype config error: " + e.getMessage(), e);
    }
}

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

/**
 * Store file into workspace./*from w w  w .jav a2 s.com*/
 *
 * @param graph the graph
 * @param outPutFile the out put file
 * @param out the out
 * @throws JAXBException the JAXB exception
 * @throws CoreException the core exception
 */
private void storeFileIntoWorkspace(Graph graph, boolean validate, IFile outPutFile, ByteArrayOutputStream out)
        throws JAXBException, CoreException {

    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);

    /*
     * To-do will be removed in future
     * String updatedXML=escapeXml(out.toString());
    out.reset();
    try {
       if(!unknownComponentLists.isEmpty())
      out.write(updatedXML.getBytes());
    } catch (IOException ioException) {
      LOGGER.error("Unable to update escape sequene in xml file",ioException);
    }*/
    if (outPutFile.exists()) {
        outPutFile.setContents(new ByteArrayInputStream(out.toByteArray()), true, false, null);
    } else {
        outPutFile.create(new ByteArrayInputStream(out.toByteArray()), true, null);
    }
}

From source file:cz.lbenda.dataman.db.DbConfig.java

/** Save session conf into File
 * @param writer writer to which is configuration saved */
public void save(Writer writer) throws IOException {
    cz.lbenda.dataman.schema.dataman.ObjectFactory of = new cz.lbenda.dataman.schema.dataman.ObjectFactory();
    SessionType st = storeToSessionType(null, null);
    try {/* w w w .j  av a 2s .c  o m*/
        JAXBContext jc = JAXBContext.newInstance(cz.lbenda.dataman.schema.dataman.ObjectFactory.class);
        Marshaller m = jc.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        m.marshal(of.createSession(st), writer);
    } catch (JAXBException e) {
        LOG.error("Problem with write configuration: " + e.toString(), e);
        throw new RuntimeException("Problem with write configuration: " + e.toString(), e);
    }
}