001 // Copyright (c) 2001 Hursh Jain (http://www.mollypages.org)
002 // The Molly framework is freely distributable under the terms of an
003 // MIT-style license. For details, see the molly pages web site at:
004 // http://www.mollypages.org/. Use, modify, have fun !
005
006 package fc.web.forms;
007
008 import javax.servlet.*;
009 import javax.servlet.http.*;
010 import java.io.*;
011 import java.util.*;
012 import java.util.regex.*;
013
014 import fc.jdbc.*;
015 import fc.io.*;
016 import fc.util.*;
017
018 /**
019 Validates that certain conditions in one or more fields in the form
020 require other conditions of some other fields in that form.
021 <p>
022 Since the pre/post conditions can be arbitrary, this class defines
023 abstract methods called {@link #preConditionMet} and {@link
024 #postConditionMet}. If the pre condition is true, the post condition must
025 also be true. Subclasses should implement both methods as appropriate.
026
027 @author hursh jain
028 **/
029 public abstract class VConditional extends FormValidator
030 {
031 public VConditional(Form f, String name, String errorMessage)
032 {
033 super(f, name, errorMessage);
034 }
035
036 /**
037 Returns the value returned by {@link #postConditionMet}
038 <i>if</i> the pre conditions were met. ({@link
039 #preConditionMet} returned true). If the pre condition was
040 <i>not</i> met, there is no need for further validation and
041 this method will return true.
042 */
043 public boolean validate(FormData fd, HttpServletRequest req)
044 {
045 if (! preConditionMet(fd, req) )
046 return true;
047
048 return postConditionMet(fd, req);
049 }
050
051
052 /**
053 Subclasses should implement this method to check that certain fields or
054 pre-conditions have been met. Only gf these conditions have been met will
055 there be a check to see that the post conditions are also true.
056
057 @return true if the pre-conditions have been met, false otherwise
058 */
059 public abstract boolean preConditionMet(FormData fd, HttpServletRequest req);
060
061
062 /**
063 Subclasses should implement this method to check that
064 certain post conditions have been met. This method will
065 only be called if the {@link #preConditionMet} method
066 returns true.
067
068 @return true if the post-conditions have been met, false otherwise
069 */
070 public abstract boolean postConditionMet(FormData fd, HttpServletRequest req);
071
072 } //~class VConditional
073