edu.yale.its.tp.portlets.calendar.adapter
Class ConfigurableHttpCalendarAdapter

java.lang.Object
  extended by edu.yale.its.tp.portlets.calendar.adapter.ConfigurableHttpCalendarAdapter
All Implemented Interfaces:
ICalendarAdapter, ISingleEventSupport

public final class ConfigurableHttpCalendarAdapter
extends java.lang.Object
implements ICalendarAdapter, ISingleEventSupport

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

Constructor Summary
ConfigurableHttpCalendarAdapter()
           
 
Method Summary
 CalendarEvent getEvent(CalendarConfiguration calendar, net.fortuna.ical4j.model.Period period, java.lang.String uid, java.lang.String recurrenceId, javax.servlet.http.HttpServletRequest request)
           
 CalendarEvent getEvent(CalendarConfiguration calendar, net.fortuna.ical4j.model.Period period, java.lang.String uid, java.lang.String recurrenceId, javax.portlet.PortletRequest request)
           
 java.util.Set<CalendarEvent> getEvents(CalendarConfiguration calendarConfiguration, net.fortuna.ical4j.model.Period period, javax.servlet.http.HttpServletRequest 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)
 java.util.Set<CalendarEvent> getEvents(CalendarConfiguration calendarConfiguration, net.fortuna.ical4j.model.Period period, 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)
 java.lang.String getLink(CalendarConfiguration calendar, net.fortuna.ical4j.model.Period period, javax.portlet.PortletRequest request)
          Get hyper link for the defined calendar.
protected  java.io.InputStream retrieveCalendarHttp(java.lang.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(java.lang.String cacheKeyPrefix)
           
 void setContentProcessor(IContentProcessor contentProcessor)
           
 void setCredentialsExtractor(ICredentialsExtractor credentialsExtractor)
           
 void setUrlCreator(IUrlCreator urlCreator)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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(java.lang.String cacheKeyPrefix)
Parameters:
cacheKeyPrefix - the cacheKeyPrefix to set

setCacheKeyGenerator

public void setCacheKeyGenerator(ICacheKeyGenerator cacheKeyGenerator)

getEvents

public java.util.Set<CalendarEvent> getEvents(CalendarConfiguration calendarConfiguration,
                                              net.fortuna.ical4j.model.Period period,
                                              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
period - time period for which to retrieve events
request - user's portlet request
Returns:
Set of events for this calendar and time period
Throws:
CalendarException
See Also:
ICalendarAdapter.getEvents(edu.yale.its.tp.portlets.calendar.CalendarConfiguration, net.fortuna.ical4j.model.Period, javax.portlet.PortletRequest)

getEvents

public java.util.Set<CalendarEvent> getEvents(CalendarConfiguration calendarConfiguration,
                                              net.fortuna.ical4j.model.Period period,
                                              javax.servlet.http.HttpServletRequest 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
period - time period for which to retrieve events
request - user's servlet request
Returns:
Set of events for this calendar and time period
Throws:
CalendarException
See Also:
ICalendarAdapter.getEvents(edu.yale.its.tp.portlets.calendar.CalendarConfiguration, net.fortuna.ical4j.model.Period, javax.servlet.http.HttpServletRequest)

getEvent

public CalendarEvent getEvent(CalendarConfiguration calendar,
                              net.fortuna.ical4j.model.Period period,
                              java.lang.String uid,
                              java.lang.String recurrenceId,
                              javax.servlet.http.HttpServletRequest request)
                       throws CalendarException
Specified by:
getEvent in interface ISingleEventSupport
Returns:
Throws:
CalendarException

getEvent

public CalendarEvent getEvent(CalendarConfiguration calendar,
                              net.fortuna.ical4j.model.Period period,
                              java.lang.String uid,
                              java.lang.String recurrenceId,
                              javax.portlet.PortletRequest request)
                       throws CalendarException
Specified by:
getEvent in interface ISingleEventSupport
Returns:
Throws:
CalendarException

getLink

public java.lang.String getLink(CalendarConfiguration calendar,
                                net.fortuna.ical4j.model.Period period,
                                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
period - time period for which to retrieve events
request - user's servlet request
Returns:
Set of events for this calendar and time period

retrieveCalendarHttp

protected java.io.InputStream retrieveCalendarHttp(java.lang.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 © 2009 Jasig. All Rights Reserved.