logo       

roller/src/org/roller/presentation/velocity ExportRss.java,NONE,1.1 export_: msg#00245

Subject: roller/src/org/roller/presentation/velocity ExportRss.java,NONE,1.1 export_rss.vm,NONE,1.1 ContextLoader.java,1.25,1.26 FlavorServlet.java,1.3,1.4 PageHelper.java,1.14,1.15
Update of /cvsroot/roller/roller/src/org/roller/presentation/velocity
In directory 
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8896/src/org/roller/presentation/velocity

Modified Files:
        ContextLoader.java FlavorServlet.java PageHelper.java 
Added Files:
        ExportRss.java export_rss.vm 
Log Message:
Export Entries to RSS.


--- NEW FILE: ExportRss.java ---
package org.roller.presentation.velocity;

import org.apache.commons.lang.StringUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.roller.RollerException;
import org.roller.model.RollerFactory;
import org.roller.pojos.RollerConfig;
import org.roller.pojos.UserData;
import org.roller.pojos.WebsiteData;
import org.roller.presentation.RollerContext;
import org.roller.util.RegexUtil;
import org.roller.util.Utilities;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.Locale;
import java.util.Properties;
import java.util.TimeZone;

/**
 * Does a lot of the same work as ContextLoader in preparing
 * a VelocityContext for parsing.  However, it is ignorant of
 * any HttpServletRequest related features, and so has 
 * considerably trimmed down information.
 * 
 * Created on Mar 25, 2004
 * @author lance.lavandowska
 */
public class ExportRss
{
    VelocityEngine ve = null;
    VelocityContext ctx = null;
    UserData user = null;
    
    public ExportRss(WebsiteData website) throws Exception
    {
        Properties props = new Properties();
        props.load(this.getClass().getClassLoader().
                   getResourceAsStream("velocity.properties"));
        ve = new VelocityEngine();
        ve.info("*******************************************");
        ve.info("Initializing VelocityEngine for ExportRss");
        ve.init( props );
        ve.info("Done initializing VelocityEngine for ExportRss");
        ve.info("************************************************");
        
        ctx = new VelocityContext();
        
        user = website.getUser();
        RollerContext rollerCtx = RollerContext.getRollerContext(
                                      RollerContext.getServletContext());
        loadPageHelper();
        
        loadDates(website);
        
        loadWebsiteInfo(rollerCtx, website);

        loadTheRest(rollerCtx);
    }
    
    /**
     * Export the given entries using export_rss.vm.
     * 
     * @param entries
     * @throws ResourceNotFoundException
     * @throws ParseErrorException
     * @throws Exception
     */
    public void exportEntries(Collection entries, String fileName) throws 
ResourceNotFoundException, ParseErrorException, Exception 
    {
        ctx.put("entries", entries);
        
        Template template = ve.getTemplate( 
"org/roller/presentation/velocity/export_rss.vm", "utf-8" );
        StringWriter sw = new StringWriter();
        template.merge(ctx, sw);
        
        writeResultsToFile((String)ctx.get("uploadPath"), sw, fileName);
    }

    /**
     * @param sw
     */
    private void writeResultsToFile(String filePath, StringWriter sw, String 
fileName) 
        throws RollerException, IOException
    {
        filePath += "/" + user.getUserName();
        new java.io.File( filePath ).mkdirs(); // create dir path on drive
        
        filePath += "/" + fileName;
        
        File outputFile = new java.io.File( filePath );
        FileOutputStream out = null;
        try
        {
            //outputFile.createNewFile();
            out = new FileOutputStream( outputFile );
            out.write( sw.toString().getBytes() );
            out.flush();
        }
        catch ( FileNotFoundException e )
        {
            throw new RollerException( "Unable to write to: " + 
outputFile.getAbsolutePath(), e );
        }
        finally
        {
            try
            {
                if ( out != null )
                {
                    out.close();
                }
            }
            catch ( java.io.IOException ioe )
            {
                System.err.println( "ExportRss unable to close OutputStream" );
            }
        }
    }

    /**
     * Load miscellaneous values into the Context.
     * @param rollerCtx
     */
    private void loadTheRest(RollerContext rollerCtx)
    {
        ctx.put("utilities",       new Utilities() );
        ctx.put("stringUtils",     new StringUtils() );        
        ctx.put("rollerVersion",   rollerCtx.getRollerVersion() );
        ctx.put("rollerBuildTime", rollerCtx.getRollerBuildTime() );
        ctx.put("rollerBuildUser", rollerCtx.getRollerBuildUser() );
        ctx.put("entryLength",     new Integer(-1));

        String siteName = rollerCtx.getRollerConfig().getSiteName();
        if ("Roller-based Site".equals(siteName)) siteName = "Main";
        ctx.put("siteName", siteName);
    }

    /**
     * Load information pertaining to the Website and
     * its associated User.
     * @param rollerCtx
     */
    private void loadWebsiteInfo(RollerContext rollerCtx, WebsiteData website)
    {
        ctx.put("website",       website);
        ctx.put("userName",      user.getUserName() );
        ctx.put("fullName",      user.getFullName() );
        ctx.put("emailAddress",  user.getEmailAddress() );

        ctx.put("encodedEmail",  RegexUtil.encode(user.getEmailAddress()));
        ctx.put("obfuscatedEmail",  
RegexUtil.obfuscateEmail(user.getEmailAddress()));
        

        RollerConfig  rollerConfig = rollerCtx.getRollerConfig();
        
        // custom figureResourcePath() due to no "request" object
        StringBuffer sb = new StringBuffer();
        String uploadPath = rollerConfig.getUploadPath();
        if ( uploadPath != null && uploadPath.trim().length() > 0 )
        {
            sb.append( uploadPath );
        }
        else
        {
            sb.append( "." + RollerContext.USER_RESOURCES );
        }
        String path = 
RollerContext.getServletContext().getRealPath(sb.toString());
        ctx.put("uploadPath", path);
    }

