List of usage examples for org.apache.commons.jxpath JXPathContext selectNodes
public List selectNodes(String xpath)
From source file:org.commonjava.maven.galley.maven.model.view.MavenXmlView.java
/** * Select the ordered list of nodes matching the given XPath expression, rooted in the given context. If * cachePath is true, compile the XPath expression and cache for future use. This is useful if the * expression isn't overly specific, and will be used multiple times. */// ww w.ja v a 2s .c o m public synchronized List<Node> resolveXPathToNodeListFrom(final JXPathContext context, final String path, final boolean cachePath) throws GalleyMavenRuntimeException { final List<Node> result = new ArrayList<>(); final List<?> iter = context.selectNodes(path); if (iter != null) { for (final Object obj : iter) { result.add((Node) obj); } } return result; }
From source file:org.freud.analysed.css.jdom.CssJdomParser.java
@SuppressWarnings("unchecked") static Iterable<CssRule> parseCssRules(final Reader reader) throws RecognitionException, IOException { List<CssRule> cssRuleList = new ArrayList<CssRule>(); Document root = parseCssToDocument(reader); JXPathContext context = JXPathContext.newContext(root.getRootElement()); List<Element> cssRuleElementList = (List<Element>) context.selectNodes("/RULE"); for (Element element : cssRuleElementList) { final CssRuleJdom cssRuleJdom = new CssRuleJdom(element, 0); cssRuleList.add(cssRuleJdom);/*w ww.j a v a 2 s. co m*/ for (int i = 1; i < cssRuleJdom.getNumberOfCommaSeparatedSelectorLists(); i++) { cssRuleList.add(new CssRuleJdom(element, i)); } } return cssRuleList; }
From source file:org.freud.analysed.css.jdom.CssRuleJdom.java
@SuppressWarnings("unchecked") private void parseDeclarations() { cssDeclarationList = new ArrayList<CssDeclaration>(); JXPathContext context = JXPathContext.newContext(ruleElement); List<Element> cssSelectorElementList = (List<Element>) context .selectNodes("/" + CssTokenType.PROPERTY.name()); for (Element element : cssSelectorElementList) { cssDeclarationList.add(new CssDeclarationJdom(this, element)); }//from w w w. j av a 2 s .c o m }
From source file:org.freud.analysed.javasource.jdom.AnnotationJdom.java
private String getAnnotationValueForElement(final Element element) { final JXPathContext context = JXPathContext.newContext(element); final Element expr = (Element) context.selectSingleNode("/" + JavaSourceTokenType.EXPR.name() + "/*"); if (expr != null) { return expr.getText(); } else {/*from www . j a v a 2s.co m*/ final List<Element> exprList = context.selectNodes("//" + JavaSourceTokenType.EXPR.name() + "/*"); StringBuilder sb = new StringBuilder("{"); for (Element item : exprList) { sb.append(item.getText()).append(","); } sb.setCharAt(sb.length() - 1, '}'); return sb.toString(); } }
From source file:org.freud.analysed.javasource.jdom.ClassDeclarationJdom.java
@SuppressWarnings("unchecked") public Map<String, ClassDeclaration> getInnerClassDeclarationByNameMap() { if (innerClassDeclarationByNameMap == null) { JXPathContext context = JXPathContext.newContext(classDeclElement); innerClassDeclarationByNameMap = new LinkedHashMap<String, ClassDeclaration>(); for (JavaSourceTokenType tokenType : POSSIBLE_CLASS_DECLARATION_TYPES) { final String tokenName = tokenType.getName(); List<Element> innerClassElementList = context .selectNodes("/" + CLASS_TOP_LEVEL_SCOPE.getName() + "/" + tokenName); for (Element innerClassElement : innerClassElementList) { ClassDeclaration innerClass = new ClassDeclarationJdom(innerClassElement, DeclarationType.valueOf(tokenName), this); innerClassDeclarationByNameMap.put(innerClass.getName(), innerClass); }//from w w w .j ava2 s .co m } } return innerClassDeclarationByNameMap; }
From source file:org.freud.analysed.javasource.jdom.ClassDeclarationJdom.java
private void getMethodDeclarationListByNameMap(final JXPathContext context) { List<Element> methodDeclElementList = context .selectNodes("//" + FUNCTION_METHOD_DECL.getName() + "|//" + VOID_METHOD_DECL.getName()); for (Element methodElement : methodDeclElementList) { MethodDeclaration methodDeclaration = new MethodDeclarationJdom(methodElement, this); final String name = methodDeclaration.getName(); List<MethodDeclaration> methodDeclarationList = methodDeclarationListByNameMap.get(name); if (methodDeclarationList == null) { methodDeclarationList = new LinkedList<MethodDeclaration>(); methodDeclarationListByNameMap.put(name, methodDeclarationList); }//from w w w . j ava 2s. c o m methodDeclarationList.add(methodDeclaration); } }
From source file:org.freud.analysed.javasource.jdom.CodeBlockJdom.java
@Override @SuppressWarnings("unchecked") public Map<String, List<MethodCall>> getMethodCallByMethodNameMap() { if (methodCallByMethodNameMap == null) { methodCallByMethodNameMap = new HashMap<String, List<MethodCall>>(); JXPathContext context = JXPathContext.newContext(codeBlockElement); List<Element> methodCallElementList = context .selectNodes("//" + JavaSourceTokenType.METHOD_CALL.getName()); for (Element methodCallElement : methodCallElementList) { final MethodCall methodCall = new MethodCallJdom(methodCallElement); List<MethodCall> methodCallList = methodCallByMethodNameMap.get(methodCall.getMethodName()); if (methodCallList == null) { methodCallList = new LinkedList<MethodCall>(); methodCallByMethodNameMap.put(methodCall.getMethodName(), methodCallList); }//from w w w . j a v a 2 s. c om methodCallList.add(methodCall); } } return methodCallByMethodNameMap; }
From source file:org.freud.analysed.javasource.jdom.JavaSourceJdom.java
private List<ImportDeclaration> parseImportDeclaration() { try {//from w w w .j a v a2 s . com final JXPathContext context = JXPathContext.newContext(root); final List importNodes = context .selectNodes("/" + JAVA_SOURCE_ROOT_ELEMENT_NAME + "/" + JavaSourceTokenType.IMPORT.name()); importDeclarations = new ArrayList<ImportDeclaration>(importNodes.size()); for (Object importNode : importNodes) { importDeclarations.add(new ImportDeclarationJdom((Element) importNode)); } } catch (JXPathException e) { importDeclarations = emptyList(); } return importDeclarations; }
From source file:org.freud.analysed.javasource.jdom.JavaSourceJdom.java
public static List<Annotation> parseAnnotations(final Element element) { final List<Annotation> annotations; JXPathContext context = JXPathContext.newContext(element); List annotationList = context.selectNodes( "/" + JavaSourceTokenType.MODIFIER_LIST.getName() + "/" + JavaSourceTokenType.AT.getName()); annotations = new ArrayList<Annotation>(annotationList.size()); for (Object annotationElement : annotationList) { annotations.add(new AnnotationJdom((Element) annotationElement)); }//from www . j a v a 2 s . c o m return annotations; }
From source file:org.freud.analysed.javasource.jdom.MethodCallJdom.java
@SuppressWarnings("unchecked") public String getMethodName() { if (methodName == null) { final Attribute idAttr = methodCallElement.getAttribute(JdomTreeAdaptor.ID_ATTR); if (idAttr != null) { methodName = idAttr.getValue(); instanceReferences = EMPTY_ARRAY; } else {/* ww w.j a v a 2 s . c o m*/ JXPathContext context = JXPathContext.newContext(methodCallElement); final List<Element> identElementList = context .selectNodes("//" + JavaSourceTokenType.IDENT.getName()); Collections.sort(identElementList, JdomTreePositionComparator.getInstance()); final int methodNameIndex = identElementList.size() - 1; methodName = identElementList.get(methodNameIndex).getText(); instanceReferences = new String[methodNameIndex]; for (int i = 0, size = instanceReferences.length; i < size; i++) { instanceReferences[i] = identElementList.get(i).getText(); } } } return methodName; }