roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r418161 - in /incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering: model/PageRenderModel.java util/WeblogEntriesCollectionPager.java util/WeblogEntriesPager.java util/WeblogEntriesPermalinkPager.java
Date Fri, 30 Jun 2006 01:38:20 GMT
Author: agilliland
Date: Thu Jun 29 18:38:19 2006
New Revision: 418161

URL: http://svn.apache.org/viewvc?rev=418161&view=rev
Log:
modifying implementation of entry pager and updating page render model to use entry pager.
 we now have 2 entry pagers, 1 for a single entry pager, and one for
a collection entry pager.

NOTE: these changes have not been tested yet.


Added:
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesCollectionPager.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesPermalinkPager.java
Modified:
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PageRenderModel.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesPager.java

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PageRenderModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PageRenderModel.java?rev=418161&r1=418160&r2=418161&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PageRenderModel.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PageRenderModel.java
Thu Jun 29 18:38:19 2006
@@ -15,6 +15,7 @@
  * copyright in this work, please see the NOTICE file in the top level
  * directory of this distribution.
  */
+
 package org.apache.roller.ui.rendering.model;
 
 import java.util.ArrayList;
@@ -41,32 +42,38 @@
 import org.apache.roller.pojos.wrapper.WebsiteDataWrapper;
 import org.apache.roller.ui.authoring.struts.formbeans.CommentFormEx;
 import org.apache.roller.ui.core.RollerSession;
+import org.apache.roller.ui.rendering.util.WeblogEntriesPager;
 import org.apache.roller.ui.rendering.util.WeblogPageRequest;
 
+
 /**
  * Model provides information needed to render a weblog page.
  */
 public class PageRenderModel implements RenderModel {
+    
+    protected static Log log = LogFactory.getLog(PageRenderModel.class);
+    
     private HttpServletRequest     request = null;
     private WebsiteData            weblog = null;
     private int                    offset = 0;
     private String                 categoryPath = null;
     private String                 entryAnchor = null;
     private String                 dateString = null;
+    private int page = 0;
     private WeblogEntryDataWrapper nextEntry = null;
     private WeblogEntryDataWrapper prevEntry = null;
     private WeblogEntryDataWrapper firstEntry = null;
     private WeblogEntryDataWrapper lastEntry = null;
     
-    protected static Log log =
-            LogFactory.getFactory().getInstance(PageRenderModel.class);
+    private WeblogEntriesPager pager = null;
+    
     
     /** 
      * Creates an un-initialized new instance, Roller calls init() to complete
      * construction. 
      */
-    public PageRenderModel() {
-    }
+    public PageRenderModel() {}
+    
     
     /** 
      * Template context name to be used for model.
@@ -75,6 +82,7 @@
         return "model";
     }
     
+    
     /** 
      * Init page model based on request. 
      */
@@ -92,11 +100,19 @@
         categoryPath = parsed.getWeblogCategory();
         entryAnchor = parsed.getWeblogAnchor();
         dateString = parsed.getWeblogDate();
+        page = parsed.getPageNum();
+        
+        // lookup weblog object
         Roller roller = RollerFactory.getRoller();
         UserManager umgr = roller.getUserManager();
         weblog = umgr.getWebsiteByHandle(parsed.getWeblogHandle(), Boolean.TRUE);
+        
+        // get the entry pager which represents this page
+        this.pager = WeblogEntriesPager.getWeblogEntriesPager(
+                weblog, entryAnchor, dateString, categoryPath, page);
     }
     
+    
     /**
      * Get weblog being displayed.
      */
@@ -104,29 +120,91 @@
         return WebsiteDataWrapper.wrap(weblog);
     }
     
+    
     /**
-     * Get weblog entry to be displayed; null if not on single-entry page or 
-     * if entry not published. The entry is also available from teh pager,
-     * so this is a convenience method.
+     * Is this page considered a permalink?
      */
-    public WeblogEntryDataWrapper getWeblogEntry() {
-       WeblogEntryDataWrapper ret = null;
-        try {
-            Roller roller = RollerFactory.getRoller();
-            WeblogManager wmgr = roller.getWeblogManager();
-            WeblogEntryData entry = 
-                 wmgr.getWeblogEntryByAnchor(weblog, entryAnchor);
-            if (entry != null && entry.getStatus().equals(WeblogEntryData.PUBLISHED))
{
-                ret = WeblogEntryDataWrapper.wrap(entry);
-            }
-
-        } catch (Exception e) {
-            log.error("ERROR: fetching entry");
-        }
-        return ret;
+    public boolean isPermalink() {
+        return false;
+    }
+    
+    
+    /**
+     * A map of entries representing this page.
+     *
+     * The collection is grouped by days of entries.  Each value is a list of
+     * entry objects keyed by the date they were published.
+     */
+    public Map getEntries() {
+        return this.pager.getEntries();
+    }
+    
+    
+    /**
+     * Link value for next collection view
+     */
+    public String getNextLink() {
+        return this.pager.getNextLink();
+    }
+    
+    /**
+     * Link name for next collection view
+     */
+    public String getNextLinkName() {
+        return this.pager.getNextLinkName();
+    }
+    
+    /**
+     * Link value for prev collection view
+     */
+    public String getPrevLink() {
+        return this.pager.getPrevLink();
+    }
+    
+    /**
+     * Link name for prev collection view
+     */
+    public String getPrevLinkName() {
+        return this.pager.getPrevLinkName();
+    }
+    
+    /**
+     * Does this pager represent a multi-page collection?
+     */
+    public boolean isMultiPage() {
+        return this.pager.isMultiPage();
     }
     
     /**
+     * Link value for next page in current collection view
+     */
+    public String getNextPageLink() {
+        return this.pager.getNextPageLink();
+    }
+    
+    /**
+     * Link name for next page in current collection view
+     */
+    public String getNextPageName() {
+        return this.pager.getNextPageName();
+    }
+    
+    /**
+     * Link value for prev page in current collection view
+     */
+    public String getPrevPageLink() {
+        return this.pager.getPrevPageLink();
+    }
+    
+    /**
+     * Link value for prev page in current collection view
+     */
+    public String getPrevPageName() {
+        return this.pager.getPrevPageName();
+    }
+    
+    
+    /**
      * Get weblog category specified by request, or null if the category path
      * found in the request does not exist in the current weblog.
      */
@@ -145,14 +223,7 @@
         }
         return ret;
     }
