Example usage for javax.xml.bind Marshaller JAXB_FRAGMENT

List of usage examples for javax.xml.bind Marshaller JAXB_FRAGMENT

Introduction

In this page you can find the example usage for javax.xml.bind Marshaller JAXB_FRAGMENT.

Prototype

String JAXB_FRAGMENT

To view the source code for javax.xml.bind Marshaller JAXB_FRAGMENT.

Click Source Link

Document

The name of the property used to specify whether or not the marshaller will generate document level events (ie calling startDocument or endDocument).

Usage

From source file:org.wso2.developerstudio.eclipse.qos.project.ui.dashboard.QoSDashboardPage.java

private void saveTofile() throws JAXBException, PropertyException, CoreException {
    JAXBContext jaxbContext = JAXBContext.newInstance(ServiceGroup.class);
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
    jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    jaxbMarshaller.marshal(serviceGroup, serviceMetaFile);

    RefreshProject();//ww w . j av a  2  s. c  om
}

From source file:pl.psnc.synat.wrdz.common.metadata.mets.MetsMetadataBuilder.java

/**
 * Constructs builder of METS metadata./*from w  ww.  ja va2s  . c  o m*/
 * 
 * @param jaxbContext
 *            JAXB context for the METS classes
 * @param datatypeFactory
 *            factory for converting dates into XML Gregorian Calendar instances.
 * @param domBuilderFactory
 *            factory for parsing XML to DOM.
 */
public MetsMetadataBuilder(JAXBContext jaxbContext, DatatypeFactory datatypeFactory,
        DocumentBuilderFactory domBuilderFactory) {
    try {
        this.marshaller = jaxbContext.createMarshaller();
        this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        this.marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
        this.marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
                MetsConsts.METS_NAMESPACE_URI + " " + MetsConsts.METS_SCHEMA_LOCATION);
    } catch (JAXBException e) {
        logger.error("JAXB - METS marshaller creation failed.", e);
        throw new RuntimeException(e);
    }
    try {
        this.unmarshaller = jaxbContext.createUnmarshaller();
    } catch (JAXBException e) {
        logger.error("JAXB - METS unmarshaller creation failed.", e);
        throw new RuntimeException(e);
    }
    this.datatypeFactory = datatypeFactory;
    this.domBuilderFactory = domBuilderFactory;
    this.idGenerators = new MetsIdGenerators();
    this.premisAdmId = null;
    this.premisDpId = null;
    this.dataFileMap = new HashMap<String, String>();
    this.mets = new Mets();
}

From source file:pl.psnc.synat.wrdz.common.metadata.mets.MetsMetadataBuilder.java

/**
 * Constructs builder of METS metadata./*from   ww  w.  j a v a  2  s.  c  o m*/
 * 
 * @param jaxbContext
 *            JAXB context for the METS classes
 * @param datatypeFactory
 *            factory for converting dates into XML Gregorian Calendar instances.
 * @param domBuilderFactory
 *            factory for parsing XML to DOM.
 * @param tmpMetsFileUri
 *            URI to tmpMets file.
 */
public MetsMetadataBuilder(JAXBContext jaxbContext, DatatypeFactory datatypeFactory,
        DocumentBuilderFactory domBuilderFactory, URI tmpMetsFileUri) {
    try {
        this.marshaller = jaxbContext.createMarshaller();
        this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        this.marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
        this.marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
                MetsConsts.METS_NAMESPACE_URI + " " + MetsConsts.METS_SCHEMA_LOCATION);
    } catch (JAXBException e) {
        logger.error("JAXB - METS marshaller creation failed.", e);
        throw new RuntimeException(e);
    }
    try {
        this.unmarshaller = jaxbContext.createUnmarshaller();
    } catch (JAXBException e) {
        logger.error("JAXB - METS unmarshaller creation failed.", e);
        throw new RuntimeException(e);
    }
    this.datatypeFactory = datatypeFactory;
    this.domBuilderFactory = domBuilderFactory;
    this.idGenerators = new MetsIdGenerators();
    this.premisAdmId = null;
    this.premisDpId = null;
    this.dataFileMap = new HashMap<String, String>();

    try {
        File tmpMetsFile = new File(tmpMetsFileUri.getPath());
        this.mets = (Mets) unmarshaller.unmarshal(tmpMetsFile);
    } catch (JAXBException e) {
        logger.error("JAXB - METS unmarshaller - tmpMets file unmarshalling failed.", e);
        throw new RuntimeException(e);
    }
}

From source file:uta.ak.usttmp.common.util.UsttmpXmlUtil.java

public static final String objectToXmlStr(Object obj, Class cls, boolean removeXmlHead) throws JAXBException {

    JAXBContext context = JAXBContext.newInstance(cls);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FRAGMENT, removeXmlHead);
    //        CharacterEscapeHandler escapeHandler = new JaxbNoEscapeCharacterHandler();
    //        m.setProperty("com.sun.xml.bind.characterEscapeHandler", escapeHandler); 
    m.setProperty(Marshaller.JAXB_ENCODING, "utf-8");
    StringWriter sw = new StringWriter();
    m.marshal(obj, sw);/*www.j a v  a 2  s. c  om*/
    String xmlstr = sw.toString();
    //        String xmlstr=StringEscapeUtils.unescapeXml(sw.toString());
    logger.log(Level.FINE, "Converted to XML: {0}", xmlstr);

    return xmlstr;
}