roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r349595 [2/2] - in /incubator/roller/trunk: contrib/plugins/src/org/roller/presentation/velocity/plugins/acronyms/ contrib/plugins/src/org/roller/presentation/velocity/plugins/bookmarks/ contrib/plugins/src/org/roller/presentation/velocity/...
Date Tue, 29 Nov 2005 02:45:09 GMT
Modified: incubator/roller/trunk/src/org/roller/pojos/PlanetEntryData.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/pojos/PlanetEntryData.java?rev=349595&r1=349594&r2=349595&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/pojos/PlanetEntryData.java (original)
+++ incubator/roller/trunk/src/org/roller/pojos/PlanetEntryData.java Mon Nov 28 18:44:45 2005
@@ -20,6 +20,8 @@
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
+
+import org.roller.config.RollerRuntimeConfig;
 import org.roller.util.rome.ContentModule;
 
 import org.roller.util.Utilities;
@@ -31,7 +33,12 @@
 import com.sun.syndication.feed.synd.SyndFeed;
 
 // this will be needed for ROME v0.8
-//import com.sun.syndication.feed.synd.SyndPerson;
+import com.sun.syndication.feed.synd.SyndPerson;
+import java.util.Map;
+import org.roller.RollerException;
+import org.roller.model.PagePluginManager;
+import org.roller.model.Roller;
+import org.roller.model.RollerFactory;
 
 /**
  * A syndication feed entry intended for use in an in-memory or database cache to 
@@ -73,18 +80,30 @@
         initFromRomeEntry(romeFeed, romeEntry);
     }
     
+    /**
+     * Create entry from Rome entry.
+     */
+    public PlanetEntryData(
+            WeblogEntryData rollerEntry, 
+            PlanetSubscriptionData sub, 
+            Map pagePlugins) throws RollerException
+    {
+        setSubscription(sub);
+        initFromRollerEntry(rollerEntry, pagePlugins);
+    }
+    
     /** 
      * Init entry from Rome entry 
      */
     private void initFromRomeEntry(SyndFeed romeFeed, SyndEntry romeEntry)
     {
-        setAuthor(romeEntry.getAuthor());
+        //setAuthor(romeEntry.getAuthor());
         // this will be needed (instead of the previous line) for ROME v0.8
-        //List authors = romeEntry.getAuthors();
-        //if (authors!=null && authors.size() > 0) {
-            //SyndPerson person = (SyndPerson)authors.get(0);
-            //setAuthor(person.getName());
-        //}
+        List authors = romeEntry.getAuthors();
+        if (authors!=null && authors.size() > 0) {
+            SyndPerson person = (SyndPerson)authors.get(0);
+            setAuthor(person.getName());
+        }
         setTitle(romeEntry.getTitle());
         setPermalink(romeEntry.getLink());
         
@@ -99,18 +118,6 @@
         {
             setPublished(entrydc.getDate()); // use <dc:date>
         }       
-        // Commented out: preserve knowledge that entry has no date
-        //if (getPublished() == null) // Still no published date?
-        //{
-            //if (romeFeed.getPublishedDate() != null)
-            //{
-                //setPublished(romeFeed.getPublishedDate()); // try feed's <pubDate>
-            //}
-            //else if (feeddc != null)
-            //{
-                //setPublished(feeddc.getDate()); // try feed's <dc:date>
-            //}
-        //}
         
         // get content and unescape if it is 'text/plain' 
         if (romeEntry.getContents().size() > 0)
@@ -148,6 +155,31 @@
             }
             setCategories(list);
         }
+    }
+    
+    /** 
+     * Init entry from Roller entry 
+     */
+    private void initFromRollerEntry(WeblogEntryData rollerEntry, Map pagePlugins) 
+        throws RollerException
+    {
+        Roller roller = RollerFactory.getRoller();
+        PagePluginManager ppmgr = roller.getPagePluginManager();
+        WeblogEntryData processedEntry = 
+            ppmgr.applyPagePlugins(rollerEntry, pagePlugins, true);
+        
+        setAuthor(    processedEntry.getCreator().getFullName());
+        setTitle(     processedEntry.getTitle());
+        setPermalink( processedEntry.getLink());
+        setPublished( processedEntry.getPubTime());         
+        setContent(   processedEntry.getText());
+        
+        setPermalink(RollerRuntimeConfig.getProperty("site.absoluteurl") 
+                    + processedEntry.getPermaLink());
+        
+        List cats = new ArrayList();
+        cats.add(processedEntry.getCategory().getPath());
+        setCategories(cats);   
     }
     
     //----------------------------------------------------------- persistent fields

Modified: incubator/roller/trunk/src/org/roller/pojos/RefererData.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/pojos/RefererData.java?rev=349595&r1=349594&r2=349595&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/pojos/RefererData.java (original)
+++ incubator/roller/trunk/src/org/roller/pojos/RefererData.java Mon Nov 28 18:44:45 2005
@@ -14,7 +14,7 @@
  * @struts.form include-all="true"
  * @hibernate.class lazy="false" table="referer" 
  */
-public class RefererData extends org.roller.pojos.PersistentObject
+public class RefererData extends PersistentObject
     implements java.io.Serializable
 {
     static final long serialVersionUID = -1817992900602131316L;

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=349595&r1=349594&r2=349595&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/pojos/WebsiteData.java (original)
+++ incubator/roller/trunk/src/org/roller/pojos/WebsiteData.java Mon Nov 28 18:44:45 2005
@@ -59,6 +59,9 @@
     private String  defaultPlugins = null;
     private Boolean enabled = Boolean.TRUE;
     private Date dateCreated = null;
+    private Boolean defaultAllowComments = Boolean.TRUE;
+    private int defaultCommentDays = 0;
+    private Boolean moderateComments = Boolean.FALSE;
        
     // Associated objects
     private UserData creator = null; // TODO: decide if website.user is needed
@@ -88,7 +91,11 @@
                        final String   emailFromAddress,
                        final Boolean  enabled,
                        final String   emailAddress,
-                       final Date     dateCreated)
+                       final Date     dateCreated,
+                       final Boolean  defaultAllowComments,
+                       final int      defaultCommentDays,
+                       final Boolean  moderateComments
+                       )
     {
         this.id = id;
         this.name = name;
@@ -107,7 +114,9 @@
         this.emailFromAddress = emailFromAddress;
         this.enabled = enabled;
         this.emailAddress = emailAddress;
-        this.dateCreated = dateCreated;
+        this.defaultAllowComments = defaultAllowComments;
+        this.defaultCommentDays = defaultCommentDays;
+        this.moderateComments = moderateComments;
     }
 
     public WebsiteData(WebsiteData otherData)
@@ -573,6 +582,48 @@
     {
         this.allowComments = allowComments;
     }
