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.exist.xquery.RestBinariesTest.java
private HttpResponse postXquery(final String xquery) throws JAXBException, IOException { final Query query = new Query(); query.setText(xquery);/*from www . jav a 2 s.c o m*/ final JAXBContext jaxbContext = JAXBContext.newInstance("org.exist.http.jaxb"); final Marshaller marshaller = jaxbContext.createMarshaller(); final HttpResponse response; try (final FastByteArrayOutputStream baos = new FastByteArrayOutputStream()) { marshaller.marshal(query, baos); response = executor.execute(Request.Post(getRestUrl() + "/db/").bodyByteArray(baos.toByteArray(), ContentType.APPLICATION_XML)).returnResponse(); } if (response.getStatusLine().getStatusCode() != SC_OK) { throw new IOException( "Unable to query, HTTP response code: " + response.getStatusLine().getStatusCode()); } return response; }
From source file:hydrograph.ui.engine.util.ConverterUtil.java
/** * Store file into workspace.//from w w w . j a va2s . c o m * * @param graph the graph * @param outPutFile the out put file * @param out the out * @throws JAXBException the JAXB exception * @throws CoreException the core exception */ private void storeFileIntoWorkspace(Graph graph, boolean validate, IFile outPutFile, ByteArrayOutputStream out) throws JAXBException, CoreException { 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); /* * To-do will be removed in future * String updatedXML=escapeXml(out.toString()); out.reset(); try { if(!unknownComponentLists.isEmpty()) out.write(updatedXML.getBytes()); } catch (IOException ioException) { LOGGER.error("Unable to update escape sequene in xml file",ioException); }*/ if (outPutFile.exists()) { outPutFile.setContents(new ByteArrayInputStream(out.toByteArray()), true, false, null); } else { outPutFile.create(new ByteArrayInputStream(out.toByteArray()), true, null); } }
From source file:com.healthcit.cacure.businessdelegates.export.DataExportTest.java
@Test public void testConstructFormXML() throws JAXBException { assertNotNull(dataExport);/* w w w.jav a 2 s.c om*/ JAXBContext jc = JAXBContext.newInstance("com.healthcit.cacure.export.model"); Marshaller m = jc.createMarshaller(); //long formId = 9712; //long formId = 9724; long formId = 9731; //long formId = 9833; Cure xml = dataExport.constructFormXML(formId); //Cure xml = dataExport.constructFormXML(9724); //Cure xml = dataExport.constructFormXML(9731); //m.marshal(xml, new File("C:\\temp\\caure-9724.xml")); m.marshal(xml, new File("C:\\temp\\cure-" + formId + ".xml")); }
From source file:net.sf.taverna.t2.maven.plugins.TavernaProfileGenerateMojo.java
/** * Generates the application profile file. * * @return the <code>File</code> that the application profile has been written to * @throws JAXBException/*from w w w. j a v a 2s. c o m*/ * if the application profile cannot be created * @throws MojoExecutionException */ private File createApplicationProfile() throws JAXBException, MojoExecutionException { String groupId = project.getGroupId(); String artifactId = project.getArtifactId(); String version = maven2OsgiConverter.getVersion(project.getVersion()); if (version.endsWith("SNAPSHOT")) { version = version.substring(0, version.indexOf("SNAPSHOT")) + buildNumber; } tempDirectory.mkdirs(); File applicationProfileFile = new File(tempDirectory, APPLICATION_PROFILE_FILE); ApplicationProfile applicationProfile = new ApplicationProfile(); applicationProfile.setId(groupId + "." + artifactId); applicationProfile.setName(project.getName()); applicationProfile.setVersion(version); Updates updates = new Updates(); updates.setUpdateSite(updateSite); updates.setUpdatesFile(updatesFile); updates.setLibDirectory(libDirectory); updates.setPluginSite(pluginSite); updates.setPluginsFile(pluginsFile); applicationProfile.setUpdates(updates); List<FrameworkConfiguration> frameworkConfiguration = applicationProfile.getFrameworkConfiguration(); for (FrameworkConfiguration configuration : frameworkConfigurations) { frameworkConfiguration.add(configuration); } Set<BundleArtifact> bundleDependencies = osgiUtils.getBundleDependencies(Artifact.SCOPE_COMPILE, Artifact.SCOPE_RUNTIME); List<BundleInfo> runtimeBundles = osgiUtils.getBundles(bundleDependencies); if (!runtimeBundles.isEmpty()) { List<BundleInfo> bundles = applicationProfile.getBundle(); for (BundleInfo bundle : runtimeBundles) { bundles.add(bundle); } } JAXBContext jaxbContext = JAXBContext.newInstance(ApplicationProfile.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, SCHEMA_LOCATION); marshaller.marshal(applicationProfile, applicationProfileFile); return applicationProfileFile; }
From source file:it.cnr.icar.eric.server.cms.AbstractContentManagementService.java
/** * Gets the <code>RegistryObjectType</code> as a stream of XML markup. * * @param ebRegistryObjectType an <code>RegistryObjectType</code> value * @return a <code>StreamSource</code> value * @exception RegistryException if an error occurs *///from w w w . j av a 2 s .c o m protected StreamSource getAsStreamSource(RegistryObjectType ebRegistryObjectType) throws RegistryException { log.debug("getAsStreamSource(RegistryObjectType) entered"); StreamSource src = null; try { StringWriter sw = new StringWriter(); Marshaller marshaller = bu.getJAXBContext().createMarshaller(); /* * marshal JAXBElement Identifiable */ JAXBElement<IdentifiableType> ebIdentifiable = bu.rimFac.createIdentifiable(ebRegistryObjectType); marshaller.marshal(ebIdentifiable, sw); StringReader reader = new StringReader(sw.toString()); src = new StreamSource(reader); } // these Exceptions should already be caught by Binding catch (JAXBException e) { throw new RegistryException(e); } return src; }
From source file:eu.impress.impressplatform.IntegrationLayer.ResourcesMgmt.BedAvailabilityServiceBean.java
@Override public String getBedAvailablityHAVE(String hospitalname) { String hospitalstatushave;/*ww w . j a va2 s. c om*/ BedStats bedStats = bedService.getHospitalAvailableBeds(hospitalname); HospitalStatus hospitalStatus = beansTransformation.BedStatstoHAVE(bedStats); try { JAXBContext jaxbContext = JAXBContext.newInstance(HospitalStatus.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); //jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); StringWriter sw = new StringWriter(); //marshal the envelope jaxbMarshaller.marshal(hospitalStatus, sw); hospitalstatushave = sw.toString(); } catch (JAXBException e) { e.printStackTrace(); return "Error Marshalling XML Object" + HttpStatus.INTERNAL_SERVER_ERROR; } return hospitalstatushave; }
From source file:eu.impress.impressplatform.IntegrationLayer.ResourcesMgmt.BedAvailabilityServiceBean.java
@Override public String createBedAvailabilityDE() throws DatatypeConfigurationException { String DEmessageenvelope = ""; String DEmessage = ""; EDXLDistribution ed = EDXLlib.createEDXLEnvelope(); try {// ww w .java2s . c o m JAXBContext jaxbContext = JAXBContext.newInstance(EDXLDistribution.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); //jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); StringWriter sw = new StringWriter(); //marshal the envelope jaxbMarshaller.marshal(ed, sw); DEmessageenvelope = sw.toString(); //could not unescape characters no matter what! //encapsulate the edxl have message into DE by avoiding jaxb //DEmessage = EDXLlib.DEEncapsulation(DEmessageenvelope, edxlhave); DEmessage = DEmessageenvelope; } catch (JAXBException e) { e.printStackTrace(); return "Error Marshalling XML Object" + HttpStatus.INTERNAL_SERVER_ERROR; } return DEmessage; }
From source file:edu.umd.ks.cm.util.spring.CmToSisExportAdvice.java
@Transactional(readOnly = false, noRollbackFor = { DoesNotExistException.class }, rollbackFor = { Throwable.class }) private void doWorkflowDocument(CourseInfo courseInfo, ContextInfo contextInfo) { try {//from w ww . java2 s. c o m String principalId = SecurityUtils.getCurrentPrincipalId(); // Creating xml element with all info CourseModifyAuditInfo course = getCourseModifyAuditInfo(courseInfo, principalId, contextInfo); JAXBContext context = JAXBContext.newInstance(CourseModifyAuditInfo.class); Marshaller marshaller = context.createMarshaller(); StringWriter writer = new StringWriter(); marshaller.marshal(course, writer); String appContent = writer.toString(); // Creating a document and sending to Workflow to "Final" state // 2.0 upgrade - based on code in KualiStudentPostProcessorBase line 119 WorkflowDocument document = WorkflowDocumentFactory.createDocument(principalId, "kuali.admin.type.course.modify"); document.setApplicationContent(appContent); document.saveDocument(""); document.approve("Audit course change to approve"); } catch (Exception e) { LOG.error("Error doWorkflowDocument with courseId: " + courseInfo.getId(), e); } }
From source file:com.azaptree.services.command.http.WebXmlRequestCommand.java
@Override protected void writeResponseMessage(final HttpServletResponse httpResponse, final Object message) { Assert.notNull(httpResponse, "httpResponse is required"); Assert.notNull(message, "message is required"); final Optional<JAXBContext> jaxbContext = getJaxbContext(); Assert.isTrue(jaxbContext.isPresent(), "JAXBContext is required"); httpResponse.setContentType("application/xml"); httpResponse.setCharacterEncoding("UTF-8"); Marshaller marshaller; try {// w ww .j ava 2 s .c o m marshaller = jaxbContext.get().createMarshaller(); } catch (final JAXBException e) { throw new IllegalStateException("failed to create JAXB marshaller", e); } try { marshaller.marshal(message, httpResponse.getOutputStream()); } catch (JAXBException | IOException e) { throw new RuntimeException("Failed to write JAXB message response", e); } }
From source file:TwitterRetrieval.java
private void Twitter2XML(PostsType posts, PrintWriter out) throws Exception { JAXBContext context = JAXBContext.newInstance("entities"); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(posts, out); }