roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r430234 - in /incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering: model/ pagers/
Date Thu, 10 Aug 2006 04:07:48 GMT
Author: agilliland
Date: Wed Aug  9 21:07:47 2006
New Revision: 430234

URL: http://svn.apache.org/viewvc?rev=430234&view=rev
Log:
separating weblog entries impl classes into separate classes while fixing some paging bugs.


Added:
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/AbstractWeblogEntriesPager.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesLatestPager.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesPermalinkPager.java
Modified:
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PageModel.java

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?rev=430234&r1=430233&r2=430234&view=diff
==============================================================================
--- 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 Aug  9 21:07:47 2006
@@ -19,22 +19,20 @@
 package org.apache.roller.ui.rendering.model; 
 
 import java.util.Map;
-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.WeblogCategoryData;
 import org.apache.roller.pojos.WebsiteData;
 import org.apache.roller.pojos.wrapper.TemplateWrapper;
 import org.apache.roller.pojos.wrapper.WeblogCategoryDataWrapper;
 import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
 import org.apache.roller.pojos.wrapper.WebsiteDataWrapper;
-import org.apache.roller.ui.authoring.struts.formbeans.CommentFormEx;
+import org.apache.roller.ui.rendering.pagers.WeblogEntriesDayPager;
+import org.apache.roller.ui.rendering.pagers.WeblogEntriesLatestPager;
+import org.apache.roller.ui.rendering.pagers.WeblogEntriesMonthPager;
 import org.apache.roller.ui.rendering.pagers.WeblogEntriesPager;
-import org.apache.roller.ui.rendering.pagers.WeblogEntriesPagerImpl;
+import org.apache.roller.ui.rendering.pagers.WeblogEntriesPermalinkPager;
 import org.apache.roller.ui.rendering.util.WeblogEntryCommentForm;
 import org.apache.roller.ui.rendering.util.WeblogPageRequest;
 
@@ -167,26 +165,55 @@
      * date they were published.
      * @param catArgument Category restriction (null or "nil" for no restriction)
      */
