[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/plugin/blogdirectory ...

Christian Bauer christian at hibernate.org
Thu Apr 26 11:11:51 EDT 2007


  User: cbauer  
  Date: 07/04/26 11:11:51

  Modified:    examples/wiki/src/main/org/jboss/seam/wiki/plugin/blogdirectory   
                        BlogDirectory.java BlogDirectoryPreferences.java
                        BlogEntry.java
  Log:
  New blog features: recent entries, index of all entries
  
  Revision  Changes    Path
  1.7       +76 -17    jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/plugin/blogdirectory/BlogDirectory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BlogDirectory.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/plugin/blogdirectory/BlogDirectory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- BlogDirectory.java	19 Apr 2007 09:32:05 -0000	1.6
  +++ BlogDirectory.java	26 Apr 2007 15:11:51 -0000	1.7
  @@ -1,14 +1,16 @@
   package org.jboss.seam.wiki.plugin.blogdirectory;
   
  +import org.jboss.seam.ScopeType;
   import org.jboss.seam.annotations.*;
   import org.jboss.seam.annotations.Observer;
  -import org.jboss.seam.ScopeType;
  +import org.jboss.seam.annotations.datamodel.DataModel;
  +import org.jboss.seam.core.FacesMessages;
   import org.jboss.seam.wiki.core.dao.NodeDAO;
   import org.jboss.seam.wiki.core.model.Directory;
   import org.jboss.seam.wiki.core.model.Document;
   
  -import java.util.*;
   import java.io.Serializable;
  +import java.util.*;
   
   @Name("blogDirectory")
   @Scope(ScopeType.PAGE)
  @@ -18,41 +20,41 @@
       NodeDAO nodeDAO;
   
       @In
  +    FacesMessages facesMessages;
  +
  +    @In
       Directory currentDirectory;
   
       @In
       Document currentDocument;
   
       @RequestParameter
  +    Boolean blogIndex;
  +
  +    @RequestParameter
       private void setBlogPage(Integer blogPage) {
           if (blogPage != null) this.page = blogPage;
       }
   
  -    @RequestParameter
  -    private Integer day;
  -    @RequestParameter
  -    private Integer month;
  -    @RequestParameter
  -    private Integer year;
  -
       private List<BlogEntry> blogEntries;
   
  +    // Need to expose this as a datamodel so Seam can convert our map to a bunch of Map.Entry objects
  +    @DataModel
  +    private Map<Date, List<BlogEntry>> recentBlogEntries;
  +    @DataModel
  +    private Map<Date, List<BlogEntry>> allBlogEntries;
  +   
       private String orderByProperty;
       private boolean orderDescending;
       private int totalRowCount;
       private int page;
       @In("#{blogDirectoryPreferences.properties['pageSize']}")
       private long pageSize;
  -    private Calendar startDate;
  -    private Calendar endDate;
  +    @In("#{blogDirectoryPreferences.properties['recentHeadlines']}")
  +    private long recentBlogEntriesCount;
   
       @Create
       public void initialize() {
  -        Calendar today = new GregorianCalendar();
  -        if (day == null) day = today.get(Calendar.DAY_OF_MONTH);
  -        if (month == null) month = today.get(Calendar.MONTH);
  -        if (year == null) year = today.get(Calendar.YEAR);
  -
           orderByProperty = "createdOn";
           orderDescending = true;
           refreshBlogEntries();
  @@ -76,11 +78,68 @@
           }
       }
   
  +    private void queryRecentBlogEntries() {
  +        List<Document> documents =
  +                nodeDAO.findWithParent(Document.class, currentDirectory, currentDocument, "createdOn", true, 0, recentBlogEntriesCount);
  +
  +        recentBlogEntries = new LinkedHashMap<Date, List<BlogEntry>>();
  +        for (Document document : documents) {
  +
  +            // Find the day (ignore the hours, minutes, etc.)
  +            Calendar createdOn = new GregorianCalendar();
  +            createdOn.setTime(document.getCreatedOn());
  +            GregorianCalendar createdOnDay = new GregorianCalendar(
  +                createdOn.get(Calendar.YEAR), createdOn.get(Calendar.MONTH), createdOn.get(Calendar.DAY_OF_MONTH)
  +            );
  +            Date createdOnDate = createdOnDay.getTime(); // Jesus, this API is just bad...
  +
  +            // Aggregate by day
  +            List<BlogEntry> entriesForDay =
  +                recentBlogEntries.containsKey(createdOnDate)
  +                ? recentBlogEntries.get(createdOnDate)
  +                : new ArrayList<BlogEntry>();
  +
  +            entriesForDay.add(new BlogEntry(document));
  +            recentBlogEntries.put(createdOnDate, entriesForDay);
  +        }
  +    }
  +
  +    private void queryAllBlogEntries() {
  +        if (blogIndex == null || !blogIndex) return;
  +        List<Document> documents =
  +                nodeDAO.findWithParent(Document.class, currentDirectory, currentDocument, "createdOn", true, 0, 0);
  +
  +        allBlogEntries = new LinkedHashMap<Date, List<BlogEntry>>();
  +        for (Document document : documents) {
  +
  +            // Find the month (ignore the days, hours, minutes, etc.)
  +            Calendar createdOn = new GregorianCalendar();
  +            createdOn.setTime(document.getCreatedOn());
  +            GregorianCalendar createdOnMonth = new GregorianCalendar(
  +                createdOn.get(Calendar.YEAR), createdOn.get(Calendar.MONTH), 1
  +            );
  +            Date createdOnDate = createdOnMonth.getTime(); // Jesus, this API is just bad...
  +
  +            // Aggregate by month
  +            List<BlogEntry> entriesForMonth =
  +                allBlogEntries.containsKey(createdOnDate)
  +                ? allBlogEntries.get(createdOnDate)
  +                : new ArrayList<BlogEntry>();
  +
  +            entriesForMonth.add(new BlogEntry(document));
  +            allBlogEntries.put(createdOnDate, entriesForMonth);
  +        }
  +    }
  +
       @Observer("Preferences.blogDirectoryPreferences")
       public void refreshBlogEntries() {
           blogEntries = new ArrayList<BlogEntry>();
           queryRowCount();
  -        if (totalRowCount != 0) queryBlogEntries();
  +        if (totalRowCount != 0) {
  +            queryBlogEntries();
  +            queryRecentBlogEntries();
  +            queryAllBlogEntries();
  +        }
       }
   
       public List<BlogEntry> getBlogEntries() {
  
  
  
  1.3       +4 -0      jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/plugin/blogdirectory/BlogDirectoryPreferences.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BlogDirectoryPreferences.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/plugin/blogdirectory/BlogDirectoryPreferences.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- BlogDirectoryPreferences.java	5 Apr 2007 14:38:25 -0000	1.2
  +++ BlogDirectoryPreferences.java	26 Apr 2007 15:11:51 -0000	1.3
  @@ -26,4 +26,8 @@
       @Range(min = 1l, max = 100l)
       private Long pageSize;
   
  +    @Preference(description = "02. Number of recent entries in headline list", visibility = PreferenceVisibility.INSTANCE)
  +    @Range(min = 1l, max = 100l)
  +    private Long recentHeadlines;
  +
   }
  
  
  
  1.3       +4 -0      jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/plugin/blogdirectory/BlogEntry.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BlogEntry.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/plugin/blogdirectory/BlogEntry.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- BlogEntry.java	19 Apr 2007 09:32:05 -0000	1.2
  +++ BlogEntry.java	26 Apr 2007 15:11:51 -0000	1.3
  @@ -9,6 +9,10 @@
       Document entryDocument;
       Long commentCount;
   
  +    public BlogEntry(Document entryDocument) {
  +        this.entryDocument = entryDocument;
  +    }
  +
       public BlogEntry(Document entryDocument, Long commentCount) {
           this.entryDocument = entryDocument;
           this.commentCount = commentCount;
  
  
  



More information about the jboss-cvs-commits mailing list