mirror of
https://github.com/apache/struts.git
synced 2026-08-06 23:27:07 +00:00
WW-4622 - Adds fallback to static config definitions to allow work in restricted envs (cherry picked from 6770b35), getRealPath NPE check; WW-4623, WW-4624 - Adds support for multiple tiles defintions (cherry picked from c12cd61)
This commit is contained in:
+12
-4
@@ -63,6 +63,8 @@ import org.apache.tiles.renderer.impl.ChainedDelegateAttributeRenderer;
|
||||
import org.apache.tiles.servlet.context.ServletUtil;
|
||||
import org.apache.tiles.util.URLUtil;
|
||||
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
|
||||
import javax.el.ArrayELResolver;
|
||||
import javax.el.BeanELResolver;
|
||||
import javax.el.CompositeELResolver;
|
||||
@@ -73,6 +75,7 @@ import javax.el.ResourceBundleELResolver;
|
||||
import javax.servlet.ServletContext;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -201,7 +204,12 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory {
|
||||
@Override
|
||||
protected List<URL> getSourceURLs(TilesApplicationContext applicationContext, TilesRequestContextFactory contextFactory) {
|
||||
try {
|
||||
Set<URL> finalSet = applicationContext.getResources(getTilesDefinitionPattern(applicationContext.getInitParams()));
|
||||
Set<URL> finalSet = new HashSet<URL>();
|
||||
|
||||
Set<String> definitions = getTilesDefinitions(applicationContext.getInitParams());
|
||||
for (String definition : definitions) {
|
||||
finalSet.addAll(applicationContext.getResources(definition));
|
||||
}
|
||||
|
||||
return URLUtil.getBaseTilesDefinitionURLs(finalSet);
|
||||
} catch (IOException e) {
|
||||
@@ -209,11 +217,11 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory {
|
||||
}
|
||||
}
|
||||
|
||||
protected String getTilesDefinitionPattern(Map<String, String> params) {
|
||||
protected Set<String> getTilesDefinitions(Map<String, String> params) {
|
||||
if (params.containsKey(DefinitionsFactory.DEFINITIONS_CONFIG)) {
|
||||
return params.get(DefinitionsFactory.DEFINITIONS_CONFIG);
|
||||
return TextParseUtil.commaDelimitedStringToSet(params.get(DefinitionsFactory.DEFINITIONS_CONFIG));
|
||||
}
|
||||
return TILES_DEFAULT_PATTERN;
|
||||
return TextParseUtil.commaDelimitedStringToSet(TILES_DEFAULT_PATTERN);
|
||||
}
|
||||
|
||||
protected ELAttributeEvaluator createELEvaluator(TilesApplicationContext applicationContext) {
|
||||
|
||||
@@ -22,7 +22,9 @@ package org.apache.struts2.tiles;
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
import org.apache.tiles.TilesApplicationContext;
|
||||
import org.apache.tiles.definition.DefinitionsFactory;
|
||||
import org.apache.tiles.factory.AbstractTilesContainerFactory;
|
||||
import org.apache.tiles.servlet.context.ServletTilesApplicationContext;
|
||||
import org.apache.tiles.startup.AbstractTilesInitializer;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
@@ -33,8 +35,15 @@ public class StrutsTilesInitializer extends AbstractTilesInitializer {
|
||||
|
||||
@Override
|
||||
protected TilesApplicationContext createTilesApplicationContext(TilesApplicationContext preliminaryContext) {
|
||||
LOG.debug("Initializing Tiles wildcard support ...");
|
||||
return new StrutsWildcardServletTilesApplicationContext((ServletContext) preliminaryContext.getContext());
|
||||
ServletContext servletContext = (ServletContext) preliminaryContext.getContext();
|
||||
|
||||
if (servletContext.getInitParameter(DefinitionsFactory.DEFINITIONS_CONFIG) != null) {
|
||||
LOG.trace("Found definitions config in web.xml, using standard Servlet support ....");
|
||||
return new ServletTilesApplicationContext(servletContext);
|
||||
} else {
|
||||
LOG.trace("Initializing Tiles wildcard support ...");
|
||||
return new StrutsWildcardServletTilesApplicationContext(servletContext);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-2
@@ -50,8 +50,12 @@ public class StrutsWildcardServletTilesApplicationContext extends ServletTilesAp
|
||||
|
||||
for (Object path : context.getResourcePaths("/")) {
|
||||
try {
|
||||
URL url = new File(context.getRealPath(String.valueOf(path))).toURI().toURL();
|
||||
urls.add(url);
|
||||
String realPath = context.getRealPath(String.valueOf(path));
|
||||
|
||||
if (realPath != null) {
|
||||
URL url = new File(realPath).toURI().toURL();
|
||||
urls.add(url);
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
throw new ConfigurationException(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user