-    public WeblogEntriesPager getWeblogEntriesPager(String catArgument) {        
+    public WeblogEntriesPager getWeblogEntriesPager(String catArgument) {
+        
         // category specified by argument wins over request parameter
-        WeblogCategoryData chosenCat = null;
-        if (catArgument != null) {
-            try {
-                Roller roller = RollerFactory.getRoller();
-                WeblogManager wmgr = roller.getWeblogManager();
-                chosenCat = wmgr.getWeblogCategoryByPath(weblog, catArgument);
-            } catch (Exception ignore) {
-                log.debug("Ignoring unknown category restriction");
-            }
-        }            
-        return new WeblogEntriesPagerImpl(  
-            weblog, 
-            pageRequest.getWeblogPage(), 
-            pageRequest.getWeblogEntry(),
-            pageRequest.getWeblogDate(), 
-            chosenCat != null ? chosenCat : pageRequest.getWeblogCategory(),  
-            pageRequest.getLocale(), 
-            pageRequest.getPageNum());
+        String cat = pageRequest.getWeblogCategoryName();
+        if(catArgument != null && !StringUtils.isEmpty(catArgument) &&
+                !"nil".equals(catArgument)) {
+            cat = catArgument;
+        }
+        
+        String dateString = pageRequest.getWeblogDate();
+        
+        // determine which mode to use
+        if (pageRequest.getWeblogAnchor() != null) {
+            return new WeblogEntriesPermalinkPager(
+                    weblog,
+                    pageRequest.getLocale(),
+                    pageRequest.getWeblogPageName(),
+                    pageRequest.getWeblogAnchor(),
+                    pageRequest.getWeblogDate(),
+                    pageRequest.getWeblogCategoryName(),
+                    pageRequest.getPageNum());
+        } else if (dateString != null && dateString.length() == 8) {
+            return new WeblogEntriesDayPager(
+                    weblog,
+                    pageRequest.getLocale(),
+                    pageRequest.getWeblogPageName(),
+                    pageRequest.getWeblogAnchor(),
+                    pageRequest.getWeblogDate(),
+                    pageRequest.getWeblogCategoryName(),
+                    pageRequest.getPageNum());
+        } else if (dateString != null && dateString.length() == 6) {
+            return new WeblogEntriesMonthPager(
+                    weblog,
+                    pageRequest.getLocale(),
+                    pageRequest.getWeblogPageName(),
+                    pageRequest.getWeblogAnchor(),
+                    pageRequest.getWeblogDate(),
+                    pageRequest.getWeblogCategoryName(),
+                    pageRequest.getPageNum());
+        } else {
+            return new WeblogEntriesLatestPager(
+                    weblog,
+                    pageRequest.getLocale(),
+                    pageRequest.getWeblogPageName(),
+                    pageRequest.getWeblogAnchor(),
+                    pageRequest.getWeblogDate(),
+                    pageRequest.getWeblogCategoryName(),
+                    pageRequest.getPageNum());
+        }
     }
     
     

Added: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/AbstractWeblogEntriesPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/AbstractWeblogEntriesPager.java?rev=430234&view=auto
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/AbstractWeblogEntriesPager.java
(added)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/AbstractWeblogEntriesPager.java
Wed Aug  9 21:07:47 2006
@@ -0,0 +1,216 @@
+/*
+ * AbstractWeblogEntriesPager.java
+ *
+ * Created on August 9, 2006, 2:05 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package org.apache.roller.ui.rendering.pagers;
+
+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.collections.comparators.ReverseComparator;
+import org.apache.commons.lang.StringUtils;
+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.WeblogManager;
+import org.apache.roller.pojos.WeblogCategoryData;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.pojos.WeblogTemplate;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
+import org.apache.roller.util.DateUtil;
+import org.apache.roller.util.MessageUtilities;
+import org.apache.roller.util.URLUtilities;
+
+
+/**
+ *
+ */
+public abstract class AbstractWeblogEntriesPager implements WeblogEntriesPager {
+    
+    private static Log log = LogFactory.getLog(AbstractWeblogEntriesPager.class);
+    
+    WebsiteData weblog = null;
+    String locale = null;
+    String pageLink = null;
+    String entryAnchor = null;
+    String dateString = null;
+    String catPath = null;
+    int offset = 0;
+    int page = 0;
+    int length = 0;
+    
+    
+    public AbstractWeblogEntriesPager(
+            WebsiteData        weblog,
+            String             locale,
+            String             pageLink,
+            String             entryAnchor,
+            String             dateString,
+            String             catPath,
+            int                page) {
+        
+        this.weblog = weblog;
+        this.locale = locale;
+        this.pageLink = pageLink;
+        this.entryAnchor = entryAnchor;
+        this.dateString = dateString;
+        this.catPath = catPath;
+        
+        // make sure offset, length, and page are valid
+        length = weblog.getEntryDisplayCount();
+        if(page > 0) {
+            this.page = page;
+        }
+        this.offset = length * page;
+    }
+    
+    
+    public boolean hasMoreEntries() {
+        return false;
+    }
+    
+    
+    public String getHomeLink() {
+        return createURL(0, 0, weblog, locale, pageLink, entryAnchor, dateString, catPath);
+    }
+    
+    
+    public String getHomeName() {
+        return MessageUtilities.getString("weblogEntriesPager.latest.home");
+    }
+    
+    
+    public String getNextLink() {
+        if (hasMoreEntries()) {
+            return createURL(page, 1, weblog, locale, pageLink, entryAnchor, dateString,
catPath);
+        }
+        return null;
+    }
+    
+    
+    public String getNextName() {
+        if (hasMoreEntries()) {
+            return MessageUtilities.getString("weblogEntriesPager.latest.next");
+        }
+        return null;
+    }
+    
+    
+    public String getPrevLink() {
+        if (page > 0) {
+            return createURL(page, -1, weblog, locale, pageLink, entryAnchor, dateString,
catPath);
+        }
+        return null;
+    }
+    
+    
+    public String getPrevName() {
+        if (page > 0) {
+            return MessageUtilities.getString("weblogEntriesPager.latest.prev");
+        }
+        return null;
+    }
+    
+    
+    public String getNextCollectionLink() {
+        return null;
+    }
+    
+    
+    public String getNextCollectionName() {
+        return null;
+    }
+    
+    
+    public String getPrevCollectionLink() {
+        return null;
+    }
+    
+    
+    public String getPrevCollectionName() {
+        return null;
+    }
+    
+    
+    /**
+     * Parse data as either 6-char or 8-char format.
+     */
+    protected 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;
+    }
+    
+    
+    /**
+     * Return today based on current blog's timezone/locale.
+     */
+    protected Date getToday() {
+        Calendar todayCal = Calendar.getInstance();
+        todayCal = Calendar.getInstance(
+                weblog.getTimeZoneInstance(), weblog.getLocaleInstance());
+        todayCal.setTime(new Date());
+        return todayCal.getTime();
+    }
+    
+    
+    /**
+     * Create URL that encodes pager state using most appropriate forms of URL.
+     * @param pageAdd To be added to page number, or 0 for no page number
+     */
+    protected String createURL(
+            int                page,
+            int                pageAdd,
+            WebsiteData        website,
+            String             locale,
+            String             pageLink,
+            String             entryAnchor,
+            String             dateString,
+            String             catPath) {
+        
+        int pageNum = page + pageAdd;
+        
+        if (pageLink != null) {
+            return URLUtilities.getWeblogPageURL(website, locale, pageLink, entryAnchor,
catPath, dateString, pageNum, false);
+        } else if (entryAnchor != null) {
+            return URLUtilities.getWeblogEntryURL(website, locale, entryAnchor, true);
+        }
+        
+        return URLUtilities.getWeblogCollectionURL(website, locale, catPath, dateString,
pageNum, false);
+    }
+    
+}