-
-    /**
-     * Return pager for displaying weblog entries, next/prev pagers, etc.
-     */    
-    public RenderDayPager getWeblogEntriesPager(String cat) {
-       return new WeblogEntriesPager(
-               request, weblog, entryAnchor, categoryPath, cat, dateString);
-    }
+    
     
     /**
      * Get up to 100 most recent published entries in weblog.
@@ -190,6 +261,7 @@
         return recentEntries;
     }
     
+    
     /**
      * Get up to 100 most recent approved and non-spam comments in weblog.
      * @param length Max entries to return (1-100)
@@ -226,6 +298,7 @@
         return recentComments;
     }
     
+    
     /**
      * Get comment form to be displayed, may contain preview data. 
      * @return Comment form object or null if not on a comment page.
@@ -243,6 +316,7 @@
         }
         return commentForm;
     }
+    
     
     /**
      * Get preview comment or null if none exists.

Added: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesCollectionPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesCollectionPager.java?rev=418161&view=auto
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesCollectionPager.java
(added)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesCollectionPager.java
Thu Jun 29 18:38:19 2006
@@ -0,0 +1,343 @@
+/*
+ * WeblogEntriesCollectionPager.java
+ *
+ * Created on June 29, 2006, 3:09 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package org.apache.roller.ui.rendering.util;
+
+import java.text.ParsePosition;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
+import org.apache.roller.util.DateUtil;
+
+
+/**
+ * We're paging through the latest entries in the blog.
+ * In this mode there's no prev/next collection.
+ */
+public class WeblogEntriesCollectionPager extends WeblogEntriesPager {
+    
+    private static Log log = LogFactory.getLog(WeblogEntriesCollectionPager.class);
+    
+    private Map entries = null;
+    
+    private WebsiteData weblog = null;
+    private String dateString = null;
+    private String catPath = null;
+    private int page = 0;
+    
+    // these will help define the boundaries of the entries query
+    private Date startDate = null;
+    private Date endDate = null;
+    private int offset = 0;
+    private int length = 0;
+        
+    // next/prev link variables
+    private String nextLink = null;
+    private String nextLinkName = null;
+    private String prevLink = null;
+    private String prevLinkName = null;
+    
+    
+    public WeblogEntriesCollectionPager(WebsiteData weblog, String dateString,
+                              String catPath, int page) {
+        
+        this.weblog = weblog;
+        this.dateString = dateString;
+        this.catPath = catPath;
+        if(page > 0) {
+            this.page = page;
+        }
+        
+        // calculate offset and length
+        this.length = weblog.getEntryDisplayCount();
+        this.offset = length * page;
+        
+        // if we have a date string then do date calculations
+        Date thisDate = null;
+        Date nextDate = null;
+        Date prevDate = null;
+        String nextDateString = null;
+        String prevDateString = null;
+        if(dateString != null) {
+            Calendar cal = Calendar.getInstance();
+            
+            // parse date string and figure out date
+            thisDate = parseDate(dateString, weblog);
+            
+            // single day
+            if(dateString.length() == 8) {
+                // calculate next day
+                cal.setTime(thisDate);
+                cal.add(Calendar.DAY_OF_MONTH, 1);
+                cal.set(Calendar.HOUR, 0);
+                cal.set(Calendar.MINUTE, 0);
+                cal.set(Calendar.SECOND, 0);
+                nextDate = cal.getTime();
+                if(nextDate.after(getToday(weblog))) {
+                    nextDate = null;
+                }
+                
+                // calculate next day date string
+                nextDateString = DateUtil.format8chars(nextDate);
+                
+                // calculate previous day
+                cal.setTime(thisDate);
+                cal.add(Calendar.DAY_OF_MONTH, -1);
+                cal.set(Calendar.HOUR, 23);
+                cal.set(Calendar.MINUTE, 59);
+                cal.set(Calendar.SECOND, 59);
+                prevDate = cal.getTime();
+                
+                // calculate prev day date string
+                prevDateString = DateUtil.format8chars(prevDate);
+                
+                // calculate query start/end dates
+                cal = Calendar.getInstance(weblog.getTimeZoneInstance());
+                startDate = DateUtil.getStartOfDay(thisDate, cal);
+                endDate = DateUtil.getEndOfDay(thisDate, cal);
+                
+            // single month
+            } else if(dateString.length() == 6) {
+                // calculate next month
+                cal.setTime(thisDate);
+                cal.add(Calendar.MONTH, 1);
+                nextDate = cal.getTime();
+                if(nextDate.after(getToday(weblog))) {
+                    nextDate = null;
+                }
+                
+                // calculate next month date string
+                nextDateString = DateUtil.format6chars(nextDate);
+                
+                // calculate previous month
+                cal.setTime(thisDate);
+                cal.add(Calendar.MONTH, -1);
+                prevDate = cal.getTime();
+                
+                // calculate prev month date string
+                prevDateString = DateUtil.format6chars(prevDate);
+                
+                // calculate query start/end dates
+                cal = Calendar.getInstance(weblog.getTimeZoneInstance());
+                startDate = DateUtil.getStartOfMonth(thisDate, cal);
+                endDate = DateUtil.getEndOfMonth(thisDate, cal);
+            }
+        }
+        
+        // finally, calculate next/prev links and link names
+        if(dateString != null & catPath != null) {
+            nextLink = weblog.getURL()+"?date="+nextDateString+"&cat="+catPath+"&page="+page++;
+            nextLinkName = nextDateString;
+            prevLink = weblog.getURL()+"?date="+prevDateString+"&cat="+catPath;
+            prevLinkName = prevDateString;
+            
+            if(page > 1) {
+                prevLink += "&page="+page--;
+            }
+            
+        } else if(dateString != null) {
+            nextLink = weblog.getURL()+"/date/"+nextDateString;
+            nextLinkName = nextDateString;
+            prevLink = weblog.getURL()+"/date/"+prevDateString;
+            prevLinkName = prevDateString;
+            
+            nextLink += "?page="+page++;
+            if(page > 1) {
+                prevLink += "?page="+page--;
+            }
+        } else {
+            // there is no next/prev paging for homepage or just category
+        }
+    }
+    
+    
+    public Map getEntries() {
+        
+        if(this.entries == null) {
+            try {
+                this.entries = getEntriesMap(weblog, startDate, endDate,
+                        catPath, offset, length);
+            } catch (RollerException ex) {
+                log.error("Error getting entries", ex);
+            }
+        }
+        
+        return this.entries;
+    }
+    
+    
+    public String getNextLink() {
+        return nextLink;
+    }
+    
+    
+    public String getNextLinkName() {
+        return nextLinkName;
+    }
+    
+    
+    public String getPrevLink() {
+        return prevLink;
+    }
+    
+    
+    public String getPrevLinkName() {
+        return prevLinkName;
+    }
+    
+    
+    // TODO 3.0: calculate # of entries and figure this out
+//    public boolean isMultiPage() {
+//        return more;
+//    }
+//    
+//    
+//    public String getNextPageLink() {
+//        String ret = null;
+//        if (more) {
+//            ret = getCurrentPageLink() + "?page=" + this.page++;
+//        }
+//        return ret;
+//    }
+    
+    
+    public String getNextPageLinkName() {
+        String ret = null;
+        if (getNextLink() != null) {
+            ret = "Next"; // TODO: I18N
+        }
+        return ret;
+    }
+    
+    
+    public String getPrevPageLink() {
+        String ret = null;
+        if(this.page > 0) {
+            ret = getCurrentPageLink() + "?page=" + this.page--;
+        }
+        return ret;
+    }
+    
+    
+    public String getPrevPageLinkName() {
+        String ret = null;
+        if (getNextLink() != null) {
+            ret = "Prev"; // TODO: I18N
+        }
+        return ret;
+    }
+    
+    
+    private String getCurrentPageLink() {
+        return weblog.getURL();
+    }
+    
+    
+    /**
+     * Convenience method for querying for a map of entries and getting the
+     * results wrapped using our pojo wrappers.
+     */
+    Map getEntriesMap(WebsiteData weblog, Date start, Date end,
+                      String catPath, int offset, int length)
+            throws RollerException {
+        
+        Map entries = new TreeMap();
+        
+        Map mmap = RollerFactory.getRoller().getWeblogManager().getWeblogEntryObjectMap(
+                weblog,
+                start,
+                end,
+                catPath,
+                WeblogEntryData.PUBLISHED,
+                offset,
+                length);
+        
+        // need to wrap pojos
+        java.util.Date key = null;
+        Iterator days = mmap.keySet().iterator();
+        while(days.hasNext()) {
+            key = (java.util.Date)days.next();
+            
+            // now we need to go through each entry in a day and wrap
+            List wrapped = new ArrayList();
+            List unwrapped= (List) mmap.get(key);
+            for(int i=0; i < unwrapped.size(); i++) {
+                wrapped.add(i,
+                        WeblogEntryDataWrapper.wrap((WeblogEntryData)unwrapped.get(i)));
+            }
+            entries.put(key, wrapped);
+        }
+        
+        return entries;
+    }
+    
+    
+    /** 
+     * Parse data as either 6-char or 8-char format.
+     */
+    Date parseDate(String dateString, WebsiteData weblog) {
+        
+        Date ret = null;
+        SimpleDateFormat char8DateFormat = DateUtil.get8charDateFormat();
+        SimpleDateFormat char6DateFormat = DateUtil.get6charDateFormat();
+        
+        if (dateString != null
+                && dateString.length()==8
+                && StringUtils.isNumeric(dateString) ) {
+            ParsePosition pos = new ParsePosition(0);
+            ret = char8DateFormat.parse(dateString, pos);
+            
+            // make sure the requested date is not in the future
+            Date today = getToday(weblog);
+            if(ret.after(today)) {
+                ret = today;
+            }
+            
+        } else if(dateString != null
+                && dateString.length()==6
+                && StringUtils.isNumeric(dateString)) {
+            ParsePosition pos = new ParsePosition(0);
+            ret = char6DateFormat.parse(dateString, pos);
+            
+            // make sure the requested date is not in the future
+            Date today = getToday(weblog);
+            if(ret.after(today)) {
+                ret = today;
+            }
+        }
+        
+        return ret;
+    }
+    
+    
+    /**
+     * Return today based on current blog's timezone/locale.
+     */
+    Date getToday(WebsiteData weblog) {
+        Calendar todayCal = Calendar.getInstance();
+        todayCal = Calendar.getInstance(
+            weblog.getTimeZoneInstance(), weblog.getLocaleInstance());
+        todayCal.setTime(new Date());
+        return todayCal.getTime();
+    }
+    
+}

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesPager.java?rev=418161&r1=418160&r2=418161&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesPager.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesPager.java
Thu Jun 29 18:38:19 2006
@@ -4,24 +4,17 @@
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
-import java.util.Collections;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
-import javax.servlet.http.HttpServletRequest;
 import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.roller.RollerException;
