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.manydesigns.portofino.dispatcher.DispatcherLogic.java

/**
 * Persists a page to the file system.//from ww w  .j ava2 s.c  o  m
 * @param directory the directory where to save the page.xml file.
 * @param page the page to save.
 * @return the file where the page was saved.
 * @throws Exception in case the save fails.
 */
public static File savePage(File directory, Page page) throws Exception {
    File pageFile = getPageFile(directory);
    Marshaller marshaller = pagesJaxbContext.createMarshaller();
    marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.marshal(page, pageFile);
    pageCache.invalidate(pageFile);
    return pageFile;
}

From source file:edu.harvard.lib.lcloud.SolrItem.java

protected static void marshalingExample(Item item) throws JAXBException {
    JAXBContext jaxbContext = JAXBContext.newInstance(Item.class);
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    jaxbMarshaller.marshal(item, System.out);

}

From source file:org.javelin.sws.ext.bind.jaxb.JaxbTest.java

@Test
public void marshalIllegalName() throws Exception {
    JAXBContext ctx = JAXBContext.newInstance(org.javelin.sws.ext.bind.jaxb.context1.MyClassJ1.class);
    Marshaller m = ctx.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

    // and I thought it's illegal...
    m.marshal(new JAXBElement<String>(new QName("a", "a a"), String.class, "hello"), System.out);
}

From source file:hydrograph.ui.engine.util.ConverterUtil.java

private void validateJobState(Graph graph, boolean validate, IFileStore externalOutputFile,
        ByteArrayOutputStream out) throws CoreException, JAXBException, IOException {
    JAXBContext jaxbContext = JAXBContext.newInstance(graph.getClass());
    Marshaller marshaller = jaxbContext.createMarshaller();
    out = new ByteArrayOutputStream();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(graph, out);/* www .  j a  va  2 s.  c  o  m*/
    out = ComponentXpath.INSTANCE.addParameters(out);
}

From source file:cz.zcu.kiv.eegdatabase.logic.xml.XMLTransformer.java

public OutputStream transform(Experiment meas, MetadataCommand mc, Set<DataFile> datas)
        throws JAXBException, IOException {

    if (meas == null) {
        return null;
    }//from   w  w  w .j  a  v  a  2  s  . c o m
    jc = JAXBContext.newInstance(objects);
    of = new ObjectFactory();
    log.debug("Creating JAXB context");
    MeasurationType measType = of.createMeasurationType();
    XMLMeasuration mea = new XMLMeasuration(measType);
    if (mc.isTimes()) {
        mea.writeStartAndEndTime(meas.getStartTime().toString(), meas.getEndTime().toString());
        log.debug("Written start and end time: " + measType.getStartTime() + ", " + measType.getEndTime());
    }
    Scenario scenario = meas.getScenario();
    ScenarioType scType = of.createScenarioType();
    XMLScenario scen = new XMLScenario(scType);
    if (mc.isTitle()) {
        scen.writeTitle(scenario.getTitle());
    }
    if (mc.isLength() && scenario.getScenarioLength() >= 0) {
        scen.writeLength("" + scenario.getScenarioLength()
                + ResourceUtils.getString("valueTable.scenarioLength.minutes"));
    }
    if (mc.isDescription()) {
        scen.writeDescription(scenario.getDescription());
    }
    measType.setScenario(scType);
    log.debug("Written Scenario metadata: " + scType);
    if (mc.isTemperature()) {
        measType.setTemperature(meas.getTemperature());
    }
    if (mc.isHardware()) {
        List<HardwareType> hwType = measType.getHardware();
        for (Hardware hw : meas.getHardwares()) {
            hwType.add(mea.writeHardware(hw, of));
            log.debug("Written hardware: " + hw);
        }
    }
    if (mc.isMeasurationAddParams()) {
        List<MeasurationAddParam> param = measType.getAddParam();
        for (ExperimentOptParamVal measAddParam : meas.getExperimentOptParamVals()) {
            param.add(mea.writeAdditionalParams(measAddParam, of));
            log.debug("Written measured additional params: " + measAddParam);
        }
    }

    if (mc.isWeather() && meas.getWeather() != null) {
        WeatherType wType = of.createWeatherType();
        wType.setTitle(meas.getWeather().getTitle());
        wType.setDescription(meas.getWeather().getDescription());
        measType.setWeather(wType);
        log.debug("Written weather: " + wType);
    }
    if (mc.isWeatherNote()) {
        measType.setEnvironmentNote(meas.getEnvironmentNote());
    }
    List<PersonType> perType = measType.getPerson();
    writePerson(perType, meas.getPersonBySubjectPersonId(), measured, mc, meas.getStartTime());
    for (Person person : meas.getPersons()) {
        writePerson(perType, person, experimenter, mc, null);
        log.debug("Written Person metadata: " + person);
    }

    List<DataType> dataType = measType.getData();
    if (meas.getDataFiles() != null) {
        for (DataFile data : datas) {
            log.debug("creating data into output xml: " + data.getFilename());
            DataType datat = of.createDataType();
            datat.setFileName(data.getFilename());
            if (mc.isSamplingRate()) {
                datat.setDescription(data.getDescription());
            }
            log.debug("Written file description: " + datat.getDescription());
            if (data.getFileMetadataParamVals() != null) {
                List<FileMetadataType> metType = datat.getFileMetadata();
                for (FileMetadataParamVal fileMetadata : data.getFileMetadataParamVals()) {
                    metType.add(mea.writeFileMetadata(fileMetadata, of));
                    log.debug("Written sampling rate and file metadata: " + fileMetadata);
                }
            }
            dataType.add(datat);
        }
    }

    Marshaller m = jc.createMarshaller();
    m.setProperty(Marshaller.JAXB_ENCODING, encoding);
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    //        m.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, XSDSchema);
    JAXBElement<MeasurationType> me = of.createMeasuration(measType);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    m.marshal(me, baos);
    log.debug("Written XML document into a ByteArrayOutputStream ");
    return baos;
}