Added: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java?rev=430234&view=auto
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java
(added)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesDayPager.java
Wed Aug  9 21:07:47 2006
@@ -0,0 +1,220 @@
+/*
+ * WeblogEntriesDayPager.java
+ *
+ * Created on August 9, 2006, 2:36 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package org.apache.roller.ui.rendering.pagers;
+
+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.collections.comparators.ReverseComparator;
+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.WeblogManager;
+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;
+import org.apache.roller.util.MessageUtilities;
+
+
+/**
+ *
+ */
+public class WeblogEntriesDayPager extends AbstractWeblogEntriesPager {
+    
+    private static Log log = LogFactory.getLog(WeblogEntriesDayPager.class);
+    
+    private SimpleDateFormat dayFormat = new SimpleDateFormat(
+            MessageUtilities.getString("weblogEntriesPager.day.dateFormat"));
+    
+    private Date day;
+    private Date nextDay;
+    private Date prevDay;
+    
+    // collection for the pager
+    private Map entries = null;
+    
+    // are there more pages?
+    private boolean more = false;
+    
+    
+    public WeblogEntriesDayPager(
+            WebsiteData        weblog,
+            String             locale,
+            String             pageLink,
+            String             entryAnchor,
+            String             dateString,
+            String             catPath,
+            int                page) {
+        
+        super(weblog, locale, pageLink, entryAnchor, dateString, catPath, page);
+        
+        getEntries();
+        
+        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 getEntries() {
+        Date date = parseDate(dateString);
+        Calendar cal = Calendar.getInstance(weblog.getTimeZoneInstance());
+        Date startDate = null;
+        Date endDate = date;
+        startDate = DateUtil.getStartOfDay(endDate, cal);
+        endDate = DateUtil.getEndOfDay(endDate, cal);
+        
+        if (entries == null) {
+            entries = new TreeMap(new ReverseComparator());
+            try {
+                Roller roller = RollerFactory.getRoller();
+                WeblogManager wmgr = roller.getWeblogManager();
+                Map mmap = RollerFactory.getRoller().getWeblogManager().getWeblogEntryObjectMap(
+                        weblog,
+                        startDate,
+                        endDate,
+                        catPath,
+                        WeblogEntryData.PUBLISHED, 
+                        locale,
+                        offset,  
+                        length + 1);
+                
+                // need to wrap pojos
+                int count = 0;
+                Date key = null;
+                Iterator days = mmap.keySet().iterator();
+                while(days.hasNext()) {
+                    key = (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++) {
+                        if (count++ < length) {
+                            wrapped.add(i, 
+                            WeblogEntryDataWrapper.wrap((WeblogEntryData)unwrapped.get(i)));
+                        } else {
+                            more = true;
+                        }
+                    }
+                    
+                    // done with that day, put it in the map
+                    entries.put(key, wrapped);
+                }
+                
+                
+            } catch (Exception e) {
+                log.error("ERROR: getting entry month map", e);
+            }
+        }
+        return entries;
+    }
+    
+    
+    public String getHomeLink() {
+        return createURL(0, 0, weblog, locale, pageLink, null, null, catPath);
+    }
+    
+    
+    public String getHomeName() {
+        return MessageUtilities.getString("weblogEntriesPager.day.home");
+    }
+    
+    
+    public String getNextLink() {
+        if (more) {
+            return createURL(page, 1, weblog, locale, pageLink, null, dateString, catPath);
+        }
+        return null;
+    }
+    
+    
+    public String getNextName() {
+        if (getNextLink() != null) {
+            return MessageUtilities.getString("weblogEntriesPager.day.next", new Object[]
{dayFormat.format(day)});
+        }
+        return null;
+    }
+    
+    
+    public String getPrevLink() {
+        if (page > 0) {
+            return createURL(page, -1, weblog, locale, pageLink, null, dateString, catPath);
+        }
+        return null;
+    }
+    
+    
+    public String getPrevName() {
+        if (getPrevLink() != null) {
+            return MessageUtilities.getString("weblogEntriesPager.day.prev", new Object[]
{dayFormat.format(day)});
+        }
+        return null;
+    }
+    
+    
+    public String getNextCollectionLink() {
+        if (nextDay != null) {
+            String next = DateUtil.format8chars(nextDay);
+            return createURL(0, 0, weblog, locale, pageLink, null, next, catPath);
+        }
+        return null;
+    }
+    
+    
+    public String getNextCollectionName() {
+        if (nextDay != null) {
+            return MessageUtilities.getString("weblogEntriesPager.day.nextCollection", new
Object[] {dayFormat.format(nextDay)});
+        }
+        return null;
+    }
+    
+    
+    public String getPrevCollectionLink() {
+        if (prevDay != null) {
+            String prev = DateUtil.format8chars(prevDay);
+            return createURL(0, 0, weblog, locale, pageLink, null, prev, catPath);
+        }
+        return null;
+    }
+    
+    
+    public String getPrevCollectionName() {
+        if (prevDay != null) {
+            return MessageUtilities.getString("weblogEntriesPager.day.prevCollection", new
Object[] {dayFormat.format(prevDay)});
+        }
+        return null;
+    }
+    
+}

Added: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesLatestPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesLatestPager.java?rev=430234&view=auto
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesLatestPager.java
(added)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesLatestPager.java
Wed Aug  9 21:07:47 2006
@@ -0,0 +1,113 @@
+/*
+ * WeblogEntriesLatestPager.java
+ *
+ * Created on August 9, 2006, 2:04 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package org.apache.roller.ui.rendering.pagers;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import org.apache.commons.collections.comparators.ReverseComparator;
+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.WeblogManager;
+import org.apache.roller.pojos.WeblogCategoryData;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.pojos.WeblogTemplate;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
+
+
+/**
+ *
+ */
+public class WeblogEntriesLatestPager extends AbstractWeblogEntriesPager {
+    
+    private static Log log = LogFactory.getLog(WeblogEntriesLatestPager.class);
+    
+    // collection for the pager
+    private Map entries = null;
+    
+    // are there more pages?
+    private boolean more = false;
+    
+    
+    public WeblogEntriesLatestPager(
+            WebsiteData        weblog,
+            String             locale,
+            String             pageLink,
+            String             entryAnchor,
+            String             dateString,
+            String             catPath,
+            int                page) {
+        
+        super(weblog, locale, pageLink, entryAnchor, dateString, catPath, page);
+        
+        // initialize the pager collection
+        getEntries();
+    }
+    
+    
+    public Map getEntries() {
+        
+        if (entries == null) {
+            entries = new TreeMap(new ReverseComparator());
+            try {
+                Roller roller = RollerFactory.getRoller();
+                WeblogManager wmgr = roller.getWeblogManager();
+                Map mmap = RollerFactory.getRoller().getWeblogManager().getWeblogEntryObjectMap(
+                        weblog,
+                        null,
+                        new Date(),
+                        catPath,
+                        WeblogEntryData.PUBLISHED,
+                        locale,
+                        offset,
+                        length + 1);
+                
+                // need to wrap pojos
+                int count = 0;
+                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++) {
+                        if (count++ < length) {
+                            wrapped.add(i,
+                                WeblogEntryDataWrapper.wrap((WeblogEntryData)unwrapped.get(i)));
+                        } else {
+                            more = true;
+                        }
+                    }
+                    
+                    // done with that day, put it in the map
+                    entries.put(key, wrapped);
+                }
+            } catch (Exception e) {
+                log.error("ERROR: getting entry month map", e);
+            }
+        }
+        
+        return entries;
+    }
+    
+    
+    public boolean hasMoreEntries() {
+        return more;
+    }
+    
+}

