prev = prev.getPreviousSibling(); if (prev != null && prev.getNodeType() == Node.ELEMENT_NODE && isSameElementType(e, (Element) prev)) firstt = false; } while (prev != null && firstt); next = next.getNextSibling(); if (next != null && next.getNodeType() == Node.ELEMENT_NODE && isSameElementType(e, (Element) next)) lastt = false; } while(next != null && lastt); return false; case NTH_CHILD: return positionMatches(countSiblingsBefore(e, false) + 1, elementIndex); case NTH_LAST_CHILD: return positionMatches(countSiblingsAfter(e, false) + 1, elementIndex); case NTH_OF_TYPE: return positionMatches(countSiblingsBefore(e, true) + 1, elementIndex); case NTH_LAST_OF_TYPE: return positionMatches(countSiblingsAfter(e, true) + 1, elementIndex); case ROOT: return e.getParentNode().getNodeType() == Node.DOCUMENT_NODE;
|| def == PseudoClassDef.NTH_LAST_OF_TYPE) { try { elementIndex = decodeIndex(args[0]); } catch (NumberFormatException e) {
prev = prev.getPreviousSibling(); if (prev != null && prev.getNodeType() == Node.ELEMENT_NODE && isSameElementType(e, (Element) prev)) firstt = false; } while (prev != null && firstt); next = next.getNextSibling(); if (next != null && next.getNodeType() == Node.ELEMENT_NODE && isSameElementType(e, (Element) next)) lastt = false; } while(next != null && lastt); return false; case NTH_CHILD: return positionMatches(countSiblingsBefore(e, false) + 1, elementIndex); case NTH_LAST_CHILD: return positionMatches(countSiblingsAfter(e, false) + 1, elementIndex); case NTH_OF_TYPE: return positionMatches(countSiblingsBefore(e, true) + 1, elementIndex); case NTH_LAST_OF_TYPE: return positionMatches(countSiblingsAfter(e, true) + 1, elementIndex); case ROOT: return e.getParentNode().getNodeType() == Node.DOCUMENT_NODE;
private PseudoClassImpl(String name, String functionValue, Selector nestedSelector) { this.name = name; type = PseudoClassType.forName(name); this.functionValue = functionValue; this.nestedSelector = nestedSelector; // Type-specific initialization if (type != null) { switch (type) { case NOT: if (nestedSelector == null && functionValue != null) { nestedSelector = new SelectorImpl(); nestedSelector.unlock(); nestedSelector.add(new ElementNameImpl(functionValue)); } break; case NTH_CHILD: case NTH_LAST_CHILD: case NTH_OF_TYPE: case NTH_LAST_OF_TYPE: elementIndex = decodeIndex(functionValue); break; } } }
/** * Computes the count of element siblings before the given element in the DOM tree. * @param e The element to be examined * @param sameType when set to <code>true</code> only the element with the same type are considered. * Otherwise, all elements are considered. * @return the number of preceding siblings */ protected int countSiblingsBefore(Element e, boolean sameType) { int cnt = 0; Node prev = e; do { prev = prev.getPreviousSibling(); if (prev != null && prev.getNodeType() == Node.ELEMENT_NODE) { if (!sameType || isSameElementType(e, (Element) prev)) cnt++; } } while (prev != null); return cnt; }
/** * Computes the count of element siblings after the given element in the DOM tree. * @param e The element to be examined * @param sameType when set to <code>true</code> only the element with the same type are considered. * Otherwise, all elements are considered. * @return the number of following siblings */ protected int countSiblingsAfter(Element e, boolean sameType) { int cnt = 0; Node next = e; do { next = next.getNextSibling(); if (next != null && next.getNodeType() == Node.ELEMENT_NODE) { if (!sameType || isSameElementType(e, (Element) next)) cnt++; } } while (next != null); return cnt; }
/** * Computes the count of element siblings after the given element in the DOM tree. * @param e The element to be examined * @param sameType when set to <code>true</code> only the element with the same type are considered. * Otherwise, all elements are considered. * @return the number of following siblings */ protected int countSiblingsAfter(Element e, boolean sameType) { int cnt = 0; Node next = e; do { next = next.getNextSibling(); if (next != null && next.getNodeType() == Node.ELEMENT_NODE) { if (!sameType || isSameElementType(e, (Element) next)) cnt++; } } while (next != null); return cnt; }
/** * Computes the count of element siblings before the given element in the DOM tree. * @param e The element to be examined * @param sameType when set to <code>true</code> only the element with the same type are considered. * Otherwise, all elements are considered. * @return the number of preceding siblings */ protected int countSiblingsBefore(Element e, boolean sameType) { int cnt = 0; Node prev = e; do { prev = prev.getPreviousSibling(); if (prev != null && prev.getNodeType() == Node.ELEMENT_NODE) { if (!sameType || isSameElementType(e, (Element) prev)) cnt++; } } while (prev != null); return cnt; }
@Override public Selector.PseudoClass createPseudoClass(String name) { return new SelectorImpl.PseudoClassImpl(name); }
@Override public Selector.PseudoClass createPseudoClass(String name, Selector nestedSelector) { return new SelectorImpl.PseudoClassImpl(name, nestedSelector); }
@Override public Selector.PseudoClass createPseudoClass(String name, String functionValue) { return new SelectorImpl.PseudoClassImpl(name, functionValue); }
public PseudoClass createPseudoClassFunction(String name, String... args) { return new SelectorImpl.PseudoClassImpl(name, args); }
public PseudoClass createPseudoClass(String name) { return new SelectorImpl.PseudoClassImpl(name); }
/** * Creates the fefault condition that matches the LINK pseudo class to links. */ public MatchConditionImpl() { pseudo = new SelectorImpl.PseudoClassImpl("link"); }