com.xpn.xwiki.render.macro.rss
Class RSSMacro

java.lang.Object
  extended by org.radeox.macro.BaseMacro
      extended by org.radeox.macro.BaseLocaleMacro
          extended by com.xpn.xwiki.render.macro.rss.RSSMacro
All Implemented Interfaces:
java.lang.Comparable, org.radeox.macro.LocaleMacro, org.radeox.macro.Macro

public class RSSMacro
extends org.radeox.macro.BaseLocaleMacro

A Radeox MacroFilter for rendering an RSS feed.

Version:
0.2d
Author:
Joe Germuska

Field Summary
private static java.lang.String DESCRIPTION
           
private static java.lang.String NAME
           
private static char NEWLINE
           
private static java.lang.String[] PARAM_DESCRIPTION
           
private static java.lang.String[] PARAM_NAMES
           
 
Fields inherited from class org.radeox.macro.BaseMacro
description, initialContext, paramDescription
 
Constructor Summary
RSSMacro()
           
 
Method Summary
 void execute(java.io.Writer writer, org.radeox.macro.parameter.MacroParameter parameter)
          Process the macro.
 java.lang.String getDescription()
           
 java.lang.String getLocaleKey()
           
 java.lang.String getName()
           
 java.lang.String[] getParamDescription()
           
private  RSSMacroParameters processParameters(org.radeox.macro.parameter.MacroParameter parameter)
          Transform the input parameters into RSSMacroParameters object.
private  void renderEntries(com.sun.syndication.feed.synd.SyndFeed feed, java.io.Writer writer, RSSMacroParameters paramObj)
          Render as many of the given Channel's items as needed, according to the value of the optional count parameter and the number of items in the feed.
private  void renderEntry(com.sun.syndication.feed.synd.SyndEntry entry, java.io.Writer writer, RSSMacroParameters paramObj)
          Render the given RSS Item according to whether or not the parameters call for CSS processing.
private  void renderEntryCSS(com.sun.syndication.feed.synd.SyndEntry entry, java.lang.StringBuffer buf, RSSMacroParameters paramObj)
          Render the given Item using <div> tags with CSS class attributes.
private  void renderEntryDefault(com.sun.syndication.feed.synd.SyndEntry entry, java.lang.StringBuffer buf, RSSMacroParameters paramObj)
          Render the given Item using Radeox macros.
private  void renderImage(com.sun.syndication.feed.synd.SyndFeed feed, java.io.Writer writer, RSSMacroParameters paramObj)
          If a parameter was passed with the name "img" and the literal value "true", render the image from the channel (if it has one.) This requires the use of named parameters.
private  void renderSearch(com.sun.syndication.feed.synd.SyndFeed feed, java.io.Writer writer, RSSMacroParameters paramObj)
          CSS styles are used because there is no way to render this using 'default' because org.snipsnap.render.macro.FieldMacro only permits form submission to other snips.
private  void renderTitle(com.sun.syndication.feed.synd.SyndFeed feed, java.io.Writer writer, RSSMacroParameters paramObj)
          Render the 'title' of the given RSS Channel to the Writer.
private  void renderTitleCSS(com.sun.syndication.feed.synd.SyndFeed feed, java.lang.StringBuffer buf)
          Render the title from the given Channel to the given StringBuffer, using CSS styled 'div' tags.
private  void renderTitleDefault(com.sun.syndication.feed.synd.SyndFeed feed, java.lang.StringBuffer buf)
          Render the title from the given Channel to the given StringBuffer, using standard Radeox filtering tags.
 
Methods inherited from class org.radeox.macro.BaseLocaleMacro
setInitialContext
 
Methods inherited from class org.radeox.macro.BaseMacro
compareTo, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NAME

private static final java.lang.String NAME
See Also:
Constant Field Values

DESCRIPTION

private static final java.lang.String DESCRIPTION
See Also:
Constant Field Values

PARAM_DESCRIPTION

private static final java.lang.String[] PARAM_DESCRIPTION

PARAM_NAMES

private static final java.lang.String[] PARAM_NAMES

NEWLINE

private static final char NEWLINE
See Also:
Constant Field Values
Constructor Detail

RSSMacro

public RSSMacro()
Method Detail

getLocaleKey

public java.lang.String getLocaleKey()

getName

public java.lang.String getName()
Specified by:
getName in interface org.radeox.macro.Macro
Overrides:
getName in class org.radeox.macro.BaseLocaleMacro

execute

public void execute(java.io.Writer writer,
                    org.radeox.macro.parameter.MacroParameter parameter)
             throws java.lang.IllegalArgumentException,
                    java.io.IOException
Process the macro.

Specified by:
execute in interface org.radeox.macro.Macro
Specified by:
execute in class org.radeox.macro.BaseMacro
Parameters:
writer - the output writer
parameter - the input parameters of the macro.
Throws:
java.lang.IllegalArgumentException
java.io.IOException - from calls to writer.write() TODO Make commons-digester understand more different RSS feeds, or switch to a better RSS library.

renderEntries

private void renderEntries(com.sun.syndication.feed.synd.SyndFeed feed,
                           java.io.Writer writer,
                           RSSMacroParameters paramObj)
                    throws java.io.IOException
Render as many of the given Channel's items as needed, according to the value of the optional count parameter and the number of items in the feed.

Parameters:
writer - the output writer
paramObj - our parameter helper object
Throws:
java.io.IOException

renderEntry

