struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgra...@apache.org
Subject cvs commit: jakarta-struts/src/share/org/apache/struts/validator ValidatorPlugIn.java
Date Thu, 22 May 2003 00:42:30 GMT
dgraham     2003/05/21 17:42:29

  Modified:    src/share/org/apache/struts/validator ValidatorPlugIn.java
  Log:
  Minor code cleanup.
  
  Revision  Changes    Path
  1.17      +45 -44    jakarta-struts/src/share/org/apache/struts/validator/ValidatorPlugIn.java
  
  Index: ValidatorPlugIn.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/validator/ValidatorPlugIn.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- ValidatorPlugIn.java	28 Nov 2002 07:20:18 -0000	1.16
  +++ ValidatorPlugIn.java	22 May 2003 00:42:29 -0000	1.17
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -59,10 +59,8 @@
    *
    */
   
  -
   package org.apache.struts.validator;
   
  -
   import java.util.StringTokenizer;
   import java.io.BufferedInputStream;
   import java.io.InputStream;
  @@ -78,7 +76,6 @@
   import org.apache.struts.action.PlugIn;
   import org.apache.struts.config.ModuleConfig;
   
  -
   /**
    * <p>Loads <code>ValidatorResources</code> based on
    * configuration in the struts-config.xml.</p>
  @@ -99,7 +96,6 @@
        */
       private ModuleConfig config = null;
   
  -
       /**
        * The {@link ActionServlet} owning this application.
        */
  @@ -146,8 +142,6 @@
       }
   
       /**
  -
  -    /**
        * Initialize and load our resources.
        *
        * @param servlet The ActionServlet for our application
  @@ -156,7 +150,7 @@
        * @exception ServletException if we cannot configure ourselves correctly
        */
       public void init(ActionServlet servlet, ModuleConfig config)
  -                         throws ServletException {
  +        throws ServletException {
   
           // Remember our associated configuration and servlet
           this.config = config;
  @@ -165,11 +159,14 @@
           // Load our database from persistent storage
           try {
               initResources();
  -            servlet.getServletContext().setAttribute(VALIDATOR_KEY + config.getPrefix(),
resources);
  +            servlet.getServletContext().setAttribute(
  +                VALIDATOR_KEY + config.getPrefix(),
  +                resources);
  +                
           } catch (Exception e) {
               log.error(e.getMessage(), e);
  -            throw new UnavailableException
  -                                 ("Cannot load a validator resource from '" + pathnames
+ "'");
  +            throw new UnavailableException(
  +                "Cannot load a validator resource from '" + pathnames + "'");
           }
   
       }
  @@ -197,44 +194,48 @@
        * @exception ServletException if we cannot initialize these resources, not thrown
by this implementation
        */
       protected void initResources() throws IOException, ServletException {
  -        resources = new ValidatorResources();
  +        this.resources = new ValidatorResources();
  +
  +        if (pathnames == null || pathnames.length() <= 0) {
  +            return;
  +        }
   
  -        if (pathnames != null && pathnames.length() > 0) {
  -            StringTokenizer st = new StringTokenizer(pathnames, RESOURCE_DELIM);
  +        StringTokenizer st = new StringTokenizer(pathnames, RESOURCE_DELIM);
   
  -            while (st.hasMoreTokens()) {
  -                String validatorRules = st.nextToken();
  +        while (st.hasMoreTokens()) {
  +            String validatorRules = st.nextToken().trim();
   
  -                validatorRules = validatorRules.trim();
  +            if (log.isInfoEnabled()) {
  +                log.info(
  +                    "Loading validation rules file from '" + validatorRules + "'");
  +            }
   
  -                if (log.isInfoEnabled()) {
  -                    log.info("Loading validation rules file from '" + validatorRules +
"'");
  -                }
  +            InputStream input =
  +                servlet.getServletContext().getResourceAsStream(validatorRules);
   
  -                InputStream input = null;
  -                input = servlet.getServletContext().getResourceAsStream(validatorRules);
  +            if (input != null) {
  +                BufferedInputStream bis = new BufferedInputStream(input);
   
  -                if (input != null) {
  -                    BufferedInputStream bis = null;
  -                    bis = new BufferedInputStream(input);
  -
  -                    try {
  -                        // pass in false so resources aren't processed
  -                        // until last file is loaded
  -                        ValidatorResourcesInitializer.initialize(resources, bis, false);
  -                        bis.close();
  -                    } catch (Exception e) {
  -                        log.error(e.getMessage(), e);
  -                        bis.close();
  -                    }
  -                } else {
  -                    log.error("Skipping validation rules file from '" + validatorRules
+ "'.  No stream could be opened.");
  +                try {
  +                    // pass in false so resources aren't processed
  +                    // until last file is loaded
  +                    ValidatorResourcesInitializer.initialize(resources, bis, false);
  +                } catch (IOException e) {
  +                    log.error(e.getMessage(), e);
  +                } finally {
  +                    bis.close();
                   }
  -            }
   
  -            // process resources
  -            resources.process();
  +            } else {
  +                log.error(
  +                    "Skipping validation rules file from '"
  +                        + validatorRules
  +                        + "'.  No stream could be opened.");
  +            }
           }
  +
  +        resources.process();
  +
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


Mime
View raw message