-import org.apache.roller.model.Roller;
 import org.apache.roller.model.RollerFactory;
-import org.apache.roller.model.WeblogManager;
 import org.apache.roller.pojos.WeblogEntryData;
 import org.apache.roller.pojos.WebsiteData;
 import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
-import org.apache.roller.ui.rendering.model.*;
 import org.apache.roller.util.DateUtil;
 
 
@@ -30,602 +23,96 @@
  * Collection returned is a list of lists of entries, where each list of 
  * entries represents one day.
  */
-public class WeblogEntriesPager implements RenderDayPager {
+public abstract class WeblogEntriesPager {
     
-    /**
-     * Behavior of the pager is detemined by the mode, which is itself a pager.
-     * The mode may be LatestMode, SingleEntryMode, DayMode or MonthMode.
-     */
-    protected RenderDayPager mode = null;
     
-    protected Map            entries = null;
-    protected WebsiteData    weblog = null;
-    protected int            offset = 0;
-    protected int            length = 0;
-    protected String         chosenCatPath = null; 
-    protected String         dateString = null; 
-    protected String         entryAnchor = null;
-    protected boolean        more = false;
-        
-    protected static Log log =
-            LogFactory.getFactory().getInstance(WeblogEntriesPager.class); 
-    
-    public WeblogEntriesPager(
-            HttpServletRequest request, 
-            WebsiteData weblog, 
+    public static WeblogEntriesPager getWeblogEntriesPager(
+            WebsiteData weblog,
             String entryAnchor,
-            String requestedCat,
-            String callerCat,
-            String dateString) { 
-        
-        this.weblog = weblog;
-        this.dateString = dateString;
-        this.entryAnchor = entryAnchor;
-        
-        length = weblog.getEntryDisplayCount();
-        
-        if (callerCat != null && "nil".equals(callerCat)) callerCat = null;
-        
-        if (request.getParameter("offset") != null) {
-            try {
-                offset = Integer.parseInt(request.getParameter("offset"));
-            } catch (Exception ignored) {}
-        }
+            String dateString,
+            String catPath,
+            int page) {
         
-        String chosenCatPath = callerCat != null ? callerCat : requestedCat;
-        if (chosenCatPath == null) {
-            // no category specifed so use default
-            chosenCatPath = weblog.getDefaultCategory().getPath();
-            chosenCatPath = chosenCatPath.equals("/") ? null : chosenCatPath;
-        }
-        
-        // determine which mode we're working in
+        // determine which implementation to return
         if (entryAnchor != null) {
-            mode = new SingleEntryMode();
-        } else if (dateString != null && dateString.length() == 8) {
-            mode = new DayMode();
-        } else if (dateString != null && dateString.length() == 6) {
-            mode = new MonthMode();
+            return new WeblogEntriesPermalinkPager(weblog, entryAnchor);
         } else {
-            mode = new LatestMode();
+            return new WeblogEntriesCollectionPager(weblog, dateString, catPath, page);
         }
     }
-        
-    public Map getCurrentValues() {
-        return mode.getCurrentValues();
-    }
     
+    
+    /**
+     * A map of entries representing this collection.
+     *
+     * The collection is grouped by days of entries.  Each value is a list of
+     * entry objects keyed by the date they were published.
+     */
+    public abstract Map getEntries();
+    
+    
+    /**
+     * Link value for next collection view
+     */
     public String getNextLink() {
-        return mode.getNextLink();
+        return null;
     }
-
+    
+    /**
+     * Link name for next collection view
+     */
     public String getNextLinkName() {
-        return mode.getNextLink();
-    }
-
-    public String getPrevLink() {
-        return mode.getPrevLink();
-    }
-
-    public String getPrevLinkName() {
-        return mode.getPrevLinkName();
-    }
-
-    public String getNextCollectionLink() {
-        return mode.getNextCollectionLink();
-    }
-
-    public String getNextCollectionName() {
-        return mode.getNextCollectionName();
+        return null;
     }
-
-    public String getPrevCollectionLink() {
-        return mode.getPrevCollectionLink();
-    }
-
-    public String getPrevCollectionName() {
-        return mode.getPrevCollectionName();
-    }
-    
-    //-------------------------------------------------------------------------
     
     /**
-     * We're paging through the latest entries in the blog.
-     * In this mode there's no prev/next collection.
+     * Link value for prev collection view
      */
-    class LatestMode implements RenderDayPager {
-        
-        public Map getCurrentValues() {
-            return getCurrentValuesImpl();
-        }
-
-        public String getNextLink() {
-            String ret = null;
-            if (more) {
-                int nextOffset = offset + length;
-                ret = weblog.getURL() + "&offset=" + nextOffset;
-            }
-            return ret;
-        }
-
-        public String getNextLinkName() {
-            String ret = null;
-            if (getNextLink() != null) {
-                ret = "Next"; // TODO: I18N
-            }
-            return ret;
-        }
-
-        public String getPrevLink() {
-            String ret = null;
-            if (offset > 0) {
-                int prevOffset = offset + length;
-                prevOffset = (prevOffset < 0) ? 0 : prevOffset;
-                ret = weblog.getURL() + "&offset=" + prevOffset;
-            }
-            return ret;
-        }
-
-        public String getPrevLinkName() {
-            String ret = null;
-            if (getNextLink() != null) {
-                ret = "Prev"; // TODO: I18N
-            }
-            return ret;
-        }
-
-        public String getNextCollectionLink() {
-            return null;
-        }
-
-        public String getNextCollectionName() {
-            return null;
-        }
-
-        public String getPrevCollectionLink() {
-            return null;
-        }
-
-        public String getPrevCollectionName() {
-            return null;
-        }
-       
-     }
-
-    //-------------------------------------------------------------------------
+    public String getPrevLink() {
+        return null;
+    }
     
     /**
-     * We're showing one weblog entry.
-     * Next/prev return permalinks of next and previous weblog entries.
-     * In this mode there's no prev/next collection.
+     * Link name for prev collection view
      */
-    class SingleEntryMode implements RenderDayPager {
-        String nextLink = null;
-        WeblogEntryData entry = null;
-        WeblogEntryData nextEntry = null;
-        WeblogEntryData prevEntry = null;
-        
-        public SingleEntryMode() {
-            SingleEntryMode.this.getCurrentValues();
-        }
-        
-        /**
-         * Wrap entry up in map of lists.
-         */
-        public Map getCurrentValues() {
-            if (entries == null) try {
-                Roller roller = RollerFactory.getRoller();
-                WeblogManager wmgr = roller.getWeblogManager();
-                entry = wmgr.getWeblogEntryByAnchor(weblog, entryAnchor);
-                if (entry == null || !entry.getStatus().equals(WeblogEntryData.PUBLISHED))
{
-                    entry = null;
-                } else {
-                    entries = new TreeMap();
-                    entries.put(new Date(entry.getPubTime().getTime()), 
-                        Collections.singletonList(WeblogEntryDataWrapper.wrap(entry)));
-                } 
-            } catch (Exception e) {
-                log.error("ERROR: fetching entry");
-            }
-            return entries;
-        }
-
-        public String getNextLink() {
-            String ret = null;
-            if (getNextEntry() != null) {
-                ret = getNextEntry().getPermalink();
-            }
-            return ret;
-        }
-
-        public String getNextLinkName() {
-            String ret = null;
-            if (getNextEntry() != null) {
-                ret = getNextEntry().getTitle();
-            }
-            return ret;
-        }
-
-        public String getPrevLink() {
-            String ret = null;
-            if (getPrevEntry() != null) {
-                ret = getPrevEntry().getPermalink();
-            }
-            return ret;
-        }
-
-        public String getPrevLinkName() {
-            String ret = null;
-            if (getPrevEntry() != null) {
-                ret = getPrevEntry().getTitle();
-            }
-            return ret;
-        }
-
-        public String getNextCollectionLink() {
-            return null;
-        }
-
-        public String getNextCollectionName() {
-            return null;
-        }
-
-        public String getPrevCollectionLink() {
-            return null;
-        }
-
-        public String getPrevCollectionName() {
-            return null;
-        }   
-        
-        private WeblogEntryData getNextEntry() {
-            if (nextEntry == null) try {
-                Roller roller = RollerFactory.getRoller();
-                WeblogManager wmgr = roller.getWeblogManager();
-                nextEntry = wmgr.getNextEntry(entry, chosenCatPath);
-                // make sure that entry is published and not to future
-                if (nextEntry != null && nextEntry.getPubTime().after(new Date())

-                    && nextEntry.getStatus().equals(WeblogEntryData.PUBLISHED)) {
-                    nextEntry = null;
-                }
-            } catch (RollerException e) {
-                log.error("ERROR: getting next entry", e);
-            }
-            return nextEntry;
-        }
-        
-        private WeblogEntryData getPrevEntry() {
-            if (prevEntry == null) try {
-                Roller roller = RollerFactory.getRoller();
-                WeblogManager wmgr = roller.getWeblogManager();
-                prevEntry = wmgr.getPreviousEntry(entry, chosenCatPath); 
-                // make sure that entry is published and not to future
-                if (prevEntry != null && prevEntry.getPubTime().after(new Date())

-                    && prevEntry.getStatus().equals(WeblogEntryData.PUBLISHED)) {
-                    prevEntry = null;
-                }
-            } catch (RollerException e) {
-                log.error("ERROR: getting prev entry", e);
-            }
-            return prevEntry;
-        }
+    public String getPrevLinkName() {
+        return null;
     }
     
-    //-------------------------------------------------------------------------
-
     /**
-     * We're paging through entries in one day.
-     * Next/prev methods return links to offsets within day's entries.
-     * Next/prev collection methods return links to next and previous days.
+     * Does this pager represent a multi-page collection?
      */
-    class DayMode implements RenderDayPager {
-        private Date day;
-        private Date nextDay;
-        private Date prevDay;
-        
-        public DayMode() {
-            getCurrentValuesImpl();
-            day = parseDate(dateString);
-            
-            Calendar cal = Calendar.getInstance();
-            
-            cal.setTime(day);
-            cal.add(Calendar.DAY_OF_MONTH, 1);
-            cal.set(Calendar.HOUR, 0);
-            cal.set(Calendar.MINUTE, 0);
-            cal.set(Calendar.SECOND, 0);
-            nextDay = cal.getTime();
-            if (nextDay.after(getToday())) {
-                nextDay = null;
-            }
-            
-            cal.setTime(day);
-            cal.add(Calendar.DAY_OF_MONTH, -1);
-            cal.set(Calendar.HOUR, 23);
-            cal.set(Calendar.MINUTE, 59);
-            cal.set(Calendar.SECOND, 59);
-            prevDay = cal.getTime();
-        }
-        
-        public Map getCurrentValues() {
-            return getCurrentValuesImpl();
-        }
-
-        public String getNextLink() {
-            String ret = null;
-            if (more) {
-                int nextOffset = offset + length;
-                ret = weblog.getURL() + "/date/" + dateString + "&offset=" + nextOffset;
-            }
-            return ret;
-        }
-
-        public String getNextLinkName() {
-            String ret = null;
-            if (getNextLink() != null) {
-                ret = "Next"; // TODO: I18N
-            }
-            return ret;
-        }
-
-        public String getPrevLink() {
-            String ret = null;
-            if (offset > 0) {
-                int prevOffset = offset + length;
-                prevOffset = (prevOffset < 0) ? 0 : prevOffset;
-                ret = weblog.getURL() + "/date/" + dateString + "&offset=" + prevOffset;
-            }
-            return ret;
-        }
-
-        public String getPrevLinkName() {
-            String ret = null;
-            if (getNextLink() != null) {
-                ret = "Prev"; // TODO: I18N
-            }
-            return ret;
-        }
-
-        public String getNextCollectionLink() {
-            String ret = null;
-            if (nextDay != null) {
-                String next = DateUtil.format8chars(nextDay);
-                ret = weblog.getURL() + "/date/" + next;
-            }
-            return ret;
-        }
-
-        public String getNextCollectionName() {
-            String ret = null;
-            if (nextDay != null) {
-                ret = DateUtil.format8chars(nextDay);
-            }
-            return ret;
-        }
-
-        public String getPrevCollectionLink() {
-            String ret = null;
-            if (prevDay != null) {
-                String prev = DateUtil.format8chars(prevDay);
-                ret = weblog.getURL() + "/date/" + prev;
-            }
-            return ret;
-        }
-
-        public String getPrevCollectionName() {
-            String ret = null;
-            if (prevDay != null) {
-                ret = DateUtil.format8chars(prevDay);
-            }
-            return ret;
-        }
+    public boolean isMultiPage() {
+        return false;
     }
     
-    //-------------------------------------------------------------------------
-
     /**
-     * We're paging through entries within one month.
-     * Next/prev methods return links to offsets within month's entries.
-     * Next/prev collection methods return links to next and previous months.
+     * Link value for next page in current collection view
      */
-    class MonthMode implements RenderDayPager {
-        private Date month;
-        private Date nextMonth;
-        private Date prevMonth;
-        
-        public MonthMode() {
-            getCurrentValuesImpl();
-            month = parseDate(dateString);
-            
-            Calendar cal = Calendar.getInstance();
-            
-            cal.setTime(month);
-            cal.add(Calendar.MONTH, 1);
-            nextMonth = cal.getTime();
-            if (nextMonth.after(getToday())) {
-                nextMonth = null;
-            }
-            
-            cal.setTime(month);
-            cal.add(Calendar.MONTH, -1);
-            prevMonth = cal.getTime();
-        }
-        
-        public Map getCurrentValues() {
-            return getCurrentValuesImpl();
-        }
-
-        public String getNextLink() {
-            String ret = null;
-            if (more) {
-                int nextOffset = offset + length;
-                ret = weblog.getURL() + "/date/" + dateString + "&offset=" + nextOffset;
-            }
-            return ret;
-        }
-
-        public String getNextLinkName() {
-            String ret = null;
-            if (getNextLink() != null) {
-                ret = "Next"; // TODO: I18N
-            }
-            return ret;
-        }
-
-        public String getPrevLink() {
-            String ret = null;
-            if (offset > 0) {
-                int prevOffset = offset + length;
-                prevOffset = (prevOffset < 0) ? 0 : prevOffset;
-                ret = weblog.getURL() + "/date/" + dateString + "&offset=" + prevOffset;
-            }
-            return ret;
-        }
-
-        public String getPrevLinkName() {
-            String ret = null;
-            if (getNextLink() != null) {
-                ret = "Prev"; // TODO: I18N
-            }
-            return ret;
-        }
-
-        public String getNextCollectionLink() {
-            String ret = null;
-            if (nextMonth != null) {
-                String next = DateUtil.format6chars(nextMonth); 
-                ret = weblog.getURL() + "/date/" + next;
-            }
-            return ret;
-        }
-
-        public String getNextCollectionName() {
-            String ret = null;
-            if (nextMonth != null) {
-                ret = DateUtil.format6chars(nextMonth);
-            }
-            return ret;
-        }
-
-        public String getPrevCollectionLink() {
-            String ret = null;
-            if (prevMonth != null) {
-                String prev = DateUtil.format6chars(prevMonth);
-                ret = weblog.getURL() + "/date/" + prev;
-            }
-            return ret;
-        }
-
-        public String getPrevCollectionName() {
-            String ret = null;
-            if (prevMonth != null) {
-                ret = DateUtil.format6chars(prevMonth);
-            }
-            return ret;
-        }
-        
-    }  
-                
-    //------------------------------------------------------------------------
+    public String getNextPageLink() {
+        return null;
+    }
     
     /**
-     * Get current values specified by request, a map of lists of entry  
-     * wrappers, keyed by date objects, where each list holds entries 
-     * for one day.
+     * Link name for next page in current collection view
      */
-    private Map getCurrentValuesImpl() {
-        if (entries == null) {
-            entries = new TreeMap();
-            try {
-                Roller roller = RollerFactory.getRoller();
-                WeblogManager wmgr = roller.getWeblogManager();
-                Date date = parseDate(dateString);
-
-                Calendar cal = Calendar.getInstance(weblog.getTimeZoneInstance());
-                Date startDate = null;
-                Date endDate = date;
-                if (endDate == null) endDate = new Date();
-                if (mode instanceof DayMode) {
-                    // URL specified a specific day so get all entries for it
-                    startDate = DateUtil.getStartOfDay(endDate, cal);
-                    endDate = DateUtil.getEndOfDay(endDate, cal);
-                } else if (mode instanceof MonthMode) {
-                    // URL specified a specific month so get all entries for it
-                    startDate = DateUtil.getStartOfMonth(endDate, cal);
-                    endDate = DateUtil.getEndOfMonth(endDate, cal);
-                }
-                Map mmap = RollerFactory.getRoller().getWeblogManager().getWeblogEntryObjectMap(
-                        weblog,
-                        startDate,
-                        endDate,
-                        chosenCatPath,
-                        WeblogEntryData.PUBLISHED, 
-                        offset,  
-                        length);
-
-                // need to wrap pojos
-                java.util.Date key = null;
-                Iterator days = mmap.keySet().iterator();
-                while(days.hasNext()) {
-                    key = (java.util.Date)days.next();
-
-                    // now we need to go through each entry in a day and wrap
-                    List wrapped = new ArrayList();
-                    List unwrapped= (List) mmap.get(key);
-                    for(int i=0; i < unwrapped.size(); i++) {
-                        wrapped.add(i, 
-                            WeblogEntryDataWrapper.wrap((WeblogEntryData)unwrapped.get(i)));
-                    }
-                    entries.put(key, wrapped);
-                }
-            } catch (Exception e) {
-                log.error("ERROR: getting entry month map", e);
-            }
-        }
-        return entries;
+    public String getNextPageName() {
+        return null;
     }
     
-    /** 
-     * Parse data as either 6-char or 8-char format.
+    /**
+     * Link value for prev page in current collection view
      */
-    private Date parseDate(String dateString) {
-        Date ret = null;
-        SimpleDateFormat char8DateFormat = DateUtil.get8charDateFormat();
-        SimpleDateFormat char6DateFormat = DateUtil.get6charDateFormat();
-        if (   dateString!=null
-                && dateString.length()==8
-                && StringUtils.isNumeric(dateString) ) {
-            ParsePosition pos = new ParsePosition(0);
-            ret = char8DateFormat.parse( dateString, pos );
-            
-            // make sure the requested date is not in the future
-            Date today = getToday();
-            if (ret.after(today)) ret = today;
-        }
-        if (   dateString!=null
-                && dateString.length()==6
-                && StringUtils.isNumeric(dateString) ) {
-            ParsePosition pos = new ParsePosition(0);
-            ret = char6DateFormat.parse( dateString, pos );
-            
-            // make sure the requested date is not in the future
-            Date today = getToday();
-            if (ret.after(today)) ret = today;
-        }
-        return ret;
+    public String getPrevPageLink() {
+        return null;
     }
     
     /**
-     * Return today based on current blog's timezone/locale.
+     * Link value for prev page in current collection view
      */
-    private Date getToday() {
-        Calendar todayCal = Calendar.getInstance();
-        todayCal = Calendar.getInstance(
-            weblog.getTimeZoneInstance(), weblog.getLocaleInstance());
-        todayCal.setTime(new Date());
-        return todayCal.getTime();
+    public String getPrevPageName() {
+        return null;
     }
     
-
 }
 

Added: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesPermalinkPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesPermalinkPager.java?rev=418161&view=auto
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesPermalinkPager.java
(added)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesPermalinkPager.java
Thu Jun 29 18:38:19 2006
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.ui.rendering.util;
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.model.Roller;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.model.WeblogManager;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
+
+
+/**
+ * We're showing one weblog entry.
+ * Next/prev return permalinks of next and previous weblog entries.
+ * In this mode there's no prev/next collection.
+ */
+public class WeblogEntriesPermalinkPager extends WeblogEntriesPager {
+    
+    private static Log log = LogFactory.getLog(WeblogEntriesPermalinkPager.class);
+    
+    private Map entries = null;
+    private String entryAnchor = null;
+    private WebsiteData weblog = null;
+    private WeblogEntryData entry = null;
+    private WeblogEntryData nextEntry = null;
+    private WeblogEntryData prevEntry = null;
+    
+    
+    public WeblogEntriesPermalinkPager(WebsiteData weblog, String anchor) {
+        this.weblog = weblog;
+        this.entryAnchor = anchor;
+    }
+    
+    
+    /**
+     * Wrap entry up in map of lists.
+     */
+    public Map getEntries() {
+        
+        if(this.entries == null) {
+            entry = getEntry();
+            if(entry != null) {
+                entries = new HashMap();
+                entries.put(new Date(entry.getPubTime().getTime()),
+                        Collections.singletonList(WeblogEntryDataWrapper.wrap(entry)));
+            }
+        }
+        
+        return this.entries;
+    }
+    
+    
+    public String getNextLink() {
+        String ret = null;
+        if (getNextEntry() != null) {
+            ret = getNextEntry().getPermalink();
+        }
+        return ret;
+    }
+    
+    
+    public String getNextLinkName() {
+        String ret = null;
+        if (getNextEntry() != null) {
+            ret = getNextEntry().getTitle();
+        }
+        return ret;
+    }
+    
+    
+    public String getPrevLink() {
+        String ret = null;
+        if (getPrevEntry() != null) {
+            ret = getPrevEntry().getPermalink();
+        }
+        return ret;
+    }
+    
+    
+    public String getPrevLinkName() {
+        String ret = null;
+        if (getPrevEntry() != null) {
+            ret = getPrevEntry().getTitle();
+        }
+        return ret;
+    }
+    
+    
+    private WeblogEntryData getEntry() {
+        
+        if (entry == null) try {
+            Roller roller = RollerFactory.getRoller();
+            WeblogManager wmgr = roller.getWeblogManager();
+            entry = wmgr.getWeblogEntryByAnchor(weblog, entryAnchor);
+            
+            // make sure that entry is published and not to future
+            if(entry == null || 
+                    !entry.getStatus().equals(WeblogEntryData.PUBLISHED) ||
+                    entry.getPubTime().after(new Date())) {
+                entry = null;
+            }
+        } catch (RollerException e) {
+            log.error("ERROR: getting entry", e);
+        }
+        
+        return entry;
+    }
+    
+    
+    private WeblogEntryData getNextEntry() {
+        
+        if (nextEntry == null) try {
+            Roller roller = RollerFactory.getRoller();
+            WeblogManager wmgr = roller.getWeblogManager();
+            //nextEntry = wmgr.getNextEntry(entry, chosenCatPath);
+            nextEntry = wmgr.getNextEntry(getEntry(), null);
+            // make sure that entry is published and not to future
+            if (nextEntry != null && nextEntry.getPubTime().after(new Date())
+            && nextEntry.getStatus().equals(WeblogEntryData.PUBLISHED)) {
+                nextEntry = null;
+            }
+        } catch (RollerException e) {
+            log.error("ERROR: getting next entry", e);
+        }
+        
+        return nextEntry;
+    }
+    
+    
+    private WeblogEntryData getPrevEntry() {
+        
+        if (prevEntry == null) try {
+            Roller roller = RollerFactory.getRoller();
+            WeblogManager wmgr = roller.getWeblogManager();
+            //prevEntry = wmgr.getPreviousEntry(entry, chosenCatPath);
+            nextEntry = wmgr.getPreviousEntry(getEntry(), null);
+            // make sure that entry is published and not to future
+            if (prevEntry != null && prevEntry.getPubTime().after(new Date())
+            && prevEntry.getStatus().equals(WeblogEntryData.PUBLISHED)) {
+                prevEntry = null;
+            }
+        } catch (RollerException e) {
+            log.error("ERROR: getting prev entry", e);
+        }
+        
+        return prevEntry;
+    }
+    
+}



Mime
View raw message