http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/BeforeResult.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/BeforeResult.java b/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/BeforeResult.java deleted file mode 100644 index faeb400..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/BeforeResult.java +++ /dev/null @@ -1,80 +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.interceptor.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * <!-- START SNIPPET: description --> - * Marks a action method that needs to be executed before the result. Return value is ignored. - * <!-- END SNIPPET: description --> - * - * <p/> <u>Annotation usage:</u> - * - * <!-- START SNIPPET: usage --> - * The BeforeResult annotation can be applied at method level. - * - * <!-- END SNIPPET: usage --> - * - * <p/> <u>Annotation parameters:</u> - * - * <!-- START SNIPPET: parameters --> - * <table class='confluenceTable'> - * <tr> - * <th class='confluenceTh'> Parameter </th> - * <th class='confluenceTh'> Required </th> - * <th class='confluenceTh'> Default </th> - * <th class='confluenceTh'> Notes </th> - * </tr> - * <tr> - * <td class='confluenceTd'>priority</td> - * <td class='confluenceTd'>no</td> - * <td class='confluenceTd'>10</td> - * <td class='confluenceTd'>Priority order of method execution</td> - * </tr> - * </table> - * <!-- END SNIPPET: parameters --> - * - * <p/> <u>Example code:</u> - * - * <pre> - * <!-- START SNIPPET: example --> - * public class SampleAction extends ActionSupport { - * - * @BeforeResult - * public void isValid() throws ValidationException { - * // validate model object, throw exception if failed - * } - * - * public String execute() { - * // perform action - * return SUCCESS; - * } - * } - * <!-- END SNIPPET: example --> - * </pre> - * - * @author Zsolt Szasz, zsolt at lorecraft dot com - * @author Rainer Hermanns - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD}) -public @interface BeforeResult { - int priority() default 10; -}
http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/BlockByDefault.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/BlockByDefault.java b/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/BlockByDefault.java deleted file mode 100644 index a87ac0b..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/BlockByDefault.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.opensymphony.xwork2.interceptor.annotations; - -import com.opensymphony.xwork2.Action; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Declares that by default fields on the {@link Action} class - * are NOT permitted to be set from HttpRequest parameters. - * To allow access to a field it must be annotated with {@link Allowed} - * - * @author martin.gilday - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface BlockByDefault { - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Blocked.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Blocked.java b/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Blocked.java deleted file mode 100644 index e9a2885..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/Blocked.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.opensymphony.xwork2.interceptor.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Declares that the given field should NOT be able to be mutated through - * a HttpRequest parameter. - * - * @author martin.gilday - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface Blocked { - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/InputConfig.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/InputConfig.java b/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/InputConfig.java deleted file mode 100644 index 5d70744..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/InputConfig.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2002-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.interceptor.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import com.opensymphony.xwork2.Action; - -/** - * <!-- START SNIPPET: description --> - * Marks a action method that if it's not validated by ValidationInterceptor then execute input method or input result. - * <!-- END SNIPPET: description --> - * - * <p/> <u>Annotation usage:</u> - * - * <!-- START SNIPPET: usage --> - * The InputConfig annotation can be applied at method level. - * - * <!-- END SNIPPET: usage --> - * - * <p/> <u>Annotation parameters:</u> - * - * <!-- START SNIPPET: parameters --> - * <table class='confluenceTable'> - * <tr> - * <th class='confluenceTh'> Parameter </th> - * <th class='confluenceTh'> Required </th> - * <th class='confluenceTh'> Default </th> - * <th class='confluenceTh'> Notes </th> - * </tr> - * <tr> - * <td class='confluenceTd'>methodName</td> - * <td class='confluenceTd'>no</td> - * <td class='confluenceTd'></td> - * <td class='confluenceTd'>execute this method if specific</td> - * </tr> - * <tr> - * <td class='confluenceTd'>resultName</td> - * <td class='confluenceTd'>no</td> - * <td class='confluenceTd'></td> - * <td class='confluenceTd'>return this result if methodName not specific</td> - * </tr> - * </table> - * <!-- END SNIPPET: parameters --> - * - * <p/> <u>Example code:</u> - * - * <pre> - * <!-- START SNIPPET: example --> - * public class SampleAction extends ActionSupport { - * - * public void isValid() throws ValidationException { - * // validate model object, throw exception if failed - * } - * - * @InputConfig(methodName="input") - * public String execute() { - * // perform action - * return SUCCESS; - * } - * public String input() { - * // perform some data filling - * return INPUT; - * } - * } - * <!-- END SNIPPET: example --> - * </pre> - * - * @author zhouyanming, [email protected] - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD}) -public @interface InputConfig { - String methodName() default ""; - String resultName() default Action.INPUT; -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/package.html ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/package.html b/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/package.html deleted file mode 100644 index 8ac50a8..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/package.html +++ /dev/null @@ -1 +0,0 @@ -<body>Interceptor annotations.</body> http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/package.html ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/package.html b/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/package.html deleted file mode 100644 index 505d814..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/package.html +++ /dev/null @@ -1 +0,0 @@ -<body>Interceptor classes.</body> http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockActionInvocation.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockActionInvocation.java b/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockActionInvocation.java deleted file mode 100644 index 0749689..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockActionInvocation.java +++ /dev/null @@ -1,133 +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.mock; - -import com.opensymphony.xwork2.*; -import com.opensymphony.xwork2.interceptor.PreResultListener; -import com.opensymphony.xwork2.util.ValueStack; - -import java.util.ArrayList; -import java.util.List; - -/** - * Mock for an {@link ActionInvocation}. - * - * @author plightbo - * @author Rainer Hermanns - * @author tm_jee - * @version $Id$ - */ -public class MockActionInvocation implements ActionInvocation { - - private Object action; - private ActionContext invocationContext; - private ActionEventListener actionEventListener; - private ActionProxy proxy; - private Result result; - private String resultCode; - private ValueStack stack; - - private List<PreResultListener> preResultListeners = new ArrayList<>(); - - public Object getAction() { - return action; - } - - public void setAction(Object action) { - this.action = action; - } - - public ActionContext getInvocationContext() { - return invocationContext; - } - - public void setInvocationContext(ActionContext invocationContext) { - this.invocationContext = invocationContext; - } - - public ActionProxy getProxy() { - return proxy; - } - - public void setProxy(ActionProxy proxy) { - this.proxy = proxy; - } - - public Result getResult() { - return result; - } - - public void setResult(Result result) { - this.result = result; - } - - public String getResultCode() { - return resultCode; - } - - public void setResultCode(String resultCode) { - this.resultCode = resultCode; - } - - public ValueStack getStack() { - return stack; - } - - public void setStack(ValueStack stack) { - this.stack = stack; - } - - public boolean isExecuted() { - return false; - } - - public void addPreResultListener(PreResultListener listener) { - preResultListeners.add(listener); - } - - public String invoke() throws Exception { - for (Object preResultListener : preResultListeners) { - PreResultListener listener = (PreResultListener) preResultListener; - listener.beforeResult(this, resultCode); - } - return resultCode; - } - - public String invokeActionOnly() throws Exception { - return resultCode; - } - - public void setActionEventListener(ActionEventListener listener) { - this.actionEventListener = listener; - } - - public ActionEventListener getActionEventListener() { - return this.actionEventListener; - } - - public void init(ActionProxy proxy) { - } - - public ActionInvocation serialize() { - return this; - } - - public ActionInvocation deserialize(ActionContext actionContext) { - return this; - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockActionProxy.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockActionProxy.java b/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockActionProxy.java deleted file mode 100644 index f373591..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockActionProxy.java +++ /dev/null @@ -1,127 +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.mock; - -import com.opensymphony.xwork2.ActionInvocation; -import com.opensymphony.xwork2.ActionProxy; -import com.opensymphony.xwork2.config.Configuration; -import com.opensymphony.xwork2.config.entities.ActionConfig; -import org.apache.commons.lang3.StringUtils; - -/** - * Mock for an {@link ActionProxy}. - * - * @author Patrick Lightbody (plightbo at gmail dot com) - */ -public class MockActionProxy implements ActionProxy { - - Object action; - String actionName; - ActionConfig config; - boolean executeResult; - ActionInvocation invocation; - String namespace; - String method; - boolean executedCalled; - String returnedResult; - Configuration configuration; - boolean methodSpecified; - - public void prepare() throws Exception {} - - public String execute() throws Exception { - executedCalled = true; - - return returnedResult; - } - - public void setReturnedResult(String returnedResult) { - this.returnedResult = returnedResult; - } - - public boolean isExecutedCalled() { - return executedCalled; - } - - public Object getAction() { - return action; - } - - public void setAction(Object action) { - this.action = action; - } - - public String getActionName() { - return actionName; - } - - public void setActionName(String actionName) { - this.actionName = actionName; - } - - public ActionConfig getConfig() { - return config; - } - - public void setConfig(ActionConfig config) { - this.config = config; - } - - public boolean getExecuteResult() { - return executeResult; - } - - public void setExecuteResult(boolean executeResult) { - this.executeResult = executeResult; - } - - public ActionInvocation getInvocation() { - return invocation; - } - - public void setInvocation(ActionInvocation invocation) { - this.invocation = invocation; - } - - public String getNamespace() { - return namespace; - } - - public void setNamespace(String namespace) { - this.namespace = namespace; - } - - public String getMethod() { - return method; - } - - public void setMethod(String method) { - this.method = method; - methodSpecified = StringUtils.isNotEmpty(method); - } - - public boolean isMethodSpecified() - { - return methodSpecified; - } - - public void setMethodSpecified(boolean methodSpecified) - { - this.methodSpecified = methodSpecified; - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockContainer.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockContainer.java b/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockContainer.java deleted file mode 100644 index bcad8a9..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockContainer.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.opensymphony.xwork2.mock; - -import com.opensymphony.xwork2.inject.Container; -import com.opensymphony.xwork2.inject.Scope; - -import java.util.Set; - -/** - * Mock implementation to be used in unittests - */ -public class MockContainer implements Container { - - public void inject(Object o) { - - } - - public <T> T inject(Class<T> implementation) { - return null; - } - - public <T> T getInstance(Class<T> type, String name) { - return null; - } - - public <T> T getInstance(Class<T> type) { - return null; - } - - public Set<String> getInstanceNames(Class<?> type) { - return null; - } - - public void setScopeStrategy(Scope.Strategy scopeStrategy) { - - } - - public void removeScopeStrategy() { - - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockInterceptor.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockInterceptor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockInterceptor.java deleted file mode 100644 index c244770..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockInterceptor.java +++ /dev/null @@ -1,122 +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.mock; - -import com.opensymphony.xwork2.ActionInvocation; -import com.opensymphony.xwork2.interceptor.Interceptor; -import junit.framework.Assert; - - -/** - * Mock for an {@link com.opensymphony.xwork2.interceptor.Interceptor}. - * - * @author Jason Carreira - */ -public class MockInterceptor implements Interceptor { - - private static final long serialVersionUID = 2692551676567227756L; - - public static final String DEFAULT_FOO_VALUE = "fooDefault"; - - - private String expectedFoo = DEFAULT_FOO_VALUE; - private String foo = DEFAULT_FOO_VALUE; - private boolean executed = false; - - - public boolean isExecuted() { - return executed; - } - - public void setExpectedFoo(String expectedFoo) { - this.expectedFoo = expectedFoo; - } - - public String getExpectedFoo() { - return expectedFoo; - } - - public void setFoo(String foo) { - this.foo = foo; - } - - public String getFoo() { - return foo; - } - - /** - * Called to let an interceptor clean up any resources it has allocated. - */ - public void destroy() { - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - if (!(o instanceof MockInterceptor)) { - return false; - } - - final MockInterceptor testInterceptor = (MockInterceptor) o; - - if (executed != testInterceptor.executed) { - return false; - } - - if ((expectedFoo != null) ? (!expectedFoo.equals(testInterceptor.expectedFoo)) : (testInterceptor.expectedFoo != null)) - { - return false; - } - - if ((foo != null) ? (!foo.equals(testInterceptor.foo)) : (testInterceptor.foo != null)) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - int result; - result = ((expectedFoo != null) ? expectedFoo.hashCode() : 0); - result = (29 * result) + ((foo != null) ? foo.hashCode() : 0); - result = (29 * result) + (executed ? 1 : 0); - - return result; - } - - /** - * Called after an Interceptor is created, but before any requests are processed using the intercept() methodName. This - * gives the Interceptor a chance to initialize any needed resources. - */ - public void init() { - } - - /** - * Allows the Interceptor to do some processing on the request before and/or after the rest of the processing of the - * request by the DefaultActionInvocation or to short-circuit the processing and just return a String return code. - */ - public String intercept(ActionInvocation invocation) throws Exception { - executed = true; - Assert.assertNotSame(DEFAULT_FOO_VALUE, foo); - Assert.assertEquals(expectedFoo, foo); - - return invocation.invoke(); - } -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockObjectTypeDeterminer.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockObjectTypeDeterminer.java b/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockObjectTypeDeterminer.java deleted file mode 100644 index 605aaf2..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockObjectTypeDeterminer.java +++ /dev/null @@ -1,125 +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.mock; - -import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer; -import ognl.OgnlException; -import ognl.OgnlRuntime; - -import java.util.Map; - -/** - * Mocks the function of an ObjectTypeDeterminer for testing purposes. - * - * @author Gabe - */ -public class MockObjectTypeDeterminer implements ObjectTypeDeterminer { - - private Class keyClass; - private Class elementClass; - private String keyProperty; - private boolean shouldCreateIfNew; - - public MockObjectTypeDeterminer() {} - - - /** - * @param keyClass - * @param elementClass - * @param keyProperty - * @param shouldCreateIfNew - */ - public MockObjectTypeDeterminer(Class keyClass, Class elementClass, - String keyProperty, boolean shouldCreateIfNew) { - super(); - this.keyClass = keyClass; - this.elementClass = elementClass; - this.keyProperty = keyProperty; - this.shouldCreateIfNew = shouldCreateIfNew; - } - - public Class getKeyClass(Class parentClass, String property) { - return getKeyClass(); - } - - public Class getElementClass(Class parentClass, String property, Object key) { - return getElementClass(); - } - - public String getKeyProperty(Class parentClass, String property) { - return getKeyProperty(); - } - - public boolean shouldCreateIfNew(Class parentClass, String property, - Object target, String keyProperty, boolean isIndexAccessed) { - try { - System.out.println("ognl:"+OgnlRuntime.getPropertyAccessor(Map.class)+" this:"+this); - } catch (OgnlException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return isShouldCreateIfNew(); - } - - /** - * @return Returns the elementClass. - */ - public Class getElementClass() { - return elementClass; - } - /** - * @param elementClass The elementClass to set. - */ - public void setElementClass(Class elementClass) { - this.elementClass = elementClass; - } - /** - * @return Returns the keyClass. - */ - public Class getKeyClass() { - return keyClass; - } - /** - * @param keyClass The keyClass to set. - */ - public void setKeyClass(Class keyClass) { - this.keyClass = keyClass; - } - /** - * @return Returns the keyProperty. - */ - public String getKeyProperty() { - return keyProperty; - } - /** - * @param keyProperty The keyProperty to set. - */ - public void setKeyProperty(String keyProperty) { - this.keyProperty = keyProperty; - } - /** - * @return Returns the shouldCreateIfNew. - */ - public boolean isShouldCreateIfNew() { - return shouldCreateIfNew; - } - /** - * @param shouldCreateIfNew The shouldCreateIfNew to set. - */ - public void setShouldCreateIfNew(boolean shouldCreateIfNew) { - this.shouldCreateIfNew = shouldCreateIfNew; - } -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockResult.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockResult.java b/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockResult.java deleted file mode 100644 index 571469c..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/mock/MockResult.java +++ /dev/null @@ -1,53 +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.mock; - -import com.opensymphony.xwork2.ActionInvocation; -import com.opensymphony.xwork2.Result; - -/** - * Mock for a {@link Result}. - * - * @author Mike - * @author Rainer Hermanns - */ -public class MockResult implements Result { - - public static final String DEFAULT_PARAM = "foo"; - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - return o instanceof MockResult; - } - - public void execute(ActionInvocation invocation) throws Exception { - // no op - } - - @Override - public int hashCode() { - return 10; - } - - public void setFoo(String foo) { - // no op - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/mock/package.html ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/mock/package.html b/xwork-core/src/main/java/com/opensymphony/xwork2/mock/package.html deleted file mode 100644 index 61bdf48..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/mock/package.html +++ /dev/null @@ -1 +0,0 @@ -<body>XWork specific mock classes.</body> http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/ErrorMessageBuilder.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/ErrorMessageBuilder.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/ErrorMessageBuilder.java deleted file mode 100644 index 0172e73..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/ErrorMessageBuilder.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.opensymphony.xwork2.ognl; - -/** - * Helper class to build error messages. - */ -public class ErrorMessageBuilder { - - private StringBuilder message = new StringBuilder(); - - public static ErrorMessageBuilder create() { - return new ErrorMessageBuilder(); - } - - private ErrorMessageBuilder() { - } - - public ErrorMessageBuilder errorSettingExpressionWithValue(String expr, Object value) { - appenExpression(expr); - if (value instanceof Object[]) { - appendValueAsArray((Object[]) value, message); - } else { - appendValue(value); - } - return this; - } - - private void appenExpression(String expr) { - message.append("Error setting expression '"); - message.append(expr); - message.append("' with value "); - } - - private void appendValue(Object value) { - message.append("'"); - message.append(value); - message.append("'"); - } - - private void appendValueAsArray(Object[] valueArray, StringBuilder msg) { - msg.append("["); - for (int index = 0; index < valueArray.length; index++) { - appendValue(valueArray[index]); - if (hasMoreElements(valueArray, index)) { - msg.append(", "); - } - } - msg.append("]"); - } - - private boolean hasMoreElements(Object[] valueArray, int index) { - return index < (valueArray.length + 1); - } - - public String build() { - return message.toString(); - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/ObjectProxy.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/ObjectProxy.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/ObjectProxy.java deleted file mode 100644 index b01fd67..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/ObjectProxy.java +++ /dev/null @@ -1,55 +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; - -/** - * An Object to use within OGNL to proxy other Objects - * usually Collections that you set in a different place - * on the ValueStack but want to retain the context information - * about where they previously were. - * - * @author Gabe - */ -public class ObjectProxy { - private Object value; - private Class lastClassAccessed; - private String lastPropertyAccessed; - - public Class getLastClassAccessed() { - return lastClassAccessed; - } - - public void setLastClassAccessed(Class lastClassAccessed) { - this.lastClassAccessed = lastClassAccessed; - } - - public String getLastPropertyAccessed() { - return lastPropertyAccessed; - } - - public void setLastPropertyAccessed(String lastPropertyAccessed) { - this.lastPropertyAccessed = lastPropertyAccessed; - } - - public Object getValue() { - return value; - } - - public void setValue(Object value) { - this.value = value; - } -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlNullHandlerWrapper.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlNullHandlerWrapper.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlNullHandlerWrapper.java deleted file mode 100644 index 95a0e35..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlNullHandlerWrapper.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.opensymphony.xwork2.ognl; - -import com.opensymphony.xwork2.conversion.NullHandler; - -import java.util.Map; - -public class OgnlNullHandlerWrapper implements ognl.NullHandler { - - private NullHandler wrapped; - - public OgnlNullHandlerWrapper(NullHandler target) { - this.wrapped = target; - } - - public Object nullMethodResult(Map context, Object target, - String methodName, Object[] args) { - return wrapped.nullMethodResult(context, target, methodName, args); - } - - public Object nullPropertyValue(Map context, Object target, Object property) { - return wrapped.nullPropertyValue(context, target, property); - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionContextFactory.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionContextFactory.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionContextFactory.java deleted file mode 100644 index 03a5537..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionContextFactory.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.opensymphony.xwork2.ognl; - -import com.opensymphony.xwork2.util.reflection.ReflectionContextFactory; -import ognl.Ognl; - -import java.util.Map; - -public class OgnlReflectionContextFactory implements ReflectionContextFactory { - - public Map createDefaultContext(Object root) { - return Ognl.createDefaultContext(root); - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionProvider.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionProvider.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionProvider.java deleted file mode 100644 index 34f3043..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlReflectionProvider.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.opensymphony.xwork2.ognl; - -import com.opensymphony.xwork2.inject.Inject; -import com.opensymphony.xwork2.util.reflection.ReflectionException; -import com.opensymphony.xwork2.util.reflection.ReflectionProvider; -import ognl.Ognl; -import ognl.OgnlException; -import ognl.OgnlRuntime; - -import java.beans.IntrospectionException; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.Map; - -public class OgnlReflectionProvider implements ReflectionProvider { - - private OgnlUtil ognlUtil; - - @Inject - public void setOgnlUtil(OgnlUtil ognlUtil) { - this.ognlUtil = ognlUtil; - } - - public Field getField(Class inClass, String name) { - return OgnlRuntime.getField(inClass, name); - } - - public Method getGetMethod(Class targetClass, String propertyName) - throws IntrospectionException, ReflectionException { - try { - return OgnlRuntime.getGetMethod(null, targetClass, propertyName); - } catch (OgnlException e) { - throw new ReflectionException(e); - } - } - - public Method getSetMethod(Class targetClass, String propertyName) - throws IntrospectionException, ReflectionException { - try { - return OgnlRuntime.getSetMethod(null, targetClass, propertyName); - } catch (OgnlException e) { - throw new ReflectionException(e); - } - } - - public void setProperties(Map<String, ?> props, Object o, Map<String, Object> context) { - ognlUtil.setProperties(props, o, context); - } - - public void setProperties(Map<String, ?> props, Object o, Map<String, Object> context, boolean throwPropertyExceptions) throws ReflectionException{ - ognlUtil.setProperties(props, o, context, throwPropertyExceptions); - - } - - public void setProperties(Map<String, ?> properties, Object o) { - ognlUtil.setProperties(properties, o); - } - - public PropertyDescriptor getPropertyDescriptor(Class targetClass, - String propertyName) throws IntrospectionException, - ReflectionException { - try { - return OgnlRuntime.getPropertyDescriptor(targetClass, propertyName); - } catch (OgnlException e) { - throw new ReflectionException(e); - } - } - - public void copy(Object from, Object to, Map<String, Object> context, - Collection<String> exclusions, Collection<String> inclusions) { - ognlUtil.copy(from, to, context, exclusions, inclusions); - } - - public Object getRealTarget(String property, Map<String, Object> context, Object root) - throws ReflectionException { - try { - return ognlUtil.getRealTarget(property, context, root); - } catch (OgnlException e) { - throw new ReflectionException(e); - } - } - - public void setProperty(String name, Object value, Object o, Map<String, Object> context) { - ognlUtil.setProperty(name, value, o, context); - } - - public void setProperty(String name, Object value, Object o, Map<String, Object> context, boolean throwPropertyExceptions) { - ognlUtil.setProperty(name, value, o, context, throwPropertyExceptions); - } - - public Map getBeanMap(Object source) throws IntrospectionException, - ReflectionException { - try { - return ognlUtil.getBeanMap(source); - } catch (OgnlException e) { - throw new ReflectionException(e); - } - } - - public Object getValue(String expression, Map<String, Object> context, Object root) - throws ReflectionException { - try { - return ognlUtil.getValue(expression, context, root); - } catch (OgnlException e) { - throw new ReflectionException(e); - } - } - - public void setValue(String expression, Map<String, Object> context, Object root, - Object value) throws ReflectionException { - try { - Ognl.setValue(expression, context, root, value); - } catch (OgnlException e) { - throw new ReflectionException(e); - } - } - - public PropertyDescriptor[] getPropertyDescriptors(Object source) - throws IntrospectionException { - return ognlUtil.getPropertyDescriptors(source); - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlTypeConverterWrapper.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlTypeConverterWrapper.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlTypeConverterWrapper.java deleted file mode 100644 index ad79542..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlTypeConverterWrapper.java +++ /dev/null @@ -1,45 +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 XWork type conversion class for as an OGNL TypeConverter - */ -public class OgnlTypeConverterWrapper implements ognl.TypeConverter { - - private TypeConverter typeConverter; - - public OgnlTypeConverterWrapper(TypeConverter converter) { - if (converter == null) { - throw new IllegalArgumentException("Wrapped type converter cannot be null"); - } - this.typeConverter = converter; - } - - public Object convertValue(Map context, Object target, Member member, - String propertyName, Object value, Class toType) { - return typeConverter.convertValue(context, target, member, propertyName, value, toType); - } - - public TypeConverter getTarget() { - return typeConverter; - } -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java deleted file mode 100644 index 45e9992..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java +++ /dev/null @@ -1,574 +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.XWorkConstants; -import com.opensymphony.xwork2.config.ConfigurationException; -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.TextParseUtil; -import com.opensymphony.xwork2.util.reflection.ReflectionException; -import ognl.*; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Method; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.regex.Pattern; - - -/** - * Utility class that provides common access to the Ognl APIs for - * setting and getting properties from objects (usually Actions). - * - * @author Jason Carreira - */ -public class OgnlUtil { - - private static final Logger LOG = LogManager.getLogger(OgnlUtil.class); - private ConcurrentMap<String, Object> expressions = new ConcurrentHashMap<>(); - private final ConcurrentMap<Class, BeanInfo> beanInfoCache = new ConcurrentHashMap<>(); - private TypeConverter defaultConverter; - - private boolean devMode = false; - private boolean enableExpressionCache = true; - private boolean enableEvalExpression; - - private Set<Class<?>> excludedClasses = new HashSet<>(); - private Set<Pattern> excludedPackageNamePatterns = new HashSet<>(); - - private Container container; - private boolean allowStaticMethodAccess; - - @Inject - public void setXWorkConverter(XWorkConverter conv) { - this.defaultConverter = new OgnlTypeConverterWrapper(conv); - } - - @Inject(XWorkConstants.DEV_MODE) - public void setDevMode(String mode) { - this.devMode = BooleanUtils.toBoolean(mode); - } - - @Inject(XWorkConstants.ENABLE_OGNL_EXPRESSION_CACHE) - public void setEnableExpressionCache(String cache) { - enableExpressionCache = BooleanUtils.toBoolean(cache); - } - - @Inject(value = XWorkConstants.ENABLE_OGNL_EVAL_EXPRESSION, required = false) - public void setEnableEvalExpression(String evalExpression) { - enableEvalExpression = "true".equals(evalExpression); - if(enableEvalExpression){ - LOG.warn("Enabling OGNL expression evaluation may introduce security risks " + - "(see http://struts.apache.org/release/2.3.x/docs/s2-013.html for further details)"); - } - } - - @Inject(value = XWorkConstants.OGNL_EXCLUDED_CLASSES, required = false) - public void setExcludedClasses(String commaDelimitedClasses) { - Set<String> classes = TextParseUtil.commaDelimitedStringToSet(commaDelimitedClasses); - for (String className : classes) { - try { - excludedClasses.add(Class.forName(className)); - } catch (ClassNotFoundException e) { - throw new ConfigurationException("Cannot load excluded class: " + className, e); - } - } - } - - @Inject(value = XWorkConstants.OGNL_EXCLUDED_PACKAGE_NAME_PATTERNS, required = false) - public void setExcludedPackageName(String commaDelimitedPackagePatterns) { - Set<String> packagePatterns = TextParseUtil.commaDelimitedStringToSet(commaDelimitedPackagePatterns); - for (String pattern : packagePatterns) { - excludedPackageNamePatterns.add(Pattern.compile(pattern)); - } - } - - public Set<Class<?>> getExcludedClasses() { - return excludedClasses; - } - - public Set<Pattern> getExcludedPackageNamePatterns() { - return excludedPackageNamePatterns; - } - - @Inject - public void setContainer(Container container) { - this.container = container; - } - - @Inject(value = XWorkConstants.ALLOW_STATIC_METHOD_ACCESS, required = false) - public void setAllowStaticMethodAccess(String allowStaticMethodAccess) { - this.allowStaticMethodAccess = Boolean.parseBoolean(allowStaticMethodAccess); - } - - /** - * Sets the object's properties using the default type converter, defaulting to not throw - * exceptions for problems setting the properties. - * - * @param props the properties being set - * @param o the object - * @param context the action context - */ - public void setProperties(Map<String, ?> props, Object o, Map<String, Object> context) { - setProperties(props, o, context, false); - } - - /** - * Sets the object's properties using the default type converter. - * - * @param props the properties being set - * @param o the object - * @param context the action context - * @param throwPropertyExceptions boolean which tells whether it should throw exceptions for - * problems setting the properties - */ - public void setProperties(Map<String, ?> props, Object o, Map<String, Object> context, boolean throwPropertyExceptions) throws ReflectionException{ - if (props == null) { - return; - } - - Ognl.setTypeConverter(context, getTypeConverterFromContext(context)); - - Object oldRoot = Ognl.getRoot(context); - Ognl.setRoot(context, o); - - for (Map.Entry<String, ?> entry : props.entrySet()) { - String expression = entry.getKey(); - internalSetProperty(expression, entry.getValue(), o, context, throwPropertyExceptions); - } - - Ognl.setRoot(context, oldRoot); - } - - /** - * Sets the properties on the object using the default context, defaulting to not throwing - * exceptions for problems setting the properties. - * - * @param properties - * @param o - */ - public void setProperties(Map<String, ?> properties, Object o) { - setProperties(properties, o, false); - } - - /** - * Sets the properties on the object using the default context. - * - * @param properties the property map to set on the object - * @param o the object to set the properties into - * @param throwPropertyExceptions boolean which tells whether it should throw exceptions for - * problems setting the properties - */ - public void setProperties(Map<String, ?> properties, Object o, boolean throwPropertyExceptions) { - Map context = createDefaultContext(o, null); - setProperties(properties, o, context, throwPropertyExceptions); - } - - /** - * Sets the named property to the supplied value on the Object, defaults to not throwing - * property exceptions. - * - * @param name the name of the property to be set - * @param value the value to set into the named property - * @param o the object upon which to set the property - * @param context the context which may include the TypeConverter - */ - public void setProperty(String name, Object value, Object o, Map<String, Object> context) { - setProperty(name, value, o, context, false); - } - - /** - * Sets the named property to the supplied value on the Object. - * - * @param name the name of the property to be set - * @param value the value to set into the named property - * @param o the object upon which to set the property - * @param context the context which may include the TypeConverter - * @param throwPropertyExceptions boolean which tells whether it should throw exceptions for - * 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); - - internalSetProperty(name, value, o, context, throwPropertyExceptions); - - Ognl.setRoot(context, oldRoot); - } - - /** - * Looks for the real target with the specified property given a root Object which may be a - * CompoundRoot. - * - * @return the real target or null if no object can be found with the specified property - */ - public Object getRealTarget(String property, Map<String, Object> context, Object root) throws OgnlException { - //special keyword, they must be cutting the stack - if ("top".equals(property)) { - return root; - } - - if (root instanceof CompoundRoot) { - // find real target - CompoundRoot cr = (CompoundRoot) root; - - try { - for (Object target : cr) { - if (OgnlRuntime.hasSetProperty((OgnlContext) context, target, property) - || OgnlRuntime.hasGetProperty((OgnlContext) context, target, property) - || OgnlRuntime.getIndexedPropertyType((OgnlContext) context, target.getClass(), property) != OgnlRuntime.INDEXED_PROPERTY_NONE - ) { - return target; - } - } - } catch (IntrospectionException ex) { - throw new ReflectionException("Cannot figure out real target class", ex); - } - - return null; - } - - return root; - } - - /** - * Wrapper around Ognl.setValue() to handle type conversion for collection elements. - * Ideally, this should be handled by OGNL directly. - */ - public void setValue(String name, Map<String, Object> context, Object root, Object value) throws OgnlException { - setValue(name, context, root, value, true); - } - - protected void setValue(String name, final Map<String, Object> context, final Object root, final Object value, final boolean evalName) throws OgnlException { - compileAndExecute(name, context, new OgnlTask<Void>() { - public Void execute(Object tree) throws OgnlException { - if (!evalName && isEvalExpression(tree, context)) { - throw new OgnlException("Eval expression cannot be used as parameter name"); - } - Ognl.setValue(tree, context, root, value); - return null; - } - }); - } - - private boolean isEvalExpression(Object tree, Map<String, Object> context) throws OgnlException { - if (tree instanceof SimpleNode) { - SimpleNode node = (SimpleNode) tree; - OgnlContext ognlContext = null; - - if (context!=null && context instanceof OgnlContext) { - ognlContext = (OgnlContext) context; - } - return node.isEvalChain(ognlContext); - } - return false; - } - - public Object getValue(final String name, final Map<String, Object> context, final Object root) throws OgnlException { - return compileAndExecute(name, context, new OgnlTask<Object>() { - public Object execute(Object tree) throws OgnlException { - return Ognl.getValue(tree, context, root); - } - }); - } - - public Object getValue(final String name, final Map<String, Object> context, final Object root, final Class resultType) throws OgnlException { - return compileAndExecute(name, context, new OgnlTask<Object>() { - public Object execute(Object tree) throws OgnlException { - return Ognl.getValue(tree, context, root, resultType); - } - }); - } - - - public Object compile(String expression) throws OgnlException { - return compile(expression, null); - } - - private <T> Object compileAndExecute(String expression, Map<String, Object> context, OgnlTask<T> task) throws OgnlException { - Object tree; - if (enableExpressionCache) { - tree = expressions.get(expression); - if (tree == null) { - tree = Ognl.parseExpression(expression); - checkEnableEvalExpression(tree, context); - } - } else { - tree = Ognl.parseExpression(expression); - checkEnableEvalExpression(tree, context); - } - - final T exec = task.execute(tree); - // if cache is enabled and it's a valid expression, puts it in - if(enableExpressionCache) { - expressions.putIfAbsent(expression, tree); - } - return exec; - } - - public Object compile(String expression, Map<String, Object> context) throws OgnlException { - return compileAndExecute(expression,context,new OgnlTask<Object>() { - public Object execute(Object tree) throws OgnlException { - return tree; - } - }); - } - - private void checkEnableEvalExpression(Object tree, Map<String, Object> context) throws OgnlException { - if (!enableEvalExpression && isEvalExpression(tree, context)) { - throw new OgnlException("Eval expressions has been disabled!"); - } - } - - /** - * Copies the properties in the object "from" and sets them in the object "to" - * using specified type converter, or {@link com.opensymphony.xwork2.conversion.impl.XWorkConverter} if none - * is specified. - * - * @param from the source object - * @param to the target object - * @param context the action context we're running under - * @param exclusions collection of method names to excluded from copying ( can be null) - * @param inclusions collection of method names to included copying (can be null) - * note if exclusions AND inclusions are supplied and not null nothing will get copied. - */ - public void copy(final Object from, final Object to, final Map<String, Object> context, Collection<String> exclusions, Collection<String> inclusions) { - if (from == null || to == null) { - LOG.warn("Attempting to copy from or to a null source. This is illegal and is bein skipped. This may be due to an error in an OGNL expression, action chaining, or some other event."); - 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; - - try { - fromPds = getPropertyDescriptors(from); - toPds = getPropertyDescriptors(to); - } catch (IntrospectionException e) { - LOG.error("An error occurred", e); - return; - } - - Map<String, PropertyDescriptor> toPdHash = new HashMap<>(); - - for (PropertyDescriptor toPd : toPds) { - toPdHash.put(toPd.getName(), toPd); - } - - for (PropertyDescriptor fromPd : fromPds) { - if (fromPd.getReadMethod() != null) { - boolean copy = true; - if (exclusions != null && exclusions.contains(fromPd.getName())) { - copy = false; - } else if (inclusions != null && !inclusions.contains(fromPd.getName())) { - copy = false; - } - - if (copy) { - PropertyDescriptor toPd = toPdHash.get(fromPd.getName()); - if ((toPd != null) && (toPd.getWriteMethod() != null)) { - try { - compileAndExecute(fromPd.getName(), context, new OgnlTask<Object>() { - public Void execute(Object expr) throws OgnlException { - Object value = Ognl.getValue(expr, contextFrom, from); - Ognl.setValue(expr, contextTo, to, value); - return null; - } - }); - - } catch (OgnlException e) { - LOG.debug("Got OGNL exception", e); - } - } - - } - - } - - } - } - - - /** - * Copies the properties in the object "from" and sets them in the object "to" - * using specified type converter, or {@link com.opensymphony.xwork2.conversion.impl.XWorkConverter} if none - * is specified. - * - * @param from the source object - * @param to the target object - * @param context the action context we're running under - */ - public void copy(Object from, Object to, Map<String, Object> context) { - copy(from, to, context, null, null); - } - - /** - * Get's the java beans property descriptors for the given source. - * - * @param source the source object. - * @return property descriptors. - * @throws IntrospectionException is thrown if an exception occurs during introspection. - */ - public PropertyDescriptor[] getPropertyDescriptors(Object source) throws IntrospectionException { - BeanInfo beanInfo = getBeanInfo(source); - return beanInfo.getPropertyDescriptors(); - } - - - /** - * Get's the java beans property descriptors for the given class. - * - * @param clazz the source object. - * @return property descriptors. - * @throws IntrospectionException is thrown if an exception occurs during introspection. - */ - public PropertyDescriptor[] getPropertyDescriptors(Class clazz) throws IntrospectionException { - BeanInfo beanInfo = getBeanInfo(clazz); - return beanInfo.getPropertyDescriptors(); - } - - /** - * Creates a Map with read properties for the given source object. - * <p/> - * If the source object does not have a read property (i.e. write-only) then - * the property is added to the map with the value <code>here is no read method for property-name</code>. - * - * @param source the source object. - * @return a Map with (key = read property name, value = value of read property). - * @throws IntrospectionException is thrown if an exception occurs during introspection. - * @throws OgnlException is thrown by OGNL if the property value could not be retrieved - */ - public Map<String, Object> getBeanMap(final Object source) throws IntrospectionException, OgnlException { - Map<String, Object> beanMap = new HashMap<>(); - final Map sourceMap = createDefaultContext(source, null); - PropertyDescriptor[] propertyDescriptors = getPropertyDescriptors(source); - for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { - final String propertyName = propertyDescriptor.getDisplayName(); - Method readMethod = propertyDescriptor.getReadMethod(); - if (readMethod != null) { - final Object value = compileAndExecute(propertyName, null, new OgnlTask<Object>() { - public Object execute(Object expr) throws OgnlException { - return Ognl.getValue(expr, sourceMap, source); - } - }); - beanMap.put(propertyName, value); - } else { - beanMap.put(propertyName, "There is no read method for " + propertyName); - } - } - return beanMap; - } - - /** - * Get's the java bean info for the given source object. Calls getBeanInfo(Class c). - * - * @param from the source object. - * @return java bean info. - * @throws IntrospectionException is thrown if an exception occurs during introspection. - */ - public BeanInfo getBeanInfo(Object from) throws IntrospectionException { - return getBeanInfo(from.getClass()); - } - - - /** - * Get's the java bean info for the given source. - * - * @param clazz the source class. - * @return java bean info. - * @throws IntrospectionException is thrown if an exception occurs during introspection. - */ - public BeanInfo getBeanInfo(Class clazz) throws IntrospectionException { - synchronized (beanInfoCache) { - BeanInfo beanInfo; - beanInfo = beanInfoCache.get(clazz); - if (beanInfo == null) { - beanInfo = Introspector.getBeanInfo(clazz, Object.class); - beanInfoCache.putIfAbsent(clazz, beanInfo); - } - return beanInfo; - } - } - - void internalSetProperty(String name, Object value, Object o, Map<String, Object> context, boolean throwPropertyExceptions) throws ReflectionException{ - try { - setValue(name, context, o, value); - } catch (OgnlException e) { - Throwable reason = e.getReason(); - String msg = "Caught OgnlException while setting property '" + name + "' on type '" + o.getClass().getName() + "'."; - Throwable exception = (reason == null) ? e : reason; - - if (throwPropertyExceptions) { - throw new ReflectionException(msg, exception); - } else if (devMode) { - LOG.warn(msg, exception); - } - } - } - - 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); - } - - protected Map createDefaultContext(Object root, ClassResolver classResolver) { - ClassResolver resolver = classResolver; - if (resolver == null) { - resolver = container.getInstance(CompoundRootAccessor.class); - } - - SecurityMemberAccess memberAccess = new SecurityMemberAccess(allowStaticMethodAccess); - memberAccess.setExcludedClasses(excludedClasses); - memberAccess.setExcludedPackageNamePatterns(excludedPackageNamePatterns); - - return Ognl.createDefaultContext(root, resolver, defaultConverter, memberAccess); - } - - private interface OgnlTask<T> { - T execute(Object tree) throws OgnlException; - } - -} http://git-wip-us.apache.org/repos/asf/struts/blob/31af5842/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java ---------------------------------------------------------------------- diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java deleted file mode 100644 index af7fbc5..0000000 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java +++ /dev/null @@ -1,479 +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.XWorkConstants; -import com.opensymphony.xwork2.XWorkException; -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.ClearableValueStack; -import com.opensymphony.xwork2.util.CompoundRoot; -import com.opensymphony.xwork2.util.MemberAccessValueStack; -import com.opensymphony.xwork2.util.ValueStack; -import com.opensymphony.xwork2.util.reflection.ReflectionContextState; -import ognl.*; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.regex.Pattern; - -/** - * Ognl implementation of a value stack that allows for dynamic Ognl expressions to be evaluated against it. When evaluating an expression, - * the stack will be searched down the stack, from the latest objects pushed in to the earliest, looking for a bean with a getter or setter - * for the given property or a method of the given name (depending on the expression being evaluated). - * - * @author Patrick Lightbody - * @author tm_jee - * @version $Date$ $Id$ - */ -public class OgnlValueStack implements Serializable, ValueStack, ClearableValueStack, MemberAccessValueStack { - - public static final String THROW_EXCEPTION_ON_FAILURE = OgnlValueStack.class.getName() + ".throwExceptionOnFailure"; - - private static final long serialVersionUID = 370737852934925530L; - - private static final String MAP_IDENTIFIER_KEY = "com.opensymphony.xwork2.util.OgnlValueStack.MAP_IDENTIFIER_KEY"; - private static final Logger LOG = LogManager.getLogger(OgnlValueStack.class); - - CompoundRoot root; - transient Map<String, Object> context; - Class defaultType; - Map<Object, Object> overrides; - transient OgnlUtil ognlUtil; - transient SecurityMemberAccess securityMemberAccess; - private transient XWorkConverter converter; - - private boolean devMode; - private boolean logMissingProperties; - - protected OgnlValueStack(XWorkConverter xworkConverter, CompoundRootAccessor accessor, TextProvider prov, boolean allowStaticAccess) { - setRoot(xworkConverter, accessor, new CompoundRoot(), allowStaticAccess); - push(prov); - } - - protected OgnlValueStack(ValueStack vs, XWorkConverter xworkConverter, CompoundRootAccessor accessor, boolean allowStaticAccess) { - setRoot(xworkConverter, accessor, new CompoundRoot(vs.getRoot()), allowStaticAccess); - } - - @Inject - public void setOgnlUtil(OgnlUtil ognlUtil) { - this.ognlUtil = ognlUtil; - securityMemberAccess.setExcludedClasses(ognlUtil.getExcludedClasses()); - securityMemberAccess.setExcludedPackageNamePatterns(ognlUtil.getExcludedPackageNamePatterns()); - } - - protected void setRoot(XWorkConverter xworkConverter, CompoundRootAccessor accessor, CompoundRoot compoundRoot, - boolean allowStaticMethodAccess) { - this.root = compoundRoot; - 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); - } - - @Inject(XWorkConstants.DEV_MODE) - public void setDevMode(String mode) { - this.devMode = BooleanUtils.toBoolean(mode); - } - - @Inject(value = "logMissingProperties", required = false) - public void setLogMissingProperties(String logMissingProperties) { - this.logMissingProperties = BooleanUtils.toBoolean(logMissingProperties); - } - - /** - * @see com.opensymphony.xwork2.util.ValueStack#getContext() - */ - public Map<String, Object> getContext() { - return context; - } - - /** - * @see com.opensymphony.xwork2.util.ValueStack#setDefaultType(java.lang.Class) - */ - public void setDefaultType(Class defaultType) { - this.defaultType = defaultType; - } - - /** - * @see com.opensymphony.xwork2.util.ValueStack#setExprOverrides(java.util.Map) - */ - public void setExprOverrides(Map<Object, Object> overrides) { - if (this.overrides == null) { - this.overrides = overrides; - } else { - this.overrides.putAll(overrides); - } - } - - /** - * @see com.opensymphony.xwork2.util.ValueStack#getExprOverrides() - */ - public Map<Object, Object> getExprOverrides() { - return this.overrides; - } - - /** - * @see com.opensymphony.xwork2.util.ValueStack#getRoot() - */ - public CompoundRoot getRoot() { - return root; - } - - /** - * @see com.opensymphony.xwork2.util.ValueStack#setParameter(String, Object) - */ - public void setParameter(String expr, Object value) { - setValue(expr, value, devMode, false); - } - - /** - - /** - * @see com.opensymphony.xwork2.util.ValueStack#setValue(java.lang.String, java.lang.Object) - */ - public void setValue(String expr, Object value) { - setValue(expr, value, devMode); - } - - /** - * @see com.opensymphony.xwork2.util.ValueStack#setValue(java.lang.String, java.lang.Object, boolean) - */ - public void setValue(String expr, Object value, boolean throwExceptionOnFailure) { - setValue(expr, value, throwExceptionOnFailure, true); - } - - private void setValue(String expr, Object value, boolean throwExceptionOnFailure, boolean evalExpression) { - Map<String, Object> context = getContext(); - try { - trySetValue(expr, value, throwExceptionOnFailure, context, evalExpression); - } catch (OgnlException e) { - handleOgnlException(expr, value, throwExceptionOnFailure, e); - } catch (RuntimeException re) { //XW-281 - handleRuntimeException(expr, value, throwExceptionOnFailure, re); - } finally { - cleanUpContext(context); - } - } - - private void trySetValue(String expr, Object value, boolean throwExceptionOnFailure, Map<String, Object> context, boolean evalExpression) throws OgnlException { - context.put(XWorkConverter.CONVERSION_PROPERTY_FULLNAME, expr); - context.put(REPORT_ERRORS_ON_NO_PROP, (throwExceptionOnFailure) ? Boolean.TRUE : Boolean.FALSE); - ognlUtil.setValue(expr, context, root, value, evalExpression); - } - - private void cleanUpContext(Map<String, Object> context) { - ReflectionContextState.clear(context); - context.remove(XWorkConverter.CONVERSION_PROPERTY_FULLNAME); - context.remove(REPORT_ERRORS_ON_NO_PROP); - } - - private void handleRuntimeException(String expr, Object value, boolean throwExceptionOnFailure, RuntimeException re) { - if (throwExceptionOnFailure) { - String message = ErrorMessageBuilder.create() - .errorSettingExpressionWithValue(expr, value) - .build(); - throw new XWorkException(message, re); - } else { - LOG.warn("Error setting value [{}] with expression [{}]", value, expr, re); - } - } - - private void handleOgnlException(String expr, Object value, boolean throwExceptionOnFailure, OgnlException e) { - boolean shouldLog = shouldLogMissingPropertyWarning(e); - String msg = null; - if (throwExceptionOnFailure || shouldLog) { - msg = ErrorMessageBuilder.create().errorSettingExpressionWithValue(expr, value).build(); - } - if (shouldLog) { - LOG.warn(msg, e); - } - - if (throwExceptionOnFailure) { - throw new XWorkException(msg, e); - } - } - - /** - * @see com.opensymphony.xwork2.util.ValueStack#findString(java.lang.String) - */ - public String findString(String expr) { - return (String) findValue(expr, String.class); - } - - public String findString(String expr, boolean throwExceptionOnFailure) { - return (String) findValue(expr, String.class, throwExceptionOnFailure); - } - - /** - * @see com.opensymphony.xwork2.util.ValueStack#findValue(java.lang.String) - */ - public Object findValue(String expr, boolean throwExceptionOnFailure) { - try { - setupExceptionOnFailure(throwExceptionOnFailure); - return tryFindValueWhenExpressionIsNotNull(expr); - } catch (OgnlException e) { - return handleOgnlException(expr, throwExceptionOnFailure, e); - } catch (Exception e) { - return handleOtherException(expr, throwExceptionOnFailure, e); - } finally { - ReflectionContextState.clear(context); - } - } - - private void setupExceptionOnFailure(boolean throwExceptionOnFailure) { - if (throwExceptionOnFailure) { - context.put(THROW_EXCEPTION_ON_FAILURE, true); - } - } - - private Object tryFindValueWhenExpressionIsNotNull(String expr) throws OgnlException { - if (expr == null) { - return null; - } - return tryFindValue(expr); - } - - private Object handleOtherException(String expr, boolean throwExceptionOnFailure, Exception e) { - logLookupFailure(expr, e); - - if (throwExceptionOnFailure) - throw new XWorkException(e); - - return findInContext(expr); - } - - private Object tryFindValue(String expr) throws OgnlException { - Object value; - expr = lookupForOverrides(expr); - if (defaultType != null) { - value = findValue(expr, defaultType); - } else { - value = getValueUsingOgnl(expr); - if (value == null) { - value = findInContext(expr); - } - } - return value; - } - - private String lookupForOverrides(String expr) { - if ((overrides != null) && overrides.containsKey(expr)) { - expr = (String) overrides.get(expr); - } - return expr; - } - - private Object getValueUsingOgnl(String expr) throws OgnlException { - try { - return ognlUtil.getValue(expr, context, root); - } finally { - context.remove(THROW_EXCEPTION_ON_FAILURE); - } - } - - public Object findValue(String expr) { - return findValue(expr, false); - } - - /** - * @see com.opensymphony.xwork2.util.ValueStack#findValue(java.lang.String, java.lang.Class) - */ - public Object findValue(String expr, Class asType, boolean throwExceptionOnFailure) { - try { - setupExceptionOnFailure(throwExceptionOnFailure); - return tryFindValueWhenExpressionIsNotNull(expr, asType); - } catch (OgnlException e) { - final Object value = handleOgnlException(expr, throwExceptionOnFailure, e); - return converter.convertValue(getContext(), value, asType); - } catch (Exception e) { - final Object value = handleOtherException(expr, throwExceptionOnFailure, e); - return converter.convertValue(getContext(), value, asType); - } finally { - ReflectionContextState.clear(context); - } - } - - private Object tryFindValueWhenExpressionIsNotNull(String expr, Class asType) throws OgnlException { - if (expr == null) { - return null; - } - return tryFindValue(expr, asType); - } - - private Object handleOgnlException(String expr, boolean throwExceptionOnFailure, OgnlException e) { - Object ret = findInContext(expr); - if (ret == null) { - if (shouldLogMissingPropertyWarning(e)) { - LOG.warn("Could not find property [{}]!", expr, e); - } - if (throwExceptionOnFailure) { - throw new XWorkException(e); - } - } - return ret; - } - - private boolean shouldLogMissingPropertyWarning(OgnlException e) { - return (e instanceof NoSuchPropertyException || e instanceof MethodFailedException) - && devMode && logMissingProperties; - } - - private Object tryFindValue(String expr, Class asType) throws OgnlException { - Object value = null; - try { - expr = lookupForOverrides(expr); - value = getValue(expr, asType); - if (value == null) { - value = findInContext(expr); - return converter.convertValue(getContext(), value, asType); - } - } finally { - context.remove(THROW_EXCEPTION_ON_FAILURE); - } - return value; - } - - private Object getValue(String expr, Class asType) throws OgnlException { - return ognlUtil.getValue(expr, context, root, asType); - } - - private Object findInContext(String name) { - return getContext().get(name); - } - - public Object findValue(String expr, Class asType) { - return findValue(expr, asType, false); - } - - /** - * Log a failed lookup, being more verbose when devMode=true. - * - * @param expr The failed expression - * @param e The thrown exception. - */ - private void logLookupFailure(String expr, Exception e) { - if (devMode && LOG.isWarnEnabled()) { - LOG.warn("Caught an exception while evaluating expression '{}' against value stack", expr, e); - LOG.warn("NOTE: Previous warning message was issued due to devMode set to true."); - } else { - LOG.debug("Caught an exception while evaluating expression '{}' against value stack", expr, e); - } - } - - /** - * @see com.opensymphony.xwork2.util.ValueStack#peek() - */ - public Object peek() { - return root.peek(); - } - - /** - * @see com.opensymphony.xwork2.util.ValueStack#pop() - */ - public Object pop() { - return root.pop(); - } - - /** - * @see com.opensymphony.xwork2.util.ValueStack#push(java.lang.Object) - */ - public void push(Object o) { - root.push(o); - } - - /** - * @see com.opensymphony.xwork2.util.ValueStack#set(java.lang.String, java.lang.Object) - */ - public void set(String key, Object o) { - //set basically is backed by a Map pushed on the stack with a key being put on the map and the Object being the value - Map setMap = retrieveSetMap(); - setMap.put(key, o); - } - - private Map retrieveSetMap() { - Map setMap; - Object topObj = peek(); - if (shouldUseOldMap(topObj)) { - setMap = (Map) topObj; - } else { - setMap = new HashMap(); - setMap.put(MAP_IDENTIFIER_KEY, ""); - push(setMap); - } - return setMap; - } - - /** - * check if this is a Map put on the stack for setting if so just use the old map (reduces waste) - */ - private boolean shouldUseOldMap(Object topObj) { - return topObj instanceof Map && ((Map) topObj).get(MAP_IDENTIFIER_KEY) != null; - } - - /** - * @see com.opensymphony.xwork2.util.ValueStack#size() - */ - public int size() { - return root.size(); - } - - private Object readResolve() { - // TODO: this should be done better - ActionContext ac = ActionContext.getContext(); - Container cont = ac.getContainer(); - XWorkConverter xworkConverter = cont.getInstance(XWorkConverter.class); - CompoundRootAccessor accessor = (CompoundRootAccessor) cont.getInstance(PropertyAccessor.class, CompoundRoot.class.getName()); - TextProvider prov = cont.getInstance(TextProvider.class, "system"); - boolean allow = BooleanUtils.toBoolean(cont.getInstance(String.class, XWorkConstants.ALLOW_STATIC_METHOD_ACCESS)); - OgnlValueStack aStack = new OgnlValueStack(xworkConverter, accessor, prov, allow); - aStack.setOgnlUtil(cont.getInstance(OgnlUtil.class)); - aStack.setRoot(xworkConverter, accessor, this.root, allow); - - return aStack; - } - - - public void clearContextValues() { - //this is an OGNL ValueStack so the context will be an OgnlContext - //it would be better to make context of type OgnlContext - ((OgnlContext) context).getValues().clear(); - } - - public void setAcceptProperties(Set<Pattern> acceptedProperties) { - securityMemberAccess.setAcceptProperties(acceptedProperties); - } - - public void setExcludeProperties(Set<Pattern> excludeProperties) { - securityMemberAccess.setExcludeProperties(excludeProperties); - } - - @Inject - public void setXWorkConverter(final XWorkConverter converter) { - this.converter = converter; - } -}
