Search in sources :

Example 11 with Builder

use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project struts by apache.

the class PropertiesConfigurationProviderTest method testRegister_NoLocale.

public void testRegister_NoLocale() {
    ContainerBuilder builder = new ContainerBuilder();
    builder.constant("foo", "bar");
    PropertiesConfigurationProvider prov = new PropertiesConfigurationProvider();
    prov.register(builder, new LocatableProperties());
    Container container = builder.create(true);
    String localeStr = container.getInstance(String.class, StrutsConstants.STRUTS_LOCALE);
    assertNull(localeStr);
}
Also used : Container(com.opensymphony.xwork2.inject.Container) ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties)

Example 12 with Builder

use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project struts by apache.

the class DefaultInterceptorMapBuilder method build.

protected List<InterceptorMapping> build(InterceptorRef[] interceptors, String actionName, PackageConfig.Builder builder) {
    List<InterceptorMapping> interceptorList = new ArrayList<>(10);
    for (InterceptorRef interceptor : interceptors) {
        LOG.trace("Adding interceptor [{}] to [{}]", interceptor.value(), actionName);
        Map<String, String> params = StringTools.createParameterMap(interceptor.params());
        interceptorList.addAll(buildInterceptorList(builder, interceptor, params));
    }
    return interceptorList;
}
Also used : ArrayList(java.util.ArrayList) InterceptorRef(org.apache.struts2.convention.annotation.InterceptorRef) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping)

Example 13 with Builder

use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project struts by apache.

the class DefaultInterceptorMapBuilder method build.

public List<InterceptorMapping> build(Class<?> actionClass, PackageConfig.Builder builder, String actionName, Action annotation) {
    List<InterceptorMapping> interceptorList = new ArrayList<>(10);
    // from @InterceptorRefs annotation
    InterceptorRefs interceptorRefs = AnnotationUtils.findAnnotation(actionClass, InterceptorRefs.class);
    if (interceptorRefs != null)
        interceptorList.addAll(build(interceptorRefs.value(), actionName, builder));
    // from @InterceptorRef annotation
    InterceptorRef interceptorRef = AnnotationUtils.findAnnotation(actionClass, InterceptorRef.class);
    if (interceptorRef != null)
        interceptorList.addAll(build(new InterceptorRef[] { interceptorRef }, actionName, builder));
    // from @Action annotation
    if (annotation != null) {
        InterceptorRef[] interceptors = annotation.interceptorRefs();
        if (interceptors != null) {
            interceptorList.addAll(build(interceptors, actionName, builder));
        }
    }
    return interceptorList;
}
Also used : ArrayList(java.util.ArrayList) InterceptorRef(org.apache.struts2.convention.annotation.InterceptorRef) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping) InterceptorRefs(org.apache.struts2.convention.annotation.InterceptorRefs)

Example 14 with Builder

use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project struts by apache.

the class DefaultResultMapBuilderTest method testClassLevelInheritanceMultipleResultAnnotation.

