use of org.olat.core.gui.components.form.flexible.elements.TextElement in project openolat by klemens.
the class XingPropertyHandler method addFormItem.
/**
* @see org.olat.user.propertyhandlers.Generic127CharTextPropertyHandler#addFormItem(java.util.Locale,
* org.olat.core.id.User, java.lang.String, boolean,
* org.olat.core.gui.components.form.flexible.FormItemContainer)
*/
@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
TextElement textElement = (TextElement) super.addFormItem(locale, user, usageIdentifyer, isAdministrativeUser, formItemContainer);
textElement.setMaxLength(XING_NAME_MAX_LENGTH);
if (!UserManager.getInstance().isUserViewReadOnly(usageIdentifyer, this) || isAdministrativeUser) {
textElement.setExampleKey("form.example.xingname", null);
}
return textElement;
}
use of org.olat.core.gui.components.form.flexible.elements.TextElement in project openolat by klemens.
the class MSNPropertyHandler method isValid.
/**
* @see org.olat.user.propertyhandlers.Generic127CharTextPropertyHandler#isValid(org.olat.core.gui.components.form.flexible.FormItem, java.util.Map)
*/
@Override
public boolean isValid(User user, FormItem formItem, Map<String, String> formContext) {
boolean result;
TextElement textElement = (TextElement) formItem;
if (StringHelper.containsNonWhitespace(textElement.getValue())) {
// Use an HttpClient to fetch a profile information page from MSN.
CloseableHttpClient httpClient = HttpClientFactory.getHttpClientInstance(false);
try {
URIBuilder uriBuilder = new URIBuilder(MSN_NAME_VALIDATION_URL);
uriBuilder.addParameter(MSN_NAME_URL_PARAMETER, textElement.getValue());
HttpGet httpMethod = new HttpGet(uriBuilder.build());
// Get the user profile page
HttpResponse response = httpClient.execute(httpMethod);
int httpStatusCode = response.getStatusLine().getStatusCode();
// Looking at the HTTP status code tells us whether a user with the given MSN name exists.
if (httpStatusCode == HttpStatus.SC_MOVED_PERMANENTLY) {
// If the user exists, we get a 301...
result = true;
} else if (httpStatusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
// ...and if the user doesn't exist, MSN sends a 500.
textElement.setErrorKey("form.name.msn.error", null);
result = false;
} else {
// For HTTP status codes other than 301 and 500 we will assume that the given MSN name is valid, but inform the user about this.
textElement.setExampleKey("form.example.msnname.notvalidated", null);
log.warn("MSN name validation: Expected HTTP status 301 or 500, but got " + httpStatusCode);
result = true;
}
} catch (Exception e) {
// In case of any exception, assume that the given MSN name is valid (The opposite would block easily upon network problems), and inform the user about this.
textElement.setExampleKey("form.example.msnname.notvalidated", null);
log.warn("MSN name validation: Exception: " + e.getMessage());
result = true;
} finally {
IOUtils.closeQuietly(httpClient);
}
} else {
result = true;
}
return result;
}
use of org.olat.core.gui.components.form.flexible.elements.TextElement in project openolat by klemens.
the class EPShareListController method secureListBox.
/**
* loops over all EPSharePolicyWrappers and updates the datamodel according to the
* current form-values
*/
protected void secureListBox() {
if (isLogDebugEnabled())
logDebug(" 'securing' ListBox --> updating policyWrappers with field values...", null);
for (EPSharePolicyWrapper policyWrapper : policyWrappers) {
if (policyWrapper.getUserListBox() != null) {
List<Identity> identities = policyWrapper.getIdentities();
policyWrapper.setIdentities(identities);
}
if (policyWrapper.getGroups() != null) {
List<BusinessGroup> selectedGroups = policyWrapper.getGroups();
policyWrapper.setGroups(selectedGroups);
}
TextElement firstNameEl = policyWrapper.getFirstNameEl();
if (firstNameEl != null) {
policyWrapper.getInvitation().setFirstName(firstNameEl.getValue());
}
TextElement lastNameEl = policyWrapper.getLastNameEl();
if (lastNameEl != null) {
policyWrapper.getInvitation().setLastName(lastNameEl.getValue());
}
TextElement mailEl = policyWrapper.getMailEl();
if (mailEl != null) {
policyWrapper.getInvitation().setMail(mailEl.getValue());
}
if (policyWrapper.getFromChooser() != null) {
policyWrapper.setFrom(policyWrapper.getFromChooser().getDate());
}
if (policyWrapper.getToChooser() != null) {
policyWrapper.setTo(policyWrapper.getToChooser().getDate());
}
}
}
use of org.olat.core.gui.components.form.flexible.elements.TextElement in project openolat by klemens.
the class EPShareListController method createContainerForInvitation.
private void createContainerForInvitation(Invitation invitation, EPSharePolicyWrapper policyWrapper, String cmpName, FormLayoutContainer container) {
FormLayoutContainer invitationContainer = FormLayoutContainer.createDefaultFormLayout("map.share.with." + cmpName, getTranslator());
invitationContainer.contextPut("wrapper", policyWrapper);
invitationContainer.setRootForm(mainForm);
container.add("map.share.with." + cmpName, invitationContainer);
TextElement firstNameEl = uifactory.addTextElement("map.share.with.firstName." + cmpName, "map.share.with.firstName", 64, invitation.getFirstName(), invitationContainer);
firstNameEl.setMandatory(true);
firstNameEl.setNotEmptyCheck("map.share.empty.warn");
TextElement lastNameEl = uifactory.addTextElement("map.share.with.lastName." + cmpName, "map.share.with.lastName", 64, invitation.getLastName(), invitationContainer);
lastNameEl.setMandatory(true);
lastNameEl.setNotEmptyCheck("map.share.empty.warn");
TextElement mailEl = uifactory.addTextElement("map.share.with.mail." + cmpName, "map.share.with.mail", 128, invitation.getMail(), invitationContainer);
mailEl.setMandatory(true);
mailEl.setNotEmptyCheck("map.share.empty.warn");
if (StringHelper.containsNonWhitespace(invitation.getMail()) && MailHelper.isValidEmailAddress(invitation.getMail())) {
SecurityGroup allUsers = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
List<Identity> shareWithIdentities = userManager.findIdentitiesByEmail(Collections.singletonList(invitation.getMail()));
if (isAtLeastOneInSecurityGroup(shareWithIdentities, allUsers)) {
mailEl.setErrorKey("map.share.with.mail.error.olatUser", new String[] { invitation.getMail() });
}
}
policyWrapper.setFirstNameEl(firstNameEl);
policyWrapper.setLastNameEl(lastNameEl);
policyWrapper.setMailEl(mailEl);
String link = getInvitationLink(invitation, map);
StaticTextElement linkEl = uifactory.addStaticTextElement("map.share.with.link." + cmpName, link, invitationContainer);
linkEl.setLabel("map.share.with.link", null);
}
use of org.olat.core.gui.components.form.flexible.elements.TextElement in project openolat by klemens.
the class ShibbolethRegistrationUserPropertiesFrom method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
// Add all available user fields to this form
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler != null) {
FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, USERPROPERTIES_FORM_IDENTIFIER, false, formLayout);
propFormItems.put(userPropertyHandler.getName(), fi);
if (fi instanceof TextElement) {
String value = shibbolethAttributes.getValueForUserPropertyName(userPropertyHandler.getName());
if (StringHelper.containsNonWhitespace(value)) {
TextElement formElement = (TextElement) fi;
formElement.setValue(value);
formElement.setEnabled(false);
}
}
}
}
FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
formLayout.add(buttonLayout);
uifactory.addFormSubmitButton("save", buttonLayout);
}
Aggregations