KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > blojsom > plugin > trackback > TrackbackModerationPlugin


1 /**
2  * Copyright (c) 2003-2006, David A. Czarnecki
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and the
9  * following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11  * following disclaimer in the documentation and/or other materials provided with the distribution.
12  * Neither the name of "David A. Czarnecki" and "blojsom" nor the names of its contributors may be used to
13  * endorse or promote products derived from this software without specific prior written permission.
14  * Products derived from this software may not be called "blojsom", nor may "blojsom" appear in their name,
15  * without prior written permission of David A. Czarnecki.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
18  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
19  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
21  * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */

31 package org.blojsom.plugin.trackback;
32
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35 import org.blojsom.blog.Blog;
36 import org.blojsom.blog.Entry;
37 import org.blojsom.plugin.Plugin;
38 import org.blojsom.plugin.PluginException;
39
40 import javax.servlet.http.HttpServletRequest JavaDoc;
41 import javax.servlet.http.HttpServletResponse JavaDoc;
42 import java.util.HashMap JavaDoc;
43 import java.util.Map JavaDoc;
44
45 /**
46  * Trackback moderation plugin
47  *
48  * @author David Czarnecki
49  * @version $Id: TrackbackModerationPlugin.java,v 1.1 2006/03/20 21:31:01 czarneckid Exp $
50  * @since blojsom 3.0
51  */

52 public class TrackbackModerationPlugin implements Plugin {
53
54     private Log _logger = LogFactory.getLog(TrackbackModerationPlugin.class);
55
56     // blog.properties property
57
public static final String JavaDoc TRACKBACK_MODERATION_ENABLED = "trackback-moderation-enabled";
58
59     // Trackback meta-data
60
public static final String JavaDoc BLOJSOM_TRACKBACK_MODERATION_PLUGIN_APPROVED = "BLOJSOM_TRACKBACK_MODERATION_PLUGIN_APPROVED";
61
62     /**
63      * Construct a new trackback moderation plugin
64      */

65     public TrackbackModerationPlugin() {
66     }
67
68     /**
69      * Initialize this plugin. This method only called when the plugin is instantiated.
70      *
71      * @throws org.blojsom.plugin.PluginException
72      * If there is an error initializing the plugin
73      */

74     public void init() throws PluginException {
75     }
76
77     /**
78      * Process the blog entries
79      *
80      * @param httpServletRequest Request
81      * @param httpServletResponse Response
82      * @param blog {@link Blog} instance
83      * @param context Context
84      * @param entries Blog entries retrieved for the particular request
85      * @return Modified set of blog entries
86      * @throws PluginException If there is an error processing the blog entries
87      */

88     public Entry[] process(HttpServletRequest JavaDoc httpServletRequest, HttpServletResponse JavaDoc httpServletResponse, Blog blog, Map JavaDoc context, Entry[] entries) throws PluginException {
89         moderateTrackback(httpServletRequest, httpServletResponse, blog, context, entries);
90
91         return entries;
92     }
93
94     /**
95      * Simple check to see if trackback moderation is enabled
96      * <p/>
97      * @param httpServletRequest Request
98      * @param httpServletResponse Response
99      * @param blog {@link Blog} instance
100      * @param context Context
101      * @param entries Blog entries retrieved for the particular request
102      * @throws PluginException If there is an error in moderating a trackback
103      */

104     protected void moderateTrackback(HttpServletRequest JavaDoc httpServletRequest, HttpServletResponse JavaDoc httpServletResponse, Blog blog, Map JavaDoc context, Entry[] entries) throws PluginException {
105         if ("true".equalsIgnoreCase(blog.getProperty(TRACKBACK_MODERATION_ENABLED))) {
106             if ("y".equalsIgnoreCase(httpServletRequest.getParameter(TrackbackPlugin.TRACKBACK_PARAM)) && blog.getBlogTrackbacksEnabled().booleanValue()) {
107                 Map JavaDoc trackbackMetaData;
108                 if (context.containsKey(TrackbackPlugin.BLOJSOM_PLUGIN_TRACKBACK_METADATA)) {
109                     trackbackMetaData = (Map JavaDoc) context.get(TrackbackPlugin.BLOJSOM_PLUGIN_TRACKBACK_METADATA);
110                 } else {
111                     trackbackMetaData = new HashMap JavaDoc();
112                 }
113                 
114                 trackbackMetaData.put(BLOJSOM_TRACKBACK_MODERATION_PLUGIN_APPROVED, Boolean.FALSE.toString());
115                 context.put(TrackbackPlugin.BLOJSOM_PLUGIN_TRACKBACK_METADATA, trackbackMetaData);
116
117                 if (_logger.isDebugEnabled()) {
118                     _logger.debug("Marking trackback as requiring approval");
119                 }
120             }
121         }
122     }
123
124     /**
125      * Perform any cleanup for the plugin. Called after {@link #process}.
126      *
127      * @throws org.blojsom.plugin.PluginException
128      * If there is an error performing cleanup for this plugin
129      */

130     public void cleanup() throws PluginException {
131     }
132
133     /**
134      * Called when BlojsomServlet is taken out of service
135      *
136      * @throws org.blojsom.plugin.PluginException
137      * If there is an error in finalizing this plugin
138      */

139     public void destroy() throws PluginException {
140     }
141 }
Popular Tags