    /**
     * Load time-related information.
     * @param website
     */
    private void loadDates(WebsiteData website)
    {
        try
        {
            // Add current time and last updated times to context
            Date updateTime = RollerFactory.getRoller().getWeblogManager()
            .getWeblogLastPublishTime( user.getUserName(), null );              
          
            ctx.put("updateTime",   updateTime);
        }
        catch (RollerException e)
        {                       
            ctx.put("updateTime",   new Date());
        }
        ctx.put("now",              new Date());
        
        // setup Locale for future rendering
        Locale locale = website.getLocaleInstance();
        ctx.put("locale", locale);
        
        // setup Timezone for future rendering
        ctx.put("timezone", website.getTimeZoneInstance());

        // date formats need to be run through the Localized
        // SimpleDateFormat and pulled back out as localized patterns.
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd", locale);  
        sdf.setTimeZone( (TimeZone)ctx.get("timezone") );    
        ctx.put("plainFormat",     sdf.toLocalizedPattern());
        
        sdf.applyPattern("EEEE MMMM dd, yyyy");
        ctx.put("toStringFormat",  sdf.toLocalizedPattern());
        
        sdf.applyPattern("MMM dd yyyy, hh:mm:ss a z");
        ctx.put("timestampFormat", sdf.toLocalizedPattern());
        
        ctx.put("dateFormatter", sdf );
    }

    /**
     * Create a PageHelper.  Note that will have no values
     * necessary in parsing a Web request (such as /page) -
     * it is only useful for the restricted export_rss.vm
     * and has no PagePlugins either.  We want the exported
     * Entry.text to be the raw values.
     */
    private void loadPageHelper()
    {
        // Add Velocity page helper to context
        PageHelper pageHelper = new PageHelper(null, null, ctx);
        pageHelper.setPagePlugins( null ); // no plugins in this context
        ctx.put("pageHelper", pageHelper );
    }
}

--- NEW FILE: export_rss.vm ---
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
  <title>$utilities.textToHTML($website.name,true)</title>
  <description>$utilities.textToHTML($website.description,true)</description>
  <language>$website.locale</language>
  <copyright>Copyright #formatDate("yyyy" $now)</copyright>
  <lastBuildDate>$utilities.formatRfc822Date($updateTime)</lastBuildDate>
  <generator>Roller Weblogger #showVersion() 
($rollerBuildTime:$rollerBuildUser)</generator>
  <managingEditor>$emailAddress</managingEditor>
  <webMaster>$emailAddress</webMaster> 

  #foreach( $entry in $entries )
  <item>
    <title>$utilities.textToHTML($entry.title,true)</title>   
    <description>#showEntryDescription($entry)</description>       
    <category>$entry.category.name</category>
    <pubDate>$utilities.formatRfc822Date($entry.pubTime)</pubDate>    
  </item>
  #end  
