Example usage for javax.xml.bind Marshaller setProperty

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

Introduction

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

Prototype

public void setProperty(String name, Object value) throws PropertyException;

Source Link

Document

Set the particular property in the underlying implementation of Marshaller .

Usage

From source file:org.mule.module.apikit.leagues.Teams.java

@Transformer(resultMimeType = "text/xml")
public String toXml(Teams teams) throws IOException, JAXBException {
    JAXBContext context = JAXBContext.newInstance(getClass());

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

    ByteArrayOutputStream boas = new ByteArrayOutputStream();
    m.marshal(teams, boas);//  w  w w  . ja va2s  . c  o m

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

From source file:Product.java

public String toXML() throws JAXBException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    JAXBContext context = JAXBContext.newInstance(Product.class);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.marshal(this, out);
    return out.toString();
}

From source file:org.mule.module.apikit.leagues.Leagues.java

@Transformer(resultMimeType = "text/xml")
public String toXml(Leagues leagues) throws IOException, JAXBException {
    JAXBContext context = JAXBContext.newInstance(getClass());

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

    ByteArrayOutputStream boas = new ByteArrayOutputStream();
    m.marshal(leagues, boas);//from  w  w w .j a v a 2 s. com

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

From source file:com.redhat.akashche.wixgen.jaxb.SampleInstallerTest.java

@Test
public void test() throws Exception {
    JAXBContext jaxb = JAXBContext.newInstance(SampleInstallerTest.class.getPackage().getName());
    InputStream is = null;//www.  j  av a  2 s.co m
    Writer writer = null;
    try {
        is = SampleInstallerTest.class.getResourceAsStream("SampleInstaller.wxs");
        Reader reader = new InputStreamReader(is, Charset.forName("UTF-8"));
        Wix wix = (Wix) jaxb.createUnmarshaller().unmarshal(reader);
        wix.getProduct().setName(wix.getProduct().getName() + " (JAXB)");
        //            OutputStream os = new FileOutputStream("SampleInstaller_JAXB.wxs");
        OutputStream os = new NullOutputStream();
        writer = new OutputStreamWriter(os, Charset.forName("UTF-8"));
        Marshaller marshaller = jaxb.createMarshaller();
        marshaller.setProperty(JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(wix, writer);
    } finally {
        closeQuietly(is);
        closeQuietly(writer);
    }
}

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();//from   ww w .j  a va  2s.  c  o m
        }
    }

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

}

From source file:org.sonarqube.shell.services.JsonContext.java

public Marshaller getMarshaller() {
    try {//  w  ww.  j  av a2s  . c  o  m
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        return marshaller;
    } catch (JAXBException e) {
        throw new IllegalStateException("Bad configuration", e);
    }
}

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.  c o m*/
}

From source file:com.photon.phresco.plugins.util.WarConfigProcessor.java

public void save() throws JAXBException {
    JAXBContext jaxbContext = JAXBContext.newInstance(Assembly.class);
    Marshaller marshal = jaxbContext.createMarshaller();
    marshal.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshal.marshal(assembly, file);//from w ww. j a v a  2 s.c  o m
}

From source file:org.esbtools.gateway.GatewayRequest.java

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

    try {//from ww w. ja va 2 s . 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:com.codercowboy.photo.organizer.service.LibraryMarshaller.java

public void saveLibrary(Library library, String fileName) throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {/*from  w ww .jav a 2 s.co  m*/
        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();
    }
}