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);
}
});
}
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);
}
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);
}
}
}
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);
}
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);
}
Aggregations