Skip to content

Commit

Permalink
WW-4622 - Adds fallback to static config definitions to allow work in…
Browse files Browse the repository at this point in the history
… restricted envs (cherry picked from 6770b35), getRealPath NPE check; WW-4623, WW-4624 - Adds support for multiple tiles defintions (cherry picked from c12cd61)
  • Loading branch information
aleksandr-m committed Apr 6, 2016
1 parent 17dab89 commit 5ce807a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
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;
Expand All @@ -73,6 +75,7 @@
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;
Expand Down Expand Up @@ -201,19 +204,24 @@ protected <T> PatternDefinitionResolver<T> createPatternDefinitionResolver(Class
@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) {
throw new DefinitionsFactoryException("Cannot load definition URLs", e);
}
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ public StrutsWildcardServletTilesApplicationContext(ServletContext context) {

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);
}
Expand Down

0 comments on commit 5ce807a

Please sign in to comment.