Exemple #1
0
  public boolean match(String search, Tag child, Tag mapping) {
    String target = child.getName();
    String sn = null;
    String tn = null;

    if (search.equals("*")) return true;

    int s = search.indexOf(':');
    if (s > 0) {
      sn = search.substring(0, s);
      search = search.substring(s + 1);
    }
    int t = target.indexOf(':');
    if (t > 0) {
      tn = target.substring(0, t);
      target = target.substring(t + 1);
    }

    if (!search.equals(target)) // different tag names
    return false;

    if (mapping == null) {
      return tn == sn || (sn != null && sn.equals(tn));
    } else {
      String suri =
          sn == null ? mapping.getAttribute("xmlns") : mapping.getAttribute("xmlns:" + sn);
      String turi =
          tn == null
              ? child.findRecursiveAttribute("xmlns")
              : child.findRecursiveAttribute("xmlns:" + tn);
      return turi == suri || (turi != null && suri != null && turi.equals(suri));
    }
  }
Exemple #2
0
  void select(String path, Vector<Object> results, Tag mapping) {
    if (path.startsWith("//")) {
      int i = path.indexOf('/', 2);
      String name = path.substring(2, i < 0 ? path.length() : i);

      for (Object o : content) {
        if (o instanceof Tag) {
          Tag child = (Tag) o;
          if (match(name, child, mapping)) results.add(child);
          child.select(path, results, mapping);
        }
      }
      return;
    }

    if (path.length() == 0) {
      results.addElement(this);
      return;
    }

    int i = path.indexOf("/");
    String elementName = path;
    String remainder = "";
    if (i > 0) {
      elementName = path.substring(0, i);
      remainder = path.substring(i + 1);
    }

    for (Object o : content) {
      if (o instanceof Tag) {
        Tag child = (Tag) o;
        if (child.getName().equals(elementName) || elementName.equals("*"))
          child.select(remainder, results, mapping);
      }
    }
  }