use of com.google.gwt.regexp.shared.RegExp in project perun by CESNET.
the class JsonUtils method isStringWithIds.
/**
* Whether string contains IDs separated by a comma
*
* @param text
* @return
*/
public static boolean isStringWithIds(String text) {
final String IDS_PATTERN = "^[0-9, ]+$";
RegExp regExp = RegExp.compile(IDS_PATTERN);
MatchResult matcher = regExp.exec(text);
return (matcher != null);
}
use of com.google.gwt.regexp.shared.RegExp in project perun by CESNET.
the class TestJSONParserTabItem method draw.
public Widget draw() {
Button sendMessageButton = new Button("Parse response");
final FlexTable ft = new FlexTable();
ft.setCellSpacing(15);
int row = 0;
ft.setText(row, 0, "Server response:");
ft.setWidget(row, 1, returnedValue);
row++;
ft.setText(row, 0, "Callback name:");
ft.setHTML(row, 1, "callbackPost");
row++;
ft.setWidget(row, 0, sendMessageButton);
row++;
sendMessageButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
String resp = returnedValue.getText();
// trims the whitespace
resp = resp.trim();
// short comparing
if (("callbackPost(null);").equalsIgnoreCase(resp)) {
UiElements.generateInfo("Parser result", "Parsed value is: NULL");
}
// if starts with callbackName( and ends with ) or ); - wrapped, must be unwrapped
RegExp re = RegExp.compile("^" + "callbackPost" + "\\((.*)\\)|\\);$");
MatchResult result = re.exec(resp);
if (result != null) {
resp = result.getGroup(1);
}
UiElements.generateInfo("Unwrapped value", "Non-null unwrapped value is: " + resp);
// if response = null - return null
if (resp.equals("null")) {
UiElements.generateInfo("Parser result", "Parsed value is: NULL");
}
// normal object
JavaScriptObject jso = JsonUtils.parseJson(resp);
BasicOverlayType basic = jso.cast();
UiElements.generateInfo("Parser result", "Parsed result is: " + basic.getString());
}
});
this.contentWidget.setWidget(ft);
return getWidget();
}
use of com.google.gwt.regexp.shared.RegExp in project perun by CESNET.
the class AddLoginTabItem method draw.
public Widget draw() {
titleWidget.setText("Add login");
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
final ExtendedTextBox userLogin = new ExtendedTextBox();
final ListBox namespace = new ListBox();
final CustomButton createLogin = TabMenu.getPredefinedButton(ButtonType.ADD, "Add login in selected namespace");
final Label notice = new Label("Your login will be automatically generated.");
notice.setVisible(false);
// offer only available namespaces.
ArrayList<String> logins = new ArrayList<String>();
for (Attribute a : usersLogins) {
logins.add(a.getFriendlyNameParameter());
}
for (String s : Utils.getSupportedPasswordNamespaces()) {
if (!logins.contains(s)) {
namespace.addItem(s.toUpperCase(), s);
}
}
final ExtendedTextBox.TextBoxValidator loginValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (userLogin.getTextBox().getValue().trim().isEmpty()) {
userLogin.setError("Login can't be empty!");
return false;
}
RegExp regExp = RegExp.compile(Utils.LOGIN_VALUE_MATCHER);
boolean match = regExp.test(userLogin.getTextBox().getValue().trim());
if (!match) {
userLogin.setError("Invalid format!");
return false;
}
if (userLogin.isProcessing() || userLogin.isHardError()) {
return false;
}
userLogin.setOk();
return true;
}
};
userLogin.setValidator(loginValidator);
final FlexTable layout = new FlexTable();
layout.addStyleName("inputFormFlexTable");
layout.setHTML(0, 0, "Namespace:");
layout.setHTML(1, 0, "Login:");
for (int i = 0; i < layout.getRowCount(); i++) {
layout.getFlexCellFormatter().addStyleName(i, 0, "itemName");
}
layout.setWidget(0, 1, namespace);
layout.setWidget(1, 1, userLogin);
layout.getFlexCellFormatter().setColSpan(2, 0, 2);
layout.setWidget(2, 0, notice);
layout.getFlexCellFormatter().addStyleName(2, 0, "inputFormInlineComment");
HTML help = new HTML("Login must<ul><li>start with lower-cased letter<li>be 2-15 characters long<li>consist only of<ul><li>lower-cased non-accented letters<li>digits<li>hyphens and underscores</ul></ul>");
help.setVisible(false);
layout.getFlexCellFormatter().setColSpan(3, 0, 2);
layout.setWidget(3, 0, help);
layout.getFlexCellFormatter().addStyleName(3, 0, "inputFormInlineComment");
TabMenu menu = new TabMenu();
menu.addWidget(createLogin);
final TabItem tab = this;
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
// user can't add new login
if (namespace.getItemCount() == 0) {
vp.add(new HTML("<p><strong>You already have login in all supported namespaces!</strong></p>"));
createLogin.setEnabled(false);
} else {
// user can add new login
vp.add(layout);
// check login availability
userLogin.getTextBox().addKeyUpHandler(new KeyUpHandler() {
@Override
public void onKeyUp(KeyUpEvent keyUpEvent) {
if (keyUpEvent.isDownArrow() || keyUpEvent.isUpArrow() || keyUpEvent.isLeftArrow() || keyUpEvent.isRightArrow()) {
// do not trigger when no text input
return;
}
final String value = userLogin.getTextBox().getValue().trim();
// trigger new validation on checked input or if previously was hard error
if ((!value.isEmpty() && RegExp.compile(Utils.LOGIN_VALUE_MATCHER).test(value)) || userLogin.isHardError()) {
new IsLoginAvailable(namespace.getValue(namespace.getSelectedIndex()), userLogin.getTextBox().getValue().trim(), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
if (value.equals(userLogin.getTextBox().getValue().trim())) {
BasicOverlayType bo = jso.cast();
userLogin.setProcessing(false);
if (!bo.getBoolean()) {
userLogin.setHardError("Login is already in use!");
} else {
userLogin.removeHardError();
loginValidator.validateTextBox();
}
}
}
@Override
public void onLoadingStart() {
if (value.equals(userLogin.getTextBox().getValue().trim())) {
userLogin.removeHardError();
userLogin.setProcessing(true);
}
}
@Override
public void onError(PerunError error) {
if (value.equals(userLogin.getTextBox().getValue().trim())) {
if ("InvalidLoginException".equalsIgnoreCase(error.getName())) {
userLogin.setProcessing(false);
String text = error.getErrorInfo();
text = text.split(":", 2)[1];
text = (text == null || text.isEmpty()) ? error.getErrorInfo() : text;
userLogin.setHardError(text);
} else {
// generic error
userLogin.setProcessing(false);
userLogin.setHardError("Unable to check if login is available!");
}
}
}
}).retrieveData();
}
}
});
namespace.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent changeEvent) {
if (namespace.getSelectedValue().equals("einfra")) {
help.setVisible(true);
} else {
help.setVisible(false);
}
if (namespace.getSelectedValue().equals("mu")) {
userLogin.getTextBox().setValue("");
userLogin.removeHardError();
userLogin.setOk();
userLogin.getTextBox().setEnabled(false);
notice.setVisible(true);
} else {
userLogin.getTextBox().setEnabled(true);
notice.setVisible(false);
final String value = userLogin.getTextBox().getValue().trim();
// trigger new validation on checked input or if previously was hard error
if ((!value.isEmpty() && RegExp.compile(Utils.LOGIN_VALUE_MATCHER).test(value)) || userLogin.isHardError()) {
new IsLoginAvailable(namespace.getValue(namespace.getSelectedIndex()), userLogin.getTextBox().getValue().trim(), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
if (value.equals(userLogin.getTextBox().getValue().trim())) {
BasicOverlayType bo = jso.cast();
userLogin.setProcessing(false);
if (!bo.getBoolean()) {
userLogin.setError("Login is already in use!");
} else {
userLogin.removeHardError();
loginValidator.validateTextBox();
}
}
}
@Override
public void onLoadingStart() {
if (value.equals(userLogin.getTextBox().getValue().trim())) {
userLogin.removeHardError();
userLogin.setProcessing(true);
}
}
@Override
public void onError(PerunError error) {
if (value.equals(userLogin.getTextBox().getValue().trim())) {
userLogin.setProcessing(false);
userLogin.setHardError("Error while loading.");
}
}
}).retrieveData();
}
}
}
});
createLogin.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (namespace.getSelectedValue().equals("mu")) {
session.getTabManager().addTabToCurrentTab(new SelfPasswordTabItem(user, namespace.getValue(namespace.getSelectedIndex()), userLogin.getTextBox().getValue().trim(), SelfPasswordTabItem.Actions.CREATE));
} else {
if (!loginValidator.validateTextBox())
return;
SetLogin request = new SetLogin(JsonCallbackEvents.disableButtonEvents(createLogin, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
session.getTabManager().addTabToCurrentTab(new SelfPasswordTabItem(user, namespace.getValue(namespace.getSelectedIndex()), userLogin.getTextBox().getValue().trim(), SelfPasswordTabItem.Actions.CREATE));
}
}));
request.setLogin(user, namespace.getValue(namespace.getSelectedIndex()), userLogin.getTextBox().getValue().trim());
}
}
});
}
if (namespace.getSelectedValue().equals("mu")) {
userLogin.getTextBox().setValue("");
userLogin.removeHardError();
userLogin.setOk();
userLogin.getTextBox().setEnabled(false);
notice.setVisible(true);
} else if (namespace.getSelectedValue().equals("einfra")) {
help.setVisible(true);
}
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of com.google.gwt.regexp.shared.RegExp in project che by eclipse.
the class FuzzyMatches method fuzzyMatch.
public List<Match> fuzzyMatch(String word, String wordToMatch, boolean substringMatch) {
RegExp regExp = regExpCache.get(word);
if (regExp == null) {
regExp = convertWordToRegExp(word);
regExpCache.put(word, regExp);
}
MatchResult matchResult = regExp.exec(wordToMatch);
if (matchResult != null) {
return Collections.singletonList(new Match(matchResult.getIndex(), matchResult.getIndex() + matchResult.getGroup(0).length()));
}
if (substringMatch) {
return FUZZY_SEPARATE.match(word, wordToMatch);
} else {
return FUZZY_CONTIGUOUS.match(word, wordToMatch);
}
}
use of com.google.gwt.regexp.shared.RegExp in project che by eclipse.
the class OutputConsoleViewImpl method print.
@Override
public void print(final String text, boolean carriageReturn, String color) {
if (this.carriageReturn) {
Node lastChild = consoleLines.getElement().getLastChild();
if (lastChild != null) {
lastChild.removeFromParent();
}
}
this.carriageReturn = carriageReturn;
final SafeHtml colorOutput = new SafeHtml() {
@Override
public String asString() {
if (Strings.isNullOrEmpty(text)) {
return " ";
}
for (final Pair<RegExp, String> pair : output2Color) {
final MatchResult matcher = pair.first.exec(text);
if (matcher != null) {
return text.replaceAll(matcher.getGroup(1), "<span style=\"color: " + pair.second + "\">" + matcher.getGroup(1) + "</span>");
}
}
return text;
}
};
PreElement pre = DOM.createElement("pre").cast();
pre.setInnerSafeHtml(colorOutput);
if (color != null) {
pre.getStyle().setColor(color);
}
consoleLines.getElement().appendChild(pre);
followOutput();
}
Aggregations