value stack code

1)  ParametersInterceptor

 

doIntercept

 

 

public String doIntercept(ActionInvocation invocation) throws Exception {

        Object action = invocation.getAction() ;

        if (!(action instanceof NoParameters)) {

            ActionContext ac = invocation.getInvocationContext();

            final Map<String, Object> parameters = retrieveParameters(ac);

 

            if ( LOG .isDebugEnabled()) {

                LOG .debug( "Setting params " + getParameterLogMap(parameters));

            }

 

            if (parameters != null ) {

                Map<String, Object> contextMap = ac.getContextMap();

                try {

                    ReflectionContextState.setCreatingNullObjects (contextMap, true );

                    ReflectionContextState.setDenyMethodExecution (contextMap, true );

                    ReflectionContextState.setReportingConversionErrors (contextMap, true );

 

                    ValueStack stack = ac.getValueStack();

                    setParameters(action, stack, parameters);

                } finally {

                    ReflectionContextState.setCreatingNullObjects (contextMap, false );

                    ReflectionContextState.setDenyMethodExecution (contextMap, false );

                    ReflectionContextState.setReportingConversionErrors (contextMap, false );

                }

            }

        }

        return invocation.invoke();

    }

 

setParameters

 

protected void setParameters(Object action, ValueStack stack, final Map<String, Object> parameters) {

        ParameterNameAware parameterNameAware = (action instanceof ParameterNameAware)

                ? (ParameterNameAware) action : null ;

 

        Map<String, Object> params;

        Map<String, Object> acceptableParameters;

        if ( ordered ) {

            params = new TreeMap<String, Object>(getOrderedComparator());

            acceptableParameters = new TreeMap<String, Object>(getOrderedComparator());

            params.putAll(parameters);

        } else {

            params = new TreeMap<String, Object>(parameters);

            acceptableParameters = new TreeMap<String, Object>();

        }

 

        for (Map.Entry<String, Object> entry : params.entrySet()) {

            String name = entry.getKey();

 

            boolean acceptableName = acceptableName(name)

                    && (parameterNameAware == null

                    || parameterNameAware.acceptableParameterName(name));

 

            if (acceptableName) {

                acceptableParameters.put(name, entry.getValue());

            }

        }

 

        ValueStack newStack = valueStackFactory .createValueStack(stack);

        boolean clearableStack = newStack instanceof ClearableValueStack;

        if (clearableStack) {

            //if the stack's context can be cleared, do that to prevent OGNL

            //from having access to objects in the stack, see XW-641

            ((ClearableValueStack)newStack).clearContextValues();

            Map<String, Object> context = newStack.getContext ();

            ReflectionContextState.setCreatingNullObjects (context, true );

            ReflectionContextState.setDenyMethodExecution (context, true );

            ReflectionContextState.setReportingConversionErrors (context, true );

 

            //keep locale from original context

            context.put(ActionContext. LOCALE , stack.getContext ().get(ActionContext. LOCALE ));

        }

 

        boolean memberAccessStack = newStack instanceof MemberAccessValueStack;

        if (memberAccessStack) {

            //block or allow access to properties

            //see WW-2761 for more details

            MemberAccessValueStack accessValueStack = (MemberAccessValueStack) newStack;

            accessValueStack.setAcceptProperties( acceptParams );

            accessValueStack.setExcludeProperties( excludeParams );

        }

 

        for (Map.Entry<String, Object> entry : acceptableParameters.entrySet()) {

            String name = entry.getKey();

            Object value = entry.getValue();

            try {

                newStack.setValue(name, value);

            } catch (RuntimeException e) {

                if ( devMode ) {

                    String developerNotification = LocalizedTextUtil.findText (ParametersInterceptor. class , "devmode.notification" , ActionContext.getContext ().getLocale(), "Developer Notification:/n{0}" , new Object[]{

                             "Unexpected Exception caught setting '" + name + "' on '" + action.getClass() + ": " + e.getMessage()

                    });

                    LOG .error(developerNotification);

                    if (action instanceof ValidationAware) {

                         ((ValidationAware) action).addActionMessage(developerNotification);

                    }

                }

            }

        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值