roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r376921 - /incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java
Date Sat, 11 Feb 2006 03:52:15 GMT
Author: snoopdave
Date: Fri Feb 10 19:52:13 2006
New Revision: 376921

URL: http://svn.apache.org/viewcvs?rev=376921&view=rev
Log:
Feeds obey weblog entry count, but don't exceed site-wide maxEntries setting

Modified:
    incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java?rev=376921&r1=376920&r2=376921&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java Fri Feb
10 19:52:13 2006
@@ -47,7 +47,6 @@
 
 /**
  * Load Velocity Context with Roller objects, values, and custom plugins.
- *
  * @author llavandowska
  * @author David M Johnson
  */
@@ -68,7 +67,10 @@
      * Setup the a Velocity context by loading it with objects, values, and
      * RollerPagePlugins needed for Roller page execution.
      */
-    public static void setupContext(Context ctx, RollerRequest rreq, HttpServletResponse
response )
+    public static void setupContext(
+            Context ctx, 
+            RollerRequest rreq, 
+            HttpServletResponse response )
             throws RollerException {
         
         mLogger.debug("setupContext( ctx = "+ctx+")");
@@ -79,7 +81,7 @@
         try {
             // Add page model object to context
             String pageModelClassName =
-                    RollerConfig.getProperty("velocity.pagemodel.classname");
+                RollerConfig.getProperty("velocity.pagemodel.classname");
             Class pageModelClass = Class.forName(pageModelClassName);
             PageModel pageModel = (PageModel)pageModelClass.newInstance();
             pageModel.init(rreq);
@@ -93,15 +95,16 @@
         PageHelper pageHelper = new PageHelper(request, response, ctx);
         Roller roller = RollerFactory.getRoller();
         ctx.put("pageHelper", pageHelper);
-        
+                
         // Load standard Roller objects and values into the context
-        String handle = loadWebsiteValues(ctx, rreq, rollerCtx );
-        loadWeblogValues( ctx, rreq, rollerCtx, handle );
-        loadPathValues( ctx, rreq, rollerCtx, handle );
-        loadRssValues( ctx, rreq, handle );
-        loadUtilityObjects( ctx, rreq, rollerCtx, handle );
-        loadRequestParamKeys(ctx);
-        loadStatusMessage( ctx, rreq );
+        WebsiteData website = 
+            loadWebsiteValues(ctx, rreq, rollerCtx );
+        loadWeblogValues(     ctx, rreq, rollerCtx, website );
+        loadPathValues(       ctx, rreq, rollerCtx, website );
+        loadRssValues(        ctx, rreq, website );
+        loadUtilityObjects(   ctx, rreq, rollerCtx, website );
+        loadRequestParamKeys( ctx);
+        loadStatusMessage(    ctx, rreq );
         
         // If single entry is specified, load comments too
         if ( rreq.getWeblogEntry() != null ) {
@@ -111,53 +114,90 @@
         // add Velocity Toolbox tools to context
         loadToolboxContext(request, response, ctx);
     }
-    
-    
+        
     /**
-     * If there is an ERROR or STATUS message in the session,
-     * place it into the Context for rendering later.
-     *
-     * @param rreq
+     * Load website object and related objects.
      */
-    private static void loadStatusMessage(Context ctx, RollerRequest rreq) {
+    protected static WebsiteData loadWebsiteValues(
+            Context ctx, 
+            RollerRequest rreq, 
+            RollerContext rollerCtx )
+            throws RollerException {
+                
+        Roller mRoller = RollerFactory.getRoller();
+        Map props = mRoller.getPropertiesManager().getProperties();
         
-        mLogger.debug("Loading status message");
+        WebsiteData website = rreq.getWebsite();            
+        if (website == null && rreq.getRequest().getParameter("entry") != null) {
+            String handle = rreq.getRequest().getParameter("entry");
+            website = RollerFactory.getRoller().getUserManager().getWebsiteByHandle(handle);
+        }
+        if (website == null && rreq.getRequest().getAttribute(RollerRequest.OWNING_WEBSITE)
!= null) {
+            website = (WebsiteData)rreq.getRequest().getAttribute(RollerRequest.OWNING_WEBSITE);
+        } 
         
-        HttpSession session = rreq.getRequest().getSession(false);
-        String msg = null;
-        if (session != null)
-            msg = (String)session.getAttribute(RollerSession.ERROR_MESSAGE);
-        if (msg != null) {
-            ctx.put("errorMessage", msg);
-            session.removeAttribute(RollerSession.ERROR_MESSAGE);
+        if (website != null) {
+            ctx.put("userName",         website.getHandle());
+            ctx.put("fullName",         website.getName() );
+            ctx.put("emailAddress",     website.getEmailAddress() );
+            ctx.put("encodedEmail",     RegexUtil.encode(website.getEmailAddress()));
+            ctx.put("obfuscatedEmail",  RegexUtil.obfuscateEmail(website.getEmailAddress()));
+            
+            // setup Locale for future rendering
+            ctx.put("locale", website.getLocaleInstance());
+            
+            // setup Timezone for future rendering
+            ctx.put("timezone", website.getTimeZoneInstance());
+            ctx.put("timeZone", website.getTimeZoneInstance());
+        } else {
+            website = new WebsiteData();
+            website.setAllowComments(Boolean.FALSE);
+            website.setHandle("zzz_none_zzz");
+            website.setName(
+                ((RollerPropertyData)props.get("site.name")).getValue());
+            website.setDescription(
+                ((RollerPropertyData)props.get("site.description")).getValue());
+            ctx.put("handle",   website.getHandle() );
+            ctx.put("userName", website.getHandle() );
+            ctx.put("fullName", website.getHandle());
+            ctx.put("locale",   Locale.getDefault());
+            ctx.put("timezone", TimeZone.getDefault());
+            ctx.put("timeZone", TimeZone.getDefault());
+            ctx.put("emailAddress",
+                ((RollerPropertyData)props.get("site.adminemail")).getValue());
         }
+        ctx.put("website", WebsiteDataWrapper.wrap(website) );
         
-        if (session != null)
-            msg = (String)session.getAttribute(RollerSession.STATUS_MESSAGE);
-        if (msg != null) {
-            ctx.put("statusMessage", msg);
-            session.removeAttribute(RollerSession.STATUS_MESSAGE);
-        }
+        String siteName = ((RollerPropertyData)props.get("site.name")).getValue();
+        if ("Roller-based Site".equals(siteName)) siteName = "Main";
+        ctx.put("siteName", siteName);
+        
+        String siteShortName = ((RollerPropertyData)props.get("site.shortName")).getValue();
+        ctx.put("siteShortName", siteShortName);
+        
+        // add language of the session (using locale of viewer set by Struts)
+        ctx.put("viewLocale",
+                LanguageUtil.getViewLocale(rreq.getRequest()));
+        mLogger.debug("context viewLocale = "+ctx.get( "viewLocale"));
+        
+        return website;
     }
     
-    
     /**
-     * @param ctx
-     * @param rreq
-     * @param rollerCtx
-     * @param userName
+     * Load other values associated with one weblog
      */
-    private static void loadWeblogValues(Context ctx, RollerRequest rreq, 
-                                        RollerContext rollerCtx, String handle)
+    private static void loadWeblogValues(
+            Context ctx, 
+            RollerRequest rreq, 
+            RollerContext 
+            rollerCtx, WebsiteData website)
             throws RollerException {
         
         mLogger.debug("Loading weblog values");
         
         // if there is an "_entry" page, only load it once
-        WebsiteData website =
-                RollerFactory.getRoller().getUserManager().getWebsiteByHandle(handle);
         if (website != null) {
-            /* alternative display pages - customization */
+            // alternative display pages - customization
             Template entryPage = website.getPageByName("_entry");
             if (entryPage != null) {
                 ctx.put("entryPage", TemplateWrapper.wrap(entryPage));
@@ -169,29 +209,23 @@
         }
         
         boolean commentsEnabled =
-                RollerRuntimeConfig.getBooleanProperty("users.comments.enabled");
+            RollerRuntimeConfig.getBooleanProperty("users.comments.enabled");
         boolean trackbacksEnabled =
-                RollerRuntimeConfig.getBooleanProperty("users.trackbacks.enabled");
+            RollerRuntimeConfig.getBooleanProperty("users.trackbacks.enabled");
         boolean linkbacksEnabled =
-                RollerRuntimeConfig.getBooleanProperty("site.linkbacks.enabled");
+            RollerRuntimeConfig.getBooleanProperty("site.linkbacks.enabled");
         ctx.put("commentsEnabled", new Boolean(commentsEnabled) );
         ctx.put("trackbacksEnabled", new Boolean(trackbacksEnabled) );
         ctx.put("linkbacksEnabled", new Boolean(linkbacksEnabled) );
     }
-    
-    
-    private static String figureResourcePath(RollerRequest rreq) {
-        
-        String uploadurl = null;
-        try {
-            uploadurl = RollerFactory.getRoller().getFileManager().getUploadUrl();
-        } catch(Exception e) {}
         
-        return uploadurl;
-    }
-    
-    
-    protected static void loadCommentValues(Context ctx, RollerRequest rreq, RollerContext
rollerCtx )
+    /**
+     * Load comments for one weblog entry and related objects.
+     */
+    protected static void loadCommentValues(
+            Context       ctx, 
+            RollerRequest rreq, 
+            RollerContext rollerCtx )
             throws RollerException {
         
         mLogger.debug("Loading comment values");
@@ -199,9 +233,9 @@
         HttpServletRequest request = rreq.getRequest();
         
         String escapeHtml =
-                RollerRuntimeConfig.getProperty("users.comments.escapehtml");
+            RollerRuntimeConfig.getProperty("users.comments.escapehtml");
         String autoFormat =
-                RollerRuntimeConfig.getProperty("users.comments.autoformat");
+            RollerRuntimeConfig.getProperty("users.comments.autoformat");
         
         // Add comments related values to context
         ctx.put("isCommentPage", Boolean.TRUE);
@@ -237,62 +271,13 @@
         }
     }
     
-    
-    protected static void loadPathValues(Context ctx, RollerRequest rreq, 
-                                        RollerContext rollerCtx, String userName)
-            throws RollerException {
-        
-        mLogger.debug("Loading path values");
-        
-        HttpServletRequest request = rreq.getRequest();
-        String url = null;
-        if ( userName != null && !userName.equals("zzz_none_zzz")) {
-            url = Utilities.escapeHTML(
-                    rollerCtx.getAbsoluteContextUrl(request)+"/page/"+userName);
-        } else {
-            url= Utilities.escapeHTML(rollerCtx.getAbsoluteContextUrl(request));
-        }
-        ctx.put("websiteURL", url);
-        ctx.put("baseURL",    rollerCtx.getContextUrl( request ) );
-        ctx.put("absBaseURL", rollerCtx.getAbsoluteContextUrl( request ) );
-        ctx.put("ctxPath",    request.getContextPath() );
-        ctx.put("uploadPath", ContextLoader.figureResourcePath( rreq ) );
-        
-        try {
-            URL absUrl = RequestUtils.absoluteURL(request, "/");
-            ctx.put("host", absUrl.getHost());
-        } catch (MalformedURLException e) {
-            throw new RollerException(e);
-        }
-    }
-    
-    
-    protected static void loadRequestParamKeys(Context ctx) {
-        
-        mLogger.debug("Loading request param keys");
-        
-        // Since Velocity *requires* accessor methods, these values from
-        // RollerRequest are not available to it, put them into the context
-        ctx.put("USERNAME_KEY",           RollerRequest.USERNAME_KEY);
-        ctx.put("WEBSITEID_KEY",          RollerRequest.WEBSITEID_KEY);
-        ctx.put("FOLDERID_KEY",           RollerRequest.FOLDERID_KEY);
-        ctx.put("NEWSFEEDID_KEY",         RollerRequest.NEWSFEEDID_KEY);
-        ctx.put("PAGEID_KEY",             RollerRequest.PAGEID_KEY);
-        ctx.put("PAGELINK_KEY",           RollerRequest.PAGELINK_KEY);
-        ctx.put("ANCHOR_KEY",             RollerRequest.ANCHOR_KEY);
-        ctx.put("EXCERPTS_KEY",           RollerRequest.EXCERPTS_KEY);
-        ctx.put("BOOKMARKID_KEY",         RollerRequest.BOOKMARKID_KEY);
-        ctx.put("REFERERID_KEY",          RollerRequest.REFERERID_KEY);
-        ctx.put("WEBLOGENTRYID_KEY",      RollerRequest.WEBLOGENTRYID_KEY);
-        ctx.put("WEBLOGCATEGORYNAME_KEY", RollerRequest.WEBLOGCATEGORYNAME_KEY);
-        ctx.put("WEBLOGCATEGORYID_KEY",   RollerRequest.WEBLOGENTRIES_KEY);
-        ctx.put("WEBLOGENTRIES_KEY",      RollerRequest.WEBLOGENTRIES_KEY);
-        ctx.put("WEBLOGDAY_KEY",          RollerRequest.WEBLOGDAY_KEY);
-        ctx.put("WEBLOGCOMMENTID_KEY",    RollerRequest.WEBLOGCOMMENTID_KEY);
-    }
-    
-    
-    protected static void loadRssValues(Context ctx, RollerRequest rreq, String handle) 
+    /**
+     * Load objects needed for RSS and Atom newsfeed generation.
+     */
+    protected static void loadRssValues(
+            Context ctx, 
+            RollerRequest rreq, 
+            WebsiteData website) 
             throws RollerException {
         
         mLogger.debug("Loading rss values");
@@ -306,17 +291,16 @@
         }
         ctx.put("entryLength",  new Integer(entryLength));
         
-        int entryCount = 15;
-        String sCount = request.getParameter("count");
-        if ( sCount!=null && sExcerpts!=null && sExcerpts.trim().equals(""))
{
-            try {
-                entryCount = Integer.parseInt(sCount);
-            } catch (NumberFormatException e) {
-                mLogger.warn("Improperly formatted count parameter");
-            }
-            if ( entryCount > 50 ) entryCount = 50;
-            if ( entryCount < 0 ) entryCount = 15;
-        }
+        // Display same number of entries in feed as displayed on page
+        int entryCount = website.getEntryDisplayCount();
+        
+        // But don't exceed installation-wide maxEntries settings
+        int maxEntries = 
+            RollerRuntimeConfig.getIntProperty("site.newsfeeds.maxEntries");
+        int defaultEntries = 
+            RollerRuntimeConfig.getIntProperty("site.newsfeeds.defaultEntries");
+        if (entryCount < 1) entryCount = defaultEntries;
+        if (entryCount > maxEntries) entryCount = maxEntries;
         ctx.put("entryCount",  new Integer(entryCount));
         
         String catname = null;
@@ -331,19 +315,22 @@
         ctx.put("now", new Date());
     }
     
-    
-    protected static void loadUtilityObjects(Context ctx, RollerRequest rreq, 
-                                            RollerContext rollerCtx, String handle)
+    /**
+     * Load useful utility objects for string and date formatting.
+     */
+    protected static void loadUtilityObjects(
+            Context ctx, 
+            RollerRequest rreq,                                             
+            RollerContext rollerCtx, 
+            WebsiteData website)
             throws RollerException {
         
         mLogger.debug("Loading utility objects");
         
-        // date formatter for macro's
-        // set this up with the Locale to make sure we can reuse it with other patterns
-        // in the macro's
+        // date formatter for macro's set this up with the Locale to make 
+        // sure we can reuse it with other patterns in the macro's
         Locale viewLocale = (Locale) ctx.get("viewLocale");
         SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd", viewLocale);
-        WebsiteData website = rreq.getWebsite();
         if (website != null) {
             sdf.setTimeZone(website.getTimeZoneInstance());
         }
@@ -365,74 +352,107 @@
         
         ctx.put("requestParameters", rreq.getRequest().getParameterMap());
     }
-    
-    
-    protected static String loadWebsiteValues(Context ctx, RollerRequest rreq, RollerContext
rollerCtx )
+        
+    /**
+     * Load URL paths useful in page templates.
+     */
+    protected static void loadPathValues(
+            Context ctx,  RollerRequest rreq, 
+            RollerContext rollerCtx, 
+            WebsiteData   website)
             throws RollerException {
         
-        String handle = null;
-        WebsiteData website = null;
+        mLogger.debug("Loading path values");
         
-        Roller mRoller = RollerFactory.getRoller();
-        Map props = mRoller.getPropertiesManager().getProperties();
+        HttpServletRequest request = rreq.getRequest();
+        String url = null;
+        if (website != null) {
+            url = Utilities.escapeHTML(
+                      rollerCtx.getAbsoluteContextUrl(request) 
+                          + "/page/" + website.getHandle());
+        } else {
+            url= Utilities.escapeHTML(rollerCtx.getAbsoluteContextUrl(request));
+        }
+        ctx.put("websiteURL", url);
+        ctx.put("baseURL",    rollerCtx.getContextUrl( request ) );
+        ctx.put("absBaseURL", rollerCtx.getAbsoluteContextUrl( request ) );
+        ctx.put("ctxPath",    request.getContextPath() );
+        ctx.put("uploadPath", ContextLoader.figureResourcePath( rreq ) );
         
-        if ( rreq.getRequest().getAttribute(RollerRequest.OWNING_WEBSITE) != null) {
-            website = (WebsiteData)
-            rreq.getRequest().getAttribute(RollerRequest.OWNING_WEBSITE);
-        } else if ( rreq.getWebsite() != null ) {
-            website = rreq.getWebsite();
+        try {
+            URL absUrl = RequestUtils.absoluteURL(request, "/");
+            ctx.put("host", absUrl.getHost());
+        } catch (MalformedURLException e) {
+            throw new RollerException(e);
         }
+    }
+      
+    /**
+     * Determine URL path to Roller upload directory.
+     */
+    private static String figureResourcePath(RollerRequest rreq) {
         
-        if ( website != null ) {
-            handle = website.getHandle();
-            ctx.put("userName",      handle);
-            ctx.put("fullName",      website.getName() );
-            ctx.put("emailAddress",  website.getEmailAddress() );
-            ctx.put("encodedEmail",  RegexUtil.encode(website.getEmailAddress()));
-            ctx.put("obfuscatedEmail",  RegexUtil.obfuscateEmail(website.getEmailAddress()));
-            
-            // setup Locale for future rendering
-            ctx.put("locale", website.getLocaleInstance());
-            
-            // setup Timezone for future rendering
-            ctx.put("timezone", website.getTimeZoneInstance());
-            ctx.put("timeZone", website.getTimeZoneInstance());
-        } else {
-            website = new WebsiteData();
-            website.setName(((RollerPropertyData)props.get("site.name")).getValue());
-            website.setAllowComments(Boolean.FALSE);
-            website.setDescription(((RollerPropertyData)props.get("site.description")).getValue());
-            handle = "zzz_none_zzz";
-            ctx.put("userName", handle );
-            ctx.put("fullName","zzz_none_zzz");
-            ctx.put("emailAddress",
-                    ((RollerPropertyData)props.get("site.adminemail")).getValue());
-            ctx.put("locale", Locale.getDefault());
-            ctx.put("timezone", TimeZone.getDefault());
-            ctx.put("timeZone", TimeZone.getDefault());
+        String uploadurl = null;
+        try {
+            uploadurl = RollerFactory.getRoller().getFileManager().getUploadUrl();
+        } catch(Exception e) {}
+        
+        return uploadurl;
+    }
+    
+    /**
+     * If there is an ERROR or STATUS message in the session,
+     * place it into the Context for rendering later.
+     */
+    private static void loadStatusMessage(Context ctx, RollerRequest rreq) {
+        
+        mLogger.debug("Loading status message");
+        
+        HttpSession session = rreq.getRequest().getSession(false);
+        String msg = null;
+        if (session != null)
+            msg = (String)session.getAttribute(RollerSession.ERROR_MESSAGE);
+        if (msg != null) {
+            ctx.put("errorMessage", msg);
+            session.removeAttribute(RollerSession.ERROR_MESSAGE);
         }
-        ctx.put("website", WebsiteDataWrapper.wrap(website) );
         
-        String siteName = ((RollerPropertyData)props.get("site.name")).getValue();
-        if ("Roller-based Site".equals(siteName)) siteName = "Main";
-        ctx.put("siteName", siteName);
+        if (session != null)
+            msg = (String)session.getAttribute(RollerSession.STATUS_MESSAGE);
+        if (msg != null) {
+            ctx.put("statusMessage", msg);
+            session.removeAttribute(RollerSession.STATUS_MESSAGE);
+        }
+    }
         
-        String siteShortName = ((RollerPropertyData)props.get("site.shortName")).getValue();
-        ctx.put("siteShortName", siteShortName);
+    protected static void loadRequestParamKeys(Context ctx) {
         
-        // add language of the session (using locale of viewer set by Struts)
-        ctx.put(
-                "viewLocale",
-                LanguageUtil.getViewLocale(rreq.getRequest()));
-        mLogger.debug("context viewLocale = "+ctx.get( "viewLocale"));
+        mLogger.debug("Loading request param keys");
         
-        return handle;
+        // Since Velocity *requires* accessor methods, these values from
+        // RollerRequest are not available to it, put them into the context
+        ctx.put("USERNAME_KEY",           RollerRequest.USERNAME_KEY);
+        ctx.put("WEBSITEID_KEY",          RollerRequest.WEBSITEID_KEY);
+        ctx.put("FOLDERID_KEY",           RollerRequest.FOLDERID_KEY);
+        ctx.put("NEWSFEEDID_KEY",         RollerRequest.NEWSFEEDID_KEY);
+        ctx.put("PAGEID_KEY",             RollerRequest.PAGEID_KEY);
+        ctx.put("PAGELINK_KEY",           RollerRequest.PAGELINK_KEY);
+        ctx.put("ANCHOR_KEY",             RollerRequest.ANCHOR_KEY);
+        ctx.put("EXCERPTS_KEY",           RollerRequest.EXCERPTS_KEY);
+        ctx.put("BOOKMARKID_KEY",         RollerRequest.BOOKMARKID_KEY);
+        ctx.put("REFERERID_KEY",          RollerRequest.REFERERID_KEY);
+        ctx.put("WEBLOGENTRYID_KEY",      RollerRequest.WEBLOGENTRYID_KEY);
+        ctx.put("WEBLOGCATEGORYNAME_KEY", RollerRequest.WEBLOGCATEGORYNAME_KEY);
+        ctx.put("WEBLOGCATEGORYID_KEY",   RollerRequest.WEBLOGENTRIES_KEY);
+        ctx.put("WEBLOGENTRIES_KEY",      RollerRequest.WEBLOGENTRIES_KEY);
+        ctx.put("WEBLOGDAY_KEY",          RollerRequest.WEBLOGDAY_KEY);
+        ctx.put("WEBLOGCOMMENTID_KEY",    RollerRequest.WEBLOGCOMMENTID_KEY);
     }
     
-    
-    public static ToolboxContext loadToolboxContext(HttpServletRequest request, 
-                                                    HttpServletResponse response, 
-                                                    Context ctx) {
+    public static ToolboxContext loadToolboxContext(
+            HttpServletRequest request,                                                 
   
+            HttpServletResponse response,                                               
    
+            Context ctx) {
         
         mLogger.debug("Loading toolbox context");
         



Mime
View raw message