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:at.ac.tuwien.dsg.cloud.salsa.engine.smartdeployment.QUELLE.QuelleService.java

@POST
@Path("/submitCloudDescription")
@Consumes(MediaType.APPLICATION_XML)//from ww  w .  j  a  va2 s. c  om
public boolean submitCloudProviderDescription(CloudProvider provider,
        @DefaultValue("true") @QueryParam("overwrite") boolean overwrite) {
    File saveAs = new File(SalsaConfiguration.getCloudProviderDescriptionDir() + File.separator
            + provider.getName() + cloudDescriptionFileExtension);
    if (saveAs.exists() && overwrite == false) {
        EngineLogger.logger.debug("Do not overwrite file : " + saveAs);
        return false;
    }
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(CloudProvider.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        jaxbMarshaller.marshal(provider, saveAs);
    } catch (JAXBException e) {
        EngineLogger.logger.debug("Fail to pass the cloud description !");
        e.printStackTrace();
    }
    EngineLogger.logger.debug("Saved/Updated cloud description in : " + saveAs);
    return true;
}

From source file:edu.purdue.cybercenter.dm.service.VocabularyService.java

/**
 * Convert a vocabulary object to Xml vocabulary
 *
 * @param vocabulary: a vocabulary object
 * @return: an XML version of the vocabulary
 *//*from w  ww.j  av a2 s  .  c  o m*/
public String convertVocabularyToXml(Vocabulary vocabulary) {
    String xmlVocabulary = null;
    try (OutputStream os = new ByteArrayOutputStream()) {
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(CharacterEscapeHandler.class.getName(), CDataEscapeHandler.theInstance);
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, VOCABULARY_SCHEMA_LOCATION);
        marshaller.marshal(vocabulary, os);
        xmlVocabulary = os.toString();
    } catch (JAXBException ex) {
        throw new RuntimeException("Unable to generate xml vocabulary definition", ex);
    } catch (IOException ex) {
        throw new RuntimeException("UUnable to write xml vocabulary definition", ex);
    }
    return xmlVocabulary;
}

From source file:edu.uci.ics.asterix.event.service.AsterixEventServiceUtil.java

private static void writeAsterixConfigurationFile(AsterixInstance asterixInstance)
        throws IOException, JAXBException {
    String asterixInstanceName = asterixInstance.getName();
    Cluster cluster = asterixInstance.getCluster();
    String metadataNodeId = asterixInstance.getMetadataNodeId();

    AsterixConfiguration configuration = asterixInstance.getAsterixConfiguration();
    configuration.setInstanceName(asterixInstanceName);
    configuration.setMetadataNode(asterixInstanceName + "_" + metadataNodeId);
    String storeDir = null;//ww  w  .  j a v a2s.  co  m
    List<Store> stores = new ArrayList<Store>();
    for (Node node : cluster.getNode()) {
        storeDir = node.getStore() == null ? cluster.getStore() : node.getStore();
        stores.add(new Store(asterixInstanceName + "_" + node.getId(), storeDir));
    }
    configuration.setStore(stores);

    List<Coredump> coredump = new ArrayList<Coredump>();
    String coredumpDir = null;
    List<TransactionLogDir> txnLogDirs = new ArrayList<TransactionLogDir>();
    String txnLogDir = null;
    for (Node node : cluster.getNode()) {
        coredumpDir = node.getLogDir() == null ? cluster.getLogDir() : node.getLogDir();
        coredump.add(new Coredump(asterixInstanceName + "_" + node.getId(),
                coredumpDir + File.separator + asterixInstanceName + "_" + node.getId()));

        txnLogDir = node.getTxnLogDir() == null ? cluster.getTxnLogDir() : node.getTxnLogDir();
        txnLogDirs.add(new TransactionLogDir(asterixInstanceName + "_" + node.getId(), txnLogDir));
    }
    configuration.setCoredump(coredump);
    configuration.setTransactionLogDir(txnLogDirs);

    File asterixConfDir = new File(AsterixEventService.getAsterixDir() + File.separator + asterixInstanceName);
    asterixConfDir.mkdirs();

    JAXBContext ctx = JAXBContext.newInstance(AsterixConfiguration.class);
    Marshaller marshaller = ctx.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    FileOutputStream os = new FileOutputStream(asterixConfDir + File.separator + ASTERIX_CONFIGURATION_FILE);
    marshaller.marshal(configuration, os);
    os.close();
}

From source file:labr_client.xml.ObjToXML.java

public static String marshallRequest(KmehrMessage message) {
    String xml = "";
    String date = String.format("%1$tY%1$tm%1$td", new Date());
    String time = String.format("%1$tH%1$tM%1$tS", new Date());
    try {//from  ww  w . ja v  a2  s . c om
        JAXBContext context = JAXBContext.newInstance(LabrRequest.class);
        Marshaller m = context.createMarshaller();
        //for pretty-print XML in JAXB
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        File kmehrMessage = new File("data/tmp/kmehr" + date + time + ".xml");
        m.marshal(message, kmehrMessage);
        xml = FileUtils.readFileToString(kmehrMessage);

    } catch (JAXBException | IOException ex) {
        Logger.getLogger(ObjToXML.class.getName()).log(Level.SEVERE, null, ex);
    }
    return xml;
}

