1 package org.roller.presentation.weblog.tags; 2 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 import org.apache.velocity.Template; 6 import org.apache.velocity.VelocityContext; 7 import org.apache.velocity.runtime.RuntimeSingleton; 8 import org.roller.model.WeblogManager; 9 import org.roller.pojos.PageData; 10 import org.roller.pojos.WebsiteData; 11 import org.roller.presentation.RollerRequest; 12 13 import java.io.PrintWriter ; 14 import java.util.ArrayList ; 15 import java.util.Date ; 16 import java.util.Iterator ; 17 import java.util.Map ; 18 19 import javax.servlet.http.HttpServletRequest ; 20 import javax.servlet.jsp.JspException ; 21 import javax.servlet.jsp.tagext.Tag ; 22 23 24 28 public class ViewWeblogEntriesTag 29 extends org.roller.presentation.tags.HybridTag 30 { 31 private static Log mLogger = 32 LogFactory.getFactory().getInstance(RollerRequest.class); 33 34 35 public String getDayTemplate() { return mDayTemplate; } 36 public void setDayTemplate( String n ) { mDayTemplate = n; } 37 private String mDayTemplate = null; 38 39 40 public String getCatName() { return mCatName; } 41 public void setCatName( String n ) { mCatName = n; } 42 private String mCatName = null; 43 44 45 public int getMaxEntries() { return mMaxEntries; } 46 public void setMaxEntries( int v ) { mMaxEntries = v; } 47 private int mMaxEntries = -1; 48 49 51 public String view( String catName ) 52 { 53 mCatName = catName; 54 return emit(); 55 } 56 57 public String view( String catName, int maxEntries ) 58 { 59 mCatName = catName; 60 mMaxEntries = maxEntries; 61 return emit(); 62 } 63 64 69 public int doStartTag( PrintWriter pw ) throws JspException 70 { 71 try 72 { 73 HttpServletRequest req = 74 (HttpServletRequest )pageContext.getRequest(); 75 76 RollerRequest rreq = RollerRequest.getRollerRequest(req); 77 78 WebsiteData website = rreq.getWebsite( ); 80 81 String catName = mCatName; 82 if (catName == null) 83 { 84 catName= req.getParameter(RollerRequest.WEBLOGCATEGORYNAME_KEY); 85 } 86 87 String name = null; 88 if ( rreq.getUser() != null ) 89 { 90 name = rreq.getUser().getUserName(); 91 } 92 93 int max = (mMaxEntries == -1) ? 15 : mMaxEntries; 95 Date dayParam = rreq.getDate(true); 96 WeblogManager mgr = rreq.getRoller().getWeblogManager(); 97 98 101 Map map = mgr.getWeblogEntryObjectMap( 102 rreq.getWebsite(), null, dayParam, catName, WeblogManager.PUB_ONLY, new Integer (max)); 109 110 String pid = null; 112 if ( mDayTemplate != null ) 113 { 114 PageData page = 115 rreq.getRoller().getUserManager().getPageByLink( 116 website, mDayTemplate ); 117 if (page != null) 118 { 119 pid = page.getId(); 120 } 121 } 122 if ( pid == null ) 123 { 124 pid = website.getWeblogDayPageId(); 125 } 126 127 Template vtemplate = RuntimeSingleton.getTemplate( pid ); 129 130 int count = 0; 132 Iterator iter = map.keySet().iterator(); 133 while ( iter.hasNext() ) 134 { 135 Date d = (Date )iter.next(); 137 138 VelocityContext vcontext = new VelocityContext(); 139 WeblogEntryMacros macros = 140 new WeblogEntryMacros( pageContext, d ); 141 vcontext.put( "macros", macros ); 142 143 ArrayList entries = (ArrayList )map.get( d ); 144 vcontext.put( "entries", entries ); 145 146 vtemplate.merge( vcontext, pw ); 147 148 if ( mMaxEntries != -1 && count > mMaxEntries ) break; 149 count++; 150 } 151 } 152 catch (Exception e) 153 { 154 mLogger.error("Unexpected exception",e); 155 throw new JspException (e); 156 } 157 return Tag.SKIP_BODY; 158 } 159 } 160 161 | Popular Tags |