myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bara...@apache.org
Subject svn commit: r226840 - in /myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/urlvalidator: ./ UrlValidator.java ValidateUrlTag.java
Date Mon, 01 Aug 2005 17:11:33 GMT
Author: baranda
Date: Mon Aug  1 10:11:28 2005
New Revision: 226840

URL: http://svn.apache.org/viewcvs?rev=226840&view=rev
Log:
Added new UrlValidator. Thanks to Fabian Frederick for this contribution

Added:
    myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/urlvalidator/
    myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/urlvalidator/UrlValidator.java
    myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/urlvalidator/ValidateUrlTag.java

Added: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/urlvalidator/UrlValidator.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/urlvalidator/UrlValidator.java?rev=226840&view=auto
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/urlvalidator/UrlValidator.java
(added)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/urlvalidator/UrlValidator.java
Mon Aug  1 10:11:28 2005
@@ -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));
+
+			}
+
+	}
+
+}

Added: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/urlvalidator/ValidateUrlTag.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/urlvalidator/ValidateUrlTag.java?rev=226840&view=auto
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/urlvalidator/ValidateUrlTag.java
(added)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/urlvalidator/ValidateUrlTag.java
Mon Aug  1 10:11:28 2005
@@ -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