Package org.olat.core.gui.components.form.flexible.elements

Examples of org.olat.core.gui.components.form.flexible.elements.TextElement


   *      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(MSN_NAME_MAX_LENGTH);

    if (!UserManager.getInstance().isUserViewReadOnly(usageIdentifyer, this) || isAdministrativeUser) {
      textElement.setExampleKey("form.example.msnname", null);
    }
    return textElement;
  }
View Full Code Here


   */
  @SuppressWarnings({"unchecked"})
  @Override
  public boolean isValid(FormItem formItem, Map formContext) {
    boolean result;
    TextElement textElement = (TextElement)formItem;
    OLog log = Tracing.createLoggerFor(this.getClass());
    if (StringHelper.containsNonWhitespace(textElement.getValue())) {
     
      // Use an HttpClient to fetch a profile information page from MSN.
      HttpClient httpClient = HttpClientFactory.getHttpClientInstance();
      HttpClientParams httpClientParams = httpClient.getParams();
      httpClientParams.setConnectionManagerTimeout(2500);
      httpClient.setParams(httpClientParams);
      HttpMethod httpMethod = new GetMethod(MSN_NAME_VALIDATION_URL);
      NameValuePair idParam = new NameValuePair(MSN_NAME_URL_PARAMETER, textElement.getValue());
      httpMethod.setQueryString(new NameValuePair[] {idParam});
      // Don't allow redirects since otherwise, we won't be able to get the correct status
      httpMethod.setFollowRedirects(false);
      try {
        // Get the user profile page
        httpClient.executeMethod(httpMethod);
        int httpStatusCode = httpMethod.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;
      }
    } else {
      result = true;
View Full Code Here

   *      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(ICQ_NAME_MAX_LENGTH);

    if (!UserManager.getInstance().isUserViewReadOnly(usageIdentifyer, this) || isAdministrativeUser) {
      textElement.setExampleKey("form.example.icqname", null);
    }
    return textElement;
  }
View Full Code Here

   */
  @SuppressWarnings({"unchecked", "unused"})
  @Override
  public boolean isValid(FormItem formItem, Map formContext) {
    boolean result;
    TextElement textElement = (TextElement)formItem;
    OLog log = Tracing.createLoggerFor(this.getClass());
    if (StringHelper.containsNonWhitespace(textElement.getValue())) {
     
      // Use an HttpClient to fetch a profile information page from ICQ.
      HttpClient httpClient = HttpClientFactory.getHttpClientInstance();
      HttpClientParams httpClientParams = httpClient.getParams();
      httpClientParams.setConnectionManagerTimeout(2500);
      httpClient.setParams(httpClientParams);
      HttpMethod httpMethod = new GetMethod(ICQ_NAME_VALIDATION_URL);
      NameValuePair uinParam = new NameValuePair(ICQ_NAME_URL_PARAMETER, textElement.getValue());
      httpMethod.setQueryString(new NameValuePair[] {uinParam});
      // Don't allow redirects since otherwise, we won't be able to get the HTTP 302 further down.
      httpMethod.setFollowRedirects(false);
      try {
        // Get the user profile page
        httpClient.executeMethod(httpMethod);
        int httpStatusCode = httpMethod.getStatusCode();
        // Looking at the HTTP status code tells us whether a user with the given ICQ name exists.
        if (httpStatusCode == HttpStatus.SC_OK) {
          // ICQ tells us that a user name is valid if it sends an HTTP 200...
          result = true;
        } else if (httpStatusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
          // ...and if it's invalid, it sends an HTTP 302.
          textElement.setErrorKey("form.name.icq.error", null);
          result = false;
        } else {
          // For HTTP status codes other than 200 and 302 we will silently assume that the given ICQ name is valid, but inform the user about this.
          textElement.setExampleKey("form.example.icqname.notvalidated", null);
          log.warn("ICQ name validation: Expected HTTP status 200 or 301, but got " + httpStatusCode);
          result = true;
        }
      } catch (Exception e) {
        // In case of any exception, assume that the given ICQ name is valid (The opposite would block easily upon network problems), and inform the user about this.
        textElement.setExampleKey("form.example.icqname.notvalidated", null);
        log.warn("ICQ name validation: Exception: " + e.getMessage());
        result = true;
      }
    } else {
      result = true;
View Full Code Here

TOP

Related Classes of org.olat.core.gui.components.form.flexible.elements.TextElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.