Skip to content

Commit

Permalink
Merge 11571f0 into 5e40998
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Dec 26, 2019
2 parents 5e40998 + 11571f0 commit 2e93576
Show file tree
Hide file tree
Showing 128 changed files with 976 additions and 1,852 deletions.
5 changes: 5 additions & 0 deletions apps/showcase/pom.xml
Expand Up @@ -94,6 +94,11 @@
<artifactId>struts2-async-plugin</artifactId>
</dependency>

<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-velocity-plugin</artifactId>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion apps/showcase/src/main/resources/struts-tags-ui.xml
Expand Up @@ -24,7 +24,7 @@
"http://struts.apache.org/dtds/struts-2.5.dtd">

<struts>
<package name="ui-tags" extends="struts-default" namespace="/tags/ui">
<package name="ui-tags" extends="velocity-default" namespace="/tags/ui">
<action name="example" class="org.apache.struts2.showcase.UITagExample">
<result>/WEB-INF/tags/ui/example.jsp</result>
<result name="input">/WEB-INF/tags/ui/example.jsp</result>
Expand Down
4 changes: 4 additions & 0 deletions assembly/src/main/assembly/all.xml
Expand Up @@ -209,6 +209,10 @@
<directory>../plugins/tiles/target/apidocs</directory>
<outputDirectory>docs/struts2-plugins/struts2-tiles-plugin/apidocs</outputDirectory>
</fileSet>
<fileSet>
<directory>../plugins/velocity/target/apidocs</directory>
<outputDirectory>docs/struts2-plugins/struts2-velocity-plugin/apidocs</outputDirectory>
</fileSet>

