cziegeler 2004/07/11 06:59:12
Modified: . status.xml
src/java/org/apache/cocoon/environment Request.java
src/java/org/apache/cocoon/environment/wrapper
RequestWrapper.java AbstractRequestWrapper.java
src/java/org/apache/cocoon/components/flow/javascript/fom
FOM_Cocoon.java
src/blocks/portal/java/org/apache/cocoon/environment/portlet
PortletRequest.java
src/java/org/apache/cocoon/environment/http HttpRequest.java
src/test/org/apache/cocoon/environment/mock MockRequest.java
src/java/org/apache/cocoon/environment/commandline
CommandLineRequest.java
Log:
Add scoped request attributes (global/request).
Revision Changes Path
1.391 +4 -1 cocoon-2.1/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/status.xml,v
retrieving revision 1.390
retrieving revision 1.391
diff -u -r1.390 -r1.391
--- status.xml 10 Jul 2004 09:06:18 -0000 1.390
+++ status.xml 11 Jul 2004 13:59:11 -0000 1.391
@@ -204,6 +204,9 @@
<changes>
<release version="@version@" date="@date@">
+ <action dev="CZ" type="add">
+ Add scoped request attributes (global/request).
+ </action>
<action dev="UH" type="add">
Enhanced JMS support by adding a JMSConnectionManager component to the
JMS block.
This component replaces the JMSConnection component which only
supported
1.8 +98 -10
cocoon-2.1/src/java/org/apache/cocoon/environment/Request.java
Index: Request.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/Request.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Request.java 7 Jul 2004 07:58:49 -0000 1.7
+++ Request.java 11 Jul 2004 13:59:12 -0000 1.8
@@ -23,6 +23,17 @@
/**
* Defines an interface to provide client request information .
*
+ * A client can bind an object attribute into a <code>Request</code> by name.
+ * The <code>Request</code> interface defines two scopes for storing objects:
+ * <ul>
+ * <li><code>GLOBAL_SCOPE</code>
+ * <li><code>REQUEST_SCOPE</code>
+ * </ul>
+ * All objects stored in the request using the <code>GLOBAL_SCOPE</code>
+ * are available to all sub requests and the main request associatiated
+ * Objects stored in the request using the <code>REQUEST_SCOPE</code> are
+ * only available for the current (sub) request.
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
@@ -33,6 +44,17 @@
public interface Request {
/**
+ * This constant defines an request wide scope for the request attribute.
+ */
+ public static final int GLOBAL_SCOPE = 1;
+
+ /**
+ * This constant defines the scope of the request attribute to be
+ * private to the current (sub) request.
+ */
+ public static final int REQUEST_SCOPE = 2;
+
+ /**
*
* Returns the value of the named attribute as an <code>Object</code>,
* or <code>null</code> if no attribute of the given name exists.
@@ -49,8 +71,9 @@
/**
*
- * Returns the value of the named attribute as an <code>Object</code>,
- * or <code>null</code> if no attribute of the given name exists.
+ * Returns the value of the named attribute from the
<code>GLOBAL_SCOPE</code>
+ * as an <code>Object</code>, or <code>null</code> if no attribute
+ * of the given name exists.
*
* @param name a <code>String</code> specifying the name of
* the attribute
@@ -60,12 +83,11 @@
* the attribute does not exist
*
*/
-
Object getAttribute(String name);
/**
* Returns an <code>Enumeration</code> containing the
- * names of the attributes available to this request.
+ * names of the attributes available to this request in the
<code>GLOBAL_SCOPE</code>.
* This method returns an empty <code>Enumeration</code>
* if the request has no attributes available to it.
*
@@ -75,12 +97,11 @@
* of the request's attributes
*
*/
-
Enumeration getAttributeNames();
/**
*
- * Stores an attribute in this request.
+ * Stores an attribute in this request in the <code>GLOBAL_SCOPE</code>.
* Attributes are reset between requests.
*
* <p>Attribute names should follow the same conventions as
@@ -95,12 +116,12 @@
* @param o the <code>Object</code> to be
stored
*
*/
-
void setAttribute(String name, Object o);
/**
*
- * Removes an attribute from this request. This method is not
+ * Removes an attribute from this request in the
<code>GLOBAL_SCOPE</code>.
+ * This method is not
* generally needed as attributes only persist as long as the request
* is being handled.
*
@@ -114,9 +135,76 @@
* the name of the attribute to
remove
*
*/
-
void removeAttribute(String name);
+ /**
+ * Returns the value of the named attribute from the scope
+ * as an <code>Object</code>, or <code>null</code> if no attribute
+ * of the given name exists.
+ *
+ * @param name a <code>String</code> specifying the name of
+ * the attribute
+ * @param scope scope (global or request) of the attribute
+ *
+ * @return an <code>Object</code> containing the value
+ * of the attribute, or <code>null</code> if
+ * the attribute does not exist
+ *
+ */
+ Object getAttribute(String name, int scope);
+
+ /**
+ * Returns an <code>Enumeration</code> containing the
+ * names of the attributes available to this request in the scope.
+ * This method returns an empty <code>Enumeration</code>
+ * if the request has no attributes available to it.
+ *
+ * @param scope scope (global or request) of the attribute
+ *
+ * @return an <code>Enumeration</code> of strings
+ * containing the names
+ * of the request's attributes
+ *
+ */
+ Enumeration getAttributeNames(int scope);
+
+ /**
+ *
+ * Stores an attribute in this request in the scope.
+ * Attributes are reset between requests.
+ *
+ * <p>Attribute names should follow the same conventions as
+ * package names. Names beginning with <code>java.*</code>,
+ * <code>javax.*</code>, and <code>com.sun.*</code>, are
+ * reserved for use by Sun Microsystems.
+ *
+ *
+ * @param name a <code>String</code> specifying
+ * the name of the attribute
+ * @param o the <code>Object</code> to be
stored
+ * @param scope scope (global or request) of the attribute
+ *
+ */
+ void setAttribute(String name, Object o, int scope);
+
+ /**
+ * Removes an attribute from this request in the scope.
+ * This method is not
+ * generally needed as attributes only persist as long as the request
+ * is being handled.
+ *
+ * <p>Attribute names should follow the same conventions as
+ * package names. Names beginning with <code>java.*</code>,
+ * <code>javax.*</code>, and <code>com.sun.*</code>, are
+ * reserved for use by Sun Microsystems.
+ *
+ *
+ * @param name a <code>String</code> specifying
+ * the name of the attribute to
remove
+ * @param scope scope (global or request) of the attribute
+ *
+ */
+ void removeAttribute(String name, int scope);
/**
*
1.9 +50 -7
cocoon-2.1/src/java/org/apache/cocoon/environment/wrapper/RequestWrapper.java
Index: RequestWrapper.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/wrapper/RequestWrapper.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- RequestWrapper.java 7 Jul 2004 07:58:49 -0000 1.8
+++ RequestWrapper.java 11 Jul 2004 13:59:12 -0000 1.9
@@ -16,12 +16,15 @@
package org.apache.cocoon.environment.wrapper;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Map;
import java.util.Set;
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.Request;
+import org.apache.commons.collections.IteratorUtils;
/**
@@ -32,12 +35,6 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @version CVS $Id$
*/
-/**
- * @author CZiegeler
- *
- * To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
public final class RequestWrapper extends AbstractRequestWrapper {
/** The query string */
@@ -55,6 +52,8 @@
/** The request uri */
private String requestURI;
+ private final Map requestAttributes = new HashMap();
+
/**
* Constructor
*/
@@ -184,5 +183,49 @@
buffer.append(prefix);
buffer.append(uri);
this.requestURI = buffer.toString();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#getAttribute(java.lang.String, int)
+ */
+ public Object getAttribute(String name, int scope) {
+ if ( scope == Request.GLOBAL_SCOPE ) {
+ return super.getAttribute(name, scope);
+ } else {
+ return this.requestAttributes.get( name );
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Request#getAttributeNames(int)
+ */
+ public Enumeration getAttributeNames(int scope) {
+ if ( scope == Request.GLOBAL_SCOPE ) {
+ return super.getAttributeNames(scope);
+ } else {
+ return
IteratorUtils.asEnumeration(this.requestAttributes.keySet().iterator());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#removeAttribute(java.lang.String, int)
+ */
+ public void removeAttribute(String name, int scope) {
+ if ( scope == Request.GLOBAL_SCOPE ) {
+ super.removeAttribute(name, scope);
+ } else {
+ this.requestAttributes.remove( name );
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#setAttribute(java.lang.String,
java.lang.Object, int)
+ */
+ public void setAttribute(String name, Object o, int scope) {
+ if ( scope == Request.GLOBAL_SCOPE ) {
+ super.setAttribute(name, o, scope);
+ } else {
+ this.requestAttributes.put( name, o );
+ }
}
}
1.2 +29 -1
cocoon-2.1/src/java/org/apache/cocoon/environment/wrapper/AbstractRequestWrapper.java
Index: AbstractRequestWrapper.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/wrapper/AbstractRequestWrapper.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractRequestWrapper.java 7 Jul 2004 07:58:49 -0000 1.1
+++ AbstractRequestWrapper.java 11 Jul 2004 13:59:12 -0000 1.2
@@ -368,4 +368,32 @@
public String getAuthType() {
return this.req.getAuthType();
}
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#getAttribute(java.lang.String, int)
+ */
+ public Object getAttribute(String name, int scope) {
+ return this.req.getAttribute(name, scope);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Request#getAttributeNames(int)
+ */
+ public Enumeration getAttributeNames(int scope) {
+ return this.req.getAttributeNames(scope);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#removeAttribute(java.lang.String, int)
+ */
+ public void removeAttribute(String name, int scope) {
+ this.req.removeAttribute(name,scope);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#setAttribute(java.lang.String,
java.lang.Object, int)
+ */
+ public void setAttribute(String name, Object o, int scope) {
+ this.req.setAttribute(name, o, scope);
+ }
}
1.38 +28 -1
cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
Index: FOM_Cocoon.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- FOM_Cocoon.java 7 Jul 2004 07:58:49 -0000 1.37
+++ FOM_Cocoon.java 11 Jul 2004 13:59:12 -0000 1.38
@@ -794,6 +794,33 @@
return request.isRequestedSessionIdFromURL();
}
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#getAttribute(java.lang.String, int)
+ */
+ public Object getAttribute(String name, int scope) {
+ return this.request.getAttribute(name, scope);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Request#getAttributeNames(int)
+ */
+ public Enumeration getAttributeNames(int scope) {
+ return this.request.getAttributeNames(scope);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#removeAttribute(java.lang.String, int)
+ */
+ public void removeAttribute(String name, int scope) {
+ this.request.removeAttribute(name, scope);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#setAttribute(java.lang.String,
java.lang.Object, int)
+ */
+ public void setAttribute(String name, Object o, int scope) {
+ this.request.setAttribute( name, o, scope );
+ }
}
public static class FOM_Cookie
1.5 +77 -20
cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletRequest.java
Index: PortletRequest.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletRequest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- PortletRequest.java 7 Jul 2004 07:58:49 -0000 1.4
+++ PortletRequest.java 11 Jul 2004 13:59:12 -0000 1.5
@@ -19,6 +19,7 @@
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.portlet.multipart.MultipartActionRequest;
+import org.apache.commons.collections.IteratorUtils;
import org.apache.avalon.framework.CascadingRuntimeException;
@@ -69,7 +70,8 @@
private Map wrappedCookieMap;
protected String portletRequestURI;
-
+ private final Map attributes = new HashMap();
+
/**
* Creates a PortletRequest based on a real PortletRequest object
*/
@@ -311,16 +313,6 @@
return true;
}
- /* The ServletRequest interface methods */
-
- public Object getAttribute(String name) {
- return this.request.getAttribute(name);
- }
-
- public Enumeration getAttributeNames() {
- return this.request.getAttributeNames();
- }
-
public String getCharacterEncoding() {
return this.form_encoding;
}
@@ -418,14 +410,6 @@
return null;
}
- public void setAttribute(String name, Object o) {
- this.request.setAttribute(name, o);
- }
-
- public void removeAttribute(String name) {
- this.request.removeAttribute(name);
- }
-
public Locale getLocale() {
return this.request.getLocale();
}
@@ -504,4 +488,77 @@
public boolean isWindowStateAllowed(WindowState state) {
return this.request.isWindowStateAllowed(state);
}
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#getAttribute(java.lang.String)
+ */
+ public Object getAttribute(String name) {
+ return this.getAttribute(name, Request.GLOBAL_SCOPE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Request#getAttributeNames()
+ */
+ public Enumeration getAttributeNames() {
+ return this.getAttributeNames(Request.GLOBAL_SCOPE);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#setAttribute(java.lang.String,
java.lang.Object)
+ */
+ public void setAttribute(String name, Object value) {
+ this.setAttribute(name, value, Request.GLOBAL_SCOPE);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#removeAttribute(java.lang.String)
+ */
+ public void removeAttribute(String name) {
+ this.removeAttribute(name, Request.GLOBAL_SCOPE);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#getAttribute(java.lang.String, int)
+ */
+ public Object getAttribute(String name, int scope) {
+ if ( scope == Request.REQUEST_SCOPE ) {
+ return this.attributes.get(name);
+ } else {
+ return this.request.getAttribute(name);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Request#getAttributeNames(int)
+ */
+ public Enumeration getAttributeNames(int scope) {
+ if ( scope == Request.REQUEST_SCOPE ) {
+ return
IteratorUtils.asEnumeration(this.attributes.keySet().iterator());
+ } else {
+ return this.request.getAttributeNames();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#setAttribute(java.lang.String,
java.lang.Object, int)
+ */
+ public void setAttribute(String name, Object value, int scope) {
+ if ( scope == Request.REQUEST_SCOPE ) {
+ this.attributes.put(name, value);
+ } else {
+ this.request.setAttribute(name, value);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#removeAttribute(java.lang.String, int)
+ */
+ public void removeAttribute(String name, int scope) {
+ if ( scope == Request.REQUEST_SCOPE ) {
+ this.attributes.remove(name);
+ } else {
+ this.request.removeAttribute(name);
+ }
+ }
+
}
1.10 +71 -12
cocoon-2.1/src/java/org/apache/cocoon/environment/http/HttpRequest.java
Index: HttpRequest.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/http/HttpRequest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- HttpRequest.java 7 Jul 2004 07:58:50 -0000 1.9
+++ HttpRequest.java 11 Jul 2004 13:59:12 -0000 1.10
@@ -33,6 +33,7 @@
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.servlet.multipart.MultipartHttpServletRequest;
+import org.apache.commons.collections.IteratorUtils;
/**
* Implements the [EMAIL PROTECTED] org.apache.cocoon.environment.Request}
interface
@@ -59,6 +60,8 @@
/** The current session */
private HttpSession session;
+ private final Map attributes = new HashMap();
+
/**
* Creates a HttpRequest based on a real HttpServletRequest object
*/
@@ -270,12 +273,76 @@
/* The ServletRequest interface methods */
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#getAttribute(java.lang.String)
+ */
public Object getAttribute(String name) {
- return this.req.getAttribute(name);
+ return this.getAttribute(name, Request.GLOBAL_SCOPE);
}
-
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Request#getAttributeNames()
+ */
public Enumeration getAttributeNames() {
- return this.req.getAttributeNames();
+ return this.getAttributeNames(Request.GLOBAL_SCOPE);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#setAttribute(java.lang.String,
java.lang.Object)
+ */
+ public void setAttribute(String name, Object value) {
+ this.setAttribute(name, value, Request.GLOBAL_SCOPE);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#removeAttribute(java.lang.String)
+ */
+ public void removeAttribute(String name) {
+ this.removeAttribute(name, Request.GLOBAL_SCOPE);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#getAttribute(java.lang.String, int)
+ */
+ public Object getAttribute(String name, int scope) {
+ if ( scope == Request.REQUEST_SCOPE ) {
+ return this.attributes.get(name);
+ } else {
+ return this.req.getAttribute(name);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Request#getAttributeNames(int)
+ */
+ public Enumeration getAttributeNames(int scope) {
+ if ( scope == Request.REQUEST_SCOPE ) {
+ return
IteratorUtils.asEnumeration(this.attributes.keySet().iterator());
+ } else {
+ return this.req.getAttributeNames();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#setAttribute(java.lang.String,
java.lang.Object, int)
+ */
+ public void setAttribute(String name, Object value, int scope) {
+ if ( scope == Request.REQUEST_SCOPE ) {
+ this.attributes.put(name, value);
+ } else {
+ this.req.setAttribute(name, value);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#removeAttribute(java.lang.String, int)
+ */
+ public void removeAttribute(String name, int scope) {
+ if ( scope == Request.REQUEST_SCOPE ) {
+ this.attributes.remove(name);
+ } else {
+ this.req.removeAttribute(name);
+ }
}
public String getCharacterEncoding() {
@@ -373,14 +440,6 @@
public String getRemoteHost() {
return this.req.getRemoteHost();
- }
-
- public void setAttribute(String name, Object o) {
- this.req.setAttribute(name, o);
- }
-
- public void removeAttribute(String name) {
- this.req.removeAttribute(name);
}
public Locale getLocale() {
1.13 +76 -20
cocoon-2.1/src/test/org/apache/cocoon/environment/mock/MockRequest.java
Index: MockRequest.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/test/org/apache/cocoon/environment/mock/MockRequest.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- MockRequest.java 7 Jul 2004 07:58:50 -0000 1.12
+++ MockRequest.java 11 Jul 2004 13:59:12 -0000 1.13
@@ -35,6 +35,7 @@
public class MockRequest implements Request {
private Hashtable attributes = new Hashtable();
+ private Hashtable globalAttributes = new Hashtable();
private String scheme;
private String protocol = "HTTP/1.1";
private String requestURI;
@@ -69,26 +70,6 @@
return getAttribute(name);
}
- public Object getAttribute(String name) {
- return attributes.get(name);
- }
-
- public Enumeration getAttributeNames() {
- return attributes.keys();
- }
-
- public void setAttribute(String name, Object o) {
- if (o == null) {
- attributes.remove(name);
- } else {
- attributes.put(name, o);
- }
- }
-
- public void removeAttribute(String name) {
- attributes.remove(name);
- }
-
public String getAuthType() {
return authType;
}
@@ -314,6 +295,7 @@
}
public void reset() {
attributes.clear();
+ globalAttributes.clear();
scheme = null;
protocol = "HTTP/1.1";
requestURI = null;
@@ -356,4 +338,78 @@
public void setIsRequestedSessionIdFromCooki( boolean
isRequestedSessionIdFromCookie ) {
this.isRequestedSessionIdFromCookie = isRequestedSessionIdFromCookie;
}
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#getAttribute(java.lang.String)
+ */
+ public Object getAttribute(String name) {
+ return this.getAttribute(name, Request.GLOBAL_SCOPE);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Request#getAttributeNames()
+ */
+ public Enumeration getAttributeNames() {
+ return this.getAttributeNames(Request.GLOBAL_SCOPE);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#setAttribute(java.lang.String,
java.lang.Object)
+ */
+ public void setAttribute(String name, Object value) {
+ this.setAttribute(name, value, Request.GLOBAL_SCOPE);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#removeAttribute(java.lang.String)
+ */
+ public void removeAttribute(String name) {
+ this.removeAttribute(name, Request.GLOBAL_SCOPE);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#getAttribute(java.lang.String, int)
+ */
+ public Object getAttribute(String name, int scope) {
+ if ( scope == Request.REQUEST_SCOPE ) {
+ return this.attributes.get(name);
+ } else {
+ return this.globalAttributes.get(name);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Request#getAttributeNames(int)
+ */
+ public Enumeration getAttributeNames(int scope) {
+ if ( scope == Request.REQUEST_SCOPE ) {
+ return this.attributes.keys();
+ } else {
+ return this.globalAttributes.keys();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#setAttribute(java.lang.String,
java.lang.Object, int)
+ */
+ public void setAttribute(String name, Object value, int scope) {
+ if ( scope == Request.REQUEST_SCOPE ) {
+ this.attributes.put(name, value);
+ } else {
+ this.globalAttributes.put(name, value);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#removeAttribute(java.lang.String, int)
+ */
+ public void removeAttribute(String name, int scope) {
+ if ( scope == Request.REQUEST_SCOPE ) {
+ this.attributes.remove(name);
+ } else {
+ this.globalAttributes.remove(name);
+ }
+ }
+
+
}
1.11 +71 -23
cocoon-2.1/src/java/org/apache/cocoon/environment/commandline/CommandLineRequest.java
Index: CommandLineRequest.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/commandline/CommandLineRequest.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- CommandLineRequest.java 7 Jul 2004 07:58:50 -0000 1.10
+++ CommandLineRequest.java 11 Jul 2004 13:59:12 -0000 1.11
@@ -18,7 +18,6 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
@@ -27,6 +26,7 @@
import org.apache.cocoon.environment.Environment;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
+import org.apache.commons.collections.IteratorUtils;
/**
* Creates a specific servlet request simulation from command line usage.
@@ -42,19 +42,6 @@
*/
public class CommandLineRequest implements Request {
- private class IteratorWrapper implements Enumeration {
- private Iterator iterator;
- public IteratorWrapper(Iterator i) {
- this.iterator = i;
- }
- public boolean hasMoreElements() {
- return iterator.hasNext();
- }
- public Object nextElement() {
- return iterator.next();
- }
- }
-
private class EmptyEnumeration implements Enumeration {
public boolean hasMoreElements() {
return false;
@@ -68,10 +55,11 @@
private String contextPath;
private String servletPath;
private String pathInfo;
+ private Map globalAttributes;
private Map attributes;
private Map parameters;
private Map headers;
- private String characterEncoding = null;
+ private String characterEncoding;
public CommandLineRequest(Environment env,
String contextPath,
@@ -108,7 +96,8 @@
this.contextPath = contextPath;
this.servletPath = servletPath;
this.pathInfo = pathInfo;
- this.attributes = (attributes == null ? new HashMap() : attributes);
+ this.globalAttributes = (attributes == null ? new HashMap() :
attributes);
+ this.attributes = new HashMap();
this.parameters = parameters;
this.headers = headers;
}
@@ -140,17 +129,76 @@
public String getQueryString() { return null; } // use parameters instead
public String getPathTranslated() { return null; } // FIXME (SM) this is
legal but should we do something more?
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#getAttribute(java.lang.String)
+ */
public Object getAttribute(String name) {
- return this.attributes.get(name);
+ return this.getAttribute(name, Request.GLOBAL_SCOPE);
}
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Request#getAttributeNames()
+ */
public Enumeration getAttributeNames() {
- return new IteratorWrapper(this.attributes.keySet().iterator());
+ return this.getAttributeNames(Request.GLOBAL_SCOPE);
}
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#setAttribute(java.lang.String,
java.lang.Object)
+ */
public void setAttribute(String name, Object value) {
- this.attributes.put(name, value);
+ this.setAttribute(name, value, Request.GLOBAL_SCOPE);
}
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#removeAttribute(java.lang.String)
+ */
public void removeAttribute(String name) {
- this.attributes.remove(name);
+ this.removeAttribute(name, Request.GLOBAL_SCOPE);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#getAttribute(java.lang.String, int)
+ */
+ public Object getAttribute(String name, int scope) {
+ if ( scope == Request.REQUEST_SCOPE ) {
+ return this.attributes.get(name);
+ } else {
+ return this.globalAttributes.get(name);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.environment.Request#getAttributeNames(int)
+ */
+ public Enumeration getAttributeNames(int scope) {
+ if ( scope == Request.REQUEST_SCOPE ) {
+ return
IteratorUtils.asEnumeration(this.attributes.keySet().iterator());
+ } else {
+ return
IteratorUtils.asEnumeration(this.globalAttributes.keySet().iterator());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#setAttribute(java.lang.String,
java.lang.Object, int)
+ */
+ public void setAttribute(String name, Object value, int scope) {
+ if ( scope == Request.REQUEST_SCOPE ) {
+ this.attributes.put(name, value);
+ } else {
+ this.globalAttributes.put(name, value);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.environment.Request#removeAttribute(java.lang.String, int)
+ */
+ public void removeAttribute(String name, int scope) {
+ if ( scope == Request.REQUEST_SCOPE ) {
+ this.attributes.remove(name);
+ } else {
+ this.globalAttributes.remove(name);
+ }
}
public String getParameter(String name) {
@@ -173,7 +221,7 @@
}
public Enumeration getParameterNames() {
- return (this.parameters != null) ? new
IteratorWrapper(this.parameters.keySet().iterator()) : null;
+ return (this.parameters != null) ?
IteratorUtils.asEnumeration(this.parameters.keySet().iterator()) : null;
}
public String[] getParameterValues(String name) {
@@ -207,7 +255,7 @@
public Enumeration getHeaderNames() {
if (headers != null) {
- return new IteratorWrapper(headers.keySet().iterator());
+ return IteratorUtils.asEnumeration(headers.keySet().iterator());
} else {
return new EmptyEnumeration();
}