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:org.esbtools.gateway.GatewayRequest.java

public String toXML() {
    StringWriter thisXML = new StringWriter();

    try {/*from   w  w  w  .j  a  v  a  2s. c o m*/
        JAXBContext jaxbContext = JAXBContext.newInstance(this.getClass());
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        jaxbMarshaller.marshal(this, thisXML);

    } catch (JAXBException e) {
        throw new RuntimeException(e);
    }
    return thisXML.toString();
}

From source file:org.mule.modules.rest.model.LeagueTransformers.java

@Transformer(resultMimeType = "text/xml")
public String toXml(League league) throws IOException, JAXBException {
    JAXBContext context = JAXBContext.newInstance(League.class);

    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    ByteArrayOutputStream boas = new ByteArrayOutputStream();
    m.marshal(league, boas);/*  ww  w.  ja v a  2 s .  c om*/

    return new String(boas.toByteArray());
}

From source file:com.github.woozoo73.ht.format.XmlFormat.java

public String formatInternal(Invocation invocation) throws Exception {
    JAXBContext jaxbContext = JAXBContext.newInstance(invocation.getClass());
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    StringWriter writer = new StringWriter();
    marshaller.marshal(invocation, writer);

    String xml = writer.getBuffer().toString();

    return xml;/*from   w  ww  .j a v a  2s  .  co m*/
}

From source file:com.codercowboy.photo.organizer.service.LibraryMarshaller.java

public void saveLibrary(Library library, String fileName) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {/*from  w  w  w  .  ja  v a 2s  .  c  om*/
        Marshaller marshaller = this.createContext().createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(library, outputStream);
        FileUtils.writeByteArrayToFile(new File(fileName), outputStream.toByteArray());
    } finally {
        outputStream.close();
    }
}

From source file:Main.java

/**
 * Create a marshaller for XML generation.
 *
 * @param encoding/*from ww  w .  ja  va2 s. co  m*/
 * encoding of generated XML output
 *
 * @param prettyPrint
 * enable pretty printing for generated XML output
 *
 * @return
 * marshaller
 *
 * @throws JAXBException
 * if the marshaller is not creatable
 */
public static Marshaller createMarshaller(String encoding, boolean prettyPrint) throws JAXBException {
    Marshaller m = getContext().createMarshaller();
    m.setProperty(Marshaller.JAXB_ENCODING, encoding);
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, prettyPrint);
    return m;
}

From source file:com.sharksharding.util.xml.CreateCoreXml.java

public CreateCoreXml() {
    try {// w w w  . j  av  a2  s .co m
        JAXBContext jAXBContext = JAXBContext.newInstance(Beans.class);
        marshaller = jAXBContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.wallerlab.yoink.molecular.data.AbstractJaxbWriter.java

/**
 * use JAXB writer to write out an instance to a file.
 * //  w  w w  .  ja  v a2s  . c  o m
 * @param nameOfFile
 *            - the name of out put file
 * @param jaxbObject
 *            - the instance will be written into a file
 */
protected void marshall() {
    try {
        jaxbContext = JAXBContext.newInstance(Class.forName(jaxbObject.getClass().getName()));
        jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshal();
    } catch (JAXBException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:au.id.hazelwood.xmltvguidebuilder.binding.BindingService.java

public BindingService(String contextPath) throws JAXBException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*from  w  w  w  .j  a  va2 s  .  c om*/
    JAXBContext jaxbContext = JAXBContext.newInstance(contextPath);
    marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    stopWatch.stop();
    LOGGER.debug("BindingService created for {} in {}", contextPath, formatDurationWords(stopWatch.getTime()));
}

From source file:com.mycompany.dao.report.XMLReport.java

@Override
public void generate() throws JAXBException {
    JAXBContext jaxbContext = JAXBContext.newInstance(Books.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    Books books = (Books) jaxbUnmarshaller.unmarshal(new File(fileName));

    for (Iterator<Book> iterator = books.getBooks().iterator(); iterator.hasNext();) {
        Book book = iterator.next();
        if (book.getQuantity() != 0) {
            // Remove the current element from the iterator and the list.
            iterator.remove();//ww w . j av  a  2s  .co  m
        }
    }

    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    jaxbMarshaller.marshal(books, new File(fileName2));

}

From source file:org.bremersee.common.spring.autoconfigure.JaxbAutoConfiguration.java

public static Jaxb2Marshaller createJaxbMarshaller(final Collection<String> packages) {
    final Set<String> packageSet = createPackageSet(packages);
    Jaxb2Marshaller m = new Jaxb2Marshaller();
    Map<String, Object> marshallerProperties = new HashMap<>();
    marshallerProperties.put(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.setMarshallerProperties(marshallerProperties);
    m.setContextPaths(packageSet.toArray(new String[packageSet.size()]));
    return m;/*from   w  w w .  j  a v a2s . co m*/
}