if(debug)
System.out.println( "Enter Rss Channel Action" );
// Try to retrieve tile context
ComponentContext context = ComponentContext.getContext( request );
if( context == null )
{
throw new ServletException( "This action must be called by a Tile, not directly" );
}
ActionErrors errors = new ActionErrors();
org.apache.commons.digester.rss.Channel channel = null;
// -- Retrieve parameters --
// Urls can come from a list, or from a single attribute.
List channels = (List)context.getAttribute( CHANNEL_URLS_KEY );
if( channels == null )
{
Object url = context.getAttribute( CHANNEL_URL_KEY );
channels = new ArrayList(1);
channels.add(url);
}
//channels.add("http://www.newsforge.com/newsforge.rss");
//channels.add("http://xmlhack.com/rss.php");
//channels.add("http://lwn.net/headlines/rss");
// channels.trimToSize();
if(debug)
System.out.println( "urls count" + channels.size() ) ;
// -- Loop through channels --
ArrayList channelBeans = new ArrayList(channels.size());
try {
for (int i=0; i<channels.size(); i++) {
RSSDigester digester = new RSSDigester();
String url = (String)channels.get(i);
// Add application path if needed
if( url.startsWith("/") )
{
url = toFullUrl( request, url );
}
if(debug) System.out.println( "Channel url=" + url) ;
Channel obj = (Channel)digester.parse(url);
if(debug) System.out.println( "Channel:" + obj) ;
//System.out.println( "Channel.items:" + obj.getI) ;
channelBeans.add(obj);
}
}
catch (Throwable t) {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("rss.access.error"));
servlet.log(t.toString());
}
// -- Handle Errors ---
if (!errors.empty()) {
saveErrors(request, errors);
if (mapping.getInput()!=null)
return (new ActionForward(mapping.getInput()));
// If no input page, use error forwarding
if(debug)
System.out.println( "Exit Rss Channel Action : error" );
return (mapping.findForward("error"));
}
// -- Save Bean, and Continue ---
if(debug)
System.out.println( "Exit Rss Channel Action" );
//request.setAttribute(CHANNELS_KEY,channelBeans);
// Use Tile context to pass channels
context.putAttribute( CHANNELS_KEY,channelBeans);
return (mapping.findForward("continue"));
} // ---- End perform ----