haul 01/07/23 08:50:10 Modified: src/org/apache/cocoon/acting AbstractAction.java AbstractComplementaryConfigurableAction.java AbstractDatabaseAction.java FormValidatorAction.java HttpHeaderAction.java SessionPropagatorAction.java SessionStateAction.java Added: src/org/apache/cocoon/util HashMap.java src/org/apache/cocoon/acting AbstractConfigurableAction.java ConfigurableComposerAction.java Log: moved configuration code from AbstractAction to AbstractConfigurableAction, subclassed it with ConfigurableComposerAction and moved some action that used this configuration code appropriately. Added configuration support for default values to HttpHeaderAction, SessionPropagatorAction Revision Changes Path 1.1 xml-cocoon2/src/org/apache/cocoon/util/HashMap.java Index: HashMap.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.cocoon.util; import java.util.Map; /** * Extended Version of {@link java.util.HashMap}. * * @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a> * @version CVS $Revision: 1.1 $ $Date: 2001/07/23 15:50:10 $ */ public class HashMap extends java.util.HashMap { public HashMap () { super(); } public HashMap ( int initialCapacity ) { super(initialCapacity); } public HashMap ( int initialCapacity, float loadFactor ) { super(initialCapacity, loadFactor); } public HashMap ( Map t) { super(t); } /** * Get method extended by default object to be returned when key * is not found. * * @param key key to look up * @param _default default value to return if key is not found * @return value that is associated with key */ public Object get ( Object key, Object _default ) { if (this.containsKey(key)) { return this.get(key); } else { return _default; }; } } 1.5 +3 -27 xml-cocoon2/src/org/apache/cocoon/acting/AbstractAction.java Index: AbstractAction.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/acting/AbstractAction.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- AbstractAction.java 2001/07/20 08:40:44 1.4 +++ AbstractAction.java 2001/07/23 15:50:10 1.5 @@ -13,48 +13,24 @@ import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.logger.AbstractLoggable; -import java.util.HashMap; - /** * AbstractAction gives you the infrastructure for easily deploying more * Actions. In order to get at the Logger, use getLogger(). * * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a> * @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a> - * @version CVS $Revision: 1.4 $ $Date: 2001/07/20 08:40:44 $ + * @version CVS $Revision: 1.5 $ $Date: 2001/07/23 15:50:10 $ */ public abstract class AbstractAction extends AbstractLoggable implements Action, Configurable, Disposable { /** - * Stores (global) configuration parameters as <code>key</code> / - * <code>value</code> pairs. - */ - protected HashMap settings = null; - - /** * Configures the Action. * - * Takes the children from the <code>Configuration</code> and stores them - * them as key (configuration name) and value (configuration value) - * in <code>settings</code>. - * <br/> - * This automates parsing of flat string-only configurations. - * 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); - } - } + // Purposely empty so that we don't need to implement it in every + // class. } /** 1.7 +2 -2 xml-cocoon2/src/org/apache/cocoon/acting/AbstractComplementaryConfigurableAction.java Index: AbstractComplementaryConfigurableAction.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/acting/AbstractComplementaryConfigurableAction.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- AbstractComplementaryConfigurableAction.java 2001/07/11 08:47:48 1.6 +++ AbstractComplementaryConfigurableAction.java 2001/07/23 15:50:10 1.7 @@ -32,9 +32,9 @@ * effective. The name of the root configuration element is irrelevant. * * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a> - * @version CVS $Revision: 1.6 $ $Date: 2001/07/11 08:47:48 $ + * @version CVS $Revision: 1.7 $ $Date: 2001/07/23 15:50:10 $ */ -public abstract class AbstractComplementaryConfigurableAction extends ComposerAction { +public abstract class AbstractComplementaryConfigurableAction extends ConfigurableComposerAction { private static Map configurations = new HashMap(); /** 1.9 +23 -9 xml-cocoon2/src/org/apache/cocoon/acting/AbstractDatabaseAction.java Index: AbstractDatabaseAction.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/acting/AbstractDatabaseAction.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- AbstractDatabaseAction.java 2001/07/07 11:43:12 1.8 +++ AbstractDatabaseAction.java 2001/07/23 15:50:10 1.9 @@ -158,7 +158,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a> * @author <a href="mailto:[EMAIL PROTECTED]">Donald Ball</a> - * @version CVS $Revision: 1.8 $ $Date: 2001/07/07 11:43:12 $ + * @version CVS $Revision: 1.9 $ $Date: 2001/07/23 15:50:10 $ */ public abstract class AbstractDatabaseAction extends AbstractComplementaryConfigurableAction implements Configurable, Disposable { protected Map files = new HashMap(); @@ -537,10 +537,12 @@ file = (File) request.get(imageAttr); synchronized (this.files) { Parameters parameters = (Parameters) this.files.get(file); - statement.setString(position, parameters.getParameter("image-mime-type","")); + String imageMimeType = parameters.getParameter("image-mime-type", + (String) settings.get("image-mime-type","")); + statement.setString(position, imageMimeType); /** Store the image mime type in the request attributes. Why do we do this? **/ - setRequestAttribute(request,param,parameters.getParameter("image-mime-type","")); + setRequestAttribute(request, param, imageMimeType); } break; } @@ -588,10 +590,14 @@ file = (File) request.get(imageAttr); synchronized (this.files) { Parameters parameters = (Parameters) this.files.get(file); - statement.setInt(position, parameters.getParameterAsInteger("image-width", -1)); + statement.setInt(position, parameters.getParameterAsInteger("image-width", + Integer.parseInt((String)settings.get("image-width","-1")))); /** Store the image width in the request attributes. Why do we do this? **/ - setRequestAttribute(request,param,parameters.getParameter("image-width","")); + setRequestAttribute(request, + param, + parameters.getParameter("image-width", + (String) settings.get("image-width",""))); } break; } else if ("image-height".equals(typeName)) { @@ -600,8 +606,12 @@ file = (File) request.get(imageAttr); synchronized (this.files) { Parameters parameters = (Parameters) this.files.get(file); - statement.setInt(position, parameters.getParameterAsInteger("image-height", -1)); - setRequestAttribute(request,param,parameters.getParameter("image-height","")); + statement.setInt(position, parameters.getParameterAsInteger("image-height", + Integer.parseInt((String)settings.get("image-height","-1")))); + setRequestAttribute(request, + param, + parameters.getParameter("image-height", + (String) settings.get("image-height",""))); } break; } else if ("image-size".equals(typeName)) { @@ -610,8 +620,12 @@ file = (File) request.get(imageAttr); synchronized (this.files) { Parameters parameters = (Parameters) this.files.get(file); - statement.setInt(position, parameters.getParameterAsInteger("image-size", -1)); - setRequestAttribute(request,param,parameters.getParameter("image-size","")); + statement.setInt(position, parameters.getParameterAsInteger("image-size", + Integer.parseInt((String)settings.get("image-height","-1")))); + setRequestAttribute(request, + param, + parameters.getParameter("image-size", + (String) settings.get("image-size",""))); } break; } else if ("row-index".equals(typeName)) { 1.8 +5 -5 xml-cocoon2/src/org/apache/cocoon/acting/FormValidatorAction.java Index: FormValidatorAction.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/acting/FormValidatorAction.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- FormValidatorAction.java 2001/07/11 08:47:55 1.7 +++ FormValidatorAction.java 2001/07/23 15:50:10 1.8 @@ -1,4 +1,4 @@ -// $Id: FormValidatorAction.java,v 1.7 2001/07/11 08:47:55 haul Exp $ +// $Id: FormValidatorAction.java,v 1.8 2001/07/23 15:50:10 haul Exp $ package org.apache.cocoon.acting; import java.util.Collections; @@ -58,7 +58,7 @@ * * @author Martin Man <[EMAIL PROTECTED]> * @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a> - * @version CVS $Revision: 1.7 $ $Date: 2001/07/11 08:47:55 $ + * @version CVS $Revision: 1.8 $ $Date: 2001/07/23 15:50:10 $ */ public class FormValidatorAction extends AbstractValidatorAction { @@ -86,8 +86,8 @@ Configuration conf = this.getConfiguration ( parameters.getParameter ("descriptor", (String) this.settings.get("descriptor")), parameters.getParameterAsBoolean("reloadable", reloadable)); - String valstr = parameters.getParameter ("validate", ""); - String valsetstr = parameters.getParameter ("validate-set", ""); + String valstr = parameters.getParameter ("validate", (String) settings.get("validate","")); + String valsetstr = parameters.getParameter ("validate-set", (String) settings.get("validate-set","")); Configuration[] desc = conf.getChildren ("parameter"); Configuration[] csets = conf.getChildren ("constraint-set"); HashMap actionMap = new HashMap (); @@ -208,5 +208,5 @@ } } -// $Id: FormValidatorAction.java,v 1.7 2001/07/11 08:47:55 haul Exp $ +// $Id: FormValidatorAction.java,v 1.8 2001/07/23 15:50:10 haul Exp $ // vim: set et ts=4 sw=4: 1.2 +31 -7 xml-cocoon2/src/org/apache/cocoon/acting/HttpHeaderAction.java Index: HttpHeaderAction.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/acting/HttpHeaderAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- HttpHeaderAction.java 2001/06/14 04:30:36 1.1 +++ HttpHeaderAction.java 2001/07/23 15:50:10 1.2 @@ -10,8 +10,9 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.Iterator; import org.apache.avalon.framework.parameters.Parameters; +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.cocoon.Constants; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.Response; @@ -23,17 +24,40 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Donald Ball</a> * @version CVS $Revision: */ -public class HttpHeaderAction extends AbstractAction { +public class HttpHeaderAction extends AbstractConfigurableAction { + private static Object[] defaults = {}; + + public void configure(Configuration conf) throws ConfigurationException { + if (conf != null) { + String[] names = {}; + super.configure(conf); + defaults=(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); + Response response = (Response)objectModel.get(Constants.RESPONSE_OBJECT); - Iterator iterator = parameters.getParameterNames(); - while (iterator.hasNext()) { - String name = (String)iterator.next(); - response.setHeader(name,parameters.getParameter(name)); - results.put(name,parameters.getParameter(name)); + String[] names = parameters.getNames(); + + // parameters + for (int i=0; i<names.length; i++) { + isDone.put(names[i], dummy); + response.setHeader(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])); + } + } + return Collections.unmodifiableMap(results); } 1.4 +48 -10 xml-cocoon2/src/org/apache/cocoon/acting/SessionPropagatorAction.java Index: SessionPropagatorAction.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/acting/SessionPropagatorAction.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SessionPropagatorAction.java 2001/06/05 21:36:21 1.3 +++ SessionPropagatorAction.java 2001/07/23 15:50:10 1.4 @@ -1,4 +1,4 @@ -// $Id: SessionPropagatorAction.java,v 1.3 2001/06/05 21:36:21 dims Exp $ +// $Id: SessionPropagatorAction.java,v 1.4 2001/07/23 15:50:10 haul Exp $ package org.apache.cocoon.acting; import java.util.Collections; @@ -7,6 +7,8 @@ import java.util.Map; import org.apache.avalon.framework.logger.AbstractLoggable; import org.apache.avalon.framework.parameters.Parameters; +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.cocoon.Constants; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.Request; @@ -28,10 +30,21 @@ * </pre> * * @author Martin Man <[EMAIL PROTECTED]> - * @version CVS $Revision: 1.3 $ $Date: 2001/06/05 21:36:21 $ + * @version CVS $Revision: 1.4 $ $Date: 2001/07/23 15:50:10 $ */ -public class SessionPropagatorAction extends ComposerAction +public class SessionPropagatorAction extends AbstractConfigurableAction { + + private static Object[] defaults = {}; + + public void configure(Configuration conf) throws ConfigurationException { + if (conf != null) { + String[] names = {}; + super.configure(conf); + defaults=(settings.keySet()).toArray(); + }; + } + /** * Main invocation routine. */ @@ -41,6 +54,9 @@ objectModel.get (Constants.REQUEST_OBJECT); HashMap actionMap = new HashMap (); + HashMap isDone = new HashMap(); + Integer dummy = new Integer(1); + if (req == null) { getLogger ().debug ("SESSIONPROPAGATOR: no request object"); return null; @@ -54,20 +70,42 @@ } try { - Iterator keys = parameters.getParameterNames (); - while (keys.hasNext ()) { - String sessionParamName = (String) keys.next (); + + String[] names = parameters.getNames(); + + // parameters + for (int i=0; i<names.length; i++) { + String sessionParamName = names[i]; if (sessionParamName == null || - "".equals (sessionParamName.trim ())) + "".equals (sessionParamName.trim ())) return null; - String value = parameters.getParameter (sessionParamName, null); + isDone.put(sessionParamName, dummy); + String value = parameters.getParameter(sessionParamName); getLogger().debug ("SESSIONPROPAGATOR: propagating value " + value + " to session attribute " + sessionParamName); session.setAttribute (sessionParamName, value); actionMap.put (sessionParamName, value); - } + } + + // defaults, that are not overridden + for (int i=0; i<defaults.length; i++) { + if (! isDone.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); + getLogger().debug ("SESSIONPROPAGATOR: propagating value " + + value + + " to session attribute " + + sessionParamName); + session.setAttribute (sessionParamName, value); + actionMap.put (sessionParamName, value); + } + } getLogger().debug ("SESSIONPROPAGATOR: all params propagated " + "to session"); return Collections.unmodifiableMap (actionMap); @@ -78,6 +116,6 @@ } } -// $Id: SessionPropagatorAction.java,v 1.3 2001/06/05 21:36:21 dims Exp $ +// $Id: SessionPropagatorAction.java,v 1.4 2001/07/23 15:50:10 haul Exp $ // vim: set et ts=4 sw=4: 1.2 +3 -5 xml-cocoon2/src/org/apache/cocoon/acting/SessionStateAction.java Index: SessionStateAction.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/acting/SessionStateAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SessionStateAction.java 2001/07/11 09:50:03 1.1 +++ SessionStateAction.java 2001/07/23 15:50:10 1.2 @@ -69,8 +69,8 @@ * @see org.apache.cocoon.selection.SessionStateSelectorFactory * * @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a> - * @version CVS $Id: SessionStateAction.java,v 1.1 2001/07/11 09:50:03 haul Exp $ */ -public class SessionStateAction extends ComposerAction { + * @version CVS $Id: SessionStateAction.java,v 1.2 2001/07/23 15:50:10 haul Exp $ */ +public class SessionStateAction extends AbstractConfigurableAction { private static String componentName = "REZEPTE SessionStateAction"; protected String statekey = Constants.SESSION_STATE_ATTRIBUTE; @@ -79,10 +79,8 @@ protected int mylevel = 0; /** - * read settings from global section and store them for - * easier access to instance variables. + * Configures the Action. */ - public void configure(Configuration conf) throws ConfigurationException { super.configure(conf); 1.1 xml-cocoon2/src/org/apache/cocoon/acting/AbstractConfigurableAction.java Index: AbstractConfigurableAction.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.cocoon.acting; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.cocoon.util.HashMap; /** * AbstractConfigurableAction gives you the infrastructure for easily * deploying more Actions that take default parameters. * * @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a> * @version CVS $Revision: 1.1 $ $Date: 2001/07/23 15:50:10 $ */ public abstract class AbstractConfigurableAction extends AbstractAction { /** * Stores (global) configuration parameters as <code>key</code> / * <code>value</code> pairs. */ protected HashMap settings = null; /** * Configures the Action. * * Takes the children from the <code>Configuration</code> and stores them * them as key (configuration name) and value (configuration value) * in <code>settings</code>. * <br/> * This automates parsing of flat string-only configurations. * 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); } } } } 1.1 xml-cocoon2/src/org/apache/cocoon/acting/ConfigurableComposerAction.java Index: ConfigurableComposerAction.java =================================================================== /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ package org.apache.cocoon.acting; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.Composable; import org.apache.cocoon.Cocoon; /** * The <code>ComposerAction</code> will allow any <code>Action</code> * that extends this to access SitemapComponents. * * Basically a copy of {@link ComposerAction} that inherits from * {@link ConfigurableAction}. * * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a> * @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a> * @version CVS $Revision: 1.1 $ $Date: 2001/07/23 15:50:10 $ */ public abstract class ConfigurableComposerAction extends AbstractConfigurableAction implements Composable { /** The component manager instance */ protected ComponentManager manager; /** * Set the current <code>ComponentManager</code> instance used by this * <code>Composable</code>. */ public void compose(ComponentManager manager) throws ComponentException { this.manager=manager; } } ---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]