Package com.opensymphony.xwork2.config.entities

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


                    LOG.debug("The '" + actionConfig.getName()
                            + viewActionPostfix + "' action is overridden in '"
                            + packageName + "' package.");
                }
            } else {
                ResultConfig inputResultConfig = actionConfig.getResults().get(
                        Action.INPUT);
                if (inputResultConfig == null) {
                    throw new ConfigurationException("There is no '"
                            + Action.INPUT + "' result defined for action '"
                            + actionConfig.getName() + "' in '" + packageName
                            + "' package.", actionConfig);
                }

                ResultConfig resultConfig = new ResultConfig.Builder(
                        Action.SUCCESS, inputResultConfig.getClassName())
                        .addParams(inputResultConfig.getParams()).build();
                // build action configuration
                ActionConfig act = new ActionConfig.Builder(packageName,
                        actionConfig.getName() + viewActionPostfix,
                        actionConfig.getClassName())
                        .methodName(viewActionMethod)
                        .addInterceptors(actionConfig.getInterceptors())
                        .addResultConfig(resultConfig).build();
                viewActionConfigs.add(act);
            }

            String nextKey = null;
            if (mapkeyitr.hasNext()) {
                // peek
                nextKey = mapkeyitr.next();
                mapkeyitr.previous();
            }

            String nextActionVal = null;
            String prevActionVal = null;
            if (nextKey == null) {
                nextActionVal = null;
            } else {
                ActionConfig nextActionConfig = actionsStepMap.get(nextKey);
                nextActionVal = nextActionConfig.getName();
            }

            if (prevKey == null) {
                prevActionVal = ActionFlowInterceptor.FIRST_FLOW_ACTION_NAME;

                // first action
                ActionFlowStepConfig.Builder stepConfigBuilder = new ActionFlowStepConfig.Builder(
                        0, actionConfig.getName(),
                        ActionFlowInterceptor.FIRST_FLOW_ACTION_NAME);
                ActionFlowStepConfig stepConfig = stepConfigBuilder.build();
                actionFlows.put(ActionFlowInterceptor.FIRST_FLOW_ACTION_NAME,
                        stepConfig);
            } else {
                prevActionVal = actionsStepMap.get(prevKey).getName();
            }

            ActionFlowStepConfig.Builder stepConfigBuilder = new ActionFlowStepConfig.Builder(
                    index, nextActionVal, prevActionVal);
            ActionFlowStepConfig stepConfig = stepConfigBuilder.build();
            actionFlows.put(actionConfig.getName(), stepConfig);

            prevKey = key;
            index++;
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug("Created action flow mapping: " + actionFlows);
        }

        if (actionFlows != null && !actionFlows.isEmpty()) {
            // build new package configuration with special actions
            PackageConfig.Builder pcb = new PackageConfig.Builder(packageConfig);

            // view global result check
            if (packageConfig.getAllGlobalResults().containsKey(
                    ActionFlowInterceptor.GLOBAL_VIEW_RESULT)) {
                ResultConfig rs = packageConfig.getAllGlobalResults().get(
                        ActionFlowInterceptor.GLOBAL_VIEW_RESULT);
                if (!ServletActionRedirectResult.class.getName().equals(
                        rs.getClassName())) {
                    throw new ConfigurationException(
                            "The '"
                                    + ActionFlowInterceptor.GLOBAL_VIEW_RESULT
                                    + "' global result type must be 'redirectAction' in package '"
                                    + packageName + "'.", rs);
                } else if (!("${" + ActionFlowInterceptor.VIEW_ACTION_PARAM + "}")
                        .equals(rs.getParams().get(
                                ServletActionRedirectResult.DEFAULT_PARAM))) {
                    throw new ConfigurationException("The '"
                            + ActionFlowInterceptor.GLOBAL_VIEW_RESULT
                            + "' global result '"
                            + ServletActionRedirectResult.DEFAULT_PARAM
                            + "' parameter must be '${"
                            + ActionFlowInterceptor.VIEW_ACTION_PARAM
                            + "}' in package '" + packageName + "'.", rs);
                }
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("There is no 'view' global result with name '"
                            + ActionFlowInterceptor.GLOBAL_VIEW_RESULT
                            + "' defined in '" + packageName
                            + "' package. Creating one.", packageConfig);
                }

                // add view global result
                ResultConfig viewGlobalResult = new ResultConfig.Builder(
                        ActionFlowInterceptor.GLOBAL_VIEW_RESULT,
                        ServletActionRedirectResult.class.getName()).addParam(
                        ServletActionRedirectResult.DEFAULT_PARAM,
                        "${" + ActionFlowInterceptor.VIEW_ACTION_PARAM + "}")
                        .build();
                pcb.addGlobalResultConfig(viewGlobalResult);
            }

            // add view actions
            if (viewActionConfigs != null && !viewActionConfigs.isEmpty()) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("View action configurations: "
                            + viewActionConfigs);
                }

                for (ActionConfig ac : viewActionConfigs) {
                    pcb.addActionConfig(ac.getName(), ac);
                }
            }

            // TODO add interceptors ?
            // previous action
            if (actionConfigs.containsKey(prevActionName)) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("The '" + prevActionName
                            + "' action is overridden in '" + packageName
                            + "' package.");
                }

                // previous action check
                Map<String, ResultConfig> rs = actionConfigs
                        .get(prevActionName).getResults();
                if (rs == null
                        || rs.isEmpty()
                        || !rs.containsKey(Action.SUCCESS)
                        || !ServletActionRedirectResult.class.getName().equals(
                                rs.get(Action.SUCCESS).getClassName())) {
                    throw new ConfigurationException("The '" + prevActionName
                            + "' action must define '" + Action.SUCCESS
                            + "' result of 'redirectAction' type in package '"
                            + packageName + "'.",
                            actionConfigs.get(prevActionName));
                } else if (!("${" + ActionFlowInterceptor.PREV_ACTION_PARAM + "}")
                        .equals(rs.get(Action.SUCCESS).getParams()
                                .get(ServletActionRedirectResult.DEFAULT_PARAM))) {
                    throw new ConfigurationException("The '" + prevActionName
                            + "' action '" + Action.SUCCESS + "' result '"
                            + ServletActionRedirectResult.DEFAULT_PARAM
                            + "' parameter must be '${"
                            + ActionFlowInterceptor.PREV_ACTION_PARAM
                            + "}' in package '" + packageName + "'.",
                            rs.get(Action.SUCCESS));
                }
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("There is no 'previous' action with name '"
                            + prevActionName + "' found in '" + packageName
                            + "' package. Creating one.");
                }

                // add previous action
                ResultConfig prevResultConfig = new ResultConfig.Builder(
                        Action.SUCCESS,
                        ServletActionRedirectResult.class.getName()).addParam(
                        ServletActionRedirectResult.DEFAULT_PARAM,
                        "${" + ActionFlowInterceptor.PREV_ACTION_PARAM + "}")
                        .build();
                // build previous action configuration
                ActionConfig prevAct = new ActionConfig.Builder(packageName,
                        prevActionName, "").addResultConfig(prevResultConfig)
                        .build();
                pcb.addActionConfig(prevAct.getName(), prevAct);
            }

            // next action
            if (actionConfigs.containsKey(nextActionName)) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("The '" + nextActionName
                            + "' action is overridden in '" + packageName
                            + "' package.");
                }

                // next action check
                Map<String, ResultConfig> rs = actionConfigs
                        .get(nextActionName).getResults();
                if (rs == null
                        || rs.isEmpty()
                        || !ActionChainResult.class.getName().equals(
                                rs.get(Action.SUCCESS).getClassName())) {
                    throw new ConfigurationException("The '" + nextActionName
                            + "' action must define '" + Action.SUCCESS
                            + "' result of 'chain' type in package '"
                            + packageName + "'.",
                            actionConfigs.get(nextActionName));
                } else if (!("${" + ActionFlowInterceptor.NEXT_ACTION_PARAM + "}")
                        .equals(rs.get(Action.SUCCESS).getParams()
                                .get(ActionChainResult.DEFAULT_PARAM))) {
                    throw new ConfigurationException("The '" + nextActionName
                            + "' action '" + Action.SUCCESS + "' result '"
                            + ActionChainResult.DEFAULT_PARAM
                            + "' parameter must be '${"
                            + ActionFlowInterceptor.NEXT_ACTION_PARAM
                            + "}' in package '" + packageName + "'.",
                            rs.get(Action.SUCCESS));
                }
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("There is no 'next' action with name '"
                            + nextActionName + "' found in '" + packageName
                            + "' package. Creating one.");
                }

                // add next action
                ResultConfig nextResultConfig = new ResultConfig.Builder(
                        Action.SUCCESS, ActionChainResult.class.getName())
                        .addParam(
                                ActionChainResult.DEFAULT_PARAM,
                                "${" + ActionFlowInterceptor.NEXT_ACTION_PARAM
                                        + "}").build();