private void renderEntry(com.sun.syndication.feed.synd.SyndEntry entry,
                         java.io.Writer writer,
                         RSSMacroParameters paramObj)
                  throws java.io.IOException
Render the given RSS Item according to whether or not the parameters call for CSS processing.

Parameters:
writer - the output writer
paramObj - our parameter helper object
Throws:
java.io.IOException - from calls to writer.write()

renderEntryDefault

private void renderEntryDefault(com.sun.syndication.feed.synd.SyndEntry entry,
                                java.lang.StringBuffer buf,
                                RSSMacroParameters paramObj)
Render the given Item using Radeox macros.

Parameters:
buf - the StringBuffer we're using to prepare the output
paramObj - our parameter helper object

renderEntryCSS

private void renderEntryCSS(com.sun.syndication.feed.synd.SyndEntry entry,
                            java.lang.StringBuffer buf,
                            RSSMacroParameters paramObj)
Render the given Item using <div> tags with CSS class attributes.

Parameters:
buf - the StringBuffer we're using to prepare the output
paramObj - our parameter helper object TODO Figure out how to stop Radeox from filtering the URLs

renderTitle

private void renderTitle(com.sun.syndication.feed.synd.SyndFeed feed,
                         java.io.Writer writer,
                         RSSMacroParameters paramObj)
                  throws java.io.IOException
Render the 'title' of the given RSS Channel to the Writer.

Parameters:
feed - the RSS Channel we retrieved via the Feed URL
writer - the output writer
paramObj - our parameter helper object
Throws:
java.io.IOException - from calls to writer.write()

renderTitleDefault

private void renderTitleDefault(com.sun.syndication.feed.synd.SyndFeed feed,
                                java.lang.StringBuffer buf)
Render the title from the given Channel to the given StringBuffer, using standard Radeox filtering tags.

Parameters:
feed - the RSS Channel we retrieved via the Feed URL
buf - the StringBuffer we're using to prepare the output

renderTitleCSS

private void renderTitleCSS(com.sun.syndication.feed.synd.SyndFeed feed,
                            java.lang.StringBuffer buf)
Render the title from the given Channel to the given StringBuffer, using CSS styled 'div' tags. In this case, the title will be enclosed in a <div> with the class rss.channel.title. If the channel includes a link, the title will be rendered as a link to that URL, and the <a> tag will also be of class rss.channel.title

Parameters:
feed - the RSS Channel we retrieved via the Feed URL
buf - the StringBuffer we're using to prepare the output TODO Figure out how to stop Radeox from filtering the URLs

renderImage

private void renderImage(com.sun.syndication.feed.synd.SyndFeed feed,
                         java.io.Writer writer,
                         RSSMacroParameters paramObj)
                  throws java.io.IOException
If a parameter was passed with the name "img" and the literal value "true", render the image from the channel (if it has one.) This requires the use of named parameters.

Parameters:
feed - the RSS Channel we retrieved via the Feed URL
writer - the output writer
paramObj - our parameter helper object
Throws:
java.io.IOException - from calls to writer.write()

renderSearch

private void renderSearch(com.sun.syndication.feed.synd.SyndFeed feed,
                          java.io.Writer writer,
                          RSSMacroParameters paramObj)
                   throws java.io.IOException
CSS styles are used because there is no way to render this using 'default' because org.snipsnap.render.macro.FieldMacro only permits form submission to other snips. Body of this method essentially adapted from that implementation. Entire block will be wrapped in a div, class 'rss.textinput'. Description will be in a div, class 'rss.textinput.description'. <form> element will be class 'rss.textinput.form'. Field will be an HTML <input> (type text) tag, class 'rss.textinput.field'. Submit button will be an HTML <input> (type submit), class 'rss.textinput.submit'.

Parameters:
feed - the RSS Channel we retrieved via the Feed URL
writer - the output writer
paramObj - our parameter helper object
Throws:
java.io.IOException - from calls to writer.write()

getParamDescription

public java.lang.String[] getParamDescription()
Specified by:
getParamDescription in interface org.radeox.macro.Macro
Overrides:
getParamDescription in class org.radeox.macro.BaseLocaleMacro
Returns:
the MacroFilter's parameter descriptions:
  • feed: url of an RSS feed
  • ?img: if 'true' and if feed has an image, image will be included
  • ?align: if an image will be included, use this alignment
  • ?css: if 'true', elements will be created with CSS styles; otherwise, static formatting methods will be used
  • ?count: an integer, the maximum number of feed items to display
  • ?full: if 'true', descriptions for each item will be included. Otherwise, just titles.
  • ?search: if 'true' and if feed has a search field, field will be included
Note that all parameters must be passed using names.

getDescription

public java.lang.String getDescription()
Specified by:
getDescription in interface org.radeox.macro.Macro
Overrides:
getDescription in class org.radeox.macro.BaseLocaleMacro
Returns:
the MacroFilter's description: 'Use to aggregate RSS feeds'.

processParameters

private RSSMacroParameters processParameters(org.radeox.macro.parameter.MacroParameter parameter)
                                      throws java.lang.IllegalArgumentException
Transform the input parameters into RSSMacroParameters object.

Parameters:
parameter - the parameters as prepared by the Radeox system.
Returns:
a parameters helper object
Throws:
java.lang.IllegalArgumentException - if the 'feed' named parameter is missing, or is a malformed URL, or if any of the other parameter values are not of the correct types. Note that unknown parameters will simply be ignored, and all parameters must be passed using names.
See Also:
RSSMacroParameters


Copyright 2003 Ludovic Dubost