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 11 public class BaseForm 12 extends ActionForm 13 { 14 16 private String _redirectUri = ""; 17 18 20 public void checkCreditCardDateFormat( String value, 21 String 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 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 value, 49 int len, 50 String 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 value, 60 String 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 72 public String getRedirectUri( ) 73 { 74 return _redirectUri; 75 } 76 77 81 public void setRedirectUri( String redirectUri ) 82 { 83 _redirectUri = redirectUri; 84 } 85 } 86 | Popular Tags |