KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xpetstore > web > struts > action > BaseForm


1 package xpetstore.web.struts.action;
2
3 import org.apache.struts.action.ActionError;
4 import org.apache.struts.action.ActionErrors;
5 import org.apache.struts.action.ActionForm;
6
7
8 /**
9  * @author <a HREF="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
10  */

11 public class BaseForm
12     extends ActionForm
13 {
14     //~ Instance fields --------------------------------------------------------
15

16     private String JavaDoc _redirectUri = "";
17
18     //~ Methods ----------------------------------------------------------------
19

20     public void checkCreditCardDateFormat( String JavaDoc value,
21                                            String JavaDoc msg,
22                                            ActionErrors errors )
23     {
24         boolean err = false;
25
26         try
27         {
28             int i = value.indexOf( "-" );
29
30             if ( ( err = ( i >= 0 ) ) )
31             {
32                 int lhs = Integer.parseInt( value.substring( 0, i ) );
33                 int rhs = Integer.parseInt( value.substring( i + 1 ) );
34                 err = !( ( lhs >= 1 ) && ( lhs <= 12 ) && ( rhs >= 0 ) );
35             }
36         }
37         catch ( Exception JavaDoc e )
38         {
39             err = true;
40         }
41
42         if ( err )
43         {
44             errors.add( "ActionForm", new ActionError( msg ) );
45         }
46     }
47
48     public void checkLength( String JavaDoc value,
49                              int len,
50                              String JavaDoc msg,
51                              ActionErrors errors )
52     {
53         if ( ( value == null ) || ( value.length( ) < len ) )
54         {
55             errors.add( "ActionForm", new ActionError( msg ) );
56         }
57     }
58
59     public void checkNotEmpty( String JavaDoc value,
60                                String JavaDoc msg,
61                                ActionErrors errors )
62     {
63         if ( ( value == null ) || ( value.trim( ).length( ) == 0 ) )
64         {
65             errors.add( "ActionForm", new ActionError( msg ) );
66         }
67     }
68
69     /**
70      * @return String
71      */

72     public String JavaDoc getRedirectUri( )
73     {
74         return _redirectUri;
75     }
76
77     /**
78      * Sets the redirectUri.
79      * @param redirectUri The redirectUri to set
80      */

81     public void setRedirectUri( String JavaDoc redirectUri )
82     {
83         _redirectUri = redirectUri;
84     }
85 }
86
Popular Tags