List of usage examples for org.dom4j XPath selectNodes
List<Node> selectNodes(Object context);
selectNodes
performs this XPath expression on the given Node or List of Node s instances appending all the results together into a single list. From source file:org.intalio.tempo.workflow.fds.dispatches.NotifyDispatcher.java
License:Open Source License
public Document dispatchResponse(Document response) throws InvalidInputFormatException { XPath xpath = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Body/soapenv:Fault"); xpath.setNamespaceURIs(MessageConstants.get_nsMap()); List fault = xpath.selectNodes(response); if (fault.size() != 0) { // return fault as-is LOG.error("Fault response during notify:\n" + response.asXML()); return response; }//from ww w . j a v a 2s .co m Document notifyResponse = DocumentHelper.createDocument(); Element rootElement = notifyResponse.addElement("notifyResponse", userProcessNamespace); Element statusElement = rootElement.addElement("status", userProcessNamespace); statusElement.setText("OK"); return notifyResponse; }
From source file:org.jage.platform.config.xml.loaders.AbstractDocumentLoader.java
License:Open Source License
@SuppressWarnings("unchecked") protected static final List<Element> selectNodes(final XPath xpath, final Object node) { return xpath.selectNodes(node); }
From source file:org.jasig.portlet.widget.links.PortletXmlGroupService.java
License:Apache License
Set<String> getGroups(final String portletName) { if (doc == null) { return null; }//from ww w . j a v a 2 s .c om final String xpathStr = "//p:portlet[p:portlet-name='" + portletName + "']/p:security-role-ref"; XPath xpath = doc.createXPath(xpathStr); xpath.setNamespaceContext(namespaceContext); List<Node> roles = xpath.selectNodes(doc); if (roles == null || roles.isEmpty()) { log.error("No security roles found for portlet: {}", portletName); return Collections.emptySet(); } else { Set<String> groups = roles.stream().map(e -> xpathRoleName.selectSingleNode(e).getText()) .collect(Collectors.toSet()); return groups; } }
From source file:org.jbpm.gd.jpdl.util.JbpmClasspathContainer.java
License:Open Source License
private Map getJarNames() { HashMap result = new HashMap(); try {/*from w w w .j av a2 s . c om*/ String location = VariablesPlugin.getDefault().getStringVariableManager() .performStringSubstitution(jbpmInstallation.location); IPath locationPath = new Path(location); Document document = new SAXReader() .read(locationPath.append("src/resources/gpd/version.info.xml").toFile()); XPath xpath = document.createXPath("/jbpm-version-info/classpathentry"); List list = xpath.selectNodes(document); for (int i = 0; i < list.size(); i++) { Element entry = (Element) list.get(i); IPath sourcePath = null; if (entry.attribute("src") != null) { sourcePath = locationPath.append((String) entry.attribute("src").getData()); } result.put(locationPath.append((String) entry.attribute("path").getData()), sourcePath); } } catch (MalformedURLException e) { } catch (DocumentException e) { } catch (CoreException e) { Logger.logError("Problem while resolving expression", e); } return result; }
From source file:org.jbpm.gd.jpdl.wizard.NewProcessProjectWizard.java
License:Open Source License
private String getLocation(String selector, String baseLocation) { String result = null;/*from w ww. ja v a2 s.c om*/ try { IPath locationPath = new Path(baseLocation); Document document = new SAXReader() .read(locationPath.append("src/resources/gpd/version.info.xml").toFile()); XPath xpath = document.createXPath("/jbpm-version-info/" + selector); List list = xpath.selectNodes(document); if (!list.isEmpty()) { result = (String) ((Element) list.get(0)).attribute("path").getData(); } } catch (MalformedURLException e) { } catch (DocumentException e) { } return result; }
From source file:org.mitre.muc.callisto.session.SessionLogger.java
License:Open Source License
/** Retrieves existing file element or creates a new one. */ private Element getFileElement(Element root, URI uri) { XPath xpath = DocumentHelper.createXPath("file[@uri='" + uri.toString() + "']"); List results = xpath.selectNodes(root); Element element = null;/*from www .j av a 2 s . c o m*/ if (results.isEmpty()) { element = root.addElement("file"); element.addAttribute("uri", uri.toString()); } else { element = (Element) results.get(0); } return element; }
From source file:org.mitre.muc.callisto.session.SessionLogger.java
License:Open Source License
/** Retrieves existing session element or creates a new one. */ private Element getSessionElement(Element file, Timer timer) { XPath xpath = DocumentHelper.createXPath("session[@id='" + timer.getId() + "']"); List results = xpath.selectNodes(file); Element element = null;//from w ww. j a va 2 s . co m if (results.isEmpty()) { element = file.addElement("session"); element.addAttribute("id", String.valueOf(timer.getId())); } else { element = (Element) results.get(0); } return element; }
From source file:org.mitre.muc.callisto.session.SessionLogger.java
License:Open Source License
/** Retrieves iterator over sessions elements */ private Iterator getSessionIterator(Element file) { XPath xpath = DocumentHelper.createXPath("session"); List results = xpath.selectNodes(file); return results.iterator(); }
From source file:org.nuxeo.cm.core.service.caseimporter.DefaultXMLCaseReader.java
License:Open Source License
@SuppressWarnings("unchecked") private List<Document> readDomDoc(Document doc) throws ClientException { XPath xpathSelector = DocumentHelper.createXPath("/" + ALL_CASES_TAG + "/" + CASE_TAG); List<Element> allCases = xpathSelector.selectNodes(doc); List<Document> caseReaders = new ArrayList<Document>(); for (Element element : allCases) { caseReaders.add(extractEntireCase(element)); }/*from w w w . j a va2 s . c o m*/ return caseReaders; }
From source file:org.olat.fileresource.types.ImsCPFileResource.java
License:Apache License
/** * Check for title and at least one resource. * //from www . ja v a2s.c o m * @param unzippedDir * @return True if is of type. */ public static boolean validate(final File unzippedDir) throws AddingResourceException { final File fManifest = new File(unzippedDir, "imsmanifest.xml"); final Document doc = IMSLoader.loadIMSDocument(fManifest); // do not throw exception already here, as it might be only a generic zip file if (doc == null) { return false; } // get all organization elements. need to set namespace final Element rootElement = doc.getRootElement(); final String nsuri = rootElement.getNamespace().getURI(); final Map nsuris = new HashMap(1); nsuris.put("ns", nsuri); // Check for organiztaion element. Must provide at least one... title gets ectracted from either // the (optional) <title> element or the mandatory identifier attribute. // This makes sure, at least a root node gets created in CPManifestTreeModel. final XPath meta = rootElement.createXPath("//ns:organization"); meta.setNamespaceURIs(nsuris); final Element orgaEl = (Element) meta.selectSingleNode(rootElement); // TODO: accept several organizations? if (orgaEl == null) { throw new AddingResourceException("resource.no.organisation"); } // Check for at least one <item> element referencing a <resource>, which will serve as an entry point. // This is mandatory, as we need an entry point as the user has the option of setting // CPDisplayController to not display a menu at all, in which case the first <item>/<resource> // element pair gets displayed. final XPath resourcesXPath = rootElement.createXPath("//ns:resources"); resourcesXPath.setNamespaceURIs(nsuris); final Element elResources = (Element) resourcesXPath.selectSingleNode(rootElement); if (elResources == null) { throw new AddingResourceException("resource.no.resource"); // no <resources> element. } final XPath itemsXPath = rootElement.createXPath("//ns:item"); itemsXPath.setNamespaceURIs(nsuris); final List items = itemsXPath.selectNodes(rootElement); if (items.size() == 0) { throw new AddingResourceException("resource.no.item"); // no <item> element. } for (final Iterator iter = items.iterator(); iter.hasNext();) { final Element item = (Element) iter.next(); final String identifierref = item.attributeValue("identifierref"); if (identifierref == null) { continue; } final XPath resourceXPath = rootElement .createXPath("//ns:resource[@identifier='" + identifierref + "']"); resourceXPath.setNamespaceURIs(nsuris); final Element elResource = (Element) resourceXPath.selectSingleNode(elResources); if (elResource == null) { throw new AddingResourceException("resource.no.matching.resource"); } if (elResource.attribute("scormtype") != null) { return false; } if (elResource.attribute("scormType") != null) { return false; } if (elResource.attribute("SCORMTYPE") != null) { return false; } if (elResource.attributeValue("href") != null) { return true; // success. } } return false; // throw new AddingResourceException("resource.general.error"); }