From source file:mx.bigdata.sat.cfdi.CFDv32.java

public void guardar(OutputStream out) throws Exception {
    Marshaller m = context.createMarshaller();
    m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(localPrefixes));
    m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://www.sat.gob.mx/cfd/3  " + "http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv32.xsd");
    byte[] xmlHeaderBytes = XML_HEADER.getBytes("UTF8");
    out.write(xmlHeaderBytes);//from  w  w  w  .j ava 2 s  .c o  m
    m.marshal(document, out);
}

From source file:eu.learnpad.core.impl.cw.XwikiBridgeInterfaceRestResource.java

@Override
public void notifyRecommendations(String modelSetId, String simulationid, String userId, Recommendations rec)
        throws LpRestException {
    String contentType = "application/xml";

    HttpClient httpClient = this.getClient();
    String uri = String.format("%s/learnpad/cw/bridge/notify/%s", DefaultRestResource.REST_URI, modelSetId);

    PutMethod putMethod = new PutMethod(uri);
    putMethod.addRequestHeader("Accept", contentType);

    NameValuePair[] queryString = new NameValuePair[2];
    queryString[0] = new NameValuePair("simulationid", simulationid);
    queryString[1] = new NameValuePair("userid", userId);
    putMethod.setQueryString(queryString);

    try {// w  w w.j a  v a 2  s.c  om
        JAXBContext jc = JAXBContext.newInstance(Recommendations.class);
        Writer recWriter = new StringWriter();

        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(rec, recWriter);

        RequestEntity requestEntity = new StringRequestEntity(recWriter.toString(), contentType, "UTF-8");
        putMethod.setRequestEntity(requestEntity);

        httpClient.executeMethod(putMethod);
    } catch (JAXBException | IOException e) {
        throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause());
    }
}

From source file:esg.node.components.registry.LasSistersGleaner.java

public synchronized boolean saveLasServers(LasServers servers) {
    boolean success = false;
    if (servers == null) {
        log.error("LasServers is [" + servers + "]");
        return success;
    }/*from ww w. j ava  2  s  .co m*/
    log.trace("Saving LAS LasServers information to " + sistersPath + sistersFile);
    try {
        JAXBContext jc = JAXBContext.newInstance(LasServers.class);
        Marshaller m = jc.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(servers, new FileOutputStream(sistersPath + sistersFile));
        success = true;
    } catch (Exception e) {
        log.error(e);
    }

    return success;
}

