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

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

Introduction

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

Prototype

public static RegExp compile(String pattern, String flags) 

Source Link

Document

Creates a regular expression object from a pattern with no flags.

Usage

From source file:ch.takoyaki.email.html.client.HtmlPreview.java

License:Open Source License

private boolean isXmlContent(String content) {
    return RegExp.compile("^<\\?xml", "gmi").exec(content) != null;
}

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.java  2 s  .  com
        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 stripXmlComments(String content) {
    RegExp p = RegExp.compile("<!--[\\w\\W]*?-->", "gmi");
    String stripped = p.replace(content, "");
    return stripped;
}

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);/*w  ww. jav a2s  .  co  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.  j  a  v a  2 s  . c  o  m
        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);
    }/*from   w  ww  . ja v a 2s  . c om*/
    return "";
}

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

License:Open Source License

public static String removeStyleSheet(String content) {
    content = stripXmlComments(content);
    return RegExp.compile("^<\\?xml-stylesheet[^>]*\\?>", "gmi").replace(content, "");
}

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;//from  w w w .j av  a2 s . c  o  m
    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 ww w  . j a  v a  2 s.c om*/
    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;
}

From source file:com.akanoo.client.views.CanvasView.java

License:Apache License

/**
 * Replace URLs in the given string with anchors that will open in a new
 * window//from   w w  w. ja v a2s.  c o  m
 * 
 * @param html
 * @return
 */
private String replaceUrlsWithLinks(String html) {
    RegExp r = RegExp.compile("(https?://[^ ]+)", "gim");
    return r.replace(html, "<a href=\"$1\" target=\"_blank\">$1</a>");
}