roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r209354 - in /incubator/roller/trunk/src/org/roller: pojos/ presentation/ presentation/velocity/ presentation/weblog/tags/
Date Tue, 05 Jul 2005 23:52:26 GMT
Author: agilliland
Date: Tue Jul  5 16:52:24 2005
New Revision: 209354

URL: http://svn.apache.org/viewcvs?rev=209354&view=rev
Log:
Added a set of new WebsiteData.getPageByXXX() methods for returning
Template objects which are sensitive to the state of a Website object.

Many classes were modified to make use of the new website
centric getPage...() methods in support of the new theme management code.


Modified:
    incubator/roller/trunk/src/org/roller/pojos/WebsiteData.java
    incubator/roller/trunk/src/org/roller/presentation/RollerRequest.java
    incubator/roller/trunk/src/org/roller/presentation/velocity/BasePageServlet.java
    incubator/roller/trunk/src/org/roller/presentation/velocity/CommentServlet.java
    incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java
    incubator/roller/trunk/src/org/roller/presentation/velocity/Macros.java
    incubator/roller/trunk/src/org/roller/presentation/velocity/PageModel.java
    incubator/roller/trunk/src/org/roller/presentation/weblog/tags/ViewWeblogEntriesTag.java

Modified: incubator/roller/trunk/src/org/roller/pojos/WebsiteData.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/pojos/WebsiteData.java?rev=209354&r1=209353&r2=209354&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/pojos/WebsiteData.java (original)
+++ incubator/roller/trunk/src/org/roller/pojos/WebsiteData.java Tue Jul  5 16:52:24 2005
@@ -1,13 +1,25 @@
 package org.roller.pojos;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
 import org.apache.commons.lang.StringUtils;
 import org.roller.RollerException;
 import org.roller.model.Roller;
 import org.roller.model.RollerFactory;
 import org.roller.util.PojoUtil;
-
 import java.util.Locale;
+import java.util.Map;
 import java.util.TimeZone;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.ThemeNotFoundException;
