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:org.eclipse.lyo.testsuite.oslcv2.cm.ChangeRequestXmlTests.java
@Test public void changeRequestHasOneTitle() throws XPathExpressionException { // All change requests have exactly one title. NodeList titles = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_cm_v2:ChangeRequest/dc:title", doc, XPathConstants.NODESET); assertEquals(getFailureMessage(), 1, titles.getLength()); }
From source file:com.rax.deployment.TopologyUpdateClient.java
private boolean isRmiURIinXML(String topologyXML) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dbFactory.newDocumentBuilder(); ByteArrayInputStream input = new ByteArrayInputStream(topologyXML.getBytes("UTF-8")); Document doc = builder.parse(input); // doc.getDocumentElement().normalize(); XPath xPath = XPathFactory.newInstance().newXPath(); String rmiuri = getConfiguration().getThisHostname() + ":" + getConfiguration().getRmiPort(); String expression = "/publishing-deployment-topology/target/agent/transport/rmi-uri"; NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(doc, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); i++) { String val = nodeList.item(i).getFirstChild().getNodeValue(); vlogDebug("The node uri obtained: " + val); if (val.contains(rmiuri)) { vlogInfo("Agent already added for " + rmiuri); return true; }//from w w w .j a v a 2 s . co m } return false; }
From source file:at.sti2.spark.handler.ImpactoriumHandler.java
public String extractInfoObjectIdentifier(String infoObjectResponse) { String reportId = null;/* www . j av a2 s . c om*/ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); //dbf.setNamespaceAware(true); try { DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new ByteArrayInputStream(infoObjectResponse.getBytes("UTF-8"))); XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expr = xpath.compile("//info-object"); Object result = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) result; Node item = nodes.item(0); if (item != null) { NamedNodeMap attributesMap = item.getAttributes(); Node idAttribute = attributesMap.getNamedItem("id"); reportId = idAttribute.getNodeValue(); } } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (XPathExpressionException e) { e.printStackTrace(); } return reportId; }
From source file:it.tidalwave.northernwind.frontend.ui.component.calendar.DefaultCalendarViewController.java
/******************************************************************************************************************* * * * ******************************************************************************************************************/ @PostConstruct//from www . j ava 2 s. c om /* package */ void initialize() throws NotFoundException, IOException, ParserConfigurationException, SAXException, XPathExpressionException, HttpStatusException { final String pathParams = requestHolder.get().getPathParams(siteNode); final int currentYear = getCurrentYear(pathParams); final ResourceProperties siteNodeProperties = siteNode.getProperties(); final ResourceProperties viewProperties = siteNode.getPropertyGroup(view.getId()); // try // { // siteNodeProperties.getProperty(PROPERTY_ENTRIES); // } // catch (NotFoundException e) // { // throw new HttpStatusException(404); // } final String entries = siteNodeProperties.getProperty(PROPERTY_ENTRIES); final StringBuilder builder = new StringBuilder(); final int selectedYear = viewProperties.getIntProperty(PROPERTY_SELECTED_YEAR, currentYear); final int firstYear = viewProperties.getIntProperty(PROPERTY_FIRST_YEAR, Math.min(selectedYear, currentYear)); final int lastYear = viewProperties.getIntProperty(PROPERTY_LAST_YEAR, Math.max(selectedYear, currentYear)); final int columns = 4; builder.append("<div class='nw-calendar'>\n"); appendTitle(builder, siteNodeProperties); builder.append("<table class='nw-calendar-table'>\n").append("<tbody>\n"); builder.append(String.format("<tr>%n<th colspan='%d' class='nw-calendar-title'>%d</th>%n</tr>%n", columns, selectedYear)); final String[] monthNames = DateFormatSymbols.getInstance(requestLocaleManager.getLocales().get(0)) .getMonths(); final String[] shortMonthNames = DateFormatSymbols.getInstance(Locale.ENGLISH).getShortMonths(); final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); final DocumentBuilder db = dbf.newDocumentBuilder(); final Document document = db.parse(new InputSource(new StringReader(entries))); final XPathFactory xPathFactory = XPathFactory.newInstance(); final XPath xPath = xPathFactory.newXPath(); for (int month = 1; month <= 12; month++) { if ((month - 1) % columns == 0) { builder.append("<tr>\n"); for (int column = 0; column < columns; column++) { builder.append(String.format("<th width='%d%%'>%s</th>", 100 / columns, monthNames[month + column - 1])); } builder.append("</tr>\n<tr>\n"); } builder.append("<td>\n<ul>\n"); final String pathTemplate = "/calendar/year[@id='%d']/month[@id='%s']/item"; final String jq1 = String.format(pathTemplate, selectedYear, shortMonthNames[month - 1].toLowerCase()); final XPathExpression jx1 = xPath.compile(jq1); final NodeList nodes = (NodeList) jx1.evaluate(document, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); i++) { // FIXME: verbose XML code below final Node node = nodes.item(i); final String link = site .createLink(new ResourcePath(node.getAttributes().getNamedItem("link").getNodeValue())); String linkClass = ""; Node typeNode = node.getAttributes().getNamedItem("type"); if (typeNode != null) { linkClass = String.format(" class='nw-calendar-table-link-%s'", typeNode.getNodeValue()); } final String name = node.getAttributes().getNamedItem("name").getNodeValue(); builder.append(String.format("<li><a href='%s'%s>%s</a></li>%n", link, linkClass, name)); } builder.append("</ul>\n</td>\n"); if ((month - 1) % columns == (columns - 1)) { builder.append("</tr>\n"); } } builder.append("</tbody>\n</table>\n"); appendYearSelector(builder, firstYear, lastYear, selectedYear); builder.append("</div>\n"); view.setContent(builder.toString()); }
From source file:au.csiro.casda.sodalint.ValidateServiceDescriptor.java
private void checkSodaAccessUrl(Reporter reporter, Node sodaSvcNode) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); NodeList accessUrlList = (NodeList) xpath.evaluate("*[local-name()='PARAM']", sodaSvcNode, XPathConstants.NODESET); if (accessUrlList == null || accessUrlList.getLength() == 0) { reporter.report(SodaCode.E_SDMP, "Service descriptor is missing accessURL PARAM."); return;/*from w w w. j a v a2 s . c om*/ } Node node = accessUrlList.item(0); if (node.getAttributes().getNamedItem("value") == null) { reporter.report(SodaCode.E_SDMP, "Service descriptor accessURL PARAM does not have a value."); return; } }
From source file:ch.dbs.actions.bestellung.EZBXML.java
public List<JournalDetails> searchByJourids(final List<String> jourids, final String bibid) { final List<JournalDetails> list = new ArrayList<JournalDetails>(); final Http http = new Http(); final StringBuffer link = new StringBuffer( "http://rzblx1.uni-regensburg.de/ezeit/detail.phtml?xmloutput=1&colors=7&lang=de&bibid="); link.append(bibid);//from www.j av a 2 s. co m link.append("&jour_id="); final StringBuffer infoLink = new StringBuffer( "http://ezb.uni-regensburg.de/ezeit/detail.phtml?colors=7&lang=de&bibid="); infoLink.append(bibid); infoLink.append("&jour_id="); try { for (final String jourid : jourids) { final JournalDetails jd = new JournalDetails(); final String content = http.getContent(link.toString() + jourid, Connect.TIMEOUT_1.getValue(), Connect.TRIES_1.getValue(), null); if (content != null) { final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); final DocumentBuilder builder = domFactory.newDocumentBuilder(); final Document doc = builder.parse(new InputSource(new StringReader(content))); final XPathFactory factory = XPathFactory.newInstance(); final XPath xpath = factory.newXPath(); final XPathExpression exprJournal = xpath.compile("//journal"); final XPathExpression exprPissns = xpath.compile("//journal/detail/P_ISSNs"); final XPathExpression exprEissns = xpath.compile("//journal/detail/E_ISSNs"); final NodeList resultJournal = (NodeList) exprJournal.evaluate(doc, XPathConstants.NODESET); for (int i = 0; i < resultJournal.getLength(); i++) { final Node firstResultNode = resultJournal.item(i); final Element journal = (Element) firstResultNode; // Title String title = getValue(journal.getElementsByTagName("title")); if (title != null) { title = Jsoup.clean(title, Whitelist.none()); title = Jsoup.parse(title).text(); } jd.setZeitschriftentitel(title); // P-ISSNs final NodeList resultPissns = (NodeList) exprPissns.evaluate(doc, XPathConstants.NODESET); // get first pissn for (int z = 0; z < resultPissns.getLength(); z++) { final Node firstPissnsNode = resultPissns.item(i); final Element pissnElement = (Element) firstPissnsNode; final String pissn = getValue(pissnElement.getElementsByTagName("P_ISSN")); jd.setIssn(pissn); } // try to get Eissn if we have no Pissn if (jd.getIssn() == null) { // E-ISSNs final NodeList resultEissns = (NodeList) exprEissns.evaluate(doc, XPathConstants.NODESET); // get first eissn for (int z = 0; z < resultEissns.getLength(); z++) { final Node firstEissnsNode = resultEissns.item(i); final Element eissnElement = (Element) firstEissnsNode; final String eissn = getValue(eissnElement.getElementsByTagName("E_ISSN")); jd.setIssn(eissn); } } // add info link jd.setLink(infoLink.toString() + jourid); list.add(jd); } } } } catch (final XPathExpressionException e) { LOG.error(e.toString()); } catch (final SAXParseException e) { LOG.error(e.toString()); } catch (final SAXException e) { LOG.error(e.toString()); } catch (final IOException e) { LOG.error(e.toString()); } catch (final ParserConfigurationException e) { LOG.error(e.toString()); } catch (final Exception e) { LOG.error(e.toString()); } return list; }
From source file:org.opencastproject.remotetest.server.EpisodeServiceTest.java
private static void assertXpathExists(Document doc, String path) { try {//from ww w. ja va 2s .c om NodeList nodes = (NodeList) Utils.xpath(doc, path, XPathConstants.NODESET); assertTrue(nodes.getLength() > 0); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:es.juntadeandalucia.panelGestion.negocio.utiles.geosearch.GeosearchDataImportWriter.java
private NodeList getEntities(String entityName) throws XPathExpressionException { NodeList entities = null;// ww w. j a v a 2 s .co m entities = (NodeList) xpath.compile("/dataConfig/document/entity[@name='".concat(entityName).concat("']")) .evaluate(dataImportXML, XPathConstants.NODESET); return entities; }
From source file:org.eclipse.lyo.testsuite.oslcv2.QueryTests.java
@Test public void validGreaterThanQueryContainsExpectedDefects() throws IOException, SAXException, ParserConfigurationException, XPathExpressionException, ParseException { //Build the query using the specified comparison property String query = getQueryBase() + "oslc.where=" + queryComparisonProperty + URLEncoder.encode(">=\"" + queryComparisonValue + "\"", "UTF-8") + "&oslc.select=" + queryComparisonProperty;//w w w. j ava 2 s . c om String respBody = runQuery(query, OSLCConstants.CT_XML); Document doc = OSLCUtils.createXMLDocFromResponseBody(respBody); NodeList results = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_cm_v2:ChangeRequest", doc, XPathConstants.NODESET); if (results == null) { results = (NodeList) OSLCUtils.getXPath().evaluate("//rdf:Description", doc, XPathConstants.NODESET); } assertTrue(results != null); assertTrue("Expected query results >0", results.getLength() > 0); //Check that the property elements are greater than the query comparison property checkGreaterThanProperty(results, queryComparisonProperty, queryComparisonValue, doc); }
From source file:eu.europa.ec.markt.dss.validation102853.toolbox.XPointerResourceResolver.java
@Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { final Attr uriAttr = context.attr; final String baseUri = context.baseUri; String uriNodeValue = uriAttr.getNodeValue(); if (uriNodeValue.charAt(0) != '#') { return null; }/*from www. j av a 2s . co m*/ String xpURI; try { xpURI = URLDecoder.decode(uriNodeValue, "utf-8"); } catch (UnsupportedEncodingException e) { LOG.warn("utf-8 not a valid encoding", e); return null; } String parts[] = xpURI.substring(1).split("\\s"); int i = 0; DSigNamespaceContext nsContext = null; if (parts.length > 1) { nsContext = new DSigNamespaceContext(); for (; i < parts.length - 1; ++i) { if (!parts[i].endsWith(")") || !parts[i].startsWith(XNS_OPEN)) { return null; } String mapping = parts[i].substring(XNS_OPEN.length(), parts[i].length() - 1); int pos = mapping.indexOf('='); if (pos <= 0 || pos >= mapping.length() - 1) { throw new ResourceResolverException("malformed namespace part of XPointer expression", uriNodeValue, baseUri); } nsContext.addNamespace(mapping.substring(0, pos), mapping.substring(pos + 1)); } } try { Node node = null; NodeList nodes = null; // plain ID reference. if (i == 0 && !parts[i].startsWith(XP_OPEN)) { node = this.baseNode.getOwnerDocument().getElementById(parts[i]); } else { if (!parts[i].endsWith(")") || !parts[i].startsWith(XP_OPEN)) { return null; } XPath xp = this.xPathFactory.newXPath(); if (nsContext != null) { xp.setNamespaceContext(nsContext); } nodes = (NodeList) xp.evaluate(parts[i].substring(XP_OPEN.length(), parts[i].length() - 1), this.baseNode, XPathConstants.NODESET); if (nodes.getLength() == 0) { return null; } if (nodes.getLength() == 1) { node = nodes.item(0); } } XMLSignatureInput result = null; if (node != null) { result = new XMLSignatureInput(node); } else if (nodes != null) { Set<Node> nodeSet = new HashSet<Node>(nodes.getLength()); for (int j = 0; j < nodes.getLength(); ++j) { nodeSet.add(nodes.item(j)); } result = new XMLSignatureInput(nodeSet); } else { return null; } result.setMIMEType("text/xml"); result.setExcludeComments(true); result.setSourceURI((baseUri != null) ? baseUri.concat(uriNodeValue) : uriNodeValue); return result; } catch (XPathExpressionException e) { throw new ResourceResolverException("malformed XPath inside XPointer expression", e, uriNodeValue, baseUri); } }