Package com.opensymphony.xwork2.config.entities

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


        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("null", SomeResult.class.getName(), "location");
       
        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

                    + "', perhaps the parent package does not specify the result type?",
                resultElement);
          }
        }

        ResultTypeConfig config = packageContext
            .getResultType(resultType);

        if (config == null) {
          throw new ConfigurationException(
              "There is no result type defined for type '"
                  + resultType + "' mapped with name '"
                  + resultName + "'." + "  Did you mean '"
                  + guessResultType(resultType) + "'?",
              resultElement);
        }

        @SuppressWarnings("deprecation")
        String resultClass = config.getClazz();

        // invalid result type specified in result definition
        if (resultClass == null) {
          throw new ConfigurationException("Result type '"
              + resultType + "' is invalid");
        }

        Map<String, String> resultParams = XmlHelper
            .getParams(resultElement);

        if (resultParams.size() == 0) // maybe we just have a body -
                        // therefore a default parameter
        {
          // if <result ...>something</result> then we add a parameter
          // of 'something' as this is the most used result param
          if (resultElement.getChildNodes().getLength() >= 1) {
            resultParams = new LinkedHashMap<String, String>();

            String paramName = config.getDefaultResultParam();
            if (paramName != null) {
              StringBuilder paramValue = new StringBuilder();
              for (int j = 0; j < resultElement.getChildNodes()
                  .getLength(); j++) {
                if (resultElement.getChildNodes().item(j)
                    .getNodeType() == Node.TEXT_NODE) {
                  String val = resultElement.getChildNodes()
                      .item(j).getNodeValue();
                  if (val != null) {
                    paramValue.append(val);
                  }
                }
              }
              String val = paramValue.toString().trim();
              if (val.length() > 0) {
                resultParams.put(paramName, val);
              }
            } else {
              if (LOG.isWarnEnabled()) {
                LOG.warn("no default parameter defined for result of type "
                    + config.getName());
              }
            }
          }
        }

        // 处理resultParams
        if ("redirectAction".equals(resultType)) {
          String namespace = resultParams.get("namespace");
          if (namespace != null) {
            namespace = handleNamespace(namespace);
          }
          resultParams.put("namespace", namespace);
        }

        // create new param map, so that the result param can override
        // the config param
        Map<String, String> params = new LinkedHashMap<String, String>();
        Map<String, String> configParams = config.getParams();
        if (configParams != null) {
          params.putAll(configParams);
        }
        params.putAll(resultParams);
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

            if (!TextUtils.stringSet(pkgConfig.getNamespace()) && TextUtils.stringSet(parentPkg.getNamespace())) {
                pkgConfig.namespace(parentPkg.getNamespace());
            }
        }

        ResultTypeConfig defaultResultType = packageLoader.getDefaultResultType(pkgConfig);
        ActionConfig actionConfig = new ActionConfig.Builder(actionPackage, actionName, cls.getName())
                .addResultConfigs(new ResultMap<String,ResultConfig>(cls, actionName, defaultResultType))
                .build();
        pkgConfig.addActionConfig(actionName, actionConfig);
    }
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

    @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

            // 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.