Search in sources :

Example 51 with MatchResult

use of com.google.gwt.regexp.shared.MatchResult in project flow by vaadin.

the class DefaultConnectionStateHandler method xhrInvalidContent.

@Override
public void xhrInvalidContent(XhrConnectionError xhrConnectionError) {
    debug("xhrInvalidContent");
    endRequest();
    String responseText = xhrConnectionError.getXhr().getResponseText();
    /*
         * A servlet filter or equivalent may have intercepted the request and
         * served non-UIDL content (for instance, a login page if the session
         * has expired.) If the response contains a magic substring, do a
         * synchronous refresh. See #8241.
         */
    MatchResult refreshToken = RegExp.compile(UIDL_REFRESH_TOKEN + "(:\\s*(.*?))?(\\s|$)").exec(responseText);
    if (refreshToken != null) {
        WidgetUtil.redirect(refreshToken.getGroup(2));
    } else {
        handleUnrecoverableCommunicationError("Invalid JSON response from server: " + responseText, xhrConnectionError);
    }
}
Also used : MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 52 with MatchResult

use of com.google.gwt.regexp.shared.MatchResult in project ovirt-engine by oVirt.

the class FormatterJava method parse.

// Look for format specifiers in the format string.
private FormatString[] parse(String s) {
    ArrayList<FormatString> al = new ArrayList<>();
    while (s.length() > 0) {
        MatchResult m = fsPattern.exec(s);
        if (m != null) {
            int i = m.getIndex();
            if (i > 0) {
                // Anything between the start of the string and the beginning
                // of the format specifier is either fixed text or contains
                // an invalid format string.
                String staticText = s.substring(0, i);
                // Make sure we didn't miss any invalid format specifiers
                checkText(staticText);
                // Assume previous characters were fixed text
                al.add(new FixedString(staticText));
            }
            // Expect 6 groups in regular expression
            String[] sa = new String[6];
            for (int j = 1; j < m.getGroupCount(); j++) {
                sa[j - 1] = m.getGroup(j);
            // System.out.print(sa[j] + " ");
            }
            // System.out.println();
            al.add(new FormatSpecifier(this, sa));
            // trim parsed string
            s = s.substring(i + m.getGroup(0).length(), s.length());
        } else {
            // No more valid format specifiers. Check for possible invalid
            // format specifiers.
            checkText(s);
            // The rest of the string is fixed text
            al.add(new FixedString(s));
            break;
        }
    }
    // System.out.println(((FormatString) al.get(j)).toString());
    return al.toArray(new FormatString[0]);
}
Also used : ArrayList(java.util.ArrayList) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 53 with MatchResult

use of com.google.gwt.regexp.shared.MatchResult in project perun by CESNET.

the class RegistrarFormItemGenerator method checkValueRegex.

protected boolean checkValueRegex() {
    if (item.getRegex() != null && !("".equals(item.getRegex()))) {
        // Compile and use regular expression
        RegExp regExp = RegExp.compile(item.getRegex());
        MatchResult matcher = regExp.exec(strValueBox.getValue());
        // equivalent to regExp.test(inputStr);
        boolean matchFound = (matcher != null);
        if (!matchFound) {
            String errorMessage = ApplicationMessages.INSTANCE.incorrectFormat();
            // does a custom message exist?
            ItemTexts it = item.getItemTexts(locale);
            if (it != null) {
                if (it.getErrorMessage() != null && !it.getErrorMessage().equals("")) {
                    errorMessage = it.getErrorMessage();
                }
            }
            statusCellWrapper.setWidget(new FormInputStatusWidget(errorMessage, Status.ERROR));
            return false;
        }
    }
    return true;
}
Also used : ItemTexts(cz.metacentrum.perun.webgui.model.ItemTexts) RegExp(com.google.gwt.regexp.shared.RegExp) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Aggregations

MatchResult (com.google.gwt.regexp.shared.MatchResult)53 RegExp (com.google.gwt.regexp.shared.RegExp)24 ArrayList (java.util.ArrayList)9 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)3 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)3 JsArrayString (com.google.gwt.core.client.JsArrayString)1 Node (com.google.gwt.dom.client.Node)1 PreElement (com.google.gwt.dom.client.PreElement)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 BasicOverlayType (cz.metacentrum.perun.webgui.model.BasicOverlayType)1 ItemTexts (cz.metacentrum.perun.webgui.model.ItemTexts)1 AutoCompletionChoice (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice)1 AutoCompletionResult (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionResult)1 EditorPosition (edu.stanford.bmir.gwtcodemirror.client.EditorPosition)1 CollectionId (edu.stanford.bmir.protege.web.shared.collection.CollectionId)1 CollectionItem (edu.stanford.bmir.protege.web.shared.collection.CollectionItem)1 FormId (edu.stanford.bmir.protege.web.shared.form.FormId)1 GetUserIdCompletionsAction (edu.stanford.bmir.protege.web.shared.itemlist.GetUserIdCompletionsAction)1