View Full Code Here


*/
public class ServletActionRedirectResultTest extends StrutsTestCase {

    public void testIncludeParameterInResultWithConditionParseOn() throws Exception {

        ResultConfig resultConfig = new ResultConfig();
        resultConfig.addParam("actionName", "someActionName");
        resultConfig.addParam("namespace", "someNamespace");
        resultConfig.addParam("encode", "true");
        resultConfig.addParam("parse", "true");
        resultConfig.addParam("location", "someLocation");
        resultConfig.addParam("prependServletContext", "true");
        resultConfig.addParam("method", "someMethod");
        resultConfig.addParam("param1", "${#value1}");
        resultConfig.addParam("param2", "${#value2}");
        resultConfig.addParam("param3", "${#value3}");



        ActionContext context = ActionContext.getContext();
        ValueStack stack = context.getValueStack();
View Full Code Here

        control.verify();
    }

    public void testIncludeParameterInResult() throws Exception {

        ResultConfig resultConfig = new ResultConfig();
        resultConfig.addParam("actionName", "someActionName");
        resultConfig.addParam("namespace", "someNamespace");
        resultConfig.addParam("encode", "true");
        resultConfig.addParam("parse", "true");
        resultConfig.addParam("location", "someLocation");
        resultConfig.addParam("prependServletContext", "true");
        resultConfig.addParam("method", "someMethod");
        resultConfig.addParam("param1", "value 1");
        resultConfig.addParam("param2", "value 2");
        resultConfig.addParam("param3", "value 3");

        ActionContext context = ActionContext.getContext();
        MockHttpServletRequest req = new MockHttpServletRequest();
        MockHttpServletResponse res = new MockHttpServletResponse();
        context.put(ServletActionContext.HTTP_REQUEST, req);
View Full Code Here

                    LOG.warn("ExecuteAndWait interceptor has detected that no result named 'wait' is available. " +
                            "Defaulting to a plain built-in wait page. It is highly recommend you " +
                            "provide an action-specific or global result named '" + WAIT +
                            "'! This requires FreeMarker support and won't work if you don't have it installed");
                    // no wait result? hmm -- let's try to do dynamically put it in for you!
                    ResultConfig rc = new ResultConfig.Builder(WAIT, "org.apache.struts2.views.freemarker.FreemarkerResult")
                            .addParams(Collections.singletonMap("location", "/org/apache/struts2/interceptor/wait.ftl"))
                            .build();
                    results.put(WAIT, rc);
                }
View Full Code Here

