001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018:
019: package org.apache.roller.ui.rendering.pagers;
020:
021: import java.util.ArrayList;
022: import java.util.Date;
023: import java.util.Iterator;
024: import java.util.List;
025: import java.util.Map;
026: import java.util.TreeMap;
027: import org.apache.commons.collections.comparators.ReverseComparator;
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.apache.roller.business.Roller;
031: import org.apache.roller.business.RollerFactory;
032: import org.apache.roller.business.WeblogManager;
033: import org.apache.roller.pojos.WeblogCategoryData;
034: import org.apache.roller.pojos.WeblogEntryData;
035: import org.apache.roller.pojos.WeblogTemplate;
036: import org.apache.roller.pojos.WebsiteData;
037: import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
038:
039: /**
040: *
041: */
042: public class WeblogEntriesLatestPager extends
043: AbstractWeblogEntriesPager {
044:
045: private static Log log = LogFactory
046: .getLog(WeblogEntriesLatestPager.class);
047:
048: // collection for the pager
049: private Map entries = null;
050:
051: // are there more pages?
052: private boolean more = false;
053:
054: public WeblogEntriesLatestPager(WebsiteData weblog, String locale,
055: String pageLink, String entryAnchor, String dateString,
056: String catPath, List tags, int page) {
057:
058: super (weblog, locale, pageLink, entryAnchor, dateString,
059: catPath, tags, page);
060:
061: // initialize the pager collection
062: getEntries();
063: }
064:
065: public Map getEntries() {
066:
067: if (entries == null) {
068: entries = new TreeMap(new ReverseComparator());
069: try {
070: Roller roller = RollerFactory.getRoller();
071: WeblogManager wmgr = roller.getWeblogManager();
072: Map mmap = RollerFactory.getRoller().getWeblogManager()
073: .getWeblogEntryObjectMap(weblog, null,
074: new Date(), catPath, tags,
075: WeblogEntryData.PUBLISHED, locale,
076: offset, length + 1);
077:
078: // need to wrap pojos
079: int count = 0;
080: java.util.Date key = null;
081: Iterator days = mmap.keySet().iterator();
082: while (days.hasNext()) {
083: key = (java.util.Date) days.next();
084:
085: // now we need to go through each entry in a day and wrap
086: List wrapped = new ArrayList();
087: List unwrapped = (List) mmap.get(key);
088: for (int i = 0; i < unwrapped.size(); i++) {
089: if (count++ < length) {
090: wrapped.add(i, WeblogEntryDataWrapper
091: .wrap((WeblogEntryData) unwrapped
092: .get(i)));
093: } else {
094: more = true;
095: }
096: }
097:
098: // done with that day, put it in the map
099: if (wrapped.size() > 0) {
100: entries.put(key, wrapped);
101: }
102: }
103: } catch (Exception e) {
104: log.error("ERROR: getting entry month map", e);
105: }
106: }
107:
108: return entries;
109: }
110:
111: public boolean hasMoreEntries() {
112: return more;
113: }
114:
115: }
|