|
|||||||||||||||||||
| This license of Clover is provided to support the development of Flock only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover. | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| URLValidator.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 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 | 0 |
public Object toObject(IField field, String value) throws ValidatorException {
|
| 16 | 0 |
if (value==null) {
|
| 17 | 0 |
return null; |
| 18 |
} |
|
| 19 | 0 |
if (!value.startsWith("http://")) {
|
| 20 | 0 |
throw new ValidatorException(field.getBinding("displayName").getString() + " must start with http://", null, value);
|
| 21 |
} |
|
| 22 | 0 |
try {
|
| 23 | 0 |
return new URL(value); |
| 24 |
} catch (MalformedURLException e) {
|
|
| 25 | 0 |
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 | 0 |
public String toString(IField field, Object value) {
|
| 33 | 0 |
return value==null ? null : ((URL)value).toString(); |
| 34 |
} |
|
| 35 |
|
|
| 36 |
} |
|
| 37 |
|
|
||||||||||