Added: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java?rev=430234&view=auto
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java
(added)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesMonthPager.java
Wed Aug  9 21:07:47 2006
@@ -0,0 +1,213 @@
+/*
+ * WeblogEntriesMonthPager.java
+ *
+ * Created on August 9, 2006, 2:39 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package org.apache.roller.ui.rendering.pagers;
+
+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.collections.comparators.ReverseComparator;
+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.WeblogManager;
+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;
+import org.apache.roller.util.MessageUtilities;
+
+
+/**
+ *
+ */
+public class WeblogEntriesMonthPager extends AbstractWeblogEntriesPager {
+    
+    private static Log log = LogFactory.getLog(WeblogEntriesMonthPager.class);
+    
+    private SimpleDateFormat monthFormat = new SimpleDateFormat(
+            MessageUtilities.getString("weblogEntriesPager.month.dateFormat"));
+    
+    private Date month;
+    private Date nextMonth;
+    private Date prevMonth;
+    
+    // collection for the pager
+    private Map entries = null;
+    
+    // are there more pages?
+    private boolean more = false;
+    
+    
+    public WeblogEntriesMonthPager(
+            WebsiteData        weblog,
+            String             locale,
+            String             pageLink,
+            String             entryAnchor,
+            String             dateString,
+            String             catPath,
+            int                page) {
+        
+        super(weblog, locale, pageLink, entryAnchor, dateString, catPath, page);
+        
+        getEntries();
+        
+        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 getEntries() {
+        Date date = parseDate(dateString);
+        Calendar cal = Calendar.getInstance(weblog.getTimeZoneInstance());
+        cal.setTime(date);
+        cal.add(Calendar.DATE, 1);
+        date = cal.getTime();
+        Date startDate = DateUtil.getStartOfMonth(date, cal);;
+        Date endDate = DateUtil.getEndOfMonth(date, cal);;
+        
+        if (entries == null) {
+            entries = new TreeMap(new ReverseComparator());
+            try {
+                Roller roller = RollerFactory.getRoller();
+                WeblogManager wmgr = roller.getWeblogManager();
+                Map mmap = RollerFactory.getRoller().getWeblogManager().getWeblogEntryObjectMap(
+                        weblog,
+                        startDate,
+                        endDate,
+                        catPath,
+                        WeblogEntryData.PUBLISHED, 
+                        locale,
+                        offset,  
+                        length + 1);
+                              
+                // need to wrap pojos
+                int count = 0;
+                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++) {
+                        if (count++ < length) {
+                            wrapped.add(i, 
+                            WeblogEntryDataWrapper.wrap((WeblogEntryData)unwrapped.get(i)));
+                        } else {
+                            more = true;
+                        }
+                    }
+                    
+                    // done with that day, put it in the map
+                    entries.put(key, wrapped);
+                }
+            } catch (Exception e) {
+                log.error("ERROR: getting entry month map", e);
+            }
+        }
+        return entries;
+    }
+    
+    
+    public String getHomeLink() {
+        return createURL(0, 0, weblog, locale, pageLink, null, null, catPath);
+    }
+    
+    
+    public String getHomeName() {
+        return MessageUtilities.getString("weblogEntriesPager.month.home");
+    }
+    
+    
+    public String getNextLink() {
+        if (more) {
+            return createURL(page, 1, weblog, locale, pageLink, null, dateString, catPath);
+        }
+        return null;
+    }
+    
+    
+    public String getNextName() {
+        if (getNextLink() != null) {
+            return MessageUtilities.getString("weblogEntriesPager.month.next", new Object[]
{monthFormat.format(month)});
+        }
+        return null;
+    }
+    
+    
+    public String getPrevLink() {
+        if (offset > 0) {
+            return createURL(page, -1, weblog, locale, pageLink, null, dateString, catPath);
+        }
+        return null;
+    }
+    
+    
+    public String getPrevName() {
+        if (getPrevLink() != null) {
+            return MessageUtilities.getString("weblogEntriesPager.month.prev", new Object[]
{monthFormat.format(month)});
+        }
+        return null;
+    }
+    
+    
+    public String getNextCollectionLink() {
+        if (nextMonth != null) {
+            String next = DateUtil.format6chars(nextMonth);
+            return createURL(0, 0, weblog, locale, pageLink, null, next, catPath);
+        }
+        return null;
+    }
+    
+    
+    public String getNextCollectionName() {
+        if (nextMonth != null) {
+            return MessageUtilities.getString("weblogEntriesPager.month.nextCollection",
new Object[] {monthFormat.format(nextMonth)});
+        }
+        return null;
+    }
+    
+    
+    public String getPrevCollectionLink() {
+        if (prevMonth != null) {
+            String prev = DateUtil.format6chars(prevMonth);
+            return createURL(0, 0, weblog, locale, pageLink, null, prev, catPath);
+        }
+        return null;
+    }
+    
+    
+    public String getPrevCollectionName() {
+        if (prevMonth != null) {
+            return MessageUtilities.getString("weblogEntriesPager.month.prevCollection",
new Object[] {monthFormat.format(prevMonth)});
+        }
+        return null;
+    }
+    
+}

