List of usage examples for javax.xml.xpath XPathConstants NODE
QName NODE
To view the source code for javax.xml.xpath XPathConstants NODE.
Click Source Link
The XPath 1.0 NodeSet data type.
From source file:de.ingrid.iplug.opensearch.converter.IngridRSSConverter.java
/** * Set an IngridHitDetail with data that is needed by default. * //from w w w . j a v a 2 s . com * @param hit * @param item * @param groupedBy * @throws XPathExpressionException */ private void setIngridHitDetail(IngridHit hit, Node item, String groupedBy) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); // get plug id Node node = (Node) xpath.evaluate("plugid", item, XPathConstants.NODE); if (node != null) { hit.setPlugId(node.getTextContent()); } // get doc id hit.setDocumentId(getDocumentId(item)); // ===================================================================== // the following must be put into the HitDetail // this detail will be put into a cache and returned when getDetail() // is called // ===================================================================== IngridHitDetail hitDetail = new IngridHitDetail(hit, (String) hit.get("title"), (String) hit.get("abstract")); node = (Node) xpath.evaluate("timeReference/start", item, XPathConstants.NODE); if (node != null) { hitDetail.put("t1", node.getTextContent()); } node = (Node) xpath.evaluate("timeReference/stop", item, XPathConstants.NODE); if (node != null) { hitDetail.put("t2", node.getTextContent()); } // set partner and provider setPartnerAndProvider(hitDetail, item); // get box node = (Node) xpath.evaluate("box", item, XPathConstants.NODE); if (node != null) { String[] box = node.getTextContent().split(" "); hitDetail.put("x1", box[0]); hitDetail.put("y1", box[0]); hitDetail.put("x2", box[0]); hitDetail.put("y2", box[0]); } // add grouping information if (groupedBy != null) { String groupInfos = null; if (IngridQuery.GROUPED_BY_PARTNER.equalsIgnoreCase(groupedBy)) { String[] partner = (String[]) hitDetail.get("partner"); if (partner != null && partner.length > 0) groupInfos = partner[0]; } else if (IngridQuery.GROUPED_BY_ORGANISATION.equalsIgnoreCase(groupedBy)) { String[] provider = (String[]) hitDetail.get("provider"); if (provider != null && provider.length > 0) groupInfos = provider[0]; } else if (IngridQuery.GROUPED_BY_DATASOURCE.equalsIgnoreCase(groupedBy)) { groupInfos = (String) hit.get("url"); try { groupInfos = new URL(groupInfos).getHost(); } catch (MalformedURLException e) { log.warn("can not group url: " + groupInfos, e); } } if (groupInfos != null) { hit.addGroupedField(groupInfos); } } // add some important default values hitDetail.setDocumentId(hit.getDocumentId()); hitDetail.setPlugId(hit.getPlugId()); hitDetail.setDataSourceId(hit.getDataSourceId()); hitDetail.put("url", hit.get("url")); // put detail into cache cache.put(new Element(hit.getDocumentId(), hitDetail)); }
From source file:org.eclipse.lyo.testsuite.oslcv2.ServiceProviderCatalogXmlTests.java
@Test public void catalogRootIsRdfNamespaceDeclaration() throws XPathException { // Make sure our root element is the RDF namespace declarations Node rootNode = (Node) OSLCUtils.getXPath().evaluate("/rdf:RDF", doc, XPathConstants.NODE); assertNotNull(rootNode);/* w ww . ja va2 s.c o m*/ }
From source file:com.adaptris.util.text.xml.XPath.java
/** * Selects a single Node based on the supplied Xpath * * @param context the root node to query * @param xpath the xpath to apply//from ww w. j a va 2 s .co m * @return the Node extracted * @throws XPathExpressionException on error. */ public Node selectSingleNode(Node context, String xpath) throws XPathExpressionException { return (Node) createXpath().evaluate(xpath, context, XPathConstants.NODE); }
From source file:com.esri.gpt.server.openls.provider.services.geocode.GeocodeProvider.java
/** * Reads Address Information from request * @param reqParams/*from w w w . j a v a 2s . c om*/ * @param ndReq * @param xpath * @throws XPathExpressionException */ public void parseRequest(GeocodeParams reqParams, Node ndReq, XPath xpath) throws XPathExpressionException { NodeList ndAddresses = (NodeList) xpath.evaluate("xls:Address", ndReq, XPathConstants.NODESET); if (ndAddresses != null) { for (int i = 0; i < ndAddresses.getLength(); i++) { Node address = ndAddresses.item(i); if (address != null) { Address addr = new Address(); Node ndStrAddr = (Node) xpath.evaluate("xls:StreetAddress", address, XPathConstants.NODE); if (ndStrAddr != null) { Node ndStr = (Node) xpath.evaluate("xls:Street", ndStrAddr, XPathConstants.NODE); if (ndStr != null) { addr.setStreet(ndStr.getTextContent()); } } Node ndPostalCode = (Node) xpath.evaluate("xls:PostalCode", address, XPathConstants.NODE); if (ndPostalCode != null) { addr.setPostalCode(ndPostalCode.getTextContent()); } NodeList ndPlaces = (NodeList) xpath.evaluate("xls:Place", address, XPathConstants.NODESET); if (ndPlaces != null) { for (int j = 0; j < ndPlaces.getLength(); j++) { Node ndPlace = ndPlaces.item(j); String type = Val .chkStr((String) xpath.evaluate("@type", ndPlace, XPathConstants.STRING)); addr.setPlaceType(type); if (type.equalsIgnoreCase("Municipality")) { addr.setMunicipality(ndPlace.getTextContent()); } else if (type.equalsIgnoreCase("CountrySubdivision")) { addr.setCountrySubdivision(ndPlace.getTextContent()); } else if (type.equalsIgnoreCase("BuildingNumber")) { addr.setBuildingNumber(ndPlace.getTextContent()); } else if (type.equalsIgnoreCase("Intersection")) { addr.setIntersection(ndPlace.getTextContent()); } else if (type.equalsIgnoreCase("StreetVec")) { addr.setStreetVec(ndPlace.getTextContent()); } } } reqParams.getAddresses().add(addr); } } } }
From source file:com.vimeo.VimeoUploadClient.java
public VimeoUploadClient(String apiKey, String secret) throws IOException, APIException { saveToken = false; // no save token verbose = true; // be verbose checkStatusOnly = false; // we want upload this.apiKey = apiKey; this.secret = secret; /**// w w w .jav a 2 s.co m * read .vimeo-uploader */ FileInputStream in1 = null; Properties properties = null; try { File f = new File(System.getProperty("user.home"), VimeoUploadClient.CONFIG_FILE); properties = new Properties(); if (f.createNewFile()) { properties.put("apiKey", apiKey); properties.put("secret", secret); properties.store(new FileOutputStream(f), "vimeo-uploader configuration file"); } in1 = new FileInputStream(f); properties.load(in1); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { in1.close(); } try { service = new ServiceBuilder().provider(VimeoApi.class).apiKey(properties.getProperty("apiKey")) .apiSecret(properties.getProperty("secret")).build(); } catch (Exception e) { System.out.println(e.getMessage() + "\nCheck Your configuration file (" + CONFIG_FILE + ")"); return; } /** * try read saved token */ accessToken = readToken(); if (accessToken == null) { if (verbose) System.out.println("Fetching the Request Token..."); Token token = service.getRequestToken(); System.out.println("Got the Request Token!"); System.out.println(); if (verbose) System.out.println("Fetching the Authorization URL..."); String authURL = service.getAuthorizationUrl(token); if (verbose) System.out.println("Got the Authorization URL!"); System.out.println("Now go and authorize Scribe here:"); System.out.println(authURL + "&permission=write"); System.out.println("And paste the authorization code here"); System.out.print(">>"); // TODO: SCRIBE AUTHORIZATION GETTED THE FIRST TIME Verifier verifier = new Verifier("land-5zbo4"); System.out.println(); // Trade the Request Token and Verfier for the Access Token if (verbose) System.out.println("Trading the Request Token for an Access Token..."); accessToken = service.getAccessToken(token, verifier); if (verbose) System.out.println("Got the Access Token!"); if (saveToken) { saveToken(accessToken); } if (verbose) { System.out.println("(if your curious it looks like this [token, secret]: " + accessToken + " )"); System.out.println(); } } // get logged username ResponseWrapper response = call("vimeo.test.login", null); String username = (((Node) path(response.getResponse().getBody(), "//username", XPathConstants.NODE)) .getTextContent()); System.out.printf("%-30S: %s\n", "Logged", username); // TODO: Get User name from Vimeo: xstain1981 -> user14301672 // get free storage space in bytes response = call("vimeo.videos.upload.getQuota", null); String free = ((Node) path(response.getResponse().getBody(), "//upload_space", XPathConstants.NODE)) .getAttributes().getNamedItem("free").getNodeValue(); System.out.printf("%-30S: %s MB\n", "Free Storage Space", Double.parseDouble(free) / 1024 / 1024); // TODO: Get free storage (new Vimeo Account has 500.MB (January 2013)) }
From source file:aurelienribon.gdxsetupui.ProjectUpdate.java
private void writeClasspath(File classpathFile, List<ClasspathEntry> classpath) { try {/*from w w w . java 2 s . c o m*/ Document doc = XmlUtils.createParser().parse(classpathFile); Node root = (Node) XmlUtils.xpath("classpath", doc, XPathConstants.NODE); NodeList libsNodes = (NodeList) XmlUtils.xpath("classpath/classpathentry[@kind='lib' and @path]", doc, XPathConstants.NODESET); for (int i = 0; i < libsNodes.getLength(); i++) { root.removeChild(libsNodes.item(i)); } for (ClasspathEntry entry : classpath) { Element elem = doc.createElement("classpathentry"); root.appendChild(elem); elem.setAttribute("kind", "lib"); if (entry.exported) elem.setAttribute("exported", "true"); elem.setAttribute("path", entry.path); if (entry.sourcepath != null) elem.setAttribute("sourcepath", entry.sourcepath); } XmlUtils.clean(doc); String str = XmlUtils.transform(doc); FileUtils.writeStringToFile(classpathFile, str); } catch (SAXException ex) { throw new RuntimeException(ex); } catch (IOException ex) { throw new RuntimeException(ex); } catch (TransformerException ex) { throw new RuntimeException(ex); } }
From source file:io.takari.maven.testing.executor.junit.MavenVersionResolver.java
private List<Repository> getRepositories(TestProperties properties) throws Exception { Map<String, Credentials> credentials = getCredentials(properties); List<Repository> repositories = new ArrayList<>(); for (String property : properties.getRepositories()) { InputSource is = new InputSource(new StringReader("<repository>" + property + "</repository>")); Element repository = (Element) xpathFactory.newXPath() // .compile("/repository") // .evaluate(is, XPathConstants.NODE); String url = getChildValue(repository, "url"); if (url == null) { continue; // malformed test.properties }//from w ww.j a v a2s.com if (!url.endsWith("/")) { url = url + "/"; } String id = getChildValue(repository, "id"); repositories.add(new Repository(new URL(url), credentials.get(id))); } return repositories; }
From source file:de.bayern.gdi.services.CatalogService.java
/** * retrieves a Map of ServiceNames and URLs for a Filter-Word. * * @param filter the Word to filter to/* w ww .j av a 2s . c o m*/ * @return Map of Service Names and URLs * @throws URISyntaxException if URL is wrong * @throws IOException if something in IO is wrong */ public List<Service> getServicesByFilter(String filter) throws URISyntaxException, IOException { List<Service> services = new ArrayList<>(); if (filter.length() > MIN_SEARCHLENGTH && this.getRecordsURL != null) { String search = loadXMLFilter(filter); Document xml = XML.getDocument(this.getRecordsURL, this.userName, this.password, search, true); Node exceptionNode = (Node) XML.xpath(xml, "//ows:ExceptionReport", XPathConstants.NODE, this.context); if (exceptionNode != null) { String exceptionCode = (String) XML.xpath(xml, "//ows:ExceptionReport/ows:Exception/@exceptionCode", XPathConstants.STRING, this.context); String exceptionlocator = (String) XML.xpath(xml, "//ows:ExceptionReport/ows:Exception/@locator", XPathConstants.STRING, this.context); String exceptiontext = (String) XML.xpath(xml, "//ows:ExceptionReport/ows:Exception/ows:ExceptionText", XPathConstants.STRING, this.context); String excpetion = "An Excpetion was thrown by the CSW: \n"; excpetion += "\texceptionCode: " + exceptionCode + "\n"; excpetion += "\tlocator: " + exceptionlocator + "\n"; excpetion += "\texceptiontext: " + exceptiontext + "\n"; LOG.error(excpetion, xml); return services; } String nodeListOfServicesExpr = "//csw:SearchResults//gmd:MD_Metadata"; NodeList servicesNL = (NodeList) XML.xpath(xml, nodeListOfServicesExpr, XPathConstants.NODESET, this.context); services = parseServices(servicesNL); } return services; }
From source file:gov.nij.bundles.intermediaries.ers.EntityResolutionMessageHandlerTest.java
@Test public void testPerformEntityResolutionWithDetermFactors() throws Exception { XmlConverter converter = new XmlConverter(); converter.getDocumentBuilderFactory().setNamespaceAware(true); InputStream attributeParametersStream = getClass() .getResourceAsStream("/xml/TestAttributeParametersWithDeterm.xml"); entityResolutionMessageHandler.setAttributeParametersStream(attributeParametersStream); testRequestMessageInputStream = getClass() .getResourceAsStream("/xml/EntityMergeRequestMessageForDeterm.xml"); Document testRequestMessage = converter.toDOMDocument(testRequestMessageInputStream); Node entityContainerNode = testRequestMessage .getElementsByTagNameNS(EntityResolutionNamespaceContext.ER_EXT_NAMESPACE, "EntityContainer") .item(0);/* w ww .j ava 2 s . c o m*/ assertNotNull(entityContainerNode); Document resultDocument = entityResolutionMessageHandler.performEntityResolution(entityContainerNode, null, null); resultDocument.normalizeDocument(); // LOG.info(converter.toString(resultDocument)); XPath xp = XPathFactory.newInstance().newXPath(); xp.setNamespaceContext(new EntityResolutionNamespaceContext()); NodeList entityNodes = (NodeList) xp.evaluate("//merge-result:EntityContainer/merge-result-ext:Entity", resultDocument, XPathConstants.NODESET); assertEquals(2, entityNodes.getLength()); entityNodes = (NodeList) xp.evaluate("//merge-result-ext:MergedRecord", resultDocument, XPathConstants.NODESET); assertEquals(2, entityNodes.getLength()); entityNodes = (NodeList) xp.evaluate("//merge-result-ext:OriginalRecordReference", resultDocument, XPathConstants.NODESET); assertEquals(2, entityNodes.getLength()); for (int i = 0; i < entityNodes.getLength(); i++) { Element e = (Element) entityNodes.item(i); String entityIdRef = e.getAttributeNS(EntityResolutionNamespaceContext.STRUCTURES_NAMESPACE, "ref"); assertNotNull(entityIdRef); assertNotNull(xp.evaluate("//merge-result-ext:Entity[@s:id='" + entityIdRef + "']", resultDocument, XPathConstants.NODE)); } }
From source file:org.eclipse.lyo.testsuite.oslcv2.ServiceProviderCatalogXmlTests.java
@Test public void catalogRootAboutElementPointsToSelf() throws XPathException, IOException { // Make sure that we our root element has an rdf:about that points the // same server provider catalog Node aboutRoot = (Node) OSLCUtils.getXPath().evaluate("/*/oslc_v2:ServiceProviderCatalog/@rdf:about", doc, XPathConstants.NODE); assertNotNull(aboutRoot);/*ww w. ja va2s . c o m*/ assertTrue(currentUrl.equals(aboutRoot.getNodeValue())); }