Package com.google.gwt.query.client.js

Examples of com.google.gwt.query.client.js.JsRegexp


        if (truth(splitRule.allAttr)) {
          xPathExpression += replaceAttr(
              JsUtils.or(splitRule.allAttr, ""));
        }
        if (truth(splitRule.allPseudos)) {
          JsRegexp pseudoSplitRegExp = new JsRegexp(
              ":(\\w[\\w\\-]*)(\\(([^\\)]+)\\))?");
          JsRegexp pseudoMatchRegExp = new JsRegexp(
              "(:\\w+[\\w\\-]*)(\\([^\\)]+\\))?", "g");
          JsObjectArray<String> allPseudos = pseudoMatchRegExp.match(splitRule.allPseudos);
          for (int k = 0, kl = allPseudos.length(); k < kl; k++) {
            JsObjectArray<String> pseudo = pseudoSplitRegExp.match(allPseudos.get(k));
            String pseudoClass = truth(pseudo.get(1)) ? pseudo.get(1)
                .toLowerCase() : null;
            String pseudoValue = truth(pseudo.get(3)) ? pseudo.get(3)
View Full Code Here


    return JsUtils.unique(elm.<JsArray<Element>>cast()).cast();
  }

  private void init() {
    if (cssSelectorRegExp == null) {
      cssSelectorRegExp = new JsRegexp(
          "^(\\w+)?(#[\\w\\u00C0-\\uFFFF\\-\\_]+|(\\*))?((\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?((\\[\\w+(\\^|\\$|\\*|\\||~)?(=[\"']*[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+[\"']*)?\\]+)*)?(((:\\w+[\\w\\-]*)(\\((odd|even|\\-?\\d*n?((\\+|\\-)\\d+)?|[\\w\\u00C0-\\uFFFF\\-_]+|((\\w*\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?|(\\[#?\\w+(\\^|\\$|\\*|\\||~)?=?[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+\\]+)|(:\\w+[\\w\\-]*))\\))?)*)?(>|\\+|~)?");
      selectorSplitRegExp = new JsRegexp("[^\\s]+", "g");
      combinator = new JsRegexp("(>|\\+|~)");
    }
  }
View Full Code Here

    } else if (eq("disabled", pseudoClass)) {
      xpath = "@disabled";
    } else if (eq("checked", pseudoClass)) {
      xpath = "@checked='checked'"; // Doesn't work in Opera 9.24
    } else if (eq("not", pseudoClass)) {
      if (new JsRegexp("^(:\\w+[\\w\\-]*)$").test(pseudoValue)) {
        xpath = "not(" + pseudoToXPath(tag, pseudoValue.substring(1), "") + ")";
      } else {

        pseudoValue = pseudoValue
            .replaceFirst("^\\[#([\\w\\u00C0-\\uFFFF\\-\\_]+)\\]$", "[id=$1]");
View Full Code Here

    }
  }

  protected static Sequence getSequence(String expression) {
    int start = 0, add = 2, max = -1, modVal = -1;
    JsRegexp expressionRegExp = new JsRegexp(
        "^((odd|even)|([1-9]\\d*)|((([1-9]\\d*)?)n((\\+|\\-)(\\d+))?)|(\\-(([1-9]\\d*)?)n\\+(\\d+)))$");
    JsObjectArray<String> pseudoValue = expressionRegExp.exec(expression);
    if (!truth(pseudoValue)) {
      return null;
    } else {
      if (truth(pseudoValue.get(2))) {        // odd or even
        start = (eq(pseudoValue.get(2), "odd")) ? 1 : 2;
View Full Code Here

  private JsRegexp selectorSplitRegExp;

  private JsRegexp childOrSiblingRefRegExp;

  public SelectorEngineJS() {
    selectorSplitRegExp = new JsRegexp("[^\\s]+", "g");
    childOrSiblingRefRegExp = new JsRegexp("^(>|\\+|~)$");
    cssSelectorRegExp = new JsRegexp(
        "^(\\w+)?(#[\\w\\u00C0-\\uFFFF\\-\\_]+|(\\*))?((\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?((\\[\\w+(\\^|\\$|\\*|\\||~)?(=[\"']*[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+[\"']*)?\\]+)*)?(((:\\w+[\\w\\-]*)(\\((odd|even|\\-?\\d*n?((\\+|\\-)\\d+)?|[\\w\\u00C0-\\uFFFF\\-_]+|((\\w*\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?|(\\[#?\\w+(\\^|\\$|\\*|\\||~)?=?[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+\\]+)|(:\\w+[\\w\\-]*))\\))?)*)?");
  }
View Full Code Here

        JsNodeArray matchingElms = JsNodeArray.create();
        String rule = cssSelectors.get(i);
        if (i > 0 && childOrSiblingRefRegExp.test(rule)) {
          JsObjectArray<String> childOrSiblingRef = childOrSiblingRefRegExp.exec(rule);
          if (JsUtils.truth(childOrSiblingRef)) {
            JsObjectArray<String> nextTag = new JsRegexp("^\\w+")
                .exec(cssSelectors.get(i + 1));
            JsRegexp nextRegExp = null;
            String nextTagStr = null;
            if (JsUtils.truth(nextTag)) {
              nextTagStr = nextTag.get(0);
              nextRegExp = new JsRegexp("(^|\\s)" + nextTagStr + "(\\s|$)", "i");
            }
            for (int j = 0, jlen = prevElem.size(); j < jlen; j++) {
              Node prevRef = prevElem.getNode(j);
              String ref = childOrSiblingRef.get(0);
              if (JsUtils.eq(">", ref)) {
                getDescendantNodes(matchingElms, nextTagStr, prevRef);
              } else if (JsUtils.eq("+", ref)) {
                getSiblingNodes(matchingElms, nextTag, nextRegExp, prevRef);
              } else if (JsUtils.eq("~", ref)) {
                getGeneralSiblingNodes(matchingElms, nextTag, nextRegExp,
                    prevRef);
              }
            }
            prevElem = matchingElms;
            clearAdded(prevElem);
            rule = cssSelectors.get(++i);
            if (new JsRegexp("^\\w+$").test(rule)) {
              continue;
            }
            setSkipTag(prevElem, true);
          }
        }
        JsObjectArray<String> cssSelector = cssSelectorRegExp.exec(rule);
        SplitRule splitRule = new SplitRule(
            !JsUtils.truth(cssSelector.get(1)) || JsUtils
                .eq(cssSelector.get(3), "*") ? "*" : cssSelector.get(1),
            !JsUtils.eq(cssSelector.get(3), "*") ? cssSelector
                .get(2) : null, cssSelector.get(4), cssSelector.get(6),
            cssSelector.get(10));
        if (JsUtils.truth(splitRule.id)) {
          Element domelem = Document.get()
              .getElementById(splitRule.id.substring(1));
          if (JsUtils.truth(domelem)) {
            matchingElms = JsNodeArray.create(domelem);
          }
          prevElem = matchingElms;
        } else if (JsUtils.truth(splitRule.tag) && !isSkipped(
            prevElem)) {
          if (i == 0 && matchingElms.size() == 0 && prevElem.size() == 1) {
            prevElem = matchingElms = JsNodeArray.create(
                getElementsByTagName(splitRule.tag, prevElem.getNode(0)));
          } else {
            NodeList<Element> tagCollectionMatches;
            for (int l = 0, ll = prevElem.size(); l < ll; l++) {
              tagCollectionMatches = getElementsByTagName(splitRule.tag,
                  prevElem.getNode(l));
              for (int m = 0, mlen = tagCollectionMatches.getLength(); m < mlen;
                  m++) {
                Node tagMatch = tagCollectionMatches.getItem(m);

                if (!isAdded(tagMatch)) {
                  setAdded(tagMatch, true);
                  matchingElms.addNode(tagMatch);
                }
              }
            }
            prevElem = matchingElms;
            clearAdded(prevElem);
          }
          if (matchingElms.size() == 0) {
            break;
          }
          setSkipTag(prevElem, false);
          if (JsUtils.truth(splitRule.allClasses)) {
            String[] allClasses = splitRule.allClasses.replaceFirst("^\\.", "")
                .split("\\.");
            JsRegexp[] regExpClassNames = new JsRegexp[allClasses.length];
            for (int n = 0, nl = allClasses.length; n < nl; n++) {
              regExpClassNames[n] = new JsRegexp(
                  "(^|\\s)" + allClasses[n] + "(\\s|$)");
            }
            JsNodeArray matchingClassElms = JsNodeArray.create();
            for (int o = 0, olen = prevElem.size(); o < olen; o++) {
              Element current = prevElem.getElement(o);
              String elmClass = current.getClassName();
              boolean addElm = false;
              if (JsUtils.truth(elmClass) && !isAdded(current)) {
                for (int p = 0, pl = regExpClassNames.length; p < pl; p++) {
                  addElm = regExpClassNames[p].test(elmClass);
                  if (!addElm) {
                    break;
                  }
                }
                if (addElm) {
                  setAdded(current, true);
                  matchingClassElms.addNode(current);
                }
              }
            }
            clearAdded(prevElem);
            prevElem = matchingElms = matchingClassElms;
          }
          if (JsUtils.truth(splitRule.allAttr)) {
            JsObjectArray<String> allAttr = JsRegexp
                .match("\\[[^\\]]+\\]", "g", splitRule.allAttr);
            JsRegexp[] regExpAttributes = new JsRegexp[allAttr.length()];
            String[] regExpAttributesStr = new String[allAttr.length()];
            JsRegexp attributeMatchRegExp = new JsRegexp(
                "(\\w+)(\\^|\\$|\\*|\\||~)?=?[\"']?([\\w\u00C0-\uFFFF\\s\\-_\\.]+)?");
            for (int q = 0, ql = allAttr.length(); q < ql; q++) {
              JsObjectArray<String> attributeMatch = attributeMatchRegExp
                  .exec(allAttr.get(q));
              String attributeValue =
                  JsUtils.truth(attributeMatch.get(3))
                      ? attributeMatch.get(3).replaceAll("\\.", "\\.")
                      : null;
              String attrVal = attrToRegExp(attributeValue,
                  (JsUtils.or(attributeMatch.get(2), null)));
              regExpAttributes[q] = (JsUtils.truth(attrVal) ? new JsRegexp(
                  attrVal) : null);
              regExpAttributesStr[q] = attributeMatch.get(1);
            }
            JsNodeArray matchingAttributeElms = JsNodeArray.create();

            for (int r = 0, rlen = matchingElms.size(); r < rlen; r++) {
              Element current = matchingElms.getElement(r);
              boolean addElm = false;
              for (int s = 0, sl = regExpAttributes.length;
                  s < sl; s++) {
                addElm = false;
                JsRegexp attributeRegexp = regExpAttributes[s];
                String currentAttr = getAttr(current, regExpAttributesStr[s]);
                if (JsUtils.truth(currentAttr)
                    && currentAttr.length() != 0) {
                  if (attributeRegexp == null || attributeRegexp
                      .test(currentAttr)) {
                    addElm = true;
                  }
                }
                if (!addElm) {
                  break;
                }
              }
              if (addElm) {
                matchingAttributeElms.addNode(current);
              }
            }
            prevElem = matchingElms = matchingAttributeElms;
          }
          if (JsUtils.truth(splitRule.allPseudos)) {
            JsRegexp pseudoSplitRegExp = new JsRegexp(
                ":(\\w[\\w\\-]*)(\\(([^\\)]+)\\))?");

            JsObjectArray<String> allPseudos = JsRegexp
                .match("(:\\w+[\\w\\-]*)(\\([^\\)]+\\))?", "g",
                    splitRule.allPseudos);
            for (int t = 0, tl = allPseudos.length(); t < tl; t++) {
              JsObjectArray<String> pseudo = pseudoSplitRegExp.match(allPseudos.get(t));
              String pseudoClass = JsUtils.truth(pseudo.get(1))
                  ? pseudo.get(1).toLowerCase() : null;
              String pseudoValue = JsUtils.truth(pseudo.get(3))
                  ? pseudo.get(3) : null;
              matchingElms = getElementsByPseudo(matchingElms, pseudoClass,
View Full Code Here

    }
  }

  private JsNodeArray getNotPseudo(JsNodeArray previousMatch, String pseudoValue,
      JsNodeArray matchingElms) {
    if (new JsRegexp("(:\\w+[\\w\\-]*)$").test(pseudoValue)) {
      matchingElms = subtractArray(previousMatch,
          getElementsByPseudo(previousMatch, pseudoValue.substring(1), ""));
    } else {
      pseudoValue = pseudoValue
          .replace("^\\[#([\\w\\u00C0-\\uFFFF\\-\\_]+)\\]$", "[id=$1]");
      JsObjectArray<String> notTag = new JsRegexp("^(\\w+)").exec(pseudoValue);
      JsObjectArray<String> notClass = new JsRegexp("^\\.([\\w\u00C0-\uFFFF\\-_]+)")
          .exec(pseudoValue);
      JsObjectArray<String> notAttr = new JsRegexp(
          "\\[(\\w+)(\\^|\\$|\\*|\\||~)?=?([\\w\\u00C0-\\uFFFF\\s\\-_\\.]+)?\\]")
          .exec(pseudoValue);
      JsRegexp notRegExp = new JsRegexp("(^|\\s)"
          + (JsUtils.truth(notTag) ? notTag.get(1)
          : JsUtils.truth(notClass) ? notClass.get(1) : "")
          + "(\\s|$)", "i");
      if (JsUtils.truth(notAttr)) {
        String notAttribute = JsUtils.truth(notAttr.get(3)) ? notAttr
            .get(3).replace("\\.", "\\.") : null;
        String notMatchingAttrVal = attrToRegExp(notAttribute,
            notAttr.get(2));
        notRegExp = new JsRegexp(notMatchingAttrVal, "i");
      }
      for (int v = 0, vlen = previousMatch.size(); v < vlen; v++) {
        Element notElm = previousMatch.getElement(v);
        Element addElm = null;
        if (JsUtils.truth(notTag) && !notRegExp
            .test(notElm.getNodeName())) {
          addElm = notElm;
        } else if (JsUtils.truth(notClass) && !notRegExp
            .test(notElm.getClassName())) {
          addElm = notElm;
        } else if (JsUtils.truth(notAttr)) {
          String att = getAttr(notElm, notAttr.get(1));
          if (!JsUtils.truth(att) || !notRegExp.test(att)) {
            addElm = notElm;
          }
        }
        if (JsUtils.truth(addElm) && !isAdded(addElm)) {
          setAdded(addElm, true);
View Full Code Here

TOP

Related Classes of com.google.gwt.query.client.js.JsRegexp

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.