Source Code Cross Referenced for ShowAuthorsPlugIn.java in  » RSS-RDF » curn » org » clapper » curn » plugins » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » RSS RDF » curn » org.clapper.curn.plugins 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*---------------------------------------------------------------------------*\
002:          $Id: ShowAuthorsPlugIn.java 7041 2007-09-09 01:04:47Z bmc $
003:          ---------------------------------------------------------------------------
004:          This software is released under a BSD-style license:
005:
006:          Copyright (c) 2004-2007 Brian M. Clapper. All rights reserved.
007:
008:          Redistribution and use in source and binary forms, with or without
009:          modification, are permitted provided that the following conditions are
010:          met:
011:
012:          1. Redistributions of source code must retain the above copyright notice,
013:             this list of conditions and the following disclaimer.
014:
015:          2. The end-user documentation included with the redistribution, if any,
016:             must include the following acknowlegement:
017:
018:                "This product includes software developed by Brian M. Clapper
019:                (bmc@clapper.org, http://www.clapper.org/bmc/). That software is
020:                copyright (c) 2004-2007 Brian M. Clapper."
021:
022:             Alternately, this acknowlegement may appear in the software itself,
023:             if wherever such third-party acknowlegements normally appear.
024:
025:          3. Neither the names "clapper.org", "curn", nor any of the names of the
026:             project contributors may be used to endorse or promote products
027:             derived from this software without prior written permission. For
028:             written permission, please contact bmc@clapper.org.
029:
030:          4. Products derived from this software may not be called "curn", nor may
031:             "clapper.org" appear in their names without prior written permission
032:             of Brian M. Clapper.
033:
034:          THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035:          WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
036:          MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
037:          NO EVENT SHALL BRIAN M. CLAPPER BE LIABLE FOR ANY DIRECT, INDIRECT,
038:          INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
039:          NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
040:          DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
041:          THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
042:          (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
043:          THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
044:        \*---------------------------------------------------------------------------*/
045:
046:        package org.clapper.curn.plugins;
047:
048:        import org.clapper.curn.CurnConfig;
049:        import org.clapper.curn.CurnException;
050:        import org.clapper.curn.FeedInfo;
051:        import org.clapper.curn.MainConfigItemPlugIn;
052:        import org.clapper.curn.FeedConfigItemPlugIn;
053:        import org.clapper.curn.PostFeedParsePlugIn;
054:        import org.clapper.curn.parser.RSSChannel;
055:        import org.clapper.curn.parser.RSSItem;
056:
057:        import org.clapper.util.classutil.ClassUtil;
058:        import org.clapper.util.config.ConfigurationException;
059:        import org.clapper.util.logging.Logger;
060:
061:        import java.util.HashMap;
062:        import java.util.Map;
063:        import org.clapper.curn.FeedCache;
064:
065:        /**
066:         * The <tt>ShowAuthorsPlugIn</tt> handles enabling/disabling display of the
067:         * "author" fields on feeds and feed items. It intercepts the following
068:         * configuration parameters:
069:         *
070:         * <table border="1">
071:         *   <tr valign="top" align="left">
072:         *     <th align="left">Section</th>
073:         *     <th align="left">Parameter</th>
074:         *     <th align="left">Meaning</th>
075:         *   </tr>
076:         *   <tr valign="top">
077:         *     <td><tt>[curn]</tt></td>
078:         *     <td><tt>ShowAuthors</tt></td>
079:         *     <td>Default (global) value for the show authors capability.
080:         *         Defaults to false.</td>
081:         *   </tr>
082:         *   <tr valign="top">
083:         *     <td><tt>[Feed<i>xxx</i>]</tt></td>
084:         *     <td><tt>ShowAuthors</tt></td>
085:         *     <td>Whether or not to show author data for the feed. If not specified,
086:         *         the global default is used.</td>
087:         *   </tr>
088:         * </table>
089:         *
090:         * @version <tt>$Revision: 7041 $</tt>
091:         */
092:        public class ShowAuthorsPlugIn implements  MainConfigItemPlugIn,
093:                FeedConfigItemPlugIn, PostFeedParsePlugIn {
094:            /*----------------------------------------------------------------------*\
095:                                     Private Constants
096:            \*----------------------------------------------------------------------*/
097:
098:            private static final String VAR_SHOW_AUTHORS = "ShowAuthors";
099:
100:            /*----------------------------------------------------------------------*\
101:                                    Private Data Items
102:            \*----------------------------------------------------------------------*/
103:
104:            /**
105:             * Feed author flag, by feed
106:             */
107:            private Map<FeedInfo, Boolean> perFeedShowAuthorsFlag = new HashMap<FeedInfo, Boolean>();
108:
109:            /**
110:             * Global default
111:             */
112:            private boolean showAuthorsDefault = false;
113:
114:            /**
115:             * For log messages
116:             */
117:            private static final Logger log = new Logger(
118:                    ShowAuthorsPlugIn.class);
119:
120:            /*----------------------------------------------------------------------*\
121:                                        Constructor
122:            \*----------------------------------------------------------------------*/
123:
124:            /**
125:             * Default constructor (required).
126:             */
127:            public ShowAuthorsPlugIn() {
128:                // Nothing to do
129:            }
130:
131:            /*----------------------------------------------------------------------*\
132:                       Public Methods Required by *PlugIn Interfaces
133:            \*----------------------------------------------------------------------*/
134:
135:            /**
136:             * Get a displayable name for the plug-in.
137:             *
138:             * @return the name
139:             */
140:            public String getPlugInName() {
141:                return "Show Authors";
142:            }
143:
144:            /**
145:             * Get the sort key for this plug-in.
146:             *
147:             * @return the sort key string.
148:             */
149:            public String getPlugInSortKey() {
150:                return ClassUtil.getShortClassName(getClass().getName());
151:            }
152:
153:            /**
154:             * Initialize the plug-in. This method is called before any of the
155:             * plug-in methods are called.
156:             *
157:             * @throws CurnException on error
158:             */
159:            public void initPlugIn() throws CurnException {
160:            }
161:
162:            /**
163:             * Called immediately after <i>curn</i> has read and processed a
164:             * configuration item in the main [curn] configuration section. All
165:             * configuration items are passed, one by one, to each loaded plug-in.
166:             * If a plug-in class is not interested in a particular configuration
167:             * item, this method should simply return without doing anything. Note
168:             * that some configuration items may simply be variable assignment;
169:             * there's no real way to distinguish a variable assignment from a
170:             * blessed configuration item.
171:             *
172:             * @param sectionName  the name of the configuration section where
173:             *                     the item was found
174:             * @param paramName    the name of the parameter
175:             * @param config       the {@link CurnConfig} object
176:             * 
177:             * @throws CurnException on error
178:             *
179:             * @see CurnConfig
180:             */
181:            public void runMainConfigItemPlugIn(String sectionName,
182:                    String paramName, CurnConfig config) throws CurnException {
183:                try {
184:                    if (paramName.equals(VAR_SHOW_AUTHORS)) {
185:                        showAuthorsDefault = config.getRequiredBooleanValue(
186:                                sectionName, paramName);
187:                    }
188:                }
189:
190:                catch (ConfigurationException ex) {
191:                    throw new CurnException(ex);
192:                }
193:            }
194:
195:            /**
196:             * Called immediately after <i>curn</i> has read and processed a
197:             * configuration item in a "feed" configuration section. All
198:             * configuration items are passed, one by one, to each loaded plug-in.
199:             * If a plug-in class is not interested in a particular configuration
200:             * item, this method should simply return without doing anything. Note
201:             * that some configuration items may simply be variable assignment;
202:             * there's no real way to distinguish a variable assignment from a
203:             * blessed configuration item.
204:             *
205:             * @param sectionName  the name of the configuration section where
206:             *                     the item was found
207:             * @param paramName    the name of the parameter
208:             * @param config       the active configuration
209:             * @param feedInfo     partially complete <tt>FeedInfo</tt> object
210:             *                     for the feed. The URL is guaranteed to be
211:             *                     present, but no other fields are.
212:             * 
213:             * @return <tt>true</tt> to continue processing the feed,
214:             *         <tt>false</tt> to skip it
215:             *
216:             * @throws CurnException on error
217:             *
218:             * @see CurnConfig
219:             * @see FeedInfo
220:             * @see FeedInfo#getURL
221:             */
222:            public boolean runFeedConfigItemPlugIn(String sectionName,
223:                    String paramName, CurnConfig config, FeedInfo feedInfo)
224:                    throws CurnException {
225:                try {
226:                    if (paramName.equals(VAR_SHOW_AUTHORS)) {
227:                        boolean flag = config.getRequiredBooleanValue(
228:                                sectionName, paramName);
229:                        perFeedShowAuthorsFlag.put(feedInfo, flag);
230:                        log.debug("[" + sectionName + "]: " + paramName + "="
231:                                + flag);
232:                    }
233:
234:                    return true;
235:                }
236:
237:                catch (ConfigurationException ex) {
238:                    throw new CurnException(ex);
239:                }
240:            }
241:
242:            /**
243:             * Called immediately after a feed is parsed, but before it is
244:             * otherwise processed. This method can return <tt>false</tt> to signal
245:             * <i>curn</i> that the feed should be skipped. For instance, a plug-in
246:             * that filters on the parsed feed data could use this method to weed
247:             * out non-matching feeds before they are downloaded. Similarly, a
248:             * plug-in that edits the parsed data (removing or editing individual
249:             * items, for instance) could use method to do so.
250:             *
251:             * @param feedInfo  the {@link FeedInfo} object for the feed that
252:             *                  has been downloaded and parsed.
253:             * @param feedCache the feed cache
254:             * @param channel   the parsed channel data
255:             *
256:             * @return <tt>true</tt> if <i>curn</i> should continue to process the
257:             *         feed, <tt>false</tt> to skip the feed. A return value of
258:             *         <tt>false</tt> aborts all further processing on the feed.
259:             *         In particular, <i>curn</i> will not pass the feed along to
260:             *         other plug-ins that have yet to be notified of this event.
261:             *
262:             * @throws CurnException on error
263:             *
264:             * @see RSSChannel
265:             * @see FeedInfo
266:             */
267:            public boolean runPostFeedParsePlugIn(FeedInfo feedInfo,
268:                    FeedCache feedCache, RSSChannel channel)
269:                    throws CurnException {
270:                Boolean showBoxed = perFeedShowAuthorsFlag.get(feedInfo);
271:                boolean show = showAuthorsDefault;
272:
273:                if (showBoxed != null)
274:                    show = showBoxed;
275:
276:                log.debug("Post-parse, " + feedInfo.getURL() + ": showAuthors="
277:                        + show);
278:
279:                if (!show) {
280:                    log.debug("Removing author fields from feed \""
281:                            + feedInfo.getURL().toString() + "\"");
282:
283:                    channel.clearAuthors();
284:                    for (RSSItem item : channel.getItems())
285:                        item.clearAuthors();
286:                }
287:
288:                return true;
289:            }
290:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.