Package com.opensymphony.xwork2.config.entities

Examples of com.opensymphony.xwork2.config.entities.ResultTypeConfig


        handler.setServletContext((ServletContext)mockServletContext.proxy());
    }

    public void testBuildResult() {
        ActionContext ctx = new ActionContext(new HashMap());
        ResultTypeConfig config = new ResultTypeConfig.Builder("null", SomeResult.class.getName()).defaultResultParam("location").build();
       
        Result result = handler.buildResult("/foo.jsp", "success", config, ctx);
        assertNotNull(result);
        assertTrue(result instanceof SomeResult);
        assertEquals("/foo.jsp", ((SomeResult) result).location);
View Full Code Here


            // If the URL is /foo and there is an action we can redirect to, send the redirect to /foo/.
            // However, if that action is not in the same namespace, it is the default, so I'm not going
            // to return that.
            if (!actionName.equals("") && redirectToSlash) {
                ResultTypeConfig redirectResultTypeConfig = parentPackage.getAllResultTypeConfigs().get("redirect");
                String redirectNamespace = namespace + "/" + actionName;
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Checking if there is an action named index in the namespace [#0]",
                            redirectNamespace);
                }
View Full Code Here

            if (chainedToConfig != null) {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Action [#0] used as chain result for [#1] and result [#2]", chainedTo, actionName, resultCode);
                }

                ResultTypeConfig chainResultType = pkg.getAllResultTypeConfigs().get("chain");
                result = buildResult(chainedTo, resultCode, chainResultType, actionContext);
            }
        }

        return result;
View Full Code Here

    @SuppressWarnings(value = {"unchecked"})
    protected ResultConfig createResultConfig(Class<?> actionClass, ResultInfo info,
            PackageConfig packageConfig, Result result) {
        // Look up by the type that was determined from the annotation or by the extension in the
        // ResultInfo class
        ResultTypeConfig resultTypeConfig = packageConfig.getAllResultTypeConfigs().get(info.type);
        if (resultTypeConfig == null) {
            throw new ConfigurationException("The Result type [" + info.type + "] which is" +
                " defined in the Result annotation on the class [" + actionClass + "] or determined" +
                " by the file extension or is the default result type for the PackageConfig of the" +
                " action, could not be found as a result-type defined for the Struts/XWork package [" +
                packageConfig.getName() + "]");
        }

        // Add the default parameters for the result type config (if any)
        HashMap<String, String> params = new HashMap<String, String>();
        if (resultTypeConfig.getParams() != null) {
            params.putAll(resultTypeConfig.getParams());
        }

        // Handle the annotation
        if (result != null) {
            params.putAll(StringTools.createParameterMap(result.params()));
        }

        // Map the location to the default param for the result or a param named location
        if (info.location != null) {
            String defaultParamName = resultTypeConfig.getDefaultResultParam();
            if (!params.containsKey(defaultParamName)) {
                params.put(defaultParamName, info.location);
            }
        }

        return new ResultConfig.Builder(info.name, resultTypeConfig.getClassName()).addParams(params).build();
    }
View Full Code Here

        String determineType(String location, PackageConfig packageConfig,
                Map<String, ResultTypeConfig> resultsByExtension) {
            int indexOfDot = location.lastIndexOf(".");
            if (indexOfDot > 0) {
                String extension = location.substring(indexOfDot + 1);
                ResultTypeConfig resultTypeConfig = resultsByExtension.get(extension);
                if (resultTypeConfig != null) {
                    return resultTypeConfig.getName();
                } else
                    throw new ConfigurationException("Unable to find a result type for extension [" + extension + "] " +
                        "in location attribute [" + location + "].");
            } else {
                return packageConfig.getFullDefaultResultType();
View Full Code Here

        // resultValue 有两种可能:
        // 1.一种直接是字面量(比如 dispatcher:/xxx.html)
        // 2.另一种是 json 参数(比如 dispatcher:{'location': '/xxx.html'} )

        ResultTypeConfig typeConfig = resultTypes.get(resultType);
        //如果没有默认参数
        if (Strings.isNullOrEmpty(typeConfig.getDefaultResultParam())) {
            ResultConfig.Builder resultBuilder = createResultConfigFromResultType(resultCode, typeConfig);
            // 只有返回类型, 例如是 "json"
            if (resultCode.length() == resultType.length()) {
                return resultBuilder.build();
            }
            //或者 ":" 后面有 json 参数
            if (resultCode.indexOf(":") == resultType.length()) {
                String resultParam = resultCode.substring(resultType.length() + 1);
                addParamByJSON(resultBuilder, resultParam);
                return resultBuilder.build();
            }
        }
        //如果有默认参数
        else {
            //  如果是 "type:" 这种形式
            if (resultCode.indexOf(":") == resultType.length()) {
                ResultConfig.Builder resultBuilder = createResultConfigFromResultType(resultCode, typeConfig);

                // 拿到参数部分(":" 后面的部分)
                String resultParam = resultCode.substring(resultType.length() + 1);
                String location = null; // 通常是 defaultParam
                if (isJSONObject(resultParam)) { //判断是否是 json 格式
                    /**
                     * 如果是 json 形式传递 param(并非 struts json 插件)的返回结果,
                     * 如果有 location ,也需要进行路径相对路径或绝对路径转换
                     */
                    Map<String, String> params = addParamByJSON(resultBuilder, resultParam);
                    location = params.get(typeConfig.getDefaultResultParam());
                } else {
                    location = resultParam;
                }
                // 动态处理内容的路径
                location = parsePath(contentBase, routeMapping, location);
                resultBuilder.addParam(typeConfig.getDefaultResultParam(), location);
                return resultBuilder.build();
            }
        }

        return null;
View Full Code Here

        String defaultResult = packageContext.getFullDefaultResultType();

        for (Map.Entry<String, ResultConfig> entry : results.entrySet()) {

            if (entry.getValue() == null) {
                ResultTypeConfig resultTypeConfig = packageContext.getAllResultTypeConfigs().get(defaultResult);
                entry.setValue(new ResultConfig.Builder(null, resultTypeConfig.getClassName()).build());
            }
        }
    }
View Full Code Here

        handler.setServletContext((ServletContext)mockServletContext.proxy());
    }

    public void testBuildResult() {
        ActionContext ctx = new ActionContext(new HashMap());
        ResultTypeConfig config = new ResultTypeConfig.Builder("null", SomeResult.class.getName()).defaultResultParam("location").build();
       
        Result result = handler.buildResult("/foo.jsp", "success", config, ctx);
        assertNotNull(result);
        assertTrue(result instanceof SomeResult);
        assertEquals("/foo.jsp", ((SomeResult) result).location);
View Full Code Here

            // If the URL is /foo and there is an action we can redirect to, send the redirect to /foo/.
            // However, if that action is not in the same namespace, it is the default, so I'm not going
            // to return that.
            if (!actionName.equals("") && redirectToSlash) {
                ResultTypeConfig redirectResultTypeConfig = parentPackage.getAllResultTypeConfigs().get("redirect");
                String redirectNamespace = namespace + "/" + actionName;
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Checking if there is an action named index in the namespace [#0]",
                            redirectNamespace);
                }
View Full Code Here

            if (chainedToConfig != null) {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Action [#0] used as chain result for [#1] and result [#2]", chainedTo, actionName, resultCode);
                }

                ResultTypeConfig chainResultType = pkg.getAllResultTypeConfigs().get("chain");
                result = buildResult(chainedTo, resultCode, chainResultType, actionContext);
            }
        }

        return result;
View Full Code Here

TOP

Related Classes of com.opensymphony.xwork2.config.entities.ResultTypeConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.