You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2005/11/17 19:52:33 UTC

svn commit: r345303 - in /incubator/roller/trunk: src/org/roller/presentation/velocity/ src/org/roller/presentation/weblog/actions/ web/weblog/

Author: snoopdave
Date: Thu Nov 17 10:52:26 2005
New Revision: 345303

URL: http://svn.apache.org/viewcvs?rev=345303&view=rev
Log:
Instantiate plugins on every request to resolve ROL-893 topic tag uneliable

Modified:
    incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java
    incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java
    incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java
    incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryPageModel.java
    incubator/roller/trunk/web/weblog/WeblogEdit.jsp

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=345303&r1=345302&r2=345303&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java Thu Nov 17 10:52:26 2005
@@ -5,7 +5,7 @@
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
-import java.util.List;
+import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
 import java.util.TimeZone;
@@ -56,8 +56,8 @@
 {   
     private RollerRequest mRollerReq = null;
     
-    // List of PagePlugins for "transforming" WeblogEntries
-    static List mPagePlugins = new ArrayList();
+    // Plugin classes keyed by plugin name
+    static Map mPagePlugins = new HashMap();
     
     private static Log mLogger = 
        LogFactory.getFactory().getInstance(ContextLoader.class);
@@ -469,12 +469,10 @@
     //------------------------------------------------------------------------
 
     /**
-     * Initialize PagePlugins declared in web.xml.  By using the full class
-     * name we also allow for the implementation of "external" Plugins
-     * (maybe even packaged seperately).  These classes are then later 
-     * instantiated by PageHelper.
-     * 
-     * @param mContext
+     * Initialize PagePlugins declared in web.xml, called once by RollerContext.
+     * By using the full class name we also allow for the implementation of 
+     * "external" Plugins (maybe even packaged seperately). These classes are 
+     * then later instantiated by PageHelper.
      */
     public static void initializePagePlugins(ServletContext mContext)
     {
@@ -494,7 +492,8 @@
                     Class pluginClass = Class.forName(plugins[i]);
                     if (isPagePlugin(pluginClass))
                     {
-                        mPagePlugins.add(pluginClass.newInstance());
+                        PagePlugin plugin = (PagePlugin)pluginClass.newInstance();
+                        mPagePlugins.put(plugin.getName(), pluginClass);
                     }
                     else
                     {
@@ -537,7 +536,7 @@
         return (mPagePlugins != null && mPagePlugins.size() > 0);
     }
     
-    public static List getPagePlugins()
+    public static Map getPagePluginClasses()
     {
         return mPagePlugins;
     }

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java?rev=345303&r1=345302&r2=345303&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java Thu Nov 17 10:52:26 2005
@@ -1,11 +1,12 @@
 package org.roller.presentation.velocity;
 import java.net.MalformedURLException;
-import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.Vector;
 
 import javax.servlet.http.HttpServletRequest;
@@ -50,8 +51,8 @@
     private Context              mVelocityContext = null;
     private PageContext          mPageContext = null;
     private HttpServletResponse  mResponse = null;     
-    private RollerRequest        mRollerReq = null;
-    private Collection           mPagePlugins = new ArrayList();
+    private RollerRequest        mRollerReq = null;  
+    private Map                  mPagePlugins = new HashMap();  // Plugins keyed by name   
     private boolean              mSkipFlag = false;
     private WebsiteData          mWebsite = null;
     
@@ -96,7 +97,8 @@
 
     //------------------------------------------------------------------------
     /**
-     * Return a PageHelper with a new VelocityContext.
+     * Return a PageHelper with a new VelocityContext, 
+     * added to support the ApplyPlugins JSP tag.
      */
     public static PageHelper createPageHelper(
         HttpServletRequest request, HttpServletResponse response)
@@ -104,7 +106,7 @@
         Context ctx = (Context)(new VelocityContext());
         RollerRequest rreq = RollerRequest.getRollerRequest(request);
         PageHelper pageHelper = new PageHelper(rreq, response, ctx);
-        pageHelper.initializePlugins(ContextLoader.getPagePlugins());
+        pageHelper.initializePlugins(ContextLoader.getPagePluginClasses());
 
         return pageHelper;
     }
@@ -113,18 +115,19 @@
     /**
      * Create individual instances of the PagePlugins for use by this PageHelper.
      */
-    protected void initializePlugins(Collection pluginClasses) 
+    protected void initializePlugins(Map pluginClasses) 
     {
-        Iterator it = pluginClasses.iterator();
+        Iterator it = pluginClasses.values().iterator();
         while (it.hasNext()) 
         {
             try
             {
-                PagePlugin plugin = (PagePlugin)it.next();
+                Class pluginClass = (Class)it.next();
+                PagePlugin plugin = (PagePlugin)pluginClass.newInstance();
                 plugin.init(mRollerReq, mVelocityContext);
-                mPagePlugins.add(plugin);
+                mPagePlugins.put(plugin.getName(), plugin);
             }
-            catch (RollerException e)
+            catch (Exception e)
             {
                 mLogger.warn("Unable to init() PagePlugin: ", e    );
             }
@@ -465,34 +468,7 @@
         }
         return returnUrl;
     }
-    
-    /**
-     * Pass the String through any PagePlugins that have been
-     * assigned to the PageHelper.
-     * 
-     * @param str
-     * @return
-     */
-    public String renderPlugins(String str)
-    {
-        mLogger.debug("Rendering page plugins on String");
-        
-        if (mPagePlugins != null)
-        {
-            Iterator iter = mPagePlugins.iterator();
-            PagePlugin plugin = null;
-            while (iter.hasNext())
-            {
-                plugin = (PagePlugin) iter.next();
-                
-                mLogger.debug("applying plugin - ");
-                str = plugin.render(str);
-            }
-        }
         
-        return str;
-    }
-    
     /**
      * Pass the String through any PagePlugins that have been
      * assigned to the PageHelper, as selected by the Entry.
@@ -525,13 +501,13 @@
                 // now loop over mPagePlugins, matching
                 // against Entry plugins (by name):
                 // where a match is found render Plugin.
-                Iterator iter = mPagePlugins.iterator();
-                PagePlugin pagePlugin = null;
+                Iterator iter = mPagePlugins.keySet().iterator();
                 while (iter.hasNext())
                 {
-                    pagePlugin = (PagePlugin)iter.next();
-                    if (entryPlugins.contains(pagePlugin.getName()))
+                    String key = (String)iter.next();
+                    if (entryPlugins.contains(key))
                     {
+                        PagePlugin pagePlugin = (PagePlugin)mPagePlugins.get(key);
                         copy.setText((pagePlugin).render(copy, mSkipFlag));
                     }
                 }

Modified: incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java?rev=345303&r1=345302&r2=345303&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java Thu Nov 17 10:52:26 2005
@@ -297,7 +297,7 @@
                 mLogger.debug("setting update time now");
                 form.setUpdateTime(new Timestamp(new Date().getTime()));
                 
-                if("PUBLISHED".equals(form.getStatus()) &&
+                if ("PUBLISHED".equals(form.getStatus()) &&
                         "0/0/0".equals(form.getDateString())) {
                     mLogger.debug("setting pubtime now");
                     

Modified: incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryPageModel.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryPageModel.java?rev=345303&r1=345302&r2=345303&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryPageModel.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryPageModel.java Thu Nov 17 10:52:26 2005
@@ -31,6 +31,10 @@
 import org.roller.util.StringUtils;
 
 import com.swabunga.spell.event.SpellCheckEvent;
+import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.presentation.velocity.PagePlugin;
 
 /**
  * All data needed to render the edit-weblog page.
@@ -38,6 +42,9 @@
  */
 public class WeblogEntryPageModel extends BasePageModel
 {
+    private static Log logger = 
+       LogFactory.getFactory().getInstance(WeblogEntryPageModel.class);
+        
     private RollerRequest rollerRequest = null;
     private PageMode mode = null;
     private ArrayList words = null;
@@ -190,6 +197,31 @@
     public boolean getHasPagePlugins()
     {
         return ContextLoader.hasPlugins();
+    }
+    
+    public List getPagePlugins() 
+    {
+        List list = new ArrayList();
+        if (getHasPagePlugins()) 
+        {
+            Map pluginClasses = ContextLoader.getPagePluginClasses();
+            Iterator it = pluginClasses.values().iterator();
+            while (it.hasNext()) 
+            {
+                try
+                {
+                    Class pluginClass = (Class)it.next();
+                    PagePlugin plugin = (PagePlugin)pluginClass.newInstance();
+                    // no need to init plugins, we're not gonna run them
+                    list.add(plugin);
+                }
+                catch (Exception e)
+                {
+                    logger.warn("Unable to create a PagePlugin: ", e);
+                }
+            }  
+        }
+        return list;
     }
 
     public String getEditorPage()

Modified: incubator/roller/trunk/web/weblog/WeblogEdit.jsp
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/web/weblog/WeblogEdit.jsp?rev=345303&r1=345302&r2=345303&view=diff
==============================================================================
--- incubator/roller/trunk/web/weblog/WeblogEdit.jsp (original)
+++ incubator/roller/trunk/web/weblog/WeblogEdit.jsp Thu Nov 17 10:52:26 2005
@@ -263,7 +263,7 @@
       </div>
       <div id="pluginControl" class="miscControl" style="display:none">
         <logic:iterate id="plugin" type="org.roller.presentation.velocity.PagePlugin"
-            collection="<%= org.roller.presentation.velocity.ContextLoader.getPagePlugins() %>">
+            collection="<%= model.getPagePlugins() %>">
             <html:multibox property="pluginsArray"
                  title="<%= plugin.getName() %>" value="<%= plugin.getName() %>"
                  styleId="<%= plugin.getName() %>"/></input>



Re: website settings page broken ... was Re: svn commit: r345303 - in /incubator/roller/trunk: src/org/roller/presentation/velocity/ src/org/roller/presentation/weblog/actions/ web/weblog/

Posted by Dave Johnson <da...@rollerweblogger.org>.
On Nov 18, 2005, at 5:43 PM, Allen Gilliland wrote:
> yeah, jsp compilation would definitely be a handy tool.
>
> I noticed another slight problem with this fix, it now displays the 
> plugins in a randomly ordered list.  We should probably sort that 
> list.  The other tough part is that the label on the left suggests 
> that plugins are, "applied in the listed order".  I suppose that can't 
> really be considered true anymore?

That's definitely a bug. I'll make sure the original order is preserved.

- Dave


Re: website settings page broken ... was Re: svn commit: r345303 - in /incubator/roller/trunk: src/org/roller/presentation/velocity/ src/org/roller/presentation/weblog/actions/ web/weblog/

Posted by Allen Gilliland <Al...@Sun.COM>.
yeah, jsp compilation would definitely be a handy tool.

I noticed another slight problem with this fix, it now displays the plugins in a randomly ordered list.  We should probably sort that list.  The other tough part is that the label on the left suggests that plugins are, "applied in the listed order".  I suppose that can't really be considered true anymore?

-- Allen


On Fri, 2005-11-18 at 11:01, Dave Johnson wrote:
> Thanks Allen. I just committed a fix. If I had configured JSP  
> compilation, I would have caught that one.
> 
> - Dave
> 
> 
> On Nov 18, 2005, at 12:44 PM, Allen Gilliland wrote:
> 
> > this commit broke the website settings page.
> >
> > -- Allen
> >
> >
> > On Thu, 2005-11-17 at 10:52, snoopdave@apache.org wrote:
> >> Author: snoopdave
> >> Date: Thu Nov 17 10:52:26 2005
> >> New Revision: 345303
> >>
> >> URL: http://svn.apache.org/viewcvs?rev=345303&view=rev
> >> Log:
> >> Instantiate plugins on every request to resolve ROL-893 topic tag  
> >> uneliable
> >>
> >> Modified:
> >>      
> >> incubator/roller/trunk/src/org/roller/presentation/velocity/ 
> >> ContextLoader.java
> >>      
> >> incubator/roller/trunk/src/org/roller/presentation/velocity/ 
> >> PageHelper.java
> >>      
> >> incubator/roller/trunk/src/org/roller/presentation/weblog/actions/ 
> >> WeblogEntryFormAction.java
> >>      
> >> incubator/roller/trunk/src/org/roller/presentation/weblog/actions/ 
> >> WeblogEntryPageModel.java
> >>     incubator/roller/trunk/web/weblog/WeblogEdit.jsp
> >>
> >> ...
> 


Re: website settings page broken ... was Re: svn commit: r345303 - in /incubator/roller/trunk: src/org/roller/presentation/velocity/ src/org/roller/presentation/weblog/actions/ web/weblog/

Posted by Dave Johnson <da...@rollerweblogger.org>.
Thanks Allen. I just committed a fix. If I had configured JSP  
compilation, I would have caught that one.

- Dave


On Nov 18, 2005, at 12:44 PM, Allen Gilliland wrote:

> this commit broke the website settings page.
>
> -- Allen
>
>
> On Thu, 2005-11-17 at 10:52, snoopdave@apache.org wrote:
>> Author: snoopdave
>> Date: Thu Nov 17 10:52:26 2005
>> New Revision: 345303
>>
>> URL: http://svn.apache.org/viewcvs?rev=345303&view=rev
>> Log:
>> Instantiate plugins on every request to resolve ROL-893 topic tag  
>> uneliable
>>
>> Modified:
>>      
>> incubator/roller/trunk/src/org/roller/presentation/velocity/ 
>> ContextLoader.java
>>      
>> incubator/roller/trunk/src/org/roller/presentation/velocity/ 
>> PageHelper.java
>>      
>> incubator/roller/trunk/src/org/roller/presentation/weblog/actions/ 
>> WeblogEntryFormAction.java
>>      
>> incubator/roller/trunk/src/org/roller/presentation/weblog/actions/ 
>> WeblogEntryPageModel.java
>>     incubator/roller/trunk/web/weblog/WeblogEdit.jsp
>>
>> ...


Re: website settings page broken ... was Re: svn commit: r345303 - in /incubator/roller/trunk: src/org/roller/presentation/velocity/ src/org/roller/presentation/weblog/actions/ web/weblog/

Posted by Dave Johnson <da...@rollerweblogger.org>.
Thanks Allen. I just committed a fix. If I had configured JSP  
compilation, I would have caught that one.

- Dave


On Nov 18, 2005, at 12:44 PM, Allen Gilliland wrote:

> this commit broke the website settings page.
>
> -- Allen
>
>
> On Thu, 2005-11-17 at 10:52, snoopdave@apache.org wrote:
>> Author: snoopdave
>> Date: Thu Nov 17 10:52:26 2005
>> New Revision: 345303
>>
>> URL: http://svn.apache.org/viewcvs?rev=345303&view=rev
>> Log:
>> Instantiate plugins on every request to resolve ROL-893 topic tag  
>> uneliable
>>
>> Modified:
>>      
>> incubator/roller/trunk/src/org/roller/presentation/velocity/ 
>> ContextLoader.java
>>      
>> incubator/roller/trunk/src/org/roller/presentation/velocity/ 
>> PageHelper.java
>>      
>> incubator/roller/trunk/src/org/roller/presentation/weblog/actions/ 
>> WeblogEntryFormAction.java
>>      
>> incubator/roller/trunk/src/org/roller/presentation/weblog/actions/ 
>> WeblogEntryPageModel.java
>>     incubator/roller/trunk/web/weblog/WeblogEdit.jsp
>>
>> ...


website settings page broken ... was Re: svn commit: r345303 - in /incubator/roller/trunk: src/org/roller/presentation/velocity/ src/org/roller/presentation/weblog/actions/ web/weblog/

Posted by Allen Gilliland <Al...@Sun.COM>.
this commit broke the website settings page.

-- Allen


On Thu, 2005-11-17 at 10:52, snoopdave@apache.org wrote:
> Author: snoopdave
> Date: Thu Nov 17 10:52:26 2005
> New Revision: 345303
> 
> URL: http://svn.apache.org/viewcvs?rev=345303&view=rev
> Log:
> Instantiate plugins on every request to resolve ROL-893 topic tag uneliable
> 
> Modified:
>     incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java
>     incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java
>     incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java
>     incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryPageModel.java
>     incubator/roller/trunk/web/weblog/WeblogEdit.jsp
> 
> 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=345303&r1=345302&r2=345303&view=diff
> ==============================================================================
> --- incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java (original)
> +++ incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java Thu Nov 17 10:52:26 2005
> @@ -5,7 +5,7 @@
>  import java.text.SimpleDateFormat;
>  import java.util.ArrayList;
>  import java.util.Date;
> -import java.util.List;
> +import java.util.HashMap;
>  import java.util.Locale;
>  import java.util.Map;
>  import java.util.TimeZone;
> @@ -56,8 +56,8 @@
>  {   
>      private RollerRequest mRollerReq = null;
>      
> -    // List of PagePlugins for "transforming" WeblogEntries
> -    static List mPagePlugins = new ArrayList();
> +    // Plugin classes keyed by plugin name
> +    static Map mPagePlugins = new HashMap();
>      
>      private static Log mLogger = 
>         LogFactory.getFactory().getInstance(ContextLoader.class);
> @@ -469,12 +469,10 @@
>      //------------------------------------------------------------------------
>  
>      /**
> -     * Initialize PagePlugins declared in web.xml.  By using the full class
> -     * name we also allow for the implementation of "external" Plugins
> -     * (maybe even packaged seperately).  These classes are then later 
> -     * instantiated by PageHelper.
> -     * 
> -     * @param mContext
> +     * Initialize PagePlugins declared in web.xml, called once by RollerContext.
> +     * By using the full class name we also allow for the implementation of 
> +     * "external" Plugins (maybe even packaged seperately). These classes are 
> +     * then later instantiated by PageHelper.
>       */
>      public static void initializePagePlugins(ServletContext mContext)
>      {
> @@ -494,7 +492,8 @@
>                      Class pluginClass = Class.forName(plugins[i]);
>                      if (isPagePlugin(pluginClass))
>                      {
> -                        mPagePlugins.add(pluginClass.newInstance());
> +                        PagePlugin plugin = (PagePlugin)pluginClass.newInstance();
> +                        mPagePlugins.put(plugin.getName(), pluginClass);
>                      }
>                      else
>                      {
> @@ -537,7 +536,7 @@
>          return (mPagePlugins != null && mPagePlugins.size() > 0);
>      }
>      
> -    public static List getPagePlugins()
> +    public static Map getPagePluginClasses()
>      {
>          return mPagePlugins;
>      }
> 
> Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java
> URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java?rev=345303&r1=345302&r2=345303&view=diff
> ==============================================================================
> --- incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java (original)
> +++ incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java Thu Nov 17 10:52:26 2005
> @@ -1,11 +1,12 @@
>  package org.roller.presentation.velocity;
>  import java.net.MalformedURLException;
> -import java.util.ArrayList;
>  import java.util.Collection;
> +import java.util.HashMap;
>  import java.util.Hashtable;
>  import java.util.Iterator;
>  import java.util.List;
>  import java.util.Locale;
> +import java.util.Map;
>  import java.util.Vector;
>  
>  import javax.servlet.http.HttpServletRequest;
> @@ -50,8 +51,8 @@
>      private Context              mVelocityContext = null;
>      private PageContext          mPageContext = null;
>      private HttpServletResponse  mResponse = null;     
> -    private RollerRequest        mRollerReq = null;
> -    private Collection           mPagePlugins = new ArrayList();
> +    private RollerRequest        mRollerReq = null;  
> +    private Map                  mPagePlugins = new HashMap();  // Plugins keyed by name   
>      private boolean              mSkipFlag = false;
>      private WebsiteData          mWebsite = null;
>      
> @@ -96,7 +97,8 @@
>  
>      //------------------------------------------------------------------------
>      /**
> -     * Return a PageHelper with a new VelocityContext.
> +     * Return a PageHelper with a new VelocityContext, 
> +     * added to support the ApplyPlugins JSP tag.
>       */
>      public static PageHelper createPageHelper(
>          HttpServletRequest request, HttpServletResponse response)
> @@ -104,7 +106,7 @@
>          Context ctx = (Context)(new VelocityContext());
>          RollerRequest rreq = RollerRequest.getRollerRequest(request);
>          PageHelper pageHelper = new PageHelper(rreq, response, ctx);
> -        pageHelper.initializePlugins(ContextLoader.getPagePlugins());
> +        pageHelper.initializePlugins(ContextLoader.getPagePluginClasses());
>  
>          return pageHelper;
>      }
> @@ -113,18 +115,19 @@
>      /**
>       * Create individual instances of the PagePlugins for use by this PageHelper.
>       */
> -    protected void initializePlugins(Collection pluginClasses) 
> +    protected void initializePlugins(Map pluginClasses) 
>      {
> -        Iterator it = pluginClasses.iterator();
> +        Iterator it = pluginClasses.values().iterator();
>          while (it.hasNext()) 
>          {
>              try
>              {
> -                PagePlugin plugin = (PagePlugin)it.next();
> +                Class pluginClass = (Class)it.next();
> +                PagePlugin plugin = (PagePlugin)pluginClass.newInstance();
>                  plugin.init(mRollerReq, mVelocityContext);
> -                mPagePlugins.add(plugin);
> +                mPagePlugins.put(plugin.getName(), plugin);
>              }
> -            catch (RollerException e)
> +            catch (Exception e)
>              {
>                  mLogger.warn("Unable to init() PagePlugin: ", e    );
>              }
> @@ -465,34 +468,7 @@
>          }
>          return returnUrl;
>      }
> -    
> -    /**
> -     * Pass the String through any PagePlugins that have been
> -     * assigned to the PageHelper.
> -     * 
> -     * @param str
> -     * @return
> -     */
> -    public String renderPlugins(String str)
> -    {
> -        mLogger.debug("Rendering page plugins on String");
> -        
> -        if (mPagePlugins != null)
> -        {
> -            Iterator iter = mPagePlugins.iterator();
> -            PagePlugin plugin = null;
> -            while (iter.hasNext())
> -            {
> -                plugin = (PagePlugin) iter.next();
> -                
> -                mLogger.debug("applying plugin - ");
> -                str = plugin.render(str);
> -            }
> -        }
>          
> -        return str;
> -    }
> -    
>      /**
>       * Pass the String through any PagePlugins that have been
>       * assigned to the PageHelper, as selected by the Entry.
> @@ -525,13 +501,13 @@
>                  // now loop over mPagePlugins, matching
>                  // against Entry plugins (by name):
>                  // where a match is found render Plugin.
> -                Iterator iter = mPagePlugins.iterator();
> -                PagePlugin pagePlugin = null;
> +                Iterator iter = mPagePlugins.keySet().iterator();
>                  while (iter.hasNext())
>                  {
> -                    pagePlugin = (PagePlugin)iter.next();
> -                    if (entryPlugins.contains(pagePlugin.getName()))
> +                    String key = (String)iter.next();
> +                    if (entryPlugins.contains(key))
>                      {
> +                        PagePlugin pagePlugin = (PagePlugin)mPagePlugins.get(key);
>                          copy.setText((pagePlugin).render(copy, mSkipFlag));
>                      }
>                  }
> 
> Modified: incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java
> URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java?rev=345303&r1=345302&r2=345303&view=diff
> ==============================================================================
> --- incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java (original)
> +++ incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java Thu Nov 17 10:52:26 2005
> @@ -297,7 +297,7 @@
>                  mLogger.debug("setting update time now");
>                  form.setUpdateTime(new Timestamp(new Date().getTime()));
>                  
> -                if("PUBLISHED".equals(form.getStatus()) &&
> +                if ("PUBLISHED".equals(form.getStatus()) &&
>                          "0/0/0".equals(form.getDateString())) {
>                      mLogger.debug("setting pubtime now");
>                      
> 
> Modified: incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryPageModel.java
> URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryPageModel.java?rev=345303&r1=345302&r2=345303&view=diff
> ==============================================================================
> --- incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryPageModel.java (original)
> +++ incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryPageModel.java Thu Nov 17 10:52:26 2005
> @@ -31,6 +31,10 @@
>  import org.roller.util.StringUtils;
>  
>  import com.swabunga.spell.event.SpellCheckEvent;
> +import java.util.Map;
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
> +import org.roller.presentation.velocity.PagePlugin;
>  
>  /**
>   * All data needed to render the edit-weblog page.
> @@ -38,6 +42,9 @@
>   */
>  public class WeblogEntryPageModel extends BasePageModel
>  {
> +    private static Log logger = 
> +       LogFactory.getFactory().getInstance(WeblogEntryPageModel.class);
> +        
>      private RollerRequest rollerRequest = null;
>      private PageMode mode = null;
>      private ArrayList words = null;
> @@ -190,6 +197,31 @@
>      public boolean getHasPagePlugins()
>      {
>          return ContextLoader.hasPlugins();
> +    }
> +    
> +    public List getPagePlugins() 
> +    {
> +        List list = new ArrayList();
> +        if (getHasPagePlugins()) 
> +        {
> +            Map pluginClasses = ContextLoader.getPagePluginClasses();
> +            Iterator it = pluginClasses.values().iterator();
> +            while (it.hasNext()) 
> +            {
> +                try
> +                {
> +                    Class pluginClass = (Class)it.next();
> +                    PagePlugin plugin = (PagePlugin)pluginClass.newInstance();
> +                    // no need to init plugins, we're not gonna run them
> +                    list.add(plugin);
> +                }
> +                catch (Exception e)
> +                {
> +                    logger.warn("Unable to create a PagePlugin: ", e);
> +                }
> +            }  
> +        }
> +        return list;
>      }
>  
>      public String getEditorPage()
> 
> Modified: incubator/roller/trunk/web/weblog/WeblogEdit.jsp
> URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/web/weblog/WeblogEdit.jsp?rev=345303&r1=345302&r2=345303&view=diff
> ==============================================================================
> --- incubator/roller/trunk/web/weblog/WeblogEdit.jsp (original)
> +++ incubator/roller/trunk/web/weblog/WeblogEdit.jsp Thu Nov 17 10:52:26 2005
> @@ -263,7 +263,7 @@
>        </div>
>        <div id="pluginControl" class="miscControl" style="display:none">
>          <logic:iterate id="plugin" type="org.roller.presentation.velocity.PagePlugin"
> -            collection="<%= org.roller.presentation.velocity.ContextLoader.getPagePlugins() %>">
> +            collection="<%= model.getPagePlugins() %>">
>              <html:multibox property="pluginsArray"
>                   title="<%= plugin.getName() %>" value="<%= plugin.getName() %>"
>                   styleId="<%= plugin.getName() %>"/></input>
> 
> 


website settings page broken ... was Re: svn commit: r345303 - in /incubator/roller/trunk: src/org/roller/presentation/velocity/ src/org/roller/presentation/weblog/actions/ web/weblog/

Posted by Allen Gilliland <Al...@Sun.COM>.
this commit broke the website settings page.

-- Allen


On Thu, 2005-11-17 at 10:52, snoopdave@apache.org wrote:
> Author: snoopdave
> Date: Thu Nov 17 10:52:26 2005
> New Revision: 345303
> 
> URL: http://svn.apache.org/viewcvs?rev=345303&view=rev
> Log:
> Instantiate plugins on every request to resolve ROL-893 topic tag uneliable
> 
> Modified:
>     incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java
>     incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java
>     incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java
>     incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryPageModel.java
>     incubator/roller/trunk/web/weblog/WeblogEdit.jsp
> 
> 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=345303&r1=345302&r2=345303&view=diff
> ==============================================================================
> --- incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java (original)
> +++ incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java Thu Nov 17 10:52:26 2005
> @@ -5,7 +5,7 @@
>  import java.text.SimpleDateFormat;
>  import java.util.ArrayList;
>  import java.util.Date;
> -import java.util.List;
> +import java.util.HashMap;
>  import java.util.Locale;
>  import java.util.Map;
>  import java.util.TimeZone;
> @@ -56,8 +56,8 @@
>  {   
>      private RollerRequest mRollerReq = null;
>      
> -    // List of PagePlugins for "transforming" WeblogEntries
> -    static List mPagePlugins = new ArrayList();
> +    // Plugin classes keyed by plugin name
> +    static Map mPagePlugins = new HashMap();
>      
>      private static Log mLogger = 
>         LogFactory.getFactory().getInstance(ContextLoader.class);
> @@ -469,12 +469,10 @@
>      //------------------------------------------------------------------------
>  
>      /**
> -     * Initialize PagePlugins declared in web.xml.  By using the full class
> -     * name we also allow for the implementation of "external" Plugins
> -     * (maybe even packaged seperately).  These classes are then later 
> -     * instantiated by PageHelper.
> -     * 
> -     * @param mContext
> +     * Initialize PagePlugins declared in web.xml, called once by RollerContext.
> +     * By using the full class name we also allow for the implementation of 
> +     * "external" Plugins (maybe even packaged seperately). These classes are 
> +     * then later instantiated by PageHelper.
>       */
>      public static void initializePagePlugins(ServletContext mContext)
>      {
> @@ -494,7 +492,8 @@
>                      Class pluginClass = Class.forName(plugins[i]);
>                      if (isPagePlugin(pluginClass))
>                      {
> -                        mPagePlugins.add(pluginClass.newInstance());
> +                        PagePlugin plugin = (PagePlugin)pluginClass.newInstance();
> +                        mPagePlugins.put(plugin.getName(), pluginClass);
>                      }
>                      else
>                      {
> @@ -537,7 +536,7 @@
>          return (mPagePlugins != null && mPagePlugins.size() > 0);
>      }
>      
> -    public static List getPagePlugins()
> +    public static Map getPagePluginClasses()
>      {
>          return mPagePlugins;
>      }
> 
> Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java
> URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java?rev=345303&r1=345302&r2=345303&view=diff
> ==============================================================================
> --- incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java (original)
> +++ incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java Thu Nov 17 10:52:26 2005
> @@ -1,11 +1,12 @@
>  package org.roller.presentation.velocity;
>  import java.net.MalformedURLException;
> -import java.util.ArrayList;
>  import java.util.Collection;
> +import java.util.HashMap;
>  import java.util.Hashtable;
>  import java.util.Iterator;
>  import java.util.List;
>  import java.util.Locale;
> +import java.util.Map;
>  import java.util.Vector;
>  
>  import javax.servlet.http.HttpServletRequest;
> @@ -50,8 +51,8 @@
>      private Context              mVelocityContext = null;
>      private PageContext          mPageContext = null;
>      private HttpServletResponse  mResponse = null;     
> -    private RollerRequest        mRollerReq = null;
> -    private Collection           mPagePlugins = new ArrayList();
> +    private RollerRequest        mRollerReq = null;  
> +    private Map                  mPagePlugins = new HashMap();  // Plugins keyed by name   
>      private boolean              mSkipFlag = false;
>      private WebsiteData          mWebsite = null;
>      
> @@ -96,7 +97,8 @@
>  
>      //------------------------------------------------------------------------
>      /**
> -     * Return a PageHelper with a new VelocityContext.
> +     * Return a PageHelper with a new VelocityContext, 
> +     * added to support the ApplyPlugins JSP tag.
>       */
>      public static PageHelper createPageHelper(
>          HttpServletRequest request, HttpServletResponse response)
> @@ -104,7 +106,7 @@
>          Context ctx = (Context)(new VelocityContext());
>          RollerRequest rreq = RollerRequest.getRollerRequest(request);
>          PageHelper pageHelper = new PageHelper(rreq, response, ctx);
> -        pageHelper.initializePlugins(ContextLoader.getPagePlugins());
> +        pageHelper.initializePlugins(ContextLoader.getPagePluginClasses());
>  
>          return pageHelper;
>      }
> @@ -113,18 +115,19 @@
>      /**
>       * Create individual instances of the PagePlugins for use by this PageHelper.
>       */
> -    protected void initializePlugins(Collection pluginClasses) 
> +    protected void initializePlugins(Map pluginClasses) 
>      {
> -        Iterator it = pluginClasses.iterator();
> +        Iterator it = pluginClasses.values().iterator();
>          while (it.hasNext()) 
>          {
>              try
>              {
> -                PagePlugin plugin = (PagePlugin)it.next();
> +                Class pluginClass = (Class)it.next();
> +                PagePlugin plugin = (PagePlugin)pluginClass.newInstance();
>                  plugin.init(mRollerReq, mVelocityContext);
> -                mPagePlugins.add(plugin);
> +                mPagePlugins.put(plugin.getName(), plugin);
>              }
> -            catch (RollerException e)
> +            catch (Exception e)
>              {
>                  mLogger.warn("Unable to init() PagePlugin: ", e    );
>              }
> @@ -465,34 +468,7 @@
>          }
>          return returnUrl;
>      }
> -    
> -    /**
> -     * Pass the String through any PagePlugins that have been
> -     * assigned to the PageHelper.
> -     * 
> -     * @param str
> -     * @return
> -     */
> -    public String renderPlugins(String str)
> -    {
> -        mLogger.debug("Rendering page plugins on String");
> -        
> -        if (mPagePlugins != null)
> -        {
> -            Iterator iter = mPagePlugins.iterator();
> -            PagePlugin plugin = null;
> -            while (iter.hasNext())
> -            {
> -                plugin = (PagePlugin) iter.next();
> -                
> -                mLogger.debug("applying plugin - ");
> -                str = plugin.render(str);
> -            }
> -        }
>          
> -        return str;
> -    }
> -    
>      /**
>       * Pass the String through any PagePlugins that have been
>       * assigned to the PageHelper, as selected by the Entry.
> @@ -525,13 +501,13 @@
>                  // now loop over mPagePlugins, matching
>                  // against Entry plugins (by name):
>                  // where a match is found render Plugin.
> -                Iterator iter = mPagePlugins.iterator();
> -                PagePlugin pagePlugin = null;
> +                Iterator iter = mPagePlugins.keySet().iterator();
>                  while (iter.hasNext())
>                  {
> -                    pagePlugin = (PagePlugin)iter.next();
> -                    if (entryPlugins.contains(pagePlugin.getName()))
> +                    String key = (String)iter.next();
> +                    if (entryPlugins.contains(key))
>                      {
> +                        PagePlugin pagePlugin = (PagePlugin)mPagePlugins.get(key);
>                          copy.setText((pagePlugin).render(copy, mSkipFlag));
>                      }
>                  }
> 
> Modified: incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java
> URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java?rev=345303&r1=345302&r2=345303&view=diff
> ==============================================================================
> --- incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java (original)
> +++ incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryFormAction.java Thu Nov 17 10:52:26 2005
> @@ -297,7 +297,7 @@
>                  mLogger.debug("setting update time now");
>                  form.setUpdateTime(new Timestamp(new Date().getTime()));
>                  
> -                if("PUBLISHED".equals(form.getStatus()) &&
> +                if ("PUBLISHED".equals(form.getStatus()) &&
>                          "0/0/0".equals(form.getDateString())) {
>                      mLogger.debug("setting pubtime now");
>                      
> 
> Modified: incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryPageModel.java
> URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryPageModel.java?rev=345303&r1=345302&r2=345303&view=diff
> ==============================================================================
> --- incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryPageModel.java (original)
> +++ incubator/roller/trunk/src/org/roller/presentation/weblog/actions/WeblogEntryPageModel.java Thu Nov 17 10:52:26 2005
> @@ -31,6 +31,10 @@
>  import org.roller.util.StringUtils;
>  
>  import com.swabunga.spell.event.SpellCheckEvent;
> +import java.util.Map;
> +import org.apache.commons.logging.Log;
> +import org.apache.commons.logging.LogFactory;
> +import org.roller.presentation.velocity.PagePlugin;
>  
>  /**
>   * All data needed to render the edit-weblog page.
> @@ -38,6 +42,9 @@
>   */
>  public class WeblogEntryPageModel extends BasePageModel
>  {
> +    private static Log logger = 
> +       LogFactory.getFactory().getInstance(WeblogEntryPageModel.class);
> +        
>      private RollerRequest rollerRequest = null;
>      private PageMode mode = null;
>      private ArrayList words = null;
> @@ -190,6 +197,31 @@
>      public boolean getHasPagePlugins()
>      {
>          return ContextLoader.hasPlugins();
> +    }
> +    
> +    public List getPagePlugins() 
> +    {
> +        List list = new ArrayList();
> +        if (getHasPagePlugins()) 
> +        {
> +            Map pluginClasses = ContextLoader.getPagePluginClasses();
> +            Iterator it = pluginClasses.values().iterator();
> +            while (it.hasNext()) 
> +            {
> +                try
> +                {
> +                    Class pluginClass = (Class)it.next();
> +                    PagePlugin plugin = (PagePlugin)pluginClass.newInstance();
> +                    // no need to init plugins, we're not gonna run them
> +                    list.add(plugin);
> +                }
> +                catch (Exception e)
> +                {
> +                    logger.warn("Unable to create a PagePlugin: ", e);
> +                }
> +            }  
> +        }
> +        return list;
>      }
>  
>      public String getEditorPage()
> 
> Modified: incubator/roller/trunk/web/weblog/WeblogEdit.jsp
> URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/web/weblog/WeblogEdit.jsp?rev=345303&r1=345302&r2=345303&view=diff
> ==============================================================================
> --- incubator/roller/trunk/web/weblog/WeblogEdit.jsp (original)
> +++ incubator/roller/trunk/web/weblog/WeblogEdit.jsp Thu Nov 17 10:52:26 2005
> @@ -263,7 +263,7 @@
>        </div>
>        <div id="pluginControl" class="miscControl" style="display:none">
>          <logic:iterate id="plugin" type="org.roller.presentation.velocity.PagePlugin"
> -            collection="<%= org.roller.presentation.velocity.ContextLoader.getPagePlugins() %>">
> +            collection="<%= model.getPagePlugins() %>">
>              <html:multibox property="pluginsArray"
>                   title="<%= plugin.getName() %>" value="<%= plugin.getName() %>"
>                   styleId="<%= plugin.getName() %>"/></input>
> 
>