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

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

Introduction

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

Prototype

public final boolean test(String input) 

Source Link

Usage

From source file:cmg.org.monitor.module.client.InviteUser.java

License:Open Source License

/**
 * Validate email./*from   www .  j  a va 2s.  c om*/
 *
 * @param email the email
 * @return the string
 */
private static String validateEmail(String email) {
    String msg = "";
    if (email == null || email == "") {
        msg = "This field is required";
    }
    String pattern = "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
    RegExp regExp = RegExp.compile(pattern);
    String[] data = email.split(",");
    for (String em : data) {
        boolean matchFound = regExp.test(em);
        if (matchFound == false) {
            msg = "Email " + em + " is not validate";
            return msg;
        }
        if (listUser3rds != null) {
            for (InvitedUser e : listUser3rds) {
                if (e.getEmail().toString().equals(em)) {
                    msg = "Email : " + em + "is existed";
                    return msg;
                }

            }
        }

    }
    return msg;
}

From source file:com.akanoo.client.presenters.SharingPopupPresenter.java

License:Apache License

@Override
public void onAddEmailClicked() {
    String email = getView().getEmail();

    RegExp regex = RegExp.compile(emailpattern);

    if (!regex.test(email)) {
        getView().alertInvalidEmail();//www .  j  a  va 2 s.c  om
        return;
    }

    List<UserInfo> users = new ArrayList<UserInfo>();
    if (collaborators != null)
        users.addAll(collaborators);
    if (friends != null)
        users.addAll(friends);

    for (UserInfo user : users) {
        if (email.equalsIgnoreCase(user.email)) {
            getView().alertDuplicateEmail();
            return;
        }
    }

    UserInfo userInfo = new UserInfo();
    userInfo.email = email;
    // set name to email address also
    userInfo.name = email;

    // add invitee to list of friends (so duplicates aren't possible)
    friends.add(userInfo);

    getView().addInvitee(userInfo);
    getView().clearEmail();
}

From source file:com.arcbees.chosen.client.ClientResultsFilter.java

License:Apache License

@Override
public void filter(String searchText, ChosenImpl chosen, boolean isShowing) {
    ChosenOptions options = chosen.getOptions();

    // TODO should be part of this object
    String regexAnchor = options.isSearchContains() ? "" : "^";
    // escape reg exp special chars
    String escapedSearchText = regExpChars.replace(searchText, "\\$&");

    RegExp regex = RegExp.compile(regexAnchor + escapedSearchText, "i");
    RegExp zregex = RegExp.compile("(" + escapedSearchText + ")", "i");

    int results = 0;

    List<SelectItem> selectItems = chosen.getSelectItems();

    for (SelectItem item : selectItems) {
        if (item.isDisabled() || item.isEmpty()) {
            continue;
        }//from w  w w .j ava  2 s  .c  om

        if (item.isGroup()) {
            $('#' + item.getDomId()).css("display", "none");
        } else {
            OptionItem option = (OptionItem) item;

            if (!(chosen.isMultiple() && option.isSelected())) {
                boolean found = false;
                String resultId = option.getDomId();
                GQuery result = $("#" + resultId);
                String optionContent = option.getHtml();
                if (optionContent == null || optionContent.trim().isEmpty()) {
                    optionContent = option.getText();
                }

                if (regex.test(optionContent)) {
                    found = true;
                    results++;
                } else if (optionContent.contains(" ") || optionContent.indexOf("[") == 0) {
                    String[] parts = optionContent.replaceAll("\\[|\\]", "").split(" ");
                    for (String part : parts) {
                        if (regex.test(part)) {
                            found = true;
                            results++;
                        }
                    }
                }

                if (found) {
                    String text;
                    if (searchText.length() > 0) {
                        text = zregex.replace(optionContent, "<em>$1</em>");
                    } else {
                        text = optionContent;
                    }

                    result.html(text);
                    chosen.resultActivate(result);

                    if (option.getGroupArrayIndex() != -1) {
                        $("#" + selectItems.get(option.getGroupArrayIndex()).getDomId()).css("display",
                                "list-item");
                    }
                } else {
                    if (chosen.getResultHighlight() != null
                            && resultId.equals(chosen.getResultHighlight().attr("id"))) {
                        chosen.resultClearHighlight();
                    }
                    chosen.resultDeactivate(result);
                }
            }
        }
    }

    if (results < 1 && !searchText.isEmpty()) {
        chosen.noResults(searchText);
    } else {
        chosen.winnowResultsSetHighlight();
    }

    if (isShowing) {
        chosen.positionDropdownResult();
    }
}

From source file:com.cgxlib.core.component.tooltip.SingleTooltip.java

License:Apache License

