diff --git a/core/src/main/java/org/apache/struts2/components/Set.java b/core/src/main/java/org/apache/struts2/components/Set.java
index 8cb1ca4617..cca990ea84 100644
--- a/core/src/main/java/org/apache/struts2/components/Set.java
+++ b/core/src/main/java/org/apache/struts2/components/Set.java
@@ -20,6 +20,7 @@
import java.io.Writer;
+import org.apache.struts2.dispatcher.DispatcherConstants;
import org.apache.struts2.views.annotations.StrutsTag;
import org.apache.struts2.views.annotations.StrutsTagAttribute;
@@ -53,16 +54,11 @@
*
*
*
- *
* - var* (String): The name of the new variable that is assigned the value of value
- *
* - value (Object): The value that is assigned to the variable named name
- *
* - scope (String): The scope in which to assign the variable. Can be application, session,
* request, page, or action. By default it is action.
- *
* - Note: With the action scope, the variable is also assigned to the page scope.
- *
*
*
*
@@ -107,16 +103,16 @@ public boolean end(Writer writer, String body) {
body="";
- if ("application".equalsIgnoreCase(scope)) {
+ if (DispatcherConstants.APPLICATION.equalsIgnoreCase(scope)) {
stack.setValue("#application['" + getVar() + "']", o);
- } else if ("session".equalsIgnoreCase(scope)) {
+ } else if (DispatcherConstants.SESSION.equalsIgnoreCase(scope)) {
stack.setValue("#session['" + getVar() + "']", o);
- } else if ("request".equalsIgnoreCase(scope)) {
+ } else if (DispatcherConstants.REQUEST.equalsIgnoreCase(scope)) {
stack.setValue("#request['" + getVar() + "']", o);
- } else if ("page".equalsIgnoreCase(scope)) {
+ } else if (DispatcherConstants.PAGE.equalsIgnoreCase(scope)) {
stack.setValue("#attr['" + getVar() + "']", o, false);
} else {
- // Default scope is action. Note: The action acope handling also adds the var to the page scope.
+ // Default scope is action. Note: The action scope handling also adds the var to the page scope.
stack.getContext().put(getVar(), o);
stack.setValue("#attr['" + getVar() + "']", o, false);
}
diff --git a/core/src/main/java/org/apache/struts2/util/AttributeMap.java b/core/src/main/java/org/apache/struts2/dispatcher/AttributeMap.java
similarity index 63%
rename from core/src/main/java/org/apache/struts2/util/AttributeMap.java
rename to core/src/main/java/org/apache/struts2/dispatcher/AttributeMap.java
index ea088b4af8..dbdc686bbd 100644
--- a/core/src/main/java/org/apache/struts2/util/AttributeMap.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/AttributeMap.java
@@ -16,14 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.struts2.util;
+package org.apache.struts2.dispatcher;
-import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.StrutsStatics;
import javax.servlet.jsp.PageContext;
+import java.util.AbstractMap;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
/**
@@ -38,17 +40,16 @@
* Session scope
* Application scope
*
- *
+ *
* A object is searched in the order above, starting from page and ending at application scope.
- *
*/
-public class AttributeMap implements Map {
+public class AttributeMap extends AbstractMap {
protected static final String UNSUPPORTED = "method makes no sense for a simplified map";
- Map context;
+ private final Map context;
- public AttributeMap(Map context) {
+ public AttributeMap(Map context) {
this.context = context;
}
@@ -73,18 +74,22 @@ public boolean containsValue(Object value) {
}
@Override
- public Set entrySet() {
- return Collections.EMPTY_SET;
+ public Set> entrySet() {
+ return Collections.unmodifiableSet(this.context.entrySet());
}
@Override
public Object get(Object key) {
+ if (key == null) {
+ return null;
+ }
+
PageContext pc = getPageContext();
if (pc == null) {
- Map request = (Map) context.get("request");
- Map session = (Map) context.get("session");
- Map application = (Map) context.get("application");
+ RequestMap request = (RequestMap) context.get(DispatcherConstants.REQUEST);
+ SessionMap session = (SessionMap) context.get(DispatcherConstants.SESSION);
+ ApplicationMap application = (ApplicationMap) context.get(DispatcherConstants.APPLICATION);
if ((request != null) && (request.get(key) != null)) {
return request.get(key);
@@ -94,26 +99,23 @@ public Object get(Object key) {
return application.get(key);
}
} else {
- try {
- return pc.findAttribute(key.toString());
- } catch (NullPointerException npe) {
- return null;
- }
+ return pc.findAttribute(key.toString());
}
return null;
}
@Override
- public Set keySet() {
- return Collections.EMPTY_SET;
+ public Set keySet() {
+ return Collections.unmodifiableSet(this.context.keySet());
}
@Override
- public Object put(Object key, Object value) {
+ public Object put(String key, Object value) {
PageContext pc = getPageContext();
if (pc != null) {
- pc.setAttribute(key.toString(), value);
+ pc.setAttribute(key, value);
+ return value;
}
return null;
@@ -135,21 +137,21 @@ public int size() {
}
@Override
- public Collection values() {
- return Collections.EMPTY_SET;
+ public Collection