Example usage for com.google.gwt.regexp.shared RegExp exec

List of usage examples for com.google.gwt.regexp.shared RegExp exec

Introduction

In this page you can find the example usage for com.google.gwt.regexp.shared RegExp exec.

Prototype

public final MatchResult exec(String input) 

Source Link

Usage

From source file:ch.takoyaki.email.html.client.utils.Html.java

License:Open Source License

public static String inlinecss(String content, FileService fService) {

    RegExp p = RegExp.compile("<link [^>]*href=\"([^\"]*)\"[^>]*/?>", "gmi");

    MatchResult matcher = p.exec(content);
    while (matcher != null) {
        String tag = matcher.getGroup(0);
        String href = matcher.getGroup(1);
        String cssContent = fService.retrieve(href);
        if (cssContent == null) {
            cssContent = "";
        }/*from  ww w  . ja v a2s. c  o m*/
        cssContent = "<style>" + cssContent + "</style>";
        content = content.replace(tag, cssContent);
        matcher = p.exec(content);
    }
    return content;
}

From source file:ch.takoyaki.email.html.client.utils.Xsl.java

License:Open Source License

public static String loadStyleSheetContent(String content, FileService fservice) {

    String type = "";
    String href = "";

    content = stripXmlComments(content);
    RegExp p = RegExp.compile("<\\?xml-stylesheet[^>]*type=\"([^\"]*)", "m");
    MatchResult r = p.exec(content);
    if (r != null) {
        type = r.getGroup(1);/* ww w . j a  v  a 2 s.  c  o m*/
    }
    p = RegExp.compile("<\\?xml-stylesheet[^>]*href=\"([^\"]*)", "m");
    r = p.exec(content);
    if (r != null) {
        href = r.getGroup(1);
    }

    if (!type.equals("text/xsl") || "".equals(href)) {
        return null;
    }

    String xsl = fservice.retrieve(href);

    xsl = inlineXslInclude(xsl, fservice);
    return xsl;
}

From source file:ch.takoyaki.email.html.client.utils.Xsl.java

License:Open Source License

private static String inlineXslInclude(String xsl, FileService fService) {

    RegExp p = RegExp.compile("<[^:]*:?include[^>]*href=\"([^\"]*)\"[^>]*/?>", "gmi");

    MatchResult matcher = p.exec(xsl);
    while (matcher != null) {
        String tag = matcher.getGroup(0);
        String href = matcher.getGroup(1);
        String xslinclude = fService.retrieve(href);
        if (xslinclude == null) {
            xslinclude = "";
        }/*from  w  ww  . ja  v  a 2s  . c om*/
        xslinclude = xslIncludeStrip(xslinclude);
        xsl = xsl.replace(tag, xslinclude);
        matcher = p.exec(xsl);
    }
    return xsl;
}

From source file:ch.takoyaki.email.html.client.utils.Xsl.java

License:Open Source License

private static String xslIncludeStrip(String xslinclude) {
    RegExp p = RegExp.compile("<[^:]*:?stylesheet[^>]*>([\\w\\W]*)</[^:]*:?stylesheet>", "gmi");
    MatchResult m = p.exec(xslinclude);
    if (m != null) {
        return m.getGroup(1);
    }/*  w  w  w.  j  a  va  2 s  . c  om*/
    return "";
}

From source file:ch.unifr.pai.twice.mousecontrol.client.TouchPadWidget.java

License:Apache License

/**
 * Helper method to extract values from the HTTP-response by the given regular expression
 * //w ww  . ja v  a  2 s. c o  m
 * @param response
 * @param regex
 * @return
 */
private static String extractByRegex(Response response, String regex) {
    RegExp re = RegExp.compile(regex);
    MatchResult result = re.exec(response.getText());
    return result.getGroup(0);
}

From source file:cimav.client.view.provider.DeptosProvider.java

@Override
public boolean matchFilter(Departamento value, String filter) {
    if (value == null) {
        return false;
    }// ww  w  .ja v a2  s.c  om
    if (filter == null || filter.trim().isEmpty()) {
        return true;
    }

    // ^.*\b(one|two|three)\b.*$    one, tow or three
    // ^(?=.*?\bone\b)(?=.*?\btwo\b)(?=.*?\bthree\b).*$ one, two AND three
    // ^(?=.*?one)(?=.*?two)(?=.*?three).*$ las palabras no tiene boundiry
    // la frase completa debe tener todos los terminos
    String pattern = "^";
    filter = filter.toLowerCase();
    String[] array = filter.split("\\s+");
    for (String term : array) {
        pattern = pattern + "(?=.*?" + term.trim() + ")";
    }
    pattern = pattern + ".+";

    String string = value.getName() + " " + value.getCode();
    string = string.toLowerCase();

    RegExp regExp = RegExp.compile(pattern);
    MatchResult matcher = regExp.exec(string);

    return matcher != null;
}

From source file:cimav.client.view.provider.EmpleadosBaseProvider.java

