Search in sources :

Example 6 with Builder

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

the class PreResultListenerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    loadConfigurationProviders(new ConfigurationProvider() {

        Configuration configuration;

        public void destroy() {
        }

        public void init(Configuration config) {
            this.configuration = config;
        }

        public void loadPackages() {
            PackageConfig packageConfig = new PackageConfig.Builder("package").addActionConfig("action", new ActionConfig.Builder("package", "action", SimpleFooAction.class.getName()).build()).build();
            configuration.addPackageConfig("package", packageConfig);
        }

        /**
         * Tells whether the ConfigurationProvider should reload its configuration
         */
        public boolean needsReload() {
            return false;
        }

        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
            builder.factory(ActionProxyFactory.class, DefaultActionProxyFactory.class);
            builder.factory(ObjectFactory.class);
        }
    });
}
Also used : ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) Configuration(com.opensymphony.xwork2.config.Configuration) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 7 with Builder

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

the class OgnlUtilTest method reloadTestContainerConfiguration.

private void reloadTestContainerConfiguration(boolean allowStaticField) {
    loadConfigurationProviders(new StubConfigurationProvider() {

        @Override
        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
            props.setProperty(StrutsConstants.STRUTS_ALLOW_STATIC_FIELD_ACCESS, "" + allowStaticField);
        }
    });
    ognlUtil = container.getInstance(OgnlUtil.class);
}
Also used : ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) StubConfigurationProvider(com.opensymphony.xwork2.test.StubConfigurationProvider) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException)

Example 8 with Builder

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

the class StrutsJavaConfigurationProvider method register.

@Override
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
    Map<String, Object> loadedBeans = new HashMap<>();
    // bean
    List<BeanConfig> beanConfigs = javaConfig.beans();
    if (beanConfigs != null) {
        for (BeanConfig bc : beanConfigs) {
            if (bc != null) {
                registerBean(loadedBeans, builder, bc);
            }
        }
    }
    // constant
    List<ConstantConfig> constantConfigList = javaConfig.constants();
    if (constantConfigList != null) {
        for (ConstantConfig constantConf : constantConfigList) {
            if (constantConf != null) {
                Map<String, String> constantMap = constantConf.getAllAsStringsMap();
                for (Entry<String, String> entr : constantMap.entrySet()) {
                    if (entr.getKey() != null && entr.getValue() != null) {
                        registerConstant(props, entr.getKey(), entr.getValue());
                    }
                }
            }
        }
    }
    // bean-selection
    javaConfig.beanSelection().ifPresent(beanSelectionConfig -> {
        try {
            LOG.debug("Registering bean selection provider {} of type {}", beanSelectionConfig.getName(), beanSelectionConfig.getClazz().getName());
            BeanSelectionProvider provider = beanSelectionConfig.getClazz().newInstance();
            provider.register(builder, props);
        } catch (IllegalAccessException | InstantiationException e) {
            throw new ConfigurationException("Unable to load : name:" + beanSelectionConfig.getName() + " class:" + beanSelectionConfig.getClazz().getName());
        }
    });
    // unknown-handler-stack
    List<String> unknownHandlers = javaConfig.unknownHandlerStack();
    if (unknownHandlers != null) {
        List<UnknownHandlerConfig> unknownHandlerStack = new ArrayList<>();
        for (String unknownHandler : unknownHandlers) {
            Location location = LocationUtils.getLocation(unknownHandler);
            unknownHandlerStack.add(new UnknownHandlerConfig(unknownHandler, location));
        }
        if (!unknownHandlerStack.isEmpty()) {
            configuration.setUnknownHandlerStack(unknownHandlerStack);
        }
    }
}
Also used : BeanConfig(org.apache.struts2.config.entities.BeanConfig) BeanSelectionProvider(com.opensymphony.xwork2.config.BeanSelectionProvider) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UnknownHandlerConfig(com.opensymphony.xwork2.config.entities.UnknownHandlerConfig) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) ConstantConfig(org.apache.struts2.config.entities.ConstantConfig) Location(com.opensymphony.xwork2.util.location.Location)

Example 9 with Builder

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

the class OgnlValueStackTest method reloadTestContainerConfiguration.

private void reloadTestContainerConfiguration(Boolean allowStaticMethod, Boolean allowStaticField) throws Exception {
    loadConfigurationProviders(new StubConfigurationProvider() {

        @Override
        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
            // undefined values then should be evaluated to false
            if (props.containsKey(StrutsConstants.STRUTS_ALLOW_STATIC_METHOD_ACCESS)) {
                props.remove(StrutsConstants.STRUTS_ALLOW_STATIC_METHOD_ACCESS);
            }
            if (props.containsKey(StrutsConstants.STRUTS_ALLOW_STATIC_FIELD_ACCESS)) {
                props.remove(StrutsConstants.STRUTS_ALLOW_STATIC_FIELD_ACCESS);
            }
            if (allowStaticMethod != null) {
                props.setProperty(StrutsConstants.STRUTS_ALLOW_STATIC_METHOD_ACCESS, "" + allowStaticMethod);
            }
            if (allowStaticField != null) {
                props.setProperty(StrutsConstants.STRUTS_ALLOW_STATIC_FIELD_ACCESS, "" + allowStaticField);
            }
        }
    });
    ognlUtil = container.getInstance(OgnlUtil.class);
}
Also used : ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) StubConfigurationProvider(com.opensymphony.xwork2.test.StubConfigurationProvider) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException)

Example 10 with Builder

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

the class PrefixBasedActionProxyFactoryTest method setUp.

@Override
public void setUp() throws Exception {
    ConfigurationProvider[] providers = new ConfigurationProvider[] { new StrutsXmlConfigurationProvider("xwork-sample.xml"), new StubConfigurationProvider() {

        @Override
        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
            builder.factory(ActionProxyFactory.class, "prefix1", new Factory() {

                public Object create(Context context) throws Exception {
                    return new Prefix1Factory();
                }

                public Class type() {
                    return Prefix1Factory.class;
                }
            }, Scope.SINGLETON);
        }
    }, new StubConfigurationProvider() {

        @Override
        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
            builder.factory(ActionProxyFactory.class, "prefix2", new Factory() {

                public Object create(Context context) throws Exception {
                    return new Prefix2Factory();
                }

                public Class type() {
                    return Prefix2Factory.class;
                }
            }, Scope.SINGLETON);
        }
    } };
    loadConfigurationProviders(providers);
    factory = new PrefixBasedActionProxyFactory();
    factory.setContainer(container);
}
Also used : Context(com.opensymphony.xwork2.inject.Context) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) StubConfigurationProvider(com.opensymphony.xwork2.test.StubConfigurationProvider) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) StubConfigurationProvider(com.opensymphony.xwork2.test.StubConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) Factory(com.opensymphony.xwork2.inject.Factory) ActionProxyFactory(com.opensymphony.xwork2.ActionProxyFactory) DefaultActionProxyFactory(com.opensymphony.xwork2.DefaultActionProxyFactory) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties)

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