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:com.jaspersoft.jasperserver.rest.services.RESTPermission.java
private String generatePermissionUsingJaxb(List<ObjectPermission> permissions) { try {/*from w ww . j a va 2 s . c o m*/ StringWriter sw = new StringWriter(); JAXBList<ObjectPermission> lst; lst = new JAXBList<ObjectPermission>(permissions); Marshaller m = restUtils.getMarshaller(JAXBList.class, ObjectPermissionImpl.class, UserImpl.class, RoleImpl.class); m.marshal(lst, sw); if (log.isDebugEnabled()) { log.debug("finished marshaling permissions: " + lst.size()); } return sw.toString(); } catch (JAXBException e) { throw new ServiceException(e.getMessage()); } }
From source file:org.github.alexwibowo.opentext.client.AxiomVRDClient.java
@Override public List<DocumentMetadata> getMetadata(List<String> recordAttributesToBeRetrieved, List<String> attributesToBeRetrieved, List<ConditionType> conditions, Long maximumRecordsToRetrieve) throws Exception { DataSource dataSource = new DataSource(); QueryType queryType = new QueryType(); queryType.setAction(ActionType.SELECT); queryType.setSource("#DEFAULT_FILEPLAN#"); if (!recordAttributesToBeRetrieved.isEmpty() || !attributesToBeRetrieved.isEmpty()) { queryType.setAttrs(new QueryType.Attrs()); for (String recordAttribute : recordAttributesToBeRetrieved) { queryType.getAttrs().getRecordAttr().add(recordAttribute); }// ww w . jav a 2 s . c o m for (String attribute : attributesToBeRetrieved) { queryType.getAttrs().getAttr().add(attribute); } } if (!conditions.isEmpty()) { queryType.setConditions(new QueryType.Conditions()); for (ConditionType condition : conditions) { queryType.getConditions().getCondition().add(condition); } } dataSource.getQuery().add(queryType); StringWriter sw = new StringWriter(); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(dataSource, sw); Execute execute = new Execute(); execute.setLicense(""); execute.setXmlRequest(sw.toString()); SOAPMessageBuilder soap11MessageBuilder = new AxiomSOAP11MessageBuilder(jaxbContext, soap11Factory) .withPayload(execute).withUsernameToken(configuration.getUsername(), configuration.getPassword()); SOAPEnvelope envelope = (SOAPEnvelope) soap11MessageBuilder.build(); HttpResponse httpResponse = simplePost(envelope, VRDOperationQName.Execute.getQName()); if (httpResponse.getEntity() != null && httpResponse.getEntity().getContent() != null) { InputStream in = httpResponse.getEntity().getContent(); SOAPEnvelope response = OMXMLBuilderFactory.createSOAPModelBuilder(in, "UTF-8").getSOAPEnvelope(); OMElement retrieveContentResponse = response.getBody().getFirstElement(); OMElement content = retrieveContentResponse.getFirstElement(); DataSource dataSourceResult = new VRDXmlUtil(jaxbContext).parseResponse(content.getText()); return convertToVRDMetadata(dataSourceResult.getQueryResult()); } return null; }
From source file:org.remus.marketplace.servlets.FeaturedListing.java
@Override public void handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { String marketId = arg0.getParameter("marketId"); arg1.setContentType("text/xml"); int categoryId = 0; try {//from ww w . ja v a2 s.co m categoryId = Integer.parseInt(arg0.getParameter("categoryId")); } catch (Exception e1) { // do nothing } if (categoryId != 0) { Category category2search = categoryDao.findById(categoryId); if (category2search != null) { try { JAXBContext newInstance = JAXBContext.newInstance(Marketplace.class, org.remus.marketplace.xml.Market.class); Marketplace marketplace = new Marketplace(); List<Node> findByCategoriesId = nodeDao.find(new AdvancedCriteria().setMaxResults(10) .addRestriction(Restrictions.eq(Node.FOUNDATIONMEMBER, 1)) .addSubCriteria(new AdvancedCriteria().setAssosication(Node.CATEGORIES) .addRestriction(Restrictions.eq(Category.ID, category2search.getId())))); Featured featured = new Featured(); featured.setCount(findByCategoriesId.size()); for (Node findById : findByCategoriesId) { org.remus.marketplace.xml.Node node = XMLBuilder.buildNode(serverPrefix, findById); featured.getNode().add(node); } marketplace.setFeatured(featured); Marshaller createMarshaller = newInstance.createMarshaller(); XMLSerializer xmlSerializer = XMLBuilder.getXMLSerializer(arg1.getOutputStream()); createMarshaller.marshal(marketplace, xmlSerializer.asContentHandler()); } catch (JAXBException e) { throw new ServletException(e); } } else { throw new ServletException("Category not found"); } } else if (marketId != null && marketId.trim().length() > 0) { try { JAXBContext newInstance = JAXBContext.newInstance(Marketplace.class, org.remus.marketplace.xml.Market.class); List<Category> findByMarketId = categoryDao.findByMarketId(marketId, null); if (findByMarketId.size() == 0) { throw new ServletException("market id not matching"); } List<Integer> categoryIds = new ArrayList<Integer>(); for (Category category : findByMarketId) { categoryIds.add(category.getId()); } Marketplace marketplace = new Marketplace(); List<Node> findByCategoriesId = nodeDao.find(new AdvancedCriteria().setMaxResults(10) .addRestriction( Restrictions.eq(Node.FOUNDATIONMEMBER, 1)) .addSubCriteria(new AdvancedCriteria().setAssosication(Node.CATEGORIES) .addRestriction(Restrictions.in(Category.ID, categoryIds)))); Featured featured = new Featured(); featured.setCount(findByCategoriesId.size()); for (Node findById : findByCategoriesId) { org.remus.marketplace.xml.Node node = XMLBuilder.buildNode(serverPrefix, findById); featured.getNode().add(node); } marketplace.setFeatured(featured); Marshaller createMarshaller = newInstance.createMarshaller(); XMLSerializer xmlSerializer = XMLBuilder.getXMLSerializer(arg1.getOutputStream()); createMarshaller.marshal(marketplace, xmlSerializer.asContentHandler()); } catch (JAXBException e) { throw new ServletException(e); } } else { try { JAXBContext newInstance = JAXBContext.newInstance(Marketplace.class, org.remus.marketplace.xml.Market.class); Marketplace marketplace = new Marketplace(); List<Node> findByCategoriesId = nodeDao.find(new AdvancedCriteria() .addRestriction(Restrictions.eq(Node.FOUNDATIONMEMBER, 1)).setMaxResults(10)); Featured featured = new Featured(); featured.setCount(findByCategoriesId.size()); for (Node findById : findByCategoriesId) { org.remus.marketplace.xml.Node node = XMLBuilder.buildNode(serverPrefix, findById); featured.getNode().add(node); } marketplace.setFeatured(featured); Marshaller createMarshaller = newInstance.createMarshaller(); XMLSerializer xmlSerializer = XMLBuilder.getXMLSerializer(arg1.getOutputStream()); createMarshaller.marshal(marketplace, xmlSerializer.asContentHandler()); } catch (JAXBException e) { throw new ServletException(e); } } }
From source file:com.tremolosecurity.openunison.util.OpenUnisonUtils.java
private static void storeMethod(String unisonXMLFile, TremoloType tt, String ksPath, KeyStore ks) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, JAXBException, PropertyException { logger.info("Storing the keystore"); ks.store(new FileOutputStream(ksPath), tt.getKeyStorePassword().toCharArray()); logger.info("Saving the unison xml file"); JAXBContext jc = JAXBContext.newInstance("com.tremolosecurity.config.xml"); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); OutputStream os = new FileOutputStream(unisonXMLFile); JAXBElement<TremoloType> root = new JAXBElement<TremoloType>( new QName("http://www.tremolosecurity.com/tremoloConfig", "tremoloConfig", "tns"), TremoloType.class, tt); marshaller.marshal(root, os); os.flush();//from w w w .j a v a2s .c o m os.close(); }
From source file:org.kemri.wellcome.dhisreport.api.model.HttpDhis2Server.java
@Override public ImportSummary postReport(DataValueSet report) throws DHIS2ReportingException { log.debug("Posting datavalueset report"); ImportSummary summary = null;//from w w w. j a v a 2 s . co m StringWriter xmlReport = new StringWriter(); try { JAXBContext jaxbDataValueSetContext = JAXBContext.newInstance(DataValueSet.class); Marshaller dataValueSetMarshaller = jaxbDataValueSetContext.createMarshaller(); // output pretty printed dataValueSetMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); dataValueSetMarshaller.marshal(report, xmlReport); } catch (JAXBException ex) { log.error(ex.getMessage()); throw new Dxf2Exception("Problem marshalling dataValueSet", ex); } String host = getUrl().getHost(); int port = getUrl().getPort(); HttpHost targetHost = new HttpHost(host, port, getUrl().getProtocol()); DefaultHttpClient httpclient = new DefaultHttpClient(); BasicHttpContext localcontext = new BasicHttpContext(); try { String postUrl = getUrl().toString() + DATAVALUESET_PATH; log.error("Post URL: " + postUrl); HttpPost httpPost = new HttpPost(postUrl); Credentials creds = new UsernamePasswordCredentials(username, password); Header bs = new BasicScheme().authenticate(creds, httpPost, localcontext); httpPost.addHeader("Authorization", bs.getValue()); httpPost.addHeader("Content-Type", "application/xml; charset=utf-8"); httpPost.addHeader("Accept", "application/xml"); httpPost.setEntity(new StringEntity(xmlReport.toString())); HttpResponse response = httpclient.execute(targetHost, httpPost, localcontext); HttpEntity entity = response.getEntity(); if (entity != null) { JAXBContext jaxbImportSummaryContext = JAXBContext.newInstance(ImportSummary.class); Unmarshaller importSummaryUnMarshaller = jaxbImportSummaryContext.createUnmarshaller(); summary = (ImportSummary) importSummaryUnMarshaller.unmarshal(entity.getContent()); } } catch (Exception ex) { log.error(ex.getMessage()); throw new Dhis2Exception(this, "Problem accessing Dhis2 server", ex); } finally { httpclient.getConnectionManager().shutdown(); } return summary; }
From source file:org.kemri.wellcome.dhisreport.api.impl.DHIS2ReportingServiceImpl.java
@Override public void marshallReportTemplates(OutputStream os, ReportTemplates rt) throws Exception { JAXBContext jaxbContext = JAXBContext.newInstance(ReportTemplates.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(rt, os); }
From source file:com.u2apple.tool.dao.DeviceXmlDaoJaxbImpl.java
private void flushDevices() throws JAXBException, PropertyException { if (isDeviceChanged) { File file = new File(Configuration.getProperty(Constants.DEVICES_XML)); JAXBContext jaxbContext = JAXBContext.newInstance(StaticMapFile.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(getStaticMapFile(), file); isDeviceChanged = false;/*from w w w .j a v a2s . c o m*/ } }
From source file:esg.common.security.PolicyGleaner.java
public synchronized boolean savePolicyAs(Policies policy, String policyFileLocation) { boolean success = false; if (policy == null) { log.error("Sorry internal policy representation is null ? [" + policy + "] perhaps you need to load policy file first?"); return success; }/*from w w w . ja v a 2s . c o m*/ log.info("Saving policy information to " + policyFileLocation); try { JAXBContext jc = JAXBContext.newInstance(Policies.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(policy, new FileOutputStream(policyFileLocation)); success = true; } catch (Exception e) { log.error(e); } return success; }
From source file:tools.xor.logic.DefaultStoredProcedure.java
private void outputSP(AggregateView view) throws JAXBException, UnsupportedEncodingException { javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(AggregateView.class); javax.xml.bind.Marshaller marshaller = jaxbCtx.createMarshaller(); marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8"); //NOI18N marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(view, System.out); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); marshaller.marshal(view, bOut);// w ww. jav a2 s .com bOut.toString("UTF-8"); }
From source file:de.intevation.test.irixservice.UploadReportTest.java
@Test(expected = UploadReportException.class) public void testInvalidDokpool() throws UploadReportException, JAXBException { ReportType report = getReportFromFile(VALID_REPORT); DokpoolMeta meta = new DokpoolMeta(); meta.setDokpoolContentType("Invalid doc"); DOMResult res = new DOMResult(); Element ele = null;/*from ww w. j a va2 s . c o m*/ JAXBContext jaxbContext = JAXBContext.newInstance(DokpoolMeta.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); jaxbMarshaller.marshal(meta, res); ele = ((Document) res.getNode()).getDocumentElement(); report.getAnnexes().getAnnotation().get(0).getAny().add(ele); testObj.uploadReport(report); }