roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r440765 - in /incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering: model/ servlets/
Date Wed, 06 Sep 2006 16:23:25 GMT
Author: agilliland
Date: Wed Sep  6 09:23:24 2006
New Revision: 440765

URL: http://svn.apache.org/viewvc?view=rev&rev=440765
Log:
cleaning up the way WeblogRequest objects are passed to Models and used for initialization.

the standard is that Models which need info about the weblog they are being used on should
lookup the WeblogRequest via the 'weblogRequest' init data parameter. If they need a subclass
of WeblogRequest then it is the Models job to cast the weblogRequest into the expected subclass
and verify that they have what they need.


Modified:
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/CalendarModel.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/FeedModel.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PageModel.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PlanetModel.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/SiteModel.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/UtilitiesModel.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/SearchServlet.java

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/CalendarModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/CalendarModel.java?view=diff&rev=440765&r1=440764&r2=440765
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/CalendarModel.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/CalendarModel.java
Wed Sep  6 09:23:24 2006
@@ -19,8 +19,6 @@
 package org.apache.roller.ui.rendering.model;
 
 import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 import javax.servlet.jsp.PageContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -30,6 +28,7 @@
 import org.apache.roller.ui.core.tags.calendar.CalendarTag;
 import org.apache.roller.ui.core.tags.calendar.WeblogCalendarModel;
 import org.apache.roller.ui.rendering.util.WeblogPageRequest;
