/*
* Created on 12-May-2003
*/
package net.sf.jportlet.portlets.rss;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import net.sf.jportlet.portlet.Portlet;
import net.sf.jportlet.portlet.PortletConfig;
import net.sf.jportlet.portlet.PortletException;
import net.sf.jportlet.portlet.PortletLog;
import net.sf.jportlet.portlet.PortletRequest;
import net.sf.jportlet.portlets.AbstractXslPortlet;
/**
* @author <a href="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
*/
public class RSSPortlet
extends AbstractXslPortlet
{
//~ Static fields/initializers ---------------------------------------------
public static final String CONFIG_URL = "url";
//~ Instance fields --------------------------------------------------------
private URL _url;
//~ Methods ----------------------------------------------------------------
/**
* @see net.sf.jportlet.portlet.Portlet#init(net.sf.jportlet.portlet.PortletConfig)
*/
public void init( PortletConfig portletConfig )
throws PortletException
{
super.init( portletConfig );
String url = portletConfig.getInitParameter( CONFIG_URL );
if ( url == null )
{
throw new PortletException( "Missing parameter: " + CONFIG_URL );
}
try
{
_url = new URL( url );
}
catch ( MalformedURLException m )
{
throw new PortletException( "Bad URL: " + url, m );
}
}
/**
* @see net.sf.jportlet.portlets.AbstractXslPortlet#openXmlInputStream(net.sf.jportlet.portlet.PortletRequest)
*/
protected InputStream openXmlInputStream( PortletRequest request )
throws PortletException, IOException
{
return _url.openStream( );
}
/**
* @see net.sf.jportlet.portlets.AbstractXslPortlet#openXslInputStream(net.sf.jportlet.portlet.PortletRequest)
*/
protected InputStream openXslInputStream( PortletRequest request )
throws PortletException, IOException
{
Portlet.Markup markup = request.getClient( ).getMarkup( );
InputStream in = findInputStream( "xsl." + markup, request );
if ( in == null )
{
PortletLog log = getLog( );
String path = "net/sf/jportlet/portlets/rss/" + markup + ".xsl";
if ( log.isDebugEnabled( ) )
{
log.debug( "Using default XSL: " + path );
}
in = getClass( ).getClassLoader( ).getResourceAsStream( path );
if ( in == null )
{
throw new PortletException( "Markup not supported: " + markup );
}
}
return in;
}
}