List of usage examples for javax.xml.bind Marshaller marshal
public void marshal(Object jaxbElement, javax.xml.stream.XMLEventWriter writer) throws JAXBException;
From source file:org.hisp.dhis.dxf2.importsummary.ImportSummaryTest.java
@Test public void marshallImportSummary() throws Exception { ImportSummary summary = new ImportSummary(); summary.setDescription("Testing"); summary.setStatus(ImportStatus.SUCCESS); summary.setDataValueCount(new ImportCount(2, 1, 4)); JAXBContext jaxbContext = JAXBContext.newInstance(ImportSummary.class); Marshaller jaxbmarshaller = jaxbContext.createMarshaller(); jaxbmarshaller.marshal(summary, System.out); }
From source file:com.fujitsu.dc.test.utils.DavResourceUtils.java
/** * BoxACL?./*from w ww . j a v a 2s .c o m*/ * <p> * * <pre> * Acl acl = new Acl(); * acl.getAce().add(DavResourceUtils.createAce(false, roleRead, "read")); * acl.getAce().add(DavResourceUtils.createAce(false, roleWrite, "write")); * acl.setXmlbase(String.format("%s/%s/__role/%s/", * UrlUtils.getBaseUrl(), CELL_NAME, Box.DEFAULT_BOX_NAME)); * DavResourceUtils.setAcl(MASTER_TOKEN, CELL_NAME, BOX_NAME, COL_NAME, acl, HttpStatus.SC_OK); * </pre> * </p> * @param token * @param cell ?? * @param box ?? * @param col ?? * @param acl ?ACL * @param code ? * @return ? * @throws JAXBException ACL???????? */ public static TResponse setAcl(String token, String cell, String box, String col, Acl acl, int code) throws JAXBException { StringWriter writer = new StringWriter(); JAXBContext context = JAXBContext.newInstance(Acl.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(acl, writer); return Http.request("box/acl-setting-none-body.txt").with("cell", cell).with("box", box) .with("colname", col).with("token", token).with("body", writer.toString()).returns().debug() .statusCode(code); }
From source file:StringAdapter.java
private void demo(String xml) throws JAXBException { StringReader stringReader = new StringReader(xml); Unmarshaller unmarshaller = jc.createUnmarshaller(); Root root = (Root) unmarshaller.unmarshal(stringReader); System.out.println("ITEM: " + root.getItem()); System.out.print("OUTPUT: "); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); marshaller.marshal(root, System.out); }
From source file:org.openmrs.module.dhisreport.api.model.ReportTemplatesTest.java
@Test public void marshallReportTemplates() throws Exception { ClassPathResource resource = new ClassPathResource("templates_ethiopia.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(ReportTemplates.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); ReportTemplates reportTemplates = (ReportTemplates) jaxbUnmarshaller.unmarshal(resource.getInputStream()); Collection<DataValueTemplate> dvts = reportTemplates.getReportDefinitions().get(1).getDataValueTemplates(); for (DataValueTemplate dvt : dvts) { dvt.setQuery("select count(*) from something & something_else"); }// w ww.java 2 s .c o m Marshaller jaxbmarshaller = jaxbContext.createMarshaller(); jaxbmarshaller.marshal(reportTemplates, System.out); }
From source file:edu.wisc.http.converter.xml.JaxbMarshallingHttpMessageConverter.java
@Override protected void writeToResult(Object o, HttpHeaders headers, Result result) throws IOException { try {//from ww w. j a v a2s . co m final Marshaller marshaller = this.jaxbContext.createMarshaller(); marshaller.marshal(o, result); } catch (JAXBException e) { throw new HttpMessageNotWritableException("Could not write [" + o + "]", e); } }
From source file:org.openmrs.module.dhisreport.api.DHIS2ReportingServiceDXFTest.java
@Ignore @Test//from w w w . j a va2 s.c o m public void postDhisReportTest() throws Exception { HttpDhis2Server server = new HttpDhis2Server(); server.setUsername("admin"); server.setPassword("district"); server.setUrl(new URL("http://apps.dhis2.org/dev")); service.setDhis2Server(server); ClassPathResource resource = new ClassPathResource("dvset.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(DataValueSet.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); DataValueSet dvset = (DataValueSet) jaxbUnmarshaller.unmarshal(resource.getInputStream()); ImportSummary summary = service.postDataValueSet(dvset); JAXBContext importSummaryContext = JAXBContext.newInstance(ImportSummary.class); Marshaller jaxbmarshaller = importSummaryContext.createMarshaller(); jaxbmarshaller.marshal(summary, System.out); }
From source file:se.inera.intyg.intygstjanst.web.integration.converter.SendMessageToCareConverter.java
public String convertToXmlString(SendMessageToCareType sendMessageToCareType) throws JAXBException { ObjectFactory objectFactory = new ObjectFactory(); JAXBContext jaxbContext = JAXBContext.newInstance(SendMessageToCareType.class); Marshaller marshaller = jaxbContext.createMarshaller(); StringWriter stringWriter = new StringWriter(); marshaller.marshal(objectFactory.createSendMessageToCare(sendMessageToCareType), stringWriter); return stringWriter.toString().replaceAll("[\\n\\t ]", ""); }
From source file:org.springframework.hateoas.ResourceIntegrationTest.java
/** * @see #124/*from w ww .j a va 2 s . c o m*/ * @see #154 */ @Test public void marshalsResourceToXml() throws Exception { Person person = new Person(); person.firstname = "Dave"; person.lastname = "Matthews"; PersonResource resource = new PersonResource(person); resource.add(new Link("/foo", "bar")); JAXBContext context = JAXBContext.newInstance(PersonResource.class, Person.class); StringWriter writer = new StringWriter(); Marshaller marshaller = context.createMarshaller(); marshaller.marshal(resource, writer); assertThat(new Diff(XML_REFERENCE, writer.toString()).similar(), is(true)); }
From source file:ait.ffma.service.preservation.riskmanagement.api.riskanalysis.risk.RiskUtils.java
/** * This method writes java object to XML file * //from w ww .ja v a 2 s.c om * @param object * The Java object that should be converted to XML format * @param filePath * The path to the place where created XML file should be stored */ public static void storeRiskDataInXML(Object object, String filePath) { try { FileWriter fileWriter = new FileWriter(filePath); try { JAXBContext context = JAXBContext.newInstance(object.getClass()); Marshaller marshaller = context.createMarshaller(); marshaller.marshal(object, fileWriter); fileWriter.close(); } finally { fileWriter.close(); } } catch (JAXBException e) { LOG.log(Level.SEVERE, e.getMessage()); } catch (IOException e) { LOG.log(Level.SEVERE, e.getMessage()); } }
From source file:com.virtualparadigm.packman.processor.JPackageManager.java
private static void marshallToFile(Collection<Package> packages, String filePath) { try {/* w ww . j av a 2s. com*/ Marshaller marshaller = jaxbContext.createMarshaller(); // removes the xml header: marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); StringWriter stringWriter = new StringWriter(); for (Package installedPackage : packages) { marshaller.marshal( new JAXBElement<Package>(new QName(null, "package"), Package.class, installedPackage), stringWriter); stringWriter.append("\n"); } FileUtils.writeStringToFile(new File(filePath), stringWriter.toString(), "UTF-8"); } catch (Exception e) { logger.error("", e); } }