List of usage examples for javax.xml.bind Unmarshaller unmarshal
public Object unmarshal(javax.xml.stream.XMLEventReader reader) throws JAXBException;
From source file:eu.apenet.dpt.standalone.gui.eaccpf.EacCpfFrame.java
public void createFrame(InputStream eacCpfStream, boolean isNew) { timeMaintenance = null;/*from www. ja v a2 s .c o m*/ personResponsible = null; inUse(true); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { inUse(false); } }); EacCpf eacCpf = null; try { JAXBContext jaxbContext = JAXBContext.newInstance(EacCpf.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); eacCpf = (EacCpf) jaxbUnmarshaller.unmarshal(eacCpfStream); eacCpfStream.close(); } catch (Exception e) { e.printStackTrace(); } this.buildPanel(eacCpf, isNew); this.getContentPane().add(mainTabbedPane); Dimension frameDim = new Dimension(((Double) (dimension.getWidth() * 0.95)).intValue(), ((Double) (dimension.getHeight() * 0.95)).intValue()); this.setSize(frameDim); this.setPreferredSize(frameDim); this.pack(); this.setVisible(true); this.setExtendedState(JFrame.MAXIMIZED_BOTH); }
From source file:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.PresentationWSDaoImplTest.java
@SuppressWarnings("unchecked") private JAXBElement<BlackboardPresentationResponseCollection> getSinglePresentation() throws JAXBException { final JAXBContext context = JAXBContext.newInstance("com.elluminate.sas"); final Unmarshaller unmarshaller = context.createUnmarshaller(); JAXBElement<BlackboardPresentationResponseCollection> response = (JAXBElement<BlackboardPresentationResponseCollection>) unmarshaller .unmarshal(this.getClass() .getResourceAsStream("/data/singleListRepositoryPresentationResponseCollection.xml")); return response; }
From source file:com.siberhus.geopoint.restclient.GeoPointRestClient.java
/** * /*from ww w .jav a 2 s . co m*/ * @param ipAddr * @param format * @return */ public IpInfo query(String ipAddr, Format format) { Assert.notNull("apiKey", apiKey); Assert.notNull("secret", secret); Assert.notNull("ipAddr", ipAddr); Assert.notNull("format", format); MessageDigest digest = null; try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { // should not happen throw new RuntimeException(e); } String formatStr = format == Format.XML ? "xml" : "json"; long timeInSeconds = (long) (System.currentTimeMillis() / 1000); String input = apiKey + secret + timeInSeconds; digest.update(input.getBytes()); String signature = String.format("%032x", new BigInteger(1, digest.digest())); String url = serviceUrl + ipAddr + "?apikey=" + apiKey + "&sig=" + signature + "&format=" + formatStr; log.debug("Calling Quova ip2loc service from URL: {}", url); DefaultHttpClient httpclient = new DefaultHttpClient(); // Create an HTTP GET request HttpGet httpget = new HttpGet(url); // Execute the request httpget.getRequestLine(); HttpResponse response = null; try { response = httpclient.execute(httpget); } catch (IOException e) { throw new HttpRequestException(e); } HttpEntity entity = response.getEntity(); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != 200) { throw new HttpRequestException(status.getReasonPhrase()); } // Print the response log.debug("Response status: {}", status); StringBuilder responseText = new StringBuilder(); if (entity != null) { try { InputStream inputStream = entity.getContent(); // Process the response BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = bufferedReader.readLine()) != null) { responseText.append(line); } bufferedReader.close(); } catch (IOException e) { throw new HttpRequestException(e); } } // shut down the connection manager to ensure // immediate deallocation of all system resources. httpclient.getConnectionManager().shutdown(); IpInfo ipInfo = null; if (format == Format.XML) { JAXBContext context; try { context = JAXBContext.newInstance(IpInfo.class); Unmarshaller um = context.createUnmarshaller(); ipInfo = (IpInfo) um.unmarshal(new StringReader(responseText.toString())); } catch (JAXBException e) { throw new ResultParseException(e); } } else { ObjectMapper mapper = new ObjectMapper(); try { ipInfo = mapper.readValue(new StringReader(responseText.toString()), IpInfoWrapper.class) .getIpInfo(); } catch (IOException e) { throw new ResultParseException(e); } } return ipInfo; }
From source file:fr.fastconnect.factory.tibco.bw.maven.compile.ArchiveBuilder.java
private Repository load(File f) { try {//from ww w .j a v a 2 s . c o m JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Object o = jaxbUnmarshaller.unmarshal(f); return (Repository) o; } catch (JAXBException e) { e.printStackTrace(); } return null; }
From source file:org.jasig.portlet.maps.dao.GoogleMyMapsDaoImpl.java
@Override @Cacheable("mapCache") public MapData getMap(String selectedMapDataUrl) { //todo change this method to use the string passed in final MapData map = new MapData(); // read a Google My Maps KML feed from the local filesystem and parse // it using JAXB Kml kml = null;/*from w w w .j a v a 2 s . c o m*/ try { JAXBContext jc = JAXBContext.newInstance(Kml.class); Unmarshaller u = jc.createUnmarshaller(); kml = (Kml) u.unmarshal(kmlFile.getInputStream()); } catch (JAXBException e) { log.error("Failed to parse KML file", e); } catch (FileNotFoundException e) { log.error("Failed to locate KML file", e); } catch (IOException e) { log.error("IO Exception reading KML file", e); } final Document doc = (Document) kml.getDocument(); // iterate through the list of styles building up a map of style IDs // to category names final Map<String, String> styles = new HashMap<String, String>(); for (Style style : doc.getStyle()) { if (!styles.containsKey(style.getId())) { final String iconUrl = style.getIconStyle().getIcon().getHref(); if (categories.containsKey(iconUrl)) { styles.put("#".concat(style.getId()), categories.get(iconUrl)); } } } final AntiSamy as = new AntiSamy(); // iterate through the list of placemarks, constructing a location for // each item int index = 0; for (final Placemark placemark : doc.getPlacemark()) { // create a new location, setting the name and description final Location location = new Location(); location.setName(placemark.getName()); try { final CleanResults cr = as.scan(placemark.getDescription(), policy); location.setDescription(cr.getCleanHTML()); } catch (ScanException e) { log.warn("Exception scanning description", e); } catch (PolicyException e) { log.warn("Exception cleaning description", e); } if (this.addresses != null && this.addresses.containsKey(placemark.getName())) { location.setAddress(this.addresses.get(placemark.getName())); } // set the coordinates for the location final String[] coordinates = placemark.getPoint().getCoordinates().split(","); location.setLatitude(new BigDecimal(Double.parseDouble(coordinates[1]))); location.setLongitude(new BigDecimal(Double.parseDouble(coordinates[0]))); // set the abbreviation to the index number just so we have a // unique ID location.setAbbreviation(String.valueOf(index)); index++; // if the style ID is mapped to a map category, add the category // to this location if (styles.containsKey(placemark.getStyleUrl())) { location.getCategories().add(styles.get(placemark.getStyleUrl())); } map.getLocations().add(location); } postProcessData(map); return map; }
From source file:org.openmrs.module.dhisreport.web.controller.LocationMappingController.java
public Metadata getDHIS2OrganizationUnits() throws Exception { String username = Context.getAdministrationService().getGlobalProperty("dhisreport.dhis2UserName"); String password = Context.getAdministrationService().getGlobalProperty("dhisreport.dhis2Password"); String dhisurl = Context.getAdministrationService().getGlobalProperty("dhisreport.dhis2URL"); String url = dhisurl + "/api/organisationUnits.xml?fields=name,code&paging=false"; // String url = "https://play.dhis2.org/demo/api/dataSets"; // String referer = webRequest.getHeader( "Referer" ); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet(url); getRequest.addHeader("accept", "application/xml"); getRequest.addHeader(// www. j av a2s. c o m BasicScheme.authenticate(new UsernamePasswordCredentials(username, password), "UTF-8", false)); HttpResponse response; InputStream is = null; Metadata metadata = null; try { response = httpClient.execute(getRequest); is = response.getEntity().getContent(); // String result = getStringFromInputStream( is ); // System.out.println( result + "\n" ); JAXBContext jaxbContext = JAXBContext.newInstance(Metadata.class); javax.xml.bind.Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); metadata = (Metadata) jaxbUnmarshaller.unmarshal(is); return metadata; } catch (ClientProtocolException e) { log.debug("ClientProtocolException occured : " + e.toString()); e.printStackTrace(); } finally { is.close(); } return metadata; }
From source file:edu.cornell.med.icb.goby.modes.StatsMode.java
private void loadInfo() { try {/*from w w w . ja v a 2 s .c om*/ final JAXBContext jc = JAXBContext.newInstance(InfoOutput.class); final Unmarshaller m = jc.createUnmarshaller(); InfoOutput info = (InfoOutput) m.unmarshal(new File(infoFilename)); for (AnnotationLength ae : info.lengths) { int index = deCalculator.getElementIndex(ae.id); if (index != -1) { deCalculator.defineElementLength(index, ae.length); } else { // OK since some elements will yield zero counts and not be in the input. } } for (SampleTotalCount tc : info.totalCounts) { deCalculator.setNumAlignedInSample(tc.sampleId, tc.totalCount); } } catch (JAXBException e) { System.err.printf("An error occurred loading the content of info file %s %n", infoFilename); e.printStackTrace(); System.exit(1); } }
From source file:vitro.vgw.communication.idas.IdasProxyImpl.java
private Object sendRequest(String request) throws VitroGatewayException { Object result = null;/* ww w . j a v a 2s. co m*/ InputStream instream = null; try { HttpPost httpPost = new HttpPost(endPoint); StringEntity entityPar = new StringEntity(request, "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:ru.cti.gosuslugi.service.client.OffenceInfoServiceClient.java
private OffenceInfoForProgrammaticSystems getOffenceInfoList(String response) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException, TransformerFactoryConfigurationError, TransformerException, JAXBException { Document responseDocument = buildXmlDocumentFromString(response); XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); NodeList nodeList = (NodeList) xpath.evaluate("//Body/*", responseDocument, XPathConstants.NODESET); StringWriter sw = new StringWriter(); if (serializer == null) serializer = TransformerFactory.newInstance().newTransformer(); serializer.transform(new DOMSource(nodeList.item(0)), new StreamResult(sw)); String res = sw.toString();// www. j av a 2 s . c o m logger.debug("offence body: {}", res); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); return (OffenceInfoForProgrammaticSystems) unmarshaller .unmarshal(new ByteArrayInputStream(res.getBytes("UTF-8"))); }
From source file:com.mgmtp.perfload.loadprofiles.ui.ctrl.ConfigController.java
public void loadActiveSettings() { checkState(activeSettingsFile != null, "No active settings file set."); Reader r = null;/* w w w . j a va2 s. com*/ File file = new File(settingsDir, activeSettingsFile); try { r = new InputStreamReader(new FileInputStream(file), "UTF-8"); JAXBContext context = JAXBContext.newInstance(Settings.class); Unmarshaller m = context.createUnmarshaller(); activeSettings = (Settings) m.unmarshal(r); } catch (JAXBException ex) { String msg = "Error unmarshalling contents from file: " + file; throw new LoadProfileException(msg, ex); } catch (IOException ex) { throw new LoadProfileException(ex.getMessage(), ex); } finally { Closeables.closeQuietly(r); } }