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:dk.statsbiblioteket.doms.licensemodule.integrationtest.LicenseModuleRestWSTester.java

@SuppressWarnings("all")
private static void testCheckAccessForIds() throws Exception {
    CheckAccessForIdsInputDTO input = new CheckAccessForIdsInputDTO();
    input.setPresentationType("Search");
    input.setAttributes(createUserObjAttributeDTO());
    ArrayList<String> ids = new ArrayList<String>();
    ids.add("doms_radioTVCollection:uuid:371157ee-b120-4504-bfaf-364c15a4137c");//radio TV        
    ids.add("doms_radioTVCollection:uuid:c3386ed5-9b79-47a2-a648-8de53569e630");//radio TV
    ids.add("doms_reklamefilm:uuid:35a1aa76-97a1-4f1b-b5aa-ad2a246eeeec"); //reklame
    ids.add("doms_newspaperCollection:uuid:18709dea-802c-4bd7-98e6-32ca3b285774-segment_6"); //aviser      
    input.setIds(ids);//  w ww  .  j ava 2 s.c  o  m

    JAXBContext context = JAXBContext.newInstance(CheckAccessForIdsInputDTO.class);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    m.marshal(input, outputStream);

    // serialize to XML
    String inputXML = outputStream.toString();
    System.out.println(inputXML);
    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    WebResource service = client
            .resource(UriBuilder.fromUri("http://devel06:9612/licensemodule/services/").build());

    // Call with XML
    CheckAccessForIdsOutputDTO output = service.path("checkAccessForIds").type(MediaType.TEXT_XML)
            .accept(MediaType.TEXT_XML).entity(inputXML).post(CheckAccessForIdsOutputDTO.class);
    context = JAXBContext.newInstance(CheckAccessForIdsOutputDTO.class);
    outputStream = new ByteArrayOutputStream();
    m = context.createMarshaller();

    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    m.marshal(output, outputStream);

    // serialize to XML
    String outputXML = outputStream.toString();
    System.out.println(outputXML);

    System.out.println("query:" + output.getQuery());
    System.out.println("presentationtype:" + output.getPresentationType());
    System.out.println("number of IDs:" + output.getAccessIds().size());
}

From source file:dk.statsbiblioteket.doms.licensemodule.integrationtest.LicenseModuleRestWSTester.java

@SuppressWarnings("all")
private static void testValidateAccess() throws Exception {
    // Test Validate Access
    ValidateAccessInputDTO input = new ValidateAccessInputDTO();

    ArrayList<UserObjAttributeDTO> userObjAttributes = createUserObjAttributeDTO();
    input.setAttributes(userObjAttributes);

    ArrayList<String> groups = new ArrayList<String>();
    groups.add("IndividueltForbud");
    groups.add("Klausuleret");
    input.setGroups(groups);/*from w  w  w. j a v  a 2  s .  com*/
    input.setPresentationType("images");

    JAXBContext context = JAXBContext.newInstance(ValidateAccessInputDTO.class);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    m.marshal(input, outputStream);

    // serialize to XML
    String inputXML = outputStream.toString();
    System.out.println("input xml:\n" + inputXML);

    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    WebResource service = client
            .resource(UriBuilder.fromUri("http://localhost:8080/licensemodule/services/").build());

    // Call with XML
    ValidateAccessOutputDTO output = service.path("validateAccess").type(MediaType.TEXT_XML)
            .accept(MediaType.TEXT_XML).entity(inputXML).post(ValidateAccessOutputDTO.class);

    // Call with @XmlRootElement
    // output = service.path("validateAccess").type(MediaType.TEXT_XML).accept(MediaType.TEXT_XML).entity(input).post(ValidateAccessOutputDTO.class);

    context = JAXBContext.newInstance(ValidateAccessOutputDTO.class);
    outputStream = new ByteArrayOutputStream();
    m = context.createMarshaller();

    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    m.marshal(output, outputStream);

    // serialize to XML
    String outputXML = outputStream.toString();
    System.out.println(outputXML);

    // Access depends on the licenses in the DB.
    System.out.println("access :" + output.isAccess());
}

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

public static String getExecutionworkitemString(String urlServer, String projectAreaAlias, String encoding,
        String testCaseId, String testPlanId) throws JAXBException {

    // Workitem/* w  w w .  ja  va  2  s . com*/
    com.ibm.rqm.xml.bind.Executionworkitem.Testcase workTest = new com.ibm.rqm.xml.bind.Executionworkitem.Testcase();
    workTest.setHref(urlServer + "resources/" + projectAreaAlias + "/testcase/" + testCaseId);

    // Testplan
    com.ibm.rqm.xml.bind.Executionworkitem.Testplan testPlan = new com.ibm.rqm.xml.bind.Executionworkitem.Testplan();
    testPlan.setHref(
            urlServer + "resources/" + projectAreaAlias + "/testplan/urn:com.ibm.rqm:testplan:" + testPlanId);

    // Criao do Execution Work Item
    Executionworkitem work = new Executionworkitem();
    work.setFrequency("Once");
    work.setRegression(false);
    work.setTitle("Registro de Execuo Automatizado - Plano de Teste " + testPlanId);
    work.setWeight(100);
    work.setTestcase(workTest);
    work.setTestplan(testPlan);

    JAXBContext jaxb = JAXBContext.newInstance(Executionworkitem.class);
    Marshaller marshaller = jaxb.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);
    StringWriter resourceString = new StringWriter();
    marshaller.marshal(work, resourceString);

    return resourceString.toString();
}

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 www  .  jav  a  2s .com*/
                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:com.silverpeas.admin.components.Instanciateur.java