@Override
public boolean matchFilter(EmpleadoBase value, String filter) {
    if (value == null) {
        return false;
    }/*from   ww  w .j a  v  a  2s .  co  m*/
    if (filter == null || filter.trim().isEmpty()) {
        return true;
    }

    boolean hasAya = filter.toLowerCase().contains("a:");
    if (hasAya) {
        filter = filter.replace("a:", "");
    }
    boolean hasHon = filter.toLowerCase().contains("h:");
    if (hasHon) {
        filter = filter.replace("h:", "");
    }

    // ^.*\b(one|two|three)\b.*$    one, tow or three
    // ^(?=.*?\bone\b)(?=.*?\btwo\b)(?=.*?\bthree\b).*$ one, two AND three
    // ^(?=.*?one)(?=.*?two)(?=.*?three).*$ las palabras no tiene boundiry
    // la frase completa debe tener todos los terminos
    String pattern = "^";
    filter = filter.toLowerCase();
    String[] array = filter.split("\\s+");
    for (String term : array) {
        pattern = pattern + "(?=.*?" + term.trim() + ")";
    }
    pattern = pattern + ".+";

    String grupoStr = value.getGrupo() != null ? value.getGrupo().getCode() + " " + value.getGrupo().getName()
            : " ";
    String codeGrupolStr = value.getGrupo() != null ? value.getGrupo().getCode() : " ";
    String nivelStr = value.getNivel() != null ? value.getNivel().getCode() + " " + value.getNivel().getName()
            : " ";
    String sedeStr = value.getSede() != null ? value.getSede().getAbrev() + " " + value.getSede().getNombre()
            : " ";
    String deptoStr = value.getDepartamento() != null
            ? value.getDepartamento().getCode() + " " + value.getDepartamento().getName()
            : " ";

    String string = value.getName() /*+ " " + value.getRfc()*/ + " " + value.getCode() + " "
            + value.getCuentaCimav() + " " + grupoStr + " " + nivelStr + " " + sedeStr + " " + deptoStr;
    string = string.toLowerCase();

    RegExp regExp = RegExp.compile(pattern);
    MatchResult matcher = regExp.exec(string);

    boolean result = matcher != null;

    if (hasAya) {
        result = result && (codeGrupolStr.toLowerCase().contains("aya"));
    }
    if (hasHon) {
        result = result && (codeGrupolStr.toLowerCase().contains("hon"));
    }

    return result;
}

From source file:cimav.client.view.provider.EmpleadosProvider.java

@Override
public boolean matchFilter(Empleado value, String filter) {
    if (value == null) {
        return false;
    }/*w w w .j  av a2s.  c o m*/
    if (filter == null || filter.trim().isEmpty()) {
        return true;
    }

    // ^.*\b(one|two|three)\b.*$    one, tow or three
    // ^(?=.*?\bone\b)(?=.*?\btwo\b)(?=.*?\bthree\b).*$ one, two AND three
    // ^(?=.*?one)(?=.*?two)(?=.*?three).*$ las palabras no tiene boundiry
    // la frase completa debe tener todos los terminos
    String pattern = "^";
    filter = filter.toLowerCase();
    String[] array = filter.split("\\s+");
    for (String term : array) {
        pattern = pattern + "(?=.*?" + term.trim() + ")";
    }
    pattern = pattern + ".+";

    String grupoStr = value.getGrupo() != null ? value.getGrupo().getCode() + " " + value.getGrupo().getName()
            : " ";
    String nivelStr = value.getNivel() != null ? value.getNivel().getCode() + " " + value.getNivel().getName()
            : " ";
    String sedeStr = value.getSede() != null ? value.getSede().getAbrev() + " " + value.getSede().getNombre()
            : " ";
    String deptoStr = value.getDepartamento() != null
            ? value.getDepartamento().getCode() + " " + value.getDepartamento().getName()
            : " ";

    String string = value.getName() + " " + value.getRfc() + " " + value.getCode() + " "
            + value.getCuentaCimav() + " " + grupoStr + " " + nivelStr + " " + sedeStr + " " + deptoStr;
    string = string.toLowerCase();

    RegExp regExp = RegExp.compile(pattern);
    MatchResult matcher = regExp.exec(string);

    return matcher != null;
}

From source file:client.net.sf.saxon.ce.dom.HTMLNodeWrapper.java

License:Mozilla Public License