protected SingleTooltip doShow() {
    NativeEvent e = CGXHelper.createNativeEvent("show", "cgx." + type, null);

    if (this.hasContent() && this.enabled) {
        this.trigger(e);

        boolean inDom = viewHandler.inDom();

        if (JsUtils.isDefaultPrevented(e) || !inDom) {
            return this;
        }//w w  w.  j  av  a  2  s  .  co m

        final SingleTooltip that = this;

        XQ $tip = tip();

        String tipId = getUID(type);

        setContent();

        viewHandler.assignId($tip, tipId);

        if (this.options.animation()) {
            viewHandler.animateTip($tip);
        }

        Placement placement = this.options.placement();
        String placementStr = placement != null ? placement.name() : null;

        String autoToken = "/\\s?auto?\\s?/i";
        RegExp regExp = RegExp.compile(autoToken);
        boolean autoPlace = placementStr != null && regExp.test(placementStr);
        if (autoPlace) {
            placementStr = regExp.replace(autoToken, "");
            if (placementStr == null || placementStr.length() < 1) {
                placement = Placement.top;
            }
        }

        viewHandler.setupTip($tip, placement);
        $tip.data("cgx." + this.type, this);

        if (this.options.container() != null) {
            $tip.appendTo(this.options.container());
        } else {
            $tip.insertAfter(this);
        }
        this.trigger("inserted.cgx." + this.type);

        Position pos = viewHandler.getPosition(this);

        int actualWidth = viewHandler.tipWidth($tip);
        int actualHeight = viewHandler.tipHeight($tip);

        if (autoPlace) {

            Placement orgPlacement = placement;
            Position viewportDim = viewHandler.getPosition($viewport);

            if (placement == Placement.bottom && pos.bottom + actualHeight > viewportDim.bottom) {
                placement = Placement.top;
            } else if (placement == Placement.top && pos.top - actualHeight < viewportDim.top) {
                placement = Placement.bottom;
            } else if (placement == Placement.right && pos.right + actualWidth > viewportDim.width) {
                placement = Placement.left;
            } else if (placement == Placement.left && pos.left - actualWidth < viewportDim.left) {
                placement = Placement.right;
            }

            viewHandler.switchPlacement($tip, orgPlacement, placement);
        }

        Offset calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight);

        applyPlacement(calculatedOffset, placement);

        Function complete = new Function() {
            @Override
            public void f() {
                HoverState prevHoverState = that.hoverState;
                that.trigger("shown.cgx." + that.type);
                that.hoverState = null;

                if (prevHoverState == HoverState.OUT) {
                    that.leave(that, false);
                }
            }
        };

        final boolean useTransitions = transitions() && viewHandler.useTransitions($tip);
        if (useTransitions) {
            $tip.as(CGXlib.CGX).onceWhenTransitionEnds(complete).emulateTransitionEnd(transitionDuration());
        } else {
            complete.f();
        }
    }

    return this;
}

From source file:com.client.hp.hpl.jena.iri.impl.ComponentPatternParser.java

License:Apache License

private int classify(String string) {
    RegExp re = RegExp.compile(separators);
    MatchResult m = keyword.exec(string);
    //        Matcher m = keyword.matcher(string);

    if (!re.test(string))
        return OTHER;
    for (int i = 1; i <= m.getGroupCount(); i++)
        //            if (m.start(i) != -1)
        return i;
    throw new IllegalStateException("IRI code internal error: no group matched.");
}

From source file:com.codenvy.ide.ext.git.client.projectImporter.importerpage.GitImporterPagePresenter.java

License:Open Source License

private boolean isGitUrlCorrect(String url) {
    // An alternative scp-like syntax: [user@]host.xz:path/to/repo.git/
    RegExp scpLikeSyntax = RegExp.compile("([A-Za-z0-9_\\-]+\\.[A-Za-z0-9_\\-:]+)+:");

    // the transport protocol
    RegExp protocol = RegExp.compile("((http|https|git|ssh|ftp|ftps)://)");

    // the address of the remote server between // and /
    RegExp host1 = RegExp.compile("//([A-Za-z0-9_\\-]+\\.[A-Za-z0-9_\\-:]+)+/");

    // the address of the remote server between @ and : or /
    RegExp host2 = RegExp.compile("@([A-Za-z0-9_\\-]+\\.[A-Za-z0-9_\\-:]+)+[:/]");

    // the repository name
    RegExp repoName = RegExp.compile("/[A-Za-z0-9_.\\-]+$");

    // start with white space
    RegExp whiteSpace = RegExp.compile("^\\s");

    if (whiteSpace.test(url)) {
        view.showUrlError(locale.importProjectMessageStartWithWhiteSpace());
        return false;
    }//from w  ww  .j av a2 s .  c o  m

    if (scpLikeSyntax.test(url) && repoName.test(url)) {
        return true;
    } else if (scpLikeSyntax.test(url) && !repoName.test(url)) {
        view.showUrlError(locale.importProjectMessageNameRepoIncorrect());
        return false;
    }

    if (!protocol.test(url)) {
        view.showUrlError(locale.importProjectMessageProtocolIncorrect());
        return false;
    }
    if (!(host1.test(url) || host2.test(url))) {
        view.showUrlError(locale.importProjectMessageHostIncorrect());
        return false;
    }
    if (!(repoName.test(url))) {
        view.showUrlError(locale.importProjectMessageNameRepoIncorrect());
        return false;
    }
    view.hideUrlError();
    return true;
}