</channel>
</rss>
Index: ContextLoader.java
===================================================================
RCS file: 
/cvsroot/roller/roller/src/org/roller/presentation/velocity/ContextLoader.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** ContextLoader.java  13 Mar 2004 20:54:13 -0000      1.25
--- ContextLoader.java  26 Mar 2004 03:00:34 -0000      1.26
***************
*** 1,491 ****
! package org.roller.presentation.velocity;
! 
! import org.apache.commons.lang.StringUtils;
! import org.apache.commons.logging.Log;
! import org.apache.commons.logging.LogFactory;
! import org.apache.velocity.context.Context;
! import org.roller.RollerException;
! import org.roller.pojos.CommentData;
! import org.roller.pojos.PageData;
! import org.roller.pojos.RollerConfig;
! import org.roller.pojos.UserData;
! import org.roller.pojos.WeblogEntryData;
! import org.roller.pojos.WebsiteData;
! import org.roller.presentation.RollerContext;
! import org.roller.presentation.RollerRequest;
! import org.roller.presentation.RollerSession;
! import org.roller.presentation.newsfeeds.NewsfeedCache;
! import org.roller.presentation.weblog.formbeans.CommentFormEx;
! import org.roller.util.RegexUtil;
! import org.roller.util.Utilities;
! 
! import java.text.SimpleDateFormat;
! import java.util.ArrayList;
! import java.util.Collections;
! import java.util.Date;
! import java.util.Iterator;
! import java.util.List;
! import java.util.Locale;
! import java.util.TimeZone;
! 
! import javax.servlet.ServletContext;
! import javax.servlet.http.HttpServletRequest;
! import javax.servlet.http.HttpServletResponse;
! import javax.servlet.http.HttpSession;
! 
! /**
!  * Load Velocity Context with Roller objects, values, and custom plugins.
!  * 
!  * @author llavandowska
!  * @author David M Johnson
!  * 
!  */
! public class ContextLoader
! {             
!     private RollerRequest mRollerReq = null;
!     
!     // List of PagePlugins for "transforming" WeblogEntries
!     static List mPlugins = new ArrayList();
!     
!     private static Log mLogger = 
!        LogFactory.getFactory().getInstance(ContextLoader.class);
! 
!     //------------------------------------------------------------------------
!     
!     /**
!      * 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 ) 
!         throws RollerException
!     {
!         HttpServletRequest request = rreq.getRequest();
!         RollerContext rollerCtx = RollerContext.getRollerContext( request );
!         
!         // Add page model object to context                    
!         PageModel pageModel = new PageModel(rreq);
!         ctx.put("pageModel", pageModel );
!         ctx.put("pages", pageModel.getPages());
!         
!         // Add Velocity page helper to context
!         PageHelper pageHelper = new PageHelper(rreq, response, ctx);
!         ctx.put("pageHelper", pageHelper );
! 
!         // Add legacy macros too, so that old-school pages still work
!         Macros macros= new Macros(rreq.getPageContext(), pageHelper);
!         ctx.put("macros", macros);
! 
!         // Load standard Roller objects and values into the context 
!         String userName = loadWebsiteValues(ctx, rreq, rollerCtx );
!         loadWeblogValues( ctx, rreq, rollerCtx, userName );            
!         loadPathValues( ctx, rreq, rollerCtx, userName );                     
                    
!         loadRssValues( ctx, rreq, userName );                        
!         loadUtilityObjects( ctx, rreq, rollerCtx ); 
!         loadRequestParamKeys(ctx);
!         loadStatusMessage( ctx, rreq );
!         
!         // If single entry is specified, load comments too
!         if ( rreq.getWeblogEntry() != null )
!         {
!             loadCommentValues( ctx, rreq, rollerCtx );
!         }  
!         
!         // Load custom page plugins
!         Iterator iter = mPlugins.iterator();
!         while (iter.hasNext())
!         {
!             PagePlugin plugin = (PagePlugin) iter.next();
!             plugin.init(rreq,ctx);
!         }
!         
!         // pass the Plugins to PageHelper, make List unmodifiable
!         pageHelper.setPagePlugins( Collections.unmodifiableCollection( 
mPlugins ) );
!     }
!       
!     //------------------------------------------------------------------------
!     
!       /**
!      * If there is an ERROR or STATUS message in the session,
!      * place it into the Context for rendering later.
!      * 
!        * @param rreq
!        */
!       private static void loadStatusMessage(Context ctx, RollerRequest rreq)
!       {
!         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 (session != null)
!             msg = (String)session.getAttribute(RollerSession.STATUS_MESSAGE);
!         if (msg != null)
!         {
!             ctx.put("statusMessage", msg);
!             session.removeAttribute(RollerSession.STATUS_MESSAGE);
!         }
!       }
!     
!     //------------------------------------------------------------------------
! 
!       /**
!        * @param ctx
!        * @param rreq
!        * @param rollerCtx
!        * @param userName
!        */
!       private static void loadWeblogValues(
!        Context ctx, RollerRequest rreq, RollerContext rollerCtx, String 
userName) 
!     {
!         // if there is an "_entry" page, only load it once
!               PageModel pageModel = (PageModel)ctx.get("pageModel");
!         PageData entryPage = pageModel.getUsersPageByName(rreq.getWebsite(), 
"_entry");
!         if (entryPage != null)
!         {
!             ctx.put("entryPage", entryPage);
!         }
!         PageData descPage = pageModel.getUsersPageByName(rreq.getWebsite(), 
"_desc");
!         if (descPage != null)
!         {
!             ctx.put("descPage", descPage);
!         }
!       }
! 
!       private static String figureResourcePath( RollerRequest rreq )
!       {
!           HttpServletRequest request = rreq.getRequest();
!           RollerContext rCtx = RollerContext.getRollerContext( request );
!           RollerConfig  rollerConfig = rCtx.getRollerConfig();
!       
!           StringBuffer sb = new StringBuffer();
!           String uploadPath = rollerConfig.getUploadPath();
!           if ( uploadPath != null && uploadPath.trim().length() > 0 )
!           {
!               sb.append( uploadPath );
!           }
!           else
!           {
!               sb.append( request.getContextPath() );
!               sb.append( RollerContext.USER_RESOURCES );
!           }
!           return sb.toString();
!       }
! 
!     //------------------------------------------------------------------------
!     
!     public boolean isUserAuthorizedToEdit()
!     {
!         try
!         {
!             return mRollerReq.isUserAuthorizedToEdit();
!         }
!         catch (Exception e)
!         {
!             mLogger.warn("PageHelper.isUserAuthorizedToEdit)", e);
!         }
!         return false;
!     }
!     
!     //------------------------------------------------------------------------
!     
!     protected static void loadCommentValues(
!        Context ctx, RollerRequest rreq, RollerContext rollerCtx ) 
!        throws RollerException
!     {
!         HttpServletRequest request = rreq.getRequest();
!         RollerConfig rollerConfig = rollerCtx.getRollerConfig();
!         
!         // Add comments related values to context
!         ctx.put("isCommentPage", Boolean.TRUE);
!         ctx.put("escapeHtml", rollerConfig.getEscapeCommentHtml() );
!         ctx.put("autoformat", rollerConfig.getAutoformatComments() );
!         
!         // Make sure comment form object is available in context
!         CommentFormEx commentForm = 
!             (CommentFormEx)request.getAttribute("commentForm");
!         if ( commentForm == null )
!         {
!             commentForm = new CommentFormEx();
!         
!             // Set fields to spaces to please Velocity
!             commentForm.setName("");
!             commentForm.setEmail("");
!             commentForm.setUrl("");
!             commentForm.setContent("");
!         }        
!         ctx.put("commentForm",commentForm); 
!             
!         // Either put a preview comment in to context          
!         if ( request.getAttribute("previewFromPage")!=null )
!         {
!             ArrayList list = new ArrayList();
!             CommentData cd = new CommentData();
!             commentForm.copyTo(cd, request.getLocale());
!             list.add(cd);
!             ctx.put("previewComments",list);            
!         }
!         else // Or the whole set of comment for the specified weblog entry
!         {
!             WeblogEntryData entry = rreq.getWeblogEntry();
!             ctx.put("entry",entry);            
!         }
!     }   
! 
!     //------------------------------------------------------------------------
!     
!     protected static void loadPathValues(
!       Context ctx, RollerRequest rreq, RollerContext rollerCtx, String 
userName)
!     {
!         HttpServletRequest request = rreq.getRequest();
!         String url = null;
!         if ( userName != null )
!         {
!             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 ) );
!     }
! 
!     //------------------------------------------------------------------------
!     
!     protected static void loadRequestParamKeys(Context ctx)
!     {
!         // 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 userName) throws 
RollerException
!     {
!         HttpServletRequest request = rreq.getRequest();
!         
!         int entryLength = -1;
!         String sExcerpts = request.getParameter("excerpts");
!         if ( sExcerpts!=null && sExcerpts.equalsIgnoreCase("true"))
!         {
!             entryLength = 150;
!         }
!         ctx.put("entryLength",  new Integer(entryLength));
!         
!         int entryCount = 15;
!         String sCount = request.getParameter("count");
!         if ( sCount!=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;
!         }
!         ctx.put("entryCount",  new Integer(entryCount));
!             
!         String catname = null;
!         if ( rreq.getWeblogCategory() != null )
!         {
!             catname = rreq.getWeblogCategory().getName();
!         } 
!         ctx.put("catname",      (catname!=null) ? catname : "");
!         
!         // Add current time and last updated times to context
!         Date updateTime = rreq.getRoller().getWeblogManager()
!             .getWeblogLastPublishTime( userName, catname );                   
     
!         ctx.put("updateTime",   updateTime);
!         ctx.put("now",          new Date());
!     }
! 
!     //------------------------------------------------------------------------
!     
!     protected static void loadUtilityObjects(
!         Context ctx, RollerRequest rreq, RollerContext rollerCtx)
!     {
!         // date formats need to be run through the Localized
!         // SimpleDateFormat and pulled back out as localized patterns.
!         Locale locale = (Locale)ctx.get("locale");
!         SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd", locale);  
!         sdf.setTimeZone( (TimeZone)ctx.get("timezone") );    
!         ctx.put("plainFormat",     sdf.toLocalizedPattern());
!         
!         sdf.applyPattern("EEEE MMMM dd, yyyy");
!         ctx.put("toStringFormat",  sdf.toLocalizedPattern());
!         
!         sdf.applyPattern("MMM dd yyyy, hh:mm:ss a z");
!         ctx.put("timestampFormat", sdf.toLocalizedPattern());
!         
!         ctx.put("dateFormatter", sdf );
! 
!         ctx.put("page",            rreq.getPage() );
!         ctx.put("utilities",       new Utilities() );
!         ctx.put("stringUtils",     new StringUtils() );        
!         ctx.put("rollerVersion",   rollerCtx.getRollerVersion() );
!         ctx.put("rollerBuildTime", rollerCtx.getRollerBuildTime() );
!         ctx.put("rollerBuildUser", rollerCtx.getRollerBuildUser() );
!         ctx.put("newsfeedCache",   NewsfeedCache.getInstance(
!                                        rollerCtx.getRollerConfig()) );
!         
!         ctx.put("requestParameters", rreq.getRequest().getParameterMap());
!     }
!       
!     //------------------------------------------------------------------------
!     
!     protected static String loadWebsiteValues(
!         Context ctx, RollerRequest rreq, RollerContext rollerCtx )
!     {
!         String userName = null;
!         WebsiteData site = null;
!         if ( rreq.getUser() != null )
!         {
!             userName = rreq.getUser().getUserName();
!         }
!         
!         if ( userName != null )
!         {
!             site = rreq.getWebsite();
!             UserData user = rreq.getUser();
!             ctx.put("userName",      user.getUserName() );
!             ctx.put("fullName",      user.getFullName() );
!             ctx.put("emailAddress",  user.getEmailAddress() );
! 
!             ctx.put("encodedEmail",  
RegexUtil.encode(user.getEmailAddress()));
!             ctx.put("obfuscatedEmail",  
RegexUtil.obfuscateEmail(user.getEmailAddress()));
!             
!             // setup Locale for future rendering
!             ctx.put("locale", site.getLocaleInstance());
!             
!             // setup Timezone for future rendering
!             ctx.put("timezone", site.getTimeZoneInstance());
!         }
!         else
!         {
!             site = new WebsiteData();
!             site.setName(rollerCtx.getRollerConfig().getSiteName());
!             site.setAllowComments(Boolean.FALSE);
!             site.setDescription(
!                 rollerCtx.getRollerConfig().getSiteDescription());
!             ctx.put("userName","Administrator" );
!             ctx.put("fullName","Administrator");
!             ctx.put("emailAddress",
!                 rollerCtx.getRollerConfig().getEmailAddress());
!             ctx.put("locale", Locale.getDefault());
!             ctx.put("timezone", TimeZone.getDefault());
!         }
!         ctx.put("website", site );
!         
!         String siteName = rollerCtx.getRollerConfig().getSiteName();
!         if ("Roller-based Site".equals(siteName)) siteName = "Main";
!         ctx.put("siteName", siteName);        
!         
!         return userName;
!     }
!     
!     //------------------------------------------------------------------------
! 
!     /**
!      * Initialize PagePlugins declared in web.xml.  By using the full class
!      * name we also allow for the implementation of "external" Plugins
!      * (maybe even packaged seperately).
!      * 
!        * @param mContext
!        */
!       public static void initializePagePlugins(ServletContext mContext)
!       {
!               String pluginStr = 
mContext.getInitParameter("org.roller.pagePlugins");
!         if (mLogger.isDebugEnabled()) mLogger.debug(pluginStr);
!         if (pluginStr != null)
!         {
!             String[] plugins = StringUtils.stripAll(
!                                    StringUtils.split(pluginStr, ",") );
!             for (int i=0; i<plugins.length; i++)
!             {
!                 if (mLogger.isDebugEnabled()) mLogger.debug("try " + 
plugins[i]);
!                 try
!                 {
!                     Class pluginClass = Class.forName(plugins[i]);
!                     if (isPagePlugin(pluginClass))
!                     {
!                         mPlugins.add(
!                             pluginClass.newInstance()
!                         );
!                     }
!                     else
!                     {
!                         mLogger.warn(pluginClass + " is not a PagePlugin");
!                     }
!                 } 
!                 catch (ClassNotFoundException e)
!                               {
!                     mLogger.warn("ClassNotFoundException for " + plugins[i]);
!                               } 
!                 catch (InstantiationException e)
!                               {
!                     mLogger.warn("InstantiationException for " + plugins[i]);
!                               } 
!                 catch (IllegalAccessException e)
!                               {
!                     mLogger.warn("IllegalAccessException for " + plugins[i]);
!                               }
!             }
!         }
!       }
!     
!     /**
!        * @param pluginClass
!        * @return
!        */
!       private static boolean isPagePlugin(Class pluginClass)
!       {
!         Class[] interfaces = pluginClass.getInterfaces();
!         for (int i=0; i<interfaces.length; i++)
!         {
!             if (interfaces[i].equals(PagePlugin.class)) return true;
!         }
!         return false;
!       }
! 
!       public static boolean hasPlugins()
!     {
!         mLogger.debug("mPlugins.size(): " + mPlugins.size());
!         return (mPlugins != null && mPlugins.size() > 0);
!     }
!     
!     public static List getPagePlugins()
!     {
!         return mPlugins;
!     }
! }
--- 1,491 ----
! package org.roller.presentation.velocity;
! 
! import org.apache.commons.lang.StringUtils;
! import org.apache.commons.logging.Log;
! import org.apache.commons.logging.LogFactory;
! import org.apache.velocity.context.Context;
! import org.roller.RollerException;
! import org.roller.pojos.CommentData;
! import org.roller.pojos.PageData;
! import org.roller.pojos.RollerConfig;
! import org.roller.pojos.UserData;
! import org.roller.pojos.WeblogEntryData;
! import org.roller.pojos.WebsiteData;
! import org.roller.presentation.RollerContext;
! import org.roller.presentation.RollerRequest;
! import org.roller.presentation.RollerSession;
! import org.roller.presentation.newsfeeds.NewsfeedCache;
! import org.roller.presentation.weblog.formbeans.CommentFormEx;
! import org.roller.util.RegexUtil;
! import org.roller.util.Utilities;
! 
! import java.text.SimpleDateFormat;
! import java.util.ArrayList;
! import java.util.Collections;
! import java.util.Date;
! import java.util.Iterator;
! import java.util.List;
! import java.util.Locale;
! import java.util.TimeZone;
! 
! import javax.servlet.ServletContext;
! import javax.servlet.http.HttpServletRequest;
! import javax.servlet.http.HttpServletResponse;
! import javax.servlet.http.HttpSession;
! 
! /**
!  * Load Velocity Context with Roller objects, values, and custom plugins.
!  * 
!  * @author llavandowska
!  * @author David M Johnson
!  * 
!  */
! public class ContextLoader
! {             
!     private RollerRequest mRollerReq = null;
!     
!     // List of PagePlugins for "transforming" WeblogEntries
!     static List mPlugins = new ArrayList();
!     
!     private static Log mLogger = 
!        LogFactory.getFactory().getInstance(ContextLoader.class);
! 
!     //------------------------------------------------------------------------
!     
!     /**
!      * 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 ) 
!         throws RollerException
!     {
!         HttpServletRequest request = rreq.getRequest();
!         RollerContext rollerCtx = RollerContext.getRollerContext( request );
!         
!         // Add page model object to context                    
!         PageModel pageModel = new PageModel(rreq);
!         ctx.put("pageModel", pageModel );
!         ctx.put("pages", pageModel.getPages());
!         
!         // Add Velocity page helper to context
!         PageHelper pageHelper = new PageHelper(rreq, response, ctx);
!         ctx.put("pageHelper", pageHelper );
! 
!         // Add legacy macros too, so that old-school pages still work
!         Macros macros= new Macros(rreq.getPageContext(), pageHelper);
!         ctx.put("macros", macros);
! 
!         // Load standard Roller objects and values into the context 
!         String userName = loadWebsiteValues(ctx, rreq, rollerCtx );
!         loadWeblogValues( ctx, rreq, rollerCtx, userName );            
!         loadPathValues( ctx, rreq, rollerCtx, userName );                     
                    
!         loadRssValues( ctx, rreq, userName );                        
!         loadUtilityObjects( ctx, rreq, rollerCtx ); 
!         loadRequestParamKeys(ctx);
!         loadStatusMessage( ctx, rreq );
!         
!         // If single entry is specified, load comments too
!         if ( rreq.getWeblogEntry() != null )
!         {
!             loadCommentValues( ctx, rreq, rollerCtx );
!         }  
!         
!         // Load custom page plugins
!         Iterator iter = mPlugins.iterator();
!         while (iter.hasNext())
!         {
!             PagePlugin plugin = (PagePlugin) iter.next();
!             plugin.init(rreq,ctx);
!         }
!         
!         // pass the Plugins to PageHelper, make List unmodifiable
!         pageHelper.setPagePlugins( Collections.unmodifiableCollection( 
mPlugins ) );
!     }
!       
!     //------------------------------------------------------------------------
!     
!       /**
!      * If there is an ERROR or STATUS message in the session,
!      * place it into the Context for rendering later.
!      * 
!        * @param rreq
!        */
!       private static void loadStatusMessage(Context ctx, RollerRequest rreq)
!       {
!         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 (session != null)
!             msg = (String)session.getAttribute(RollerSession.STATUS_MESSAGE);
!         if (msg != null)
!         {
!             ctx.put("statusMessage", msg);
!             session.removeAttribute(RollerSession.STATUS_MESSAGE);
!         }
!       }
!     
!     //------------------------------------------------------------------------
! 
!       /**
!        * @param ctx
!        * @param rreq
!        * @param rollerCtx
!        * @param userName
!        */
!       private static void loadWeblogValues(
!        Context ctx, RollerRequest rreq, RollerContext rollerCtx, String 
userName) 
!     {
!         // if there is an "_entry" page, only load it once
!               PageModel pageModel = (PageModel)ctx.get("pageModel");
!         PageData entryPage = pageModel.getUsersPageByName(rreq.getWebsite(), 
"_entry");
!         if (entryPage != null)
!         {
!             ctx.put("entryPage", entryPage);
!         }
!         PageData descPage = pageModel.getUsersPageByName(rreq.getWebsite(), 
"_desc");
!         if (descPage != null)
!         {
!             ctx.put("descPage", descPage);
!         }
!       }
! 
!       private static String figureResourcePath( RollerRequest rreq )
!       {
!           HttpServletRequest request = rreq.getRequest();
!           RollerContext rCtx = RollerContext.getRollerContext( request );
!           RollerConfig  rollerConfig = rCtx.getRollerConfig();
!       
!           StringBuffer sb = new StringBuffer();
!           String uploadPath = rollerConfig.getUploadPath();
!           if ( uploadPath != null && uploadPath.trim().length() > 0 )
!           {
!               sb.append( uploadPath );
!           }
!           else
!           {
!               sb.append( request.getContextPath() );
!               sb.append( RollerContext.USER_RESOURCES );
!           }
!           return sb.toString();
!       }
! 
!     //------------------------------------------------------------------------
!     
!     public boolean isUserAuthorizedToEdit()
!     {
!         try
!         {
!             return mRollerReq.isUserAuthorizedToEdit();
!         }
!         catch (Exception e)
!         {
!             mLogger.warn("PageHelper.isUserAuthorizedToEdit)", e);
!         }
!         return false;
!     }
!     
!     //------------------------------------------------------------------------
!     
!     protected static void loadCommentValues(
!        Context ctx, RollerRequest rreq, RollerContext rollerCtx ) 
!        throws RollerException
!     {
!         HttpServletRequest request = rreq.getRequest();
!         RollerConfig rollerConfig = rollerCtx.getRollerConfig();
!         
!         // Add comments related values to context
!         ctx.put("isCommentPage", Boolean.TRUE);
!         ctx.put("escapeHtml", rollerConfig.getEscapeCommentHtml() );
!         ctx.put("autoformat", rollerConfig.getAutoformatComments() );
!         
!         // Make sure comment form object is available in context
!         CommentFormEx commentForm = 
!             (CommentFormEx)request.getAttribute("commentForm");
!         if ( commentForm == null )
!         {
!             commentForm = new CommentFormEx();
!         
!             // Set fields to spaces to please Velocity
!             commentForm.setName("");
!             commentForm.setEmail("");
!             commentForm.setUrl("");
!             commentForm.setContent("");
!         }        
!         ctx.put("commentForm",commentForm); 
!             
!         // Either put a preview comment in to context          
!         if ( request.getAttribute("previewFromPage")!=null )
!         {
!             ArrayList list = new ArrayList();
!             CommentData cd = new CommentData();
!             commentForm.copyTo(cd, request.getLocale());
!             list.add(cd);
!             ctx.put("previewComments",list);            
!         }
!         else // Or the whole set of comment for the specified weblog entry
!         {
!             WeblogEntryData entry = rreq.getWeblogEntry();
!             ctx.put("entry",entry);            
!         }
!     }   
! 
!     //------------------------------------------------------------------------
!     
!     protected static void loadPathValues(
!       Context ctx, RollerRequest rreq, RollerContext rollerCtx, String 
userName)
!     {
!         HttpServletRequest request = rreq.getRequest();
!         String url = null;
!         if ( userName != null )
!         {
!             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 ) );
!     }
! 
!     //------------------------------------------------------------------------
!     
!     protected static void loadRequestParamKeys(Context ctx)
!     {
!         // 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 userName) throws 
RollerException
!     {
!         HttpServletRequest request = rreq.getRequest();
!         
!         int entryLength = -1;
!         String sExcerpts = request.getParameter("excerpts");
!         if ( sExcerpts!=null && sExcerpts.equalsIgnoreCase("true"))
!         {
!             entryLength = 150;
!         }
!         ctx.put("entryLength",  new Integer(entryLength));
!         
!         int entryCount = 15;
!         String sCount = request.getParameter("count");
!         if ( sCount!=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;
!         }
!         ctx.put("entryCount",  new Integer(entryCount));
!             
!         String catname = null;
!         if ( rreq.getWeblogCategory() != null )
!         {
!             catname = rreq.getWeblogCategory().getName();
!         } 
!         ctx.put("catname",      (catname!=null) ? catname : "");
!         
!         // Add current time and last updated times to context
!         Date updateTime = rreq.getRoller().getWeblogManager()
!             .getWeblogLastPublishTime( userName, catname );                   
     
!         ctx.put("updateTime",   updateTime);
!         ctx.put("now",          new Date());
!     }
! 
!     //------------------------------------------------------------------------
!     
!     protected static void loadUtilityObjects(
!         Context ctx, RollerRequest rreq, RollerContext rollerCtx)
!     {
!         // date formats need to be run through the Localized
!         // SimpleDateFormat and pulled back out as localized patterns.
!         Locale locale = (Locale)ctx.get("locale");
!         SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd", locale);  
!         sdf.setTimeZone( (TimeZone)ctx.get("timezone") );    
!         ctx.put("plainFormat",     sdf.toLocalizedPattern());
!         
!         sdf.applyPattern("EEEE MMMM dd, yyyy");
!         ctx.put("toStringFormat",  sdf.toLocalizedPattern());
!         
!         sdf.applyPattern("MMM dd yyyy, hh:mm:ss a z");
!         ctx.put("timestampFormat", sdf.toLocalizedPattern());
!         
!         ctx.put("dateFormatter", sdf );
! 
!         ctx.put("page",            rreq.getPage() );
!         ctx.put("utilities",       new Utilities() );
!         ctx.put("stringUtils",     new StringUtils() );        
!         ctx.put("rollerVersion",   rollerCtx.getRollerVersion() );
!         ctx.put("rollerBuildTime", rollerCtx.getRollerBuildTime() );
!         ctx.put("rollerBuildUser", rollerCtx.getRollerBuildUser() );
!         ctx.put("newsfeedCache",   NewsfeedCache.getInstance(
!                                        rollerCtx.getRollerConfig()) );
!         
!         ctx.put("requestParameters", rreq.getRequest().getParameterMap());
!     }
!       
!     //------------------------------------------------------------------------
!     
!     protected static String loadWebsiteValues(
!         Context ctx, RollerRequest rreq, RollerContext rollerCtx )
!     {
!         String userName = null;
!         WebsiteData site = null;
!         if ( rreq.getUser() != null )
!         {
!             userName = rreq.getUser().getUserName();
!         }
!         
!         if ( userName != null )
!         {
!             site = rreq.getWebsite();
!             UserData user = rreq.getUser();
!             ctx.put("userName",      user.getUserName() );
!             ctx.put("fullName",      user.getFullName() );
!             ctx.put("emailAddress",  user.getEmailAddress() );
! 
!             ctx.put("encodedEmail",  
RegexUtil.encode(user.getEmailAddress()));
!             ctx.put("obfuscatedEmail",  
RegexUtil.obfuscateEmail(user.getEmailAddress()));
!             
!             // setup Locale for future rendering
!             ctx.put("locale", site.getLocaleInstance());
!             
!             // setup Timezone for future rendering
!             ctx.put("timezone", site.getTimeZoneInstance());
!         }
!         else
!         {
!             site = new WebsiteData();
!             site.setName(rollerCtx.getRollerConfig().getSiteName());
!             site.setAllowComments(Boolean.FALSE);
!             site.setDescription(
!                 rollerCtx.getRollerConfig().getSiteDescription());
!             ctx.put("userName","Administrator" );
!             ctx.put("fullName","Administrator");
!             ctx.put("emailAddress",
!                 rollerCtx.getRollerConfig().getEmailAddress());
!             ctx.put("locale", Locale.getDefault());
!             ctx.put("timezone", TimeZone.getDefault());
!         }
!         ctx.put("website", site );
!         
!         String siteName = rollerCtx.getRollerConfig().getSiteName();
!         if ("Roller-based Site".equals(siteName)) siteName = "Main";
!         ctx.put("siteName", siteName);        
!         
!         return userName;
!     }
!     
!     //------------------------------------------------------------------------
! 
!     /**
!      * Initialize PagePlugins declared in web.xml.  By using the full class
!      * name we also allow for the implementation of "external" Plugins
!      * (maybe even packaged seperately).
!      * 
!        * @param mContext
!        */
!       public static void initializePagePlugins(ServletContext mContext)
!       {
!               String pluginStr = 
mContext.getInitParameter("org.roller.pagePlugins");
!         if (mLogger.isDebugEnabled()) mLogger.debug(pluginStr);
!         if (pluginStr != null)
!         {
!             String[] plugins = StringUtils.stripAll(
!                                    StringUtils.split(pluginStr, ",") );
!             for (int i=0; i<plugins.length; i++)
!             {
!                 if (mLogger.isDebugEnabled()) mLogger.debug("try " + 
plugins[i]);
!                 try
!                 {
!                     Class pluginClass = Class.forName(plugins[i]);
!                     if (isPagePlugin(pluginClass))
!                     {
!                         mPlugins.add(
!                             pluginClass.newInstance()
!                         );
!                     }
!                     else
!                     {
!                         mLogger.warn(pluginClass + " is not a PagePlugin");
!                     }
!                 } 
!                 catch (ClassNotFoundException e)
!                               {
!                     mLogger.warn("ClassNotFoundException for " + plugins[i]);
!                               } 
!                 catch (InstantiationException e)
!                               {
!                     mLogger.warn("InstantiationException for " + plugins[i]);
!                               } 
!                 catch (IllegalAccessException e)
!                               {
!                     mLogger.warn("IllegalAccessException for " + plugins[i]);
!                               }
!             }
!         }
!       }
!     
!     /**
!        * @param pluginClass
!        * @return
!        */
!       private static boolean isPagePlugin(Class pluginClass)
!       {
!         Class[] interfaces = pluginClass.getInterfaces();
!         for (int i=0; i<interfaces.length; i++)
!         {
!             if (interfaces[i].equals(PagePlugin.class)) return true;
!         }
!         return false;
!       }
! 
!       public static boolean hasPlugins()
!     {
!         mLogger.debug("mPlugins.size(): " + mPlugins.size());
!         return (mPlugins != null && mPlugins.size() > 0);
!     }
!     
!     public static List getPagePlugins()
!     {
!         return mPlugins;
!     }
! }