+import org.roller.model.Template;
+import org.roller.model.ThemeManager;
+import org.roller.model.UserManager;
+
+
 /**
  * A user's website is a weweblog, newsfeed channels and bookmarks.
  * @author David M Johnson
@@ -21,6 +33,10 @@
     implements java.io.Serializable
 {
     static final long serialVersionUID = 206437645033737127L;
+    
+    private static Log mLogger = 
+        LogFactory.getFactory().getInstance(WebsiteData.class);
+    
     protected java.lang.String id;
     protected java.lang.String name;
     protected java.lang.String description;
@@ -84,6 +100,216 @@
         this.setData(otherData);
     }
 
+    
+    /**
+     * Lookup the default page for this website.
+     */
+    public Template getDefaultPage() throws RollerException {
+        
+        Template template = null;
+        
+        // first check if this user has selected a theme
+        // if so then return the themes Weblog template
+        if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
+            try {
+                ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
+                Theme usersTheme = themeMgr.getTheme(this.editorTheme);
+                
+                // this is a bit iffy :/
+                // we assume that all theme use "Weblog" for a default template
+                template = usersTheme.getTemplate("Weblog");
+                
+            } catch(ThemeNotFoundException tnfe) {
+                // i sure hope not!
+                mLogger.error(tnfe);
+            }
+        }
+        
+        // if we didn't get the Template from a theme then look in the db
+        if(template == null) {
+            UserManager userMgr = RollerFactory.getRoller().getUserManager();
+            template = userMgr.retrievePage(this.defaultPageId);
+        }
+        
+        if(template != null)
+            mLogger.debug("returning default template id ["+template.getId()+"]");
+        
+        return template;
+    }
+    
+    
+    /**
+     * Lookup a Template for this website by id.
+     */
+    public Template getPageById(String id) throws RollerException {
+        
+        if(id == null)
+            return null;
+        
+        Template template = null;
+        
+        // first check if this user has selected a theme
+        // if so then return the proper theme template
+        if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
+            
+            // we don't actually expect to get lookups for theme pages by id
+            // but we have to be thorough and check anyways
+            String[] split = id.split(":",  2);
+            
+            // only continue if this looks like a theme id
+            // and the theme name matches this users current theme
+            if(split.length == 2 && split[0].equals(this.editorTheme)) {
+                try {
+                    ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
+                    Theme usersTheme = themeMgr.getTheme(this.editorTheme);
+                    template = usersTheme.getTemplate(split[1]);
+                    
+                } catch(ThemeNotFoundException tnfe) {
+                    // i sure hope not!
+                    mLogger.error(tnfe);
+                }
+            }
+            
+        }
+        
+        // if we didn't get the Template from a theme then look in the db
+        if(template == null) {
+            UserManager userMgr = RollerFactory.getRoller().getUserManager();
+            template = userMgr.getPageByName(this, name);
+        }
+        
+        return template;
+    }
+    
+    
+    /**
+     * Lookup a Template for this website by name.
+     */
+    public Template getPageByName(String name) throws RollerException {
+        
+        if(name == null)
+            return null;
+        
+        mLogger.debug("looking up template ["+name+"]");
+        
+        Template template = null;
+        
+        // first check if this user has selected a theme
+        // if so then return the proper theme template
+        if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
+            
+            try {
+                ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
+                Theme usersTheme = themeMgr.getTheme(this.editorTheme);
+                template = usersTheme.getTemplate(name);
+
+            } catch(ThemeNotFoundException tnfe) {
+                // i sure hope not!
+                mLogger.error(tnfe);
+            }
+            
+        }
+        
+        // if we didn't get the Template from a theme then look in the db
+        if(template == null) {
+            UserManager userMgr = RollerFactory.getRoller().getUserManager();
+            template = userMgr.getPageByName(this, name);
+        }
+        
+        if(template != null)
+            mLogger.debug("returning template ["+template.getId()+"]");
+        
+        return template;
+    }
+    
+    
+    /**
+     * Lookup a template for this website by link.
+     */
+    public Template getPageByLink(String link) throws RollerException {
+        
+        if(link == null)
+            return null;
+        
+        mLogger.debug("looking up template ["+link+"]");
+        
+        Template template = null;
+        
+        // first check if this user has selected a theme
+        // if so then return the proper theme template
+        if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
+            
+            try {
+                ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
+                Theme usersTheme = themeMgr.getTheme(this.editorTheme);
+                template = usersTheme.getTemplateByLink(link);
+
+            } catch(ThemeNotFoundException tnfe) {
+                // i sure hope not!
+                mLogger.error(tnfe);
+            }
+            
+        }
+        
+        // if we didn't get the Template from a theme then look in the db
+        if(template == null) {
+            UserManager userMgr = RollerFactory.getRoller().getUserManager();
+            template = userMgr.getPageByLink(this, link);
+        }
+        
+        if(template != null)
+            mLogger.debug("returning template ["+template.getId()+"]");
+        
+        return template;
+    }
+    
+    
+    /**
+     * Get a list of all pages that are part of this website.
+     */
+    public List getPages() {
+        
+        Map pages = new HashMap();
+        
+        // first get the pages from the db
+        try {
+            Template template = null;
+            UserManager userMgr = RollerFactory.getRoller().getUserManager();
+            Iterator dbPages = userMgr.getPages(this).iterator();
+            while(dbPages.hasNext()) {
+                template = (Template) dbPages.next();
+                pages.put(template.getName(), template);
+            }
+        } catch(Exception e) {
+            // db error
+            mLogger.error(e);
+        }
+        
+            
+        // now get theme pages if needed and put them in place of db pages
+        if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
+            try {
+                Template template = null;
+                ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
+                Theme usersTheme = themeMgr.getTheme(this.editorTheme);
+                Iterator themePages = usersTheme.getTemplates().iterator();
+                while(themePages.hasNext()) {
+                    template = (Template) themePages.next();
+                    
+                    // note that this will put theme pages over custom
+                    // pages in the pages list, which is what we want
+                    pages.put(template.getName(), template);
+                }
+            } catch(Exception e) {
+                // how??
+                mLogger.error(e);
+            }
+        }
+        
+        return new ArrayList(pages.values());
+    }
+    
+    
     /**
      * Id of the Website.
      * @ejb:persistent-field

Modified: incubator/roller/trunk/src/org/roller/presentation/RollerRequest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/RollerRequest.java?rev=209354&r1=209353&r2=209354&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/RollerRequest.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/RollerRequest.java Tue Jul  5 16:52:24
2005
@@ -18,16 +18,16 @@
 import org.roller.config.RollerRuntimeConfig;
 import org.roller.model.ParsedRequest;
 import org.roller.model.Roller;
+import org.roller.model.RollerFactory;
+import org.roller.model.Template;
 import org.roller.model.UserManager;
 import org.roller.model.WeblogManager;
 import org.roller.pojos.BookmarkData;
 import org.roller.pojos.FolderData;
-import org.roller.pojos.WeblogTemplate;
 import org.roller.pojos.UserData;
 import org.roller.pojos.WeblogCategoryData;
 import org.roller.pojos.WeblogEntryData;
 import org.roller.pojos.WebsiteData;
-import org.roller.pojos.PingTargetData;
 import org.roller.util.DateUtil;
 import org.roller.util.Utilities;
  
@@ -65,13 +65,14 @@
     private String             mDateString = null;
     private String             mPathInfo = null; 
     private String             mPageLink = null;
-    private WeblogTemplate           mPage;
+    private Template           mPage;
     private PageContext        mPageContext = null;
     private HttpServletRequest mRequest = null;
     private WebsiteData        mWebsite;
     private WeblogEntryData    mWeblogEntry;
     private WeblogCategoryData mWeblogCategory;
     private boolean           mIsDateSpecified = false;
+    private boolean            mIsPreview = false;
         
     private static ThreadLocal mRollerRequestTLS = new ThreadLocal();
     
@@ -153,6 +154,11 @@
             getRoller().setUser(currentUser);
         }
 
+        // check servlet path to see if this is a preview request
+        mLogger.debug("servlet path = "+mRequest.getServletPath());
+        if(mRequest.getServletPath().indexOf("preview") != -1)
+            this.mIsPreview = true;
+        
         // path info may be null, (e.g. on JSP error page)
         mPathInfo = mRequest.getPathInfo();
         mPathInfo = (mPathInfo!=null) ? mPathInfo : "";            
@@ -204,7 +210,7 @@
                     // we have the /username form of URL
                     mDate = getDate(true);
                     mDateString = DateUtil.format8chars(mDate);
-                    mPage = userMgr.retrievePage(mWebsite.getDefaultPageId());
+                    mPage = mWebsite.getDefaultPage();
                 }
                 else if ( pathInfo.length == 2 )
                 {
@@ -215,20 +221,20 @@
                         mDate = getDate(true);
                         mDateString = DateUtil.format8chars(mDate);
                         mPageLink = pathInfo[1];
-                        mPage = userMgr.getPageByLink(mWebsite, pathInfo[1]);
+                        mPage = mWebsite.getPageByLink(pathInfo[1]);
                     }
                     else
                     {
                         // we have the /username/datestring form of URL
                         mDateString = pathInfo[1];
-                        mPage = userMgr.retrievePage(mWebsite.getDefaultPageId());
+                        mPage = mWebsite.getDefaultPage();
                         mIsDateSpecified = true;
                     }               
                 }
                 else if ( pathInfo.length == 3 )
                 {
                     mPageLink = pathInfo[1];
-                    mPage = userMgr.getPageByLink(mWebsite, pathInfo[1]);
+                    mPage = mWebsite.getPageByLink(pathInfo[1]);
                     
                     mDate = parseDate(pathInfo[2]);
                     if ( mDate == null ) // pre-jdk1.4 --> || mDate.getYear() <= 70
)
@@ -259,7 +265,7 @@
                 {
                     // we have the /username/pagelink/datestring/anchor form of URL
                     mPageLink = pathInfo[1];
-                    mPage = userMgr.getPageByLink(mWebsite, pathInfo[1]);
+                    mPage = mWebsite.getPageByLink(pathInfo[1]);
                     
                     mDate = parseDate(pathInfo[2]);
                     mDateString = pathInfo[2];
@@ -312,16 +318,17 @@
             if ( pageId != null )
             {
                 mPage = userMgr.retrievePage(pageId);
-                
+                /*
                 // We can use page to find the user, if we don't have one yet
                 if ( mWebsite == null )
                 {
                     mWebsite = mPage.getWebsite();
-                }                    
+                }
+                 */                    
             }
             else if (mWebsite != null) 
             {
-                mPage = userMgr.retrievePage( mWebsite.getDefaultPageId() );
+                mPage = mWebsite.getDefaultPage();
             }
                                        
             // Look for day in request params 