private String getStyleAttribute(Element elem) {
    // style attribute must exist and must be quoted properly
    // IE9 does not include style attributes text if their value is not valid
    // we therefore don't expect non-quoted styles like <h1 style=color id="abc"...
    String value = getOuterHTML(elem);

    RegExp quotesPattern = RegExp.compile("(?:\".*?\"|\'.*?\'|[^\'\"]+|['\"])", "g"); // g=global: = all-matches 
    RegExp stylePattern = RegExp.compile("[\\s]style\\s*="); // e.g. match: <h1 style=
    MatchResult m = quotesPattern.exec(value);

    int i = 0;//  ww w  . j a va  2 s.  c om
    boolean styleFound = false;
    String styleContent = "";
    String nonQ = "";
    while (quotesPattern.getLastIndex() > 0) {
        if (i % 2 == 0) {
            nonQ = m.getGroup(0); // not in quotes - so check
            MatchResult ms = stylePattern.exec(nonQ);
            styleFound = ms.getGroupCount() > 0;
            if (!styleFound && nonQ.indexOf('>') > -1) {
                break; // no more attributes
            }
        } else if (styleFound) {
            styleContent = m.getGroup(0);
            // remove enclosing quotes
            styleContent = styleContent.substring(1, styleContent.length() - 1);
            break;
        }
        i++;
        m = quotesPattern.exec(value);
    }
    return styleContent;
}

From source file:client.net.sf.saxon.ce.dom.HTMLNodeWrapper.java

License:Mozilla Public License

private HTMLAttributeNode[] getAltAttributes() {
    if (attributeList != null) {
        return attributeList;
    }/*from   w w w  .ja  va2  s . co m*/
    Element elem = (Element) node;

    // Browser implementations of attributes property are potentially buggy - but preferred to
    // parsing the string. But IE6 and IE7 both list all possible attributes whether they
    // exist or not - so use outerHTML in these cases.
    int ieVersion = Configuration.getIeVersion();
    if (ieVersion < 0 || ieVersion > 8) {
        return getMainAttributes(elem);
    }

    String value = getOuterHTML(elem);

    if (value == null) {
        return getMainAttributes(elem);
    }

    ArrayList<String> nodeNames = new ArrayList<String>();
    ArrayList<String> xmlnsNames = new ArrayList<String>();
    ArrayList<String> xmlnsUris = new ArrayList<String>();
    namespaceBindings = new ArrayList<NamespaceBinding>();

    RegExp quotesPattern = RegExp.compile("(?:\"(.|\n)*?\"|\'(.|\n)*?\'|[^\'\"]+|['\"])", "gm"); // g=global: = all-matches m=multiline 
    MatchResult m = quotesPattern.exec(value);

    int i = 0;
    String nonQ = "";
    boolean awaitingXmlnsUri = false;
    while (quotesPattern.getLastIndex() > 0) {

        if (i % 2 == 0) {
            nonQ = m.getGroup(0); // not in quotes - so check
            StringBuffer sb = new StringBuffer();
            boolean endOfTag = false;
            boolean isName = !(i == 0);// first part is not a name: e.g. \r\n<H1 style="
            int start = 0;
            if (i == 0) {
                start = nonQ.indexOf('<') + 1;
            }
            for (int x = start; x < nonQ.length(); x++) {
                int[] offsetChar = skipWhitespace(x, nonQ, false);
                int offset = offsetChar[0];

                if (offset > 0 && !(isName)) {
                    // no whitespace allow in an unquoted value, so we're back on a name
                    isName = true;
                }
                char ch = (char) offsetChar[1];
                if (ch == '\0')
                    break;
                if (ch == '=') {
                    // part after the '=' is the value, until next whitespace
                    isName = false;
                    String attName = sb.toString();

                    if (attName.startsWith("xmlns")) {
                        xmlnsNames.add(attName);
                        awaitingXmlnsUri = true;
                    } else if (attName.length() != 0) {
                        nodeNames.add(attName);
                        awaitingXmlnsUri = false;
                    }

                    sb = new StringBuffer();
                    continue;
                } else if (ch == '>') {
                    endOfTag = true;
                    break;
                }

                if (isName) {
                    sb.append(ch);
                }
                x += offset;
            } // end for
            if (endOfTag) {
                break;
            }
        } else if (awaitingXmlnsUri) {// ends if i % 2
            xmlnsUris.add(m.getGroup(0));
        }
        i++;
        m = quotesPattern.exec(value);
    } // end while

    HTMLAttributeNode[] nodeArray = new HTMLAttributeNode[nodeNames.size()];
    for (int y = 0; y < nodeNames.size(); y++) {
        String name = nodeNames.get(y);
        String nValue = getAltAttribute(name); // elem.getAttribute(name);
        // must be html because using outerHTML attribute - so no namespaces
        HTMLAttributeNode hNode = new HTMLAttributeNode(this, name, "", "", nValue);
        nodeArray[y] = hNode;
    }
    int count = 0;
    for (String name : xmlnsNames) {
        // use substring to exclude xmlns: prefix
        boolean noPrefix = (name.length() == 5);
        String prefix = (noPrefix) ? "" : name.substring(6);
        // xmlns declarations with prefixes can't be fetched using getAttribute
        String attValue = (noPrefix) ? getAltAttribute(name) : trimEdgeChars(xmlnsUris.get(count));
        namespaceBindings.add(new NamespaceBinding(prefix, attValue));
        count++;
    }
    attributeList = nodeArray; // for later use
    attributeNames = nodeNames;
    return nodeArray;
}