Index: FlavorServlet.java
===================================================================
RCS file: 
/cvsroot/roller/roller/src/org/roller/presentation/velocity/FlavorServlet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** FlavorServlet.java  16 Mar 2004 04:45:38 -0000      1.3
--- FlavorServlet.java  26 Mar 2004 03:00:34 -0000      1.4
***************
*** 1,4 ****
! package org.roller.presentation.velocity;
! 
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
--- 1,3 ----
! package org.roller.presentation.velocity;

  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
***************
*** 7,23 ****
  import org.apache.velocity.servlet.VelocityServlet;
  import org.roller.RollerException;
! import org.roller.presentation.RollerRequest;
! 
! import java.io.IOException;
! 
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.jsp.JspFactory;
! import javax.servlet.jsp.PageContext;
! 
! 
! //////////////////////////////////////////////////////////////////////////////
! 
  /**
    * <p>Responsible for rendering RSS feeds and other "flavors" of output for a
--- 6,17 ----
  import org.apache.velocity.servlet.VelocityServlet;
  import org.roller.RollerException;
! import org.roller.presentation.RollerRequest;

! import java.io.IOException;

  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.jsp.JspFactory;
! import javax.servlet.jsp.PageContext;

! //////////////////////////////////////////////////////////////////////////////

  /**
    * <p>Responsible for rendering RSS feeds and other "flavors" of output for a
***************
*** 35,131 ****
    * <p>Otherwise, the template /flavors/rss.vm" will be used for 
rendering.</p>
    *
!   * <p>Assumes that If-Modified-Since has already been handled.</p>
!   *
!   * @author David M Johnson
!   *
!   * @web.servlet name="RssServlet"
!   * @web.servlet-mapping url-pattern="/rss/*"
!   * @web.servlet-mapping url-pattern="/flavor/*"
!   */
! public class FlavorServlet extends VelocityServlet
! {
!     private static Log mLogger = LogFactory.getFactory()
!                                            .getInstance(RollerRequest.class);
! 
!     public Template handleRequest(HttpServletRequest request,
!                                   HttpServletResponse response, Context ctx)
!     {
!         RollerRequest rreq = null;
! 
!         try
!         {
!             rreq = 
RollerRequest.getRollerRequest(request,getServletContext());
!         }
!         catch (RollerException e)
!         {
!             // An error initializing the request is considered to be a 404
!             if (mLogger.isDebugEnabled())
!             {
!                 mLogger.debug("RollerRequest threw Exception", e);
!             }
! 
!             try
!             {
!                 ((HttpServletResponse)response).sendError(
!                     HttpServletResponse.SC_NOT_FOUND);
!             }
!             catch (IOException e1)
!             {
!                 if (mLogger.isDebugEnabled())
!                 {
!                     mLogger.debug("IOException sending error", e);
!                 }
!             }
!             return null;
!         }
! 
!         try
!         {
!             // Needed to init request attributes, etc.
!             PageContext pageContext =
!                 JspFactory.getDefaultFactory().getPageContext(
!                 this, request,  response, "", true, 8192, true);
! 
!             rreq.setPageContext(pageContext);
!             ContextLoader.setupContext(ctx, rreq, response);
! 
!             final String useTemplate;
!             PageModel pageModel = (PageModel)ctx.get("pageModel");
!             if (    request.getServletPath().endsWith("rss")
!                  && pageModel.getPageByName("_rss") != null )
!             {
!                 // If the request specified the "/rss" mapping and the
!                 // user has defined an RSS override page, we will use that.
!                 useTemplate = pageModel.getPageByName("_rss").getId();
!             }
!             else if (request.getParameter("flavor") != null)
!             {
!                 // If request specifies a "flavor" then use that.
!                 String flavor = request.getParameter("flavor");
!                 useTemplate = "/flavors/" + flavor + ".vm";
!             }
!             else
!             {
!                 // Fall through to default RSS page template.
!                 useTemplate = "/flavors/rss.vm";
!             }
! 
!             return getTemplate(useTemplate);
!         }
!         catch (Exception e)
!         {
!             mLogger.error("ERROR in RssServlet", e);
!         }
!         return null;
!     }
! 
!     //------------------------------------------------------------------------
!     /**
!      * Handle error in Velocity processing.
!      */
!     protected void error( HttpServletRequest req, HttpServletResponse res,
!         Exception e) throws ServletException, IOException
!     {
!         mLogger.warn("ERROR in FlavorServlet",e);
!     }
! }
--- 29,38 ----
    * <p>Otherwise, the template /flavors/rss.vm" will be used for 
rendering.</p>
    *
!   * <p>Assumes that If-Modified-Since has already been handled.</p>
  *
  * @author David M Johnson
  *
  * @web.servlet name="RssServlet"
  * @web.servlet-mapping url-pattern="/rss/*"
  * @web.servlet-mapping url-pattern="/flavor/*"
  */
public class FlavorServlet extends VelocityServlet
{
    private static Log mLogger = LogFactory.getFactory()
                                           .getInstance(RollerRequest.class);

!     public Template handleRequest(HttpServletRequest request,
                                  HttpServletResponse response, Context ctx)
    {
        RollerRequest rreq = null;

!         try
        {
            rreq = RollerRequest.getRollerRequest(request,getServletContext());
        }
        catch (RollerException e)
        {
            // An error initializing the request is considered to be a 404
            if (mLogger.isDebugEnabled())
            {
                mLogger.debug("RollerRequest threw Exception", e);
            }

!             try
            {
                ((HttpServletResponse)response).sendError(
                    HttpServletResponse.SC_NOT_FOUND);
            }
            catch (IOException e1)
            {
                if (mLogger.isDebugEnabled())
                {
                    mLogger.debug("IOException sending error", e);
                }
            }
            return null;
        }

!         try
        {
            // Needed to init request attributes, etc.
            PageContext pageContext =
                JspFactory.getDefaultFactory().getPageContext(
                this, request,  response, "", true, 8192, true);

!             rreq.setPageContext(pageContext);
            ContextLoader.setupContext(ctx, rreq, response);

            final String useTemplate;
            PageModel pageModel = (PageModel)ctx.get("pageModel");
            if (    request.getServletPath().endsWith("rss")
                 && pageModel.getPageByName("_rss") != null )
            {
                // If the request specified the "/rss" mapping and the
                // user has defined an RSS override page, we will use that.
                useTemplate = pageModel.getPageByName("_rss").getId();
            }
            else if (request.getParameter("flavor") != null)
            {
                // If request specifies a "flavor" then use that.
                String flavor = request.getParameter("flavor");
                useTemplate = "/flavors/" + flavor + ".vm";
            }
            else
            {
                // Fall through to default RSS page template.
                useTemplate = "/flavors/rss.vm";
            }

!             return getTemplate(useTemplate);
        }
        catch (Exception e)
        {
            mLogger.error("ERROR in RssServlet", e);
        }
        return null;
    }

!     //------------------------------------------------------------------------
    /**
     * Handle error in Velocity processing.
     */
    protected void error( HttpServletRequest req, HttpServletResponse res,
        Exception e) throws ServletException, IOException
    {
        mLogger.warn("ERROR in FlavorServlet",e);
    }
}