Added: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesPermalinkPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesPermalinkPager.java?rev=430234&view=auto
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesPermalinkPager.java
(added)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/pagers/WeblogEntriesPermalinkPager.java
Wed Aug  9 21:07:47 2006
@@ -0,0 +1,155 @@
+/*
+ * WeblogEntriesPermalinkPager.java
+ *
+ * Created on August 9, 2006, 2:23 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package org.apache.roller.ui.rendering.pagers;
+
+import java.text.MessageFormat;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Map;
+import java.util.TreeMap;
+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.util.MessageUtilities;
+import org.apache.roller.util.Utilities;
+
+
+/**
+ *
+ */
+public class WeblogEntriesPermalinkPager extends AbstractWeblogEntriesPager {
+    
+    private static Log log = LogFactory.getLog(WeblogEntriesPermalinkPager.class);
+    
+    WeblogEntryData currEntry = null;
+    WeblogEntryData nextEntry = null;
+    WeblogEntryData prevEntry = null;
+    
+    // collection for the pager
+    private Map entries = null;
+    
+    
+    public WeblogEntriesPermalinkPager(
+            WebsiteData        weblog,
+            String             locale,
+            String             pageLink,
+            String             entryAnchor,
+            String             dateString,
+            String             catPath,
+            int                page) {
+        
+        super(weblog, locale, pageLink, entryAnchor, dateString, catPath, page);
+        
+        getEntries();
+    }
+    
+    
+    public Map getEntries() {
+        if (entries == null) try {
+            Roller roller = RollerFactory.getRoller();
+            WeblogManager wmgr = roller.getWeblogManager();
+            currEntry = wmgr.getWeblogEntryByAnchor(weblog, entryAnchor);
+            if (currEntry != null && currEntry.getStatus().equals(WeblogEntryData.PUBLISHED))
{
+                entries = new TreeMap();
+                entries.put(new Date(currEntry.getPubTime().getTime()),
+                        Collections.singletonList(WeblogEntryDataWrapper.wrap(currEntry)));
+            }
+        } catch (Exception e) {
+            log.error("ERROR: fetching entry");
+        }
+        
+        return entries;
+    }
+    
+    
+    public String getHomeLink() {
+        return createURL(0, 0, weblog, locale, pageLink, null, dateString, catPath);
+    }
+    
+    
+    public String getHomeName() {
+        return MessageUtilities.getString("weblogEntriesPager.single.home");
+    }
+    
+    
+    public String getNextLink() {
+        if (getNextEntry() != null) {
+            return createURL(0, 0, weblog, locale, pageLink, nextEntry.getAnchor(), dateString,
catPath);
+        }
+        return null;
+    }
+    
+    
+    public String getNextName() {
+        if (getNextEntry() != null) {
+            String title = Utilities.truncateNicely(getNextEntry().getTitle(), 15, 20, "...");
+            return MessageUtilities.getString("weblogEntriesPager.single.next", new Object[]
{title});
+        }
+        return null;
+    }
+    
+    
+    public String getPrevLink() {
+        if (getPrevEntry() != null) {
+            return createURL(0, 0, weblog, locale, pageLink, prevEntry.getAnchor(), dateString,
catPath);
+        }
+        return null;
+    }
+    
+    
+    public String getPrevName() {
+        if (getPrevEntry() != null) {
+            String title = Utilities.truncateNicely(getPrevEntry().getTitle(), 15, 20, "...");
+            return MessageUtilities.getString("weblogEntriesPager.single.prev", new Object[]
{title});
+        }
+        return null;
+    }
+    
+    
+    private WeblogEntryData getNextEntry() {
+        if (nextEntry == null) try {
+            Roller roller = RollerFactory.getRoller();
+            WeblogManager wmgr = roller.getWeblogManager();
+            nextEntry = wmgr.getNextEntry(currEntry, null, locale);
+            // 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(currEntry, null, locale);
+            // 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