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:curam.molsa.test.customfunctions.MOLSADOMReader.java
/** * Get list of DOM Node from query./* w w w . j a v a2s . c om*/ * * @param startElement * @param query * * @return */ public static List<Node> nodes(final Object startElement, final String query) { try { final NodeList nodeList = (NodeList) MOLSADOMParserCache.getXPath().compile(query) .evaluate(startElement, XPathConstants.NODESET); final List<Node> list = new ArrayList<Node>(); if (nodeList != null) { for (int i = 0; i < nodeList.getLength(); i++) { list.add(nodeList.item(i)); } } return list; } catch (final Exception e) { throw new RuntimeException(e); } }
From source file:org.orcid.examples.jopmts.mvc.OrcidClientModel.java
private List<String> stringListFromDocument(String path, XPath xpath, Node partialDocument) throws XPathExpressionException { NodeList stringNodes = (NodeList) xpath.evaluate(path, partialDocument, XPathConstants.NODESET); ArrayList<String> stringList = new ArrayList<String>(); for (int i = 0; i < stringNodes.getLength(); i++) { stringList.add(stringNodes.item(i).getTextContent()); }/*from www .j ava 2 s .co m*/ return stringList; }
From source file:de.egore911.versioning.deployer.performer.PerformCopy.java
public void perform(Node serverDeploymentsDeploymentNode) throws XPathExpressionException { NodeList copyOperations = (NodeList) copyXpath.evaluate(serverDeploymentsDeploymentNode, XPathConstants.NODESET); for (int j = 0; j < copyOperations.getLength(); j++) { Node copyOperation = copyOperations.item(j); String uri = (String) urlXpath.evaluate(copyOperation, XPathConstants.STRING); String target = (String) targetXpath.evaluate(copyOperation, XPathConstants.STRING); String targetFilename = (String) filenameXpath.evaluate(copyOperation, XPathConstants.STRING); if (!copy(uri, target, targetFilename)) { LOG.error("Failed copy operation"); }/*from w ww . j a v a2 s .co m*/ } }
From source file:org.orcid.examples.jopmts.mvc.OrcidProfile.java
public static List<Model> parsePublications(XPath xpath, Node orcidDocument) throws XPathExpressionException { NodeList works = (NodeList) xpath.evaluate("//o:orcid-works/o:orcid-work", orcidDocument, XPathConstants.NODESET); ArrayList<Model> pubList = new ArrayList<Model>(); for (int i = 0; i < works.getLength(); i++) { Node publication = works.item(i); Model pubModel = new OrcidWork(publication, xpath); pubModel.addAttribute("workNum", Integer.toString(i)); pubList.add(pubModel);/*from w w w . j a v a 2 s . com*/ } return pubList; }
From source file:com.esri.geoportal.commons.csw.client.impl.ProfilesLoader.java
/** * Loads profiles./*w ww . j av a 2 s . co m*/ * @return profiles * @throws IOException if loading profiles from configuration fails * @throws ParserConfigurationException if unable to obtain XML parser * @throws SAXException if unable to parse XML document * @throws XPathExpressionException if invalid XPath expression */ public Profiles load() throws IOException, ParserConfigurationException, SAXException, XPathExpressionException { LOG.info(String.format("Loading CSW profiles")); Profiles profiles = new Profiles(); try (InputStream profilesXml = Thread.currentThread().getContextClassLoader() .getResourceAsStream(CONFIG_FILE_PATH);) { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); Document profilesDom = builder.parse(new InputSource(profilesXml)); XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); NodeList profilesNodeList = (NodeList) xpath.evaluate("/CSWProfiles/Profile", profilesDom, XPathConstants.NODESET); for (int pidx = 0; pidx < profilesNodeList.getLength(); pidx++) { Node profileNode = profilesNodeList.item(pidx); String id = StringUtils .trimToEmpty((String) xpath.evaluate("ID", profileNode, XPathConstants.STRING)); String name = StringUtils .trimToEmpty((String) xpath.evaluate("Name", profileNode, XPathConstants.STRING)); String namespace = StringUtils .trimToEmpty((String) xpath.evaluate("CswNamespace", profileNode, XPathConstants.STRING)); String description = StringUtils .trimToEmpty((String) xpath.evaluate("Description", profileNode, XPathConstants.STRING)); String getRecordsReqXslt = StringUtils.trimToEmpty((String) xpath .evaluate("GetRecords/XSLTransformations/Request", profileNode, XPathConstants.STRING)); String getRecordsRspXslt = StringUtils.trimToEmpty((String) xpath .evaluate("GetRecords/XSLTransformations/Response", profileNode, XPathConstants.STRING)); String getRecordByIdReqKVP = StringUtils.trimToEmpty( (String) xpath.evaluate("GetRecordByID/RequestKVPs", profileNode, XPathConstants.STRING)); String getRecordByIdRspXslt = StringUtils.trimToEmpty((String) xpath .evaluate("GetRecordByID/XSLTransformations/Response", profileNode, XPathConstants.STRING)); Profile prof = new Profile(); prof.setId(id); prof.setName(name); prof.setDescription(description); prof.setGetRecordsReqXslt(getRecordsReqXslt); prof.setGetRecordsRspXslt(getRecordsRspXslt); prof.setKvp(getRecordByIdReqKVP); prof.setGetRecordByIdRspXslt(getRecordByIdRspXslt); profiles.add(prof); } } LOG.info(String.format("CSW profiles loaded.")); return profiles; }
From source file:org.orcid.examples.jopmts.mvc.OrcidWork.java
public static List<Model> parseAuthors(XPath xpath, Node orcidDocument) throws XPathExpressionException { NodeList authors = (NodeList) xpath.evaluate("o:work-contributors/o:contributor", orcidDocument, XPathConstants.NODESET); ArrayList<Model> authList = new ArrayList<Model>(); for (int i = 0; i < authors.getLength(); i++) { Node author = authors.item(i); Model authorModel = new OrcidAuthor(author, xpath); authList.add(authorModel);/*from w ww . j a v a 2 s . com*/ } return authList; }
From source file:org.opencastproject.remotetest.server.CaptureAdminRestEndpointTest.java
@Test public void testGetAgents() throws Exception { String endpoint = "/capture-admin/agents"; HttpGet get = new HttpGet(BASE_URL + endpoint + ".xml"); String xmlResponse = EntityUtils.toString(httpClient.execute(get).getEntity()); Main.returnClient(httpClient);//from w w w . j a v a2 s. com // parse the xml and extract the running clients names DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(IOUtils.toInputStream(xmlResponse, "UTF-8")); XPath xPath = XPathFactory.newInstance().newXPath(); NodeList agents = (NodeList) xPath.compile("//*[local-name() = 'agent']").evaluate(doc, XPathConstants.NODESET); // validate the REST endpoint for each agent state is functional for (int i = 0; i < agents.getLength(); i++) { try { httpClient = Main.getClient(); String agentName = (String) xPath.evaluate("*[local-name() = 'name']/text()", agents.item(i), XPathConstants.STRING); HttpGet agentGet = new HttpGet(BASE_URL + endpoint + "/" + agentName + ".xml"); int agentResponse = httpClient.execute(agentGet).getStatusLine().getStatusCode(); assertEquals(HttpStatus.SC_OK, agentResponse); } finally { Main.returnClient(httpClient); } } }
From source file:org.n52.smartsensoreditor.validator.MetadataValidatorSML.java
/** * validates the backend bean properties against a given schematron (or * else) validator/* w ww . j a v a 2s . c o m*/ * * @param target * @param errors */ public void validate(Object target, Errors errors) { BackendBean lBean = (BackendBean) target; // chekc if we need to validate if (lBean.getValidatorId() != null && !lBean.getValidatorId().equals("")) { // apply schematron transformation Document lReport = getService().validate(lBean.getValidatorId()); // add assertions to errors. XPathUtil lUtil = new XPathUtil(); lUtil.setContext(editorContext); Object o = lUtil.evaluateXPath("//svrl:failed-assert", XPathConstants.NODESET, lReport); if (o != null) { NodeList lList = ((NodeList) o); for (int i = 0; i < lList.getLength(); i++) { Node lNode = lList.item(i); errors.rejectValue(lUtil.evaluateAsString("@id", lNode), lUtil.evaluateAsString("svrl:text", lNode)); } } } }
From source file:org.syncope.console.commons.XMLRolesReader.java
/** * Get all roles allowed for specific page and actio requested. * * @param pageId/* w w w . j a va 2s . c o m*/ * @param actionId * @return roles list comma separated */ public String getAllAllowedRoles(final String pageId, final String actionId) { if (doc == null) { init(); } if (doc == null) { return ""; } final StringBuilder roles = new StringBuilder(); try { XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expr = xpath.compile( "//page[@id='" + pageId + "']/" + "action[@id='" + actionId + "']/" + "entitlement/text()"); Object result = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) result; for (int i = 0; i < nodes.getLength(); i++) { if (i > 0) { roles.append(","); } roles.append(nodes.item(i).getNodeValue()); } } catch (XPathExpressionException e) { LOG.error("While parsing authorizations file", e); } LOG.debug("Authorizations found: {}", roles); return roles.toString(); }
From source file:com.seajas.search.contender.service.exploration.ExplorationService.java
/** * Make an attempt to retrieve all feed links from the given HTML content. * /*w w w. j av a 2s . co m*/ * @param htmlContent * @return List<String> */ public List<String> getIndirectlyAccessibleFeedLinks(final URI uri, final String htmlContent) { List<String> result = new ArrayList<String>(); try { HtmlCleaner cleaner = new HtmlCleaner(); TagNode node = cleaner.clean(htmlContent); Document document = new CustomDomSerializer(cleaner.getProperties(), true).createDOM(node); // Now try to extract the appropriate links XPath xpath = XPathFactory.newInstance().newXPath(); try { XPathExpression xpathExpression = xpath.compile( "//head/link[contains(translate(@type, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'rss+xml') or contains(translate(@type, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'atom+xml')]/@href"); NodeList nodeList = (NodeList) xpathExpression.evaluate(document, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); i++) { Node listNode = nodeList.item(i); if (listNode instanceof Attr) { String resultUrl = ((Attr) listNode).getValue(); if (!StringUtils.hasText(resultUrl)) { logger.warn("The given alternate-link tag contains no href - skipping"); continue; } try { new URL(resultUrl.trim()); result.add(resultUrl.trim()); } catch (MalformedURLException e) { try { result.add(uri.resolve(resultUrl.trim()).normalize().toString()); } catch (IllegalArgumentException e2) { logger.warn( "The given (presumably relative) URL is not valid - not adding to the result list", e2); } } } else logger.error("Invalid node type " + listNode.getNodeType() + " - skipping"); } } catch (XPathExpressionException e) { logger.error("Could not apply the given XPath expression to extract RSS alternate links", e); } // Now determine if the URLs are fully-qualified } catch (ParserConfigurationException e) { logger.info("Could not serialize the given content", e); return null; } return result; }