                        " will be associated with success, input and error by default. This might" +
                        " be overridden by another result file or an annotation.", path);
                }

                if (!results.containsKey(Action.SUCCESS)) {
                    ResultConfig success = createResultConfig(actionClass,
                        new ResultInfo(Action.SUCCESS, path, packageConfig, resultsByExtension),
                        packageConfig, null);
                    results.put(Action.SUCCESS, success);
                }
                if (!results.containsKey(Action.INPUT)) {
                    ResultConfig input = createResultConfig(actionClass,
                        new ResultInfo(Action.INPUT, path, packageConfig, resultsByExtension),
                        packageConfig, null);
                    results.put(Action.INPUT, input);
                }
                if (!results.containsKey(Action.ERROR)) {
                    ResultConfig error = createResultConfig(actionClass,
                        new ResultInfo(Action.ERROR, path, packageConfig, resultsByExtension),
                        packageConfig, null);
                    results.put(Action.ERROR, error);
                }

            // This case is when the path contains a result code
            } else if (indexOfDot > resultPrefix.length()) {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("The result file [#0] has a result code and therefore" +
                        " will be associated with only that result code.", path);
                }

                String resultCode = path.substring(resultPrefix.length() + 1, indexOfDot);
                ResultConfig result = createResultConfig(actionClass,
                    new ResultInfo(resultCode, path, packageConfig, resultsByExtension),
                    packageConfig, null);
                results.put(resultCode, result);
            }
        }
