Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type UrlValidator is deprecated

i'm writing a custom validator to check the url entered by the user :

package tn.talan.testFramework.validators;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

import org.apache.commons.validator.UrlValidator;





  public class URLCustomValidator implements Validator{

public void validate(FacesContext context, UIComponent component,Object value) throws ValidatorException {

    String enteredURL = (String) value;
    String[] schemes = {"http","https"};
    System.out.println(enteredURL);
    FacesMessage message = null ;
    String messageStr = null ;

            UrlValidator urlValidator = new UrlValidator(schemes);


           if (!urlValidator.isValid(enteredURL)) {
               System.out.println("url is invalid valid");
               message = new FacesMessage();
               messageStr = (String)component.getAttributes().get("message");
               if (messageStr == null) {

                    messageStr = "Inavalid URL";

                  }
                  message.setDetail(messageStr);

                  message.setSummary(messageStr);

                  message.setSeverity(FacesMessage.SEVERITY_ERROR);

                  throw new ValidatorException(message);
               } 






          }

}

I get this warning and i want to solve it :

The type UrlValidator is deprecated

Thank u in advance

like image 451
Amira Avatar asked Jan 11 '13 09:01

Amira


2 Answers

UrlValidator from package org.apache.commons.validator.UrlValidator is deprecated, please use UrlValidator from this Routines package:

like image 148
Pradeep Simha Avatar answered Sep 27 '22 02:09

Pradeep Simha


According to JavaDoc:

Use the new UrlValidator in the routines package. This class will be removed in a future release.

like image 30
Andremoniy Avatar answered Sep 26 '22 02:09

Andremoniy