+import org.apache.roller.ui.rendering.util.WeblogRequest;
 
 
 /**
@@ -57,10 +56,19 @@
         // extract page context
         this.pageContext = (PageContext) initData.get("pageContext");
         
-        // we expect the init data to contain a pageRequest object
-        this.pageRequest = (WeblogPageRequest) initData.get("pageRequest");
-        if(this.pageRequest == null) {
-            throw new RollerException("expected pageRequest from init data");
+        // we expect the init data to contain a weblogRequest object
+        WeblogRequest weblogRequest = (WeblogRequest) initData.get("weblogRequest");
+        if(weblogRequest == null) {
+            throw new RollerException("expected weblogRequest from init data");
+        }
+        
+        // CalendarModel only works on page requests, so cast weblogRequest
+        // into a WeblogPageRequest and if it fails then throw exception
+        if(weblogRequest instanceof WeblogPageRequest) {
+            this.pageRequest = (WeblogPageRequest) weblogRequest;
+        } else {
+            throw new RollerException("weblogRequest is not a WeblogPageRequest."+
+                    "  CalendarModel only supports page requests.");
         }
     }
     

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/FeedModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/FeedModel.java?view=diff&rev=440765&r1=440764&r2=440765
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/FeedModel.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/FeedModel.java
Wed Sep  6 09:23:24 2006
@@ -37,6 +37,7 @@
 import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
 import org.apache.roller.pojos.wrapper.WebsiteDataWrapper;
 import org.apache.roller.ui.rendering.util.WeblogFeedRequest;
+import org.apache.roller.ui.rendering.util.WeblogRequest;
 
 
 /**
@@ -52,12 +53,22 @@
     
     public void init(Map initData) throws RollerException {
         
-        // we expect the init data to contain a feedRequest object
-        this.feedRequest = (WeblogFeedRequest) initData.get("feedRequest");
-        if(this.feedRequest == null) {
-            throw new RollerException("expected feedRequest from init data");
+        // we expect the init data to contain a weblogRequest object
+        WeblogRequest weblogRequest = (WeblogRequest) initData.get("weblogRequest");
+        if(weblogRequest == null) {
+            throw new RollerException("expected weblogRequest from init data");
         }
         
+        // PageModel only works on page requests, so cast weblogRequest
+        // into a WeblogPageRequest and if it fails then throw exception
+        if(weblogRequest instanceof WeblogFeedRequest) {
+            this.feedRequest = (WeblogFeedRequest) weblogRequest;
+        } else {
+            throw new RollerException("weblogRequest is not a WeblogFeedRequest."+
+                    "  FeedModel only supports feed requests.");
+        }
+        
+        // extract weblog object
         weblog = feedRequest.getWeblog();
     }
     

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PageModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PageModel.java?view=diff&rev=440765&r1=440764&r2=440765
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PageModel.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PageModel.java
Wed Sep  6 09:23:24 2006
@@ -35,6 +35,7 @@
 import org.apache.roller.ui.rendering.pagers.WeblogEntriesPermalinkPager;
 import org.apache.roller.ui.rendering.util.WeblogEntryCommentForm;
 import org.apache.roller.ui.rendering.util.WeblogPageRequest;
+import org.apache.roller.ui.rendering.util.WeblogRequest;
 
 
 /**
@@ -70,15 +71,25 @@
      */
     public void init(Map initData) throws RollerException {
         
-        // we expect the init data to contain a pageRequest object
-        this.pageRequest = (WeblogPageRequest) initData.get("pageRequest");
-        if(this.pageRequest == null) {
-            throw new RollerException("expected pageRequest from init data");
+        // we expect the init data to contain a weblogRequest object
+        WeblogRequest weblogRequest = (WeblogRequest) initData.get("weblogRequest");
+        if(weblogRequest == null) {
+            throw new RollerException("expected weblogRequest from init data");
+        }
+        
+        // PageModel only works on page requests, so cast weblogRequest
+        // into a WeblogPageRequest and if it fails then throw exception
+        if(weblogRequest instanceof WeblogPageRequest) {
+            this.pageRequest = (WeblogPageRequest) weblogRequest;
+        } else {
+            throw new RollerException("weblogRequest is not a WeblogPageRequest."+
+                    "  PageModel only supports page requests.");
         }
         
         // see if there is a comment form
         this.commentForm = (WeblogEntryCommentForm) initData.get("commentForm");
         
+        // custom request parameters
         this.requestParameters = (Map)initData.get("requestParameters");
         
         // extract weblog object

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PlanetModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PlanetModel.java?view=diff&rev=440765&r1=440764&r2=440765
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PlanetModel.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PlanetModel.java
Wed Sep  6 09:23:24 2006
@@ -57,13 +57,13 @@
     }
     
     public void init(Map initData) throws RollerException {
-        // we expect the init data to contain a pageRequest object
-        this.weblogRequest = (WeblogPageRequest) initData.get("pageRequest");
+        
+        // we expect the init data to contain a weblogRequest object
+        this.weblogRequest = (WeblogRequest) initData.get("weblogRequest");
         if(this.weblogRequest == null) {
-            throw new RollerException("expected pageRequest from init data");
+            throw new RollerException("expected weblogRequest from init data");
         }
         
-        // TODO 3.0: is it better to reparse URL to get these?
         if (weblogRequest instanceof WeblogPageRequest) {
             Template weblogPage = ((WeblogPageRequest)weblogRequest).getWeblogPage();
             pageLink = (weblogPage != null) ? weblogPage.getLink() : null;

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/SiteModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/SiteModel.java?view=diff&rev=440765&r1=440764&r2=440765
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/SiteModel.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/SiteModel.java
Wed Sep  6 09:23:24 2006
@@ -71,13 +71,12 @@
     
     public void init(Map initData) throws RollerException {
         
-        // we expect the init data to contain a pageRequest object
+        // we expect the init data to contain a weblogRequest object
         this.weblogRequest = (WeblogRequest) initData.get("weblogRequest");
         if(this.weblogRequest == null) {
-            throw new RollerException("expected pageRequest from init data");
+            throw new RollerException("expected weblogRequest from init data");
         }
         
-        // TODO 3.0: is it better to reparse URL to get these?
         if (weblogRequest instanceof WeblogPageRequest) {
             Template weblogPage = ((WeblogPageRequest)weblogRequest).getWeblogPage();
             pageLink = (weblogPage != null) ? weblogPage.getLink() : null;

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/UtilitiesModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/UtilitiesModel.java?view=diff&rev=440765&r1=440764&r2=440765
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/UtilitiesModel.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/UtilitiesModel.java
Wed Sep  6 09:23:24 2006
@@ -36,7 +36,7 @@
 import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
 import org.apache.roller.pojos.wrapper.WebsiteDataWrapper;
 import org.apache.roller.ui.core.RollerSession;
-import org.apache.roller.ui.rendering.util.WeblogPageRequest;
+import org.apache.roller.ui.rendering.util.WeblogRequest;
 import org.apache.roller.util.DateUtil;
 import org.apache.roller.util.RegexUtil;
 import org.apache.roller.util.Utilities;
@@ -108,10 +108,9 @@
         this.request = (HttpServletRequest) initData.get("request");        
 
         // extract timezone if available
-        WeblogPageRequest pageRequest = 
-            (WeblogPageRequest)initData.get("pageRequest");
-        if (pageRequest != null && pageRequest.getWeblog() != null) {
-            tz = pageRequest.getWeblog().getTimeZoneInstance();
+        WeblogRequest weblogRequest = (WeblogRequest)initData.get("weblogRequest");
+        if (weblogRequest != null && weblogRequest.getWeblog() != null) {
+            tz = weblogRequest.getWeblog().getTimeZoneInstance();
         }
     }
      

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java?view=diff&rev=440765&r1=440764&r2=440765
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/FeedServlet.java
Wed Sep  6 09:23:24 2006
@@ -182,7 +182,6 @@
             // populate the rendering model
             Map initData = new HashMap();
             initData.put("request", request);
-            initData.put("feedRequest", feedRequest);
             initData.put("weblogRequest", feedRequest);
 
             // Load models for feeds

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java?view=diff&rev=440765&r1=440764&r2=440765
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/PageServlet.java
Wed Sep  6 09:23:24 2006
@@ -312,7 +312,6 @@
             Map initData = new HashMap();
             initData.put("request", request);
             initData.put("requestParameters", request.getParameterMap());
-            initData.put("pageRequest", pageRequest);
             initData.put("weblogRequest", pageRequest);
             initData.put("pageContext", pageContext);
             

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/SearchServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/SearchServlet.java?view=diff&rev=440765&r1=440764&r2=440765
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/SearchServlet.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/servlets/SearchServlet.java
Wed Sep  6 09:23:24 2006
@@ -119,17 +119,19 @@
             // populate the rendering model
             Map initData = new HashMap();
             initData.put("request", request);
-            initData.put("searchRequest", searchRequest);
-            initData.put("weblogRequest", searchRequest);
             initData.put("pageContext", pageContext);
             
-            // we need to add a simple page request because the search
-            // results are rendered like a weblog page
+            // this is a little hacky, but nothing we can do about it
+            // we need the 'weblogRequest' to be a pageRequest so other models
+            // are properly loaded, which means that searchRequest needs its
+            // own custom initData property aside from the standard weblogRequest.
+            // possible better approach is make searchRequest extend pageRequest.
             WeblogPageRequest pageRequest = new WeblogPageRequest();
             pageRequest.setWeblogHandle(searchRequest.getWeblogHandle());
             pageRequest.setWeblogCategoryName(searchRequest.getWeblogCategoryName());
-            initData.put("pageRequest", pageRequest);
-        
+            initData.put("weblogRequest", pageRequest);
+            initData.put("searchRequest", searchRequest);
+            
             // Load models for pages
             String searchModels = RollerConfig.getProperty("rendering.searchModels");
             ModelLoader.loadModels(searchModels, model, initData, true);



Mime
View raw message