Package com.opensymphony.xwork2.config.entities

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


  @Inject
  protected ActionBuilder actionNameBuilder;

  public Result build(String resultCode, ActionConfig actionConfig, ActionContext context) {
    String path = null;
    ResultTypeConfig resultTypeConfig = null;

    logger.debug("result code:{} for actionConfig:{}", resultCode, actionConfig);
    if (null == resultTypeConfigs) {
      PackageConfig pc = configuration.getPackageConfig(actionConfig.getPackageName());
      this.resultTypeConfigs = pc.getAllResultTypeConfigs();
View Full Code Here


  protected List<ResultConfig> buildResultConfigs(Class<?> clazz) {
    List<ResultConfig> configs = CollectUtils.newArrayList();
    if (null == profileService) return configs;
    String extention = profileService.getProfile(clazz.getName()).getViewExtension();
    if (!extention.endsWith("ftl")) return configs;
    ResultTypeConfig resultTypeConfig = configuration.getPackageConfig("struts-default")
        .getAllResultTypeConfigs().get("freemarker");
    for (Method m : clazz.getMethods()) {
      if (String.class.equals(m.getReturnType()) && m.getParameterTypes().length == 0
          && Modifier.isPublic(m.getModifiers()) && !Modifier.isStatic(m.getModifiers())) {
        String name = m.getName();
        if (shouldGenerateResult(m)) {
          StringBuilder buf = new StringBuilder();
          buf.append(viewMapper.getViewPath(clazz.getName(), name, name));
          buf.append('.');
          buf.append(extention);
          configs.add(new ResultConfig.Builder(name, resultTypeConfig.getClassName()).addParam(
              resultTypeConfig.getDefaultResultParam(), buf.toString()).build());
        }
      }
    }
    return configs;
  }
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

        ServletContext context = mockServletContext("/WEB-INF/location");
        this.conventionsService = new ConventionsServiceImpl("/WEB-INF/location");
        DefaultResultMapBuilder builder = new DefaultResultMapBuilder(context, container, "dispatcher,velocity,freemarker");

        ResultTypeConfig resultType = new ResultTypeConfig.Builder("dispatcher", ServletDispatcherResult.class.getName()).
                addParam("key", "value").addParam("key1", "value1").defaultResultParam("location").build();
        ResultConfig globalError = new ResultConfig.Builder("error", ServletDispatcherResult.class.getName()).
                addParam("location", "/globalError.jsp").
                build();
        PackageConfig packageConfig = new PackageConfig.Builder("package").
View Full Code Here

        EasyMock.replay(context);

        this.conventionsService = new ConventionsServiceImpl("/WEB-INF/location");
        DefaultResultMapBuilder builder = new DefaultResultMapBuilder(context, container, "dispatcher,velocity,freemarker");

        ResultTypeConfig resultType = new ResultTypeConfig.Builder("dispatcher", ServletDispatcherResult.class.getName()).
                addParam("key", "value").addParam("key1", "value1").defaultResultParam("location").build();
        ResultConfig globalError = new ResultConfig.Builder("error", ServletDispatcherResult.class.getName()).
                addParam("location", "/globalError.jsp").
                build();
        PackageConfig packageConfig = new PackageConfig.Builder("package").
View Full Code Here

    }

    public void testClassPath() throws Exception {
        ServletContext context = EasyMock.createNiceMock(ServletContext.class);

        ResultTypeConfig resultType = new ResultTypeConfig.Builder("freemarker", "org.apache.struts2.dispatcher.ServletDispatcherResult").
                defaultResultParam("location").build();
        PackageConfig packageConfig = new PackageConfig.Builder("package").
                defaultResultType("dispatcher").addResultTypeConfig(resultType).build();

        this.conventionsService = new ConventionsServiceImpl("/WEB-INF/component");
View Full Code Here

        assertEquals(1, results.get("foo").getParams().size());
        assertEquals("/WEB-INF/component/no-annotation-foo.ftl", results.get("foo").getParams().get("location"));
    }

    private PackageConfig createPackageConfigBuilder(String namespace) {
        ResultTypeConfig resultType = new ResultTypeConfig.Builder("dispatcher", "org.apache.struts2.dispatcher.ServletDispatcherResult").
                addParam("key", "value").addParam("key1", "value1").defaultResultParam("location").build();

        ResultTypeConfig redirect = new ResultTypeConfig.Builder("redirectAction",
                "org.apache.struts2.dispatcher.ServletActionRedirectResult").defaultResultParam("actionName").build();

        ResultTypeConfig ftlResultType = new ResultTypeConfig.Builder("freemarker",
                "org.apache.struts2.views.freemarker.FreemarkerResult").defaultResultParam("location").build();

        return new PackageConfig.Builder("package").
                namespace(namespace).
                defaultResultType("dispatcher").
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

    @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

            {
                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

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.