roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r429901 - in /incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering: model/ pagers/
Date Wed, 09 Aug 2006 00:27:08 GMT
Author: agilliland
Date: Tue Aug  8 17:27:07 2006
New Revision: 429901

URL: http://svn.apache.org/viewvc?rev=429901&view=rev
Log:
tweaking simple pagers implementation a little bit while fixing some bugs.

- made abstract pager even more abstract such that it now only needs a baseUrl and page number
to do it's work.

- migrated existing simple pager implementations to fit the modified approach.


Modified:
    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/pagers/AbstractPager.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/CommentsPager.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/PlanetEntriesPager.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/UsersPager.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesListPager.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogsPager.java

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?rev=429901&r1=429900&r2=429901&view=diff
==============================================================================
--- 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
Tue Aug  8 17:27:07 2006
@@ -36,6 +36,7 @@
 import org.apache.roller.ui.rendering.pagers.PlanetEntriesPager;
 import org.apache.roller.ui.rendering.util.WeblogPageRequest;
 import org.apache.roller.ui.rendering.util.WeblogRequest;
+import org.apache.roller.util.URLUtilities;
 
 
 /**
@@ -61,11 +62,13 @@
         if(this.weblogRequest == null) {
             throw new RollerException("expected pageRequest from init data");
         }
+        
         // TODO 3.0: is it better to reparse URL to get these?
         if (weblogRequest instanceof WeblogPageRequest) {
             weblogPage = ((WeblogPageRequest)weblogRequest).getWeblogPage();
             pageNum = ((WeblogPageRequest)weblogRequest).getPageNum();
         }  
+        
         // extract weblog object
         weblog = weblogRequest.getWeblog();
     } 
@@ -78,11 +81,15 @@
      * @param len      Max number of results to return
      */
     public Pager getAggregationPager(int sinceDays, int length) {
+        
+        String pagerUrl = URLUtilities.getWeblogPageURL(weblog, 
+                weblogRequest.getLocale(), weblogPage.getLink(), 
+                null, null, null, 0, false);
+        
         return new PlanetEntriesPager(
             null,
             null,    
-            weblog, 
-            weblogPage,
+            pagerUrl,
             weblogRequest.getLocale(),
             sinceDays,
             pageNum, 
@@ -97,11 +104,15 @@
      * @param len      Max number of results to return
      */
     public Pager getAggregationPager(String groupHandle, int sinceDays, int length) {
+        
+        String pagerUrl = URLUtilities.getWeblogPageURL(weblog, 
+                weblogRequest.getLocale(), weblogPage.getLink(), 
+                null, null, null, 0, false);
+        
         return new PlanetEntriesPager(
             null,
             groupHandle,
-            weblog, 
-            weblogPage,
+            pagerUrl,
             weblogRequest.getLocale(),
             sinceDays,
             pageNum, 
@@ -116,11 +127,15 @@
      * @param len      Max number of results to return
      */
     public Pager getFeedPager(String feedURL, int length) {
+        
+        String pagerUrl = URLUtilities.getWeblogPageURL(weblog, 
+                weblogRequest.getLocale(), weblogPage.getLink(), 
+                null, null, null, 0, false);
+        
         return new PlanetEntriesPager(
             feedURL,
             null,
-            weblog, 
-            weblogPage,
+            pagerUrl,
             weblogRequest.getLocale(),
             -1,
             pageNum, 

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?rev=429901&r1=429900&r2=429901&view=diff
==============================================================================
--- 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
Tue Aug  8 17:27:07 2006
@@ -25,6 +25,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.RollerException;
@@ -46,6 +47,7 @@
 import org.apache.roller.ui.rendering.pagers.WeblogsPager;
 import org.apache.roller.ui.rendering.util.WeblogPageRequest;
 import org.apache.roller.ui.rendering.util.WeblogRequest;
+import org.apache.roller.util.URLUtilities;
 
 
 /**
@@ -91,9 +93,13 @@
      * @param length    Max number of results to return
      */
     public Pager getWeblogEntriesPager(int sinceDays, int length) {
+        
+        String pagerUrl = URLUtilities.getWeblogPageURL(weblog, 
+                weblogRequest.getLocale(), weblogPage.getLink(), 
+                null, null, null, 0, false);
+        
         return new WeblogEntriesListPager(
-            weblog, null, null, null,
-            weblogPage,
+            pagerUrl, null, null, null,
             weblogRequest.getLocale(),
             sinceDays,
             pageNum, 
@@ -111,9 +117,13 @@
      * @param length      Max number of results to return
      */   
     public Pager getWeblogEntriesPager(WebsiteData queryWeblog, UserData user, String cat,
int sinceDays, int length) {
+        
+        String pagerUrl = URLUtilities.getWeblogPageURL(weblog, 
+                weblogRequest.getLocale(), weblogPage.getLink(), 
+                null, null, null, 0, false);
+        
         return new WeblogEntriesListPager(
-            weblog, queryWeblog, user, cat,
-            weblogPage,
+            pagerUrl, queryWeblog, user, cat,
             weblogRequest.getLocale(),
             sinceDays,
             pageNum, 
@@ -128,9 +138,13 @@
      * @param len      Max number of results to return
      */
     public Pager getCommentsPager(int sinceDays, int length) {
+        
+        String pagerUrl = URLUtilities.getWeblogPageURL(weblog, 
+                weblogRequest.getLocale(), weblogPage.getLink(), 
+                null, null, null, 0, false);
+        
         return new CommentsPager(
-            weblog, 
-            weblogPage,
+            pagerUrl,
             weblogRequest.getLocale(),
             sinceDays,
             pageNum, 
@@ -140,10 +154,18 @@
     
     /* Get pager of users whose names begin with specified letter */
     public Pager getUsersByLetterPager(String letter, int sinceDays, int length) {
+        
+        String pagerUrl = URLUtilities.getWeblogPageURL(weblog, 
+                weblogRequest.getLocale(), weblogPage.getLink(), 
+                null, null, null, 0, false);
+        
+        if(letter != null && StringUtils.isEmpty(letter)) {
+            letter = null;
+        }
+        
         return new UsersPager(
+            pagerUrl,
             letter,
-            weblog, 
-            weblogPage,
             weblogRequest.getLocale(),
             sinceDays,
             pageNum, 
@@ -153,10 +175,18 @@
     
     /** Get pager of weblogs whose handles begin with specified letter */
     public Pager getWeblogsByLetterPager(String letter, int sinceDays, int length) {
+        
+        String pagerUrl = URLUtilities.getWeblogPageURL(weblog, 
+                weblogRequest.getLocale(), weblogPage.getLink(), 
+                null, null, null, 0, false);
+        
+        if(letter != null && StringUtils.isEmpty(letter)) {
+            letter = null;
+        }
+        
         return new WeblogsPager(
+            pagerUrl,
             letter,
-            weblog, 
-            weblogPage,
             weblogRequest.getLocale(),
             sinceDays,
             pageNum, 

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/AbstractPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/AbstractPager.java?rev=429901&r1=429900&r2=429901&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/AbstractPager.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/AbstractPager.java
Tue Aug  8 17:27:07 2006
@@ -18,100 +18,102 @@
 
 package org.apache.roller.ui.rendering.pagers;
 
-import java.util.List;
-import org.apache.roller.pojos.Template;
-import org.apache.roller.pojos.WebsiteData;
+import java.util.HashMap;
+import java.util.Map;
 import org.apache.roller.util.URLUtilities;
 
+
 /**
  * Abstract base for simple pagers.
  */
 public abstract class AbstractPager implements Pager {
     
-    protected List           users;
-    protected WebsiteData    weblog;
-    protected Template       weblogPage;
-    protected String         locale;
-    protected int            sinceDays;
-    protected int            page;
-    protected int            length;
-    protected int            offset;
-    protected boolean        more = false;   
-    
-    
-    /** Creates a new instance of AbstractPager */
-    public AbstractPager(            
-            WebsiteData    weblog,             
-            Template       weblogPage,
-            String         locale,
-            int            sinceDays,
-            int            page,
-            int            length) {
+    private String url = null;
+    private int page = 0;
+    
+    
+    public AbstractPager(String baseUrl, int pageNum) {
         
-        this.weblog =     weblog;
-        this.weblogPage = weblogPage;
-        this.locale =     locale;
-        this.sinceDays =  sinceDays;
-        this.page =       page;
-        this.length =     length;
-
-        if(page > 0) {
-            this.page = page;
+        this.url = baseUrl;
+        if(pageNum > 0) {
+            this.page = pageNum;
         }
-        this.offset = length * page;
     }
-
+    
+    
     public String getHomeLink() {
-        return createURL(page, 0, weblog, weblogPage, locale);
+        return url;
     }
-
+    
+    
     public String getHomeName() {
         return "Home";
     }
-
+    
+    
     public String getNextLink() {
-        if (page > 0) {
-            return createURL(page, -1, weblog, weblogPage, locale);
+        if(hasMoreItems()) {
+            int nextPage = page + 1;
+            Map params = new HashMap();
+            params.put("page", ""+nextPage);
+            return createURL(url, params);
         }
         return null;
     }
-
+    
+    
     public String getNextName() {
-        if (page > 0) {
+        if(hasMoreItems()) {
             return "Next";
         }
         return null;
     }
-
+    
+    
     public String getPrevLink() {
-        if (more) {        
-            return createURL(page, 1, weblog, weblogPage, locale);
+        if (page > 0) {
+            int prevPage = page - 1;
+            Map params = new HashMap();
+            params.put("page", ""+prevPage);
+            return createURL(url, params);
         }
         return null;
     }
-
+    
+    
     public String getPrevName() {
-        if (more) {
+        if (page > 0) {
             return "Previous";
         }
         return null;
     }
     
-    protected static String createURL(
-        int                page, 
-        int                pageAdd, 
-        WebsiteData        weblog, 
-        Template           weblogPage, 
-        String             locale) {
-
-        int pageNum = page + pageAdd;
-        String pageLink = (weblogPage != null) ? weblogPage.getLink() : null;
-        if (weblogPage != null) {
-            return URLUtilities.getWeblogPageURL(
-                weblog, locale, pageLink, null, null, null, pageNum, false);
-        } 
-        return URLUtilities.getWeblogCollectionURL(
-                weblog, locale, null, null, pageNum, false);
+    
+    public boolean hasMoreItems() {
+        return false;
+    }
+    
+    
+    protected String createURL(String url, Map params) {
+        
+        return url + URLUtilities.getQueryString(params);
+    }
+
+    
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public int getPage() {
+        return page;
+    }
+
+    public void setPage(int page) {
+        this.page = page;
     }
     
 }

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/CommentsPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/CommentsPager.java?rev=429901&r1=429900&r2=429901&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/CommentsPager.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/CommentsPager.java
Tue Aug  8 17:27:07 2006
@@ -33,54 +33,86 @@
 import org.apache.roller.pojos.WebsiteData;
 import org.apache.roller.pojos.wrapper.CommentDataWrapper;
 
+
 /**
- * Provides paging for comments.
+ * Paging through a collection of comments.
  */
 public class CommentsPager extends AbstractPager {
     
+    private static Log log = LogFactory.getLog(CommentsPager.class);
+    
+    private String locale = null;
+    private int sinceDays = -1;
+    private int length = 0;
+    
+    // the collection for the pager
     private List comments = null;
-    protected static Log log =
-            LogFactory.getFactory().getInstance(CommentsPager.class);
     
-    /** Creates a new instance of CommentPager */
-    public CommentsPager(            
-            WebsiteData    weblog,             
-            Template       weblogPage,
+    // are there more items?
+    private boolean more = false;
+    
+    
+    public CommentsPager(
+            String         baseUrl,
             String         locale,
             int            sinceDays,
             int            page,
             int            length) {
-        super(weblog, weblogPage, locale, sinceDays, page, length);
+        
+        super(baseUrl, page);
+        
+        this.locale = locale;
+        this.sinceDays = sinceDays;
+        this.length = length;
+        
+        // initialize the collection
         getItems();
     }
     
+    
     public List getItems() {
+        
         if (comments == null) {
+            // calculate offset
+            int offset = (getPage() * length) + 1;
+            
             List results = new ArrayList();
             Calendar cal = Calendar.getInstance();
             cal.setTime(new Date());
             cal.add(Calendar.DATE, -1 * sinceDays);
             Date startDate = cal.getTime();
-            try {            
+            try {
                 Roller roller = RollerFactory.getRoller();
                 WeblogManager wmgr = roller.getWeblogManager();
-                List entries = wmgr.getComments( 
-                    null, null, null, startDate, new Date(), 
-                    Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, true, offset, length + 1);
-                int count = 0;
+                List entries = wmgr.getComments(
+                        null, null, null, startDate, new Date(),
+                        Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, true, offset, length
+ 1);
+                
+                // check if there are more results for paging
+                if(entries.size() > length) {
+                    more = true;
+                    entries.remove(entries.size() - 1);
+                }
+                
+                // wrap the results
                 for (Iterator it = entries.iterator(); it.hasNext();) {
                     CommentData comment = (CommentData) it.next();
-                    if (count++ < length) {
-                        results.add(CommentDataWrapper.wrap(comment));
-                    } else {
-                        more = true;
-                    }                                
+                    results.add(CommentDataWrapper.wrap(comment));
                 }
+                
             } catch (Exception e) {
                 log.error("ERROR: fetching comment list", e);
             }
+            
             comments = results;
         }
+        
         return comments;
-    }   
+    }
+    
+    
+    public boolean hasMoreItems() {
+        return more;
+    }
+    
 }

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/PlanetEntriesPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/PlanetEntriesPager.java?rev=429901&r1=429900&r2=429901&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/PlanetEntriesPager.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/PlanetEntriesPager.java
Tue Aug  8 17:27:07 2006
@@ -34,50 +34,70 @@
 import org.apache.roller.pojos.WebsiteData;
 import org.apache.roller.pojos.wrapper.PlanetEntryDataWrapper;
 
+
 /**
- * Paging for planet entries.
+ * Paging through a collection of planet entries.
  */
 public class PlanetEntriesPager extends AbstractPager {
-    private String feedURL;
-    private String groupHandle;
-    private List entries;    
-    protected static Log log =
-            LogFactory.getFactory().getInstance(PlanetEntriesPager.class);
     
-    /** Creates a new instance of CommentPager */
-    public PlanetEntriesPager(   
+    private static Log log = LogFactory.getLog(PlanetEntriesPager.class);
+    
+    private String feedURL = null;
+    private String groupHandle = null;
+    private String locale = null;
+    private int sinceDays = -1;
+    private int length = 0;
+    
+    // the collection for the pager
+    private List entries = null;
+    
+    // are there more items?
+    private boolean more = false;
+    
+    
+    public PlanetEntriesPager(
             String         feedURL,
-            String         groupHandle,  
-            WebsiteData    weblog,
-            Template       weblogPage,
+            String         groupHandle,
+            String         baseUrl,
             String         locale,
             int            sinceDays,
             int            page,
             int            length) {
-        super(weblog, weblogPage, locale, sinceDays, page, length);
+        
+        super(baseUrl, page);
+        
         this.feedURL = feedURL;
         this.groupHandle = groupHandle;
+        this.locale = locale;
+        this.sinceDays = sinceDays;
+        this.length = length;
+        
+        // initialize the collection
         getItems();
     }
     
+    
     public List getItems() {
         if (entries == null) {
+            // calculate offset
+            int offset = (getPage() * length) + 1;
+            
             List results = new ArrayList();
             Calendar cal = Calendar.getInstance();
             cal.setTime(new Date());
             cal.add(Calendar.DATE, -1 * sinceDays);
-            Date startDate = cal.getTime();        
+            Date startDate = cal.getTime();
             try {
                 Roller roller = RollerFactory.getRoller();
                 PlanetManager planetManager = roller.getPlanetManager();
                 PlanetGroupData group = planetManager.getGroup(groupHandle);
-                List rawEntries = null; 
+                List rawEntries = null;
                 if (feedURL != null) {
                     rawEntries = planetManager.getFeedEntries(feedURL, offset, length);
                 } else if (groupHandle == null) {
                     rawEntries = planetManager.getAggregation(startDate, null, offset, length);
                 } else {
-                    rawEntries = planetManager.getAggregation(group, startDate, null, offset,
length); 
+                    rawEntries = planetManager.getAggregation(group, startDate, null, offset,
length);
                 }
                 int count = 0;
                 for (Iterator it = rawEntries.iterator(); it.hasNext();) {
@@ -87,7 +107,7 @@
                         results.add(wrapped);
                     } else {
                         more = true;
-                    }    
+                    }
                 }
             } catch (Exception e) {
                 log.error("ERROR: get aggregation", e);
@@ -95,5 +115,11 @@
             entries = results;
         }
         return entries;
-    }   
+    }
+    
+    
+    public boolean hasMoreItems() {
+        return more;
+    }
+    
 }

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/UsersPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/UsersPager.java?rev=429901&r1=429900&r2=429901&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/UsersPager.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/UsersPager.java
Tue Aug  8 17:27:07 2006
@@ -19,80 +19,152 @@
 package org.apache.roller.ui.rendering.pagers;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.model.Roller;
 import org.apache.roller.model.RollerFactory;
 import org.apache.roller.model.UserManager;
-import org.apache.roller.pojos.Template;
 import org.apache.roller.pojos.UserData;
-import org.apache.roller.pojos.WebsiteData;
 import org.apache.roller.pojos.wrapper.UserDataWrapper;
-import org.apache.roller.util.Technorati.Weblog;
+
 
 /**
- * Paging for users.
+ * Paging through a collection of users.
  */
 public class UsersPager extends AbstractPager {
-    private List users;    
+    
+    private static Log log = LogFactory.getLog(UsersPager.class);
+    
     private String letter = null;
-    protected static Log log =
-            LogFactory.getFactory().getInstance(UsersPager.class);
+    private String locale = null;
+    private int sinceDays = -1;
+    private int length = 0;
+    
+    // collection for the pager
+    private List users;
+    
+    // are there more items?
+    private boolean more = false;
+    
     
-    /** Creates a new instance of CommentPager */
-    public UsersPager(            
-            WebsiteData    weblog,             
-            Template       weblogPage,
+    public UsersPager(
+            String         baseUrl,
             String         locale,
             int            sinceDays,
             int            page,
             int            length) {
-        super(weblog, weblogPage, locale, sinceDays, page, length);
+        
+        super(baseUrl, page);
+        
+        this.locale = locale;
+        this.sinceDays = sinceDays;
+        this.length = length;
+        
+        // initialize the collection
         getItems();
     }
     
-    /** Creates a new instance of CommentPager */
-    public UsersPager(   
-            String letter,
-            WebsiteData    weblog,             
-            Template       weblogPage,
+    
+    public UsersPager(
+            String         baseUrl,
+            String         letter,
             String         locale,
             int            sinceDays,
             int            page,
             int            length) {
-        super(weblog, weblogPage, locale, sinceDays, page, length);
+        
+        super(baseUrl, page);
+        
         this.letter = letter;
+        this.locale = locale;
+        this.sinceDays = sinceDays;
+        this.length = length;
+        
+        // initialize the collection
         getItems();
     }
     
+    
+    public String getNextLink() {
+        // need to add letter param if it exists
+        if(letter != null) {
+            int page = getPage() + 1;
+            if(hasMoreItems()) {
+                Map params = new HashMap();
+                params.put("page", ""+page);
+                params.put("letter", letter);
+                return createURL(getUrl(), params);
+            }
+            return null;
+        } else {
+            return super.getNextLink();
+        }
+    }
+    
+    
+    public String getPrevLink() {
+        // need to add letter param if it exists
+        if(letter != null) {
+            int page = getPage() - 1;
+            if (page >= 0) {
+                Map params = new HashMap();
+                params.put("page", ""+page);
+                params.put("letter", letter);
+                return createURL(getUrl(), params);
+            }
+            return null;
+        } else {
+            return super.getPrevLink();
+        }
+    }
+    
+    
     public List getItems() {
+        
         if (users == null) {
+            // calculate offset
+            int offset = (getPage() * length) + 1;
+            
             List results = new ArrayList();
-            try {            
+            try {
                 Roller roller = RollerFactory.getRoller();
                 UserManager umgr = roller.getUserManager();
                 List rawUsers = null;
                 if (letter == null) {
                     rawUsers = umgr.getUsers(offset, length + 1);
                 } else {
-                    rawUsers = umgr.getUsersByLetter(letter.charAt(0), offset, length);
+                    rawUsers = umgr.getUsersByLetter(letter.charAt(0), offset, length + 1);
                 }
-                int count = 0;
+                
+                // check if there are more results for paging
+                if(rawUsers.size() > length) {
+                    more = true;
+                    rawUsers.remove(rawUsers.size() - 1);
+                }
+                
+                // wrap the results
                 for (Iterator it = rawUsers.iterator(); it.hasNext();) {
                     UserData user = (UserData) it.next();
-                    if (count++ < length) {
-                        results.add(UserDataWrapper.wrap(user));
-                    } else {
-                        more = true;
-                    }                    
+                    results.add(UserDataWrapper.wrap(user));
                 }
+                
             } catch (Exception e) {
                 log.error("ERROR: fetching user list", e);
             }
+            
             users = results;
         }
+        
         return users;
-    }   
+    }
+    
+    
+    public boolean hasMoreItems() {
+        return more;
+    }
+    
 }

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesListPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesListPager.java?rev=429901&r1=429900&r2=429901&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesListPager.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesListPager.java
Tue Aug  8 17:27:07 2006
@@ -35,70 +35,106 @@
 import org.apache.roller.pojos.WebsiteData;
 import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
 
+
 /**
  * Simple pager for list of weblog entries.
  */
 public class WeblogEntriesListPager extends AbstractPager {
-    private WebsiteData queryWeblog;
-    private UserData    queryUser;
-    private String      queryCat;
-    private List        entries;    
-    protected static Log log =
-            LogFactory.getFactory().getInstance(WeblogEntriesListPager.class);
     
-    public WeblogEntriesListPager(            
-            WebsiteData    weblog,
+    private static Log log = LogFactory.getLog(WeblogEntriesListPager.class);
+    
+    private String locale = null;
+    private int sinceDays = -1;
+    private int length = 0;
+    
+    private WebsiteData queryWeblog = null;
+    private UserData queryUser = null;
+    private String queryCat = null;
+    
+    // entries for the pager
+    private List entries;
+    
+    // are there more entries?
+    private boolean more = false;
+    
+    
+    public WeblogEntriesListPager(
+            String         baseUrl,
             WebsiteData    queryWeblog,
             UserData       queryUser,
             String         queryCat,
-            Template       weblogPage,
             String         locale,
             int            sinceDays,
-            int            page,
+            int            pageNum,
             int            length) {
-        super(weblog, weblogPage, locale, sinceDays, page, length);
+        
+        super(baseUrl, pageNum);
+        
+        // store the data
         this.queryWeblog = queryWeblog;
         this.queryUser = queryUser;
         this.queryCat = queryCat;
+        this.locale = locale;
+        this.sinceDays = sinceDays;
+        this.length = length;
+        
+        // initialize the pager collection
         getItems();
     }
     
+    
     public List getItems() {
+        
         if (entries == null) {
+            // calculate offset
+            int offset = (getPage() * length) + 1;
+            
             List results = new ArrayList();
             Calendar cal = Calendar.getInstance();
             cal.setTime(new Date());
             cal.add(Calendar.DATE, -1 * sinceDays);
             Date startDate = cal.getTime();
-            try {            
+            try {
                 Roller roller = RollerFactory.getRoller();
                 WeblogManager wmgr = roller.getWeblogManager();
                 UserManager umgr = roller.getUserManager();
-                List rawEntries = wmgr.getWeblogEntries( 
-                    queryWeblog, 
-                    queryUser, 
-                    startDate, 
-                    new Date(), 
-                    queryCat, 
-                    WeblogEntryData.PUBLISHED, 
-                    "pubTime", 
-                    locale, 
-                    offset, 
-                    length + 1);
-                int count = 0;
+                List rawEntries = wmgr.getWeblogEntries(
+                        queryWeblog,
+                        queryUser,
+                        startDate,
+                        new Date(),
+                        queryCat,
+                        WeblogEntryData.PUBLISHED,
+                        "pubTime",
+                        locale,
+                        offset,
+                        length + 1);
+                
+                // check if there are more results for paging
+                if(rawEntries.size() > length) {
+                    more = true;
+                    rawEntries.remove(rawEntries.size() - 1);
+                }
+                
+                // wrap the results
                 for (Iterator it = rawEntries.iterator(); it.hasNext();) {
                     WeblogEntryData entry = (WeblogEntryData) it.next();
-                    if (count++ < length) {
-                        results.add(WeblogEntryDataWrapper.wrap(entry));
-                    } else {
-                        more = true;
-                    }                      
+                    results.add(WeblogEntryDataWrapper.wrap(entry));
                 }
+                
             } catch (Exception e) {
                 log.error("ERROR: fetching weblog entries list", e);
             }
+            
             entries = results;
         }
+        
         return entries;
-    }   
+    }
+    
+    
+    public boolean hasMoreItems() {
+        return more;
+    }
+
 }

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogsPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogsPager.java?rev=429901&r1=429900&r2=429901&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogsPager.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogsPager.java
Tue Aug  8 17:27:07 2006
@@ -21,54 +21,116 @@
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.model.Roller;
 import org.apache.roller.model.RollerFactory;
 import org.apache.roller.model.UserManager;
-import org.apache.roller.pojos.Template;
 import org.apache.roller.pojos.WebsiteData;
 import org.apache.roller.pojos.wrapper.WebsiteDataWrapper;
 
+
 /**
- * Paging for weblogs.
+ * Paging through a collection of weblogs.
  */
 public class WeblogsPager extends AbstractPager {
-    private List weblogs;    
+    
+    private static Log log = LogFactory.getLog(WeblogsPager.class);
+    
     private String letter = null;
-    protected static Log log =
-            LogFactory.getFactory().getInstance(UsersPager.class);
+    private String locale = null;
+    private int sinceDays = -1;
+    private int length = 0;
+    
+    // collection for the pager
+    private List weblogs;
+    
+    // are there more items?
+    private boolean more = false;
+    
     
-    /** Creates a new instance of CommentPager */
-    public WeblogsPager(            
-            WebsiteData    weblog,             
-            Template       weblogPage,
+    public WeblogsPager(
+            String         baseUrl,
             String         locale,
             int            sinceDays,
             int            page,
             int            length) {
-        super(weblog, weblogPage, locale, sinceDays, page, length);
+        
+        super(baseUrl, page);
+        
+        this.locale = locale;
+        this.sinceDays = sinceDays;
+        this.length = length;
+        
+        // initialize the collection
         getItems();
     }
     
-    /** Creates a new instance of CommentPager */
-    public WeblogsPager( 
-            String letter,
-            WebsiteData    weblog,             
-            Template       weblogPage,
+    
+    public WeblogsPager(
+            String         baseUrl,
+            String         letter,
             String         locale,
             int            sinceDays,
             int            page,
             int            length) {
-        super(weblog, weblogPage, locale, sinceDays, page, length);
+        
+        super(baseUrl, page);
+        
         this.letter = letter;
+        this.locale = locale;
+        this.sinceDays = sinceDays;
+        this.length = length;
+        
+        // initialize the collection
         getItems();
     }
     
+    
+    public String getNextLink() {
+        // need to add letter param if it exists
+        if(letter != null) {
+            int page = getPage() + 1;
+            if(hasMoreItems()) {
+                Map params = new HashMap();
+                params.put("page", ""+page);
+                params.put("letter", letter);
+                return createURL(getUrl(), params);
+            }
+            return null;
+        } else {
+            return super.getNextLink();
+        }
+    }
+    
+    
+    public String getPrevLink() {
+        // need to add letter param if it exists
+        if(letter != null) {
+            int page = getPage() - 1;
+            if (page >= 0) {
+                Map params = new HashMap();
+                params.put("page", ""+page);
+                params.put("letter", letter);
+                return createURL(getUrl(), params);
+            }
+            return null;
+        } else {
+            return super.getPrevLink();
+        }
+    }
+    
+    
     public List getItems() {
+        
         if (weblogs == null) {
+            // calculate offset
+            int offset = getPage() * length;
+            
             List results = new ArrayList();
             Date startDate = null;
             if (sinceDays != -1) {
@@ -77,29 +139,41 @@
                 cal.add(Calendar.DATE, -1 * sinceDays);
                 startDate = cal.getTime();
             }
-            try {            
+            try {
                 Roller roller = RollerFactory.getRoller();
                 UserManager umgr = roller.getUserManager();
                 List weblogs = null;
                 if (letter == null) {
-                    weblogs = umgr.getWebsites(null, Boolean.TRUE, Boolean.TRUE, startDate,
null, offset, length);
+                    weblogs = umgr.getWebsites(null, Boolean.TRUE, Boolean.TRUE, startDate,
null, offset, length + 1);
                 } else {
-                    weblogs = umgr.getWeblogsByLetter(letter.charAt(0), offset, length);
+                    weblogs = umgr.getWeblogsByLetter(letter.charAt(0), offset, length +
1);
                 }
-                int count = 0;
+                
+                // check if there are more results for paging
+                if(weblogs.size() > length) {
+                    more = true;
+                    weblogs.remove(weblogs.size() - 1);
+                }
+                
+                // wrap the results
                 for (Iterator it = weblogs.iterator(); it.hasNext();) {
                     WebsiteData website = (WebsiteData) it.next();
-                    if (count++ < length) {
-                        results.add(WebsiteDataWrapper.wrap(website));
-                    } else {
-                        more = true;
-                    }                       
+                    results.add(WebsiteDataWrapper.wrap(website));
                 }
+                
             } catch (Exception e) {
                 log.error("ERROR: fetching weblog list", e);
             }
+            
             weblogs = results;
         }
+        
         return weblogs;
     }
+    
+    
+    public boolean hasMoreItems() {
+        return more;
+    }
+    
 }



Mime
View raw message