Search in sources :

Example 16 with ConfigurationProvider

use of com.opensymphony.xwork2.config.ConfigurationProvider in project struts by apache.

the class XmlConfigurationProviderTest method testInheritence.

public void testInheritence() throws Exception {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-include-parent.xml";
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    provider.init(configuration);
    provider.loadPackages();
    // test expectations
    assertEquals(6, configuration.getPackageConfigs().size());
    PackageConfig defaultPackage = configuration.getPackageConfig("default");
    assertNotNull(defaultPackage);
    assertEquals("default", defaultPackage.getName());
    PackageConfig namespace1 = configuration.getPackageConfig("namespace1");
    assertNotNull(namespace1);
    assertEquals("namespace1", namespace1.getName());
    assertEquals(defaultPackage, namespace1.getParents().get(0));
    PackageConfig namespace2 = configuration.getPackageConfig("namespace2");
    assertNotNull(namespace2);
    assertEquals("namespace2", namespace2.getName());
    assertEquals(1, namespace2.getParents().size());
    assertEquals(namespace1, namespace2.getParents().get(0));
    PackageConfig namespace4 = configuration.getPackageConfig("namespace4");
    assertNotNull(namespace4);
    assertEquals("namespace4", namespace4.getName());
    assertEquals(1, namespace4.getParents().size());
    assertEquals(namespace1, namespace4.getParents().get(0));
    PackageConfig namespace5 = configuration.getPackageConfig("namespace5");
    assertNotNull(namespace5);
    assertEquals("namespace5", namespace5.getName());
    assertEquals(1, namespace5.getParents().size());
    assertEquals(namespace4, namespace5.getParents().get(0));
    configurationManager.addContainerProvider(provider);
    configurationManager.reload();
    RuntimeConfiguration runtimeConfiguration = configurationManager.getConfiguration().getRuntimeConfiguration();
    assertNotNull(runtimeConfiguration.getActionConfig("/namespace1", "action1"));
    assertNotNull(runtimeConfiguration.getActionConfig("/namespace2", "action2"));
    assertNotNull(runtimeConfiguration.getActionConfig("/namespace4", "action4"));
    assertNotNull(runtimeConfiguration.getActionConfig("/namespace5", "action5"));
}
Also used : ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) RuntimeConfiguration(com.opensymphony.xwork2.config.RuntimeConfiguration)

Example 17 with ConfigurationProvider

use of com.opensymphony.xwork2.config.ConfigurationProvider in project struts by apache.

the class XmlConfigurationProviderUnknownHandlerStackTest method testEmptyStack.

public void testEmptyStack() throws ConfigurationException {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-unknownhandler-stack-empty.xml";
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    loadConfigurationProviders(provider);
    configurationManager.reload();
    List<UnknownHandlerConfig> unknownHandlerStack = configuration.getUnknownHandlerStack();
    assertNull(unknownHandlerStack);
}
Also used : UnknownHandlerConfig(com.opensymphony.xwork2.config.entities.UnknownHandlerConfig) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider)

Example 18 with ConfigurationProvider

use of com.opensymphony.xwork2.config.ConfigurationProvider in project struts by apache.

the class XmlConfigurationProviderWildCardIncludeTest method testWildCardInclude.

public void testWildCardInclude() throws Exception {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-wildcard-include.xml";
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    provider.init(configuration);
    provider.loadPackages();
    PackageConfig defaultWildcardPackage = configuration.getPackageConfig("default-wildcard");
    assertNotNull(defaultWildcardPackage);
    assertEquals("default-wildcard", defaultWildcardPackage.getName());
    PackageConfig defaultOnePackage = configuration.getPackageConfig("default-1");
    assertNotNull(defaultOnePackage);
    assertEquals("default-1", defaultOnePackage.getName());
    PackageConfig defaultTwoPackage = configuration.getPackageConfig("default-2");
    assertNotNull(defaultTwoPackage);
    assertEquals("default-2", defaultTwoPackage.getName());
    PackageConfig defaultPackage = configuration.getPackageConfig("default");
    assertNotNull(defaultPackage);
    assertEquals("default", defaultPackage.getName());
    configurationManager.addContainerProvider(provider);
    configurationManager.reload();
}
Also used : ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 19 with ConfigurationProvider