<!-- bundles -->
<fileSet>
Expand Down
Expand Up @@ -23,6 +23,7 @@
import com.opensymphony.xwork2.FileManagerFactory;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.XWorkException;
import com.opensymphony.xwork2.config.BeanSelectionProvider;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationException;
import com.opensymphony.xwork2.config.ConfigurationProvider;
Expand Down Expand Up @@ -116,6 +117,7 @@ public XmlConfigurationProvider(String filename, boolean errorIfMissing) {
this.errorIfMissing = errorIfMissing;

Map<String, String> mappings = new HashMap<>();
mappings.put("-//Apache Struts//XWork 2.6//EN", "xwork-2.6.dtd");
mappings.put("-//Apache Struts//XWork 2.5//EN", "xwork-2.5.dtd");
mappings.put("-//Apache Struts//XWork 2.3//EN", "xwork-2.3.dtd");
mappings.put("-//Apache Struts//XWork 2.1.3//EN", "xwork-2.1.3.dtd");
Expand Down Expand Up @@ -219,14 +221,28 @@ public void register(ContainerBuilder containerBuilder, LocatableProperties prop

final String nodeName = child.getNodeName();

if ("bean".equals(nodeName)) {
if ("bean-selection".equals(nodeName)) {
String name = child.getAttribute("name");
String impl = child.getAttribute("class");
try {
Class classImpl = ClassLoaderUtil.loadClass(impl, getClass());
if (BeanSelectionProvider.class.isAssignableFrom(classImpl)) {
BeanSelectionProvider provider = (BeanSelectionProvider) classImpl.newInstance();
provider.register(containerBuilder, props);
} else {
throw new ConfigurationException("The bean-provider: name:" + name + " class:" + impl + " does not implement " + BeanSelectionProvider.class.getName(), childNode);
}
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
throw new ConfigurationException("Unable to load bean-provider: name:" + name + " class:" + impl, e, childNode);
}
} else if ("bean".equals(nodeName)) {
String type = child.getAttribute("type");
String name = child.getAttribute("name");
String impl = child.getAttribute("class");
String onlyStatic = child.getAttribute("static");
String scopeStr = child.getAttribute("scope");
boolean optional = "true".equals(child.getAttribute("optional"));
Scope scope = Scope.SINGLETON;
Scope scope;
if ("prototype".equals(scopeStr)) {
scope = Scope.PROTOTYPE;
} else if ("request".equals(scopeStr)) {
Expand All @@ -237,6 +253,8 @@ public void register(ContainerBuilder containerBuilder, LocatableProperties prop
scope = Scope.SINGLETON;
} else if ("thread".equals(scopeStr)) {
scope = Scope.THREAD;
} else {
scope = Scope.SINGLETON;
}

if (StringUtils.isEmpty(name)) {
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/java/org/apache/struts2/StrutsConstants.java
Expand Up @@ -102,9 +102,6 @@ public final class StrutsConstants {

/** Maximum strong sizing for MruCacheStorage for freemarker */
public static final String STRUTS_FREEMARKER_MRU_MAX_STRONG_SIZE = "struts.freemarker.mru.max.strong.size";

/** org.apache.struts2.views.velocity.VelocityManager implementation class */
public static final String STRUTS_VELOCITY_MANAGER_CLASSNAME = "struts.velocity.manager.classname";

/** The Velocity configuration file path */
public static final String STRUTS_VELOCITY_CONFIGFILE = "struts.velocity.configfile";
Expand Down
Expand Up @@ -67,7 +67,6 @@
import org.apache.struts2.util.ContentTypeMatcher;
import org.apache.struts2.views.freemarker.FreemarkerManager;
import org.apache.struts2.views.util.UrlHelper;
import org.apache.struts2.views.velocity.VelocityManager;

/**
* Selects the implementations of key framework extension points, using the loaded
Expand Down Expand Up @@ -365,9 +364,7 @@
* <li><code>struts.configuration.xml.reload = true</code></li>
* </ul>
*/
public class DefaultBeanSelectionProvider extends AbstractBeanSelectionProvider {

private static final Logger LOG = LogManager.getLogger(DefaultBeanSelectionProvider.class);
public class StrutsBeanSelectionProvider extends AbstractBeanSelectionProvider {

public void register(ContainerBuilder builder, LocatableProperties props) {
alias(ObjectFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY, builder, props);
Expand Down Expand Up @@ -404,7 +401,6 @@ public void register(ContainerBuilder builder, LocatableProperties props) {
alias(ActionMapper.class, StrutsConstants.STRUTS_MAPPER_CLASS, builder, props);
alias(MultiPartRequest.class, StrutsConstants.STRUTS_MULTIPART_PARSER, builder, props, Scope.PROTOTYPE);
alias(FreemarkerManager.class, StrutsConstants.STRUTS_FREEMARKER_MANAGER_CLASSNAME, builder, props);
alias(VelocityManager.class, StrutsConstants.STRUTS_VELOCITY_MANAGER_CLASSNAME, builder, props);
alias(UrlRenderer.class, StrutsConstants.STRUTS_URL_RENDERER, builder, props);
alias(ActionValidatorManager.class, StrutsConstants.STRUTS_ACTIONVALIDATORMANAGER, builder, props);
alias(ValueStackFactory.class, StrutsConstants.STRUTS_VALUESTACKFACTORY, builder, props);
Expand Down
Expand Up @@ -19,14 +19,18 @@
package org.apache.struts2.config;

import java.util.List;
import java.util.Optional;

import org.apache.struts2.config.entities.BeanConfig;
import org.apache.struts2.config.entities.BeanSelectionConfig;
import org.apache.struts2.config.entities.ConstantConfig;

public interface StrutsJavaConfiguration {
List<BeanConfig> beans();

List<ConstantConfig> constants();

default Optional<BeanSelectionConfig> beanSelection() { return Optional.empty();}

List<String> unknownHandlerStack();
}
Expand Up @@ -24,9 +24,12 @@
import java.util.Map;
import java.util.Map.Entry;

import com.opensymphony.xwork2.config.BeanSelectionProvider;
import com.opensymphony.xwork2.util.ClassLoaderUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.config.entities.BeanConfig;
import org.apache.struts2.config.entities.BeanSelectionConfig;
import org.apache.struts2.config.entities.ConstantConfig;

import com.opensymphony.xwork2.config.Configuration;
Expand Down Expand Up @@ -91,6 +94,20 @@ public void register(ContainerBuilder builder, LocatableProperties props) throws
}
}

// 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) {
Expand Down Expand Up @@ -125,10 +142,10 @@ private void registerBean(Map<String, Object> loadedBeans, ContainerBuilder cont
} else {
if (containerBuilder.contains(beanConf.getType(), beanConf.getName())) {
Location loc = LocationUtils
.getLocation(loadedBeans.get(beanConf.getType().getName() + beanConf.getName()));
.getLocation(loadedBeans.get(beanConf.getType().getName() + beanConf.getName()));
if (throwExceptionOnDuplicateBeans) {
throw new ConfigurationException("Bean type " + beanConf.getType() + " with the name "
+ beanConf.getName() + " has already been loaded by " + loc, javaConfig);
+ beanConf.getName() + " has already been loaded by " + loc, javaConfig);
}
}

Expand All @@ -137,17 +154,21 @@ private void registerBean(Map<String, Object> loadedBeans, ContainerBuilder cont
beanConf.getClazz().getDeclaredConstructors();

LOG.debug("Loaded type: {} name: {} clazz: {}", beanConf.getType(), beanConf.getName(),
beanConf.getClazz());
beanConf.getClazz());

containerBuilder.factory(
beanConf.getType(), beanConf.getName(), new LocatableFactory(beanConf.getName(),
beanConf.getType(), beanConf.getClazz(), beanConf.getScope(), javaConfig),
beanConf.getScope());
beanConf.getType(),
beanConf.getName(),
new LocatableFactory(
beanConf.getName(), beanConf.getType(), beanConf.getClazz(), beanConf.getScope(), javaConfig
),
beanConf.getScope());
}
loadedBeans.put(beanConf.getType().getName() + beanConf.getName(), javaConfig);
} catch (Throwable ex) {
if (!beanConf.isOptional()) {
throw new ConfigurationException(
"Unable to load bean: type:" + beanConf.getType() + " class:" + beanConf.getClazz(), ex);
"Unable to load bean: type:" + beanConf.getType() + " class:" + beanConf.getClazz(), ex);
} else {
LOG.debug("Unable to load optional class: {}", beanConf.getClazz());
}
Expand Down
Expand Up @@ -73,6 +73,7 @@ public StrutsXmlConfigurationProvider(String filename, @Deprecated boolean error
dtdMappings.put("-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN", "struts-2.1.7.dtd");
dtdMappings.put("-//Apache Software Foundation//DTD Struts Configuration 2.3//EN", "struts-2.3.dtd");
dtdMappings.put("-//Apache Software Foundation//DTD Struts Configuration 2.5//EN", "struts-2.5.dtd");
dtdMappings.put("-//Apache Software Foundation//DTD Struts Configuration 2.6//EN", "struts-2.6.dtd");
setDtdMappings(dtdMappings);
File file = new File(filename);
if (file.getParent() != null) {
Expand Down
@@ -1,6 +1,4 @@
#*
* $Id$
*
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
Expand All @@ -17,5 +15,31 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*#
</a>
*/
package org.apache.struts2.config.entities;

import com.opensymphony.xwork2.config.BeanSelectionProvider;
import com.opensymphony.xwork2.inject.Container;

public class BeanSelectionConfig {

private final Class<? extends BeanSelectionProvider> clazz;
private final String name;

public BeanSelectionConfig(Class<? extends BeanSelectionProvider> clazz) {
this(clazz, Container.DEFAULT_NAME);
}

public BeanSelectionConfig(Class<? extends BeanSelectionProvider> clazz, String name) {
this.clazz = clazz;
this.name = name;
}

public Class<? extends BeanSelectionProvider> getClazz() {
return clazz;
}

public String getName() {
return name;
}
}
Expand Up @@ -185,7 +185,6 @@ public Map<String, String> getAllAsStringsMap() {
map.put(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY, freemarkerTemplatesCacheUpdateDelay);
map.put(StrutsConstants.STRUTS_FREEMARKER_BEANWRAPPER_CACHE, Objects.toString(freemarkerBeanwrapperCache, null));
map.put(StrutsConstants.STRUTS_FREEMARKER_MRU_MAX_STRONG_SIZE, Objects.toString(freemarkerMruMaxStrongSize, null));
map.put(StrutsConstants.STRUTS_VELOCITY_MANAGER_CLASSNAME, beanConfToString(velocityManagerClassname));
map.put(StrutsConstants.STRUTS_VELOCITY_CONFIGFILE, velocityConfigfile);
map.put(StrutsConstants.STRUTS_VELOCITY_TOOLBOXLOCATION, velocityToolboxlocation);
map.put(StrutsConstants.STRUTS_VELOCITY_CONTEXTS, StringUtils.join(velocityContexts, ','));
Expand Down
Expand Up @@ -44,7 +44,7 @@
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.StrutsException;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.config.DefaultBeanSelectionProvider;
import org.apache.struts2.config.StrutsBeanSelectionProvider;
import org.apache.struts2.config.DefaultPropertiesProvider;
import org.apache.struts2.config.PropertiesConfigurationProvider;
import org.apache.struts2.config.StrutsJavaConfiguration;
Expand Down Expand Up @@ -481,7 +481,7 @@ public void register(ContainerBuilder builder, LocatableProperties props) throws
}

private void init_AliasStandardObjects() {
configurationManager.addContainerProvider(new DefaultBeanSelectionProvider());
configurationManager.addContainerProvider(new StrutsBeanSelectionProvider());
}

private Container init_PreloadConfiguration() {
Expand Down

0 comments on commit 2e93576

Please sign in to comment.