From source file:com.moss.bdbadmin.client.ui.BdbAdminClient.java

private void saveConfig() {
    try {/* w ww  .  j a  v  a2 s. co m*/
        ServiceConfig config = new ServiceConfig();

        for (int i = 0; i < root.getChildCount(); i++) {
            DefaultMutableTreeNode serviceNode = (DefaultMutableTreeNode) root.getChildAt(i);
            ServiceContainer container = (ServiceContainer) serviceNode.getUserObject();
            config.services().add(container.getInfo());
        }

        Marshaller m = configJaxbContext.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(config, new FileOutputStream(configPath));
    } catch (Exception ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(ancestor, "Could not save configuration from file: " + configPath,
                "Config Save Failed", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:TwitterRetrieval.java

private void Twitter2XML(PostsType posts, PrintWriter out) throws Exception {
    JAXBContext context = JAXBContext.newInstance("entities");
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(posts, out);/*ww w.  j a va  2s. c  o  m*/
}

From source file:fr.cls.atoll.motu.processor.wps.framework.WPSFactory.java

/**
 * Inits the jaxbwps./*w ww.ja  v  a  2s  .  c o m*/
 * 
 * @throws MotuException the motu exception
 */
private static void initJAXBWPS() throws MotuException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("initJAXBWPS() - entering");
    }
    if (WPSFactory.jaxbContextWPS != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("initJAXBWPS() - exiting");
        }
        return;
    }

    try {
        WPSFactory.jaxbContextWPS = JAXBContext.newInstance(MotuWPSProcess.WPS100_SHEMA_PACK_NAME);
        WPSFactory.marshallerWPS = WPSFactory.jaxbContextWPS.createMarshaller();
        WPSFactory.marshallerWPS.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        WPSFactory.unmarshallerWPS = WPSFactory.jaxbContextWPS.createUnmarshaller();

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

    }

    objectFactoryWPS = new ObjectFactory();
    objectFactoryOWS = new fr.cls.atoll.motu.processor.opengis.ows110.ObjectFactory();

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

From source file:com.evolveum.midpoint.model.client.ModelClientUtil.java

public static <O extends ObjectType> String marshallToSting(O object, boolean formatted) throws JAXBException {
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
    if (formatted) {
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    }/*  w  w w.  j av  a 2 s  .  c o  m*/
    java.io.StringWriter sw = new StringWriter();
    Class<O> type = (Class<O>) object.getClass();
    JAXBElement<O> element = new JAXBElement<O>(getElementName(type), type, object);
    marshaller.marshal(element, sw);
    return sw.toString();
}

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

/** Write rows from sql query to output stream
 * @param sqlQueryRows rows/*from   ww  w  . j a  va2 s  .c  o  m*/
 * @param outputStream stream to which are data write */
public static void writeSqlQueryRowsToXMLv1(SQLQueryRows sqlQueryRows, OutputStream outputStream) {
    ObjectFactory of = new ObjectFactory();
    ExportType export = of.createExportType();
    export.setSql(sqlQueryRows.getSQL());
    export.setVersion("1");
    ColumnsType columnsType = of.createColumnsType();
    export.setColumns(columnsType);
    Map<ColumnDesc, ColumnType> ctsMap = new HashMap<>();

    sqlQueryRows.getMetaData().getColumns().forEach(cd -> {
        ColumnType ct = of.createColumnType();
        ctsMap.put(cd, ct);
        ct.setId(columnId(cd));
        ct.setCatalog(cd.getCatalog());
        ct.setSchema(cd.getSchema());
        ct.setTable(cd.getTable());
        ct.setColumn(cd.getName());
        ct.setDataType(DbStructureFactory.columnTypeToDataTypeType(cd.getDataType()));
        ct.setLength(cd.getSize());
        ct.setScale(cd.getScale());
        ct.setValue(cd.getLabel());
        columnsType.getColumn().add(ct);
    });

    sqlQueryRows.getRows().forEach(row -> {
        RowType rowType = of.createRowType();
        sqlQueryRows.getMetaData().getColumns().forEach(cd -> {
            FieldType field = of.createFieldType();
            field.setColumn(ctsMap.get(cd));
            if (row.isColumnNull(cd)) {
                field.setNull(true);
            } else {
                field.setValue(row.getColumnValueStr(cd));
            }
            rowType.getField().add(field);
        });
        export.getRow().add(rowType);
    });

    try {
        JAXBContext jc = JAXBContext.newInstance(cz.lbenda.dataman.schema.export.ObjectFactory.class);
        Marshaller m = jc.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
        m.marshal(of.createExport(export), outputStream);
    } catch (JAXBException e) {
        LOG.error("Problem with write exporting data: " + e.toString(), e);
        throw new RuntimeException("Problem with write exporting data: " + e.toString(), e);
    }
}

From source file:com.manydesigns.portofino.dispatcher.DispatcherLogic.java

public static File saveConfiguration(File directory, Object configuration) throws Exception {
    String configurationPackage = configuration.getClass().getPackage().getName();
    JAXBContext jaxbContext = JAXBContext.newInstance(configurationPackage);
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    File configurationFile = new File(directory, "configuration.xml");
    marshaller.marshal(configuration, configurationFile);
    configurationCache.invalidate(configurationFile);
    return configurationFile;
}