cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp XSPFormValidatorHelper.java
Date Thu, 12 Jul 2001 19:12:52 GMT
bloritsch    01/07/12 12:12:52

  Modified:    src/org/apache/cocoon/components/language/markup/xsp
                        XSPFormValidatorHelper.java
  Log:
  Clean up cod on XSPFormValidatorHelper code.  You now only have to maintain
  one of each type of validation action.  Also, Null is implicitly Too Small, so I reflected
  that in the code.
  
  Revision  Changes    Path
  1.8       +54 -56    xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp/XSPFormValidatorHelper.java
  
  Index: XSPFormValidatorHelper.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp/XSPFormValidatorHelper.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XSPFormValidatorHelper.java	2001/07/10 17:51:20	1.7
  +++ XSPFormValidatorHelper.java	2001/07/12 19:12:48	1.8
  @@ -37,7 +37,7 @@
    * The <code>ValidatorActionResult</code> object helper
    *
    * @author <a href="mailto:haul@informatik.tu-darmstadt.de">Christian Haul</a>
  - * @version CVS $Revision: 1.7 $ $Date: 2001/07/10 17:51:20 $
  + * @version CVS $Revision: 1.8 $ $Date: 2001/07/12 19:12:48 $
    */
   public class XSPFormValidatorHelper {
     /**
  @@ -163,8 +163,13 @@
                             Map objectModel
                             )
       {
  -	return getParamResult(objectModel, current_parameter);
  +    ValidatorActionResult result = ValidatorActionResult.NOTPRESENT;
  +    Map param_result = (Map) getResults(objectModel);
  +    if (param_result != null ) {
  +        result = (ValidatorActionResult) param_result.get(current_parameter);
       }
  +    return result;
  +    }
   
   
     /**
  @@ -199,8 +204,7 @@
                Map objectModel
                )
       {
  -    boolean ok = false;
  -    return getParamResult(objectModel, current_parameter).equals(ValidatorActionResult.OK);
  +        return isOK(objectModel, current_parameter);
       }
   
   
  @@ -219,8 +223,8 @@
                String name
                )
       {
  -    boolean ok = false;
  -    return getParamResult(objectModel, name).ge(ValidatorActionResult.ERROR);
  +        boolean ok = false;
  +        return getParamResult(objectModel, name).ge(ValidatorActionResult.ERROR);
       }
   
     /**
  @@ -236,8 +240,7 @@
                Map objectModel
                )
       {
  -    boolean ok = false;
  -    return getParamResult(objectModel, current_parameter).ge(ValidatorActionResult.ERROR);
  +        return isError(objectModel, current_parameter);
       }
   
   
  @@ -272,8 +275,7 @@
                Map objectModel
                )
       {
  -    boolean ok = false;
  -    return getParamResult(objectModel, current_parameter).equals(ValidatorActionResult.ISNULL);
  +        return isNull(objectModel, current_parameter);
       }
   
   
  @@ -292,8 +294,13 @@
                String name
                )
       {
  -    boolean ok = false;
  -    return getParamResult(objectModel, name).equals(ValidatorActionResult.TOOSMALL);
  +        boolean ok = getParamResult(objectModel, name).equals(ValidatorActionResult.TOOSMALL);
  +
  +        if (!ok) {
  +            ok = isNull(objectModel, name);
  +        }
  +
  +        return ok;
       }
   
     /**
  @@ -309,8 +316,7 @@
                Map objectModel
                )
       {
  -    boolean ok = false;
  -    return getParamResult(objectModel, current_parameter).equals(ValidatorActionResult.TOOSMALL);
  +        return isTooSmall(objectModel, current_parameter);
       }
   
   
  @@ -346,8 +352,7 @@
                Map objectModel
                )
       {
  -    boolean ok = false;
  -    return getParamResult(objectModel, current_parameter).equals(ValidatorActionResult.TOOLARGE);
  +        return isTooLarge(objectModel, current_parameter);
       }
   
   
  @@ -367,8 +372,8 @@
                String name
                )
       {
  -    boolean ok = false;
  -    return getParamResult(objectModel, name).equals(ValidatorActionResult.NOMATCH);
  +        boolean ok = false;
  +        return getParamResult(objectModel, name).equals(ValidatorActionResult.NOMATCH);
       }
   
     /**
  @@ -385,8 +390,7 @@
                Map objectModel
                )
       {
  -    boolean ok = false;
  -    return getParamResult(objectModel, current_parameter).equals(ValidatorActionResult.NOMATCH);
  +       return isNoMatch(objectModel, current_parameter);
       }
   
   
  @@ -418,8 +422,7 @@
                Map objectModel
                )
       {
  -    boolean ok = false;
  -    return getParamResult(objectModel, current_parameter).equals(ValidatorActionResult.NOTPRESENT);
  +        return isNotPresent(objectModel, current_parameter);
       }
   
   
  @@ -458,41 +461,36 @@
   
           synchronized (XSPFormValidatorHelper.configurations) {
               conf = (ConfigurationHelper) XSPFormValidatorHelper.configurations.get(descriptor);
  +        Source source = null;
  +            SourceHandler sourceHandler = null;
  +        try {
  +            sourceHandler = (SourceHandler) manager.lookup(SourceHandler.ROLE);
  +            source = sourceHandler.getSource(null, descriptor);
  +
  +        if (conf == null || ( reloadable && conf.lastModified < source.getLastModified()))
{
  +            logger.debug("XSPFormValidatorHelper.getConfiguration: (Re)Loading " + descriptor);
  +
  +            if (conf == null)
  +            conf = new ConfigurationHelper();
  +
  +            SAXConfigurationHandler builder = new SAXConfigurationHandler();
  +                    source.stream(builder);
  +
  +            conf.lastModified = source.getLastModified();
  +            conf.configuration = builder.getConfiguration();
  +
  +            XSPFormValidatorHelper.cacheConfiguration(descriptor, conf);
  +        } else {
  +            logger.debug("XSPFormValidatorHelper.getConfiguration: Using cached configuration
for " + descriptor);
  +        }
  +        } catch (Exception e) {
  +        logger.error("XSPFormValidatorHelper.getConfiguration: Could not configure Database
mapping environment", e);
  +        throw new ConfigurationException("Error trying to load configurations for resource:
" + source.getSystemId());
  +        } finally {
  +               if (sourceHandler != null) manager.release((Component) sourceHandler);
  +        }
  +        }
   
  -	    if ( reloadable || conf==null ) {
  -		Source source = null;
  -		SourceHandler sourceHandler = null;
  -		try {
  -		    sourceHandler = (SourceHandler) manager.lookup(SourceHandler.ROLE);
  -		    source = sourceHandler.getSource(null, descriptor);
  -
  -		    if (conf == null || conf.lastModified < source.getLastModified()) {
  -			logger.debug("XSPFormValidatorHelper.getConfiguration: (Re)Loading " + descriptor);
  -			
  -			if (conf == null)
  -			    conf = new ConfigurationHelper();
  -
  -			SAXConfigurationHandler builder = new SAXConfigurationHandler();
  -			source.stream(builder);
  -
  -			conf.lastModified = source.getLastModified();
  -			conf.configuration = builder.getConfiguration();
  -
  -			XSPFormValidatorHelper.cacheConfiguration(descriptor, conf);
  -		    } else {
  -			logger.debug("XSPFormValidatorHelper.getConfiguration: Using cached configuration for
" + descriptor);
  -		    }
  -		} catch (Exception e) {
  -		    logger.error("XSPFormValidatorHelper.getConfiguration: Could not configure Database
mapping environment", e);
  -		    throw new ConfigurationException("Error trying to load configurations for resource:
" + source.getSystemId());
  -		} finally {
  -		    if (sourceHandler != null) manager.release((Component) sourceHandler);
  -		}
  -	    } else {
  -		logger.debug("XSPFormValidatorHelper.getConfiguration: Using fixed cached configuration
for " + descriptor);
  -	    }
  -	}
  -	
           return conf.configuration;
       }
   
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message