tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [12/16] git commit: Add method Request.getAttributes() Extend RequestRenderer to render attributes Capture HttpServletRequest properties as Request attributes
Date Fri, 06 Jul 2012 00:38:01 GMT
Add method Request.getAttributes()
Extend RequestRenderer to render attributes
Capture HttpServletRequest properties as Request attributes


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/c9b2da41
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/c9b2da41
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/c9b2da41

Branch: refs/heads/5.4-js-rewrite
Commit: c9b2da4110d6ba3891688530e406cf607254cfb9
Parents: 7fd8d99
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Thu Jul 5 11:13:32 2012 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Thu Jul 5 11:13:59 2012 -0700

----------------------------------------------------------------------
 .../internal/renderers/RequestRenderer.java        |   46 ++++++++++++---
 .../tapestry5/internal/services/RequestImpl.java   |    7 ++
 .../internal/test/TestableRequestImpl.java         |    5 ++
 .../tapestry5/services/DelegatingRequest.java      |    5 ++
 .../org/apache/tapestry5/services/Request.java     |    8 +++
 .../apache/tapestry5/services/TapestryModule.java  |   11 ++++
 .../resources/org/apache/tapestry5/tapestry.js     |    2 +-
 7 files changed, 74 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c9b2da41/tapestry-core/src/main/java/org/apache/tapestry5/internal/renderers/RequestRenderer.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/renderers/RequestRenderer.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/renderers/RequestRenderer.java
index a50920b..067a269 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/renderers/RequestRenderer.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/renderers/RequestRenderer.java
@@ -44,6 +44,15 @@ public class RequestRenderer implements ObjectRenderer<Request>
 
     public void render(Request request, MarkupWriter writer)
     {
+        coreProperties(request, writer);
+        parameters(request, writer);
+        headers(request, writer);
+        attributes(request, writer);
+        context(writer);
+    }
+
+    private void coreProperties(Request request, MarkupWriter writer)
+    {
         writer.element("dl");
 
         dt(writer, "Context Path");
@@ -92,7 +101,7 @@ public class RequestRenderer implements ObjectRenderer<Request>
 
         if (!flags.isEmpty())
         {
-            dt(writer, "flags", InternalUtils.join(flags));
+            dt(writer, "Flags", InternalUtils.join(flags));
         }
 
         dt(writer, "Ports (local/server)",
@@ -101,10 +110,6 @@ public class RequestRenderer implements ObjectRenderer<Request>
         dt(writer, "Method", request.getMethod());
 
         writer.end();
-
-        parameters(request, writer);
-        headers(request, writer);
-        context(writer);
     }
 
     private void context(MarkupWriter writer)
@@ -175,8 +180,11 @@ public class RequestRenderer implements ObjectRenderer<Request>
 
     private void dt(MarkupWriter writer, String name, String value)
     {
-        dt(writer, name);
-        dd(writer, value);
+        if (value != null)
+        {
+            dt(writer, name);
+            dd(writer, value);
+        }
     }
 
     private void dt(MarkupWriter writer, String name)
@@ -208,12 +216,32 @@ public class RequestRenderer implements ObjectRenderer<Request>
 
         for (String name : request.getHeaderNames())
         {
-            dt(writer, name);
-            dd(writer, request.getHeader(name));
+            dt(writer, name, request.getHeader(name));
         }
 
         writer.end(); // dl
 
     }
 
+    private void attributes(Request request, MarkupWriter writer)
+    {
+        List<String> attributeNames = request.getAttributeNames();
+
+        if (attributeNames.isEmpty())
+        {
+            return;
+        }
+
+        section(writer, "Attributes");
+
+        writer.element("dl");
+
+        for (String name : attributeNames)
+        {
+            dt(writer, name, String.valueOf(request.getAttribute(name)));
+        }
+
+        writer.end(); // dl
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c9b2da41/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestImpl.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestImpl.java
index 0760968..45a469e 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestImpl.java
@@ -177,6 +177,13 @@ public class RequestImpl implements Request
         return request.getAttribute(name);
     }
 
+    public List<String> getAttributeNames()
+    {
+        setupEncoding();
+
+        return InternalUtils.toList(request.getAttributeNames());
+    }
+
     public void setAttribute(String name, Object value)
     {
         request.setAttribute(name, value);

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c9b2da41/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/TestableRequestImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/TestableRequestImpl.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/TestableRequestImpl.java
index 1561bd3..6c49f35 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/TestableRequestImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/test/TestableRequestImpl.java
@@ -208,6 +208,11 @@ public class TestableRequestImpl implements TestableRequest
         return attributes.get(name);
     }
 
+    public List<String> getAttributeNames()
+    {
+        return InternalUtils.sortedKeys(attributes);
+    }
+
     public void setAttribute(String name, Object value)
     {
         attributes.put(name, value);

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c9b2da41/tapestry-core/src/main/java/org/apache/tapestry5/services/DelegatingRequest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/DelegatingRequest.java
b/tapestry-core/src/main/java/org/apache/tapestry5/services/DelegatingRequest.java
index f10145b..d2f366f 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/DelegatingRequest.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/DelegatingRequest.java
@@ -62,6 +62,11 @@ public class DelegatingRequest implements Request
         return request.getAttribute(name);
     }
 
+    public List<String> getAttributeNames()
+    {
+        return request.getAttributeNames();
+    }
+
     public String getContextPath()
     {
         return request.getContextPath();

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c9b2da41/tapestry-core/src/main/java/org/apache/tapestry5/services/Request.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/Request.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/Request.java
index 5a23a58..e2f7ee2 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/Request.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/Request.java
@@ -149,6 +149,14 @@ public interface Request
     Object getAttribute(String name);
 
     /**
+     * Returns a sorted list of attribute names.
+     *
+     * @since 5.4
+     */
+    List<String> getAttributeNames();
+
+
+    /**
      * Stores an attribute in this request. Attributes are reset between requests (and remember
that in Tapestry, there
      * is usually two requests per operation: the action request that redirects to a render
request).
      *

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c9b2da41/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
b/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
index dd300ec..70f4014 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
@@ -229,6 +229,17 @@ public final class TapestryModule
         {
             requestGlobals.storeServletRequestResponse(servletRequest, servletResponse);
 
+            // Should have started doing this a long time ago: recoding attributes into
+            // the request for things that may be needed downstream, without having to extend
+            // Request.
+
+            servletRequest.setAttribute("servletAPI.protocol", servletRequest.getProtocol());
+            servletRequest.setAttribute("servletAPI.characterEncoding", servletRequest.getCharacterEncoding());
+            servletRequest.setAttribute("servletAPI.contentLength", servletRequest.getContentLength());
+            servletRequest.setAttribute("servletAPI.authType", servletRequest.getAuthType());
+            servletRequest.setAttribute("servletAPI.contentType", servletRequest.getContentType());
+            servletRequest.setAttribute("servletAPI.scheme", servletRequest.getScheme());
+
             Request request = new RequestImpl(servletRequest, applicationCharset, sessionFactory);
             Response response = new ResponseImpl(servletRequest, servletResponse);
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c9b2da41/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js b/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
index 2bda803..12f6ee2 100644
--- a/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
+++ b/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
@@ -363,7 +363,7 @@ var Tapestry = {
 
         if (initializations) {
             require(["core/pageinit"], function (pageinit) {
-                pageinit(initializations)
+                pageinit.initialize(initializations)
             });
         }
 


Mime
View raw message