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:com.framework.infrastructure.mapper.JaxbMapper.java

/**
 * Marshallerencoding(null).//w ww.  ja  va2 s  .  co  m
 * pooling
 */
public Marshaller createMarshaller(String encoding) {
    try {
        Marshaller marshaller = jaxbContext.createMarshaller();

        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        if (StringUtils.isNotBlank(encoding)) {
            marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);
        }

        return marshaller;
    } catch (JAXBException e) {
        throw Exceptions.unchecked(e);
    }
}

From source file:com.govsoft.framework.common.util.encode.JaxbBinder.java

/**
 * Marshallerencoding(?Null)./*from   w w  w  .  j  a v a  2s .  co  m*/
 */
public Marshaller createMarshaller(String encoding) {
    try {
        Marshaller marshaller = jaxbContext.createMarshaller();

        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        if (StringUtils.isNotBlank(encoding)) {
            marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);
        }

        return marshaller;
    } catch (JAXBException e) {
        throw new RuntimeException(e);
    }
}

From source file:br.gov.frameworkdemoiselle.behave.integration.alm.objects.util.GenerateXMLString.java

public static String getTestplanString(String urlServer, String projectAreaAlias, String encoding,
        String testCaseId, Testplan currentPlan) throws JAXBException {

    // Adiciona o novo test case se no existir
    boolean exists = false;
    String newTestCaseId = urlServer + "resources/" + projectAreaAlias + "/testcase/" + testCaseId;

    if (currentPlan.getTestcase() != null) {
        for (com.ibm.rqm.xml.bind.Testplan.Testcase link : currentPlan.getTestcase()) {
            if (link.getHref().equals(newTestCaseId)) {
                exists = true;/*from   w w w .j  av  a 2  s.c o m*/
                break;
            }
        }
    }

    if (!exists) {
        com.ibm.rqm.xml.bind.Testplan.Testcase testcase = new com.ibm.rqm.xml.bind.Testplan.Testcase();
        testcase.setHref(newTestCaseId);
        currentPlan.getTestcase().add(testcase);
    }

    JAXBContext jaxb = JAXBContext.newInstance(Testplan.class);
    Marshaller marshaller = jaxb.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);
    StringWriter testPlanString = new StringWriter();
    marshaller.marshal(currentPlan, testPlanString);

    return testPlanString.toString();
}

From source file:ejava.projects.edmv.bl.DataGen.java

public void generate(Writer writer) throws JAXBException, DatatypeConfigurationException {
    dtf = DatatypeFactory.newInstance();
    JAXBContext jaxbc = JAXBContext.newInstance(Dmv.class);
    Marshaller m = jaxbc.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    Dmv dmvDoc = new Dmv();
    dmvDoc.setPeople(new PersonsType());
    dmvDoc.setVehicleRegistrations(new VehicleRegistrationsType());

    //get all people
    int index = 0;
    List<DMVPerson> people;
    do {//from  w ww.  j  a  v  a2 s  .c  om
        people = personDAO.getPeople(index, 10);
        for (DMVPerson p : people) {
            dmvDoc.getPeople().getPerson().add(createXMLPerson(p));
        }
        index += people.size();
    } while (people.size() > 0);
    log.debug("found " + index + " total people");

    //get all vehicle registrations
    index = 0;
    List<DMVVehicleRegistration> vRegs;
    do {
        vRegs = vehicleDAO.getRegistrations(index, 10);
        for (DMVVehicleRegistration vReg : vRegs) {
            dmvDoc.getVehicleRegistrations().getVehicleRegistration()
                    .add(createXMLRegistration(vReg, dmvDoc.getPeople()));
        }
        index += vRegs.size();
    } while (vRegs.size() > 0);
    log.debug("found " + index + " total registrations");

    m.marshal(dmvDoc, writer);
}

From source file:cn.hxh.springside.mapper.JaxbMapper.java

/**
 * Marshallerencoding(?null).//  w  w  w .  j  a  va 2s . c om
 */
public Marshaller createMarshaller(String encoding) {
    try {
        Marshaller marshaller = jaxbContext.createMarshaller();

        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        if (StringUtils.isNotBlank(encoding)) {
            marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);
        }

        return marshaller;
    } catch (JAXBException e) {
        throw ExceptionUtils.unchecked(e);
    }
}

From source file:com.github.lindenb.jvarkit.tools.blast.BlastFilterJS.java