From source file:com.bluexml.side.build.tools.reader.MavenProjectReader.java

/**
 * @return//from  www . j a v  a2s . c  om
 * @throws JAXBException
 * @throws PropertyException
 */

private static Unmarshaller getUnmarshaller(String packageName) throws JAXBException, PropertyException {
    JAXBContext jaxbContext = JAXBContext.newInstance(packageName);

    Marshaller alfrescoMarshaller = jaxbContext.createMarshaller();
    alfrescoMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    alfrescoMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
    Unmarshaller alfrescoUnmarshaller = jaxbContext.createUnmarshaller();

    return alfrescoUnmarshaller;
}

From source file:com.aionemu.packetsamurai.utils.collector.data.npcskills.NpcSkillsTool.java

public static void save() {
    ObjectFactory objFactory = new ObjectFactory();
    NpcSkillTemplates collection = objFactory.createNpcSkillTemplates();
    List<NpcSkillList> templateList = collection.getNpcskills();
    templateList.addAll(skillsByNpcId.values());
    Collections.sort(templateList);

    NpcSkillTemplate total = new NpcSkillTemplate();
    total.setSkillid(0);/*  w w w . ja v  a 2  s  .c  o  m*/

    List<NpcSkillList> toRemove = new ArrayList<NpcSkillList>();

    for (NpcSkillList skillList : templateList) {
        HashMap<IntRange, Integer> useCounts = new HashMap<IntRange, Integer>();
        HashMap<NpcSkillTemplate, Integer> skillCounts = new HashMap<NpcSkillTemplate, Integer>();
        NpcSkillTemplate totalAttacks = null;
        int index = 0;

        if (skillList.getNpcskill().contains(total)) {
            totalAttacks = skillList.getNpcskill().get(index);
            index = skillList.getNpcskill().indexOf(total);
            skillList.getNpcskill().remove(index);
        }

        int useTotal = 0;
        int skillUseTotal = 0;
        for (NpcSkillTemplate template : skillList.getNpcskill())
            skillUseTotal += template.getStats().useCount;

        if (totalAttacks != null) {
            useTotal = totalAttacks.getStats().useCount;
            if (skillUseTotal > useTotal)
                useTotal = skillUseTotal;
        } else {
            useTotal = skillUseTotal;
        }

        if (skillList.getNpcskill().size() == 0) {
            toRemove.add(skillList);
            continue;
        } else if (useTotal == 0) {
            // old data from XML
            continue;
        }

        for (NpcSkillTemplate template : skillList.getNpcskill()) {
            if (useTotal < MAX_HITS_PER_NPC) {
                if (template.getStats().maxHp > 90)
                    template.setMaxhp(100);
                else if (template.getMaxhp() == null || template.getMaxhp() < template.getStats().maxHp)
                    template.setMaxhp(template.getStats().maxHp);
                if (template.getStats().minHp < 10)
                    template.setMinhp(0);
                else if (template.getMinhp() == null || template.getMinhp() > template.getStats().minHp)
                    template.setMinhp(template.getStats().minHp);
            } else {
                IntRange hpRange = new IntRange(template.getStats().minHp, template.getStats().maxHp);
                if (useCounts.containsKey(hpRange)) {
                    int oldCounts = useCounts.get(hpRange);
                    useCounts.put(hpRange, oldCounts + template.getStats().useCount);
                } else
                    useCounts.put(hpRange, template.getStats().useCount);
                skillCounts.put(template, template.getStats().useCount);
            }

            if (useTotal >= MAX_HITS_PER_NPC)
                template.setProbability(Math.round((float) template.getStats().useCount * 100 / useTotal));
            else {
                template.setProbability(25);
            }
        }
    }

    templateList.removeAll(toRemove);

    try {
        JAXBContext jaxbContext = JAXBContext
                .newInstance("com.aionemu.packetsamurai.utils.collector.data.npcskills");
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(collection, new FileOutputStream("data/npc_skills/npc_skills.xml"));
    } catch (PropertyException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    PacketSamurai.getUserInterface().log("Skills [Npcs] - Saved : " + templateList.size() + " Npc Skills!");
}