incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1087200 - in /sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl: SlingRequestProcessorImpl.java request/ContentData.java request/RequestData.java
Date Thu, 31 Mar 2011 06:56:51 GMT
Author: cziegeler
Date: Thu Mar 31 06:56:51 2011
New Revision: 1087200

URL: http://svn.apache.org/viewvc?rev=1087200&view=rev
Log:
SLING-2042 : Clean up content data and request data handling

Modified:
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingRequestProcessorImpl.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/ContentData.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestData.java

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingRequestProcessorImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingRequestProcessorImpl.java?rev=1087200&r1=1087199&r2=1087200&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingRequestProcessorImpl.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingRequestProcessorImpl.java
Thu Mar 31 06:56:51 2011
@@ -238,9 +238,6 @@ public class SlingRequestProcessorImpl i
             if (requestLogger != null) {
                 requestLogger.logRequestExit(request, response);
             }
-
-            // dispose any request data
-            requestData.dispose();
         }
     }
 
@@ -295,8 +292,9 @@ public class SlingRequestProcessorImpl i
         SlingHttpServletResponse cResponse = RequestData.toSlingHttpServletResponse(response);
 
         // get the request data (and btw check the correct type)
-        RequestData requestData = RequestData.getRequestData(cRequest);
-        ContentData contentData = requestData.pushContent(resource, resolvedURL);
+        final RequestData requestData = RequestData.getRequestData(cRequest);
+        final ContentData oldContentData = requestData.getContentData();
+        final ContentData contentData = requestData.setContent(resource, resolvedURL);
 
         try {
             // resolve the servlet
@@ -309,7 +307,7 @@ public class SlingRequestProcessorImpl i
 
             processComponent(cRequest, cResponse, type);
         } finally {
-            requestData.popContent();
+            requestData.resetContent(oldContentData);
         }
     }
 

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/ContentData.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/ContentData.java?rev=1087200&r1=1087199&r2=1087200&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/ContentData.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/ContentData.java
Thu Mar 31 06:56:51 2011
@@ -19,6 +19,7 @@
 package org.apache.sling.engine.impl.request;
 
 import javax.servlet.Servlet;
+
 import org.apache.sling.api.request.RequestPathInfo;
 import org.apache.sling.api.resource.Resource;
 
@@ -30,21 +31,17 @@ import org.apache.sling.api.resource.Res
  */
 public class ContentData {
 
-    private RequestPathInfo requestPathInfo;
+    private final RequestPathInfo requestPathInfo;
 
-    private Resource resource;
+    private final Resource resource;
 
     private Servlet servlet;
 
-    public ContentData(Resource resource, RequestPathInfo requestPathInfo) {
+    public ContentData(final Resource resource, final RequestPathInfo requestPathInfo) {
         this.resource = resource;
         this.requestPathInfo = requestPathInfo;
     }
 
-    /* package */void dispose() {
-        this.requestPathInfo = null;
-    }
-
     public Resource getResource() {
         return resource;
     }

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestData.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestData.java?rev=1087200&r1=1087199&r2=1087200&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestData.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/request/RequestData.java
Thu Mar 31 06:56:51 2011
@@ -23,7 +23,6 @@ import static org.apache.sling.api.Sling
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
-import java.util.LinkedList;
 
 import javax.servlet.Servlet;
 import javax.servlet.ServletException;
@@ -35,7 +34,6 @@ import javax.servlet.ServletResponseWrap
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.sling.api.SlingConstants;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.request.RecursionTooDeepException;
@@ -127,9 +125,6 @@ public class RequestData {
     /** the current ContentData */
     private ContentData currentContentData;
 
-    /** the stack of ContentData objects */
-    private LinkedList<ContentData> contentDataStack;
-
     /**
      * the number of servlets called by
      * {@link #service(SlingHttpServletRequest, SlingHttpServletResponse)}
@@ -144,6 +139,11 @@ public class RequestData {
      */
     private String activeServletName;
 
+    /**
+     * Recursion depth
+     */
+    private int recursionDepth;
+
     public static void setMaxCallCounter(int maxCallCounter) {
         RequestData.maxCallCounter = maxCallCounter;
     }
@@ -202,7 +202,7 @@ public class RequestData {
             final ServletResolver sr) {
         // the resource and the request path info, will never be null
         RequestPathInfo requestPathInfo = new SlingRequestPathInfo(resource);
-        ContentData contentData = pushContent(resource, requestPathInfo);
+        ContentData contentData = setContent(resource, requestPathInfo);
 
 	    requestProgressTracker.log("Resource Path Info: {0}", requestPathInfo);
 
@@ -215,32 +215,6 @@ public class RequestData {
         contentData.setServlet(servlet);
     }
 
-    public void dispose() {
-        // make sure our request attributes do not exist anymore
-        servletRequest.removeAttribute(SlingConstants.ATTR_REQUEST_CONTENT);
-        servletRequest.removeAttribute(SlingConstants.ATTR_REQUEST_SERVLET);
-
-        // clear the content data stack
-        if (contentDataStack != null) {
-            while (!contentDataStack.isEmpty()) {
-                ContentData cd = contentDataStack.removeLast();
-                cd.dispose();
-            }
-        }
-
-        // dispose current content data, if any
-        if (currentContentData != null) {
-            currentContentData.dispose();
-        }
-
-        // clear fields
-        contentDataStack = null;
-        currentContentData = null;
-        servletRequest = null;
-        servletResponse = null;
-        resourceResolver = null;
-    }
-
     public SlingRequestProcessorImpl getSlingRequestProcessor() {
         return slingRequestProcessor;
     }
@@ -530,53 +504,25 @@ public class RequestData {
 
     // ---------- Content inclusion stacking -----------------------------------
 
-    public ContentData pushContent(Resource resource,
-            RequestPathInfo requestPathInfo) {
-        if (currentContentData != null) {
-            if (contentDataStack == null) {
-                contentDataStack = new LinkedList<ContentData>();
-            } else if (contentDataStack.size() >= maxInclusionCounter) {
-                throw new RecursionTooDeepException(
-                    requestPathInfo.getResourcePath());
-            }
-
-            contentDataStack.add(currentContentData);
+    public ContentData setContent(final Resource resource,
+            final RequestPathInfo requestPathInfo) {
+        if ( this.recursionDepth >=  maxInclusionCounter) {
+            throw new RecursionTooDeepException(requestPathInfo.getResourcePath());
         }
-
+        this.recursionDepth++;
         currentContentData = new ContentData(resource, requestPathInfo);
         return currentContentData;
     }
 
-    public ContentData popContent() {
-        // dispose current content data before replacing it
-        if (currentContentData != null) {
-            currentContentData.dispose();
-        }
-
-        if (contentDataStack != null && !contentDataStack.isEmpty()) {
-            // remove the topmost content data object
-            currentContentData = contentDataStack.removeLast();
-
-        } else {
-            currentContentData = null;
-        }
-
-        return currentContentData;
+    public void resetContent(final ContentData data) {
+        this.recursionDepth--;
+        currentContentData = data;
     }
 
     public ContentData getContentData() {
         return currentContentData;
     }
 
-    /**
-     * Returns <code>true</code> if request processing is currently processing
-     * a component which has been included by
-     * <code>SlingHttpServletRequestDispatcher.include</code>.
-     */
-    public boolean isContentIncluded() {
-        return contentDataStack != null && !contentDataStack.isEmpty();
-    }
-
     public ResourceResolver getResourceResolver() {
         return resourceResolver;
     }



Mime
View raw message