use of com.opensymphony.xwork2.config.ConfigurationProvider in project struts by apache.

the class OsgiConfigurationProvider method setVelocityManager.

@Inject
public void setVelocityManager(VelocityManager vm) {
    LOG.trace("OSGi ConfigurationProvider - setVelocityManager() called - VelocityManager: [{}]", vm);
    Properties props = new Properties();
    props.setProperty("osgi.resource.loader.description", "OSGI bundle loader");
    props.setProperty("osgi.resource.loader.class", VelocityBundleResourceLoader.class.getName());
    props.setProperty(Velocity.RESOURCE_LOADER, "strutsfile,strutsclass,osgi");
    vm.setVelocityProperties(props);
}
Also used : VelocityBundleResourceLoader(org.apache.struts2.osgi.loaders.VelocityBundleResourceLoader) Properties(java.util.Properties) Inject(com.opensymphony.xwork2.inject.Inject)

Example 20 with ConfigurationProvider

use of com.opensymphony.xwork2.config.ConfigurationProvider in project struts by apache.

the class Dispatcher method init_CustomConfigurationProviders.

private void init_CustomConfigurationProviders() {
    String configProvs = initParams.get("configProviders");
    if (configProvs != null) {
        String[] classes = configProvs.split("\\s*[,]\\s*");
        for (String cname : classes) {
            try {
                Class cls = ClassLoaderUtil.loadClass(cname, this.getClass());
                ConfigurationProvider prov = (ConfigurationProvider) cls.newInstance();
                if (prov instanceof ServletContextAwareConfigurationProvider) {
                    ((ServletContextAwareConfigurationProvider) prov).initWithContext(servletContext);
                }
                configurationManager.addContainerProvider(prov);
            } catch (InstantiationException e) {
                throw new ConfigurationException("Unable to instantiate provider: " + cname, e);
            } catch (IllegalAccessException e) {
                throw new ConfigurationException("Unable to access provider: " + cname, e);
            } catch (ClassNotFoundException e) {
                throw new ConfigurationException("Unable to locate provider class: " + cname, e);
            }
        }
    }
}
Also used : ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) PropertiesConfigurationProvider(org.apache.struts2.config.PropertiesConfigurationProvider) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) ServletContextAwareConfigurationProvider(com.opensymphony.xwork2.config.ServletContextAwareConfigurationProvider) StrutsJavaConfigurationProvider(org.apache.struts2.config.StrutsJavaConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) XmlConfigurationProvider(com.opensymphony.xwork2.config.providers.XmlConfigurationProvider) ServletContextAwareConfigurationProvider(com.opensymphony.xwork2.config.ServletContextAwareConfigurationProvider)

Aggregations

ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)41 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)22 StrutsXmlConfigurationProvider (org.apache.struts2.config.StrutsXmlConfigurationProvider)21 Map (java.util.Map)12 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)11 XmlConfigurationProvider (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider)10 HashMap (java.util.HashMap)9 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)7 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)6 File (java.io.File)6 InterceptorMapping (com.opensymphony.xwork2.config.entities.InterceptorMapping)5 ContainerBuilder (com.opensymphony.xwork2.inject.ContainerBuilder)5 LocatableProperties (com.opensymphony.xwork2.util.location.LocatableProperties)5 InterceptorStackConfig (com.opensymphony.xwork2.config.entities.InterceptorStackConfig)4 MockResult (com.opensymphony.xwork2.mock.MockResult)4 DefaultUnknownHandlerManager (com.opensymphony.xwork2.DefaultUnknownHandlerManager)3 SimpleAction (com.opensymphony.xwork2.SimpleAction)3 UnknownHandlerManager (com.opensymphony.xwork2.UnknownHandlerManager)3 Configuration (com.opensymphony.xwork2.config.Configuration)3 RuntimeConfiguration (com.opensymphony.xwork2.config.RuntimeConfiguration)3