org.jasig.portlet.calendar.adapter
Class ConfigurableHttpCalendarAdapter<T>

java.lang.Object
  extended by org.jasig.portlet.calendar.adapter.AbstractCalendarAdapter
      extended by org.jasig.portlet.calendar.adapter.ConfigurableHttpCalendarAdapter<T>
All Implemented Interfaces:
ICalendarAdapter

public final class ConfigurableHttpCalendarAdapter<T>
extends AbstractCalendarAdapter
implements ICalendarAdapter

Implementation of ICalendarAdapter that uses Commons HttpClient for retrieving CalendarEvents. This bean requires an EhCache Cache be provided. This bean also depends on instances of 3 different interfaces (default implementation listed in parenthesis):

By specifying alternate implementations for these interfaces, multiple instances of this class can be configured to consume CalendarEvents from a variety of different end points, for example an RSS feed behind basic auth, a CalendarKey implementation behind a shared secret, or behind CAS.

Version:
$Header: RefactoredHttpICalendarAdapter.java Exp $
Author:
Nicholas Blair, nblair@doit.wisc.edu

Field Summary
protected  org.apache.commons.logging.Log log
           
 
Constructor Summary
ConfigurableHttpCalendarAdapter()
           
 
Method Summary
 CalendarEventSet getEvents(CalendarConfiguration calendarConfiguration, org.joda.time.Interval interval, javax.portlet.PortletRequest request)
          Workflow for this implementation: consult the configured IUrlCreator for the url to request consult the cache to see if the fetch via HTTP is necessary (if not return the cached events) if the fetch is necessary, consult the ICredentialsExtractor for necessary Credentials Invoke retrieveCalendarHttp Pass the returned InputStream into the configured IContentProcessor Return the CalendarEvents (non-Javadoc)
 String getLink(CalendarConfiguration calendar, org.joda.time.Interval interval, javax.portlet.PortletRequest request)
          Get hyper link for the defined calendar.
protected  String getPeriodSpecificCacheKey(String baseKey, org.joda.time.Interval interval)
           
protected  InputStream retrieveCalendarHttp(String url, org.apache.commons.httpclient.Credentials credentials)
          Uses Commons HttpClient to retrieve the specified url (optionally with the provided Credentials.
 void setCache(net.sf.ehcache.Cache cache)
           
 void setCacheKeyGenerator(ICacheKeyGenerator cacheKeyGenerator)
           
 void setCacheKeyPrefix(String cacheKeyPrefix)
           
 void setContentProcessor(IContentProcessor contentProcessor)
           
 void setCredentialsExtractor(ICredentialsExtractor credentialsExtractor)
           
 void setUrlCreator(IUrlCreator urlCreator)
           
 
Methods inherited from class org.jasig.portlet.calendar.adapter.AbstractCalendarAdapter
getDescriptionKey, getParameters, getTitleKey, setDescriptionKey, setParameters, setTitleKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jasig.portlet.calendar.adapter.ICalendarAdapter
getDescriptionKey, getParameters, getTitleKey
 

Field Detail

log

protected final org.apache.commons.logging.Log log
Constructor Detail

ConfigurableHttpCalendarAdapter

public ConfigurableHttpCalendarAdapter()
Method Detail

setCache

public void setCache(net.sf.ehcache.Cache cache)
Parameters:
cache - the cache to set

setUrlCreator

public void setUrlCreator(IUrlCreator urlCreator)
Parameters:
urlCreator - the urlCreator to set

setCredentialsExtractor

public void setCredentialsExtractor(ICredentialsExtractor credentialsExtractor)
Parameters:
credentialsExtractor - the credentialsExtractor to set

setContentProcessor

public void setContentProcessor(IContentProcessor contentProcessor)
Parameters:
contentProcessor - the contentProcessor to set

setCacheKeyPrefix

public void setCacheKeyPrefix(String cacheKeyPrefix)
Parameters:
cacheKeyPrefix - the cacheKeyPrefix to set

setCacheKeyGenerator

public void setCacheKeyGenerator(ICacheKeyGenerator cacheKeyGenerator)

getEvents

public CalendarEventSet getEvents(CalendarConfiguration calendarConfiguration,
                                  org.joda.time.Interval interval,
                                  javax.portlet.PortletRequest request)
                           throws CalendarException
Workflow for this implementation:
  1. consult the configured IUrlCreator for the url to request
  2. consult the cache to see if the fetch via HTTP is necessary (if not return the cached events)
  3. if the fetch is necessary, consult the ICredentialsExtractor for necessary Credentials
  4. Invoke retrieveCalendarHttp
  5. Pass the returned InputStream into the configured IContentProcessor
  6. Return the CalendarEvents
(non-Javadoc)

Specified by:
getEvents in interface ICalendarAdapter
Parameters:
calendarConfiguration - calendar configuration for which to retrieve events
request - user's portlet request
Returns:
Set of events for this calendar and time period
Throws:
CalendarException
See Also:
org.jasig.portlet.calendar.adapter.ICalendarAdapter#getEvents(org.jasig.portlet.calendar.CalendarConfiguration, net.fortuna.ical4j.model.Period, javax.portlet.PortletRequest)

getPeriodSpecificCacheKey

protected String getPeriodSpecificCacheKey(String baseKey,
                                           org.joda.time.Interval interval)

getLink

public String getLink(CalendarConfiguration calendar,
                      org.joda.time.Interval interval,
                      javax.portlet.PortletRequest request)
Description copied from interface: ICalendarAdapter
Get hyper link for the defined calendar. In cases where the calendar resource has a web interface, this method allows provides access to the url.

Specified by:
getLink in interface ICalendarAdapter
Parameters:
calendar - calendar configuration for which to retrieve events
request - user's servlet request
Returns:
Set of events for this calendar and time period

retrieveCalendarHttp

protected InputStream retrieveCalendarHttp(String url,
                                           org.apache.commons.httpclient.Credentials credentials)
                                    throws CalendarException
Uses Commons HttpClient to retrieve the specified url (optionally with the provided Credentials. The response body is returned as an InputStream.

Parameters:
url - URL of the calendar to be retrieved
credentials - Credentials to use with the request, if necessary (null is ok if credentials not required)
Returns:
the body of the http response as a stream
Throws:
CalendarException - wraps all potential Exception types


Copyright © 2012 Jasig. All Rights Reserved.