List of usage examples for org.dom4j XPath selectSingleNode
Node selectSingleNode(Object context);
selectSingleNode
evaluates this XPath expression on the given Node or List of Node s and returns the result as a single Node
instance. From source file:gov.abrs.etms.tag.ProcessImageTag.java
License:Open Source License
private int[] extractBoxConstraint(Element root, Token token) { int[] result = new int[4]; String nodeName = token.getNode().getName(); XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']"); Element node = (Element) xPath.selectSingleNode(root); result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue(); result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue(); result[2] = Integer.valueOf(node.attribute("width").getValue()).intValue(); result[3] = Integer.valueOf(node.attribute("height").getValue()).intValue(); return result; }
From source file:lost.tok.navigator.InformationComparator.java
License:Open Source License
/** * Compares according to the order.xml file which should be in the resource directory * Is not consistent with equals/* www. ja v a 2 s . c o m*/ * Resources should be in the same path * * @param r1 first res * @param r2 second res * @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object. */ public int compare(IResource r1, IResource r2) { IFolder f = (IFolder) r1.getParent(); IFile file = f.getFile("order.xml"); if (!file.exists()) { System.err.println("Error: Missing order.xml when comparing " + r1.getProjectRelativePath().toString()); return r1.getName().compareTo(r2.getName()); } Document d = GeneralFunctions.readFromXML(file); String s1 = r1.getName(); String s2 = r2.getName(); XPath xpathSelector = DocumentHelper.createXPath("//sub[name='" + s1 + "']"); Node node1 = xpathSelector.selectSingleNode(d); xpathSelector = DocumentHelper.createXPath("//sub[name='" + s2 + "']"); Node node2 = xpathSelector.selectSingleNode(d); xpathSelector = DocumentHelper.createXPath("//sub"); List list = xpathSelector.selectNodes(d); int i1 = list.indexOf(node1); int i2 = list.indexOf(node2); return i1 - i2; }
From source file:net.form105.rm.server.ant.container.InboundConfiguration.java
License:Apache License
public void readXml(Node xmlNode) { List<Node> nodes; XPath xPath; inboundType = xmlNode.valueOf("@type"); xPath = DocumentHelper.createXPath("//inbound/parameters/parameter"); nodes = (List<Node>) xPath.selectNodes(xmlNode); for (Node node : nodes) { logger.info(node);/*from ww w.j a v a2 s.c om*/ paramMap.addParameter(new ConfigParameter(node.valueOf("@key"), node.valueOf("@value"))); } xPath = DocumentHelper.createXPath("//inbound/validators/validator"); nodes = (List<Node>) xPath.selectNodes(xmlNode); for (Node node : nodes) { IInboundValidator validator = (IInboundValidator) Agent.getComponentById(node.getText()); validatorList.add(validator); } xPath = DocumentHelper.createXPath("//inbound/listeners/listener"); nodes = (List<Node>) xPath.selectNodes(xmlNode); for (Node node : nodes) { IInboundListener inboundListener = (IInboundListener) Agent.getComponentById(node.getText()); listenerList.add(inboundListener); } xPath = DocumentHelper.createXPath("//inbound/executor"); logger.info(xPath.selectSingleNode(xmlNode).getText()); command = (AbstractCallbackCommand) Agent.getComponentById(xPath.selectSingleNode(xmlNode).getText()); }
From source file:net.sf.jguard.ext.authentication.manager.XmlAuthenticationManager.java
License:Open Source License
private Element getElement(String xpath) { XPath xp2 = DocumentHelper.createXPath(xpath); Map<String, String> uris = new HashMap<String, String>(); uris.put(STRING_NAMESPACE_PREFIX, HTTP_JGUARD_SOURCEFORGE_NET_XSD_J_GUARD_USERS_PRINCIPALS_2_0_0_XSD); xp2.setNamespaceURIs(uris);/*from w w w . ja va 2 s . c o m*/ return (Element) xp2.selectSingleNode(root); }
From source file:net.sf.jguard.ext.authorization.manager.XmlAuthorizationManager.java
License:Open Source License
private Element getElement(String xpath) { XPath xp2 = DocumentHelper.createXPath(xpath); Map<String, String> uris = new HashMap<String, String>(); uris.put(STRING_NAMESPACE_PREFIX, HTTP_JGUARD_SOURCEFORGE_NET_XSD_J_GUARD_PRINCIPALS_PERMISSIONS_2_0_0); xp2.setNamespaceURIs(uris);//from ww w .j a va2 s . co m return (Element) xp2.selectSingleNode(root); }
From source file:org.alfresco.web.ui.repo.tag.JBPMProcessImageTag.java
License:Open Source License
private int[] extractBoxConstraint(Element root) { int[] result = new int[4]; String nodeName = currentToken.getNode().getName(); XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']"); Element node = (Element) xPath.selectSingleNode(root); result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue(); result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue(); result[2] = Integer.valueOf(node.attribute("width").getValue()).intValue(); result[3] = Integer.valueOf(node.attribute("height").getValue()).intValue(); return result; }
From source file:org.apache.archiva.xml.XMLReader.java
License:Apache License
public Element getElement(String xpathExpr) throws XMLException { XPath xpath = createXPath(xpathExpr); Object evaluated = xpath.selectSingleNode(document); if (evaluated == null) { return null; }/*from w ww . j ava 2 s. c o m*/ if (evaluated instanceof Element) { return (Element) evaluated; } else { // Unknown evaluated type. throw new XMLException(".getElement( Expr: " + xpathExpr + " ) resulted in non-Element type -> (" + evaluated.getClass().getName() + ") " + evaluated); } }
From source file:org.apache.archiva.xml.XMLReader.java
License:Apache License
public boolean hasElement(String xpathExpr) throws XMLException { XPath xpath = createXPath(xpathExpr); Object evaluated = xpath.selectSingleNode(document); if (evaluated == null) { return false; }/* w w w . java 2 s . co m*/ return true; }
From source file:org.apache.archiva.xml.XMLReader.java
License:Apache License
public String getElementText(Node context, String xpathExpr) throws XMLException { XPath xpath = createXPath(xpathExpr); Object evaluated = xpath.selectSingleNode(context); if (evaluated == null) { return null; }// www. ja v a2s .c om if (evaluated instanceof Element) { Element evalElem = (Element) evaluated; return evalElem.getTextTrim(); } else { // Unknown evaluated type. throw new XMLException(".getElementText( Node, Expr: " + xpathExpr + " ) resulted in non-Element type -> (" + evaluated.getClass().getName() + ") " + evaluated); } }
From source file:org.apache.archiva.xml.XMLReader.java
License:Apache License
public String getElementText(String xpathExpr) throws XMLException { XPath xpath = createXPath(xpathExpr); Object evaluated = xpath.selectSingleNode(document); if (evaluated == null) { return null; }/*from w w w . j av a2 s . c om*/ if (evaluated instanceof Element) { Element evalElem = (Element) evaluated; return evalElem.getTextTrim(); } else { // Unknown evaluated type. throw new XMLException(".getElementText( Expr: " + xpathExpr + " ) resulted in non-Element type -> (" + evaluated.getClass().getName() + ") " + evaluated); } }