List of usage examples for javax.xml.xpath XPathConstants NODESET
QName NODESET
To view the source code for javax.xml.xpath XPathConstants NODESET.
Click Source Link
The XPath 1.0 NodeSet data type.
Maps to Java org.w3c.dom.NodeList .
From source file:de.huberlin.wbi.hiway.am.galaxy.GalaxyApplicationMaster.java
/** * A (recursive) helper function for parsing the parameters of a tool from their XML specification * // w w w .j av a2s . c om * @param el * the XML element from which to commence the parsing * @return the set of parameters under this element * @throws XPathExpressionException */ private Set<GalaxyParam> getParams(Element el, GalaxyTool tool) throws XPathExpressionException { Set<GalaxyParam> params = new HashSet<>(); XPath xpath = XPathFactory.newInstance().newXPath(); // there are three different types of parameters in Galaxy's tool descriptions: atomic parameters, conditionals and repeats NodeList paramNds = (NodeList) xpath.evaluate("param", el, XPathConstants.NODESET); NodeList conditionalNds = (NodeList) xpath.evaluate("conditional", el, XPathConstants.NODESET); NodeList repeatNds = (NodeList) xpath.evaluate("repeat", el, XPathConstants.NODESET); // (1) parse atomic parameters for (int i = 0; i < paramNds.getLength(); i++) { Element paramEl = (Element) paramNds.item(i); String name = paramEl.getAttribute("name"); GalaxyParamValue param = new GalaxyParamValue(name); params.add(param); // (a) determine default values and mappings of values String type = paramEl.getAttribute("type"); switch (type) { case "data": param.addMapping("", "{\"path\": \"\"}"); tool.setPath(name); break; case "boolean": String trueValue = paramEl.getAttribute("truevalue"); param.addMapping("True", trueValue); String falseValue = paramEl.getAttribute("falsevalue"); param.addMapping("False", falseValue); break; case "select": param.addMapping("", "None"); break; default: } // (b) resolve references to Galaxy data tables NodeList optionNds = (NodeList) xpath.evaluate("option", paramEl, XPathConstants.NODESET); NodeList optionsNds = (NodeList) xpath.evaluate("options", paramEl, XPathConstants.NODESET); for (int j = 0; j < optionNds.getLength() + optionsNds.getLength(); j++) { Element optionEl = j < optionNds.getLength() ? (Element) optionNds.item(j) : (Element) optionsNds.item(j - optionNds.getLength()); if (optionEl.hasAttribute("from_data_table")) { String tableName = optionEl.getAttribute("from_data_table"); GalaxyDataTable galaxyDataTable = galaxyDataTables.get(tableName); for (String value : galaxyDataTable.getValues()) { param.addMapping(value, galaxyDataTable.getContent(value)); } } } } // (2) parse conditionals, which consist of a single condition parameter and several "when condition equals" parameters for (int i = 0; i < conditionalNds.getLength(); i++) { Element conditionalEl = (Element) conditionalNds.item(i); String name = conditionalEl.getAttribute("name"); GalaxyConditional conditional = new GalaxyConditional(name); NodeList conditionNds = (NodeList) xpath.evaluate("param", conditionalEl, XPathConstants.NODESET); NodeList whenNds = (NodeList) xpath.evaluate("when", conditionalEl, XPathConstants.NODESET); if (conditionNds.getLength() == 0 || whenNds.getLength() == 0) continue; Element conditionEl = (Element) conditionNds.item(0); name = conditionEl.getAttribute("name"); GalaxyParamValue condition = new GalaxyParamValue(name); conditional.setCondition(condition); for (int j = 0; j < whenNds.getLength(); j++) { Element whenEl = (Element) whenNds.item(j); String conditionValue = whenEl.getAttribute("value"); conditional.setConditionalParams(conditionValue, getParams(whenEl, tool)); } params.add(conditional); } // (3) parse repeats, which consist of a list of parameters for (int i = 0; i < repeatNds.getLength(); i++) { Element repeatEl = (Element) repeatNds.item(i); String name = repeatEl.getAttribute("name"); GalaxyRepeat repeat = new GalaxyRepeat(name); params.add(repeat); repeat.setParams(getParams(repeatEl, tool)); } return params; }
From source file:net.sourceforge.buildmonitor.monitors.BambooMonitor.java
private List<BuildReport> getResultsForProject(String bambooServerBaseUrl, BuildPlan plan) throws MonitoringException { List returnList = new ArrayList<BuildReport>(); try {/* ww w .j ava 2 s. co m*/ String methodURL = bambooServerBaseUrl + "/rest/api/latest/result/" + plan.key + "?os_authType=basic" + "&expand=results[0].result"; if (bambooProperties.getFavouriteProjectsOnly()) { methodURL += "&favourite"; } String serverResponse = callBambooApi(new URL(methodURL)); InputSource serverResponseIS = new InputSource(new StringReader(serverResponse)); NodeList nodes = (NodeList) XPathFactory.newInstance().newXPath().evaluate("/results/results/result", serverResponseIS, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); i++) { Element result = (Element) nodes.item(i); String dateString = getNamedChildNodeValue(result, "buildCompletedTime"); String buildState = result.getAttribute("state"); BuildReport report = new BuildReport(); report.setId(result.getAttribute("key")); report.setName(plan.name); report.setDate(parseDate(dateString)); report.setStatus(parseBuildState(buildState)); returnList.add(report); } } catch (Throwable t) { throw new MonitoringException(t, null); } return returnList; }
From source file:org.eclipse.lyo.testsuite.oslcv2.cm.ChangeRequestXmlTests.java
@Test public void changeRequestHasAtMostOneName() throws XPathExpressionException { NodeList names = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_cm_v2:ChangeRequest/dc:name", doc, XPathConstants.NODESET); assertTrue(getFailureMessage(), names.getLength() <= 1); }
From source file:io.takari.maven.testing.executor.junit.MavenVersionResolver.java
private Map<String, Credentials> getCredentials(TestProperties properties) throws IOException { File userSettings = properties.getUserSettings(); if (userSettings == null) { return Collections.emptyMap(); }//from ww w.j a v a 2 s. c o m Map<String, Credentials> result = new HashMap<>(); try { Document document = documentBuilderFactory.newDocumentBuilder().parse(userSettings); NodeList servers = (NodeList) xpathFactory.newXPath() // .compile("//settings/servers/server") // .evaluate(document, XPathConstants.NODESET); for (int i = 0; i < servers.getLength(); i++) { Element server = (Element) servers.item(i); String id = getChildValue(server, "id"); String username = getChildValue(server, "username"); String password = getChildValue(server, "password"); if (id != null && username != null) { result.put(id, new Credentials(username, password)); } } } catch (XPathExpressionException | SAXException | ParserConfigurationException e) { // can't happen } return result; }
From source file:org.eclipse.lyo.testsuite.oslcv2.CoreResourceXmlTests.java
@Test public void CoreResourceHasAtMostOneCreatedDate() throws XPathExpressionException { String eval = "//" + getNode() + "/" + "dc:created"; NodeList createdDates = (NodeList) OSLCUtils.getXPath().evaluate(eval, doc, XPathConstants.NODESET); assertTrue(getFailureMessage(), createdDates.getLength() <= 1); //If there is a created date, verify the format. if (createdDates.getLength() > 0) { try {/* ww w . ja v a2 s .co m*/ DatatypeConverter.parseDateTime(createdDates.item(0).getTextContent()); } catch (Exception e) { fail("Created date not in valid XSD format"); } } }
From source file:org.eclipse.lyo.testsuite.oslcv2.TestsBase.java
public static ArrayList<String> getServiceProviderURLsUsingXML(String inBaseURL, boolean dontGoDeep) throws IOException, XPathException, ParserConfigurationException, SAXException { staticSetup();//from ww w . j a v a 2 s . c o m // ArrayList to contain the urls from all SPCs ArrayList<String> data = new ArrayList<String>(); // If we are given a shortcut, then use it and skip the rest if (useThisServiceProvider != null && useThisServiceProvider.length() > 0) { data.add(useThisServiceProvider); return data; } String base = null; if (inBaseURL == null) base = setupBaseUrl; else base = inBaseURL; HttpResponse resp = OSLCUtils.getResponseFromUrl(base, base, basicCreds, OSLCConstants.CT_XML, headers); Document baseDoc = OSLCUtils.createXMLDocFromResponseBody(EntityUtils.toString(resp.getEntity())); // Get all ServiceProvider urls from the base document in order to // recursively add all the capability urls from them as well. // Inlined using oslc:ServiceProvider/@rdf:about NodeList sps = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_v2:ServiceProvider/@rdf:about", baseDoc, XPathConstants.NODESET); for (int i = 0; i < sps.getLength(); i++) { if (!sps.item(i).getNodeValue().equals(base) || sps.getLength() == 1) { data.add(sps.item(i).getNodeValue()); if (onlyOnce) return data; if (dontGoDeep) return data; } } // Get all ServiceProvider urls from the base document in order to // recursively add all the capability urls from them as well. // Referenced using oslc:serviceProvider/@rdf:resource sps = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_v2:serviceProvider/@rdf:resource", baseDoc, XPathConstants.NODESET); for (int i = 0; i < sps.getLength(); i++) { if (!sps.item(i).getNodeValue().equals(base) || sps.getLength() == 1) { data.add(sps.item(i).getNodeValue()); if (dontGoDeep) return data; } } // Get all ServiceProviderCatalog urls from the base document in order // to recursively add all the capability from ServiceProviders within them as well. // Inlined using oslc:ServiceProviderCatalog/@rdf:about NodeList spcs = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_v2:ServiceProviderCatalog/@rdf:about", baseDoc, XPathConstants.NODESET); for (int i = 0; i < spcs.getLength(); i++) { if (!spcs.item(i).getNodeValue().equals(base)) { ArrayList<String> subCollection = getServiceProviderURLsUsingXML(spcs.item(i).getNodeValue(), dontGoDeep); for (String subUri : subCollection) { data.add(subUri); if (dontGoDeep) return data; } } } // Get all ServiceProviderCatalog urls from the base document in order // to recursively add all the capability from ServiceProviders within them as well. // Referenced using oslc:serviceProviderCatalog/@rdf:resource spcs = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_v2:serviceProviderCatalog/@rdf:resource", baseDoc, XPathConstants.NODESET); for (int i = 0; i < spcs.getLength(); i++) { if (!spcs.item(i).getNodeValue().equals(base)) { ArrayList<String> subCollection = getServiceProviderURLsUsingXML(spcs.item(i).getNodeValue(), dontGoDeep); for (String subUri : subCollection) { data.add(subUri); if (dontGoDeep) return data; } } } return data; }
From source file:au.csiro.casda.sodalint.ValidateServiceDescriptor.java
private void checkInputParams(Reporter reporter, Node sodaSvcNode) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); String[] requiredAttrs = new String[] { "name", "ucd", "datatype" }; NodeList paramList = (NodeList) xpath.evaluate( "*[local-name()='GROUP' and @name='inputParams']/*[local-name()='PARAM']", sodaSvcNode, XPathConstants.NODESET); // <PARAM name="ID" ucd="meta.ref.url;meta.curation" datatype="char" arraysize="*" /> Map<String, Node> paramMap = new HashMap<>(); for (int i = 0; i < paramList.getLength(); i++) { Node paramNode = paramList.item(i); NamedNodeMap attributes = paramNode.getAttributes(); String paramName = "Unnamed"; boolean valid = true; for (String attrName : requiredAttrs) { Node attrNode = attributes.getNamedItem(attrName); if (attrNode == null) { reporter.report(SodaCode.E_SDIP, "Service descriptor " + paramName + " PARAM is missing the required attribute " + attrName + "."); valid = false;// w w w. j a v a2s. c o m } else if ("name".equals(attrName)) { paramName = attrNode.getNodeValue(); } } if (valid) { paramMap.put(paramName, paramNode); } } // Check for ID support - error if not present if (!paramMap.containsKey("ID")) { reporter.report(SodaCode.E_SDMP, "Required service descriptor ID PARAM is missing."); } for (SodaParameter standardParam : SodaParameter.values()) { if (paramMap.containsKey(standardParam.name())) { checkParamAttributes(reporter, paramMap.get(standardParam.name()), standardParam); } else if (!"ID".equals(standardParam.name())) { reporter.report(SodaCode.W_SDSP, "Standard service descriptor " + standardParam.name() + " PARAM is missing."); } } }
From source file:au.gov.ga.earthsci.discovery.csw.CSWDiscoveryResult.java
public CSWDiscoveryResult(CSWDiscovery discovery, int index, Element cswRecordElement) throws XPathExpressionException { super(discovery, index); XPath xpath = WWXML.makeXPath(); String title = (String) xpath.compile("title/text()").evaluate(cswRecordElement, XPathConstants.STRING); //$NON-NLS-1$ title = StringEscapeUtils.unescapeXml(title); String description = (String) xpath.compile("description/text()").evaluate(cswRecordElement, //$NON-NLS-1$ XPathConstants.STRING); description = StringEscapeUtils.unescapeXml(description); //normalize newlines description = description.replace("\r\n", "\n").replace("\r", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ this.title = title; this.description = description; NodeList referenceElements = (NodeList) xpath.compile("references/reference").evaluate(cswRecordElement, //$NON-NLS-1$ XPathConstants.NODESET); for (int i = 0; i < referenceElements.getLength(); i++) { Element referenceElement = (Element) referenceElements.item(i); String scheme = referenceElement.getAttribute("scheme"); //$NON-NLS-1$ try {/* w w w . java2 s.co m*/ URL url = new URL(referenceElement.getTextContent()); references.add(url); referenceSchemes.add(scheme); } catch (MalformedURLException e) { } } Sector bounds = null; String min = (String) xpath.compile("boundingBox/lowerCorner/text()").evaluate(cswRecordElement, //$NON-NLS-1$ XPathConstants.STRING); String max = (String) xpath.compile("boundingBox/upperCorner/text()").evaluate(cswRecordElement, //$NON-NLS-1$ XPathConstants.STRING); if (!Util.isBlank(min) && !Util.isBlank(max)) { min = StringEscapeUtils.unescapeXml(min); max = StringEscapeUtils.unescapeXml(max); String doubleGroup = "([-+]?(?:\\d*\\.?\\d+)|(?:\\d+\\.))"; //$NON-NLS-1$ Pattern pattern = Pattern.compile("\\s*" + doubleGroup + "\\s+" + doubleGroup + "\\s*"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ Matcher minMatcher = pattern.matcher(min); Matcher maxMatcher = pattern.matcher(max); if (minMatcher.matches() && maxMatcher.matches()) { double minLon = Double.parseDouble(minMatcher.group(1)); double minLat = Double.parseDouble(minMatcher.group(2)); double maxLon = Double.parseDouble(maxMatcher.group(1)); double maxLat = Double.parseDouble(maxMatcher.group(2)); bounds = Sector.fromDegrees(minLat, maxLat, minLon, maxLon); } } this.bounds = Bounds.fromSector(bounds); }
From source file:aurelienribon.gdxsetupui.Helper.java
public static List<ClasspathEntry> getClasspathEntries(File classpathFile) { List<ClasspathEntry> classpath = new ArrayList<ClasspathEntry>(); if (!classpathFile.isFile()) return classpath; try {/*w ww .jav a2 s. c o m*/ Document doc = XmlUtils.createParser().parse(classpathFile); NodeList nodes = (NodeList) XmlUtils.xpath("classpath/classpathentry[@kind='lib' and @path]", doc, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); i++) { String path = nodes.item(i).getAttributes().getNamedItem("path").getNodeValue(); String sourcepath = nodes.item(i).getAttributes().getNamedItem("sourcepath") != null ? nodes.item(i).getAttributes().getNamedItem("sourcepath").getNodeValue() : null; boolean exported = nodes.item(i).getAttributes().getNamedItem("exported") != null ? nodes.item(i) .getAttributes().getNamedItem("exported").getNodeValue().equalsIgnoreCase("true") : false; classpath.add(new ClasspathEntry(path, sourcepath, exported)); } } catch (SAXException ex) { } catch (IOException ex) { } return classpath; }
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 w w. j a v a 2 s. 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; }