mirror of
https://github.com/apache/struts.git
synced 2026-08-06 15:17:00 +00:00
WW-5326 refactor(tiles): parameterize tiles OGNL accessors with StrutsContext
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,8 +18,8 @@
|
||||
*/
|
||||
package org.apache.tiles.ognl;
|
||||
|
||||
import ognl.OgnlContext;
|
||||
import ognl.PropertyAccessor;
|
||||
import org.apache.struts2.ognl.StrutsContext;
|
||||
import org.apache.tiles.request.Request;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -27,10 +27,10 @@ import java.util.Map;
|
||||
/**
|
||||
* Accesses attributes in any scope.
|
||||
*/
|
||||
public class AnyScopePropertyAccessor implements PropertyAccessor {
|
||||
public class AnyScopePropertyAccessor implements PropertyAccessor<StrutsContext> {
|
||||
|
||||
@Override
|
||||
public Object getProperty(OgnlContext context, Object target, Object name) {
|
||||
public Object getProperty(StrutsContext context, Object target, Object name) {
|
||||
Request request = (Request) target;
|
||||
String attributeName = (String) name;
|
||||
for (String scopeName : request.getAvailableScopes()) {
|
||||
@@ -43,7 +43,7 @@ public class AnyScopePropertyAccessor implements PropertyAccessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceAccessor(OgnlContext context, Object target, Object index) {
|
||||
public String getSourceAccessor(StrutsContext context, Object target, Object index) {
|
||||
Request request = (Request) target;
|
||||
String attributeName = (String) index;
|
||||
for (String scopeName : request.getAvailableScopes()) {
|
||||
@@ -56,7 +56,7 @@ public class AnyScopePropertyAccessor implements PropertyAccessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceSetter(OgnlContext context, Object target, Object index) {
|
||||
public String getSourceSetter(StrutsContext context, Object target, Object index) {
|
||||
Request request = (Request) target;
|
||||
String attributeName = (String) index;
|
||||
String[] availableScopes = request.getAvailableScopes().toArray(new String[0]);
|
||||
@@ -70,7 +70,7 @@ public class AnyScopePropertyAccessor implements PropertyAccessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperty(OgnlContext context, Object target, Object name, Object value) {
|
||||
public void setProperty(StrutsContext context, Object target, Object name, Object value) {
|
||||
Request request = (Request) target;
|
||||
String attributeName = (String) name;
|
||||
String[] availableScopes = request.getAvailableScopes().toArray(new String[0]);
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
*/
|
||||
package org.apache.tiles.ognl;
|
||||
|
||||
import ognl.OgnlContext;
|
||||
import ognl.OgnlException;
|
||||
import ognl.PropertyAccessor;
|
||||
import org.apache.struts2.ognl.StrutsContext;
|
||||
|
||||
/**
|
||||
* Uses a {@link PropertyAccessorDelegateFactory} to delegate the methods to
|
||||
@@ -29,7 +29,7 @@ import ognl.PropertyAccessor;
|
||||
* @param <T> The type of the accessed root object.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public class DelegatePropertyAccessor<T> implements PropertyAccessor {
|
||||
public class DelegatePropertyAccessor<T> implements PropertyAccessor<StrutsContext> {
|
||||
|
||||
/**
|
||||
* The property accessor factory.
|
||||
@@ -52,7 +52,7 @@ public class DelegatePropertyAccessor<T> implements PropertyAccessor {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getProperty(OgnlContext context, Object target, Object name) throws OgnlException {
|
||||
public Object getProperty(StrutsContext context, Object target, Object name) throws OgnlException {
|
||||
return factory.getPropertyAccessor((String) name, (T) target).getProperty(context, target, name);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class DelegatePropertyAccessor<T> implements PropertyAccessor {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setProperty(OgnlContext context, Object target, Object name, Object value) throws OgnlException {
|
||||
public void setProperty(StrutsContext context, Object target, Object name, Object value) throws OgnlException {
|
||||
factory.getPropertyAccessor((String) name, (T) target).setProperty(context, target, name, value);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class DelegatePropertyAccessor<T> implements PropertyAccessor {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getSourceAccessor(OgnlContext context, Object target, Object index) {
|
||||
public String getSourceAccessor(StrutsContext context, Object target, Object index) {
|
||||
return factory.getPropertyAccessor((String) index, (T) target).getSourceAccessor(context, target, index);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class DelegatePropertyAccessor<T> implements PropertyAccessor {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getSourceSetter(OgnlContext context, Object target, Object index) {
|
||||
public String getSourceSetter(StrutsContext context, Object target, Object index) {
|
||||
return factory.getPropertyAccessor((String) index, (T) target).getSourceSetter(context, target, index);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -18,9 +18,9 @@
|
||||
*/
|
||||
package org.apache.tiles.ognl;
|
||||
|
||||
import ognl.OgnlContext;
|
||||
import ognl.OgnlException;
|
||||
import ognl.PropertyAccessor;
|
||||
import org.apache.struts2.ognl.StrutsContext;
|
||||
|
||||
/**
|
||||
* Uses a {@link PropertyAccessor} as a delegate, but passing a nested object as
|
||||
@@ -29,7 +29,7 @@ import ognl.PropertyAccessor;
|
||||
* @param <T> The root object type from which the target object will be extracted.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public class NestedObjectDelegatePropertyAccessor<T> implements PropertyAccessor {
|
||||
public class NestedObjectDelegatePropertyAccessor<T> implements PropertyAccessor<StrutsContext> {
|
||||
|
||||
/**
|
||||
* The extractor of the nested object.
|
||||
@@ -43,7 +43,7 @@ public class NestedObjectDelegatePropertyAccessor<T> implements PropertyAccessor
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
private final PropertyAccessor propertyAccessor;
|
||||
private final PropertyAccessor<StrutsContext> propertyAccessor;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -52,7 +52,7 @@ public class NestedObjectDelegatePropertyAccessor<T> implements PropertyAccessor
|
||||
* @param propertyAccessor The delegated property accessor.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public NestedObjectDelegatePropertyAccessor(NestedObjectExtractor<T> nestedObjectExtractor, PropertyAccessor propertyAccessor) {
|
||||
public NestedObjectDelegatePropertyAccessor(NestedObjectExtractor<T> nestedObjectExtractor, PropertyAccessor<StrutsContext> propertyAccessor) {
|
||||
this.nestedObjectExtractor = nestedObjectExtractor;
|
||||
this.propertyAccessor = propertyAccessor;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public class NestedObjectDelegatePropertyAccessor<T> implements PropertyAccessor
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getProperty(OgnlContext context, Object target, Object name) throws OgnlException {
|
||||
public Object getProperty(StrutsContext context, Object target, Object name) throws OgnlException {
|
||||
return propertyAccessor.getProperty(context, nestedObjectExtractor.getNestedObject((T) target), name);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class NestedObjectDelegatePropertyAccessor<T> implements PropertyAccessor
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setProperty(OgnlContext context, Object target, Object name, Object value) throws OgnlException {
|
||||
public void setProperty(StrutsContext context, Object target, Object name, Object value) throws OgnlException {
|
||||
propertyAccessor.setProperty(context, nestedObjectExtractor.getNestedObject((T) target), name, value);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class NestedObjectDelegatePropertyAccessor<T> implements PropertyAccessor
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getSourceAccessor(OgnlContext context, Object target, Object index) {
|
||||
public String getSourceAccessor(StrutsContext context, Object target, Object index) {
|
||||
return propertyAccessor.getSourceAccessor(context, nestedObjectExtractor.getNestedObject((T) target), index);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class NestedObjectDelegatePropertyAccessor<T> implements PropertyAccessor
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getSourceSetter(OgnlContext context, Object target, Object index) {
|
||||
public String getSourceSetter(StrutsContext context, Object target, Object index) {
|
||||
return propertyAccessor.getSourceSetter(context, nestedObjectExtractor.getNestedObject((T) target), index);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -20,6 +20,7 @@
|
||||
package org.apache.tiles.ognl;
|
||||
|
||||
import ognl.PropertyAccessor;
|
||||
import org.apache.struts2.ognl.StrutsContext;
|
||||
|
||||
/**
|
||||
* Decides a {@link PropertyAccessor} depending on the property name and the
|
||||
@@ -39,5 +40,5 @@ public interface PropertyAccessorDelegateFactory<T> {
|
||||
* @return The appropriate property accessor.
|
||||
* @since 2.2.0
|
||||
*/
|
||||
PropertyAccessor getPropertyAccessor(String propertyName, T obj);
|
||||
PropertyAccessor<StrutsContext> getPropertyAccessor(String propertyName, T obj);
|
||||
}
|
||||
|
||||
@@ -18,14 +18,14 @@
|
||||
*/
|
||||
package org.apache.tiles.ognl;
|
||||
|
||||
import ognl.OgnlContext;
|
||||
import ognl.PropertyAccessor;
|
||||
import org.apache.struts2.ognl.StrutsContext;
|
||||
import org.apache.tiles.request.Request;
|
||||
|
||||
/**
|
||||
* Accesses a scope.
|
||||
*/
|
||||
public class ScopePropertyAccessor implements PropertyAccessor {
|
||||
public class ScopePropertyAccessor implements PropertyAccessor<StrutsContext> {
|
||||
|
||||
/**
|
||||
* The length of the scope suffix: "Scope".
|
||||
@@ -33,7 +33,7 @@ public class ScopePropertyAccessor implements PropertyAccessor {
|
||||
static final int SCOPE_SUFFIX_LENGTH = 5;
|
||||
|
||||
@Override
|
||||
public Object getProperty(OgnlContext context, Object target, Object name) {
|
||||
public Object getProperty(StrutsContext context, Object target, Object name) {
|
||||
Request request = (Request) target;
|
||||
String scope = (String) name;
|
||||
if (scope.endsWith("Scope")) {
|
||||
@@ -44,7 +44,7 @@ public class ScopePropertyAccessor implements PropertyAccessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceAccessor(OgnlContext context, Object target, Object index) {
|
||||
public String getSourceAccessor(StrutsContext context, Object target, Object index) {
|
||||
String scope = (String) index;
|
||||
if (scope.endsWith("Scope")) {
|
||||
String scopeName = scope.substring(0, scope.length() - SCOPE_SUFFIX_LENGTH);
|
||||
@@ -54,12 +54,12 @@ public class ScopePropertyAccessor implements PropertyAccessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceSetter(OgnlContext context, Object target, Object index) {
|
||||
public String getSourceSetter(StrutsContext context, Object target, Object index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperty(OgnlContext context, Object target, Object name, Object value) {
|
||||
public void setProperty(StrutsContext context, Object target, Object name, Object value) {
|
||||
// Does nothing.
|
||||
}
|
||||
|
||||
|
||||
+11
-10
@@ -19,6 +19,7 @@
|
||||
package org.apache.tiles.ognl;
|
||||
|
||||
import ognl.PropertyAccessor;
|
||||
import org.apache.struts2.ognl.StrutsContext;
|
||||
import org.apache.tiles.core.util.CombinedBeanInfo;
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.Request;
|
||||
@@ -35,22 +36,22 @@ public class TilesContextPropertyAccessorDelegateFactory implements PropertyAcce
|
||||
* The plain object property accessor, to be used directly for
|
||||
* {@link Request}.
|
||||
*/
|
||||
private final PropertyAccessor objectPropertyAccessor;
|
||||
private final PropertyAccessor<StrutsContext> objectPropertyAccessor;
|
||||
|
||||
/**
|
||||
* The application context property accessor.
|
||||
*/
|
||||
private final PropertyAccessor applicationContextPropertyAccessor;
|
||||
private final PropertyAccessor<StrutsContext> applicationContextPropertyAccessor;
|
||||
|
||||
/**
|
||||
* The request scope property accessor.
|
||||
*/
|
||||
private final PropertyAccessor anyScopePropertyAccessor;
|
||||
private final PropertyAccessor<StrutsContext> anyScopePropertyAccessor;
|
||||
|
||||
/**
|
||||
* The session scope property accessor.
|
||||
*/
|
||||
private final PropertyAccessor scopePropertyAccessor;
|
||||
private final PropertyAccessor<StrutsContext> scopePropertyAccessor;
|
||||
|
||||
/**
|
||||
* The bean info of {@link Request} and
|
||||
@@ -70,10 +71,10 @@ public class TilesContextPropertyAccessorDelegateFactory implements PropertyAcce
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public TilesContextPropertyAccessorDelegateFactory(
|
||||
PropertyAccessor objectPropertyAccessor,
|
||||
PropertyAccessor applicationContextPropertyAccessor,
|
||||
PropertyAccessor anyScopePropertyAccessor,
|
||||
PropertyAccessor scopePropertyAccessor
|
||||
PropertyAccessor<StrutsContext> objectPropertyAccessor,
|
||||
PropertyAccessor<StrutsContext> applicationContextPropertyAccessor,
|
||||
PropertyAccessor<StrutsContext> anyScopePropertyAccessor,
|
||||
PropertyAccessor<StrutsContext> scopePropertyAccessor
|
||||
) {
|
||||
beanInfo = new CombinedBeanInfo(Request.class, ApplicationContext.class);
|
||||
this.objectPropertyAccessor = objectPropertyAccessor;
|
||||
@@ -83,8 +84,8 @@ public class TilesContextPropertyAccessorDelegateFactory implements PropertyAcce
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public PropertyAccessor getPropertyAccessor(String propertyName, Request request) {
|
||||
PropertyAccessor retValue;
|
||||
public PropertyAccessor<StrutsContext> getPropertyAccessor(String propertyName, Request request) {
|
||||
PropertyAccessor<StrutsContext> retValue;
|
||||
if (propertyName.endsWith("Scope")) {
|
||||
String scopeName = propertyName.substring(0, propertyName.length() - ScopePropertyAccessor.SCOPE_SUFFIX_LENGTH);
|
||||
if (request.getContext(scopeName) != null) {
|
||||
|
||||
Reference in New Issue
Block a user