View Full Code Here

    protected void createFromAnnotations(Map<String, ResultConfig> resultConfigs,
            String resultPath, PackageConfig packageConfig, Result[] results,
            Class<?> actionClass, Map<String, ResultTypeConfig> resultsByExtension) {
        // Check for multiple results on the class
        for (Result result : results) {
            ResultConfig config = createResultConfig(actionClass,
                new ResultInfo(result, packageConfig, resultPath, actionClass, resultsByExtension),
                packageConfig, result);
            if (config != null) {
                resultConfigs.put(config.getName(), config);
            }
        }
    }
View Full Code Here

            method = conditionalParse(method, invocation);
        }

        String resultCode = invocation.getResultCode();
        if (resultCode != null) {
            ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(
                    resultCode);
            Map resultConfigParams = resultConfig.getParams();
            for (Iterator i = resultConfigParams.entrySet().iterator(); i.hasNext(); ) {
                Map.Entry e = (Map.Entry) i.next();
                if (! prohibitedResultParam.contains(e.getKey())) {
                    requestParameters.put(e.getKey().toString(),
                            e.getValue() == null ? "":
View Full Code Here

        params.put(resultTypeConfig.getDefaultResultParam(), path);

//        PackageConfig pkg = configuration.getPackageConfig(defaultParentPackageName);
//        List<InterceptorMapping> interceptors = InterceptorBuilder.constructInterceptorReference(pkg,
//            pkg.getFullDefaultInterceptorRef(), Collections.EMPTY_MAP, null, objectFactory);
        ResultConfig config = new ResultConfig.Builder(Action.SUCCESS, resultTypeConfig.getClassName()).
            addParams(params).build();
        results.put(Action.SUCCESS, config);

        //addInterceptors(interceptors).
        return new ActionConfig.Builder(defaultParentPackageName, "execute", ActionSupport.class.getName()).
View Full Code Here

        if (config.getParams() != null) {
            params.putAll(config.getParams());
        }
        params.put(config.getDefaultResultParam(), path);

        ResultConfig resultConfig = new ResultConfig.Builder(resultCode, resultClass).addParams(params).build();
        try {
            return objectFactory.buildResult(resultConfig, invocationContext.getContextMap());
        } catch (Exception e) {
            throw new XWorkException("Unable to build convention result", e, resultConfig);
        }
View Full Code Here

                Results results = (Results) actionClass.getAnnotation(Results.class);
                if (results != null) {
                    // first check here...
                    for (int i = 0; i < results.value().length; i++) {
                        Result result = results.value()[i];
                        ResultConfig config = createResultConfig(result);
            if (!containsKey((K)config.getName())) {
                            put((K)config.getName(), (V)config);
                        }
                    }
                }

                // what about a single Result annotation?
                Result result = (Result) actionClass.getAnnotation(Result.class);
                if (result != null) {
                    ResultConfig config = createResultConfig(result);
                    if (!containsKey((K)config.getName())) {
                        put((K)config.getName(), (V)config);
                    }
                }

                actionClass = actionClass.getSuperclass();
            }
View Full Code Here

TOP

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

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.