@Override
protected Collection<Throwable> call(String inputName) throws Exception {

    final CompiledScript compiledScript;
    Unmarshaller unmarshaller;/*from   w w  w .jav a  2  s  .  c  o m*/
    Marshaller marshaller;
    try {
        compiledScript = super.compileJavascript();

        JAXBContext jc = JAXBContext.newInstance("gov.nih.nlm.ncbi.blast");

        unmarshaller = jc.createUnmarshaller();
        marshaller = jc.createMarshaller();

        XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
        xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
        xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
        xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
        xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        PrintWriter pw = openFileOrStdoutAsPrintWriter();
        XMLOutputFactory xof = XMLOutputFactory.newFactory();
        xof.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.FALSE);
        XMLEventWriter w = xof.createXMLEventWriter(pw);

        StreamSource src = null;
        if (inputName == null) {
            LOG.info("Reading stdin");
            src = new StreamSource(stdin());
        } else {
            LOG.info("Reading file " + inputName);
            src = new StreamSource(new File(inputName));
        }

        XMLEventReader r = xmlInputFactory.createXMLEventReader(src);

        XMLEventFactory eventFactory = XMLEventFactory.newFactory();

        SimpleBindings bindings = new SimpleBindings();
        while (r.hasNext()) {
            XMLEvent evt = r.peek();
            switch (evt.getEventType()) {
            case XMLEvent.START_ELEMENT: {
                StartElement sE = evt.asStartElement();
                Hit hit = null;
                JAXBElement<Hit> jaxbElement = null;
                if (sE.getName().getLocalPart().equals("Hit")) {
                    jaxbElement = unmarshaller.unmarshal(r, Hit.class);
                    hit = jaxbElement.getValue();
                } else {
                    w.add(r.nextEvent());
                    break;
                }

                if (hit != null) {

                    bindings.put("hit", hit);

                    boolean accept = super.evalJavaScriptBoolean(compiledScript, bindings);

                    if (accept) {
                        marshaller.marshal(jaxbElement, w);
                        w.add(eventFactory.createCharacters("\n"));
                    }
                }

                break;
            }
            case XMLEvent.SPACE:
                break;
            default: {
                w.add(r.nextEvent());
                break;
            }
            }
            r.close();
        }
        w.flush();
        w.close();
        pw.flush();
        pw.close();
        return RETURN_OK;
    } catch (Exception err) {
        return wrapException(err);
    } finally {

    }
}

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:com.uttesh.pdfngreport.handler.PdfReportHandler.java

/**
 * This method generate the XML data file required by the apache fo to
 * generate the PDF report. XML data file is generated by using the java
 * JAXB.//w  w  w  .j a va  2  s.  co m
 *
 * @param reportData
 * @return UUID which is used as the file name.
 *
 * {@link com.uttesh.pdfngreport.util.xml.ReportData#member ReportData}
 * @see JAXBException
 */
public int generateXmlData(ReportData reportData) {
    JAXBContext jc;
    int fileName = UUID.randomUUID().toString().substring(0, 3).hashCode();
    File file = null;
    try {
        jc = JAXBContext.newInstance(ReportData.class);
        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        if (reportData.getOsName().equalsIgnoreCase("w")) {
            file = new File(reportLocation + Constants.BACKWARD_SLASH + fileName + Constants.XML_EXTENSION);
        } else {
            file = new File(reportLocation + Constants.FORWARD_SLASH + fileName + Constants.XML_EXTENSION);
        }
        marshaller.marshal(reportData, file);
    } catch (JAXBException ex) {
        Logger.getLogger(PdfReportHandler.class.getName()).log(Level.SEVERE, null, ex);
        //new File(reportLocation + Constants.FORWARD_SLASH + fileName + Constants.XML_EXTENSION).delete();
    }
    return fileName;
}

From source file:it.tidalwave.northernwind.core.impl.io.LayoutJaxbMarshallable.java

/*******************************************************************************************************************
 *
 * {@inheritDoc}/*from w w w.  j  a v  a  2 s  .  c  o m*/
 *
 ******************************************************************************************************************/
@Override
public void marshal(final @Nonnull OutputStream os) throws IOException {
    try {
        final ComponentsJaxb componentsJaxb = objectFactory.createComponentsJaxb();
        componentsJaxb.setVersion("1.0");
        componentsJaxb.setComponent(marshal(ownerLayout));
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // FIXME: set in Spring
        marshaller.marshal(objectFactory.createComponents(componentsJaxb), os);
    } catch (JAXBException e) {
        throw new IOException("", e);
    }
}

From source file:at.ac.tuwien.dsg.comot.m.common.Utils.java

public static String asXmlString(Object obj, Class<?>... clazz) throws JAXBException {

    List<Object> list = new ArrayList<Object>(Arrays.asList(clazz));
    list.add(obj.getClass());//from w w w.j a  v a2s  .c  o m

    StringWriter w = new StringWriter();
    JAXBContext context = JAXBContext.newInstance(list.toArray(new Class[list.size()]));

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

    return w.toString();
}