@@ -446,13 +453,13 @@
         return mContext;
     }
 
-    //------------------------------------------------------------------------
-    /** Get Roller instance from */
+
     public Roller getRoller()
     {
-        return RollerContext.getRoller( mRequest );
+        return RollerFactory.getRoller();
     }
     
+    
     //------------------------------------------------------------------------
     /** Is mRequest's user the admin user? */
     public boolean isAdminUser() throws RollerException
@@ -740,7 +747,7 @@
      * Gets the WeblogTemplate specified by the request, or null.
      * @return WeblogTemplate
      */
-    public WeblogTemplate getPage()
+    public Template getPage()
     {
         if (mPage == null)
         {
@@ -763,7 +770,7 @@
     /**
      * Allow comment servlet to inject page that it has chosen.
      */
-    public void setPage(WeblogTemplate page) 
+    public void setPage(org.roller.model.Template page) 
     {
         mPage = page;
     }

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=209354&r1=209353&r2=209354&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 16:52:24 2005
@@ -1 +1 @@
-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.ParseErrorException;
import
org.apache.velocity.exception.ResourceNotFoundException;
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.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
 */
public abstract class BasePageServlet extends
VelocityServlet
{
    private static Log mLogger =
        LogFactory.getFactory().getInstance(BasePageServlet.class);
/**
	 *  <p>Sets servletContext for WebappResourceLoader.</p>
	 *
	 * @param config
servlet configuation
	 */
	public void init( ServletConfig config )
		throws ServletException
{
		super.init( config );
		WebappResourceLoader.setServletContext( getServletContext() );
}
    public Template handleRequest( HttpServletRequest request,
                        
          HttpServletResponse response,
                                   Context ctx ) throws
Exception
    {
        String pid = null;
        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 = rreq.getRoller().getUserManager();
            
            WebsiteData wd = null;
           if (request.getAttribute(RollerRequest.OWNING_USER) != null) {
               
UserData user = (UserData)
                    request.getAttribute(RollerRequest.OWNING_USER);
               wd = userMgr.getWebsite(user.getUserName());
            }
            else
           {
                wd = rreq.getWebsite();
            }
            
         
  // If request specified the page, then go with that
            WeblogTemplate pd = null;
           if (rreq.getPage() != null // RollerRequest does too much guess work
         
          && request.getAttribute(RollerRequest.OWNING_USER) == null)
           
{
                pd = rreq.getPage();
                pid = pd.getId();
            }
  
         // If page not available from request, then use website's default
            else
if (wd != null)
            {
                pd = userMgr.retrievePage(wd.getDefaultPageId());
               pid = pd.getId();
                rreq.setPage(pd); 
            }
       
    // Still no page ID, then we have a problem
            if ( pid == null )
          
 {
                throw new ResourceNotFoundException("Page not found");
            }
 
          
            outty = prepareForPageExecution(ctx, rreq, response, pd);
        }
       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;
   }

    //------------------------------------------------------------------------
    /**
    * Try to load user-specified Decorator (if specified).  Failing that
     * see if user
has a _decorator Page, if not check for a _decorator
     * in the Preview resource loader.
 Finally, if none of those can
     * be found fall back to the no-op decorator.
     * @param
object
     * @return
     */
    private Template findDecorator(String decoratorName, UserManager
userMgr, WebsiteData wd) 
        throws ResourceNotFoundException, ParseErrorException, RollerException,
Exception
    {
        Template decorator = null;
        WeblogTemplate decoratorPage =
null;
        String decoratorId = null;
        
        // check for user-specified decorator
       if (decoratorName != null)
        {    
            decoratorPage = userMgr.getPageByName(wd,
decoratorName);
            if (decoratorPage != null) 
            {
                decoratorId
= decoratorPage.getId();
            }
        }
        
        // if no user-specified
decorator try default page-name
        if (decoratorPage == null)
        {
            decoratorPage
= userMgr.getPageByName(wd, "_decorator");
            if (decoratorPage != null) 
      
     {
                decoratorId = decoratorPage.getId();
            }
            else
           {
                // could be in PreviewResourceLoader
                decoratorId
= "_decorator";
            }
        }

        // try loading Template
        if (decoratorId
!= null) 
        {
            try
            {
                decorator = getTemplate(decoratorId,
"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;
   }

    /** 
     * Prepare for page execution be setting content type, populating context,
    * and processing the page decorator if needed.
     */
    protected Template prepareForPageExecution(Context
ctx, RollerRequest rreq, 
        HttpServletResponse response, WeblogTemplate pd) throws
Exception
    {                    
        Template outty = null;
        UserManager userMgr
= rreq.getRoller().getUserManager();
        WebsiteData wd = pd.getWebsite();
        
 
      // if page has an extension - use that to set the contentType
        String pageLink
= pd.getLink();
        String mimeType = getServletConfig().getServletContext().getMimeType(pageLink);
       if(mimeType != null) {
            // we found a match ... set the content type
  
         response.setContentType(mimeType);
        }
        
        /* old way ... not
as flexible -- Allen G
        int period = pd.getLink().indexOf('.');
        if (period
> -1) 
        {
            String extension = pd.getLink().substring(period+1);
    
       if ("js".equals(extension)) 
            {
                extension = "javascript";
           }
            response.setContentType("text/" + extension);
        }
        */
   
        // Made it this far, populate the Context
        ContextLoader.setupContext(
ctx, rreq, response );

        // Get the page
        outty =  getTemplate( pd.getId(),
"UTF-8" );

        /**
         * User can define a Decorator Template.
         */
    
   if (wd != 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((String)ctx.get("decorator"), userMgr, wd);                
        }
     
  return outty;
    }
    
    //------------------------------------------------------------------------
   /**
     * 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;
        }
    }
}
\ No newline at end of file

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/CommentServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/CommentServlet.java?rev=209354&r1=209353&r2=209354&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/CommentServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/CommentServlet.java Tue Jul
 5 16:52:24 2005
@@ -110,12 +110,12 @@
             WebsiteData website = rreq.getWebsite();
                 
             // Request specifies popup
-            WeblogTemplate page = null;
+            org.roller.model.Template page = null;
             Exception pageException = null;
             try 
             {
                 // Does user have a popupcomments page?
-                page = userMgr.getPageByName(website, "_popupcomments");
+                page = website.getPageByName("_popupcomments");
             }
             catch(Exception e )
             {
@@ -444,7 +444,7 @@
             commentURL.append("/comments/");
             commentURL.append(rreq.getUser().getUserName());
             
-            WeblogTemplate page = rreq.getPage();
+            org.roller.model.Template page = rreq.getPage();
             if (page == null)
             {
                 commentURL.append("?entry=");

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java?rev=209354&r1=209353&r2=209354&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java Tue Jul
 5 16:52:24 2005
@@ -27,8 +27,8 @@
 import org.roller.config.RollerRuntimeConfig;
 import org.roller.model.Roller;
 import org.roller.model.RollerFactory;
+import org.roller.model.Template;
 import org.roller.pojos.CommentData;
-import org.roller.pojos.WeblogTemplate;
 import org.roller.pojos.RollerPropertyData;
 import org.roller.pojos.UserData;
 import org.roller.pojos.WeblogEntryData;
@@ -38,6 +38,7 @@
 import org.roller.presentation.RollerRequest;
 import org.roller.presentation.RollerSession;
 import org.roller.presentation.newsfeeds.NewsfeedCache;
+import org.roller.presentation.velocity.wrappers.TemplateWrapper;
 import org.roller.presentation.weblog.formbeans.CommentFormEx;
 import org.roller.util.RegexUtil;
 import org.roller.util.StringUtils;
@@ -161,44 +162,25 @@
     {
         // if there is an "_entry" page, only load it once
         WebsiteData website = rreq.getRoller().getUserManager().getWebsite(userName);
-        PageModel pageModel = (PageModel)ctx.get("pageModel");
-        if (website != null && pageModel != null) 
+        //PageModel pageModel = (PageModel)ctx.get("pageModel");
+        if (website != null) 
         {
             /* alternative display pages - customization */
-            WeblogTemplate entryPage = pageModel.getUsersPageByName(website, "_entry");
+            Template entryPage = website.getPageByName("_entry");
             if (entryPage != null)
             {
-                ctx.put("entryPage", entryPage);
+                ctx.put("entryPage", new TemplateWrapper(entryPage));
             }
-            WeblogTemplate descPage = pageModel.getUsersPageByName(website, "_desc");
+            Template descPage = website.getPageByName("_desc");
             if (descPage != null)
             {
-                ctx.put("descPage", descPage);
+                ctx.put("descPage", new TemplateWrapper(descPage));
             }
         }
     }
 
     private static String figureResourcePath( RollerRequest rreq )
-    {
-        /*  old way -- Allen G
-        HttpServletRequest request = rreq.getRequest();
-        RollerContext rCtx = RollerContext.getRollerContext( request );
-        RollerConfigData  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();
-        */
-        
+    {   
         String uploadurl = null;
         try {
             uploadurl = RollerFactory.getRoller().getFileManager().getUploadUrl();
@@ -240,7 +222,7 @@
         
         // Make sure comment form object is available in context
         CommentFormEx commentForm = 
-            (CommentFormEx)request.getAttribute("commentForm");
+                (CommentFormEx) request.getAttribute("commentForm");
         if ( commentForm == null )
         {
             commentForm = new CommentFormEx();
@@ -394,7 +376,7 @@
         // the Entry Day link.
         ctx.put("plainFormat", "yyyyMMdd");
 
-        ctx.put("page",            rreq.getPage() );
+        ctx.put("page",            new TemplateWrapper(rreq.getPage()));
         ctx.put("utilities",       new Utilities() );
         ctx.put("stringUtils",     new StringUtils() );        
         ctx.put("rollerVersion",   rollerCtx.getRollerVersion() );

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/Macros.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/Macros.java?rev=209354&r1=209353&r2=209354&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/Macros.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/Macros.java Tue Jul  5 16:52:24
2005
@@ -601,11 +601,12 @@
                        
             // Get included page template 
             RollerRequest rreq = RollerRequest.getRollerRequest(
-                (HttpServletRequest)mPageContext.getRequest());                
-            UserManager userMgr = rreq.getRoller().getUserManager();
+                (HttpServletRequest)mPageContext.getRequest()); 
+            WebsiteData website = rreq.getWebsite();
+            //UserManager userMgr = rreq.getRoller().getUserManager();
+            
+            org.roller.model.Template pd = website.getPageByName(pageName);
             
-            WeblogTemplate pd = userMgr.getPageByName( 
-                rreq.getWebsite(), pageName );
             Template vtemplate = null;
             if (pd != null)
             {
@@ -932,7 +933,7 @@
      */
     public String showPageName()
     {
-        WeblogTemplate pd = null;
+        org.roller.model.Template pd = null;
         RollerRequest rreq = getRollerRequest();
         try
         {
@@ -951,7 +952,7 @@
      */
     public String showPageDescription()
     {
-        WeblogTemplate pd = null;
+        org.roller.model.Template pd = null;
         RollerRequest rreq = getRollerRequest();
         try
         {
@@ -971,7 +972,7 @@
      */
     public String showPageUpdateTime()
     {
-        WeblogTemplate pd = null;
+        org.roller.model.Template pd = null;
         RollerRequest rreq = getRollerRequest();
         try
         {
@@ -981,8 +982,8 @@
         {
             return "ERROR finding page in request: " + e.toString();
         }
-        if (pd.getUpdateTime() == null) return "";
-        return pd.getUpdateTime().toString();
+        if (pd.getLastModified() == null) return "";
+        return pd.getLastModified().toString();
     }
 
     //------------------------------------------------------------------------

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/PageModel.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/PageModel.java?rev=209354&r1=209353&r2=209354&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/PageModel.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/PageModel.java Tue Jul  5
16:52:24 2005
@@ -15,6 +15,7 @@
 import org.roller.config.RollerRuntimeConfig;
 import org.roller.model.BookmarkManager;
 import org.roller.model.RefererManager;
+import org.roller.model.Template;
 import org.roller.model.UserManager;
 import org.roller.model.WeblogManager;
 import org.roller.pojos.BookmarkComparator;
@@ -26,6 +27,7 @@
 import org.roller.pojos.WeblogEntryData;
 import org.roller.pojos.WebsiteData;
 import org.roller.presentation.RollerRequest;
+import org.roller.presentation.velocity.wrappers.TemplateWrapper;
 import org.roller.util.StringUtils;
 
 /**
@@ -46,10 +48,11 @@
     private UserManager          mUserMgr = null;
     private RefererManager       mRefererMgr = null;
 
-    private Map                mCategories = new HashMap();
+    private Map                  mCategories = new HashMap();
     private HashMap              mPageMap = new HashMap();
     private RollerRequest        mRollerReq = null;
     private String               mUsername = null;
+    private WebsiteData          mWebsite = null;
     
     private WeblogEntryData      mNextEntry = null;
     private WeblogEntryData      mPreviousEntry = null;
@@ -99,14 +102,18 @@
              */
             if ( mUsername != null )
             {
+                // if we have website from RollerRequest, use it
+                mWebsite = rreq.getWebsite();
+                if(mWebsite == null)
+                    mWebsite = mUserMgr.getWebsite(user.getUserName());
+                
                 // Get the pages, put into context & load map
-                WebsiteData website = mUserMgr.getWebsite(user.getUserName());
-                List pages = mUserMgr.getPages(website);
+                List pages = mWebsite.getPages();
                 Iterator pageIter = pages.iterator();
                 while (pageIter.hasNext())
                 {
-                    WeblogTemplate page = (WeblogTemplate) pageIter.next();
-                    mPageMap.put(page.getName(), page);
+                    Template page = (Template) pageIter.next();
+                    mPageMap.put(page.getName(), new TemplateWrapper(page));
                 }
             }
             
@@ -136,8 +143,7 @@
         Collection tops = null;
         try
         {
-         tops= mBookmarkMgr.getRootFolder(
-                    mUserMgr.getWebsite(mUsername)).getFolders();
+         tops= mBookmarkMgr.getRootFolder(mWebsite).getFolders();
         }
         catch (RollerException e)
         {
@@ -202,7 +208,7 @@
         try
         {
             return mBookmarkMgr.getFolder(
-                mUserMgr.getWebsite(mUsername), folderPath);
+                mWebsite, folderPath);
         }
         catch (RollerException e)
         {
@@ -214,9 +220,9 @@
     //------------------------------------------------------------------------
     
     /** Encapsulates UserManager.getPageByName() */
-    public WeblogTemplate getUsersPageByName(WebsiteData website, String pageName)
+    public Template getUsersPageByName(WebsiteData website, String pageName)
     {
-        WeblogTemplate page = null;
+        Template page = null;
         try
         {
             if (website == null) 
@@ -225,7 +231,7 @@
             if (pageName == null) 
                 throw new NullPointerException("pageName is null");
                 
-            page = mUserMgr.getPageByName(website, pageName);
+            page = website.getPageByName(pageName);
         }
         catch (NullPointerException npe)
         {
@@ -251,15 +257,20 @@
     /** Encapsulates UserManager.getPageByName() */
     public String getPageIdByName(String pageName)
     {
-        WeblogTemplate pd = (WeblogTemplate)mPageMap.get(pageName);
-        if ( pd != null ) 
-        {
-            return pd.getId();
-        }
-        else
-        {
-            return null;
+        mLogger.debug("looking up page ["+pageName+"]");
+        
+        String template_id = null;
+        
+        try {
+            Template pd = mWebsite.getPageByName(pageName);
+            template_id = pd.getId();
+        } catch(Exception e) {
+            mLogger.error(e);
         }
+        
+        mLogger.debug("returning template id ["+template_id+"]");
+        
+        return template_id;
     }
     
     //------------------------------------------------------------------------

Modified: incubator/roller/trunk/src/org/roller/presentation/weblog/tags/ViewWeblogEntriesTag.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/weblog/tags/ViewWeblogEntriesTag.java?rev=209354&r1=209353&r2=209354&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/weblog/tags/ViewWeblogEntriesTag.java
(original)
+++ incubator/roller/trunk/src/org/roller/presentation/weblog/tags/ViewWeblogEntriesTag.java
Tue Jul  5 16:52:24 2005
@@ -111,9 +111,7 @@
             String pid = null; 
             if ( mDayTemplate != null )
             {
-                WeblogTemplate page =
-                    rreq.getRoller().getUserManager().getPageByLink(
-                        website, mDayTemplate );
+                org.roller.model.Template page = website.getPageByLink(mDayTemplate);
                 if (page != null)
                 {
                     pid = page.getId();



Mime
View raw message