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:ee.ria.xroad.common.hashchain.HashChainVerifier.java
/** Downloads data from the URI and runs transforms on it. */ private InputStream performTransforms(String uri, TransformsType transforms) throws Exception { LOG.trace("performTransforms({}, {})", uri, transforms); JAXBElement<TransformsType> transformsElement = new ObjectFactory().createTransforms(transforms); // Create the Document DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.newDocument(); Marshaller marshaller = jaxbCtx.createMarshaller(); marshaller.marshal(transformsElement, document); Transforms tr = new Transforms(document.getDocumentElement(), null); XMLSignatureInput before = new XMLSignatureInput(referenceResolver.resolve(uri)); XMLSignatureInput after = tr.performTransforms(before); return after.getOctetStream(); }
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); out = ComponentXpath.INSTANCE.addParameters(out); }
From source file:com.wavemaker.tools.project.upgrade.swamis.ServiceBeanFileUpgrade.java
@Override public void doUpgrade(Project project, UpgradeInfo upgradeInfo) { DesignServiceManager dsm = DesignTimeUtils.getDesignServiceManager(project); List<String> touchedProjects = new ArrayList<String>(); for (Service service : dsm.getServices()) { if (service.getSpringFile() == null) { // create the service bean file File serviceBeanFile = dsm.getServiceBeanXmlFile(service.getId()); if (!serviceBeanFile.exists()) { try { DesignServiceManager.generateSpringServiceConfig(service.getId(), service.getClazz(), dsm.getDesignServiceType(service.getType()), serviceBeanFile, project); } catch (JAXBException e) { throw new WMRuntimeException(e); } catch (IOException e) { throw new WMRuntimeException(e); }//from w w w .j ava2 s . c o m } // edit the servicedef File serviceDefFile = dsm.getServiceDefXmlFile(service.getId()); service.setSpringFile(serviceBeanFile.getName()); Marshaller marshaller; try { marshaller = definitionsContext.createMarshaller(); marshaller.setProperty("jaxb.formatted.output", true); Writer writer = serviceDefFile.getContent().asWriter(); try { marshaller.marshal(service, writer); } finally { writer.close(); } } catch (Exception e) { throw new WMRuntimeException(e); } // finally, add this to the list of modified services touchedProjects.add(service.getId()); } } if (!touchedProjects.isEmpty()) { upgradeInfo.addVerbose("Converted bean definitions to a separate file for services: " + StringUtils.join(touchedProjects, ", ")); } }
From source file:com.bitplan.jaxb.JaxbFactory.java
/** * get the string representation of the given marshaller * /* w w w.j ava 2s.co m*/ * @param marshaller * @param instance * @return the string representation for the given marshaller * @throws JAXBException */ public String getString(Marshaller marshaller, T instance) throws JAXBException { StringWriter sw = new StringWriter(); marshaller.marshal(instance, sw); String result = sw.toString(); return result; }
From source file:hydrograph.ui.engine.util.ConverterUtil.java
/** * Store file into local file system./*from ww w .ja v a2s .c om*/ * * @param graph * @param externalOutputFile * @param out * @throws CoreException the core exception * @throws JAXBException the JAXB exception * @throws IOException Signals that an I/O exception has occurred. */ private void storeFileIntoLocalFileSystem(Graph graph, boolean validate, IFileStore externalOutputFile, ByteArrayOutputStream out) throws CoreException, JAXBException, IOException { File externalFile = externalOutputFile.toLocalFile(0, null); OutputStream outputStream = new FileOutputStream(externalFile.getAbsolutePath().replace(".job", ".xml")); JAXBContext jaxbContext = JAXBContext.newInstance(graph.getClass()); Marshaller marshaller = jaxbContext.createMarshaller(); out = new ByteArrayOutputStream(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(graph, out); out = ComponentXpath.INSTANCE.addParameters(out); out.writeTo(outputStream); outputStream.close(); }
From source file:vitro.vgw.communication.idas.IdasProxyImpl.java
private Object sendRequest(Object request) throws VitroGatewayException { Object result = null;//from w ww .j a v a 2 s .co m InputStream instream = null; try { HttpPost httpPost = new HttpPost(endPoint); JAXBContext jaxbContext = Utils.getJAXBContext(); Marshaller mar = jaxbContext.createMarshaller(); mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); ByteArrayOutputStream baos = new ByteArrayOutputStream(); mar.marshal(request, baos); String requestXML = baos.toString(HTTP.UTF_8); StringEntity entityPar = new StringEntity(requestXML, "application/xml", HTTP.UTF_8); httpPost.setEntity(entityPar); HttpResponse response = httpclient.execute(httpPost); HttpEntity entity = response.getEntity(); if (entity != null) { instream = entity.getContent(); Unmarshaller unmarshaller = Utils.getJAXBContext().createUnmarshaller(); Object idasResponse = unmarshaller.unmarshal(instream); if (idasResponse instanceof ExceptionReport) { throw Utils.parseException((ExceptionReport) idasResponse); } result = idasResponse; } else { throw new VitroGatewayException("Server response does not contain any body"); } } catch (VitroGatewayException e) { throw e; } catch (Exception e) { throw new VitroGatewayException(e); } finally { if (instream != null) { try { instream.close(); } catch (IOException e) { logger.error("Error while closing server response stream", e); } } } return result; }
From source file:com.redhat.akashche.wixgen.dir.DirectoryGeneratorTest.java
@Test public void test() throws Exception { // emulate externally provided conf file String json = GSON.toJson(ImmutableMap.builder().put("appName", "Test Wix Application") .put("versionMajor", "0").put("versionMinor", "1").put("versionPatch", "0") .put("vendor", "Test Vendor") .put("licenseFilePath", "src/test/resources/com/redhat/akashche/wixgen/dir/LICENSE.rtf") .put("iconPath", "src/test/resources/com/redhat/akashche/wixgen/dir/test_icon.ico") .put("topBannerBmpPath", "src/test/resources/com/redhat/akashche/wixgen/dir/top_banner.bmp") .put("greetingsBannerBmpPath", "src/test/resources/com/redhat/akashche/wixgen/dir/greetings_banner.bmp") .put("registryKeys", ImmutableList.builder().add(ImmutableMap.builder().put("root", "HKCU") .put("key", "Software\\Test Wix Application") .put("values", ImmutableList.builder() .add(ImmutableMap.builder().put("type", "string").put("name", "Application Name") .put("value", "Test Application").build()) .add(ImmutableMap.builder().put("type", "integer").put("name", "Version Minor") .put("value", "1").build()) .add(ImmutableMap.builder().put("type", "string").put("name", "Test Path") .put("value", "[INSTALLDIR]src\\test\\resources\\com").build()) .build())/*from www . ja va2 s .c om*/ .build()).build()) .put("environmentVariables", ImmutableList.builder() .add(ImmutableMap.builder().put("name", "TEST_WIX_VAR").put("action", "create") .put("value", "Test Wix Var Contents").build()) .add(ImmutableMap.builder().put("name", "PATH").put("action", "set") .put("value", "[INSTALLDIR]src\\test\\resources\\com\\redhat").build()) .build()) .build()); WixConfig conf = GSON.fromJson(json, WixConfig.class); Wix wix = new DirectoryGenerator().createFromDir(new File("src"), conf); JAXBContext jaxb = JAXBContext.newInstance(Wix.class.getPackage().getName()); Marshaller marshaller = jaxb.createMarshaller(); marshaller.setProperty(JAXB_FORMATTED_OUTPUT, true); Writer writer = null; try { OutputStream os = new FileOutputStream("target/test.wxs"); writer = new OutputStreamWriter(os, Charset.forName("UTF-8")); marshaller.marshal(wix, writer); } finally { closeQuietly(writer); } marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); try { OutputStream os = new FileOutputStream("target/components.xml"); writer = new OutputStreamWriter(os, Charset.forName("UTF-8")); Directory dir = findWixDirectory(wix); marshaller.marshal(dir, writer); } finally { closeQuietly(writer); } try { OutputStream os = new FileOutputStream("target/feature.xml"); writer = new OutputStreamWriter(os, Charset.forName("UTF-8")); Feature dir = findWixFeature(wix); marshaller.marshal(dir, writer); } finally { closeQuietly(writer); } }
From source file:org.javelin.sws.ext.bind.jaxb.JaxbTest.java
@Test(expected = IllegalAnnotationsException.class) public void marshalIllegalProperties() throws Exception { JAXBContext ctx = JAXBContext.newInstance(org.javelin.sws.ext.bind.jaxb.context5.MyClassJ5_1.class); Marshaller m = ctx.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); org.javelin.sws.ext.bind.jaxb.context5.MyClassJ5_1 mc5 = new org.javelin.sws.ext.bind.jaxb.context5.MyClassJ5_1(); mc5.setC(String.class); m.marshal(new JAXBElement<org.javelin.sws.ext.bind.jaxb.context5.MyClassJ5_1>(new QName("a", "a"), org.javelin.sws.ext.bind.jaxb.context5.MyClassJ5_1.class, mc5), System.out); }
From source file:com.moss.nomad.core.packager.Packager.java
public void write(OutputStream o) throws Exception { JarOutputStream out = new JarOutputStream(o); {// w w w . ja v a2s .c o m ByteArrayOutputStream bao = new ByteArrayOutputStream(); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(container, bao); byte[] containerIndex = bao.toByteArray(); JarEntry entry = new JarEntry("META-INF/container.xml"); out.putNextEntry(entry); out.write(containerIndex); } final byte[] buffer = new byte[1024 * 10]; //10k buffer for (String path : dependencies.keySet()) { ResolvedDependencyInfo info = dependencies.get(path); JarEntry entry = new JarEntry(path); out.putNextEntry(entry); InputStream in = new FileInputStream(info.file()); for (int numRead = in.read(buffer); numRead != -1; numRead = in.read(buffer)) { out.write(buffer, 0, numRead); } in.close(); } out.close(); }
From source file:cz.lbenda.dataman.db.DbConfig.java
/** Save session conf into File * @param writer writer to which is configuration saved */ public void save(Writer writer) throws IOException { cz.lbenda.dataman.schema.dataman.ObjectFactory of = new cz.lbenda.dataman.schema.dataman.ObjectFactory(); SessionType st = storeToSessionType(null, null); try {/*from w ww .j ava2s.com*/ JAXBContext jc = JAXBContext.newInstance(cz.lbenda.dataman.schema.dataman.ObjectFactory.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(of.createSession(st), writer); } catch (JAXBException e) { LOG.error("Problem with write configuration: " + e.toString(), e); throw new RuntimeException("Problem with write configuration: " + e.toString(), e); } }