myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Fab Psycho" <psychoro...@hotmail.com>
Subject urlvalidator
Date Wed, 27 Jul 2005 20:54:34 GMT
Hi,

       Here's a patch against tomahawk svn to add url validation.It's based 
on email validator.
I made this one as a test.Could you tell me the way you want patches 
submitted if I'm wrong with this one ?

Another question is about  serialVersionUID ... What does this one means in 
emailvalidator ?

Thanks in advance,
Fab

Index: 
D:/utils/eclipse31/workspace/current/tomahawk/src/java/org/apache/myfaces/custom/urlvalidator/UrlValidator.java
===================================================================
--- 
D:/utils/eclipse31/workspace/current/tomahawk/src/java/org/apache/myfaces/custom/urlvalidator/UrlValidator.java
(revision 
0)
+++ 
D:/utils/eclipse31/workspace/current/tomahawk/src/java/org/apache/myfaces/custom/urlvalidator/UrlValidator.java
(revision 
0)
@@ -0,0 +1,54 @@
+package org.apache.myfaces.custom.urlvalidator;
+
+import org.apache.myfaces.util.MessageUtils;
+
+import org.apache.commons.validator.GenericValidator;
+
+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;
+
+public class UrlValidator implements Validator {
+
+	/**
+	 * <p>The standard converter id for this converter.</p>
+	 */
+	public static final String 	VALIDATOR_ID 	   = 
"org.apache.myfaces.validator.Url";
+	/**
+	 * <p>The message identifier of the {@link FacesMessage} to be created if
+	 * the maximum length check fails.</p>
+	 */
+	public static final String URL_MESSAGE_ID = 
"org.apache.myfaces.Url.INVALID";
+
+	public UrlValidator(){
+	}
+
+	/**
+	 * method that validates an url address.
+	 * it uses the commons-validator
+	 */
+	public void validate(
+		FacesContext facesContext,
+		UIComponent uiComponent,
+		Object value)
+		throws ValidatorException {
+
+
+			if (facesContext == null) throw new 
NullPointerException("facesContext");
+			if (uiComponent == null) throw new NullPointerException("uiComponent");
+
+			if (value == null)
+			{
+				return;
+			}
+			if (!GenericValidator.isUrl(value.toString())) {
+				Object[] args = {value.toString()};
+				throw new 
ValidatorException(MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR,URL_MESSAGE_ID, 
args));
+
+			}
+
+	}
+
+}
Index: 
D:/utils/eclipse31/workspace/current/tomahawk/src/java/org/apache/myfaces/custom/urlvalidator/ValidateUrlTag.java
===================================================================
--- 
D:/utils/eclipse31/workspace/current/tomahawk/src/java/org/apache/myfaces/custom/urlvalidator/ValidateUrlTag.java
(revision 
0)
+++ 
D:/utils/eclipse31/workspace/current/tomahawk/src/java/org/apache/myfaces/custom/urlvalidator/ValidateUrlTag.java
(revision 
0)
@@ -0,0 +1,27 @@
+package org.apache.myfaces.custom.urlvalidator;
+
+import javax.faces.validator.Validator;
+import javax.faces.webapp.ValidatorTag;
+import javax.servlet.jsp.JspException;
+
+public class ValidateUrlTag extends ValidatorTag
+{
+  private static final long serialVersionUID = 6041422002721046221L;
+
+  public ValidateUrlTag()
+    {
+	}
+
+	protected Validator createValidator() throws JspException
+    {
+		setValidatorId(UrlValidator.VALIDATOR_ID);
+	    UrlValidator validator = (UrlValidator)super.createValidator();
+		return validator;
+	}
+
+    public void release()
+    {
+        super.release();
+    }
+
+}



Mime
View raw message