mirror of
https://github.com/apache/struts.git
synced 2026-08-06 15:17:00 +00:00
Adjusts OGNL usage to avoid modify immutable context
This commit is contained in:
@@ -44,9 +44,10 @@ public interface TypeConverter
|
||||
* @return Converted value of type toType or TypeConverter.NoConversionPossible to indicate that the
|
||||
conversion was not possible.
|
||||
*/
|
||||
public Object convertValue(Map<String, Object> context, Object target, Member member, String propertyName, Object value, Class toType);
|
||||
Object convertValue(Map<String, Object> context, Object target, Member member, String propertyName, Object value, Class toType);
|
||||
|
||||
public static final Object NO_CONVERSION_POSSIBLE = "ognl.NoConversionPossible";
|
||||
|
||||
public static final String TYPE_CONVERTER_CONTEXT_KEY = "_typeConverter";
|
||||
Object NO_CONVERSION_POSSIBLE = "ognl.NoConversionPossible";
|
||||
|
||||
@Deprecated
|
||||
String TYPE_CONVERTER_CONTEXT_KEY = "_typeConverter";
|
||||
}
|
||||
+16
-11
@@ -19,12 +19,12 @@
|
||||
package com.opensymphony.xwork2.conversion.impl;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.LocaleProvider;
|
||||
import com.opensymphony.xwork2.LocaleProviderFactory;
|
||||
import com.opensymphony.xwork2.conversion.TypeConverter;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.ognl.XWorkTypeConverterWrapper;
|
||||
import ognl.OgnlContext;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Member;
|
||||
@@ -81,17 +81,22 @@ public abstract class DefaultTypeConverter implements TypeConverter {
|
||||
return convertValue(context, value, toType);
|
||||
}
|
||||
|
||||
public TypeConverter getTypeConverter( Map<String, Object> context )
|
||||
{
|
||||
Object obj = context.get(TypeConverter.TYPE_CONVERTER_CONTEXT_KEY);
|
||||
if (obj instanceof TypeConverter) {
|
||||
return (TypeConverter) obj;
|
||||
|
||||
// for backwards-compatibility
|
||||
} else if (obj instanceof ognl.TypeConverter) {
|
||||
return new XWorkTypeConverterWrapper((ognl.TypeConverter) obj);
|
||||
public TypeConverter getTypeConverter( Map<String, Object> context ) {
|
||||
ognl.TypeConverter converter = null;
|
||||
|
||||
if (context instanceof OgnlContext) {
|
||||
converter = ((OgnlContext) context).getTypeConverter();
|
||||
}
|
||||
return null;
|
||||
|
||||
if (converter != null) {
|
||||
if (converter instanceof TypeConverter) {
|
||||
return (TypeConverter) converter;
|
||||
} else {
|
||||
return new XWorkTypeConverterWrapper(converter);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -184,8 +184,6 @@ public class OgnlUtil {
|
||||
return;
|
||||
}
|
||||
|
||||
Ognl.setTypeConverter(context, getTypeConverterFromContext(context));
|
||||
|
||||
Object oldRoot = Ognl.getRoot(context);
|
||||
Ognl.setRoot(context, o);
|
||||
|
||||
@@ -245,7 +243,6 @@ public class OgnlUtil {
|
||||
* problems setting the property
|
||||
*/
|
||||
public void setProperty(String name, Object value, Object o, Map<String, Object> context, boolean throwPropertyExceptions) {
|
||||
Ognl.setTypeConverter(context, getTypeConverterFromContext(context));
|
||||
|
||||
Object oldRoot = Ognl.getRoot(context);
|
||||
Ognl.setRoot(context, o);
|
||||
@@ -487,11 +484,8 @@ public class OgnlUtil {
|
||||
return;
|
||||
}
|
||||
|
||||
TypeConverter converter = getTypeConverterFromContext(context);
|
||||
final Map contextFrom = createDefaultContext(from, null);
|
||||
Ognl.setTypeConverter(contextFrom, converter);
|
||||
final Map contextTo = createDefaultContext(to, null);
|
||||
Ognl.setTypeConverter(contextTo, converter);
|
||||
|
||||
PropertyDescriptor[] fromPds;
|
||||
PropertyDescriptor[] toPds;
|
||||
@@ -667,18 +661,6 @@ public class OgnlUtil {
|
||||
}
|
||||
}
|
||||
|
||||
TypeConverter getTypeConverterFromContext(Map<String, Object> context) {
|
||||
/*ValueStack stack = (ValueStack) context.get(ActionContext.VALUE_STACK);
|
||||
Container cont = (Container)stack.getContext().get(ActionContext.CONTAINER);
|
||||
if (cont != null) {
|
||||
return new OgnlTypeConverterWrapper(cont.getInstance(XWorkConverter.class));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Cannot find type converter in context map");
|
||||
}
|
||||
*/
|
||||
return defaultConverter;
|
||||
}
|
||||
|
||||
protected Map createDefaultContext(Object root) {
|
||||
return createDefaultContext(root, null);
|
||||
}
|
||||
|
||||
@@ -96,7 +96,6 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
|
||||
this.securityMemberAccess = new SecurityMemberAccess(allowStaticMethodAccess);
|
||||
this.context = Ognl.createDefaultContext(this.root, accessor, new OgnlTypeConverterWrapper(xworkConverter), securityMemberAccess);
|
||||
context.put(VALUE_STACK, this);
|
||||
Ognl.setClassResolver(context, accessor);
|
||||
((OgnlContext) context).setTraceEvaluations(false);
|
||||
((OgnlContext) context).setKeepLastEvaluation(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user