+    
+    /**
+     * @roller.wrapPojoMethod type="simple"
+     * @ejb:persistent-field
+     * @hibernate.property column="defaultallowcomments" non-null="true" unique="false"
+     */
+    public Boolean getDefaultAllowComments() {
+        return defaultAllowComments;
+    }
+
+    /** @ejb:persistent-field */
+    public void setDefaultAllowComments(Boolean defaultAllowComments) {
+        this.defaultAllowComments = defaultAllowComments;
+    }
+
+    /**
+     * @roller.wrapPojoMethod type="simple"
+     * @ejb:persistent-field
+     * @hibernate.property column="defaultcommentdays" non-null="true" unique="false"
+     */
+    public int getDefaultCommentDays() {
+        return defaultCommentDays;
+    }
+
+    /** @ejb:persistent-field */
+    public void setDefaultCommentDays(int defaultCommentDays) {
+        this.defaultCommentDays = defaultCommentDays;
+    }
+
+    /**
+     * @roller.wrapPojoMethod type="simple"
+     * @ejb:persistent-field
+     * @hibernate.property column="commentmod" non-null="true" unique="false"
+     */
+    public Boolean getModerateComments() {
+        return moderateComments;
+    }
+
+    /** @ejb:persistent-field */
+    public void setModerateComments(Boolean moderateComments) {
+        this.moderateComments = moderateComments;
+    }
 
     /**
      * @roller.wrapPojoMethod type="simple"
@@ -1053,5 +1104,7 @@
     {
         // no-op
     }
+
+
 }
 

Modified: incubator/roller/trunk/src/org/roller/presentation/RollerContext.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/RollerContext.java?rev=349595&r1=349594&r2=349595&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/RollerContext.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/RollerContext.java Mon Nov 28 18:44:45 2005
@@ -13,6 +13,7 @@
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.servlet.ServletContext;
+import javax.servlet.ServletConfig;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 import javax.servlet.http.HttpServletRequest;
@@ -180,7 +181,7 @@
             //
             //       this is really not a best practice and we should try to
             //       remove these dependencies on the webapp context if possible
-            RollerConfig.setContextPath(mContext.getRealPath("/"));
+            RollerConfig.setContextRealPath(mContext.getRealPath("/"));
             
             // always upgrade database first
             upgradeDatabaseIfNeeded();
@@ -191,7 +192,6 @@
             setupRollerProperties();
             roller.getThemeManager();
             setupSpellChecker();
-            setupPagePlugins();
             setupIndexManager(roller);
             setupRefererManager(roller);
             initializePingFeatures(roller);
@@ -225,7 +225,6 @@
             mLogger.fatal("RollerContext initialization failed", t);
         }
     }
-
     
     private void setupRollerProperties() throws RollerException
     {
@@ -378,19 +377,6 @@
     }
 
     //------------------------------------------------------------------------
-    /**
-     * Initialize the configured PagePlugins
-     * @param mContext
-     */
-    private void setupPagePlugins()
-    {
-        if (mLogger.isDebugEnabled())
-        {
-            mLogger.debug("Initialize PagePlugins");
-        }
-        ContextLoader.initializePagePlugins(mContext);
-
-    }
 
     /**
      * Add TurnoverReferersTask to run on a schedule.

Modified: incubator/roller/trunk/src/org/roller/presentation/planet/SyncWebsitesTask.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/planet/SyncWebsitesTask.java?rev=349595&r1=349594&r2=349595&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/planet/SyncWebsitesTask.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/planet/SyncWebsitesTask.java Mon Nov 28 18:44:45 2005
@@ -112,12 +112,14 @@
                             sub.setTitle(website.getName());
                             sub.setFeedUrl(feedUrl);
                             sub.setSiteUrl(siteUrl);
+                            sub.setAuthor(website.getHandle());
                             planet.saveSubscription(sub);
                             group.addSubscription(sub);
                         }
                         else
                         {
                             sub.setTitle(website.getName());
+                            sub.setAuthor(website.getHandle());
                             planet.saveSubscription(sub);
                         }
                     }

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=349595&r1=349594&r2=349595&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/ContextLoader.java Mon Nov 28 18:44:45 2005
@@ -56,9 +56,6 @@
 {   
     private RollerRequest mRollerReq = null;
     
-    // Plugin classes keyed by plugin name
-    static Map mPagePlugins = new LinkedHashMap();
-    
     private static Log mLogger = 
        LogFactory.getFactory().getInstance(ContextLoader.class);
 
@@ -94,9 +91,9 @@
         }
         
         // Add Velocity page helper to context
-        PageHelper pageHelper = new PageHelper(rreq, response, ctx);
-        pageHelper.initializePlugins(mPagePlugins);
-        ctx.put("pageHelper", pageHelper );
+        PageHelper pageHelper = new PageHelper(request, response, ctx);
+        Roller roller = RollerFactory.getRoller();
+        ctx.put("pageHelper", pageHelper);
 
         // Load standard Roller objects and values into the context 
         String handle = loadWebsiteValues(ctx, rreq, rollerCtx );
@@ -467,80 +464,6 @@
     }
     
     //------------------------------------------------------------------------
-
-    /**
-     * 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)
-    {
-        mLogger.debug("Initializing page plugins");
-        
-        String pluginStr = RollerConfig.getProperty("plugins.page");
-        if (mLogger.isDebugEnabled()) mLogger.debug(pluginStr);
-        if (pluginStr != null)
-        {
-            String[] plugins = StringUtils.stripAll(
-                                   StringUtils.split(pluginStr, ",") );
-            for (int i=0; i<plugins.length; i++)
-            {
-                if (mLogger.isDebugEnabled()) mLogger.debug("try " + plugins[i]);
-                try
-                {
-                    Class pluginClass = Class.forName(plugins[i]);
-                    if (isPagePlugin(pluginClass))
-                    {
-                        PagePlugin plugin = (PagePlugin)pluginClass.newInstance();
-                        mPagePlugins.put(plugin.getName(), pluginClass);
-                    }
-                    else
-                    {
-                        mLogger.warn(pluginClass + " is not a PagePlugin");
-                    }
-                } 
-                catch (ClassNotFoundException e)
-                {
-                    mLogger.error("ClassNotFoundException for " + plugins[i]);
-                }
-                catch (InstantiationException e)
-                {
-                    mLogger.error("InstantiationException for " + plugins[i]);
-                }
-                catch (IllegalAccessException e)
-                {
-                    mLogger.error("IllegalAccessException for " + plugins[i]);
-                }
-            }
-        }
-    }
-    
-    /**
-     * @param pluginClass
-     * @return
-     */
-    private static boolean isPagePlugin(Class pluginClass)
-    {
-        Class[] interfaces = pluginClass.getInterfaces();
-        for (int i=0; i<interfaces.length; i++)
-        {
-            if (interfaces[i].equals(PagePlugin.class)) return true;
-        }
-        return false;
-    }
-
-    public static boolean hasPlugins()
-    {
-        mLogger.debug("mPluginClasses.size(): " + mPagePlugins.size());
-        return (mPagePlugins != null && mPagePlugins.size() > 0);
-    }
-    
-    public static Map getPagePluginClasses()
-    {
-        return mPagePlugins;
-    }
-
 
     private static final String TOOLBOX_KEY = 
         "org.roller.presentation.velocity.toolbox";

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/ExportRss.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/ExportRss.java?rev=349595&r1=349594&r2=349595&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/ExportRss.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/ExportRss.java Mon Nov 28 18:44:45 2005
@@ -220,7 +220,7 @@
      * and has no PagePlugins either.  We want the exported
      * Entry.text to be the raw values.
      */
