Search in sources :

Example 11 with MatchResult

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

the class BaseDynamicMessages method getPlaceHolderList.

/**
 * Parse the message body and return a list of integers, one for each place holder index in the body.
 * <p>
 * For instance, if the message is 'One {0} over the {1} nest {0}' then the list will be [0,1]. Duplicates are
 * turned into a single element in the resulting list.
 *
 * @param message
 *            The message body to parse.
 * @return A list of integers matching the indexes of the place holders within the message body.
 */
protected List<Integer> getPlaceHolderList(final String message) {
    MatchResult matcher;
    Set<Integer> matchedPlaceHolders = new HashSet<>();
    for (matcher = PLACE_HOLDER_PATTERN.exec(message); matcher != null; matcher = PLACE_HOLDER_PATTERN.exec(message)) {
        matchedPlaceHolders.add(Integer.valueOf(matcher.getGroup(1)));
    }
    List<Integer> result = new ArrayList<>(matchedPlaceHolders);
    Collections.sort(result);
    for (int i = 0; i < result.size(); i++) {
        if (i != result.get(i)) {
            // $NON-NLS-1$
            throw new IllegalArgumentException("Invalid place holder index found");
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) MatchResult(com.google.gwt.regexp.shared.MatchResult) HashSet(java.util.HashSet)

Example 12 with MatchResult

use of com.google.gwt.regexp.shared.MatchResult in project webprotege by protegeproject.

the class CommentAutoCompleter method handleAutocomplete.

public void handleAutocomplete(@Nonnull String query, @Nonnull EditorPosition caretPosition, int caretPos, @Nonnull AutoCompletionCallback callback) {
    String upToCarent = query.substring(0, caretPos);
    MatchResult result = nameRegExp.exec(upToCarent);
    if (result == null) {
        handleAttemptAtEntityCompletions(upToCarent, caretPosition, callback);
    } else {
        String matchedPartialName = result.getGroup(NAME_GROUP);
        EditorPosition replaceTextFrom = new EditorPosition(caretPosition.getLineNumber(), caretPosition.getColumnNumber() - result.getGroup(0).length());
        dispatchServiceManager.execute(new GetUserIdCompletionsAction(matchedPartialName), userIdsResult -> {
            List<AutoCompletionChoice> suggestions = new ArrayList<>();
            List<UserId> userIds = userIdsResult.getPossibleItemCompletions();
            for (UserId userId : userIds) {
                String userName = userId.getUserName();
                String replacement = getReplacementStringFromUserName(userName);
                EditorPosition replaceTextTo = new EditorPosition(caretPosition.getLineNumber(), caretPosition.getColumnNumber());
                suggestions.add(new AutoCompletionChoice(replacement, userName, "", replaceTextFrom, replaceTextTo));
            }
            callback.completionsReady(new AutoCompletionResult(suggestions, replaceTextFrom));
        });
    }
}
Also used : EditorPosition(edu.stanford.bmir.gwtcodemirror.client.EditorPosition) GetUserIdCompletionsAction(edu.stanford.bmir.protege.web.shared.itemlist.GetUserIdCompletionsAction) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) ArrayList(java.util.ArrayList) AutoCompletionResult(edu.stanford.bmir.gwtcodemirror.client.AutoCompletionResult) AutoCompletionChoice(edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 13 with MatchResult

use of com.google.gwt.regexp.shared.MatchResult in project webprotege by protegeproject.

the class SharingSettingsPlaceTokenizer method getPlace.

@Override
public SharingSettingsPlace getPlace(String token) {
    String trimmedToken = token.trim();
    if (!pattern.test(trimmedToken)) {
        return null;
    }
    MatchResult matchResult = pattern.exec(trimmedToken);
    String projectIdString = matchResult.getGroup(1);
    return new SharingSettingsPlace(ProjectId.get(projectIdString));
}
Also used : MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 14 with MatchResult

use of com.google.gwt.regexp.shared.MatchResult in project webprotege by protegeproject.

the class CollectionViewPlaceTokenizer method getPlace.

@Override
public CollectionViewPlace getPlace(String token) {
    MatchResult result = regExp.exec(token);
    ProjectId projectId = ProjectId.get(result.getGroup(1));
    CollectionId collectionId = CollectionId.get(result.getGroup(2));
    FormId formId = new FormId(result.getGroup(3));
    String selectionString = result.getGroup(5);
    GWT.log("[CollectionViewPlaceTokenizer] Selection string: " + selectionString);
    Optional<CollectionItem> selection = Optional.ofNullable(selectionString).map(CollectionItem::get);
    return new CollectionViewPlace(projectId, collectionId, formId, selection);
}
Also used : CollectionId(edu.stanford.bmir.protege.web.shared.collection.CollectionId) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) CollectionViewPlace(edu.stanford.bmir.protege.web.shared.place.CollectionViewPlace) FormId(edu.stanford.bmir.protege.web.shared.form.FormId) CollectionItem(edu.stanford.bmir.protege.web.shared.collection.CollectionItem) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 15 with MatchResult

use of com.google.gwt.regexp.shared.MatchResult in project webprotege by protegeproject.

the class ProjectPrefixDeclarationsPlaceTokenizer method getPlace.

@Override
public ProjectPrefixDeclarationsPlace getPlace(String s) {
    MatchResult matchResult = pattern.exec(s);
    if (matchResult == null) {
        return null;
    }
    String projectIdString = matchResult.getGroup(PROJECT_ID_GROUP);
    if (!ProjectId.isWelFormedProjectId(projectIdString)) {
        return null;
    }
    return new ProjectPrefixDeclarationsPlace(ProjectId.get(projectIdString));
}
Also used : MatchResult(com.google.gwt.regexp.shared.MatchResult)

Aggregations

MatchResult (com.google.gwt.regexp.shared.MatchResult)47 RegExp (com.google.gwt.regexp.shared.RegExp)23 ArrayList (java.util.ArrayList)7 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