public class CheckOnly implements ServletWorker{
private static RequestParser reqParser;
private static ViewGenerator viewGenerator;
public CheckOnly()
throws Exception{
reqParser = RequestParser.getInstance();
viewGenerator = ViewGenerator.getInstance();
}
public void work(HttpServletRequest req,
HttpServletResponse res)
throws NestedException,SimpleException{
try{
// Parse the HTTP request ...
ParsedRequestParameters params
= reqParser.parseSimple(req);
// Verify all the request parameters by just
// a single line !
// The second parameter of this method specifies
// the XML that is used to verify the request
// parameters.
VerifyResult result = viewGenerator.verify(params,0);
// Insert the values between the tags.
Map values = new HashMap();
values.put("date",(new Date()).toString());
if(result.isAllOk()){
// If all the request parameters are valid ...
// The second parameter of this method specifies
// the XML that is used to generate the response.
viewGenerator.
writeResponseWithDefault(params,1,res,null,
values,true);
}
else{
// If any of the request parameters are invalid ...
// The second parameter of this method specifies
// the XML that is used to generate the response.
// The 4th parameter of this method includes the
// request parameters, and they will be appear within
// the CGI FORM as the default values.
viewGenerator.writeResponseWithDefault(params,0,res,
result.getResultMap(),values,true);
}
}
catch(NestedException ex){
throw ex;
}
catch(SimpleException ex){
throw ex;
}
catch(Exception ex){
throw (new NestedException(ex));
}
}
} //End of : CheckOnly
|
Copyright © 1997-2007 OOP-Research CorporationTM, All Rights Reserved.