cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r291111 - in /cocoon: blocks/portal/trunk/java/org/apache/cocoon/portal/util/SessionMapWrapper.java trunk/src/java/org/apache/cocoon/acting/AbstractAction.java
Date Fri, 23 Sep 2005 12:33:03 GMT
Author: cziegeler
Date: Fri Sep 23 05:32:55 2005
New Revision: 291111

URL: http://svn.apache.org/viewcvs?rev=291111&view=rev
Log:
Add new session based map; remove legay code from AbstractAction

Added:
    cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/util/SessionMapWrapper.java 
 (with props)
Modified:
    cocoon/trunk/src/java/org/apache/cocoon/acting/AbstractAction.java

Added: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/util/SessionMapWrapper.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/util/SessionMapWrapper.java?rev=291111&view=auto
==============================================================================
--- cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/util/SessionMapWrapper.java (added)
+++ cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/util/SessionMapWrapper.java Fri
Sep 23 05:32:55 2005
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.util;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.avalon.framework.context.Context;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.Session;
+
+/**
+ * This is a wrapper for a {@link java.util.Map} storing the real map
+ * in a session attribute.
+ * The idea is to have a global map for all users that delegates at run
+ * time to a user specific map stored in a session.
+ *
+ * @version $Id$
+ */
+public class SessionMapWrapper implements Map {
+
+    protected final String attrName;
+    protected final Context context;
+
+    public SessionMapWrapper(Context context, String attrName) {
+        this.context = context;
+        this.attrName = attrName;
+    }
+
+    /**
+     * Get the real map for the current user.
+     */
+    protected Map getRealMap() {
+        final Request req = ContextHelper.getRequest(this.context);
+        final Session session = req.getSession(false);
+        if ( session != null ) {
+            final Map map = (Map)session.getAttribute(this.attrName);
+            if ( map != null ) {
+                return map;
+            }
+        }
+        return Collections.EMPTY_MAP;
+    }
+
+    /**
+     * @see java.util.Map#clear()
+     */
+    public void clear() {
+        this.getRealMap().clear();
+    }
+
+    /**
+     * @see java.util.Map#containsKey(java.lang.Object)
+     */
+    public boolean containsKey(Object key) {
+        return this.getRealMap().containsKey(key);
+    }
+
+    /**
+     * @see java.util.Map#containsValue(java.lang.Object)
+     */
+    public boolean containsValue(Object value) {
+        return this.getRealMap().containsValue(value);
+    }
+
+    /**
+     * @see java.util.Map#entrySet()
+     */
+    public Set entrySet() {
+        return this.getRealMap().entrySet();
+    }
+
+    /**
+     * @see java.util.Map#get(java.lang.Object)
+     */
+    public Object get(Object key) {
+        return this.getRealMap().get(key);
+    }
+
+    /**
+     * @see java.util.Map#isEmpty()
+     */
+    public boolean isEmpty() {
+        return this.getRealMap().isEmpty();
+    }
+
+    /**
+     * @see java.util.Map#keySet()
+     */
+    public Set keySet() {
+        return this.getRealMap().keySet();
+    }
+
+    /**
+     * @see java.util.Map#put(java.lang.Object, java.lang.Object)
+     */
+    public Object put(Object key, Object value) {
+        return this.getRealMap().put(key, value);
+    }
+
+    /**
+     * @see java.util.Map#putAll(java.util.Map)
+     */
+    public void putAll(Map t) {
+        this.getRealMap().putAll(t);
+    }
+
+    /**
+     * @see java.util.Map#remove(java.lang.Object)
+     */
+    public Object remove(Object key) {
+        return this.getRealMap().remove(key);
+    }
+
+    /**
+     * @see java.util.Map#size()
+     */
+    public int size() {
+        return this.getRealMap().size();
+    }
+
+    /**
+     * @see java.util.Map#values()
+     */
+    public Collection values() {
+        return this.getRealMap().values();
+    }
+}

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/util/SessionMapWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/portal/trunk/java/org/apache/cocoon/portal/util/SessionMapWrapper.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/src/java/org/apache/cocoon/acting/AbstractAction.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/acting/AbstractAction.java?rev=291111&r1=291110&r2=291111&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/acting/AbstractAction.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/acting/AbstractAction.java Fri Sep 23 05:32:55
2005
@@ -19,7 +19,6 @@
 
 import java.util.Collections;
 import java.util.Map;
-import java.util.TreeMap;
 
 /**
  * AbstractAction gives you the infrastructure for easily deploying more
@@ -27,15 +26,14 @@
  *
  * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  * @author <a href="mailto:haul@apache.org">Christian Haul</a>
- * @version CVS $Id: AbstractAction.java,v 1.3 2004/03/05 13:02:42 bdelacretaz Exp $
+ * @version CVS $Id$
  */
 public abstract class AbstractAction extends AbstractLogEnabled
     implements Action {
 
     /**
-     * Empty unmodifiable map. Replace with Collections.EMPTY_MAP when
-     * pre-jdk1.3 support is dropped.
+     * Empty unmodifiable map.
      */
-    protected static final Map EMPTY_MAP = Collections.unmodifiableMap(new TreeMap());
+    protected static final Map EMPTY_MAP = Collections.EMPTY_MAP;
 
 }



Mime
View raw message