-    private void loadPageHelper()
+    private void loadPageHelper() throws RollerException
     {
         // Add Velocity page helper to context
         PageHelper pageHelper = new PageHelper(null, null, ctx);

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=349595&r1=349594&r2=349595&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/PageHelper.java Mon Nov 28 18:44:45 2005
@@ -2,7 +2,6 @@
 import java.net.MalformedURLException;
 import java.util.Hashtable;
 import java.util.Iterator;
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -18,6 +17,11 @@
 import org.apache.struts.util.RequestUtils;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.context.Context;
+import org.roller.RollerException;
+import org.roller.model.PagePlugin;
+import org.roller.model.PagePluginManager;
+import org.roller.model.Roller;
+import org.roller.model.RollerFactory;
 import org.roller.pojos.WeblogEntryData;
 import org.roller.pojos.WebsiteData;
 import org.roller.pojos.wrapper.RefererDataWrapper;
@@ -50,7 +54,7 @@
     private PageContext          mPageContext = null;
     private HttpServletResponse  mResponse = null;     
     private RollerRequest        mRollerReq = null;  
-    private Map                  mPagePlugins = new LinkedHashMap();  // Plugins keyed by name   
+    private Map                  mPagePlugins = null;  // Plugins keyed by name   
     private boolean              mSkipFlag = false;
     private WebsiteData          mWebsite = null;
     
@@ -60,78 +64,37 @@
      * Initialize VelocityHelper, setting the variables it will be hiding from
      * the Velocimacros.
      */
-    public PageHelper(
-            RollerRequest rreq, HttpServletResponse response, Context ctx)
+    public PageHelper( 
+            HttpServletRequest request, 
+            HttpServletResponse response, 
+            Context ctx) throws RollerException
     {
         mVelocityContext = ctx;
-        mRollerReq = rreq;
+        mRollerReq = RollerRequest.getRollerRequest(request);
         mResponse = response;
-        if (rreq != null) 
+        if (mRollerReq != null) 
         {
-            mPageContext = rreq.getPageContext();
-            if ( rreq.getRequest().getAttribute(RollerRequest.OWNING_WEBSITE) != null)
+            mPageContext = mRollerReq.getPageContext();
+            if (request.getAttribute(RollerRequest.OWNING_WEBSITE) != null)
             {
                 mWebsite = (WebsiteData)
-                    rreq.getRequest().getAttribute(RollerRequest.OWNING_WEBSITE);
+                    request.getAttribute(RollerRequest.OWNING_WEBSITE);
             }
-            else if ( rreq.getWebsite() != null )
+            else if (mRollerReq.getWebsite() != null )
             {
-                mWebsite = rreq.getWebsite();
+                mWebsite = mRollerReq.getWebsite();
             }
         }
-        
         if (mVelocityContext == null) mVelocityContext = new VelocityContext();
+        Roller roller = RollerFactory.getRoller(); 
+        PagePluginManager ppmgr = roller.getPagePluginManager();
+        mPagePlugins = ppmgr.createAndInitPagePlugins(
+                mWebsite, 
+                RollerContext.getRollerContext(request).getServletContext(),
+                RollerContext.getRollerContext(request).getAbsoluteContextUrl(),
+                mVelocityContext);
     }
-    
-    //------------------------------------------------------------------------
-    
-    /**
-     * Initialized VelocityHelper without a Velocity Context.
-     */
-    public PageHelper(RollerRequest rreq, HttpServletResponse response)
-    {
-        this(rreq, response, null);
-    }
-
-    //------------------------------------------------------------------------
-    /**
-     * Return a PageHelper with a new VelocityContext, 
-     * added to support the ApplyPlugins JSP tag.
-     */
-    public static PageHelper createPageHelper(
-        HttpServletRequest request, HttpServletResponse response)
-    {
-        Context ctx = (Context)(new VelocityContext());
-        RollerRequest rreq = RollerRequest.getRollerRequest(request);
-        PageHelper pageHelper = new PageHelper(rreq, response, ctx);
-        pageHelper.initializePlugins(ContextLoader.getPagePluginClasses());
-
-        return pageHelper;
-    }
-
-    //------------------------------------------------------------------------
-    /**
-     * Create individual instances of the PagePlugins for use by this PageHelper.
-     */
-    protected void initializePlugins(Map pluginClasses) 
-    {
-        Iterator it = pluginClasses.values().iterator();
-        while (it.hasNext()) 
-        {
-            try
-            {
-                Class pluginClass = (Class)it.next();
-                PagePlugin plugin = (PagePlugin)pluginClass.newInstance();
-                plugin.init(mRollerReq, mVelocityContext);
-                mPagePlugins.put(plugin.getName(), plugin);
-            }
-            catch (Exception e)
-            {
-                mLogger.warn("Unable to init() PagePlugin: ", e    );
-            }
-        }
-    }
-
+   
     //------------------------------------------------------------------------
     /**
      * This is a quasi-hack: there are places we don't want to render the

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/PlanetFeedServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/PlanetFeedServlet.java?rev=349595&r1=349594&r2=349595&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/PlanetFeedServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/PlanetFeedServlet.java Mon Nov 28 18:44:45 2005
@@ -11,6 +11,7 @@
 import org.apache.velocity.context.Context;
 import org.apache.velocity.servlet.VelocityServlet;
 import org.roller.RollerException;
+import org.roller.config.RollerRuntimeConfig;
 import org.roller.model.PlanetManager;
 import org.roller.model.RollerFactory;
 import org.roller.presentation.RollerRequest;
@@ -69,6 +70,27 @@
             context.put("planet", planet);
             context.put("date", new Date());
             context.put("utilities", new Utilities());
+            
+            int entryCount = 
+                RollerRuntimeConfig.getIntProperty("site.newsfeeds.defaultEntries");
+            int maxEntries = 
+                RollerRuntimeConfig.getIntProperty("site.newsfeeds.maxEntries");
+            String sCount = request.getParameter("count");
+            if (sCount!=null)
+            {
+                try
+                {
+                    entryCount = Integer.parseInt(sCount);
+                }
+                catch (NumberFormatException e)
+                {
+                    mLogger.warn("Improperly formatted count parameter");
+                }
+                if ( entryCount > maxEntries ) entryCount = maxEntries;
+                if ( entryCount < 0 ) entryCount = 0;
+            }
+            context.put("entryCount", new Integer(entryCount));            
+            
             return getTemplate("planetrss.vm");
         }
         catch (Exception e)

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=349595&r1=349594&r2=349595&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 Mon Nov 28 18:44:45 2005
@@ -1,6 +1,7 @@
 
 package org.roller.presentation.weblog.actions;
 
+import com.swabunga.spell.event.SpellCheckEvent;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
@@ -18,10 +19,10 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
+import java.util.Map;
 import java.util.ResourceBundle;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-
 import javax.mail.MessagingException;
 import javax.mail.Session;
 import javax.naming.InitialContext;
@@ -30,8 +31,6 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
-
-import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.struts.action.ActionError;
@@ -43,11 +42,14 @@
 import org.apache.struts.action.ActionMessages;
 import org.apache.struts.actions.DispatchAction;
 import org.apache.struts.util.RequestUtils;
+import org.apache.velocity.VelocityContext;
 import org.roller.RollerException;
 import org.roller.RollerPermissionsException;
 import org.roller.config.RollerConfig;
 import org.roller.model.IndexManager;
+import org.roller.model.PagePluginManager;
 import org.roller.model.Roller;
+import org.roller.model.RollerFactory;
 import org.roller.model.RollerSpellCheck;
 import org.roller.model.UserManager;
 import org.roller.model.WeblogManager;
@@ -56,20 +58,15 @@
 import org.roller.pojos.UserData;
 import org.roller.pojos.WeblogEntryData;
 import org.roller.pojos.WebsiteData;
-import org.roller.pojos.wrapper.WeblogEntryDataWrapper;
 import org.roller.presentation.RollerContext;
 import org.roller.presentation.RollerRequest;
 import org.roller.presentation.RollerSession;
-import org.roller.presentation.velocity.PageHelper;
+import org.roller.presentation.cache.CacheManager;
 import org.roller.presentation.weblog.formbeans.WeblogEntryFormEx;
 import org.roller.util.MailUtil;
+import org.roller.util.StringUtils;
 import org.roller.util.Utilities;
 
-import com.swabunga.spell.event.SpellCheckEvent;
-import org.roller.model.RollerFactory;
-import org.roller.presentation.cache.CacheManager;
-
-
 /////////////////////////////////////////////////////////////////////////////
 /**
  * Supports Weblog Entry form actions edit, remove, update, etc.
@@ -782,102 +779,6 @@
         return forward;
     }
 
-    //-----------------------------------------------------------------------
-    /**
-     * Update selected comments: delete and/or mark as spam.
-     */
-    public ActionForward updateComments(
-        ActionMapping       mapping,
-        ActionForm          actionForm,
-        HttpServletRequest  request,
-        HttpServletResponse response)
-        throws IOException, ServletException
-    {
-        ActionForward forward = mapping.findForward("weblogEdit.page");
-        ActionErrors errors = new ActionErrors();
-        RollerRequest rreq = RollerRequest.getRollerRequest(request);
-        RollerSession rollerSession = RollerSession.getRollerSession(request);
-        try
-        {
-            WeblogEntryData wd = rreq.getWeblogEntry();
-            if ( rollerSession.isUserAuthorizedToAuthor(wd.getWebsite()))
-            {
-                if (wd == null || wd.getId() == null)
-                {
-                    ResourceBundle resources = ResourceBundle.getBundle(
-                        "ApplicationResources", request.getLocale());
-                    request.setAttribute("javax.servlet.error.message", 
-                        resources.getString("weblogEntry.notFound"));  
-                    forward = mapping.findForward("error");                    
-                }
-                else 
-                {
-                    WeblogEntryFormEx form = (WeblogEntryFormEx)actionForm;
-
-                    // If form indicates that comments should be deleted, delete
-                    WeblogManager mgr= RollerFactory.getRoller().getWeblogManager();
-                    String[] deleteIds = form.getDeleteComments();
-                    if (deleteIds != null && deleteIds.length > 0)
-                    {
-                        mgr.removeComments( deleteIds );
-                    }
-
-                    List comments = mgr.getComments(wd.getId(), false); // spam too
-                    if (form.getSpamComments() != null)
-                    {
-                        // comments marked as spam
-                        List spamIds = Arrays.asList(form.getSpamComments());
-
-                        // iterate over all comments, check each to see if
-                        // is in the spamIds list.  If so, mark it as spam.
-                        Iterator it = comments.iterator();
-                        while (it.hasNext())
-                        {
-                            CommentData comment = (CommentData)it.next();
-                            if (spamIds.contains(comment.getId()))
-                            {
-                                comment.setSpam(Boolean.TRUE);                            
-                            }
-                            else 
-                            {
-                                comment.setSpam(Boolean.FALSE);
-                            }
-                            comment.save();
-                        }
-                    }
-
-                    RollerFactory.getRoller().commit();
-                    
-                    // notify cache manager
-                    CacheManager.invalidate(wd);
-
-                    reindexEntry(RollerFactory.getRoller(), wd);
-
-                    request.setAttribute("model",
-                            new WeblogEntryPageModel(request, response, mapping, 
-                                    (WeblogEntryFormEx)actionForm,
-                                    WeblogEntryPageModel.EDIT_MODE));
-                }
-            }
-            else
-            {
-                forward = mapping.findForward("access-denied");
-            }
-        }
-        catch (Exception e)
-        {
-            forward = mapping.findForward("error");
-
-            errors.add(ActionErrors.GLOBAL_ERROR,
-                new ActionError("error.edit.comment", e.toString()));
-            saveErrors(request,errors);
-
-            mLogger.error(getResources(request).getMessage("error.edit.comment")
-                + e.toString(),e);
-        }
-        return forward;
-    }
-
     /**
     *
     */
@@ -899,27 +800,30 @@
                entryid = 
                    request.getParameter(RollerRequest.WEBLOGENTRYID_KEY);
            }
