⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parametersinterceptor.java

📁 在Struts2中的jar包xwork的源代码.版本为2.0.7
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if (ordered) {            params = new TreeMap(getOrderedComparator());            params.putAll(parameters);        } else {            params = new TreeMap(parameters);        }        ValueStack newStack = ValueStackFactory.getFactory().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();            OgnlContextState.setCreatingNullObjects(context, true);            OgnlContextState.setDenyMethodExecution(context, true);            OgnlContextState.setReportingConversionErrors(context, true);        }        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 (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();) {            Map.Entry entry = (Map.Entry) iterator.next();            String name = entry.getKey().toString();            boolean acceptableName = acceptableName(name)                    && (parameterNameAware == null                    || parameterNameAware.acceptableParameterName(name));            if (acceptableName) {                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[]{                                e.getMessage()                        });                        LOG.error(developerNotification);                        if (action instanceof ValidationAware) {                            ((ValidationAware) action).addActionMessage(developerNotification);                        }                    } else {                        LOG.error("ParametersInterceptor - [setParameters]: Unexpected Exception caught setting '" + name + "' on '" + action.getClass() + ": " + e.getMessage());                    }                }            }        }        if (clearableStack && (stack.getContext() != null) && (newStack.getContext() != null))            stack.getContext().put(ActionContext.CONVERSION_ERRORS, newStack.getContext().get(ActionContext.CONVERSION_ERRORS));    }    /**     * Gets an instance of the comparator to use for the ordered sorting.  Override this     * method to customize the ordering of the parameters as they are set to the     * action.     *     * @return A comparator to sort the parameters     */    protected Comparator getOrderedComparator() {        return rbCollator;    }    private String getParameterLogMap(Map parameters) {        if (parameters == null) {            return "NONE";        }        StringBuffer logEntry = new StringBuffer();        for (Iterator paramIter = parameters.entrySet().iterator(); paramIter.hasNext();) {            Map.Entry entry = (Map.Entry) paramIter.next();            logEntry.append(String.valueOf(entry.getKey()));            logEntry.append(" => ");            if (entry.getValue() instanceof Object[]) {                Object[] valueArray = (Object[]) entry.getValue();                logEntry.append("[ ");                for (int indexA = 0; indexA < (valueArray.length - 1); indexA++) {                    Object valueAtIndex = valueArray[indexA];                    logEntry.append(valueAtIndex);                    logEntry.append(String.valueOf(valueAtIndex));                    logEntry.append(", ");                }                logEntry.append(String.valueOf(valueArray[valueArray.length - 1]));                logEntry.append(" ] ");            } else {                logEntry.append(String.valueOf(entry.getValue()));            }        }        return logEntry.toString();    }    protected boolean acceptableName(String name) {        if (isAccepted(name) && !isExcluded(name)) {            return true;        }        return false;    }    protected boolean isAccepted(String paramName) {        if (!this.acceptParams.isEmpty()) {            for (Pattern pattern : acceptParams) {                Matcher matcher = pattern.matcher(paramName);                if (matcher.matches()) {                    return true;                }            }        }        return acceptedPattern.matcher(paramName).matches();    }    protected boolean isExcluded(String paramName) {        if (!this.excludeParams.isEmpty()) {            for (Pattern pattern : excludeParams) {                Matcher matcher = pattern.matcher(paramName);                if (matcher.matches()) {                    return true;                }            }        }        return false;    }    /**     * Whether to order the parameters or not     *     * @return True to order     */    public boolean isOrdered() {        return ordered;    }    /**     * Set whether to order the parameters by object depth or not     *     * @param ordered True to order them     */    public void setOrdered(boolean ordered) {        this.ordered = ordered;    }    /**     * Gets a set of regular expressions of parameters to remove     * from the parameter map     *     * @return A set of compiled regular expression patterns     */    protected Set getExcludeParamsSet() {        return excludeParams;    }    /**     * Sets a comma-delimited list of regular expressions to match     * parameters that should be removed from the parameter map.     *     * @param commaDelim A comma-delimited list of regular expressions     */    public void setExcludeParams(String commaDelim) {        Collection<String> excludePatterns = asCollection(commaDelim);        if (excludePatterns != null) {            excludeParams = new HashSet<Pattern>();            for (String pattern : excludePatterns) {                excludeParams.add(Pattern.compile(pattern));            }        }    }    /**     * Return a collection from the comma delimited String.     *     * @param commaDelim     * @return A collection from the comma delimited String.     */    private Collection asCollection(String commaDelim) {        if (commaDelim == null || commaDelim.trim().length() == 0) {            return null;        }        return TextParseUtil.commaDelimitedStringToSet(commaDelim);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -