roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r209366 - in /incubator/roller/trunk/src/org/roller/presentation/velocity: BasePageServlet.java ExportRss.java FlavorServlet.java FoafServlet.java PlanetFeedServlet.java
Date Wed, 06 Jul 2005 00:41:33 GMT
Author: agilliland
Date: Tue Jul  5 17:41:31 2005
New Revision: 209366

URL: http://svn.apache.org/viewcvs?rev=209366&view=rev
Log:
Fixing the endline problem with these files.  changed from macOS (\r) endlines to windows style (\n\r) ... hopefully this works for everyone.


Modified:
    incubator/roller/trunk/src/org/roller/presentation/velocity/BasePageServlet.java
    incubator/roller/trunk/src/org/roller/presentation/velocity/ExportRss.java
    incubator/roller/trunk/src/org/roller/presentation/velocity/FlavorServlet.java
    incubator/roller/trunk/src/org/roller/presentation/velocity/FoafServlet.java
    incubator/roller/trunk/src/org/roller/presentation/velocity/PlanetFeedServlet.java

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/BasePageServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/BasePageServlet.java?rev=209366&r1=209365&r2=209366&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/BasePageServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/BasePageServlet.java Tue Jul  5 17:41:31 2005
@@ -1 +1,225 @@
-package org.roller.presentation.velocity;

import java.io.IOException;
import java.io.StringWriter;
import java.util.Map;

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.context.Context;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.servlet.VelocityServlet;
import org.roller.model.RollerFactory;
import org.roller.model.UserManager;
import org.roller.pojos.UserData;
import org.roller.pojos.WebsiteData;
import org.roller.presentation.RollerRequest;

/**
 * Base Servlet for Servlets that render user page templates. Loads the
 * Velocity context using the ContextLoader and runs the page template
 * selected by the request.
 *
 * @author llavandowska
 * @author David M Johnson
 * @author Allen Gilliland
 */
public abstract class BasePageServlet extends VelocityServlet {
    
