예제 #1
0
 private static void getGeneralSiblingNodes(
     JsNodeArray matchingElms, JsObjectArray<String> nextTag, JsRegexp nextRegExp, Node prevRef) {
   while (JsUtils.truth((prevRef = SelectorEngine.getNextSibling(prevRef))) && !isAdded(prevRef)) {
     if (!JsUtils.truth(nextTag) || nextRegExp.test(prevRef.getNodeName())) {
       setAdded(prevRef, true);
       matchingElms.addNode(prevRef);
     }
   }
 }
예제 #2
0
 private static void getSiblingNodes(
     JsNodeArray matchingElms, JsObjectArray<String> nextTag, JsRegexp nextRegExp, Node prevRef) {
   while (JsUtils.truth(prevRef = SelectorEngine.getNextSibling(prevRef))
       && prevRef.getNodeType() != Node.ELEMENT_NODE) {}
   if (JsUtils.truth(prevRef)) {
     if (!JsUtils.truth(nextTag) || nextRegExp.test(prevRef.getNodeName())) {
       matchingElms.addNode(prevRef);
     }
   }
 }
예제 #3
0
 private void getFirstChildPseudo(
     JsNodeArray previousMatch, boolean previousDir, JsNodeArray matchingElms) {
   Node next;
   Node previous;
   for (int j = 0, jlen = previousMatch.size(); j < jlen; j++) {
     previous = next = previousMatch.getElement(j);
     if (previousDir) {
       while (JsUtils.truth((next = SelectorEngine.getPreviousSibling(next)))
           && next.getNodeType() != Node.ELEMENT_NODE) {}
     } else {
       while (JsUtils.truth((next = SelectorEngine.getNextSibling(next)))
           && next.getNodeType() != Node.ELEMENT_NODE) {}
     }
     if (!JsUtils.truth(next)) {
       matchingElms.addNode(previous);
     }
   }
 }
예제 #4
0
 private void getOnlyOfTypePseudo(JsNodeArray previousMatch, JsNodeArray matchingElms) {
   Node previous;
   Node next;
   Node prev;
   Node oParent = null;
   for (int o = 0, olen = previousMatch.size(); o < olen; o++) {
     prev = next = previous = previousMatch.getNode(o);
     Node prevParent = previous.getParentNode();
     if (prevParent != oParent) {
       while (JsUtils.truth(prev = SelectorEngine.getPreviousSibling(prev))
           && !JsUtils.eq(prev.getNodeName(), previous.getNodeName())) {}
       while (JsUtils.truth(next = SelectorEngine.getNextSibling(next))
           && !JsUtils.eq(next.getNodeName(), previous.getNodeName())) {}
       if (!JsUtils.truth(prev) && !JsUtils.truth(next)) {
         matchingElms.addNode(previous);
       }
       oParent = prevParent;
     }
   }
 }
예제 #5
0
 private void getOnlyChildPseudo(JsNodeArray previousMatch, JsNodeArray matchingElms) {
   Node previous;
   Node next;
   Node prev;
   Node kParent = null;
   for (int k = 0, klen = previousMatch.size(); k < klen; k++) {
     prev = next = previous = previousMatch.getNode(k);
     Node prevParent = previous.getParentNode();
     if (prevParent != kParent) {
       while (JsUtils.truth(prev = SelectorEngine.getPreviousSibling(prev))
           && prev.getNodeType() != Node.ELEMENT_NODE) {}
       while (JsUtils.truth(next = SelectorEngine.getNextSibling(next))
           && next.getNodeType() != Node.ELEMENT_NODE) {}
       if (!JsUtils.truth(prev) && !JsUtils.truth(next)) {
         matchingElms.addNode(previous);
       }
       kParent = prevParent;
     }
   }
 }
예제 #6
0
  private void getFirstOfTypePseudo(
      JsNodeArray previousMatch, boolean previousDir, JsNodeArray matchingElms) {
    Node previous;
    Node next;
    for (int n = 0, nlen = previousMatch.size(); n < nlen; n++) {
      next = previous = previousMatch.getNode(n);

      if (previousDir) {
        while (JsUtils.truth(next = SelectorEngine.getPreviousSibling(next))
            && !JsUtils.eq(next.getNodeName(), previous.getNodeName())) {}
      } else {
        while (JsUtils.truth(next = SelectorEngine.getNextSibling(next))
            && !JsUtils.eq(next.getNodeName(), previous.getNodeName())) {}
      }

      if (!JsUtils.truth(next)) {
        matchingElms.addNode(previous);
      }
    }
  }
예제 #7
0
 private JsNodeArray getNthChildPseudo(
     JsNodeArray previousMatch,
     String pseudoValue,
     JsNodeArray prevParents,
     JsNodeArray matchingElms) {
   Node previous;
   if (JsUtils.eq(pseudoValue, "n")) {
     matchingElms = previousMatch;
   } else {
     Sequence sequence = getSequence(pseudoValue);
     if (sequence != null) {
       for (int l = 0, llen = previousMatch.size(); l < llen; l++) {
         previous = previousMatch.getNode(l);
         Node prevParent = previous.getParentNode();
         if (!hasChildElms(prevParent)) {
           int iteratorNext = sequence.start;
           int childCount = 0;
           Node childElm = prevParent.getFirstChild();
           while (childElm != null && (sequence.max < 0 || iteratorNext <= sequence.max)) {
             if (childElm.getNodeType() == Node.ELEMENT_NODE) {
               if (++childCount == iteratorNext) {
                 if (JsUtils.eq(childElm.getNodeName(), previous.getNodeName())) {
                   matchingElms.addNode(childElm);
                 }
                 iteratorNext += sequence.add;
               }
             }
             childElm = SelectorEngine.getNextSibling(childElm);
           }
           setHasChildElms(prevParent, true);
           prevParents.addNode(prevParent);
         }
       }
       clearChildElms(prevParents);
     }
   }
   return matchingElms;
 }