struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [34/50] [abbrv] struts git commit: Defines helper method to fetch ActionContext from request
Date Fri, 15 Jul 2016 13:19:01 GMT
Defines helper method to fetch ActionContext from request


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

Branch: refs/heads/master
Commit: 4c6e51b302a50215b06a79051dfe12e19a4bce91
Parents: 375faa4
Author: Lukasz Lenart <lukasz.lenart@gmail.com>
Authored: Wed Jan 13 12:05:03 2016 +0100
Committer: Lukasz Lenart <lukasz.lenart@gmail.com>
Committed: Tue Jan 19 16:19:19 2016 +0100

----------------------------------------------------------------------
 .../StrutsFreeMarkerAttributeRenderer.java      | 30 +++++++++++++++++---
 1 file changed, 26 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/4c6e51b3/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsFreeMarkerAttributeRenderer.java
----------------------------------------------------------------------
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsFreeMarkerAttributeRenderer.java
b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsFreeMarkerAttributeRenderer.java
index 48592e0..fbc5416 100644
--- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsFreeMarkerAttributeRenderer.java
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsFreeMarkerAttributeRenderer.java
@@ -36,7 +36,9 @@ import org.apache.struts2.views.freemarker.StrutsBeanWrapper;
 import org.apache.tiles.freemarker.template.TilesFMModelRepository;
 import org.apache.tiles.impl.InvalidTemplateException;
 import org.apache.tiles.request.Request;
+import org.apache.tiles.request.jsp.JspRequest;
 import org.apache.tiles.request.render.Renderer;
+import org.apache.tiles.request.servlet.ServletRequest;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
@@ -51,10 +53,7 @@ public class StrutsFreeMarkerAttributeRenderer implements Renderer {
         if (path != null) {
             LOG.trace("Rendering freemarker tile ...");
 
-            ActionContext ctx = ServletActionContext.getActionContext((HttpServletRequest)
request);
-            if (ctx == null) {
-                throw new ConfigurationException("There is no ActionContext for current request!");
-            }
+            ActionContext ctx = readActionContext(request);
 
             registerTilesBeanModel(ctx);
 
@@ -77,6 +76,29 @@ public class StrutsFreeMarkerAttributeRenderer implements Renderer {
         }
     }
 
+    /**
+     * Depending how Tiles definition was defined, request can an instance of JspRequest
(for JSPs)
+     * or a ServletRequest (FreeMarker)
+     */
+    protected ActionContext readActionContext(Request request) {
+        ActionContext ctx = null;
+
+        if (request instanceof ServletRequest) {
+            HttpServletRequest httpRequest = ((ServletRequest) request).getRequest();
+            ctx = ServletActionContext.getActionContext(httpRequest);
+        }
+        if (request instanceof JspRequest) {
+            HttpServletRequest httpRequest = (HttpServletRequest) ((JspRequest) request).getPageContext().getRequest();
+            ctx = ServletActionContext.getActionContext(httpRequest);
+        }
+
+        if (ctx == null) {
+            throw new ConfigurationException("There is no ActionContext for current request!");
+        }
+
+        return ctx;
+    }
+
     @Override
     public boolean isRenderable(String path, Request request) {
         return path != null && path.startsWith("/") && path.endsWith(".ftl");


Mime
View raw message