struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [13/16] struts git commit: Cleans up and fixes issue based on feedback
Date Sun, 10 Jan 2016 11:22:11 GMT
Cleans up and fixes issue based on feedback


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/9136521d
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/9136521d
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/9136521d

Branch: refs/heads/support-2-3
Commit: 9136521d27a45f8cd9206dc2dc4a50a2ebfa07db
Parents: 5be1590
Author: Lukasz Lenart <lukasz.lenart@gmail.com>
Authored: Sat Dec 19 10:15:02 2015 +0100
Committer: Lukasz Lenart <lukasz.lenart@gmail.com>
Committed: Sat Dec 19 10:15:02 2015 +0100

----------------------------------------------------------------------
 .../tiles/StrutsTilesContainerFactory.java      | 35 ++++++++++++--------
 1 file changed, 21 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/9136521d/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
----------------------------------------------------------------------
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
index b198313..b96884c 100644
--- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
@@ -27,6 +27,7 @@ import org.apache.tiles.TilesContainer;
 import org.apache.tiles.context.ChainedTilesRequestContextFactory;
 import org.apache.tiles.context.TilesRequestContext;
 import org.apache.tiles.context.TilesRequestContextFactory;
+import org.apache.tiles.definition.DefinitionsFactory;
 import org.apache.tiles.definition.DefinitionsFactoryException;
 import org.apache.tiles.definition.pattern.DefinitionPatternMatcherFactory;
 import org.apache.tiles.definition.pattern.PatternDefinitionResolver;
@@ -59,6 +60,7 @@ import org.apache.tiles.renderer.AttributeRenderer;
 import org.apache.tiles.renderer.TypeDetectingAttributeRenderer;
 import org.apache.tiles.renderer.impl.BasicRendererFactory;
 import org.apache.tiles.renderer.impl.ChainedDelegateAttributeRenderer;
+import org.apache.tiles.servlet.context.ServletUtil;
 import org.apache.tiles.util.URLUtil;
 
 import javax.el.ArrayELResolver;
@@ -68,9 +70,9 @@ import javax.el.ELResolver;
 import javax.el.ListELResolver;
 import javax.el.MapELResolver;
 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;
@@ -98,9 +100,17 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory
{
     public static final String PATTERN_WILDCARD = "WILDCARD";
     public static final String PATTERN_REGEXP = "REGEXP";
 
+    /**
+     * Default pattern to be used to collect Tiles definitions if user didn't configure any
+     */
+    public static final String TILES_DEFAULT_PATTERN = "tiles*.xml";
+
     @Override
     protected BasicTilesContainer instantiateContainer(TilesApplicationContext applicationContext)
{
-        return new CachingTilesContainer();
+        CachingTilesContainer tilesContainer = new CachingTilesContainer();
+        ServletContext servletContext = (ServletContext) applicationContext.getContext();
+        ServletUtil.setContainer(servletContext, tilesContainer);
+        return tilesContainer;
     }
 
     @Override
@@ -189,19 +199,9 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory
{
     }
 
     @Override
-    protected List<URL> getSourceURLs(TilesApplicationContext applicationContext,
-                                      TilesRequestContextFactory contextFactory) {
+    protected List<URL> getSourceURLs(TilesApplicationContext applicationContext, TilesRequestContextFactory
contextFactory) {
         try {
-            Set<URL> finalSet = new HashSet<URL>();
-            Set<URL> webINFSet = applicationContext.getResources("/WEB-INF/**/tiles*.xml");
-            Set<URL> metaINFSet = applicationContext.getResources("classpath*:META-INF/**/tiles*.xml");
-
-            if (webINFSet != null) {
-                finalSet.addAll(webINFSet);
-            }
-            if (metaINFSet != null) {
-                finalSet.addAll(metaINFSet);
-            }
+            Set<URL> finalSet = applicationContext.getResources(getTilesDefinitionPattern(applicationContext.getInitParams()));
 
             return URLUtil.getBaseTilesDefinitionURLs(finalSet);
         } catch (IOException e) {
@@ -209,6 +209,13 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory
{
         }
     }
 
+    protected String getTilesDefinitionPattern(Map<String, String> params) {
+        if (params.containsKey(DefinitionsFactory.DEFINITIONS_CONFIG)) {
+            return params.get(DefinitionsFactory.DEFINITIONS_CONFIG);
+        }
+        return TILES_DEFAULT_PATTERN;
+    }
+
     protected ELAttributeEvaluator createELEvaluator(TilesApplicationContext applicationContext)
{
 
         ELAttributeEvaluator evaluator = new ELAttributeEvaluator();


Mime
View raw message