You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2015/06/17 23:09:03 UTC
[03/57] [partial] struts git commit: Merges xwork packages into struts
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java
deleted file mode 100644
index 7617494..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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 com.opensymphony.xwork2.ognl;
-
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.TextProvider;
-import com.opensymphony.xwork2.conversion.NullHandler;
-import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
-import com.opensymphony.xwork2.inject.Container;
-import com.opensymphony.xwork2.inject.Inject;
-import com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor;
-import com.opensymphony.xwork2.util.CompoundRoot;
-import com.opensymphony.xwork2.util.ValueStack;
-import com.opensymphony.xwork2.util.ValueStackFactory;
-import ognl.MethodAccessor;
-import ognl.OgnlRuntime;
-import ognl.PropertyAccessor;
-import org.apache.commons.lang3.BooleanUtils;
-
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Creates an Ognl value stack
- */
-public class OgnlValueStackFactory implements ValueStackFactory {
-
- private XWorkConverter xworkConverter;
- private CompoundRootAccessor compoundRootAccessor;
- private TextProvider textProvider;
- private Container container;
- private boolean allowStaticMethodAccess;
-
- @Inject
- public void setXWorkConverter(XWorkConverter converter) {
- this.xworkConverter = converter;
- }
-
- @Inject("system")
- public void setTextProvider(TextProvider textProvider) {
- this.textProvider = textProvider;
- }
-
- @Inject(value="allowStaticMethodAccess", required=false)
- public void setAllowStaticMethodAccess(String allowStaticMethodAccess) {
- this.allowStaticMethodAccess = BooleanUtils.toBoolean(allowStaticMethodAccess);
- }
-
- public ValueStack createValueStack() {
- ValueStack stack = new OgnlValueStack(xworkConverter, compoundRootAccessor, textProvider, allowStaticMethodAccess);
- container.inject(stack);
- stack.getContext().put(ActionContext.CONTAINER, container);
- return stack;
- }
-
- public ValueStack createValueStack(ValueStack stack) {
- ValueStack result = new OgnlValueStack(stack, xworkConverter, compoundRootAccessor, allowStaticMethodAccess);
- container.inject(result);
- stack.getContext().put(ActionContext.CONTAINER, container);
- return result;
- }
-
- @Inject
- public void setContainer(Container container) throws ClassNotFoundException {
- Set<String> names = container.getInstanceNames(PropertyAccessor.class);
- for (String name : names) {
- Class cls = Class.forName(name);
- if (cls != null) {
- if (Map.class.isAssignableFrom(cls)) {
- PropertyAccessor acc = container.getInstance(PropertyAccessor.class, name);
- }
- OgnlRuntime.setPropertyAccessor(cls, container.getInstance(PropertyAccessor.class, name));
- if (compoundRootAccessor == null && CompoundRoot.class.isAssignableFrom(cls)) {
- compoundRootAccessor = (CompoundRootAccessor) container.getInstance(PropertyAccessor.class, name);
- }
- }
- }
-
- names = container.getInstanceNames(MethodAccessor.class);
- for (String name : names) {
- Class cls = Class.forName(name);
- if (cls != null) {
- OgnlRuntime.setMethodAccessor(cls, container.getInstance(MethodAccessor.class, name));
- }
- }
-
- names = container.getInstanceNames(NullHandler.class);
- for (String name : names) {
- Class cls = Class.forName(name);
- if (cls != null) {
- OgnlRuntime.setNullHandler(cls, new OgnlNullHandlerWrapper(container.getInstance(NullHandler.class, name)));
- }
- }
- if (compoundRootAccessor == null) {
- throw new IllegalStateException("Couldn't find the compound root accessor");
- }
- this.container = container;
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java
deleted file mode 100644
index 2afd3d6..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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 com.opensymphony.xwork2.ognl;
-
-import ognl.DefaultMemberAccess;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.lang.reflect.Member;
-import java.lang.reflect.Modifier;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Allows access decisions to be made on the basis of whether a member is static or not.
- * Also blocks or allows access to properties.
- */
-public class SecurityMemberAccess extends DefaultMemberAccess {
-
- private static final Logger LOG = LogManager.getLogger(SecurityMemberAccess.class);
-
- private final boolean allowStaticMethodAccess;
- private Set<Pattern> excludeProperties = Collections.emptySet();
- private Set<Pattern> acceptProperties = Collections.emptySet();
- private Set<Class<?>> excludedClasses = Collections.emptySet();
- private Set<Pattern> excludedPackageNamePatterns = Collections.emptySet();
-
- public SecurityMemberAccess(boolean method) {
- super(false);
- allowStaticMethodAccess = method;
- }
-
- public boolean getAllowStaticMethodAccess() {
- return allowStaticMethodAccess;
- }
-
- @Override
- public boolean isAccessible(Map context, Object target, Member member, String propertyName) {
- if (checkEnumAccess(target, member)) {
- LOG.trace("Allowing access to enum: {}", target);
- return true;
- }
-
- Class targetClass = target.getClass();
- Class memberClass = member.getDeclaringClass();
-
- if (Modifier.isStatic(member.getModifiers()) && allowStaticMethodAccess) {
- LOG.debug("Support for accessing static methods [target: {}, member: {}, property: {}] is deprecated!", target, member, propertyName);
- if (!isClassExcluded(member.getDeclaringClass())) {
- targetClass = member.getDeclaringClass();
- }
- }
-
- if (isPackageExcluded(targetClass.getPackage(), memberClass.getPackage())) {
- LOG.warn("Package of target [{}] or package of member [{}] are excluded!", target, member);
- return false;
- }
-
- if (isClassExcluded(targetClass)) {
- LOG.warn("Target class [{}] is excluded!", target);
- return false;
- }
-
- if (isClassExcluded(memberClass)) {
- LOG.warn("Declaring class of member type [{}] is excluded!", member);
- return false;
- }
-
- boolean allow = true;
- if (!checkStaticMethodAccess(member)) {
- LOG.warn("Access to static [{}] is blocked!", member);
- allow = false;
- }
-
- //failed static test
- if (!allow) {
- return false;
- }
-
- // Now check for standard scope rules
- return super.isAccessible(context, target, member, propertyName) && isAcceptableProperty(propertyName);
- }
-
- protected boolean checkStaticMethodAccess(Member member) {
- int modifiers = member.getModifiers();
- if (Modifier.isStatic(modifiers)) {
- return allowStaticMethodAccess;
- } else {
- return true;
- }
- }
-
- protected boolean checkEnumAccess(Object target, Member member) {
- if (target instanceof Class) {
- Class clazz = (Class) target;
- if (Enum.class.isAssignableFrom(clazz) && member.getName().equals("values")) {
- return true;
- }
- }
- return false;
- }
-
- protected boolean isPackageExcluded(Package targetPackage, Package memberPackage) {
- if (targetPackage == null || memberPackage == null) {
- LOG.warn("The use of the default (unnamed) package is discouraged!");
- }
-
- final String targetPackageName = targetPackage == null ? "" : targetPackage.getName();
- final String memberPackageName = memberPackage == null ? "" : memberPackage.getName();
- for (Pattern pattern : excludedPackageNamePatterns) {
- if (pattern.matcher(targetPackageName).matches() || pattern.matcher(memberPackageName).matches()) {
- return true;
- }
- }
- return false;
- }
-
- protected boolean isClassExcluded(Class<?> clazz) {
- if (clazz == Object.class) {
- return true;
- }
- for (Class<?> excludedClass : excludedClasses) {
- if (clazz.isAssignableFrom(excludedClass)) {
- return true;
- }
- }
- return false;
- }
-
- protected boolean isAcceptableProperty(String name) {
- return name == null || ((!isExcluded(name)) && isAccepted(name));
- }
-
- protected boolean isAccepted(String paramName) {
- if (!this.acceptProperties.isEmpty()) {
- for (Pattern pattern : acceptProperties) {
- Matcher matcher = pattern.matcher(paramName);
- if (matcher.matches()) {
- return true;
- }
- }
-
- //no match, but acceptedParams is not empty
- return false;
- }
-
- //empty acceptedParams
- return true;
- }
-
- protected boolean isExcluded(String paramName) {
- if (!this.excludeProperties.isEmpty()) {
- for (Pattern pattern : excludeProperties) {
- Matcher matcher = pattern.matcher(paramName);
- if (matcher.matches()) {
- return true;
- }
- }
- }
- return false;
- }
-
- public void setExcludeProperties(Set<Pattern> excludeProperties) {
- this.excludeProperties = excludeProperties;
- }
-
- public void setAcceptProperties(Set<Pattern> acceptedProperties) {
- this.acceptProperties = acceptedProperties;
- }
-
- public void setExcludedClasses(Set<Class<?>> excludedClasses) {
- this.excludedClasses = excludedClasses;
- }
-
- public void setExcludedPackageNamePatterns(Set<Pattern> excludedPackageNamePatterns) {
- this.excludedPackageNamePatterns = excludedPackageNamePatterns;
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/XWorkTypeConverterWrapper.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/XWorkTypeConverterWrapper.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/XWorkTypeConverterWrapper.java
deleted file mode 100644
index dbf21f6..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/XWorkTypeConverterWrapper.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2002-2007,2009 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 com.opensymphony.xwork2.ognl;
-
-import com.opensymphony.xwork2.conversion.TypeConverter;
-
-import java.lang.reflect.Member;
-import java.util.Map;
-
-/**
- * Wraps an OGNL TypeConverter as an XWork TypeConverter
- */
-public class XWorkTypeConverterWrapper implements TypeConverter {
-
- private ognl.TypeConverter typeConverter;
-
- public XWorkTypeConverterWrapper(ognl.TypeConverter conv) {
- this.typeConverter = conv;
- }
-
- public Object convertValue(Map context, Object target, Member member,
- String propertyName, Object value, Class toType) {
- return typeConverter.convertValue(context, target, member, propertyName, value, toType);
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/CompoundRootAccessor.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/CompoundRootAccessor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/CompoundRootAccessor.java
deleted file mode 100644
index 3beb14a..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/CompoundRootAccessor.java
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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 com.opensymphony.xwork2.ognl.accessor;
-
-import com.opensymphony.xwork2.XWorkConstants;
-import com.opensymphony.xwork2.XWorkException;
-import com.opensymphony.xwork2.inject.Inject;
-import com.opensymphony.xwork2.ognl.OgnlValueStack;
-import com.opensymphony.xwork2.util.CompoundRoot;
-import com.opensymphony.xwork2.util.ValueStack;
-import ognl.*;
-import org.apache.commons.lang3.BooleanUtils;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.beans.IntrospectionException;
-import java.beans.PropertyDescriptor;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-
-import static java.lang.String.format;
-import static org.apache.commons.lang3.BooleanUtils.toBoolean;
-
-/**
- * A stack that is able to call methods on objects in the stack.
- *
- * @author $Author$
- * @author Rainer Hermanns
- * @version $Revision$
- */
-public class CompoundRootAccessor implements PropertyAccessor, MethodAccessor, ClassResolver {
-
- /**
- * Used by OGNl to generate bytecode
- */
- public String getSourceAccessor(OgnlContext context, Object target, Object index) {
- return null;
- }
-
- /**
- * Used by OGNl to generate bytecode
- */
- public String getSourceSetter(OgnlContext context, Object target, Object index) {
- return null;
- }
-
- private final static Logger LOG = LogManager.getLogger(CompoundRootAccessor.class);
- private final static Class[] EMPTY_CLASS_ARRAY = new Class[0];
- private static Map<MethodCall, Boolean> invalidMethods = new ConcurrentHashMap<>();
- private boolean devMode = false;
-
- @Inject(XWorkConstants.DEV_MODE)
- public void setDevMode(String mode) {
- this.devMode = BooleanUtils.toBoolean(mode);
- }
-
- public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
- CompoundRoot root = (CompoundRoot) target;
- OgnlContext ognlContext = (OgnlContext) context;
-
- for (Object o : root) {
- if (o == null) {
- continue;
- }
-
- try {
- if (OgnlRuntime.hasSetProperty(ognlContext, o, name)) {
- OgnlRuntime.setProperty(ognlContext, o, name, value);
-
- return;
- } else if (o instanceof Map) {
- @SuppressWarnings("unchecked")
- Map<Object, Object> map = (Map<Object, Object>) o;
- try {
- map.put(name, value);
- return;
- } catch (UnsupportedOperationException e) {
- // This is an unmodifiable Map, so move on to the next element in the stack
- }
- }
-// } catch (OgnlException e) {
-// if (e.getReason() != null) {
-// final String msg = "Caught an Ognl exception while setting property " + name;
-// log.error(msg, e);
-// throw new RuntimeException(msg, e.getReason());
-// }
- } catch (IntrospectionException e) {
- // this is OK if this happens, we'll just keep trying the next
- }
- }
-
- boolean reportError = toBoolean((Boolean) context.get(ValueStack.REPORT_ERRORS_ON_NO_PROP));
-
- if (reportError || devMode) {
- final String msg = format("No object in the CompoundRoot has a publicly accessible property named '%s' " +
- "(no setter could be found).", name);
- if (reportError) {
- throw new XWorkException(msg);
- } else {
- LOG.warn(msg);
- }
- }
- }
-
- public Object getProperty(Map context, Object target, Object name) throws OgnlException {
- CompoundRoot root = (CompoundRoot) target;
- OgnlContext ognlContext = (OgnlContext) context;
-
- if (name instanceof Integer) {
- Integer index = (Integer) name;
- return root.cutStack(index);
- } else if (name instanceof String) {
- if ("top".equals(name)) {
- if (root.size() > 0) {
- return root.get(0);
- } else {
- return null;
- }
- }
-
- for (Object o : root) {
- if (o == null) {
- continue;
- }
-
- try {
- if ((OgnlRuntime.hasGetProperty(ognlContext, o, name)) || ((o instanceof Map) && ((Map) o).containsKey(name))) {
- return OgnlRuntime.getProperty(ognlContext, o, name);
- }
- } catch (OgnlException e) {
- if (e.getReason() != null) {
- final String msg = "Caught an Ognl exception while getting property " + name;
- throw new XWorkException(msg, e);
- }
- } catch (IntrospectionException e) {
- // this is OK if this happens, we'll just keep trying the next
- }
- }
-
- //property was not found
- if (context.containsKey(OgnlValueStack.THROW_EXCEPTION_ON_FAILURE))
- throw new NoSuchPropertyException(target, name);
- else
- return null;
- } else {
- return null;
- }
- }
-
- public Object callMethod(Map context, Object target, String name, Object[] objects) throws MethodFailedException {
- CompoundRoot root = (CompoundRoot) target;
-
- if ("describe".equals(name)) {
- Object v;
- if (objects != null && objects.length == 1) {
- v = objects[0];
- } else {
- v = root.get(0);
- }
-
-
- if (v instanceof Collection || v instanceof Map || v.getClass().isArray()) {
- return v.toString();
- }
-
- try {
- Map<String, PropertyDescriptor> descriptors = OgnlRuntime.getPropertyDescriptors(v.getClass());
-
- int maxSize = 0;
- for (String pdName : descriptors.keySet()) {
- if (pdName.length() > maxSize) {
- maxSize = pdName.length();
- }
- }
-
- SortedSet<String> set = new TreeSet<>();
- StringBuffer sb = new StringBuffer();
- for (PropertyDescriptor pd : descriptors.values()) {
-
- sb.append(pd.getName()).append(": ");
- int padding = maxSize - pd.getName().length();
- for (int i = 0; i < padding; i++) {
- sb.append(" ");
- }
- sb.append(pd.getPropertyType().getName());
- set.add(sb.toString());
-
- sb = new StringBuffer();
- }
-
- sb = new StringBuffer();
- for (Object aSet : set) {
- String s = (String) aSet;
- sb.append(s).append("\n");
- }
-
- return sb.toString();
- } catch (IntrospectionException | OgnlException e) {
- LOG.debug("Got exception in callMethod", e);
- }
- return null;
- }
-
- for (Object o : root) {
- if (o == null) {
- continue;
- }
-
- Class clazz = o.getClass();
- Class[] argTypes = getArgTypes(objects);
-
- MethodCall mc = null;
-
- if (argTypes != null) {
- mc = new MethodCall(clazz, name, argTypes);
- }
-
- if ((argTypes == null) || !invalidMethods.containsKey(mc)) {
- try {
- Object value = OgnlRuntime.callMethod((OgnlContext) context, o, name, objects);
-
- if (value != null) {
- return value;
- }
- } catch (OgnlException e) {
- // try the next one
- Throwable reason = e.getReason();
-
- if (!context.containsKey(OgnlValueStack.THROW_EXCEPTION_ON_FAILURE) && (mc != null) && (reason != null) && (reason.getClass() == NoSuchMethodException.class)) {
- invalidMethods.put(mc, Boolean.TRUE);
- } else if (reason != null) {
- throw new MethodFailedException(o, name, e.getReason());
- }
- }
- }
- }
-
- return null;
- }
-
- public Object callStaticMethod(Map transientVars, Class aClass, String s, Object[] objects) throws MethodFailedException {
- return null;
- }
-
- public Class classForName(String className, Map context) throws ClassNotFoundException {
- Object root = Ognl.getRoot(context);
-
- try {
- if (root instanceof CompoundRoot) {
- if (className.startsWith("vs")) {
- CompoundRoot compoundRoot = (CompoundRoot) root;
-
- if ("vs".equals(className)) {
- return compoundRoot.peek().getClass();
- }
-
- int index = Integer.parseInt(className.substring(2));
-
- return compoundRoot.get(index - 1).getClass();
- }
- }
- } catch (Exception e) {
- LOG.debug("Got exception when tried to get class for name [{}]", className, e);
- }
-
- return Thread.currentThread().getContextClassLoader().loadClass(className);
- }
-
- private Class[] getArgTypes(Object[] args) {
- if (args == null) {
- return EMPTY_CLASS_ARRAY;
- }
-
- Class[] classes = new Class[args.length];
-
- for (int i = 0; i < args.length; i++) {
- Object arg = args[i];
- classes[i] = (arg != null) ? arg.getClass() : Object.class;
- }
-
- return classes;
- }
-
-
- static class MethodCall {
- Class clazz;
- String name;
- Class[] args;
- int hash;
-
- public MethodCall(Class clazz, String name, Class[] args) {
- this.clazz = clazz;
- this.name = name;
- this.args = args;
- this.hash = clazz.hashCode() + name.hashCode();
-
- for (Class arg : args) {
- hash += arg.hashCode();
- }
- }
-
- @Override
- public boolean equals(Object obj) {
- MethodCall mc = (CompoundRootAccessor.MethodCall) obj;
-
- return (mc.clazz.equals(clazz) && mc.name.equals(name) && Arrays.equals(mc.args, args));
- }
-
- @Override
- public int hashCode() {
- return hash;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/ObjectAccessor.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/ObjectAccessor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/ObjectAccessor.java
deleted file mode 100644
index 255a0fc..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/ObjectAccessor.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- *
- */
-package com.opensymphony.xwork2.ognl.accessor;
-
-import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
-import com.opensymphony.xwork2.ognl.OgnlValueStack;
-import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
-import ognl.ObjectPropertyAccessor;
-import ognl.OgnlException;
-
-import java.util.Map;
-
-public class ObjectAccessor extends ObjectPropertyAccessor {
- @Override
- public Object getProperty(Map map, Object o, Object o1) throws OgnlException {
- Object obj = super.getProperty(map, o, o1);
-
- map.put(XWorkConverter.LAST_BEAN_CLASS_ACCESSED, o.getClass());
- map.put(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED, o1.toString());
- ReflectionContextState.updateCurrentPropertyPath(map, o1);
- return obj;
- }
-
- @Override
- public void setProperty(Map map, Object o, Object o1, Object o2) throws OgnlException {
- super.setProperty(map, o, o1, o2);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/ObjectProxyPropertyAccessor.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/ObjectProxyPropertyAccessor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/ObjectProxyPropertyAccessor.java
deleted file mode 100644
index 714acf7..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/ObjectProxyPropertyAccessor.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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 com.opensymphony.xwork2.ognl.accessor;
-
-import com.opensymphony.xwork2.ognl.ObjectProxy;
-import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
-import ognl.OgnlException;
-import ognl.OgnlRuntime;
-import ognl.PropertyAccessor;
-import ognl.OgnlContext;
-
-import java.util.Map;
-
-/**
- * Is able to access (set/get) properties on a given object.
- * <p/>
- * Uses Ognl internal.
- *
- * @author Gabe
- */
-public class ObjectProxyPropertyAccessor implements PropertyAccessor {
-
- /**
- * Used by OGNl to generate bytecode
- */
- public String getSourceAccessor(OgnlContext context, Object target, Object index) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- /**
- * Used by OGNl to generate bytecode
- */
- public String getSourceSetter(OgnlContext context, Object target, Object index) {
- return null;
- }
-
- public Object getProperty(Map context, Object target, Object name) throws OgnlException {
- ObjectProxy proxy = (ObjectProxy) target;
- setupContext(context, proxy);
-
- return OgnlRuntime.getPropertyAccessor(proxy.getValue().getClass()).getProperty(context, target, name);
-
- }
-
- public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
- ObjectProxy proxy = (ObjectProxy) target;
- setupContext(context, proxy);
-
- OgnlRuntime.getPropertyAccessor(proxy.getValue().getClass()).setProperty(context, target, name, value);
- }
-
- /**
- * Sets up the context with the last property and last class
- * accessed.
- *
- * @param context
- * @param proxy
- */
- private void setupContext(Map context, ObjectProxy proxy) {
- ReflectionContextState.setLastBeanClassAccessed(context, proxy.getLastClassAccessed());
- ReflectionContextState.setLastBeanPropertyAccessed(context, proxy.getLastPropertyAccessed());
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkCollectionPropertyAccessor.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkCollectionPropertyAccessor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkCollectionPropertyAccessor.java
deleted file mode 100644
index a1e7536..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkCollectionPropertyAccessor.java
+++ /dev/null
@@ -1,310 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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 com.opensymphony.xwork2.ognl.accessor;
-
-import com.opensymphony.xwork2.ObjectFactory;
-import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer;
-import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
-import com.opensymphony.xwork2.inject.Inject;
-import com.opensymphony.xwork2.ognl.OgnlUtil;
-import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
-import ognl.ObjectPropertyAccessor;
-import ognl.OgnlException;
-import ognl.OgnlRuntime;
-import ognl.SetPropertyAccessor;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author Gabe
- */
-public class XWorkCollectionPropertyAccessor extends SetPropertyAccessor {
-
- private static final Logger LOG = LogManager.getLogger(XWorkCollectionPropertyAccessor.class);
-
- public static final String KEY_PROPERTY_FOR_CREATION = "makeNew";
-
- //use a basic object Ognl property accessor here
- //to access properties of the objects in the Set
- //so that nothing is put in the context to screw things up
- private ObjectPropertyAccessor _accessor = new ObjectPropertyAccessor();
-
- private XWorkConverter xworkConverter;
- private ObjectFactory objectFactory;
- private ObjectTypeDeterminer objectTypeDeterminer;
- private OgnlUtil ognlUtil;
-
- @Inject
- public void setXWorkConverter(XWorkConverter conv) {
- this.xworkConverter = conv;
- }
-
- @Inject
- public void setObjectFactory(ObjectFactory fac) {
- this.objectFactory = fac;
- }
-
- @Inject
- public void setObjectTypeDeterminer(ObjectTypeDeterminer ot) {
- this.objectTypeDeterminer = ot;
- }
-
- @Inject
- public void setOgnlUtil(OgnlUtil util) {
- this.ognlUtil = util;
- }
-
- /**
- * Gets the property of a Collection by indexing the collection
- * based on a key property. For example, if the key property were
- * 'id', this method would convert the key Object to whatever
- * type the id property was, and then access the Set like it was
- * a Map returning a JavaBean with the value of id property matching
- * the input.
- *
- * @see ognl.PropertyAccessor#getProperty(java.util.Map, Object, Object)
- */
- @Override
- public Object getProperty(Map context, Object target, Object key) throws OgnlException {
- LOG.trace("Entering getProperty()");
-
- //check if it is a generic type property.
- //if so, return the value from the
- //superclass which will determine this.
- if (!ReflectionContextState.isGettingByKeyProperty(context) && !key.equals(KEY_PROPERTY_FOR_CREATION)) {
- return super.getProperty(context, target, key);
- } else {
- //reset context property
- ReflectionContextState.setGettingByKeyProperty(context,false);
- }
- Collection c = (Collection) target;
-
- //get the bean that this collection is a property of
- Class lastBeanClass = ReflectionContextState.getLastBeanClassAccessed(context);
-
- //get the property name that this collection uses
- String lastPropertyClass = ReflectionContextState.getLastBeanPropertyAccessed(context);
-
- //if one or the other is null, assume that it isn't
- //set up correctly so just return whatever the
- //superclass would
- if (lastBeanClass == null || lastPropertyClass == null) {
- ReflectionContextState.updateCurrentPropertyPath(context, key);
- return super.getProperty(context, target, key);
- }
-
- //get the key property to index the
- //collection with from the ObjectTypeDeterminer
- String keyProperty = objectTypeDeterminer.getKeyProperty(lastBeanClass, lastPropertyClass);
-
- //get the collection class of the
- Class collClass = objectTypeDeterminer.getElementClass(lastBeanClass, lastPropertyClass, key);
-
- Class keyType;
- Class toGetTypeFrom = (collClass != null) ? collClass : c.iterator().next().getClass();
- try {
- keyType = OgnlRuntime.getPropertyDescriptor(toGetTypeFrom, keyProperty).getPropertyType();
- } catch (Exception exc) {
- throw new OgnlException("Error getting property descriptor: " + exc.getMessage());
- }
-
-
- if (ReflectionContextState.isCreatingNullObjects(context)) {
- Map collMap = getSetMap(context, c, keyProperty);
- if (key.toString().equals(KEY_PROPERTY_FOR_CREATION)) {
- //this should return the XWorkList
- //for this set that contains new entries
- //then the ListPropertyAccessor will be called
- //to access it in the next sequence
- return collMap.get(null);
- }
- Object realKey = xworkConverter.convertValue(context, key, keyType);
- Object value = collMap.get(realKey);
- if (value == null
- && ReflectionContextState.isCreatingNullObjects(context)
- && objectTypeDeterminer
- .shouldCreateIfNew(lastBeanClass,lastPropertyClass,c,keyProperty,false)) {
- //create a new element and
- //set the value of keyProperty
- //to be the given value
- try {
- value=objectFactory.buildBean(collClass, context);
-
- //set the value of the keyProperty
- _accessor.setProperty(context,value,keyProperty,realKey);
-
- //add the new object to the collection
- c.add(value);
-
- //add to the Map if accessed later
- collMap.put(realKey, value);
-
-
- } catch (Exception exc) {
- throw new OgnlException("Error adding new element to collection", exc);
- }
-
- }
- return value;
- } else {
- if (key.toString().equals(KEY_PROPERTY_FOR_CREATION)) {
- return null;
- }
- //with getting do iteration
- //don't assume for now it is
- //optimized to create the Map
- //and unlike setting, there is
- //no easy key for the Set
- Object realKey = xworkConverter.convertValue(context, key, keyType);
- return getPropertyThroughIteration(context, c, keyProperty, realKey);
- }
- }
-
- /*
- * Gets an indexed Map by a given key property with the key being
- * the value of the property and the value being the
- */
- private Map getSetMap(Map context, Collection collection, String property) throws OgnlException {
- LOG.trace("getting set Map");
-
- String path = ReflectionContextState.getCurrentPropertyPath(context);
- Map map = ReflectionContextState.getSetMap(context, path);
-
- if (map == null) {
- LOG.trace("creating set Map");
-
- map = new HashMap();
- map.put(null, new SurrugateList(collection));
- for (Object currTest : collection) {
- Object currKey = _accessor.getProperty(context, currTest, property);
- if (currKey != null) {
- map.put(currKey, currTest);
- }
- }
- ReflectionContextState.setSetMap(context, map, path);
- }
- return map;
- }
-
- /*
- * gets a bean with the given
- */
- public Object getPropertyThroughIteration(Map context, Collection collection, String property, Object key)
- throws OgnlException {
- //TODO
- for (Object currTest : collection) {
- if (_accessor.getProperty(context, currTest, property).equals(key)) {
- return currTest;
- }
- }
- //none found
- return null;
- }
-
- @Override
- public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
- Class lastClass = (Class) context.get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
- String lastProperty = (String) context.get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED);
- Class convertToClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, name);
-
- if (name instanceof String && value.getClass().isArray()) {
- // looks like the input game in the form of "someCollection.foo" and
- // we are expected to define the index values ourselves.
- // So let's do it:
-
- Collection c = (Collection) target;
- Object[] values = (Object[]) value;
- for (Object v : values) {
- try {
- Object o = objectFactory.buildBean(convertToClass, context);
- ognlUtil.setValue((String) name, context, o, v);
- c.add(o);
- } catch (Exception e) {
- throw new OgnlException("Error converting given String values for Collection.", e);
- }
- }
-
- // we don't want to do the normal collection property setting now, since we've already done the work
- // just return instead
- return;
- }
-
- Object realValue = getRealValue(context, value, convertToClass);
-
- super.setProperty(context, target, name, realValue);
- }
-
- private Object getRealValue(Map context, Object value, Class convertToClass) {
- if (value == null || convertToClass == null) {
- return value;
- }
- return xworkConverter.convertValue(context, value, convertToClass);
- }
-}
-
-/**
- * @author Gabe
- */
-class SurrugateList extends ArrayList {
-
- private Collection surrugate;
-
- public SurrugateList(Collection surrugate) {
- this.surrugate = surrugate;
- }
-
- @Override
- public void add(int arg0, Object arg1) {
- if (arg1 != null) {
- surrugate.add(arg1);
- }
- super.add(arg0, arg1);
- }
-
- @Override
- public boolean add(Object arg0) {
- if (arg0 != null) {
- surrugate.add(arg0);
- }
- return super.add(arg0);
- }
-
- @Override
- public boolean addAll(Collection arg0) {
- surrugate.addAll(arg0);
- return super.addAll(arg0);
- }
-
- @Override
- public boolean addAll(int arg0, Collection arg1) {
- surrugate.addAll(arg1);
- return super.addAll(arg0, arg1);
- }
-
- @Override
- public Object set(int arg0, Object arg1) {
- if (arg1 != null) {
- surrugate.add(arg1);
- }
- return super.set(arg0, arg1);
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkEnumerationAccessor.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkEnumerationAccessor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkEnumerationAccessor.java
deleted file mode 100644
index 84745e4..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkEnumerationAccessor.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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 com.opensymphony.xwork2.ognl.accessor;
-
-import ognl.EnumerationPropertyAccessor;
-import ognl.ObjectPropertyAccessor;
-import ognl.OgnlException;
-
-import java.util.Map;
-
-
-/**
- * @author plightbo
- */
-public class XWorkEnumerationAccessor extends EnumerationPropertyAccessor {
-
- ObjectPropertyAccessor opa = new ObjectPropertyAccessor();
-
- @Override
- public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
- opa.setProperty(context, target, name, value);
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkIteratorPropertyAccessor.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkIteratorPropertyAccessor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkIteratorPropertyAccessor.java
deleted file mode 100644
index 2a6184b..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkIteratorPropertyAccessor.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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 com.opensymphony.xwork2.ognl.accessor;
-
-import ognl.IteratorPropertyAccessor;
-import ognl.ObjectPropertyAccessor;
-import ognl.OgnlException;
-
-import java.util.Map;
-
-
-/**
- * @author plightbo
- */
-public class XWorkIteratorPropertyAccessor extends IteratorPropertyAccessor {
-
- ObjectPropertyAccessor opa = new ObjectPropertyAccessor();
-
- @Override
- public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
- opa.setProperty(context, target, name, value);
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessor.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessor.java
deleted file mode 100644
index 6201dae..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkListPropertyAccessor.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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 com.opensymphony.xwork2.ognl.accessor;
-
-import com.opensymphony.xwork2.ObjectFactory;
-import com.opensymphony.xwork2.XWorkException;
-import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer;
-import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
-import com.opensymphony.xwork2.inject.Inject;
-import com.opensymphony.xwork2.ognl.OgnlUtil;
-import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
-import ognl.ListPropertyAccessor;
-import ognl.OgnlException;
-import ognl.PropertyAccessor;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Overrides the list property accessor so in the case of trying
- * to add properties of a given bean and the JavaBean is not present,
- * this class will create the necessary blank JavaBeans.
- *
- * @author Gabriel Zimmerman
- */
-public class XWorkListPropertyAccessor extends ListPropertyAccessor {
-
- private XWorkCollectionPropertyAccessor _sAcc = new XWorkCollectionPropertyAccessor();
-
- private XWorkConverter xworkConverter;
- private ObjectFactory objectFactory;
- private ObjectTypeDeterminer objectTypeDeterminer;
- private OgnlUtil ognlUtil;
-
- @Inject("java.util.Collection")
- public void setXWorkCollectionPropertyAccessor(PropertyAccessor acc) {
- this._sAcc = (XWorkCollectionPropertyAccessor) acc;
- }
-
- @Inject
- public void setXWorkConverter(XWorkConverter conv) {
- this.xworkConverter = conv;
- }
-
- @Inject
- public void setObjectFactory(ObjectFactory fac) {
- this.objectFactory = fac;
- }
-
- @Inject
- public void setObjectTypeDeterminer(ObjectTypeDeterminer ot) {
- this.objectTypeDeterminer = ot;
- }
-
- @Inject
- public void setOgnlUtil(OgnlUtil util) {
- this.ognlUtil = util;
- }
-
- @Override
- public Object getProperty(Map context, Object target, Object name) throws OgnlException {
-
- if (ReflectionContextState.isGettingByKeyProperty(context)
- || name.equals(XWorkCollectionPropertyAccessor.KEY_PROPERTY_FOR_CREATION)) {
- return _sAcc.getProperty(context, target, name);
- } else if (name instanceof String) {
- return super.getProperty(context, target, name);
- }
- ReflectionContextState.updateCurrentPropertyPath(context, name);
- Class lastClass = (Class) context.get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
- String lastProperty = (String) context.get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED);
-
- if (name instanceof Number
- && ReflectionContextState.isCreatingNullObjects(context)
- && objectTypeDeterminer.shouldCreateIfNew(lastClass,lastProperty,target,null,true)) {
-
- List list = (List) target;
- int index = ((Number) name).intValue();
- int listSize = list.size();
-
- if (lastClass == null || lastProperty == null) {
- return super.getProperty(context, target, name);
- }
- Class beanClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, name);
- if (listSize <= index) {
- Object result;
-
- for (int i = listSize; i < index; i++) {
- list.add(null);
- }
- try {
- list.add(index, result = objectFactory.buildBean(beanClass, context));
- } catch (Exception exc) {
- throw new XWorkException(exc);
- }
- return result;
- } else if (list.get(index) == null) {
- Object result;
- try {
- list.set(index, result = objectFactory.buildBean(beanClass, context));
- } catch (Exception exc) {
- throw new XWorkException(exc);
- }
- return result;
- }
- }
- return super.getProperty(context, target, name);
- }
-
- @Override
- public void setProperty(Map context, Object target, Object name, Object value)
- throws OgnlException {
-
- Class lastClass = (Class) context.get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
- String lastProperty = (String) context.get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED);
- Class convertToClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, name);
-
- if (name instanceof String && value.getClass().isArray()) {
- // looks like the input game in the form of "someList.foo" and
- // we are expected to define the index values ourselves.
- // So let's do it:
-
- Collection c = (Collection) target;
- Object[] values = (Object[]) value;
- for (Object v : values) {
- try {
- Object o = objectFactory.buildBean(convertToClass, context);
- ognlUtil.setValue((String) name, context, o, v);
- c.add(o);
- } catch (Exception e) {
- throw new OgnlException("Error converting given String values for Collection.", e);
- }
- }
-
- // we don't want to do the normal list property setting now, since we've already done the work
- // just return instead
- return;
- }
-
- Object realValue = getRealValue(context, value, convertToClass);
-
- if (target instanceof List && name instanceof Number) {
- //make sure there are enough spaces in the List to set
- List list = (List) target;
- int listSize = list.size();
- int count = ((Number) name).intValue();
- if (count >= listSize) {
- for (int i = listSize; i <= count; i++) {
- list.add(null);
- }
- }
- }
-
- super.setProperty(context, target, name, realValue);
- }
-
- private Object getRealValue(Map context, Object value, Class convertToClass) {
- if (value == null || convertToClass == null) {
- return value;
- }
- return xworkConverter.convertValue(context, value, convertToClass);
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMapPropertyAccessor.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMapPropertyAccessor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMapPropertyAccessor.java
deleted file mode 100644
index e30f07e..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMapPropertyAccessor.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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 com.opensymphony.xwork2.ognl.accessor;
-
-import com.opensymphony.xwork2.ObjectFactory;
-import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer;
-import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
-import com.opensymphony.xwork2.inject.Inject;
-import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
-import ognl.MapPropertyAccessor;
-import ognl.OgnlException;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.util.Map;
-
-/**
- * Implementation of PropertyAccessor that sets and gets properties by storing and looking
- * up values in Maps.
- *
- * @author Gabriel Zimmerman
- */
-public class XWorkMapPropertyAccessor extends MapPropertyAccessor {
-
- private static final Logger LOG = LogManager.getLogger(XWorkMapPropertyAccessor.class);
-
- private static final String[] INDEX_ACCESS_PROPS = new String[]{"size", "isEmpty", "keys", "values"};
-
- private XWorkConverter xworkConverter;
- private ObjectFactory objectFactory;
- private ObjectTypeDeterminer objectTypeDeterminer;
-
- @Inject
- public void setXWorkConverter(XWorkConverter conv) {
- this.xworkConverter = conv;
- }
-
- @Inject
- public void setObjectFactory(ObjectFactory fac) {
- this.objectFactory = fac;
- }
-
- @Inject
- public void setObjectTypeDeterminer(ObjectTypeDeterminer ot) {
- this.objectTypeDeterminer = ot;
- }
-
- @Override
- public Object getProperty(Map context, Object target, Object name) throws OgnlException {
- LOG.trace("Entering getProperty ({},{},{})", context, target, name);
-
- ReflectionContextState.updateCurrentPropertyPath(context, name);
- // if this is one of the regular index access
- // properties then just let the superclass deal with the
- // get.
- if (name instanceof String && contains(INDEX_ACCESS_PROPS, (String) name)) {
- return super.getProperty(context, target, name);
- }
-
- Object result = null;
-
- try{
- result = super.getProperty(context, target, name);
- } catch (ClassCastException ex) {
- }
-
- if (result == null) {
- //find the key class and convert the name to that class
- Class lastClass = (Class) context.get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
-
- String lastProperty = (String) context.get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED);
- if (lastClass == null || lastProperty == null) {
- return null;
- }
- Object key = getKey(context, name);
- Map map = (Map) target;
- result = map.get(key);
-
- if (result == null &&
- Boolean.TRUE.equals(context.get(ReflectionContextState.CREATE_NULL_OBJECTS))
- && objectTypeDeterminer.shouldCreateIfNew(lastClass,lastProperty,target,null,false)) {
- Class valueClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, key);
-
- try {
- result = objectFactory.buildBean(valueClass, context);
- map.put(key, result);
- } catch (Exception exc) {
- }
- }
- }
- return result;
- }
-
- /**
- * @param array
- * @param name
- */
- private boolean contains(String[] array, String name) {
- for (String anArray : array) {
- if (anArray.equals(name)) {
- return true;
- }
- }
-
- return false;
- }
-
- @Override
- public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException {
- LOG.trace("Entering setProperty({},{},{},{})", context, target, name, value);
-
- Object key = getKey(context, name);
- Map map = (Map) target;
- map.put(key, getValue(context, value));
- }
-
- private Object getValue(Map context, Object value) {
- Class lastClass = (Class) context.get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
- String lastProperty = (String) context.get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED);
- if (lastClass == null || lastProperty == null) {
- return value;
- }
- Class elementClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, null);
- if (elementClass == null) {
- return value; // nothing is specified, we assume it will be the value passed in.
- }
- return xworkConverter.convertValue(context, value, elementClass);
- }
-
- private Object getKey(Map context, Object name) {
- Class lastClass = (Class) context.get(XWorkConverter.LAST_BEAN_CLASS_ACCESSED);
- String lastProperty = (String) context.get(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED);
- if (lastClass == null || lastProperty == null) {
- // return java.lang.String.class;
- // commented out the above -- it makes absolutely no sense for when setting basic maps!
- return name;
- }
- Class keyClass = objectTypeDeterminer.getKeyClass(lastClass, lastProperty);
- if (keyClass == null) {
- keyClass = java.lang.String.class;
- }
-
- return xworkConverter.convertValue(context, name, keyClass);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMapPropertyAccessorTest.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMapPropertyAccessorTest.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMapPropertyAccessorTest.java
deleted file mode 100644
index a746c7e..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMapPropertyAccessorTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package com.opensymphony.xwork2.ognl.accessor;
-
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.XWorkTestCase;
-import com.opensymphony.xwork2.util.Element;
-import com.opensymphony.xwork2.util.ValueStack;
-import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
-
-import java.util.Collections;
-import java.util.Map;
-
-public class XWorkMapPropertyAccessorTest extends XWorkTestCase {
- public void testCreateNullObjectsIsFalseByDefault() {
- ValueStack vs = ActionContext.getContext().getValueStack();
- vs.push(new MapHolder(Collections.emptyMap()));
- assertNull(vs.findValue("map[key]"));
- }
-
- public void testMapContentsAreReturned() {
- ValueStack vs = ActionContext.getContext().getValueStack();
- vs.push(new MapHolder(Collections.singletonMap("key", "value")));
- assertEquals("value", vs.findValue("map['key']"));
- }
-
- public void testNullIsNotReturnedWhenCreateNullObjectsIsSpecified() {
- ValueStack vs = ActionContext.getContext().getValueStack();
- vs.push(new MapHolder(Collections.emptyMap()));
- ReflectionContextState.setCreatingNullObjects(vs.getContext(), true);
-
- Object value = vs.findValue("map['key']");
- assertNotNull(value);
- assertSame(Object.class, value.getClass());
- }
-
- public void testNullIsReturnedWhenCreateNullObjectsIsSpecifiedAsFalse() {
- ValueStack vs = ActionContext.getContext().getValueStack();
- vs.push(new MapHolder(Collections.emptyMap()));
- ReflectionContextState.setCreatingNullObjects(vs.getContext(), false);
- assertNull(vs.findValue("map['key']"));
- }
-
- private static class MapHolder {
- private final Map map;
-
- public MapHolder(Map m) {
- this.map = m;
- }
-
- @Element(value = Object.class)
- public Map getMap() {
- return map;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMethodAccessor.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMethodAccessor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMethodAccessor.java
deleted file mode 100644
index 7a05bc5..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMethodAccessor.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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 com.opensymphony.xwork2.ognl.accessor;
-
-import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
-import ognl.*;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.beans.PropertyDescriptor;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Map;
-
-
-/**
- * Allows methods to be executed under normal cirumstances, except when {@link ReflectionContextState#DENY_METHOD_EXECUTION}
- * is in the action context with a value of true.
- *
- * @author Patrick Lightbody
- * @author tmjee
- */
-public class XWorkMethodAccessor extends ObjectMethodAccessor {
-
- private static final Logger LOG = LogManager.getLogger(XWorkMethodAccessor.class);
-
- /**
- * @deprecated Use {@link ReflectionContextState#DENY_METHOD_EXECUTION} instead
- */
- @Deprecated public static final String DENY_METHOD_EXECUTION = ReflectionContextState.DENY_METHOD_EXECUTION;
- /**
- * @deprecated Use {@link ReflectionContextState#DENY_INDEXED_ACCESS_EXECUTION} instead
- */
- @Deprecated public static final String DENY_INDEXED_ACCESS_EXECUTION = ReflectionContextState.DENY_INDEXED_ACCESS_EXECUTION;
-
-
- @Override
- public Object callMethod(Map context, Object object, String string, Object[] objects) throws MethodFailedException {
-
- //Collection property accessing
- //this if statement ensures that ognl
- //statements of the form someBean.mySet('keyPropVal')
- //return the set element with value of the keyProp given
-
- if (objects.length == 1 && context instanceof OgnlContext) {
- try {
- OgnlContext ogContext=(OgnlContext)context;
- if (OgnlRuntime.hasSetProperty(ogContext, object, string)) {
- PropertyDescriptor descriptor=OgnlRuntime.getPropertyDescriptor(object.getClass(), string);
- Class propertyType=descriptor.getPropertyType();
- if ((Collection.class).isAssignableFrom(propertyType)) {
- //go directly through OgnlRuntime here
- //so that property strings are not cleared
- //i.e. OgnlUtil should be used initially, OgnlRuntime
- //thereafter
-
- Object propVal=OgnlRuntime.getProperty(ogContext, object, string);
- //use the Collection property accessor instead of the individual property accessor, because
- //in the case of Lists otherwise the index property could be used
- PropertyAccessor accessor=OgnlRuntime.getPropertyAccessor(Collection.class);
- ReflectionContextState.setGettingByKeyProperty(ogContext,true);
- return accessor.getProperty(ogContext,propVal,objects[0]);
- }
- }
- } catch (Exception oe) {
- //this exception should theoretically never happen
- //log it
- LOG.error("An unexpected exception occurred", oe);
- }
-
- }
-
- //HACK - we pass indexed method access i.e. setXXX(A,B) pattern
- if ((objects.length == 2 && string.startsWith("set")) || (objects.length == 1 && string.startsWith("get"))) {
- Boolean exec = (Boolean) context.get(ReflectionContextState.DENY_INDEXED_ACCESS_EXECUTION);
- boolean e = ((exec == null) ? false : exec.booleanValue());
- if (!e) {
- return callMethodWithDebugInfo(context, object, string, objects);
- }
- }
- Boolean exec = (Boolean) context.get(ReflectionContextState.DENY_METHOD_EXECUTION);
- boolean e = ((exec == null) ? false : exec.booleanValue());
-
- if (!e) {
- return callMethodWithDebugInfo(context, object, string, objects);
- } else {
- return null;
- }
- }
-
- private Object callMethodWithDebugInfo(Map context, Object object, String methodName, Object[] objects) throws MethodFailedException {
- try {
- return super.callMethod(context, object, methodName, objects);
- }
- catch(MethodFailedException e) {
- if (LOG.isDebugEnabled()) {
- if (!(e.getReason() instanceof NoSuchMethodException)) {
- // the method exists on the target object, but something went wrong
- LOG.debug("Error calling method through OGNL: object: [{}] method: [{}] args: [{}]", e.getReason(), object.toString(), methodName, Arrays.toString(objects));
- }
- }
- throw e;
- }
- }
-
- @Override
- public Object callStaticMethod(Map context, Class aClass, String string, Object[] objects) throws MethodFailedException {
- Boolean exec = (Boolean) context.get(ReflectionContextState.DENY_METHOD_EXECUTION);
- boolean e = ((exec == null) ? false : exec.booleanValue());
-
- if (!e) {
- return callStaticMethodWithDebugInfo(context, aClass, string, objects);
- } else {
- return null;
- }
- }
-
- private Object callStaticMethodWithDebugInfo(Map context, Class aClass, String methodName,
- Object[] objects) throws MethodFailedException {
- try {
- return super.callStaticMethod(context, aClass, methodName, objects);
- }
- catch(MethodFailedException e) {
- if (LOG.isDebugEnabled()) {
- if (!(e.getReason() instanceof NoSuchMethodException)) {
- // the method exists on the target class, but something went wrong
- LOG.debug("Error calling method through OGNL, class: [{}] method: [{}] args: [{}]", e.getReason(), aClass.getName(), methodName, Arrays.toString(objects));
- }
- }
- throw e;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkObjectPropertyAccessor.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkObjectPropertyAccessor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkObjectPropertyAccessor.java
deleted file mode 100644
index 5351401..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkObjectPropertyAccessor.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2002-2006,2009 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 com.opensymphony.xwork2.ognl.accessor;
-
-import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
-import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
-import ognl.ObjectPropertyAccessor;
-import ognl.OgnlException;
-
-import java.util.Map;
-
-/**
- * @author Gabe
- */
-public class XWorkObjectPropertyAccessor extends ObjectPropertyAccessor {
- @Override
- public Object getProperty(Map context, Object target, Object oname)
- throws OgnlException {
- //set the last set objects in the context
- //so if the next objects accessed are
- //Maps or Collections they can use the information
- //to determine conversion types
- context.put(XWorkConverter.LAST_BEAN_CLASS_ACCESSED, target.getClass());
- context.put(XWorkConverter.LAST_BEAN_PROPERTY_ACCESSED, oname.toString());
- ReflectionContextState.updateCurrentPropertyPath(context, oname);
- return super.getProperty(context, target, oname);
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/package.html
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/package.html b/xwork-core/src/main/java/com/opensymphony/xwork2/package.html
deleted file mode 100644
index 3794154..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/package.html
+++ /dev/null
@@ -1 +0,0 @@
-<body>Main XWork interfaces and classes.</body>
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/result/ParamNameAwareResult.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/result/ParamNameAwareResult.java b/xwork-core/src/main/java/com/opensymphony/xwork2/result/ParamNameAwareResult.java
deleted file mode 100644
index 1067984..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/result/ParamNameAwareResult.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.opensymphony.xwork2.result;
-
-/**
- * Accept parameter name/value to be set on {@link com.opensymphony.xwork2.Result}
- */
-public interface ParamNameAwareResult {
-
- boolean acceptableParameterName(String name, String value);
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/security/AcceptedPatternsChecker.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/security/AcceptedPatternsChecker.java b/xwork-core/src/main/java/com/opensymphony/xwork2/security/AcceptedPatternsChecker.java
deleted file mode 100644
index 64592fa..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/security/AcceptedPatternsChecker.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package com.opensymphony.xwork2.security;
-
-import java.util.Set;
-import java.util.regex.Pattern;
-
-/**
- * Used across different interceptors to check if given string matches one of the excluded patterns.
- */
-public interface AcceptedPatternsChecker {
-
- /**
- * Checks if value matches any of patterns on exclude list
- *
- * @param value to check
- * @return object containing result of matched pattern and pattern itself
- */
- public IsAccepted isAccepted(String value);
-
- /**
- * Sets excluded patterns during runtime
- *
- * @param commaDelimitedPatterns comma delimited string with patterns
- */
- public void setAcceptedPatterns(String commaDelimitedPatterns);
-
- /**
- * Set excluded patterns during runtime
- *
- * @param patterns array of additional excluded patterns
- */
- public void setAcceptedPatterns(String[] patterns);
-
- /**
- * Sets excluded patterns during runtime
- *
- * @param patterns set of additional patterns
- */
- public void setAcceptedPatterns(Set<String> patterns);
-
- /**
- * Allow access list of all defined excluded patterns
- *
- * @return set of excluded patterns
- */
- public Set<Pattern> getAcceptedPatterns();
-
- public final static class IsAccepted {
-
- private final boolean accepted;
- private final String acceptedPattern;
-
- public static IsAccepted yes(String acceptedPattern) {
- return new IsAccepted(true, acceptedPattern);
- }
-
- public static IsAccepted no(String acceptedPatterns) {
- return new IsAccepted(false, acceptedPatterns);
- }
-
- private IsAccepted(boolean accepted, String acceptedPattern) {
- this.accepted = accepted;
- this.acceptedPattern = acceptedPattern;
- }
-
- public boolean isAccepted() {
- return accepted;
- }
-
- public String getAcceptedPattern() {
- return acceptedPattern;
- }
-
- @Override
- public String toString() {
- return "IsAccepted {" +
- "accepted=" + accepted +
- ", acceptedPattern=" + acceptedPattern +
- " }";
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/security/DefaultAcceptedPatternsChecker.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/security/DefaultAcceptedPatternsChecker.java b/xwork-core/src/main/java/com/opensymphony/xwork2/security/DefaultAcceptedPatternsChecker.java
deleted file mode 100644
index 00e9f79..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/security/DefaultAcceptedPatternsChecker.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.opensymphony.xwork2.security;
-
-import com.opensymphony.xwork2.XWorkConstants;
-import com.opensymphony.xwork2.inject.Inject;
-import com.opensymphony.xwork2.util.TextParseUtil;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.regex.Pattern;
-
-public class DefaultAcceptedPatternsChecker implements AcceptedPatternsChecker {
-
- private static final Logger LOG = LogManager.getLogger(DefaultAcceptedPatternsChecker.class);
-
- public static final String[] ACCEPTED_PATTERNS = {
- "\\w+((\\.\\w+)|(\\[\\d+\\])|(\\(\\d+\\))|(\\['(\\w|[\\u4e00-\\u9fa5])+'\\])|(\\('(\\w|[\\u4e00-\\u9fa5])+'\\)))*"
- };
-
- private Set<Pattern> acceptedPatterns;
-
- public DefaultAcceptedPatternsChecker() {
- setAcceptedPatterns(ACCEPTED_PATTERNS);
- }
-
- @Inject(value = XWorkConstants.OVERRIDE_ACCEPTED_PATTERNS, required = false)
- public void setOverrideAcceptedPatterns(String acceptablePatterns) {
- LOG.warn("Overriding accepted patterns [{}] with [{}], be aware that this affects all instances and safety of your application!",
- XWorkConstants.OVERRIDE_ACCEPTED_PATTERNS, acceptablePatterns);
- acceptedPatterns = new HashSet<>();
- for (String pattern : TextParseUtil.commaDelimitedStringToSet(acceptablePatterns)) {
- acceptedPatterns.add(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE));
- }
- }
-
- @Inject(value = XWorkConstants.ADDITIONAL_ACCEPTED_PATTERNS, required = false)
- public void setAdditionalAcceptedPatterns(String acceptablePatterns) {
- LOG.warn("Adding additional global patterns [{}] to accepted patterns!", acceptablePatterns);
- for (String pattern : TextParseUtil.commaDelimitedStringToSet(acceptablePatterns)) {
- acceptedPatterns.add(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE));
- }
- }
-
- public void setAcceptedPatterns(String commaDelimitedPatterns) {
- setAcceptedPatterns(TextParseUtil.commaDelimitedStringToSet(commaDelimitedPatterns));
- }
-
- public void setAcceptedPatterns(String[] additionalPatterns) {
- setAcceptedPatterns(new HashSet<>(Arrays.asList(additionalPatterns)));
- }
-
- public void setAcceptedPatterns(Set<String> patterns) {
- LOG.trace("Sets accepted patterns [{}]", patterns);
- acceptedPatterns = new HashSet<>(patterns.size());
- for (String pattern : patterns) {
- acceptedPatterns.add(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE));
- }
- }
-
- public IsAccepted isAccepted(String value) {
- for (Pattern acceptedPattern : acceptedPatterns) {
- if (acceptedPattern.matcher(value).matches()) {
- LOG.trace("[{}] matches accepted pattern [{}]", value, acceptedPattern);
- return IsAccepted.yes(acceptedPattern.toString());
- }
- }
- return IsAccepted.no(acceptedPatterns.toString());
- }
-
- public Set<Pattern> getAcceptedPatterns() {
- return acceptedPatterns;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/security/DefaultExcludedPatternsChecker.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/security/DefaultExcludedPatternsChecker.java b/xwork-core/src/main/java/com/opensymphony/xwork2/security/DefaultExcludedPatternsChecker.java
deleted file mode 100644
index f6d48cd..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/security/DefaultExcludedPatternsChecker.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package com.opensymphony.xwork2.security;
-
-import com.opensymphony.xwork2.XWorkConstants;
-import com.opensymphony.xwork2.inject.Inject;
-import com.opensymphony.xwork2.util.TextParseUtil;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.regex.Pattern;
-
-public class DefaultExcludedPatternsChecker implements ExcludedPatternsChecker {
-
- private static final Logger LOG = LogManager.getLogger(DefaultExcludedPatternsChecker.class);
-
- public static final String[] EXCLUDED_PATTERNS = {
- "(^|.*#)(dojo|struts|session|request|application|servlet(Request|Response)|parameters|context|_memberAccess)(\\.|\\[).*",
- "^(action|method):.*"
- };
-
- private Set<Pattern> excludedPatterns;
-
- public DefaultExcludedPatternsChecker() {
- setExcludedPatterns(EXCLUDED_PATTERNS);
- }
-
- @Inject(value = XWorkConstants.OVERRIDE_EXCLUDED_PATTERNS, required = false)
- public void setOverrideExcludePatterns(String excludePatterns) {
- LOG.warn("Overriding excluded patterns [{}] with [{}], be aware that this affects all instances and safety of your application!",
- XWorkConstants.OVERRIDE_EXCLUDED_PATTERNS, excludePatterns);
- excludedPatterns = new HashSet<Pattern>();
- for (String pattern : TextParseUtil.commaDelimitedStringToSet(excludePatterns)) {
- excludedPatterns.add(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE));
- }
- }
-
- @Inject(value = XWorkConstants.ADDITIONAL_EXCLUDED_PATTERNS, required = false)
- public void setAdditionalExcludePatterns(String excludePatterns) {
- LOG.debug("Adding additional global patterns [{}] to excluded patterns!", excludePatterns);
- for (String pattern : TextParseUtil.commaDelimitedStringToSet(excludePatterns)) {
- excludedPatterns.add(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE));
- }
- }
-
- public void setExcludedPatterns(String commaDelimitedPatterns) {
- setExcludedPatterns(TextParseUtil.commaDelimitedStringToSet(commaDelimitedPatterns));
- }
-
- public void setExcludedPatterns(String[] patterns) {
- setExcludedPatterns(new HashSet<>(Arrays.asList(patterns)));
- }
-
- public void setExcludedPatterns(Set<String> patterns) {
- LOG.trace("Sets excluded patterns [{}]", patterns);
- excludedPatterns = new HashSet<>(patterns.size());
- for (String pattern : patterns) {
- excludedPatterns.add(Pattern.compile(pattern, Pattern.CASE_INSENSITIVE));
- }
- }
-
- public IsExcluded isExcluded(String value) {
- for (Pattern excludedPattern : excludedPatterns) {
- if (excludedPattern.matcher(value).matches()) {
- LOG.trace("[{}] matches excluded pattern [{}]", value, excludedPattern);
- return IsExcluded.yes(excludedPattern);
- }
- }
- return IsExcluded.no(excludedPatterns);
- }
-
- public Set<Pattern> getExcludedPatterns() {
- return excludedPatterns;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/security/ExcludedPatternsChecker.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/security/ExcludedPatternsChecker.java b/xwork-core/src/main/java/com/opensymphony/xwork2/security/ExcludedPatternsChecker.java
deleted file mode 100644
index 5a3bc07..0000000
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/security/ExcludedPatternsChecker.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package com.opensymphony.xwork2.security;
-
-import java.util.Set;
-import java.util.regex.Pattern;
-
-/**
- * Used across different interceptors to check if given string matches one of the excluded patterns.
- */
-public interface ExcludedPatternsChecker {
-
- /**
- * Checks if value matches any of patterns on exclude list
- *
- * @param value to check
- * @return object containing result of matched pattern and pattern itself
- */
- public IsExcluded isExcluded(String value);
-
- /**
- * Sets excluded patterns during runtime
- *
- * @param commaDelimitedPatterns comma delimited string with patterns
- */
- public void setExcludedPatterns(String commaDelimitedPatterns);
-
- /**
- * Sets excluded patterns during runtime
- *
- * @param patterns array of additional excluded patterns
- */
- public void setExcludedPatterns(String[] patterns);
-
- /**
- * Sets excluded patterns during runtime
- *
- * @param patterns set of additional patterns
- */
- public void setExcludedPatterns(Set<String> patterns);
-
- /**
- * Allow access list of all defined excluded patterns
- *
- * @return set of excluded patterns
- */
- public Set<Pattern> getExcludedPatterns();
-
- public final static class IsExcluded {
-
- private final boolean excluded;
- private final String excludedPattern;
-
- public static IsExcluded yes(Pattern excludedPattern) {
- return new IsExcluded(true, excludedPattern.pattern());
- }
-
- public static IsExcluded no(Set<Pattern> excludedPatterns) {
- return new IsExcluded(false, excludedPatterns.toString());
- }
-
- private IsExcluded(boolean excluded, String excludedPattern) {
- this.excluded = excluded;
- this.excludedPattern = excludedPattern;
- }
-
- public boolean isExcluded() {
- return excluded;
- }
-
- public String getExcludedPattern() {
- return excludedPattern;
- }
-
- @Override
- public String toString() {
- return "IsExcluded { " +
- "excluded=" + excluded +
- ", excludedPattern=" + excludedPattern +
- " }";
- }
- }
-
-}