public static void saveComponent(WAComponent waComponent, String fileName, boolean workflow)
        throws JAXBException {
    JAXBContext context = JAXBContext.newInstance("com.silverpeas.admin.components");
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://silverpeas.org/xml/ns/component http://www.silverpeas.org/xsd/component.xsd");
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    String path = getXMLPackage() + File.separatorChar;
    if (workflow) {
        path += "workflows" + File.separatorChar;
    }/*from   w w  w.ja  v  a2s . c o  m*/
    File file = new File(path + fileName);
    marshaller.marshal(objectFactory.createWAComponent(waComponent), file);
}

From source file:ee.ria.xroad.proxy.serverproxy.MetadataServiceHandlerImpl.java

private static void marshal(Object object, Node out) throws Exception {
    Marshaller marshaller = JAXB_CTX.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    marshaller.marshal(object, out);/*  w ww  . j a  v  a  2s  .com*/
}

From source file:gov.nih.nci.ncicb.tcga.dcc.common.jaxb.JAXBUtil.java

private static String getMetaDataXMLAsString(final JAXBContext jaxbContext, final Object jaxbObject)
        throws JAXBException {

    // Create an unmarshaller
    final Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

    // Marshal the JAXB object meta-data into XML and return the result
    final StringWriter stringWriter = new StringWriter();
    marshaller.marshal(jaxbObject, stringWriter);

    return stringWriter.toString();
}

From source file:com.redhat.akashche.wixgen.cli.Launcher.java

private static void writeXml(Marshaller marshaller, Object jaxbElement, String path, boolean fragment)
        throws Exception {
    Writer writer = null;/*  w  w w  .  j  a v  a2  s . c o m*/
    try {
        OutputStream os = new FileOutputStream(new File(path));
        writer = new OutputStreamWriter(os, Charset.forName("UTF-8"));
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, fragment);
        marshaller.marshal(jaxbElement, writer);
    } finally {
        closeQuietly(writer);
    }
}

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

public static String getTestcaseString(String urlServer, String projectAreaAlias, String encoding, String name,
        String steps, Testcase currentTestCase) throws JAXBException {

    Richtext textDesgin = new Richtext();
    textDesgin.getContent().add(escapeHTMLForAlm(steps));

    currentTestCase.setTitle(name);/*from  ww  w.java 2s .  c  o m*/
    currentTestCase.setSuspect(false);
    currentTestCase.setWeight(100);
    currentTestCase.setComIbmRqmPlanningEditorSectionTestCaseDesign(textDesgin);

    // Valor da Categoria
    String categoryTipoExecucao = BehaveConfig.getIntegration_CategoryTipoExecucao();

    // Verifica se no caso de teste vindo da ALM existe a categoria
    // "Tipo de Execuo", se no existe cria.
    boolean objExists = false;
    for (Testcase.Category c : currentTestCase.getCategory()) {
        if (c.getTerm().toLowerCase().trim().equals("tipo de execuo")) {
            objExists = true;
            // Altera para "Automtica"
            c.setValue(categoryTipoExecucao);
            break;
        }
    }

    if (!objExists) {
        Testcase.Category newC = new Testcase.Category();
        newC.setTerm("Tipo de Execuo");
        newC.setValue(categoryTipoExecucao);
        currentTestCase.getCategory().add(newC);
    }

    JAXBContext jaxb = JAXBContext.newInstance(Testcase.class);
    Marshaller marshaller = jaxb.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);
    StringWriter testCaseString = new StringWriter();
    marshaller.marshal(currentTestCase, testCaseString);

    return testCaseString.toString();
}

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

public static String getExecutionresultString(String urlServer, String projectAreaAlias, String encoding,
        String executionWorkItemUrl, ScenarioState stateOf, Date _startDate, Date _endDate, String details)
        throws JAXBException, DatatypeConfigurationException {

    Date startDate = (Date) _startDate.clone();
    Date endDate = (Date) _endDate.clone();

    com.ibm.rqm.xml.bind.Executionresult.Executionworkitem workTest = new com.ibm.rqm.xml.bind.Executionresult.Executionworkitem();
    workTest.setHref(executionWorkItemUrl);

    State state = new State();
    Executionresult result = new Executionresult();
    if (stateOf.equals(ScenarioState.FAILED)) {
        state.setContent("com.ibm.rqm.execution.common.state.failed");
    } else {//from w  w  w .ja v a2s .c  o  m
        if (stateOf.equals(ScenarioState.PENDING)) {
            state.setContent("com.ibm.rqm.execution.common.state.blocked");
        } else {
            state.setContent("com.ibm.rqm.execution.common.state.passed");
        }
    }

    result.setState(state);
    result.setExecutionworkitem(workTest);

    // Datas de incio e fim do teste
    GregorianCalendar c = new GregorianCalendar();
    c.setTime(startDate);
    XMLGregorianCalendar startDateXml = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
    result.setStarttime(startDateXml);

    c.setTime(endDate);
    XMLGregorianCalendar endDateXml = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
    result.setEndtime(endDateXml);

    // Details
    Details d = new Details();
    d.getContent().add(details);
    result.setDetails(d);

    JAXBContext jaxb = JAXBContext.newInstance(Executionresult.class);
    Marshaller marshaller = jaxb.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);
    StringWriter resourceString = new StringWriter();
    marshaller.marshal(result, resourceString);

    return resourceString.toString();
}