Example #1
0
 public CFNodeList selectNodes(String searchString, boolean includeEndTags) // throws Exception
     {
   // CFNodeList result = new CFNodeList();
   XPathSearch search = new XPathSearch();
   search.searchForEndTag = includeEndTags;
   if (!search.parseXPath(searchString)) {
     // throw new Exception("XPath string \'" + searchString + "\' was invalid");
   }
   return selectNodes(search);
 }
Example #2
0
  private CFNodeList selectNodes(XPathSearch search) {
    CFNodeList result = new CFNodeList();

    if (docNodes == null) {
      docNodes = new CFNodeList();
    }

    for (int i = 0; i < docNodes.size(); i++) {
      DocItem currItem = (DocItem) docNodes.get(i);
      DocItem endItem = null;
      if (search.searchForEndTag && currItem.getMatchingItem() != null) {
        endItem = currItem.getMatchingItem();
      }

      int matches = 0;
      int endMatches = 0;

      if (search.doChildNodes) result.addAll(currItem.selectNodes(search));

      // r2 added simple * node selection
      if (search.searchForTag
          && (currItem.getName().compareToIgnoreCase(search.tagName) == 0
              || search.tagName.equals("*"))) {
        matches++;
      }
      if (endItem != null
          && search.searchForTag
          && (endItem.getName().compareToIgnoreCase(search.tagName) == 0
              || search.tagName.equals("*"))) {
        endMatches++;
      }

      // System.out.print("DocItem::selectNodes() - Testing \'" + currItem.getName() + "\'");
      if (search.attrSearch.containsKey(XPathSearch.ATTR_STARTPOS)) {
        ComparisonType comp = (ComparisonType) search.attrSearch.get(XPathSearch.ATTR_STARTPOS);
        // System.out.println(XPathSearch.ATTR_STARTPOS + ": ");
        if (comp.performComparison(currItem.startPosition)) {
          matches++;
          // System.out.print(" success ");
        }
        if (endItem != null && comp.performComparison(endItem.startPosition)) {
          endMatches++;
        }
      }
      if (search.attrSearch.containsKey(XPathSearch.ATTR_ENDPOS)) {
        // System.out.print(XPathSearch.ATTR_ENDPOS + ":");
        ComparisonType comp = (ComparisonType) search.attrSearch.get(XPathSearch.ATTR_ENDPOS);
        if (comp.performComparison(currItem.endPosition)) {
          matches++;
          // System.out.print(" success ");
        }
        if (endItem != null && comp.performComparison(endItem.endPosition)) {
          endMatches++;
          // System.out.println(" failed ");
        }
      }

      if (matches == search.getMatchesRequired()) {
        // System.out.println("DocItem::selectNodes(XPathSearch) - Got match for " +
        // currItem.itemName);
        result.add(currItem);
        // System.out.print(" name match success");
      } else if (endItem != null && endMatches == search.getMatchesRequired()) {
        result.add(currItem);
        // System.out.println(" End matched " + endItem.getMatchingItem());
        // System.out.print(" name match failed with ");
      }

      // System.out.println("");
    }

    return result;
  }