Index: PageHelper.java
===================================================================
RCS file: 
/cvsroot/roller/roller/src/org/roller/presentation/velocity/PageHelper.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** PageHelper.java     20 Mar 2004 02:32:17 -0000      1.14
--- PageHelper.java     26 Mar 2004 03:00:34 -0000      1.15
***************
*** 1,529 ****
! package org.roller.presentation.velocity;
! 
! import org.apache.commons.lang.StringUtils;
! import org.apache.commons.logging.Log;
! import org.apache.commons.logging.LogFactory;
! import org.apache.struts.util.RequestUtils;
! import org.apache.velocity.VelocityContext;
! import org.apache.velocity.app.Velocity;
! import org.apache.velocity.context.Context;
! import org.roller.pojos.RefererData;
[...1035 lines suppressed...]
!                 }
!                 
!                 // now loop over mPagePlugins, matching
!                 // against Entry plugins (by name):
!                 // where a match is found render Plugin.
!                 Iterator iter = mPagePlugins.iterator();
!                 PagePlugin pagePlugin = null;
!                 while (iter.hasNext())
!                 {
!                     pagePlugin = (PagePlugin)iter.next();
!                     if (entryPlugins.contains(pagePlugin.toString()))
!                     {
!                         copy.setText((pagePlugin).render(copy, mSkipFlag));
!                     }
!                 }
!             }
!         }
!         return copy.getText();
!     }
! }



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
web.pylons.gene...    hurd.l4/2002-10...    kernel.commits....    user-groups.lin...    yellowdog.gener...    java.drools.use...    security.openva...    package-managem...    linux.debian.us...    qnx.openqnx.dev...    genealogy.gramp...    file-systems.if...    voip.wengophone...    tex.context/200...    ietf.smime/2003...    audio.csound.de...    culture.region....    xfree86.devel/2...    mobile.kannel.u...    distributed.con...    education.engli...    org.user-groups...    bug-tracking.gn...    recreation.bicy...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe