cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/acting AbstractConfigurableAction.java HttpHeaderAction.java LocaleAction.java SessionPropagatorAction.java
Date Sat, 25 Jan 2003 02:46:15 GMT
vgritsenko    2003/01/24 18:46:15

  Modified:    src/java/org/apache/cocoon/acting
                        AbstractConfigurableAction.java
                        HttpHeaderAction.java LocaleAction.java
                        SessionPropagatorAction.java
  Log:
  conf is never null in configure(). fix bug (static config) in http action.
  optimize a bit.
  
  Revision  Changes    Path
  1.6       +7 -13     xml-cocoon2/src/java/org/apache/cocoon/acting/AbstractConfigurableAction.java
  
  Index: AbstractConfigurableAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/AbstractConfigurableAction.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractConfigurableAction.java	22 Feb 2002 06:59:26 -0000	1.5
  +++ AbstractConfigurableAction.java	25 Jan 2003 02:46:14 -0000	1.6
  @@ -81,18 +81,12 @@
        * For nested configurations, override this function in your action.
        */
       public void configure(Configuration conf) throws ConfigurationException {
  -        if (conf != null) {
  -            String key = null;
  -            String val = null;
  -            Configuration[] parameters = conf.getChildren();
  -            this.settings = new HashMap(parameters.length);
  -            for ( int i = 0; i < parameters.length; i++) {
  -                key = parameters[i].getName();
  -                val = parameters[i].getValue(null);
  -                if ( key != null )
  -                    this.settings.put(key, val);
  -            }
  +        Configuration[] parameters = conf.getChildren();
  +        this.settings = new HashMap(parameters.length);
  +        for (int i = 0; i < parameters.length; i++) {
  +            String key = parameters[i].getName();
  +            String val = parameters[i].getValue(null);
  +            this.settings.put(key, val);
           }
       }
  -
   }
  
  
  
  1.8       +17 -21    xml-cocoon2/src/java/org/apache/cocoon/acting/HttpHeaderAction.java
  
  Index: HttpHeaderAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/HttpHeaderAction.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- HttpHeaderAction.java	13 Mar 2002 10:36:39 -0000	1.7
  +++ HttpHeaderAction.java	25 Jan 2003 02:46:14 -0000	1.8
  @@ -73,42 +73,38 @@
   extends AbstractConfigurableAction
   implements ThreadSafe {
   
  -    private static Object[] defaults = {};
  +    /**
  +     * Stores keys of global configuration.
  +     */
  +    private Object[] defaults = {};
   
       public void configure(Configuration conf) throws ConfigurationException {
  -        if (conf != null) {
  -            String[] names = {};
  -            super.configure(conf);
  -            defaults=(settings.keySet()).toArray();
  -        }
  +        super.configure(conf);
  +        this.defaults = super.settings.keySet().toArray();
       }
   
       public Map act(Redirector redirector, SourceResolver resolver,
                      Map objectModel, String source, Parameters parameters)
       throws Exception {
  -        Map results = new HashMap();
  -        HashMap isDone = new HashMap();
  -        Integer dummy = new Integer(1);
  +        final Map results = new HashMap();
   
           final Response response = ObjectModelHelper.getResponse(objectModel);
  -        final String[] names = parameters.getNames();
   
  -        // parameters
  -        for (int i=0; i<names.length; i++) {
  -            isDone.put(names[i], dummy);
  +        // Process local configuration parameters
  +        final String[] names = parameters.getNames();
  +        for (int i = 0; i < names.length; i++) {
               response.setHeader(names[i],parameters.getParameter(names[i]));
  -            results.put(names[i],parameters.getParameter(names[i]));
  +            results.put(names[i], parameters.getParameter(names[i]));
           }
   
  -        // defaults, that are not overridden
  -        for (int i=0; i<defaults.length; i++) {
  -            if (! isDone.containsKey(defaults[i])) {
  -                response.setHeader((String) defaults[i], (String) settings.get(defaults[i]));
  -                results.put((String) defaults[i],(String) settings.get(defaults[i]));
  +        // Process global defaults, that are not overridden
  +        for (int i = 0; i < defaults.length; i++) {
  +            if (!results.containsKey(this.defaults[i])) {
  +                response.setHeader((String) this.defaults[i], (String) this.settings.get(defaults[i]));
  +                results.put(this.defaults[i], this.settings.get(defaults[i]));
               }
           }
   
           return Collections.unmodifiableMap(results);
       }
  -
   }
  
  
  
  1.13      +61 -62    xml-cocoon2/src/java/org/apache/cocoon/acting/LocaleAction.java
  
  Index: LocaleAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/LocaleAction.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- LocaleAction.java	15 Dec 2002 16:46:12 -0000	1.12
  +++ LocaleAction.java	25 Jan 2003 02:46:15 -0000	1.13
  @@ -209,6 +209,26 @@
        */
       public static final String STORE_COOKIE = "store-in-cookie";
   
  +
  +    // Store the lang in request. Default is not to do this.
  +    private boolean storeInRequest = false;
  +
  +    // Store the lang in session, if available. Default is not to do this.
  +    private boolean storeInSession = false;
  +
  +    // Should we create a session if needed. Default is not to do this.
  +    private boolean createSession = false;
  +
  +    // Should we add a cookie with the lang. Default is not to do this.
  +    private boolean storeInCookie = false;
  +
  +    // Configuration attributes.
  +    private String langAttr;
  +    private String countryAttr;
  +    private String variantAttr;
  +    private String localeAttr;
  +
  +
       /**
        * Configure this action.
        *
  @@ -216,63 +236,60 @@
        */
       public void configure(Configuration conf)
       throws ConfigurationException {
  -        if (conf != null) {
  -
  -            Configuration child = conf.getChild(STORE_REQUEST);
  -            storeInRequest = child.getValueAsBoolean(false);
  +        Configuration child = conf.getChild(STORE_REQUEST);
  +        storeInRequest = child.getValueAsBoolean(false);
   
  -            if (getLogger().isDebugEnabled()) {
  -                getLogger().debug((storeInRequest ? "will" : "won't") + " set values in
request");
  -            }
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug((storeInRequest ? "will" : "won't") + " set values in request");
  +        }
   
  -            child = conf.getChild(CREATE_SESSION);
  -            createSession = child.getValueAsBoolean(false);
  +        child = conf.getChild(CREATE_SESSION);
  +        createSession = child.getValueAsBoolean(false);
   
  -            if (getLogger().isDebugEnabled()) {
  -                getLogger().debug((createSession ? "will" : "won't") + " create session");
  -            }
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug((createSession ? "will" : "won't") + " create session");
  +        }
   
  -            child = conf.getChild(STORE_SESSION);
  -            storeInSession = child.getValueAsBoolean(false);
  +        child = conf.getChild(STORE_SESSION);
  +        storeInSession = child.getValueAsBoolean(false);
   
  -            if (getLogger().isDebugEnabled()) {
  -                getLogger().debug((storeInSession ? "will" : "won't") + " set values in
session");
  -            }
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug((storeInSession ? "will" : "won't") + " set values in session");
  +        }
   
  -            child = conf.getChild(STORE_COOKIE);
  -            storeInCookie = child.getValueAsBoolean(false);
  +        child = conf.getChild(STORE_COOKIE);
  +        storeInCookie = child.getValueAsBoolean(false);
   
  -            if (getLogger().isDebugEnabled()) {
  -                getLogger().debug((storeInCookie ? "will" : "won't") + " set values in
cookies");
  -            }
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug((storeInCookie ? "will" : "won't") + " set values in cookies");
  +        }
   
  -            child = conf.getChild(LANG_ATTR);
  -            langAttr = child.getValue(LANG);
  +        child = conf.getChild(LANG_ATTR);
  +        langAttr = child.getValue(LANG);
   
  -            if (getLogger().isDebugEnabled()) {
  -                getLogger().debug("global language attribute name is " + langAttr);
  -            }
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("global language attribute name is " + langAttr);
  +        }
   
  -            child = conf.getChild(COUNTRY_ATTR);
  -            countryAttr = child.getValue(COUNTRY);
  +        child = conf.getChild(COUNTRY_ATTR);
  +        countryAttr = child.getValue(COUNTRY);
   
  -            if (getLogger().isDebugEnabled()) {
  -                getLogger().debug("global country attribute name is " + countryAttr);
  -            }
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("global country attribute name is " + countryAttr);
  +        }
   
  -            child = conf.getChild(VARIANT_ATTR);
  -            variantAttr = child.getValue(VARIANT);
  +        child = conf.getChild(VARIANT_ATTR);
  +        variantAttr = child.getValue(VARIANT);
   
  -            if (getLogger().isDebugEnabled()) {
  -                getLogger().debug("global variant attribute name is " + variantAttr);
  -            }
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("global variant attribute name is " + variantAttr);
  +        }
   
  -            child = conf.getChild(LOCALE_ATTR);
  -            localeAttr = child.getValue(LOCALE);
  +        child = conf.getChild(LOCALE_ATTR);
  +        localeAttr = child.getValue(LOCALE);
   
  -            if (getLogger().isDebugEnabled()) {
  -                getLogger().debug("global locale attribute name is " + localeAttr);
  -            }
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("global locale attribute name is " + localeAttr);
           }
       }
   
  @@ -290,7 +307,7 @@
   
           // obtain locale information from params, session or cookies
           String lc = getLocaleAttribute(objectModel, localeAttr);
  -	Locale locale = I18nUtils.parseLocale(lc);
  +        Locale locale = I18nUtils.parseLocale(lc);
   
           if (getLogger().isDebugEnabled()) {
               getLogger().debug("obtained locale information, locale = " + lc);
  @@ -412,22 +429,4 @@
               "  " + STORE_COOKIE + " = " + storeInCookie + "\n"
           );
       }
  -
  -    // Store the lang in request. Default is not to do this.
  -    private boolean storeInRequest = false;
  -
  -    // Store the lang in session, if available. Default is not to do this.
  -    private boolean storeInSession = false;
  -
  -    // Should we create a session if needed. Default is not to do this.
  -    private boolean createSession = false;
  -
  -    // Should we add a cookie with the lang. Default is not to do this.
  -    private boolean storeInCookie = false;
  -
  -    // Configuration attributes.
  -    private String langAttr;
  -    private String countryAttr;
  -    private String variantAttr;
  -    private String localeAttr;
   }
  
  
  
  1.12      +19 -38    xml-cocoon2/src/java/org/apache/cocoon/acting/SessionPropagatorAction.java
  
  Index: SessionPropagatorAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/SessionPropagatorAction.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SessionPropagatorAction.java	7 Jan 2003 23:56:11 -0000	1.11
  +++ SessionPropagatorAction.java	25 Jan 2003 02:46:15 -0000	1.12
  @@ -81,57 +81,44 @@
    * @author <a href="mailto:Martin.Man@seznam.cz">Martin Man</a>
    * @version CVS $Id$
    */
  -public class SessionPropagatorAction extends AbstractConfigurableAction implements ThreadSafe
  -{
  +public class SessionPropagatorAction extends AbstractConfigurableAction implements ThreadSafe
{
   
       private Object[] defaults = {};
   
       public void configure(Configuration conf) throws ConfigurationException {
  -        if (conf != null) {
  -        String[] names = {};
           super.configure(conf);
  -        defaults=(settings.keySet()).toArray();
  -    };
  +        this.defaults = super.settings.keySet().toArray();
       }
   
       /**
        * Main invocation routine.
        */
       public Map act (Redirector redirector, SourceResolver resolver, Map objectModel, String
src,
  -            Parameters parameters) throws Exception {
  +                    Parameters parameters) throws Exception {
           Request req = ObjectModelHelper.getRequest(objectModel);
           HashMap actionMap = new HashMap ();
   
  -        HashMap isDone = new HashMap();
  -        Integer dummy = new Integer(1);
  -
           /* check session validity */
           Session session = req.getSession (false);
           if (session == null) {
  -            if (this.getLogger().isDebugEnabled()) {
  -                getLogger ().debug ("SESSIONPROPAGATOR: no session object");
  +            if (getLogger().isDebugEnabled()) {
  +                getLogger().debug("No session object");
               }
               return null;
           }
   
           try {
  -
               String[] names = parameters.getNames();
   
               // parameters
               for (int i = 0; i < names.length; i++) {
                   String sessionParamName = names[i];
  -                if (sessionParamName == null
  -                    || "".equals(sessionParamName.trim()))
  -                    return null;
  -                isDone.put(sessionParamName, dummy);
                   String value = parameters.getParameter(sessionParamName);
  -                if (this.getLogger().isDebugEnabled()) {
  -                    getLogger().debug(
  -                    "SESSIONPROPAGATOR: propagating value "
  -                        + value
  -                        + " to session attribute "
  -                        + sessionParamName);
  +                if (getLogger().isDebugEnabled()) {
  +                    getLogger().debug("Propagating value "
  +                                      + value
  +                                      + " to session attribute "
  +                                      + sessionParamName);
                   }
                   session.setAttribute(sessionParamName, value);
                   actionMap.put(sessionParamName, value);
  @@ -139,27 +126,21 @@
   
               // defaults, that are not overridden
               for (int i = 0; i < defaults.length; i++) {
  -                if (!isDone.containsKey(defaults[i])) {
  +                if (!actionMap.containsKey(defaults[i])) {
                       String sessionParamName = (String) defaults[i];
  -                    if (sessionParamName == null
  -                        || "".equals(sessionParamName.trim()))
  -                        return null;
  -                    isDone.put(sessionParamName, dummy);
                       String value = parameters.getParameter(sessionParamName);
  -                    if (this.getLogger().isDebugEnabled()) {
  -                        getLogger().debug(
  -                            "SESSIONPROPAGATOR: propagating value "
  -                                + value
  -                                + " to session attribute "
  -                                + sessionParamName);
  +                    if (getLogger().isDebugEnabled()) {
  +                        getLogger().debug("Propagating value "
  +                                          + value
  +                                          + " to session attribute "
  +                                          + sessionParamName);
                       }  
                       session.setAttribute(sessionParamName, value);
                       actionMap.put(sessionParamName, value);
                   }
               }
  -            if (this.getLogger().isDebugEnabled()) {
  -                getLogger().debug(
  -                    "SESSIONPROPAGATOR: all params propagated " + "to session");
  +            if (getLogger().isDebugEnabled()) {
  +                getLogger().debug("All params propagated " + "to session");
               }
               return Collections.unmodifiableMap(actionMap);
           } catch (Exception e) {
  
  
  

----------------------------------------------------------------------
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