From source file:com.cristal.storm.prototype.client.mvp.view.MainPageView.java

License:Apache License

@Override
public void tagCollectionFilter(final String filter) {
    // TODO Algorithm to filter the MCE
    // Tokenize tags
    RegExp regExp = RegExp.compile(filter);
    for (MCE mce : mceListVisible) {
        if (regExp.test(mce.getTags())) {
        }//from w w  w. j av a  2s  .  c om
    }
    mceCollectionDraggable.setRowData(mceListVisible);
}

From source file:com.databasepreservation.visualization.client.common.Dialogs.java

public static void showPromptDialog(String title, String message, String placeHolder, final RegExp validator,
        String cancelButtonText, String confirmButtonText, final AsyncCallback<String> callback) {
    final DialogBox dialogBox = new DialogBox(false, true);
    dialogBox.setText(title);/*  www  . j ava 2  s  .  c  o  m*/

    final FlowPanel layout = new FlowPanel();

    if (message != null) {
        final Label messageLabel = new Label(message);
        layout.add(messageLabel);
        messageLabel.addStyleName("wui-dialog-message");
    }

    final TextBox inputBox = new TextBox();

    if (placeHolder != null) {
        inputBox.getElement().setPropertyString("placeholder", placeHolder);
    }

    final Button cancelButton = new Button(cancelButtonText);
    final Button confirmButton = new Button(confirmButtonText);

    layout.add(inputBox);
    layout.add(cancelButton);
    layout.add(confirmButton);

    dialogBox.setWidget(layout);

    dialogBox.setGlassEnabled(true);
    dialogBox.setAnimationEnabled(false);

    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            dialogBox.hide();
            callback.onFailure(null);
        }
    });

    confirmButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            dialogBox.hide();
            callback.onSuccess(inputBox.getText());
        }
    });

    inputBox.addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            boolean isValid = validator.test(inputBox.getText());
            if (isValid) {
                inputBox.addStyleName("error");
            } else {
                inputBox.removeStyleName("error");
            }
        }
    });

    inputBox.addKeyPressHandler(new KeyPressHandler() {

        @Override
        public void onKeyPress(KeyPressEvent event) {
            boolean isValid = validator.test(inputBox.getText());
            confirmButton.setEnabled(isValid);
        }
    });

    inputBox.addKeyDownHandler(new KeyDownHandler() {

        @Override
        public void onKeyDown(KeyDownEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                boolean isValid = validator.test(inputBox.getText());
                if (isValid) {
                    dialogBox.hide();
                    callback.onSuccess(inputBox.getText());
                }
            }
        }

    });

    confirmButton.setEnabled(validator.test(inputBox.getText()));

    dialogBox.addStyleName("wui-dialog-prompt");
    layout.addStyleName("wui-dialog-layout");
    inputBox.addStyleName("form-textbox wui-dialog-message");
    cancelButton.addStyleName("btn btn-link");
    confirmButton.addStyleName("pull-right btn btn-play");

    dialogBox.center();
    dialogBox.show();
    inputBox.setFocus(true);
}

From source file:com.em.validation.client.regex.RegexProvider.java

License:Apache License

public boolean matches(String regex, String check, Flag[] flags) {
    RegExp exp = null;
    if (flags != null && flags.length > 0) {
        String flagString = "";
        for (Flag f : flags) {
            if (Flag.CASE_INSENSITIVE.equals(f)) {
                flagString += "i";
            } else if (Flag.MULTILINE.equals(f)) {
                flagString += "m";
            }/* w w  w.  j  av  a2 s .c  o  m*/
        }
        exp = RegExp.compile(regex);
    } else {
        exp = RegExp.compile(regex);
    }

    return exp.test(check);
}

From source file:com.google.collide.client.search.TreeWalkFileNameSearchImpl.java

License:Open Source License

/**
 * Recurse a file tree node to find any matching children
 *
 * @param searchPath A relative path to restrict the search to
 * @param node parent tree node/*from   ww  w. ja v a  2s . co  m*/
 * @param query search query
 * @param maxResults max results
 * @param results the current results set
 */
protected void recurseTree(PathUtil searchPath, FileTreeNode node, RegExp query, int maxResults,
        JsonArray<PathUtil> results) {

    boolean isChildOfSearchPath = searchPath.containsPath(node.getNodePath());

    JsonArray<FileTreeNode> children = node.getUnifiedChildren();
    for (int i = 0; i < children.size()
            && (results.size() < maxResults || maxResults == RETURN_ALL_RESULTS); i++) {
        if (children.get(i).isDirectory()) {
            recurseTree(searchPath, children.get(i), query, maxResults, results);
            // early-out, if finished recursing the search directory
            if (searchPath.equals(children.get(i).getNodePath())) {
                return;
            }
        } else if (isChildOfSearchPath && query.test(children.get(i).getName())) {
            results.add(children.get(i).getNodePath());
        }
    }
}