    private static Log mLogger =
            LogFactory.getFactory().getInstance(BasePageServlet.class);
    
    
    /**
     * Sets servletContext for WebappResourceLoader.
     */
    public void init( ServletConfig config )
        throws ServletException {
        
        super.init( config );
        WebappResourceLoader.setServletContext( getServletContext() );
    }
    
    
    public Template handleRequest( HttpServletRequest request,
            HttpServletResponse response,
            Context ctx ) throws Exception {
        
        Template outty = null;
        Exception pageException = null;
        
        try {
            PageContext pageContext =
                    JspFactory.getDefaultFactory().getPageContext(
                    this, request, response,"", true, 8192, true);
            // Needed to init request attributes, etc.
            RollerRequest rreq = RollerRequest.getRollerRequest(pageContext);
            UserManager userMgr = RollerFactory.getRoller().getUserManager();
            
            WebsiteData website = null;
            if (request.getAttribute(RollerRequest.OWNING_USER) != null) {
                UserData user = (UserData)
                    request.getAttribute(RollerRequest.OWNING_USER);
                website = userMgr.getWebsite(user.getUserName());
            } else {
                website = rreq.getWebsite();
            }
            
            org.roller.model.Template page = null;
            
            // If request specified the page, then go with that
            if (rreq.getPage() != null &&
                    rreq.getRequest().getAttribute(RollerRequest.OWNING_USER) == null) {
                page = rreq.getPage();
                
                // If page not available from request, then use website's default
            } else if (website != null) {
                page = website.getDefaultPage();
                rreq.setPage(page);
            }
            
            // Still no page ID, then we have a problem
            if ( page == null ) {
                throw new ResourceNotFoundException("Page not found");
            }

            // this sets up the page we want to render
            outty = prepareForPageExecution(ctx, rreq, response, page);
            
            // if there is a decorator template then apply it
            if (website != null) {
                // parse/merge Page template
                StringWriter sw = new StringWriter();
                outty.merge(ctx, sw);
                ctx.put("decorator_body", sw.toString());
                
                // replace outty with decorator Template
                outty = findDecorator(website, (String) ctx.get("decorator"));
            }
            
        } catch( Exception e ) {
            pageException = e;
            response.setStatus( HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
        
        if (pageException != null) {
            mLogger.error("EXCEPTION: in RollerServlet", pageException);
            request.setAttribute("DisplayException", pageException);
        }
        
        return outty;
    }
    
    
    /**
     * Prepare the requested page for execution by setting content type
     * and populating velocity context.
     */
    protected Template prepareForPageExecution(Context ctx,
            RollerRequest rreq,
            HttpServletResponse response,
            org.roller.model.Template page) throws Exception {
        
        Template outty = null;
        
        // if page has an extension - use that to set the contentType
        String pageLink = page.getLink();
        String mimeType = getServletConfig().getServletContext().getMimeType(pageLink);
        if(mimeType != null) {
            // we found a match ... set the content type
            response.setContentType(mimeType);
        }
        
        // Made it this far, populate the Context
        ContextLoader.setupContext( ctx, rreq, response );
        
        return getTemplate( page.getId(), "UTF-8" );
    }
    
    
    /**
     * Load the decorator template and apply it.  If there is no user specified
     * decorator then the default decorator is applied.
     */
    protected Template findDecorator(WebsiteData website, String decorator_name)
        throws Exception {
        
        Template decorator = null;
        org.roller.model.Template decorator_template = null;
        
        // check for user-specified decorator
        if (decorator_name != null) {
            decorator_template = website.getPageByName(decorator_name);
        }
        
        // if no user-specified decorator try default page-name
        if (decorator_template == null) {
            decorator_template = website.getPageByName("_decorator");
        }
        
        // try loading Template
        if (decorator_template != null) {
            try {
                decorator = getTemplate(decorator_template.getId(), "UTF-8");
            } catch (Exception e) {
                // it may not exist, so this is okay
            }
        }
        
        // couldn't find Template, load default "no-op" decorator
        if (decorator == null) {
            decorator = getTemplate("/themes/noop_decorator.vm", "UTF-8");
        }
        
        return decorator;
    }
    
    
    /**
     * Handle error in Velocity processing.
     */
    protected void error( HttpServletRequest req, HttpServletResponse res,
            Exception e) throws ServletException, IOException {
        mLogger.warn("ERROR in VelocityServlet",e);
    }
    
    /**
     * Override to prevent Velocity from putting "req" and "res" into the context.
     * Allowing users access to the underlying Servlet objects is a security risk.
     * If need access to request parameters, use $requestParameters.
     */
    protected Context createContext(
            HttpServletRequest req,
            HttpServletResponse res) {
        
        VelocityContext context = new VelocityContext();
        context.put(REQUEST, new RequestWrapper(req.getParameterMap()));
        return context;
        
    }
    
    /** Provide access to request params only, not actual request */
    public static class RequestWrapper {
        Map params = null;
        public RequestWrapper(Map params) {
            this.params = params;
        }
        public String getParameter(String key) {
            String ret = null;
            String[] array = (String[])params.get(key);
            if (array != null && array.length > 0) {
                ret = array[0];
            }
            return ret;
        }
    }
}
\ No newline at end of file
+package org.roller.presentation.velocity;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Map;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspFactory;
+import javax.servlet.jsp.PageContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.servlet.VelocityServlet;
+import org.roller.model.RollerFactory;
+import org.roller.model.UserManager;
+import org.roller.pojos.UserData;
+import org.roller.pojos.WebsiteData;
+import org.roller.presentation.RollerRequest;
+
+/**
+ * Base Servlet for Servlets that render user page templates. Loads the
+ * Velocity context using the ContextLoader and runs the page template
+ * selected by the request.
+ *
+ * @author llavandowska
+ * @author David M Johnson
+ * @author Allen Gilliland
+ */
+public abstract class BasePageServlet extends VelocityServlet {
+    
+    private static Log mLogger =
+            LogFactory.getFactory().getInstance(BasePageServlet.class);
+    
+    
+    /**
+     * Sets servletContext for WebappResourceLoader.
+     */
+    public void init( ServletConfig config )
+        throws ServletException {
+        
+        super.init( config );
+        WebappResourceLoader.setServletContext( getServletContext() );
+    }
+    
+    
+    public Template handleRequest( HttpServletRequest request,
+            HttpServletResponse response,
+            Context ctx ) throws Exception {
+        
+        Template outty = null;
+        Exception pageException = null;
+        
+        try {
+            PageContext pageContext =
+                    JspFactory.getDefaultFactory().getPageContext(
+                    this, request, response,"", true, 8192, true);
+            // Needed to init request attributes, etc.
+            RollerRequest rreq = RollerRequest.getRollerRequest(pageContext);
+            UserManager userMgr = RollerFactory.getRoller().getUserManager();
+            
+            WebsiteData website = null;
+            if (request.getAttribute(RollerRequest.OWNING_USER) != null) {
+                UserData user = (UserData)
+                    request.getAttribute(RollerRequest.OWNING_USER);
+                website = userMgr.getWebsite(user.getUserName());
+            } else {
+                website = rreq.getWebsite();
+            }
+            
+            org.roller.model.Template page = null;
+            
+            // If request specified the page, then go with that
+            if (rreq.getPage() != null &&
+                    rreq.getRequest().getAttribute(RollerRequest.OWNING_USER) == null) {
+                page = rreq.getPage();
+                
+                // If page not available from request, then use website's default
+            } else if (website != null) {
+                page = website.getDefaultPage();
+                rreq.setPage(page);
+            }
+            
+            // Still no page ID, then we have a problem
+            if ( page == null ) {
+                throw new ResourceNotFoundException("Page not found");
+            }
+
+            // this sets up the page we want to render
+            outty = prepareForPageExecution(ctx, rreq, response, page);
+            
+            // if there is a decorator template then apply it
+            if (website != null) {
+                // parse/merge Page template
+                StringWriter sw = new StringWriter();
+                outty.merge(ctx, sw);
+                ctx.put("decorator_body", sw.toString());
+                
+                // replace outty with decorator Template
+                outty = findDecorator(website, (String) ctx.get("decorator"));
+            }
+            
+        } catch( Exception e ) {
+            pageException = e;
+            response.setStatus( HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+        }
+        
+        if (pageException != null) {
+            mLogger.error("EXCEPTION: in RollerServlet", pageException);
+            request.setAttribute("DisplayException", pageException);
+        }
+        
+        return outty;
+    }
+    
+    
+    /**
+     * Prepare the requested page for execution by setting content type
+     * and populating velocity context.
+     */
+    protected Template prepareForPageExecution(Context ctx,
+            RollerRequest rreq,
+            HttpServletResponse response,
+            org.roller.model.Template page) throws Exception {
+        
+        Template outty = null;
+        
+        // if page has an extension - use that to set the contentType
+        String pageLink = page.getLink();
+        String mimeType = getServletConfig().getServletContext().getMimeType(pageLink);
+        if(mimeType != null) {
+            // we found a match ... set the content type
+            response.setContentType(mimeType);
+        }
+        
+        // Made it this far, populate the Context
+        ContextLoader.setupContext( ctx, rreq, response );
+        
+        return getTemplate( page.getId(), "UTF-8" );
+    }
+    
+    
+    /**
+     * Load the decorator template and apply it.  If there is no user specified
+     * decorator then the default decorator is applied.
+     */
+    protected Template findDecorator(WebsiteData website, String decorator_name)
+        throws Exception {
+        
+        Template decorator = null;
+        org.roller.model.Template decorator_template = null;
+        
+        // check for user-specified decorator
+        if (decorator_name != null) {
+            decorator_template = website.getPageByName(decorator_name);
+        }
+        
+        // if no user-specified decorator try default page-name
+        if (decorator_template == null) {
+            decorator_template = website.getPageByName("_decorator");
+        }
+        
+        // try loading Template
+        if (decorator_template != null) {
+            try {
+                decorator = getTemplate(decorator_template.getId(), "UTF-8");
+            } catch (Exception e) {
+                // it may not exist, so this is okay
+            }
+        }
+        
+        // couldn't find Template, load default "no-op" decorator
+        if (decorator == null) {
+            decorator = getTemplate("/themes/noop_decorator.vm", "UTF-8");
+        }
+        
+        return decorator;
+    }
+    
+    
+    /**
+     * Handle error in Velocity processing.
+     */
+    protected void error( HttpServletRequest req, HttpServletResponse res,
+            Exception e) throws ServletException, IOException {
+        mLogger.warn("ERROR in VelocityServlet",e);
+    }
+    
+    /**
+     * Override to prevent Velocity from putting "req" and "res" into the context.
+     * Allowing users access to the underlying Servlet objects is a security risk.
+     * If need access to request parameters, use $requestParameters.
+     */
+    protected Context createContext(
+            HttpServletRequest req,
+            HttpServletResponse res) {
+        
+        VelocityContext context = new VelocityContext();
+        context.put(REQUEST, new RequestWrapper(req.getParameterMap()));
+        return context;
+        
+    }
+    
+    /** Provide access to request params only, not actual request */
+    public static class RequestWrapper {
+        Map params = null;
+        public RequestWrapper(Map params) {
+            this.params = params;
+        }
+        public String getParameter(String key) {
+            String ret = null;
+            String[] array = (String[])params.get(key);
+            if (array != null && array.length > 0) {
+                ret = array[0];
+            }
+            return ret;
+        }
+    }
+}

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/ExportRss.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/ExportRss.java?rev=209366&r1=209365&r2=209366&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/ExportRss.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/ExportRss.java Tue Jul  5 17:41:31 2005
@@ -1 +1,231 @@
-package org.roller.presentation.velocity;

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.UserData;
import org.roller.pojos.WebsiteData;
import org.roller.presentation.RollerContext;
import org.roller.util.RegexUtil;
import org.roller.util.StringUtils;
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
{
    private VelocityEngine ve = null;
    private VelocityContext ctx = null;
    private UserData user = null;
    private boolean exportAtom;
    
    private static final String RSS_TEMPLATE = "org/roller/presentation/velocity/export_rss.vm";
    private static final String ATOM_TEMPLATE = "org/roller/presentation/velocity/export_atom.vm";
    
    public ExportRss(WebsiteData website) throws Exception
    {
        Properties props = new Properties();
        props.load(RollerContext.getServletContext().
                   getResourceAsStream("/WEB-INF/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);
    }
    
    public void setExportAtom(boolean atom)
    {
        exportAtom = atom;
    }
    
    /**
     * 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);
        
        String templateFile = RSS_TEMPLATE;
        if (exportAtom) templateFile = ATOM_TEMPLATE;
        Template template = ve.getTemplate( templateFile, "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("entryLength",     new Integer(-1));
    }

    /**
     * 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()));

        
        // custom figureResourcePath() due to no "request" object
        StringBuffer sb = new StringBuffer();
        String uploadDir = null;
        try {
            uploadDir = RollerFactory.getRoller().getFileManager().getUploadDir();
        } catch(Exception e) {}

        ctx.put("uploadPath", uploadDir);
    }

    /**
     * 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);
        // set no PagePlugins - we *do not* want to render them.
        ctx.put("pageHelper", pageHelper );
    }
}
\ No newline at end of file
+package org.roller.presentation.velocity;
+
+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.UserData;
+import org.roller.pojos.WebsiteData;
+import org.roller.presentation.RollerContext;
+import org.roller.util.RegexUtil;
+import org.roller.util.StringUtils;
+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
+{
+    private VelocityEngine ve = null;
+    private VelocityContext ctx = null;
+    private UserData user = null;
+    private boolean exportAtom;
+    
+    private static final String RSS_TEMPLATE = "org/roller/presentation/velocity/export_rss.vm";
+    private static final String ATOM_TEMPLATE = "org/roller/presentation/velocity/export_atom.vm";
+    
+    public ExportRss(WebsiteData website) throws Exception
+    {
+        Properties props = new Properties();
+        props.load(RollerContext.getServletContext().
+                   getResourceAsStream("/WEB-INF/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);
+    }
+    
+    public void setExportAtom(boolean atom)
+    {
+        exportAtom = atom;
+    }
+    
+    /**
+     * 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);
+        
+        String templateFile = RSS_TEMPLATE;
+        if (exportAtom) templateFile = ATOM_TEMPLATE;
+        Template template = ve.getTemplate( templateFile, "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("entryLength",     new Integer(-1));
+    }
+
+    /**
+     * 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()));
+
+        
+        // custom figureResourcePath() due to no "request" object
+        StringBuffer sb = new StringBuffer();
+        String uploadDir = null;
+        try {
+            uploadDir = RollerFactory.getRoller().getFileManager().getUploadDir();
+        } catch(Exception e) {}
+
+        ctx.put("uploadPath", uploadDir);
+    }
+
+    /**
+     * 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);
+        // set no PagePlugins - we *do not* want to render them.
+        ctx.put("pageHelper", pageHelper );
+    }
+}

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/FlavorServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/FlavorServlet.java?rev=209366&r1=209365&r2=209366&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/FlavorServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/FlavorServlet.java Tue Jul  5 17:41:31 2005
@@ -1 +1,133 @@
-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.Template;
import org.apache.velocity.context.Context;
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
  * weblog.</p>
  *
  * <p>If Servlet is mapped to <code>/rss</code> and user has defined
  * an RSS override page (i.e. a page named "_rss"), then that Velocity
  * template will be used for rendering.</p>
  *
  * <p>If there is a request parameter named "flavor", then the Velocity
  * template specified by that parameter will be used for rendering. For
  * example if the flavor is "rss092" then the template at classpath
  * "/flavors/rss092.vm" will be used for rendering.</p>
  *
  * <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
{
    static final long serialVersionUID = -2720532269434186051L;
    
    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());
            
            // This is an ugly hack to fix the following bug: 
            // ROL-547: "Site wide RSS feed is your own if you are logged in"
            String[] pathInfo = StringUtils.split(rreq.getPathInfo(),"/"); 
            if (pathInfo.length < 1) 
            {
                // If website not specified in URL, set it to null
                rreq.setWebsite(null);
            }
        }
        catch (RollerException e)
        {
            // An error initializing the request is considered to be a 404
            if (mLogger.isDebugEnabled())
            {
                mLogger.debug("RollerRequest threw Exception", e);
            }
            try
            {
                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);
    }
}

\ No newline at end of file
+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.Template;
+import org.apache.velocity.context.Context;
+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
+  * weblog.</p>
+  *
+  * <p>If Servlet is mapped to <code>/rss</code> and user has defined
+  * an RSS override page (i.e. a page named "_rss"), then that Velocity
+  * template will be used for rendering.</p>
+  *
+  * <p>If there is a request parameter named "flavor", then the Velocity
+  * template specified by that parameter will be used for rendering. For
+  * example if the flavor is "rss092" then the template at classpath
+  * "/flavors/rss092.vm" will be used for rendering.</p>
+  *
+  * <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
+{
+    static final long serialVersionUID = -2720532269434186051L;
+    
+    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());
+            
+            // This is an ugly hack to fix the following bug: 
+            // ROL-547: "Site wide RSS feed is your own if you are logged in"
+            String[] pathInfo = StringUtils.split(rreq.getPathInfo(),"/"); 
+            if (pathInfo.length < 1) 
+            {
+                // If website not specified in URL, set it to null
+                rreq.setWebsite(null);
+            }
+        }
+        catch (RollerException e)
+        {
+            // An error initializing the request is considered to be a 404
+            if (mLogger.isDebugEnabled())
+            {
+                mLogger.debug("RollerRequest threw Exception", e);
+            }
+            try
+            {
+                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);
+    }
+}
+

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/FoafServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/FoafServlet.java?rev=209366&r1=209365&r2=209366&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/FoafServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/FoafServlet.java Tue Jul  5 17:41:31 2005
@@ -1 +1,154 @@
-package org.roller.presentation.velocity;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.velocity.Template;
import org.apache.velocity.context.Context;
import org.apache.velocity.servlet.VelocityServlet;
import org.roller.RollerException;
import org.roller.model.UserManager;
import org.roller.pojos.WeblogTemplate;
import org.roller.pojos.UserData;
import org.roller.pojos.WebsiteData;
import org.roller.presentation.RollerContext;
import org.roller.presentation.RollerRequest;
import org.roller.util.Utilities;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


//////////////////////////////////////////////////////////////////////////////

/**
  * <p>Responsible for rendering FOAF feed.  This servlet requires
  * that the RequestFilter is in place for it, and should also
  * have the IfModifiedFilter configured.</p>
  * 
  * <p>Resources:<br />
  * <a href="http://xmlns.com/foaf/0.1/"
  *     >FOAF Vocabulary Specification</a><br />
  * <a href="http://www.xml.com/lpt/a/2004/02/04/foaf.html"
  *     >An Introduction to FOAF</a></p>
  * 
  * <p>FOAF Autodiscovery: <br />
  * <link rel="meta" type="application/rdf+xml" title="FOAF" 
  *     href="$absBaseURL/foaf/$userName" /> </p>
  *
  * @author Lance Lavandowska
  *
  * @web.servlet name="FoafServlet"
  * @web.servlet-mapping url-pattern="/foaf/*"
  */
public class FoafServlet extends VelocityServlet
{
    static final long serialVersionUID = -1893244416537298619L;
    
    private static Log mLogger = LogFactory.getFactory()
                                           .getInstance(RollerRequest.class);

    /**
     * This Velocity servlet does not make use of ContextLoader and associated
     * classes (as do FlavorServlet and PageServlet) because that is more
     * work than is really necessary.  It implements its own setupContext()
     * to load necessary values into the Velocity Context.
     * 
     * @param ctx
     * @param rreq
     * @throws RollerException
     */
    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
            {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
            }
            catch (IOException e1)
            {
                if (mLogger.isDebugEnabled())
                {
                    mLogger.debug("IOException sending error", e);
                }
            }
            return null;
        }
        
        try
        {
            setupContext(ctx, rreq);

            response.setContentType("application/rdf+xml");
            return getTemplate("/flavors/foaf.vm");
        }
        catch (Exception e)
        {
            mLogger.error("ERROR in FoafServlet", e);
        }
        return null;
    }

    /**
	 * @param ctx
	 */
	private void setupContext(Context ctx, RollerRequest rreq) throws RollerException
	{
        HttpServletRequest request = rreq.getRequest();
        RollerContext rollerCtx = RollerContext.getRollerContext( request );
        
        UserData user = rreq.getUser();
        ctx.put("fullName", user.getFullName()); // name for FlavorServlet compatibility
        
        // foaf:homepage to equal base URL for user
        String homepage = Utilities.escapeHTML( 
                rollerCtx.getAbsoluteContextUrl(request) + 
                    "/page/" + rreq.getUser().getUserName() );
        ctx.put("websiteURL", homepage); // name for FlavorServlet compatibility

        // see if foaf:weblog is different Page
        WebsiteData website = rreq.getWebsite();
        UserManager usrMgr = RollerContext.getRoller(request).getUserManager();
        org.roller.model.Template weblog = website.getPageByName("Weblog");
        
        // if weblog != homepage, add to context
        if (weblog != null && !website.getDefaultPageId().equals(weblog.getId()))
        {
            String weblogUrl = Utilities.escapeHTML( 
                    rollerCtx.getAbsoluteContextUrl(request) + 
                        "/page/" + rreq.getUser().getUserName() + 
                            "/" + weblog.getLink() );
        	ctx.put("weblog", weblogUrl);
        }
        
        // use SHA1 encrypted email address, including mailto: prefix
        String shaEmail = Utilities.encodePassword(
                "mailto:" + user.getEmailAddress(), "SHA");
        ctx.put("shaEmail", shaEmail);
	}

	//------------------------------------------------------------------------
    /**
     * Handle error in Velocity processing.
     */
    protected void error( HttpServletRequest req, HttpServletResponse res,
        Exception e) throws ServletException, IOException
    {
        mLogger.warn("ERROR in FoafServlet",e);
    }
}
\ No newline at end of file
+package org.roller.presentation.velocity;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.Template;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.servlet.VelocityServlet;
+import org.roller.RollerException;
+import org.roller.model.UserManager;
+import org.roller.pojos.WeblogTemplate;
+import org.roller.pojos.UserData;
+import org.roller.pojos.WebsiteData;
+import org.roller.presentation.RollerContext;
+import org.roller.presentation.RollerRequest;
+import org.roller.util.Utilities;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+
+//////////////////////////////////////////////////////////////////////////////
+
+/**
+  * <p>Responsible for rendering FOAF feed.  This servlet requires
+  * that the RequestFilter is in place for it, and should also
+  * have the IfModifiedFilter configured.</p>
+  * 
+  * <p>Resources:<br />
+  * <a href="http://xmlns.com/foaf/0.1/"
+  *     >FOAF Vocabulary Specification</a><br />
+  * <a href="http://www.xml.com/lpt/a/2004/02/04/foaf.html"
+  *     >An Introduction to FOAF</a></p>
+  * 
+  * <p>FOAF Autodiscovery: <br />
+  * <link rel="meta" type="application/rdf+xml" title="FOAF" 
+  *     href="$absBaseURL/foaf/$userName" /> </p>
+  *
+  * @author Lance Lavandowska
+  *
+  * @web.servlet name="FoafServlet"
+  * @web.servlet-mapping url-pattern="/foaf/*"
+  */
+public class FoafServlet extends VelocityServlet
+{
+    static final long serialVersionUID = -1893244416537298619L;
+    
+    private static Log mLogger = LogFactory.getFactory()
+                                           .getInstance(RollerRequest.class);
+
+    /**
+     * This Velocity servlet does not make use of ContextLoader and associated
+     * classes (as do FlavorServlet and PageServlet) because that is more
+     * work than is really necessary.  It implements its own setupContext()
+     * to load necessary values into the Velocity Context.
+     * 
+     * @param ctx
+     * @param rreq
+     * @throws RollerException
+     */
+    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
+            {
+                response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            }
+            catch (IOException e1)
+            {
+                if (mLogger.isDebugEnabled())
+                {
+                    mLogger.debug("IOException sending error", e);
+                }
+            }
+            return null;
+        }
+        
+        try
+        {
+            setupContext(ctx, rreq);
+
+            response.setContentType("application/rdf+xml");
+            return getTemplate("/flavors/foaf.vm");
+        }
+        catch (Exception e)
+        {
+            mLogger.error("ERROR in FoafServlet", e);
+        }
+        return null;
+    }
+
+    /**
+	 * @param ctx
+	 */
+	private void setupContext(Context ctx, RollerRequest rreq) throws RollerException
+	{
+        HttpServletRequest request = rreq.getRequest();
+        RollerContext rollerCtx = RollerContext.getRollerContext( request );
+        
+        UserData user = rreq.getUser();
+        ctx.put("fullName", user.getFullName()); // name for FlavorServlet compatibility
+        
+        // foaf:homepage to equal base URL for user
+        String homepage = Utilities.escapeHTML( 
+                rollerCtx.getAbsoluteContextUrl(request) + 
+                    "/page/" + rreq.getUser().getUserName() );
+        ctx.put("websiteURL", homepage); // name for FlavorServlet compatibility
+
+        // see if foaf:weblog is different Page
+        WebsiteData website = rreq.getWebsite();
+        UserManager usrMgr = RollerContext.getRoller(request).getUserManager();
+        org.roller.model.Template weblog = website.getPageByName("Weblog");
+        
+        // if weblog != homepage, add to context
+        if (weblog != null && !website.getDefaultPageId().equals(weblog.getId()))
+        {
+            String weblogUrl = Utilities.escapeHTML( 
+                    rollerCtx.getAbsoluteContextUrl(request) + 
+                        "/page/" + rreq.getUser().getUserName() + 
+                            "/" + weblog.getLink() );
+        	ctx.put("weblog", weblogUrl);
+        }
+        
+        // use SHA1 encrypted email address, including mailto: prefix
+        String shaEmail = Utilities.encodePassword(
+                "mailto:" + user.getEmailAddress(), "SHA");
+        ctx.put("shaEmail", shaEmail);
+	}
+
+	//------------------------------------------------------------------------
+    /**
+     * Handle error in Velocity processing.
+     */
+    protected void error( HttpServletRequest req, HttpServletResponse res,
+        Exception e) throws ServletException, IOException
+    {
+        mLogger.warn("ERROR in FoafServlet",e);
+    }
+}

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/PlanetFeedServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/PlanetFeedServlet.java?rev=209366&r1=209365&r2=209366&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/PlanetFeedServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/PlanetFeedServlet.java Tue Jul  5 17:41:31 2005
@@ -1 +1,91 @@
-package org.roller.presentation.velocity;
import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.velocity.Template;
import org.apache.velocity.context.Context;
import org.apache.velocity.servlet.VelocityServlet;
import org.roller.RollerException;
import org.roller.model.PlanetManager;
import org.roller.presentation.RollerRequest;
import org.roller.util.Utilities;

/////////////////////////////////////////////////////////////////////////////
/**
 * Planet Roller (i.e. NOT for Planet Tool) RSS feed. 
 * @author David M Johnson
 * @web.servlet name="PlanetFeedServlet"
 * @web.servlet-mapping url-pattern="/planetrss/*"
 */
public class PlanetFeedServlet extends VelocityServlet
{
    private static Log mLogger = 
        LogFactory.getFactory().getInstance(RollerRequest.class);
    
    public Template handleRequest(HttpServletRequest request,
                                  HttpServletResponse response, Context context)
    {
        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
            {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
            }
            catch (IOException e1)
            {
                if (mLogger.isDebugEnabled())
                {
                    mLogger.debug("IOException sending error", e);
                }
            }
            return null;
        }
        try
        {
            response.setContentType("application/rss+xml;charset=utf-8");
            PlanetManager planet = 
                rreq.getRoller().getPlanetManager();
            if (request.getParameter("group") != null) 
            {
                context.put("group", 
                        planet.getGroup(request.getParameter("group")));
            }
            context.put("planet", planet);
            context.put("date", new Date());
            context.put("utilities", new Utilities());
            return getTemplate("planetrss.vm");
        }
        catch (Exception e)
        {
            mLogger.error("ERROR in PlanetFeedServlet", e);
        }
        return null;
    }

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

\ No newline at end of file
+package org.roller.presentation.velocity;
+import java.io.IOException;
+import java.util.Date;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.Template;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.servlet.VelocityServlet;
+import org.roller.RollerException;
+import org.roller.model.PlanetManager;
+import org.roller.presentation.RollerRequest;
+import org.roller.util.Utilities;
+
+/////////////////////////////////////////////////////////////////////////////
+/**
+ * Planet Roller (i.e. NOT for Planet Tool) RSS feed. 
+ * @author David M Johnson
+ * @web.servlet name="PlanetFeedServlet"
+ * @web.servlet-mapping url-pattern="/planetrss/*"
+ */
+public class PlanetFeedServlet extends VelocityServlet
+{
+    private static Log mLogger = 
+        LogFactory.getFactory().getInstance(RollerRequest.class);
+    
+    public Template handleRequest(HttpServletRequest request,
+                                  HttpServletResponse response, Context context)
+    {
+        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
+            {
+                response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            }
+            catch (IOException e1)
+            {
+                if (mLogger.isDebugEnabled())
+                {
+                    mLogger.debug("IOException sending error", e);
+                }
+            }
+            return null;
+        }
+        try
+        {
+            response.setContentType("application/rss+xml;charset=utf-8");
+            PlanetManager planet = 
+                rreq.getRoller().getPlanetManager();
+            if (request.getParameter("group") != null) 
+            {
+                context.put("group", 
+                        planet.getGroup(request.getParameter("group")));
+            }
+            context.put("planet", planet);
+            context.put("date", new Date());
+            context.put("utilities", new Utilities());
+            return getTemplate("planetrss.vm");
+        }
+        catch (Exception e)
+        {
+            mLogger.error("ERROR in PlanetFeedServlet", e);
+        }
+        return null;
+    }
+
+    //------------------------------------------------------------------------
+    /**
+     * Handle error in Velocity processing.
+     */
+    protected void error( HttpServletRequest req, HttpServletResponse res,
+        Exception e) throws ServletException, IOException
+    {
+        mLogger.warn("ERROR in PlanetFeedServlet",e);
+    }
+}
+



Mime
View raw message