KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > gui > propedit > EmailFilter


1 package net.suberic.pooka.gui.propedit;
2 import net.suberic.util.gui.propedit.*;
3 import java.util.*;
4 import javax.mail.internet.InternetAddress JavaDoc;
5
6 /**
7  * A PropertyEditorListener which sets a property as required.
8  */

9 public class EmailFilter extends PropertyEditorAdapter implements ConfigurablePropertyEditorListener {
10
11   /**
12    * Configures this filter from the given key.
13    */

14   public void configureListener(String JavaDoc key, String JavaDoc property, String JavaDoc pPropertyBase, String JavaDoc editorTemplate, PropertyEditorManager pManager) {
15
16   }
17
18   /**
19    * Checks to make sure that the value is a valid email address.
20    */

21   public void propertyCommitting(PropertyEditorUI source, String JavaDoc property, String JavaDoc newValue) throws PropertyValueVetoException {
22     validateAddress(property, newValue);
23   }
24
25   /**
26    * Checks to make sure that the value is a valid email address.
27    */

28   public void propertyChanging(PropertyEditorUI source, String JavaDoc property, String JavaDoc newValue) throws PropertyValueVetoException {
29     validateAddress(property, newValue);
30   }
31
32   /**
33    * Checks to make sure that the value is a valid email address.
34    */

35   public void validateAddress(String JavaDoc property, String JavaDoc newValue) throws PropertyValueVetoException {
36     try {
37       if (newValue == null || newValue.length() == 0) {
38         return;
39       }
40       InternetAddress.parse(newValue);
41     } catch (Exception JavaDoc e) {
42         throw new PropertyValueVetoException(property, newValue, "must be a valid email address", this);
43     }
44   }
45 }
46
Popular Tags