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
006package fc.web.forms;
007
008import javax.servlet.*;
009import javax.servlet.http.*;
010import java.io.*;
011import java.util.*;
012import java.util.regex.*;
013
014import fc.jdbc.*;
015import fc.io.*;
016import fc.util.*;
017
018/**
019Validates that certain conditions in one or more fields in the form
020require other conditions of some other fields in that form.
021<p>
022Since the pre/post conditions can be arbitrary, this class defines 
023abstract methods called {@link #preConditionMet} and {@link
024#postConditionMet}. If the pre condition is true, the post condition must
025also be true. Subclasses should implement both methods as appropriate.
026
027@author hursh jain
028**/
029public abstract class VConditional extends FormValidator
030{
031public VConditional(Form f, String name, String errorMessage)
032  {
033  super(f, name, errorMessage);
034  }
035
036/**
037Returns 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
041this method will return true.
042*/
043public 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/**
053Subclasses should implement this method to check that certain fields or
054pre-conditions have been met. Only gf these conditions have been met will
055there 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*/
059public abstract boolean preConditionMet(FormData fd, HttpServletRequest req);
060
061
062/**
063Subclasses should implement this method to check that 
064certain post conditions have been met. This method will
065only be called if the {@link #preConditionMet} method 
066returns true.
067
068@return true if the post-conditions have been met, false otherwise
069*/
070public abstract boolean postConditionMet(FormData fd, HttpServletRequest req);
071
072}          //~class VConditional
073