use of com.google.gwt.regexp.shared.RegExp in project webprotege by protegeproject.
the class PlacePropertyValueList method parse.
public static PlacePropertyValueList parse(String token) {
final String globalFlag = "g";
RegExp regExp = RegExp.compile("([^" + PROPERTY_VALUE_SEPARATOR + "]+)" + PROPERTY_VALUE_SEPARATOR + "([^" + PROPERTY_VALUE_ITEM_SEPARATOR + "]+)" + PROPERTY_VALUE_ITEM_SEPARATOR, globalFlag);
MatchResult matchResult = regExp.exec(token);
Builder resultBuilder = builder();
while (matchResult != null) {
String name = URL.decodeQueryString(matchResult.getGroup(1));
String value = URL.decodeQueryString(matchResult.getGroup(2));
resultBuilder.set(name, value);
final int matchLength = matchResult.getGroup(0).length();
final int matchStart = matchResult.getIndex();
final int nextIndex = matchStart + matchLength;
regExp.setLastIndex(nextIndex);
matchResult = regExp.exec(token);
}
return resultBuilder.build();
}
use of com.google.gwt.regexp.shared.RegExp in project webprotege by protegeproject.
the class DataFactory method parseDateTimeFormat.
/**
* Parses the specified lexical value into a datetime literal. The parser will parse dateTime according to the
* xsd:dateTime pattern. If the time information is not present, the end of the day will automatically be assumed.
* @param lexicalValue The lexical value to be parsed. Not {@code null}.
* @return The literal representing the specified datetime.
* @throws IllegalArgumentException if the lexical value cannot be parsed into a date-time format.
*/
public static OWLLiteral parseDateTimeFormat(final String lexicalValue) throws IllegalArgumentException {
final String yearFrag = "-?(?:[1-9][0-9]{3,}|0[0-9]{3})";
final String monthFrag = "-(?:0[1-9]|1[0-2])";
final String dayFrag = "-(?:0[1-9]|[12][0-9]|3[01])";
// Group 1
final String yearMonthDayFrag = "(" + yearFrag + monthFrag + dayFrag + ")";
// Slight modification to make input easier
// Group 2
final String timeFrag = "((?:T| )(?:(?:[01][0-9]|2[0-3]):(?:[0-5][0-9]):(?:[0-5][0-9])(?:\\.[0-9]+)?|(?:24:00:00(?:\\.0+)?)))?";
// Group 3
final String timeZoneFrag = "(Z|(?:\\+|-)(?:(?:0[0-9]|1[0-3]):[0-5][0-9]|14:00))?";
String pattern = "^" + yearMonthDayFrag + timeFrag + timeZoneFrag + "$";
RegExp regExp = RegExp.compile(pattern);
MatchResult matchResult = regExp.exec(lexicalValue);
if (matchResult == null) {
throw new IllegalArgumentException();
}
String matchedYearMonthDay = matchResult.getGroup(1);
String matchedTime = matchResult.getGroup(2);
String matchedTimeZone = matchResult.getGroup(3);
String properLexicalValue = matchedYearMonthDay;
if (matchedTime != null) {
if (!matchedTime.startsWith("T")) {
properLexicalValue += "T" + matchedTime.trim();
} else {
properLexicalValue += matchedTime;
}
} else {
properLexicalValue += "T00:00:00";
}
if (matchedTimeZone != null) {
properLexicalValue += matchedTimeZone;
}
return dataFactory.getOWLLiteral(properLexicalValue, OWL2Datatype.XSD_DATE_TIME);
}
use of com.google.gwt.regexp.shared.RegExp 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;
}
use of com.google.gwt.regexp.shared.RegExp in project perun by CESNET.
the class SelfPasswordTabItem method draw.
public Widget draw() {
String actionText = "Change";
if (action.equals(Actions.CREATE)) {
actionText = "Create";
} else if (action.equals(Actions.DELETE)) {
actionText = "Delete";
}
// set tab name
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(user.getFullNameWithTitles().trim()) + ": " + actionText + " password");
// main panel
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
TabMenu menu = new TabMenu();
// widgets
final Label namespaceLabel = new Label();
namespaceLabel.setText(namespace);
final Label loginLabel = new Label();
loginLabel.setText(login);
final ExtendedPasswordBox newPass = new ExtendedPasswordBox();
final ExtendedPasswordBox confPass = new ExtendedPasswordBox();
final ExtendedPasswordBox oldPass = new ExtendedPasswordBox();
final CustomButton changeButton = new CustomButton("Change password", "Changes your password in selected namespace", SmallIcons.INSTANCE.keyIcon());
final CustomButton createButton = new CustomButton("Create password", "Creates your password in selected namespace", SmallIcons.INSTANCE.keyAddIcon());
final CustomButton deleteButton = new CustomButton("Delete password", "Deletes your password in selected namespace", SmallIcons.INSTANCE.keyDeleteIcon());
final TabItem tab = this;
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (newPass.getTextBox().getValue().trim().equals("")) {
newPass.setError("Password can't be empty!");
return false;
}
// einfra check
if ("einfra".equals(namespace)) {
RegExp regExp2 = RegExp.compile("^[\\x20-\\x7E]{1,}$");
if (regExp2.exec(newPass.getTextBox().getValue()) == null) {
newPass.setError("Password <b>can`t contain accented characters (diacritics)</b> or non-printing and control characters!");
return false;
}
// check on login in password if login is longer than 2 chars
if (login.length() > 2) {
String pass = newPass.getTextBox().getValue();
if (Utils.normalizeString(pass).contains(Utils.normalizeString(login)) || Utils.normalizeString(pass).contains(Utils.normalizeString(Utils.reverseString((login))))) {
newPass.setError("Password <b>can't contain login, name or surname</b>, not even backwards!");
return false;
}
}
// Check that password contains at least 3 of 4 character groups
RegExp regExpDigit = RegExp.compile("^.*[0-9].*$");
RegExp regExpLower = RegExp.compile("^.*[a-z].*$");
RegExp regExpUpper = RegExp.compile("^.*[A-Z].*$");
RegExp regExpSpec = RegExp.compile("^.*[\\x20-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E].*$");
int matchCounter = 0;
if (regExpDigit.exec(newPass.getTextBox().getValue()) != null)
matchCounter++;
if (regExpLower.exec(newPass.getTextBox().getValue()) != null)
matchCounter++;
if (regExpUpper.exec(newPass.getTextBox().getValue()) != null)
matchCounter++;
if (regExpSpec.exec(newPass.getTextBox().getValue()) != null)
matchCounter++;
if (matchCounter < 3) {
newPass.setError("Password must consist of <b>at least 3 of 4</b> character groups<ul><li>lower-case letters</li><li>upper-case letters</li><li>digits</li><li>special characters</li></ul>");
return false;
}
// check length
if (newPass.getTextBox().getValue().length() < 10) {
newPass.setError("Password must be <b>at least 10 characters</b> long!");
return false;
}
}
if (!newPass.getTextBox().getValue().equals(confPass.getTextBox().getValue())) {
newPass.setOk();
confPass.setError("Password in both textboxes must be the same!");
return false;
}
newPass.setOk();
return true;
}
};
final ExtendedTextBox.TextBoxValidator validator2 = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (!confPass.getTextBox().getValue().equals(newPass.getTextBox().getValue())) {
confPass.setError("Password in both textboxes must be the same!");
return false;
} else {
confPass.setOk();
return true;
}
}
};
final ExtendedTextBox.TextBoxValidator oldValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (oldPass.getTextBox().getValue().trim().equals("")) {
oldPass.setError("Password can't be empty!");
return false;
} else {
oldPass.setOk();
return true;
}
}
};
newPass.setValidator(validator);
confPass.setValidator(validator2);
oldPass.setValidator(oldValidator);
// save changes
changeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if ("mu".equals(namespace) && !JsonUtils.checkParseInt(login)) {
UiElements.generateAlert("Operation not supported", "Password change/reset is not supported for non-numeric logins (UČO).");
}
if (session.isPerunAdmin() || user.isServiceUser()) {
if (!validator.validateTextBox() && !validator2.validateTextBox())
return;
ChangePassword changepw = new ChangePassword(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab, true), false);
changepw.changePassword(user, namespace, oldPass.getTextBox().getValue(), newPass.getTextBox().getValue());
} else {
if (!validator.validateTextBox() && !validator2.validateTextBox() && !oldValidator.validateTextBox())
return;
ChangePassword changepw = new ChangePassword(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab, true), true);
changepw.changePassword(user, namespace, oldPass.getTextBox().getValue(), newPass.getTextBox().getValue());
}
}
});
if (user.isServiceUser()) {
// for service users it's reset since they don't provide old password
changeButton.setText("Reset password…");
}
createButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
if (validator.validateTextBox() && validator2.validateTextBox()) {
if ("mu".equals(namespace)) {
final GenerateAccount generateAccount = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
BasicOverlayType basic = jso.cast();
final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
// VALIDATE PASSWORD - SET EXT SOURCES
CreatePassword req = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab, true));
req.validatePassword(user.getId(), login, namespace);
}
}));
setLogin.setLogin(user.getId(), "mu", login);
}
}));
final Map<String, String> params = new HashMap<String, String>();
GetEntityById get = new GetEntityById(PerunEntity.RICH_USER_WITH_ATTRS, user.getId(), JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
User usr = jso.cast();
params.put("urn:perun:user:attribute-def:core:firstName", usr.getFirstName());
params.put("urn:perun:user:attribute-def:core:lastName", usr.getLastName());
params.put("urn:perun:member:attribute-def:def:mail", usr.getAttribute("urn:perun:user:attribute-def:def:preferredMail").getValue());
generateAccount.generateAccount(namespace, newPass.getTextBox().getValue(), params);
}
}));
get.retrieveData();
} else {
// NORMAL PWD LOGIC
CreatePassword create = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab, true));
create.createPassword(userId, login, namespace, newPass.getTextBox().getValue());
}
}
}
});
deleteButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
UiElements.generateAlert("Not yet implemented", "Not yet implemented");
}
});
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
// change layout
if (action.equals(Actions.CHANGE)) {
int row = 0;
layout.setHTML(row, 0, "Namespace:");
layout.setWidget(row, 1, namespaceLabel);
row++;
layout.setHTML(row, 0, "Login:");
layout.setWidget(row, 1, loginLabel);
row++;
// mu namespace can change without knowing old
if (!session.isPerunAdmin()) {
if (!user.isServiceUser()) {
layout.setHTML(row, 0, "Old password: ");
layout.setWidget(row, 1, oldPass);
row++;
}
}
layout.setHTML(row, 0, "New password:");
layout.setWidget(row, 1, newPass);
row++;
layout.setHTML(row, 0, "Retype new pass:");
layout.setWidget(row, 1, confPass);
menu.addWidget(changeButton);
vp.add(layout);
} else if (action.equals(Actions.CREATE)) {
layout.setHTML(0, 0, "Namespace:");
layout.setWidget(0, 1, namespaceLabel);
if ("mu".equals(namespace)) {
loginLabel.setText("Will be generated...");
loginLabel.addStyleName("inputFormInlineComment");
}
layout.setHTML(1, 0, "Login:");
layout.setWidget(1, 1, loginLabel);
layout.setHTML(2, 0, "New password:");
layout.setWidget(2, 1, newPass);
layout.setHTML(3, 0, "Retype new pass:");
layout.setWidget(3, 1, confPass);
final CustomButton skip = new CustomButton("Skip", "Will set random/empty password", SmallIcons.INSTANCE.arrowRightIcon());
skip.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if ("mu".equals(namespace)) {
final GenerateAccount generateAccount = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
BasicOverlayType basic = jso.cast();
final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
// VALIDATE PASSWORD - SET EXT SOURCES
CreatePassword req = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab, true));
req.validatePassword(user.getId(), login, namespace);
}
}));
setLogin.setLogin(user.getId(), "mu", login);
}
}));
final Map<String, String> params = new HashMap<String, String>();
GetEntityById get = new GetEntityById(PerunEntity.RICH_USER_WITH_ATTRS, user.getId(), JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
User usr = jso.cast();
params.put("urn:perun:user:attribute-def:core:firstName", usr.getFirstName());
params.put("urn:perun:user:attribute-def:core:lastName", usr.getLastName());
params.put("urn:perun:member:attribute-def:def:mail", usr.getAttribute("urn:perun:user:attribute-def:def:preferredMail").getValue());
generateAccount.generateAccount(namespace, newPass.getTextBox().getValue(), params);
}
}));
get.retrieveData();
} else {
CreatePassword create = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(skip, tab, true));
create.createRandomPassword(userId, login, namespace);
}
}
});
menu.addWidget(skip);
menu.addWidget(createButton);
vp.add(layout);
} else if (action.equals(Actions.DELETE)) {
layout.setHTML(0, 0, "Namespace:");
layout.setWidget(0, 1, namespaceLabel);
layout.setHTML(1, 0, "Login:");
layout.setWidget(1, 1, loginLabel);
menu.addWidget(deleteButton);
vp.add(layout);
}
for (int i = 0; i < layout.getRowCount(); i++) {
layout.getFlexCellFormatter().setStyleName(i, 0, "itemName");
}
int row = layout.getRowCount();
if ("einfra".equals(namespace)) {
layout.setHTML(row, 0, "Password must <ul><li>contain only printing (non-accented) characters<li>be at least 10 characters long<li>consist of at least 3 of 4 character groups<ul><li>lower-case letters<li>upper-case letters<li>digits<li>special characters</ul></ul>");
} else {
layout.setHTML(row, 0, "Please <b>avoid using accented characters</b>. It might not be supported by all backend components and services.");
}
layout.getFlexCellFormatter().setColSpan(row, 0, 2);
layout.getCellFormatter().setStyleName(row, 0, "inputFormInlineComment");
layout.setWidth("400px");
if (!action.equals(Actions.CREATE)) {
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
}
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations