View Javadoc
1 package net.sf.flock.webapp.components; 2 3 import java.net.MalformedURLException; 4 import java.net.URL; 5 6 import net.sf.tapestry.valid.BaseValidator; 7 import net.sf.tapestry.valid.IField; 8 import net.sf.tapestry.valid.ValidatorException; 9 10 public class URLValidator extends BaseValidator { 11 12 /*** 13 * @see net.sf.tapestry.valid.IValidator#toObject(IField, String) 14 */ 15 public Object toObject(IField field, String value) throws ValidatorException { 16 if (value==null) { 17 return null; 18 } 19 if (!value.startsWith("http://")) { 20 throw new ValidatorException(field.getBinding("displayName").getString() + " must start with http://", null, value); 21 } 22 try { 23 return new URL(value); 24 } catch (MalformedURLException e) { 25 throw new ValidatorException("Invalid " + field.getBinding("displayName").getString() + " - " + e.getMessage(), null, value); 26 } 27 } 28 29 /*** 30 * @see net.sf.tapestry.valid.IValidator#toString(IField, Object) 31 */ 32 public String toString(IField field, Object value) { 33 return value==null ? null : ((URL)value).toString(); 34 } 35 36 }

This page was automatically generated by Maven