List of usage examples for org.dom4j Node selectNodes
List<Node> selectNodes(String xpathExpression);
selectNodes
evaluates an XPath expression and returns the result as a List
of Node
instances or String
instances depending on the XPath expression.
From source file:pt.webdetails.cpf.plugins.Plugin.java
License:Open Source License
/** * //from w w w .java 2 s . co m * @param xpath path from root settings node * @return list of matching nodes, empty if not found */ @JsonIgnore //TODO: do we have to stick this in everything now? @SuppressWarnings("unchecked") public List<Element> getSettingsSection(String xpath) { if (hasSettingsXML()) { try { Node documentNode = XmlDom4JUtils.getDocumentFromFile(pluginDirAccess, SETTINGS_XML_FILENAME); return documentNode.selectNodes("/settings" + xpath); } catch (IOException e) { logger.error(e); } } return Collections.<Element>emptyList(); }
From source file:pt.webdetails.cpk.CpkEngine.java
License:Open Source License
private void loadElements() { try {/*w w w . j av a 2 s .c o m*/ // open settings file InputStream is = this.environment.getContentAccessFactory().getPluginSystemReader(null) .getFileInputStream(this.settingsFilename); // parse settings file SAXReader reader = new SAXReader(); Document doc = reader.read(is); // clean elements map this.elementsMap.clear(); // go through each element type List elementTypeNodes = doc.selectNodes("/cpk/elementTypes/elementType"); for (Object elementTypeNode : elementTypeNodes) { Node type = (Node) elementTypeNode; // get element type attributes String typeName = type.valueOf("./@name"); String typeClass = type.valueOf("./@class"); logger.info("Loading '" + typeName + "' elements [" + typeClass + "]"); // go through each location for elements of that type List elementLocations = type.selectNodes("elementLocations/elementLocation"); for (Object elementLocation : elementLocations) { Node location = (Node) elementLocation; // get location attributes String path = location.valueOf("@path"); Boolean isRecursive = Boolean.parseBoolean(location.valueOf("@isRecursive")); String pattern = location.valueOf("@pattern"); Boolean adminOnly = Boolean.parseBoolean(location.valueOf("@adminOnly")); // go through each file in that location and load elements Collection<File> files = this.environment.getPluginUtils().getPluginResources(path, isRecursive, pattern); if (files != null) { for (File file : files) { loadElement(typeName, typeClass, file.getAbsolutePath(), adminOnly); } } } } // get default element this.defaultElement = findDefaultElement( doc.selectSingleNode("/cpk/elementTypes").valueOf("@defaultElement").toLowerCase()); // close file is.close(); } catch (IOException e) { logger.error("Failed to open settings file '" + this.settingsFilename + "'"); } catch (DocumentException e) { logger.error("Failed to parse settings file '" + this.settingsFilename + "'"); } }
From source file:pt.webdetails.cpk.elements.AbstractElementType.java
License:Mozilla Public License
/** * Scans the location of the directory and returns a list of the content * * @param node// w w w .j av a2 s .c om */ @Override public List<IElement> scanElements(Node node) { // Initialize container ArrayList<IElement> iElements = new ArrayList<IElement>(); // Grab resource loader IPluginResourceLoader resLoader = PentahoSystem.get(IPluginResourceLoader.class, null); // Get list of files to process List<Node> elementLocations = node.selectNodes("elementLocations/elementLocation"); for (Node elementLocation : elementLocations) { // Get the list of elements. We need to filter only the ones we want String elementPath = elementLocation.valueOf("@path"); Boolean isRecursive = Boolean.parseBoolean(elementLocation.valueOf("@isRecursive")); String pattern = elementLocation.valueOf("@pattern"); Collection<File> elements = PluginUtils.getInstance().getPluginResources(elementPath, isRecursive, pattern); if (elements == null) continue; // Found the list we need. Processing it! for (File elementFile : elements) { IElement iElement = this.registerElement(elementFile.getAbsolutePath(), elementLocation); if (iElement != null) { // Now - there are some reserved words for the id iElements.add(iElement); logger.debug("Registred element " + iElement.toString()); } } } return iElements; }
From source file:pt.webdetails.di.baserver.utils.inspector.WadlParser.java
License:Open Source License
private Collection<Endpoint> parseResources(Node resourceNode, final String parentPath) { String path = resourceNode.valueOf("@path"); if (path.isEmpty()) { path = parentPath;/*ww w . j a v a2 s. c o m*/ } else { path = parentPath + "/" + sanitizePath(path); } TreeSet<Endpoint> endpoints = new TreeSet<Endpoint>(); for (Object methodNode : resourceNode.selectNodes("*[name() = 'method']")) { endpoints.add(parseMethod((Node) methodNode, path)); } /* Node methodNode = resourceNode.selectSingleNode( "*[name() = 'method']" ); if ( methodNode != null ) { } */ for (Object innerResourceNode : resourceNode.selectNodes("*[name() = 'resource']")) { endpoints.addAll(parseResources((Node) innerResourceNode, path)); } return endpoints; }
From source file:pt.webdetails.di.baserver.utils.inspector.WadlParser.java
License:Open Source License
private Endpoint parseMethod(Node methodNode, final String path) { Endpoint endpoint = new Endpoint(); endpoint.setId(methodNode.valueOf("@id")); endpoint.setHttpMethod(HttpMethod.valueOf(methodNode.valueOf("@name"))); endpoint.setPath(shortPath(path));/*from w ww . j a v a 2 s . co m*/ Node requestNode = methodNode.selectSingleNode("*[name() = 'request']"); if (requestNode != null) { for (Object queryParamNode : requestNode.selectNodes("*[name() = 'param']")) { endpoint.getQueryParams().add(parseQueryParam((Node) queryParamNode)); } } return endpoint; }
From source file:service.XML.SerXPathHandling.java
License:Open Source License
public static List getDescendentNodes(Node node) { return node.selectNodes("descendant::*"); }
From source file:treesim.TreeSim.java
private static void preParentOrderFirstDOM(Node n) { if (n != null) { if (n.getParent() == null) { System.out.println("ROOT -- \"" + n.getName() + "\""); elementNodes.add(n.getName()); } else {/*from w w w . j a v a 2 s.com*/ System.out.println("\"" + n.getParent().getName() + "\" -- \"" + n.getName() + "\""); elementNodes.add(n.getName()); } for (Object a : ((Element) n).attributes()) { System.out.println("\"" + n.getName() + "\" -- \"" + ((Attribute) a).getName() + " " + ((Attribute) a).getValue() + "\""); attributeParentNodes.add(n.getName()); attributeNodes.add(((Attribute) a).getName()); } if (!n.getText().trim().equals("")) { System.out.println("\"" + n.getName() + "\" -- \"" + n.getText().trim() + "\""); textNodeConnections.add(n.getName()); } for (Object o : n.selectNodes("child::*")) { if (n.getNodeType() == Node.ELEMENT_NODE) { preParentOrderFirstDOM((Node) o); } } } }
From source file:treesim.TreeSim.java
private static void preParentOrderSecondDOM(Node n) { if (n != null) { if (n.getParent() == null) { System.out.println("ROOT -- \"" + n.getName() + "\""); elementNodes2.add(n.getName()); } else {//from ww w. j av a 2 s. c o m System.out.println("\"" + n.getParent().getName() + "\" -- \"" + n.getName() + "\""); elementNodes2.add(n.getName()); } for (Object a : ((Element) n).attributes()) { System.out.println("\"" + n.getName() + "\" -- \"" + ((Attribute) a).getName() + " " + ((Attribute) a).getValue() + "\""); attributeParentNodes2.add(n.getName()); attributeNodes2.add(((Attribute) a).getName()); } if (!n.getText().trim().equals("")) { System.out.println("\"" + n.getName() + "\" -- \"" + n.getText().trim() + "\""); textNodeConnections2.add(n.getName()); } for (Object o : n.selectNodes("child::*")) { if (n.getNodeType() == Node.ELEMENT_NODE) { preParentOrderSecondDOM((Node) o); } } } }
From source file:us.wthr.jdem846.shapefile.modeling.FeatureTypesDefinitionLoader.java
License:Apache License
public static List<FeatureTypesDefinition> loadFeatureTypesDefinition( FeatureTypeStrokeLoader featureTypeStrokeLoader) throws Exception { List<FeatureTypesDefinition> featureTypesDefinitions = new LinkedList<FeatureTypesDefinition>(); log.info("Loading feature type definitions from " + DEFAULT_XML_FILE); Document doc = loadDocument(DEFAULT_XML_FILE); FeatureTypesDefinition featureTypeDefinition = null; //Node node = null; List<?> featureTypeDefinitionList = doc.selectNodes("//jdem846/feature-types/feature-type-definition"); for (Iterator<?> iter = featureTypeDefinitionList.iterator(); iter.hasNext();) { Node featureTypeDefinitionNode = (Node) iter.next(); Node nameAttribute = featureTypeDefinitionNode.selectSingleNode("@name"); Node idAttribute = featureTypeDefinitionNode.selectSingleNode("@id"); featureTypeDefinition = new FeatureTypesDefinition(nameAttribute.getText(), idAttribute.getText()); Node defaultStrokeNode = (Node) featureTypeDefinitionNode.selectSingleNode("default-stroke"); if (defaultStrokeNode != null) { featureTypeDefinition.setDefaultStroke( featureTypeStrokeLoader.getFeatureTypeStroke(defaultStrokeNode.getText())); }/*from w w w . j a va 2 s . co m*/ List<?> featureTypeGroupList = featureTypeDefinitionNode.selectNodes("type-groups/type-group"); for (Iterator<?> featureTypeGroupIter = featureTypeGroupList.iterator(); featureTypeGroupIter .hasNext();) { Node featureTypeGroupNode = (Node) featureTypeGroupIter.next(); Node featureTypeGroupNameAttribute = featureTypeGroupNode.selectSingleNode("@name"); Node featureTypeGroupIdAttribute = featureTypeGroupNode.selectSingleNode("@id"); Node featureTypeGroupDefaultStrokeAttribute = featureTypeGroupNode .selectSingleNode("@default-stroke"); FeatureTypeStroke featureTypeStroke = featureTypeStrokeLoader .getFeatureTypeStroke(featureTypeGroupDefaultStrokeAttribute.getText()); FeatureTypeGroup featureTypeGroup = new FeatureTypeGroup(featureTypeGroupNameAttribute.getText(), featureTypeGroupIdAttribute.getText(), featureTypeStroke); featureTypeDefinition.addFeatureTypeGroup(featureTypeGroup); } List<?> featureTypeList = featureTypeDefinitionNode.selectNodes("type"); for (Iterator<?> featureTypeIter = featureTypeList.iterator(); featureTypeIter.hasNext();) { Node featureTypeNode = (Node) featureTypeIter.next(); Node featureTypeCodeAttribute = featureTypeNode.selectSingleNode("@code"); Node featureTypeGroupIdAttribute = featureTypeNode.selectSingleNode("@group"); Node featureTypeStrokeAttribute = featureTypeNode.selectSingleNode("@stroke"); String definition = featureTypeNode.getText(); FeatureTypeGroup featureTypeGroup = featureTypeDefinition .getFeatureTypeGroup(featureTypeGroupIdAttribute.getText()); FeatureTypeStroke featureTypeStroke = null; if (featureTypeStrokeAttribute != null) { featureTypeStroke = featureTypeStrokeLoader .getFeatureTypeStroke(featureTypeStrokeAttribute.getText()); } else { featureTypeStroke = featureTypeGroup.getDefaultStroke(); } // TODO: Get FeatureTypeStroke FeatureType featureType = new FeatureType(featureTypeCodeAttribute.getText(), featureTypeGroup, definition, featureTypeStroke); featureTypeDefinition.addFeatureType(featureType); } featureTypesDefinitions.add(featureTypeDefinition); } return featureTypesDefinitions; }
From source file:us.wthr.jdem846.shapefile.modeling.FeatureTypeStrokeLoader.java
License:Apache License
public static List<FeatureTypeStroke> loadFeatureTypeStrokes() throws Exception { List<FeatureTypeStroke> featureTypeStrokes = new LinkedList<FeatureTypeStroke>(); log.info("Loading feature type line strokes from " + DEFAULT_XML_FILE); Document doc = loadDocument(DEFAULT_XML_FILE); FeatureTypeStroke featureTypeStroke = null; List<?> lineStrokeList = doc.selectNodes("//jdem846/line-strokes/line-stroke"); for (Iterator<?> iter = lineStrokeList.iterator(); iter.hasNext();) { Node lineStrokeNode = (Node) iter.next(); Node nameAttribute = lineStrokeNode.selectSingleNode("@name"); featureTypeStroke = new FeatureTypeStroke(nameAttribute.getText()); List<?> strokeList = lineStrokeNode.selectNodes("stroke"); for (Iterator<?> strokeIter = strokeList.iterator(); strokeIter.hasNext();) { Node strokeNode = (Node) strokeIter.next(); float width = 1.0f; int cap = BasicStroke.CAP_SQUARE; int join = BasicStroke.JOIN_ROUND; float miterLimit = 1.0f; float[] dash = null; float dashPhase = 0.0f; int red = 0; int green = 0; int blue = 0; int alpha = 255; Node widthNode = strokeNode.selectSingleNode("@width"); if (widthNode != null) width = Float.parseFloat(widthNode.getText()); Node capNode = strokeNode.selectSingleNode("@cap"); if (capNode != null) cap = getStrokeConstant(capNode.getText()); Node joinNode = strokeNode.selectSingleNode("@join"); if (joinNode != null) join = getStrokeConstant(joinNode.getText()); Node miterLimitNode = strokeNode.selectSingleNode("@miterLimit"); if (miterLimitNode != null) miterLimit = Float.parseFloat(miterLimitNode.getText()); Node dashNode = strokeNode.selectSingleNode("@dash"); if (dashNode != null) { String[] split = dashNode.getText().split(","); dash = new float[split.length]; for (int i = 0; i < split.length; i++) { dash[i] = Float.parseFloat(split[i]); }/*from w ww . j a va 2 s.co m*/ } Node dashPhaseNode = strokeNode.selectSingleNode("@dashPhase"); if (dashPhaseNode != null) dashPhase = Float.parseFloat(dashPhaseNode.getText()); Node redNode = strokeNode.selectSingleNode("@red"); if (redNode != null) red = Integer.parseInt(redNode.getText()); Node greenNode = strokeNode.selectSingleNode("@green"); if (greenNode != null) green = Integer.parseInt(greenNode.getText()); Node blueNode = strokeNode.selectSingleNode("@blue"); if (blueNode != null) blue = Integer.parseInt(blueNode.getText()); Node alphaNode = strokeNode.selectSingleNode("@alpha"); if (alphaNode != null) alpha = Integer.parseInt(alphaNode.getText()); Color lineColor = new Color(red, green, blue, alpha); LineStroke lineStroke = new LineStroke(width, cap, join, miterLimit, dash, dashPhase, lineColor); featureTypeStroke.addLineStroke(lineStroke); } featureTypeStrokes.add(featureTypeStroke); } return featureTypeStrokes; }