public void testClassLevelInheritanceMultipleResultAnnotation() throws Exception {
    ServletContext context = EasyMock.createStrictMock(ServletContext.class);
    // Setup some mock jsps
    Set<String> resources = new HashSet<>();
    EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).andReturn(resources);
    EasyMock.replay(context);
    PackageConfig packageConfig = createPackageConfigBuilder("/namespace");
    this.conventionsService = new ConventionsServiceImpl("/WEB-INF/location");
    DefaultResultMapBuilder builder = new DefaultResultMapBuilder(context, container, "dispatcher,velocity,freemarker");
    Map<String, ResultConfig> results = builder.build(InheritedResultsExtends.class, null, "class-level-results", packageConfig);
    assertEquals(4, results.size());
    assertEquals("error", results.get("error").getName());
    assertEquals("input", results.get("input").getName());
    assertEquals("success", results.get("success").getName());
    assertEquals("failure", results.get("failure").getName());
    assertEquals(3, results.get("error").getParams().size());
    assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("error").getClassName());
    assertEquals("/WEB-INF/location/namespace/error.jsp", results.get("error").getParams().get("location"));
    assertEquals("ann-value", results.get("error").getParams().get("key"));
    assertEquals("ann-value1", results.get("error").getParams().get("key1"));
    assertEquals(1, results.get("input").getParams().size());
    assertEquals("foo.action", results.get("input").getParams().get("actionName"));
    assertEquals("org.apache.struts2.result.ServletActionRedirectResult", results.get("input").getClassName());
    assertEquals(3, results.get("failure").getParams().size());
    assertEquals("/WEB-INF/location/namespace/action-failure.jsp", results.get("failure").getParams().get("location"));
    assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("failure").getClassName());
    assertEquals("value", results.get("failure").getParams().get("key"));
    assertEquals("value1", results.get("failure").getParams().get("key1"));
    assertEquals(3, results.get("success").getParams().size());
    assertEquals("/WEB-INF/location/namespace/action-success.jsp", results.get("success").getParams().get("location"));
    assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("success").getClassName());
    assertEquals("value", results.get("success").getParams().get("key"));
    assertEquals("value1", results.get("success").getParams().get("key1"));
    EasyMock.verify(context);
}
Also used : ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) ServletContext(javax.servlet.ServletContext) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) HashSet(java.util.HashSet)

Example 15 with Builder

use of com.opensymphony.xwork2.config.entities.PackageConfig.Builder in project struts by apache.

the class DefaultResultMapBuilderTest method testClassLevelInheritedSingleResultAnnotation.

public void testClassLevelInheritedSingleResultAnnotation() throws Exception {
    ServletContext context = EasyMock.createStrictMock(ServletContext.class);
    // Setup some mock jsps
    Set<String> resources = new HashSet<>();
    EasyMock.expect(context.getResourcePaths("/WEB-INF/location/namespace/")).andReturn(resources);
    EasyMock.replay(context);
    PackageConfig packageConfig = createPackageConfigBuilder("/namespace");
    this.conventionsService = new ConventionsServiceImpl("/WEB-INF/location");
    DefaultResultMapBuilder builder = new DefaultResultMapBuilder(context, container, "dispatcher,velocity,freemarker");
    Map<String, ResultConfig> results = builder.build(InheritedResultExtends.class, null, "result-inheritance-extends", packageConfig);
    assertEquals(1, results.size());
    assertEquals("error", results.get("error").getName());
    assertEquals(3, results.get("error").getParams().size());
    assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("error").getClassName());
    assertEquals("/WEB-INF/location/namespace/error.jsp", results.get("error").getParams().get("location"));
    assertEquals("value", results.get("error").getParams().get("key"));
    assertEquals("value1", results.get("error").getParams().get("key1"));
    EasyMock.verify(context);
}
Also used : ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) ServletContext(javax.servlet.ServletContext) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) HashSet(java.util.HashSet)

Aggregations

PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)23 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)21 ServletContext (javax.servlet.ServletContext)21 ContainerBuilder (com.opensymphony.xwork2.inject.ContainerBuilder)19 LocatableProperties (com.opensymphony.xwork2.util.location.LocatableProperties)18 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)17 HashSet (java.util.HashSet)14 StubConfigurationProvider (com.opensymphony.xwork2.test.StubConfigurationProvider)10 NoAnnotationAction (org.apache.struts2.convention.actions.NoAnnotationAction)7 ClassLevelResultPathAction (org.apache.struts2.convention.actions.resultpath.ClassLevelResultPathAction)6 Action (org.apache.struts2.convention.annotation.Action)6 ObjectFactory (com.opensymphony.xwork2.ObjectFactory)4 Configuration (com.opensymphony.xwork2.config.Configuration)4 Container (com.opensymphony.xwork2.inject.Container)4 Context (com.opensymphony.xwork2.inject.Context)4 ArrayList (java.util.ArrayList)4 ActionContext (com.opensymphony.xwork2.ActionContext)3 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)3 ResultTypeConfig (com.opensymphony.xwork2.config.entities.ResultTypeConfig)3 StrutsDefaultConfigurationProvider (com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider)3