-
+           Roller roller = RollerFactory.getRoller();
            RollerContext rctx= RollerContext.getRollerContext(request);
-           WeblogManager wmgr= RollerFactory.getRoller().getWeblogManager();
+           WeblogManager wmgr= roller.getWeblogManager();
            entry = wmgr.retrieveWeblogEntry(entryid);
 
            RollerSession rses = RollerSession.getRollerSession(request);
            if (rses.isUserAuthorizedToAuthor(entry.getWebsite()))
            {
-               String title = entry.getTitle();
-
                // Run entry through registered PagePlugins
-               PageHelper pageHelper = 
-                   PageHelper.createPageHelper(request, response);
-               pageHelper.setSkipFlag(true); // don't process ReadMorePlugin
-               // we have to wrap the entry for rendering because the
-               // page helper requires wrapped objects
-               String excerpt = pageHelper.renderPlugins(WeblogEntryDataWrapper.wrap(entry));
+               PagePluginManager ppmgr = roller.getPagePluginManager();
+               Map plugins = ppmgr.createAndInitPagePlugins( 
+                   entry.getWebsite(),
+                   RollerContext.getRollerContext(request).getServletContext(),
+                   RollerContext.getRollerContext(request).getAbsoluteContextUrl(),
+                   new VelocityContext());
+               
+               WeblogEntryData applied = 
+                   ppmgr.applyPagePlugins(entry, plugins, true);
+               String title = applied.getTitle();
+               String excerpt = applied.getText();
                excerpt = StringUtils.left( Utilities.removeHTML(excerpt),255 );
 
-               String url = rctx.createEntryPermalink(entry, request, true);
-               String blog_name = entry.getWebsite().getName();
+               String url = rctx.createEntryPermalink(applied, request, true);
+               String blog_name = applied.getWebsite().getName();
 
                if (form.getTrackbackUrl() != null)
                {

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=349595&r1=349594&r2=349595&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 Mon Nov 28 18:44:45 2005
@@ -1,6 +1,4 @@
-/*
- * Created on Mar 10, 2004
- */
+/* Created on Mar 10, 2004 */
 package org.roller.presentation.weblog.actions;
 
 import java.util.ArrayList;
@@ -17,7 +15,6 @@
 import org.apache.struts.action.ActionMapping;
 import org.roller.RollerException;
 import org.roller.model.RollerFactory;
-import org.roller.model.WeblogManager;
 import org.roller.pojos.UserData;
 import org.roller.pojos.WeblogEntryData;
 import org.roller.presentation.BasePageModel;
@@ -25,7 +22,7 @@
 import org.roller.presentation.RollerRequest;
 import org.roller.presentation.RollerSession;
 import org.roller.presentation.tags.calendar.CalendarModel;
-import org.roller.presentation.velocity.ContextLoader;
+import org.roller.presentation.weblog.actions.WeblogEntryPageModel.PageMode;
 import org.roller.presentation.weblog.formbeans.WeblogEntryFormEx;
 import org.roller.presentation.weblog.tags.EditWeblogCalendarModel;
 import org.roller.util.StringUtils;
@@ -34,7 +31,9 @@
 import java.util.Map;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.roller.presentation.velocity.PagePlugin;
+import org.apache.velocity.VelocityContext;
+import org.roller.model.PagePluginManager;
+import org.roller.model.Roller;
 
 /**
  * All data needed to render the edit-weblog page.
@@ -49,7 +48,6 @@
     private PageMode mode = null;
     private ArrayList words = null;
     private WeblogEntryFormEx form;
-    private List comments = null;
     private WeblogEntryData weblogEntry;
         
     public static class PageMode {
@@ -92,15 +90,8 @@
         super("dummy", request, response, mapping);
         this.rollerRequest = RollerRequest.getRollerRequest(request);  
         this.form = form;
-        this.mode = mode;
-        
+        this.mode = mode;       
         getRequest().setAttribute("leftPage","/weblog/WeblogEditSidebar.jsp");
-        
-        if (null != form.getId()) 
-        {
-            WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
-            comments = wmgr.getComments(form.getId(), false);
-        }
     }
     
     public String getTitle() 
@@ -196,30 +187,35 @@
 
     public boolean getHasPagePlugins()
     {
-        return ContextLoader.hasPlugins();
+        boolean ret = false;
+        try {
+            Roller roller = RollerFactory.getRoller();
+            PagePluginManager ppmgr = roller.getPagePluginManager();
+            ret = ppmgr.hasPagePlugins();
+        } catch (RollerException e) {
+            logger.error(e);
+        }
+        return ret;
     }
     
     public List getPagePlugins() 
     {
         List list = new ArrayList();
-        if (getHasPagePlugins()) 
-        {
-            Map pluginClasses = ContextLoader.getPagePluginClasses();
-            Iterator it = pluginClasses.values().iterator();
-            while (it.hasNext()) 
+        try {
+            if (getHasPagePlugins()) 
             {
-                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);
-                }
-            }  
+                Roller roller = RollerFactory.getRoller();
+                PagePluginManager ppmgr = roller.getPagePluginManager();
+                Map plugins = ppmgr.createAndInitPagePlugins(
+                    getWebsite(),
+                    RollerContext.getRollerContext(request).getServletContext(),
+                    RollerContext.getRollerContext(request).getAbsoluteContextUrl(),
+                    new VelocityContext());
+                Iterator it = plugins.values().iterator();
+                while (it.hasNext()) list.add(it.next());
+            }
+        } catch (Exception e) {
+            logger.error(e);
         }
         return list;
     }
@@ -261,11 +257,6 @@
         return RollerFactory.getRoller().getWeblogManager()
             .getWeblogCategories(weblogEntry.getWebsite(), false);
     }
-
-    public List getComments() throws Exception
-    {
-        return comments;
-    }
     
     public WeblogEntryFormEx getWeblogEntryForm() throws RollerException
     {
@@ -397,6 +388,13 @@
     {
         return getRollerSession().isUserAuthorizedToAuthor(getWeblogEntry().getWebsite());
     }
+
+    public PageMode getEDIT_MODE() {
+        return EDIT_MODE;
+    }
     
-    
+    public int getCommentCount() {
+        List comments = weblogEntry.getComments(false, false);
+        return comments != null ? comments.size() : 0;
+    }
 }

Modified: incubator/roller/trunk/src/org/roller/presentation/weblog/tags/ApplyPluginsTag.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/weblog/tags/ApplyPluginsTag.java?rev=349595&r1=349594&r2=349595&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/weblog/tags/ApplyPluginsTag.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/weblog/tags/ApplyPluginsTag.java Mon Nov 28 18:44:45 2005
@@ -1,27 +1,24 @@
-     /*
- * Created on Feb 27, 2004
- */
+/* Created on Feb 27, 2004 */
 package org.roller.presentation.weblog.tags;
 
-import java.io.IOException;
-
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.tagext.TagSupport;
+import java.util.Map;
+import java.io.IOException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.struts.util.RequestUtils;
+import org.apache.velocity.VelocityContext;
+
+import org.roller.model.Roller;
+import org.roller.model.PagePluginManager;
+import org.roller.model.RollerFactory;
 import org.roller.pojos.WeblogEntryData;
-import org.roller.presentation.velocity.PageHelper;
+import org.roller.presentation.RollerContext;
 import org.roller.util.Utilities;
-import java.io.IOException;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.tagext.TagSupport;
 import org.roller.pojos.wrapper.WeblogEntryDataWrapper;
 
 /**
@@ -29,14 +26,11 @@
  * @jsp.tag name="ApplyPlugins"
  * @author David M Johnson
  */
-public class ApplyPluginsTag extends TagSupport
-{
+public class ApplyPluginsTag extends TagSupport {
     static final long serialVersionUID = 3166731504235428544L;
-    
-    private static final String HELPER_KEY = "roller.pageHelper";
     private static Log mLogger =
-        LogFactory.getFactory().getInstance(ApplyPluginsTag.class);
-
+            LogFactory.getFactory().getInstance(ApplyPluginsTag.class);
+    
     private String name = null;
     private String property = null;
     private String scope = "request";
@@ -44,42 +38,45 @@
     private boolean stripHtml = false;
     private int maxLength = -1;
     private boolean skipFlag = false;
-
+    
     /**
      * @see javax.servlet.jsp.tagext.Tag#doStartTag()
      */
-    public int doStartTag() throws JspException
-    {
-        WeblogEntryData entry = 
-            (WeblogEntryData)RequestUtils.lookup(pageContext, name, property, scope);
+    public int doStartTag() throws JspException {
+        Roller roller = RollerFactory.getRoller();
+        WeblogEntryData entry =
+                (WeblogEntryData)RequestUtils.lookup(pageContext, name, property, scope);
         
         String xformed = null;
-
-        if (entry.getPlugins() != null)
-        {
-            // check to see if a PageHelper has already been created this request
-            PageHelper helper = (PageHelper)pageContext.getRequest().getAttribute(HELPER_KEY);
-            if (helper == null)
-            {
-                helper = loadNewPageHelper();
+        
+        if (entry.getPlugins() != null) {
+            RollerContext rctx = 
+                RollerContext.getRollerContext(
+                    (HttpServletRequest)pageContext.getRequest());
+            try {
+                PagePluginManager ppmgr = roller.getPagePluginManager();
+                Map plugins = ppmgr.createAndInitPagePlugins(
+                        entry.getWebsite(),
+                        rctx.getServletContext(),
+                        rctx.getAbsoluteContextUrl(),
+                        new VelocityContext());
+                WeblogEntryData applied =
+                        ppmgr.applyPagePlugins(entry, plugins, skipFlag);
+                xformed = applied.getText();
+                
+            } catch (Exception e) {
+                mLogger.error(e);
             }
-            helper.setSkipFlag(skipFlag);
-    
-            xformed = helper.renderPlugins(WeblogEntryDataWrapper.wrap(entry));
-        }
-        else
-        {
+        } else {
             xformed = entry.getText();
         }
         
-        if (stripHtml)
-        {
+        if (stripHtml) {
             // don't escape ampersands
             xformed = Utilities.escapeHTML( Utilities.removeHTML(xformed), false );
         }
         
-        if (maxLength != -1)
-        {
+        if (maxLength != -1) {
             xformed = Utilities.truncateNicely(xformed, maxLength, maxLength, "...");
         }
         
@@ -87,70 +84,48 @@
         // but I cannot seem to track it down
         xformed = Utilities.stringReplace(xformed, "&amp#", "&#");
         
-        try
-        {
+        try {
             pageContext.getOut().println(xformed);
-        }
-        catch (IOException e)
-        {
+        } catch (IOException e) {
             throw new JspException("ERROR applying plugin to entry", e);
         }
         return TagSupport.SKIP_BODY;
     }
-
-    /**
-     * PagePlugins need to be loaded and properly initialized for use.
-     * Also, store the PageHelper in the Request as it will likely be
-     * used more than once and this way we can skip a fair amount of overhead.
-     */
-    private PageHelper loadNewPageHelper()
-    {
-        PageHelper pageHelper = PageHelper.createPageHelper(
-            (HttpServletRequest)pageContext.getRequest(), 
-            (HttpServletResponse)pageContext.getResponse());
-
-        pageContext.getRequest().setAttribute(HELPER_KEY, pageHelper);
-        return pageHelper;
-    }
-
+    
     /**
      * Maximum length of text displayed, only applies if stripHtml is true.
      * @jsp.attribute required="false"
      * @return Returns the maxLength.
      */
-    public int getMaxLength()
-    {
+    public int getMaxLength() {
         return maxLength;
     }
-
+    
     /**
      * Maximum length of text displayed, only applies if stripHtml is true.
      * @param maxLength The maxLength to set.
      */
-    public void setMaxLength(int maxLength)
-    {
+    public void setMaxLength(int maxLength) {
         this.maxLength = maxLength;
     }
-
+    
     /**
      * Set to true to strip all HTML markup from output.
      * @jsp.attribute required="false"
      * @return Returns the stripHtml.
      */
-    public boolean getStripHtml()
-    {
+    public boolean getStripHtml() {
         return stripHtml;
     }
-
+    
     /**
      * Set to true to strip all HTML markup from output.
      * @param stripHtml The stripHtml to set.
      */
-    public void setStripHtml(boolean stripHtml)
-    {
+    public void setStripHtml(boolean stripHtml) {
         this.stripHtml = stripHtml;
     }
-
+    
     /**
      * Set to true to inform PagePlugins if they
      * should "skip" themselves.
@@ -158,21 +133,19 @@
      * @jsp.attribute required="false"
      * @return Returns the skipFlag.
      */
-    public boolean getSkipFlag()
-    {
+    public boolean getSkipFlag() {
         return skipFlag;
     }
-
+    
     /**
      * Set to true to inform PagePlugins if they
      * should "skip" themselves.
      * @param skipFlag The skipFlag to set.
      */
-    public void setSkipFlag(boolean skipFlag)
-    {
+    public void setSkipFlag(boolean skipFlag) {
         this.skipFlag = skipFlag;
     }
-
+    
     /**
      * @return Returns the name.
      */

Modified: incubator/roller/trunk/src/org/roller/util/Blacklist.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/util/Blacklist.java?rev=349595&r1=349594&r2=349595&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/util/Blacklist.java (original)
+++ incubator/roller/trunk/src/org/roller/util/Blacklist.java Mon Nov 28 18:44:45 2005
@@ -1,13 +1,10 @@
-/*
- * Created on Nov 11, 2003
- */
+/* Created on Nov 11, 2003 */
 package org.roller.util;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import java.io.BufferedReader;
 import java.io.FileInputStream;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -17,97 +14,87 @@
 import java.net.URL;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.StringTokenizer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import org.roller.config.RollerConfig;
 
-
 /**
- * Based on the list provided by Jay Allen for MT-Blacklist:
- *  http://www.jayallen.org/projects/mt-blacklist/
- *
- * Will provide response whether submitted string
- * contains an item listed in the supplied blacklist.
- * This implementation does not do everything
- * MT-Blacklist does, such as the "Search &amp; De-spam mode".
+ * Loads MT-Blacklist style blacklist from disk and allows callers to test
+ * strings against the blacklist and (optionally) addition blacklists.
+ * <br />
+ * First looks for blacklist.txt in uploads directory, than in classpath 
+ * as /blacklist.txt. Download from web feature disabed.
+ * <br />
+ * Blacklist is formatted one entry per line. 
+ * Any line that begins with # is considered to be a comment. 
+ * Any line that begins with ( is considered to be a regex expression. 
+ * <br />
+ * For more information on the (discontinued) MT-Blacklist service:
+ * http://www.jayallen.org/projects/mt-blacklist. 
  *
- * @author lance
+ * @author Lance Lavandowska
  * @author Allen Gilliland
  */
 public class Blacklist {
     
     private static Log mLogger = LogFactory.getLog(Blacklist.class);
     
+    private static Blacklist blacklist;
     private static final String blacklistFile = "blacklist.txt";
-    private static final String blacklistURL = 
-            "http://www.jayallen.org/comment_spam/blacklist.txt";
     private static final String lastUpdateStr = "Last update:";
 
-    private static Blacklist blacklist;
-    
-    // Non-Static attributes
+    /** We no longer have a blacklist update URL */
+    private static final String blacklistURL = null; 
+
     private String uploadDir = null;
     private Date lastModified = null;
     private List blacklistStr = new LinkedList();
     private List blacklistRegex = new LinkedList();
     
-    
     // setup our singleton at class loading time
     static {
         mLogger.info("Initializing MT Blacklist");
-        
         blacklist = new Blacklist();
         blacklist.loadBlacklistFromFile();
     }
-
     
-    /**
-     * Hide constructor
-     */
+    /** Hide constructor */
     private Blacklist() {
         this.uploadDir = RollerConfig.getProperty("uploads.dir");
     }
-    
-    
-    /**
-     * Singleton factory method.
-     */
+      
+    /** Singleton factory method. */
     public static Blacklist getBlacklist() {
         return blacklist;
     }
     
-    
-    /**
-     * Updated MT blacklist if necessary.
-     */
+    /** Updated MT blacklist if necessary. */
     public static void checkForUpdate() {
         getBlacklist().update();
     }
     
-    
-    /**
-     * Non-Static update method.
-     */
+    /** Non-Static update method. */
     public void update() {
-        boolean blacklist_updated = this.downloadBlacklist();
-        
-        if(blacklist_updated)
-            this.loadBlacklistFromFile();
+        if (this.blacklistURL != null) {
+            boolean blacklist_updated = this.downloadBlacklist();
+            if (blacklist_updated) {
+                this.loadBlacklistFromFile();
+            }
+        }
     }
-    
-    
-    /**
-     * Download the MT blacklist from the web to our uploads directory.
-     */
+        
+    /** Download the MT blacklist from the web to our uploads directory. */
     private boolean downloadBlacklist() {
         
         boolean blacklist_updated = false;
         try {
-            mLogger.debug("attempting to download MT blacklist");
+            mLogger.debug("Attempting to download MT blacklist");
             
             URL url = new URL(blacklistURL);
             HttpURLConnection connection = 
@@ -176,11 +163,9 @@
         
         return blacklist_updated;
     }
-    
-    
+        
     /**
      * Load the MT blacklist from the file system.
-     *
      * We look for a previously downloaded version of the blacklist first and
      * if it's not found then we load the default blacklist packed with Roller.
      */
@@ -193,34 +178,32 @@
             
             // check our lastModified date to see if we need to re-read the file
             if(this.lastModified != null &&
-                    this.lastModified.getTime() >= blacklistFile.lastModified()) {
-                
+                    this.lastModified.getTime() >= blacklistFile.lastModified()) {               
                 mLogger.debug("Blacklist is current, no need to load again");
                 return;
             } else {
                 this.lastModified = new Date(blacklistFile.lastModified());
-            }
+            }           
+            txtStream = new FileInputStream(blacklistFile);           
+            mLogger.info("Loading blacklist from "+path);
             
-            txtStream = new FileInputStream(blacklistFile);
-            
-            mLogger.debug("Loading blacklist from "+path);
         } catch (Exception e) {
             // Roller keeps a copy in the webapp just in case
-            txtStream = getClass().getResourceAsStream("/"+blacklistFile);
-            
-            mLogger.debug("Couldn't find downloaded blacklist, "+
-                    "loading from classpath instead");
+            txtStream = getClass().getResourceAsStream("/"+blacklistFile);           
+            mLogger.warn("Couldn't find downloaded blacklist, " 
+                        + "loading from classpath instead");
         }
         
         if (txtStream != null) {
             readFromStream(txtStream, false);
         } else {
-            mLogger.error("couldn't load a blacklist file from anywhere, "+
-                    "this means blacklist checking is disabled for now.");
+            mLogger.error("Couldn't load a blacklist file from anywhere, "
+                        + "this means blacklist checking is disabled for now.");
         }
+        mLogger.info("Number of blacklist string rules: "+blacklistStr.size());
+        mLogger.info("Number of blacklist regex rules: "+blacklistRegex.size());
     }
-    
-    
+       
     /**
      * Read in the InputStream for rules.
      * @param txtStream
@@ -253,10 +236,6 @@
         return buf.toString();
     }
     
-    
-    /**
-     * @param str
-     */
     private void readRule(String str) {
         if (StringUtils.isEmpty(str)) return; // bad condition
         
@@ -276,12 +255,8 @@
             blacklistStr.add(rule);
         }
     }
-    
-    
-    /**
-     * Try to parse out "Last update" value: 2004/03/08 23:17:30.
-     * @param str
-     */
+        
+    /** Read comment and try to parse out "Last update" value */
     private void readComment(String str) {
         int lastUpdatePos = str.indexOf(lastUpdateStr);
         if (lastUpdatePos > -1) {
@@ -295,15 +270,23 @@
             }
         }
     }
-    
-    
-    /**
-     * Does the String argument match any of the rules in the blacklist?
-     *
-     * @param str
-     * @return
+       
+    /** 
+     * Does the String argument match any of the rules in the built-in blacklist? 
      */
     public boolean isBlacklisted(String str) {
+        return isBlacklisted(str, null, null);
+    }
+    
+    /** 
+     * Does the String argument match any of the rules in the built-in blacklist
+     * plus additional blacklists provided by caller?
+     * @param str             String to be checked against blacklist
+     * @param moreStringRules Additional string rules to consider
+     * @param moreRegexRules  Additional regex rules to consider 
+     */
+    public boolean isBlacklisted(
+         String str, List moreStringRules, List moreRegexRules) {
         if (str == null || StringUtils.isEmpty(str)) return false;
         
         // First iterate over blacklist, doing indexOf.
@@ -311,32 +294,50 @@
         // As soon as there is a hit in either case return true
         
         // test plain String.indexOf
-        if( testStringRules(str) ) return true;
+        List stringRules = blacklistStr;
+        if (moreStringRules != null && moreStringRules.size() > 0) {
+            stringRules = new ArrayList();
+            stringRules.addAll(blacklistStr);
+            stringRules.addAll(moreStringRules);
+        }
+        if (testStringRules(str, stringRules)) return true;
         
         // test regex blacklisted
-        return testRegExRules(str);
+        List regexRules = blacklistRegex;
+        if (moreRegexRules != null && moreRegexRules.size() > 0) {
+            regexRules = new ArrayList();
+            regexRules.addAll(blacklistRegex);
+            regexRules.addAll(moreRegexRules);
+        }
+        return testRegExRules(str, regexRules);
+    }      
+
+    /** 
+     * Test string only against rules provided by caller.
+     * @param str             String to be checked against rules
+     * @param moreStringRules String rules to consider
+     * @param moreRegexRules  Regex rules to consider 
+     */
+    public static boolean matches(
+        String str, List stringRules, List regexRules) {
+        if (testStringRules(str, stringRules)) return true;
+        return testRegExRules(str, regexRules);  
     }
-    
-    
-    /**
-     * Test String against the RegularExpression rules.
-     *
-     * @param str
-     * @return
-     */
-    private boolean testRegExRules(String str) {
+        
+    /** Test String against the RegularExpression rules. */
+    private static boolean testRegExRules(String str, List regexRules) {
         boolean hit = false;
         Pattern testPattern = null;
-        Iterator iter = blacklistRegex.iterator();
+        Iterator iter = regexRules.iterator();
         while (iter.hasNext()) {
             testPattern = (Pattern)iter.next();
             
-            // want to see what it is matching on
-            // if we are in "debug mode"
+            // want to see what it is matching on, but only in debug mode
             if (mLogger.isDebugEnabled()) {
                 Matcher matcher = testPattern.matcher(str);
                 if (matcher.find()) {
-                    mLogger.debug(matcher.group() + " matched by " + testPattern.pattern());
+                    mLogger.debug(matcher.group() 
+                         + " matched by " + testPattern.pattern());
                     hit = true;
                     break;
                 }
@@ -348,25 +349,17 @@
             }
         }
         return hit;
-    }
-    
+    }    
     
-    /**
-     * Test the String against the String rules,
-     * using simple indexOf.
-     *
-     * @param str
-     * @return
-     */
-    private boolean testStringRules(String str) {
+    /** Test the String against the String rules, using simple indexOf. */
+    private static boolean testStringRules(String str, List stringRules) {
         String test;
-        Iterator iter = blacklistStr.iterator();
+        Iterator iter = stringRules.iterator();
         boolean hit = false;
         while (iter.hasNext()) {
             test = (String)iter.next();
-            //System.out.println("check against |" + test + "|");
             if (str.indexOf(test) > -1) {
-                // want to see what it is matching on
+                // want to see what it is matching on, but only in debug mode
                 if (mLogger.isDebugEnabled()) {
                     mLogger.debug("matched:" + test + ":");
                 }
@@ -375,12 +368,9 @@
             }
         }
         return hit;
-    }
-    
+    }   
     
-    /**
-     * Return pretty list of String and RegEx rules.
-     */
+    /** Return pretty list of String and RegEx rules. */
     public String toString() {
         StringBuffer buf = new StringBuffer("blacklist ");
         buf.append(blacklistStr).append("\n");

Added: incubator/roller/trunk/src/org/roller/util/SpamChecker.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/util/SpamChecker.java?rev=349595&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/util/SpamChecker.java (added)
+++ incubator/roller/trunk/src/org/roller/util/SpamChecker.java Mon Nov 28 18:44:45 2005
@@ -0,0 +1,101 @@
+package org.roller.util;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.regex.Pattern;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.config.RollerConfig;
+import org.roller.config.RollerRuntimeConfig;
+import org.roller.pojos.CommentData;
+import org.roller.pojos.RefererData;
+
+/**
+ * Checks comment, trackbacks and referrers for spam.
+ * @author Lance Lavandowska
+ * @author Dave Johnson
+ */
+public class SpamChecker { 
+    private static Log mLogger = LogFactory.getLog(SpamChecker.class);
+    private Blacklist blacklist = Blacklist.getBlacklist();
+    
+    /** Test comment, applying blacklist if configured */
+    public boolean checkComment(CommentData comment) {
+        if (RollerConfig.getBooleanProperty("site.blacklist.enable.comments")) {
+            return testComment(comment);
+        }
+        return false;
+    }
+    
+    /** Test trackback comment, applying blacklist if configured */
+    public boolean checkTrackback(CommentData comment) {
+        if (RollerConfig.getBooleanProperty("site.blacklist.enable.trackbacks")) {
+            return testComment(comment);
+        }
+        return false;
+    }
+    
+    /** Test comment against built in blacklist + ignoreWords */
+    private boolean testComment(CommentData c) {
+        boolean ret = false;
+        
+        String weblogWords = c.getWeblogEntry().getWebsite().getIgnoreWords();
+        weblogWords = (weblogWords == null) ? "" : weblogWords;
+        String siteWords = 
+                RollerRuntimeConfig.getProperty("spam.referers.ignorewords");
+        siteWords = (siteWords == null) ? "" : siteWords;
+        
+        List stringRules = new ArrayList();
+        List regexRules = new ArrayList();
+        StringTokenizer toker = new StringTokenizer(siteWords + weblogWords,"\n");
+        while (toker.hasMoreTokens()) {
+            String token = toker.nextToken();
+            if (token.startsWith("#")) continue;
+            if (token.startsWith("(")) {
+                regexRules.add(Pattern.compile(token));
+            } else {
+                stringRules.add(token);
+            }
+        }
+        if (   blacklist.isBlacklisted(c.getUrl(),     stringRules, regexRules)
+            || blacklist.isBlacklisted(c.getEmail(),   stringRules, regexRules)
+            || blacklist.isBlacklisted(c.getContent(), stringRules, regexRules)) {
+            c.setSpam(Boolean.TRUE);
+            ret = true;
+        }
+        return ret;
+    }
+        
+    /** Test comment against built ignoreWords only */
+    public boolean testReferrer(RefererData referrer) {
+        boolean ret = false;
+        
+        String weblogWords = referrer.getWebsite().getIgnoreWords();
+        weblogWords = (weblogWords == null) ? "" : weblogWords;
+        String siteWords = 
+                RollerRuntimeConfig.getProperty("spam.referers.ignorewords");
+        siteWords = (siteWords == null) ? "" : siteWords;
+        
+        List stringRules = new ArrayList();
+        List regexRules = new ArrayList();
+        StringTokenizer toker = 
+            new StringTokenizer(siteWords + weblogWords,"\n");
+        while (toker.hasMoreTokens()) {
+            String token = toker.nextToken();
+            if (token.startsWith("#")) continue;
+            if (token.startsWith("(")) {
+                regexRules.add(token);
+            } else {
+                stringRules.add(token);
+            }
+        }   
+        // the blacklist.matches() doesn't use the built-in blacklist
+        if (Blacklist.matches(
+                referrer.getRefererUrl(), stringRules, regexRules)) {
+            ret = true;
+        }
+        return ret;
+    }
+}
+

Modified: incubator/roller/trunk/tests/org/roller/RollerTestBase.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/tests/org/roller/RollerTestBase.java?rev=349595&r1=349594&r2=349595&view=diff
==============================================================================
--- incubator/roller/trunk/tests/org/roller/RollerTestBase.java (original)
+++ incubator/roller/trunk/tests/org/roller/RollerTestBase.java Mon Nov 28 18:44:45 2005
@@ -17,17 +17,19 @@
 import org.apache.commons.logging.LogFactory;
 import org.roller.business.BookmarkManagerTest;
 import org.roller.config.RollerConfig;
+import org.roller.model.PlanetManager;
+import org.roller.model.PropertiesManager;
 import org.roller.model.Roller;
 import org.roller.model.RollerFactory;
 import org.roller.model.UserManager;
 import org.roller.model.WeblogManager;
 import org.roller.pojos.CommentData;
-import org.roller.pojos.PermissionsData;
-import org.roller.pojos.Theme;
+import org.roller.pojos.PlanetConfigData;
+import org.roller.pojos.PlanetGroupData;
+import org.roller.pojos.RollerPropertyData;
 import org.roller.pojos.UserData;
 import org.roller.pojos.WeblogCategoryData;
 import org.roller.pojos.WeblogEntryData;
-import org.roller.pojos.WeblogTemplate;
 import org.roller.pojos.WebsiteData;
 
 /**
@@ -117,7 +119,32 @@
         mWebsite = (WebsiteData)umgr.getWebsites(mUser, null).get(0);
         getRoller().commit();
         
-        RollerConfig.setContextPath("./build/roller");
+        RollerConfig.setContextRealPath("./build/roller");
+        
+        getRoller().begin(UserData.SYSTEM_USER);
+        PropertiesManager propmgr = getRoller().getPropertiesManager();
+        Map props = propmgr.getProperties();
+        RollerPropertyData prop = 
+            (RollerPropertyData)props.get("site.absoluteurl");
+        prop.setValue("http://localhost:8080/roller");
+        propmgr.store(props);
+        getRoller().commit();
+        
+        getRoller().begin(UserData.SYSTEM_USER);
+        PlanetManager planet = getRoller().getPlanetManager();
+        PlanetConfigData config = config = new PlanetConfigData();
+        config.setCacheDir("");
+        config.setTitle("Test");
+        config.setAdminEmail("admin@example.com");
+        planet.saveConfiguration(config);
+        getRoller().commit();
+        
+        getRoller().begin(UserData.SYSTEM_USER);
+        PlanetGroupData group = new PlanetGroupData();
+        group.setHandle("external");
+        group.setTitle("external");
+        planet.saveGroup(group);
+        getRoller().commit();        
     }
 
     //-----------------------------------------------------------------------

Added: incubator/roller/trunk/tests/org/roller/business/PlanetManagerLocalTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/tests/org/roller/business/PlanetManagerLocalTest.java?rev=349595&view=auto
==============================================================================
--- incubator/roller/trunk/tests/org/roller/business/PlanetManagerLocalTest.java (added)
+++ incubator/roller/trunk/tests/org/roller/business/PlanetManagerLocalTest.java Mon Nov 28 18:44:45 2005
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.roller.business;
+
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.roller.RollerTestBase;
+import org.roller.model.PlanetManager;
+import org.roller.presentation.planet.RefreshEntriesTask;
+import org.roller.presentation.planet.SyncWebsitesTask;
+
+
+/**
+ * Test database implementation of PlanetManager for local feeds.
+ * @author Dave Johnson
+ */
+public class PlanetManagerLocalTest extends RollerTestBase {
+    
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(PlanetManagerLocalTest.class);
+    }
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        super.setUpTestWeblogs();
+    }
+    
+    public void tearDown() throws Exception {
+        super.tearDown();
+        super.tearDownTestWeblogs();
+    }
+    public void testRefreshEntries() {
+        try {      
+            PlanetManager planet = getRoller().getPlanetManager();
+            
+            // run sync task to fill aggregator with websites created by super
+            SyncWebsitesTask syncTask = new SyncWebsitesTask();
+            syncTask.init(getRoller(), "dummy");
+            syncTask.run();           
+            
+            RefreshEntriesTask refreshTask = new RefreshEntriesTask();
+            refreshTask.init(getRoller(), "dummy");
+            refreshTask.run();
+            
+            List agg = planet.getAggregation(10000);
+            int size = agg.size();
+            assertEquals(mBlogCount * mExpectedPublishedEntryCount, size);
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
+    
+    public static Test suite() {
+        return new TestSuite(PlanetManagerLocalTest.class);
+    }
+    
+    
+}
+

Modified: incubator/roller/trunk/tests/org/roller/business/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/tests/org/roller/business/TestAll.java?rev=349595&r1=349594&r2=349595&view=diff
==============================================================================
--- incubator/roller/trunk/tests/org/roller/business/TestAll.java (original)
+++ incubator/roller/trunk/tests/org/roller/business/TestAll.java Mon Nov 28 18:44:45 2005
@@ -15,16 +15,17 @@
     public static Test suite()
     {
         TestSuite suite = new TestSuite();
-        suite.addTest(WebsiteTest.suite());
-        suite.addTest(ConfigManagerTest.suite());
-        suite.addTest(PermissionsTest.suite());
-        suite.addTest(UserManagerTest.suite());
-        suite.addTest(WeblogManagerTest.suite());
-        suite.addTest(RefererManagerTest.suite());
-        suite.addTest(IndexManagerTest.suite());             
-        suite.addTest(BookmarkManagerTest.suite());
-        suite.addTest(FileManagerTest.suite());
-        suite.addTest(PlanetManagerTest.suite()); 
+//        suite.addTest(WebsiteTest.suite());
+//        suite.addTest(ConfigManagerTest.suite());
+//        suite.addTest(PermissionsTest.suite());
+//        suite.addTest(UserManagerTest.suite());
+//        suite.addTest(WeblogManagerTest.suite());
+//        suite.addTest(RefererManagerTest.suite());
+//        suite.addTest(IndexManagerTest.suite());             
+//        suite.addTest(BookmarkManagerTest.suite());
+//        suite.addTest(FileManagerTest.suite());
+//        suite.addTest(PlanetManagerTest.suite()); 
+        suite.addTest(PlanetManagerLocalTest.suite()); 
         return suite;
     }
     public TestAll(String testName)

Modified: incubator/roller/trunk/tests/org/roller/presentation/velocity/plugins/textile/TextileTest.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/tests/org/roller/presentation/velocity/plugins/textile/TextileTest.java?rev=349595&r1=349594&r2=349595&view=diff
==============================================================================
--- incubator/roller/trunk/tests/org/roller/presentation/velocity/plugins/textile/TextileTest.java (original)
+++ incubator/roller/trunk/tests/org/roller/presentation/velocity/plugins/textile/TextileTest.java Mon Nov 28 18:44:45 2005
@@ -1,20 +1 @@
-/*
- * Created on Oct 31, 2003
- */
package org.roller.presentation.velocity.plugins.textile;

import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.roller.presentation.bookmarks.BookmarksActionTest;
-import org.roller.presentation.velocity.PagePlugin;
-import org.roller.presentation.velocity.plugins.textile.TextilePlugin;
-
/**
 * We really need to solve webtesting to adequately test our Presentation classes.
 * 
 * @author lance
 */
public class TextileTest extends TestCase
{
    String textileStr = "*strong* plain _emphasis_ * _emphaticStrong_ * ";
    String expected = "<p><strong>strong</strong> plain <em>emphasis</em> <strong> <em>emphaticStrong</em> </strong></p>";
  
    /* 
-     * This fails because Textile4J appears to place a tab (\t)
-     * at the beginning of the result.  If the result is .trim()'ed
-     * then it passes.
     */
    public void testTextile()
    {
        PagePlugin textile = new TextilePlugin();
        
        String result = textile.render(textileStr);
-        //System.out.println(expected);
-        //System.out.println(result);
        assertEquals("this will fail until Textile4J is fixed.", expected, result);         
    }
    
	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception
	{
        super.setUp();	       
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception
	{
	   super.tearDown();
	}
-
-    public static Test suite() 
-    {
-        return new TestSuite(TextileTest.class);
-    }

}
\ No newline at end of file
+/*
 * Created on Oct 31, 2003
 */
package org.roller.presentation.velocity.plugins.textile;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.roller.presentation.bookmarks.BookmarksActionTest;
import org.roller.model.PagePlugin;
import org.roller.presentation.velocity.plugins.textile.TextilePlugin;

/**
 * We really need to solve webtesting to adequately test our Presentation classes.
 * 
 * @author lance
 */
public class TextileTest extends TestCase
{
    String textileStr = "*strong* plain _emphasis_ * _emphaticStrong_ * ";
    String expected = "<p><strong>strong</strong> plain <em>emphasis</em> <strong> <em>emphaticStrong</em> </strong></p>";
  
    /* 
     * This fails because Textile4J appears to place a tab (\t)
     * at the beginning of the result.  If the result is .trim()'ed
     * then it passes.
     */
    public void testTextile()
    {
        PagePlugin textile = new TextilePlugin();
        
        String result = textile.render(textileStr);
        //System.out.println(expected);
        //System.out.println(result);
        assertEquals("this will fail until Textile4J is fixed.", expected, result);         
    }
    
	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception
	{
        super.setUp();	       
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception
	{
	   super.tearDown();
	}

    public static Test suite() 
    {
        return new TestSuite(TextileTest.class);
    }

}
\ No newline at end of file



Mime
View raw message