org.sakaiproject.component.legacy.calendar
Class BaseCalendarService

java.lang.Object
  extended byorg.sakaiproject.component.legacy.calendar.BaseCalendarService
All Implemented Interfaces:
CacheRefresher, CalendarService, EntityProducer, StorageUser
Direct Known Subclasses:
DbCalendarService

public abstract class BaseCalendarService
extends Object
implements CalendarService, StorageUser, CacheRefresher

BaseCalendarService is an base implementation of the CHEF CalendarService, implemented as a Turbine service. Extension classes implement object creation, access and storage.

Version:
$Revision: 6016 $
Author:
University of Michigan, CHEF Software Development Team

Nested Class Summary
 class BaseCalendarService.BaseCalendarEdit
          Calendar implementation
 class BaseCalendarService.BaseCalendarEventEdit
          CalendarEvent implementation
protected  class BaseCalendarService.LayoutRow
          This is a container for a list of columns, plus the timerange for all the events contained in the row.
protected  class BaseCalendarService.LayoutTableCell
          This is a single cell in a layout table (an instance of SingleDayLayoutTable).
protected  class BaseCalendarService.SingleDayLayoutTable
          Table used to layout a single day, with potentially overlapping events.
protected static interface BaseCalendarService.Storage
          Storage implementation
 
Nested classes inherited from class org.sakaiproject.service.legacy.entity.EntityProducer
EntityProducer.ChangeType
 
Field Summary
protected static String CALENDAR_PARAMETER_BASE_NAME
           
protected static String COLUMN_NODE_NAME
           
protected static String DAILY_START_TIME_PARAMETER_NAME
           
protected static String DAY_VIEW_XLST_FILENAME
          PDF file generation
protected static String DESCRIPTION_NODE
           
protected static String EVENT_NODE_NAME
           
protected static String FACULTY_EVENT_ATTRIBUTE_NAME
           
protected static String FACULTY_NODE
           
protected static String FROM_ATTRIBUTE_STRING
           
protected static String GROUP_NODE
           
protected static String HOUR_MINUTE_SEPARATOR
           
protected static String LIST_DATE_ATTRIBUTE_NAME
           
protected static String LIST_DAY_OF_WEEK_ATTRIBUTE_NAME
           
protected static String LIST_NODE_NAME
           
protected static String LIST_VIEW_XLST_FILENAME
           
protected  boolean m_caching
          Configuration: cache, or not.
protected  Cache m_calendarCache
          A Cache object for caching: calendars keyed by reference.
protected  EntityManager m_entityManager
          Dependency: EntityManager.
protected  Hashtable m_eventCaches
          A bunch of caches for events: keyed by calendar id, the cache is keyed by event reference.
protected  IdService m_IdService
          Dependency: IdService.
protected  Logger m_logger
          Dependency: logging service
protected  MemoryService m_memoryService
          Dependency: MemoryService.
protected  String m_relativeAccessPoint
          The initial portion of a relative access point URL.
protected  ServerConfigurationService m_serverConfigurationService
          Dependency: ServerConfigurationService.
protected  BaseCalendarService.Storage m_storage
          A Storage object for access to calendars and events.
protected static String MAX_CONCURRENT_EVENTS_NAME
           
protected static int MAX_OVERLAPPING_COLUMNS
           
protected static long MILLISECONDS_IN_DAY
           
protected static long MILLISECONDS_IN_HOUR
           
protected static long MILLISECONDS_IN_MINUTE
           
protected static long MINIMUM_EVENT_LENGTH_IN_MSECONDS
           
protected static String MONTH_NODE_NAME
           
protected static String MONTH_VIEW_XLST_FILENAME
           
protected static String PDF_MIME_TYPE
           
protected static String PLACE_NODE
           
protected static String ROW_NODE_NAME
           
protected static int SCHEDULE_INTERVAL_IN_MINUTES
           
protected static String SCHEDULE_NODE
           
protected static String SCHEDULE_TYPE_PARAMETER_NAME
           
protected static String START_DAY_WEEK_ATTRIBUTE_NAME
           
protected static String START_TIME_ATTRIBUTE_NAME
           
protected static String SUB_EVENT_NODE_NAME
           
protected static String TIME_RANGE_PARAMETER_NAME
           
protected static int TIMESLOT_FOR_OVERLAP_DETECTION_IN_MINUTES
           
protected static String TITLE_NODE
           
protected static String TO_ATTRIBUTE_STRING
           
protected static String TYPE_NODE
           
protected static String UID_NODE
           
protected static String USER_NAME_PARAMETER_NAME
           
protected static String WEEK_VIEW_XLST_FILENAME
           
 
Fields inherited from interface org.sakaiproject.service.legacy.calendar.CalendarService
DAY_VIEW, EVENT_ADD_CALENDAR, EVENT_IMPORT_CALENDAR, EVENT_MODIFY_CALENDAR, EVENT_READ_CALENDAR, EVENT_REMOVE_CALENDAR, LIST_VIEW, MOD_ALL, MOD_NA, MOD_PRIOR, MOD_REST, MOD_THIS, MONTH_VIEW, REF_TYPE_CALENDAR, REF_TYPE_CALENDAR_PDF, REF_TYPE_EVENT, REFERENCE_ROOT, SERVICE_NAME, UNKNOWN_VIEW, WEEK_VIEW
 
Constructor Summary
BaseCalendarService()
           
 
Method Summary
 CalendarEdit addCalendar(String ref)
          Add a new calendar.
 boolean allowAddCalendar(String ref)
          check permissions for addCalendar().
 boolean allowGetCalendar(String ref)
          check permissions for getCalendar().
 boolean allowImportCalendar(String ref)
          check permissions for importing calendar events
 boolean allowRemoveCalendar(String ref)
          check permissions for removeCalendar().
 boolean allowUpdateCalendar(String ref)
          check permissions for editCalendar()
 String archive(String siteId, Document doc, Stack stack, String archivePath, List attachments)
          Archive the resources for the given site.
 String calendarPdfReference(String context, String id, int scheduleType, List calendars, String timeRangeString, String userName, TimeRange dailyTimeRange)
          Access the internal reference which can be used to access the calendar-in-pdf format from within the system.
 String calendarReference(String context, String id)
          Access the internal reference which can be used to access the calendar from within the system.
 void cancelCalendar(CalendarEdit edit)
          Cancel the changes made to a CalendarEdit object, and release the lock.
 void commitCalendar(CalendarEdit edit)
          Commit the changes made to a CalendarEdit object, and release the lock.
 void destroy()
          Returns to uninitialized state.
protected  void disableSchedule(Site site)
          Remove a calendar for the site.
protected  String dumpTimeRange(TimeRange timeRange)
          Debugging routine to get a string for a TimeRange.
 CalendarEdit editCalendar(String ref)
          Get a locked calendar object for editing.
protected  void enableSchedule(Site site)
          Setup a calendar for the site.
 String eventReference(String context, String calendarId, String id)
          Access the internal reference which can be used to access the event from within the system.
protected  Calendar findCalendar(String ref)
          Find the calendar, in cache or info store - cache it if newly found.
protected  void generatePDF(Document doc, String xslFileName, OutputStream streamOut)
          Takes a DOM structure and renders a PDF
protected  void generateXMLDocument(int scheduleType, Document doc, TimeRange timeRange, TimeRange dailyTimeRange, List calendarReferenceList, String userID)
           
protected  void generateXMLEvent(Document doc, Element parent, CalendarEvent event, String eventNodeName, TimeRange containingTimeRange, boolean forceMinimumTime, boolean hideGroupIfNoSpace, boolean performEndTimeKludge)
          Generates the XML for an event.
protected  String getAccessPoint(boolean relative)
          Access the partial URL that forms the root of calendar URLs.
 Calendar getCalendar(String ref)
          Return a specific calendar.
protected  List getCalendarListFromParameters(Properties parameters)
          Given a Properties structure, generates a list of calendar references.
protected  String getCalendarListParameters(List calendars)
          Given a list of calendar references, formats a URL fragment of parameters.
 List getCalendars()
          Return a List of all the defined calendars.
protected  TimeRange getDailyStartTimeFromParameters(Properties parameters)
           
 Time getDate(Entity r)
          Access the resource date.
protected  String getDateFromTime(Time time)
          Gets the standard date string from the time parameter
 Entity getEntity(Reference ref)
          Access the referenced Entity - the entity will belong to the service.
 Collection getEntityAuthzGroups(Reference ref)
          Access a collection of authorization group ids for security on the for the referenced entity - the entity will belong to the service.
 String getEntityDescription(Reference ref)
          Create an entity description for the entity referenced - the entity will belong to the service.
 ResourceProperties getEntityResourceProperties(Reference ref)
          Access the resource properties for the referenced entity - the entity will belong to the service.
 String getEntityUrl(Reference ref)
          Access a URL for the referenced entity - the entity will belong to the service.
 CalendarEventVector getEvents(List references, TimeRange range)
          Takes several calendar References and merges their events from within a given time range.
protected  TimeRange getFullDayTimeRangeFromYMD(int year, int month, int day)
          Make a full-day time range given a year, month, and day
 HttpAccess getHttpAccess()
          Get the HttpAccess object that supports entity access via the access servlet for my entities.
 String getLabel()
          
protected  long getNumberDaysGivenTwoDates(int startYear, int startMonth, int startDay, int endYear, int endMonth, int endDay)
          Calculate the number of days in a range of time given two dates.
 String getOwnerId(Entity r)
          Access the resource owner user id.
protected  int getScheduleTypeFromParameterList(Properties parameters)
          Gets the schedule type from a Properties object (filled from a URL parameter list).
protected  String getSiteName(CalendarEvent event)
          Gets a site name given a CalendarEvent
protected  String getString(String name, String dflt)
          Access some named configuration value as a string.
protected  TimeRange getTimeRangeFromParameters(Properties parameters)
           
protected  ArrayList getTimeRangeListForWeek(TimeRange timeRange, List calendarReferenceList, TimeRange dailyTimeRange, boolean skipSaturdayAndSundayIfNoEvents)
          Generates a list of time ranges for a week.
protected  TimeRange getTimeRangeParameterByName(Properties parameters, String name)
          Utility routine to get a time range parameter from the URL parameters store in a Properties object.
protected  String getTimeString(Time time)
          Gets a standard time string give the time parameter.
protected  String getUniqueId()
          Access the id generating service and return a unique id.
protected  String getXSLFileNameForScheduleType(int scheduleType)
          Given a schedule type, the appropriate XSLT file is returned
 void importEntities(String fromContext, String toContext, List resourceIds)
          import tool(s) contents from the source context into the destination context
 void init()
          Final initialization, once all dependencies are set.
 boolean isDraft(Entity r)
          Check if this resource is in draft mode.
protected  List makeListViewTimeRangeList(TimeRange timeRange, List calendarReferenceList)
          Make a list of days for use in generating an XML document for the list view.
 String merge(String siteId, Element root, String archivePath, String fromSiteId, Map attachmentNames, Map userIdTrans, Set userListAllowImport)
          Merge the resources from the archive into the given site.
 Entity newContainer(Element element)
          Construct a new container resource, from an XML element.
 Entity newContainer(Entity other)
          Construct a new container resource, as a copy of another
 Entity newContainer(String ref)
          Construct a new continer given just an id.
 Edit newContainerEdit(Element element)
          Construct a new container resource, from an XML element.
 Edit newContainerEdit(Entity other)
          Construct a new container resource, as a copy of another
 Edit newContainerEdit(String ref)
          Construct a new continer given just an id.
 RecurrenceRule newRecurrence(String frequency)
          Construct a new recurrence rule who's frequency description matches the frequency parameter.
 RecurrenceRule newRecurrence(String frequency, int interval)
          Construct a new recurrence rule who's frequency description matches the frequency parameter.
 RecurrenceRule newRecurrence(String frequency, int interval, int count)
          Construct a new recurrence rule who's frequency description matches the frequency parameter.
 RecurrenceRule newRecurrence(String frequency, int interval, Time until)
          Construct a new recurrence rule who's frequency description matches the frequency parameter.
 Entity newResource(Entity container, Element element)
          Construct a new resource, from an XML element.
 Entity newResource(Entity container, Entity other)
          Construct a new resource from another resource of the same type.
 Entity newResource(Entity container, String id, Object[] others)
          Construct a new rsource given just an id.
 Edit newResourceEdit(Entity container, Element element)
          Construct a new resource, from an XML element.
 Edit newResourceEdit(Entity container, Entity other)
          Construct a new resource from another resource of the same type.
 Edit newResourceEdit(Entity container, String id, Object[] others)
          Construct a new rsource given just an id.
protected abstract  BaseCalendarService.Storage newStorage()
          Construct a Storage object.
 boolean parseEntityReference(String reference, Reference ref)
          If the service recognizes the reference as its own, parse it and fill in the Reference
protected  Time performEndMinuteKludge(TimeBreakdown breakDown)
          This routine is used to round the end time.
protected  void printSchedule(Properties parameters, StringBuffer contentType, OutputStream os)
          Called by the servlet to service a get/post requesting a calendar in PDF format.
 Object refresh(Object key, Object oldValue, Event event)
          Get a new value for this key whose value has already expired in the cache.
 void removeCalendar(CalendarEdit calendar)
          Remove a calendar that is locked for edit.
protected  TimeRange roundRangeToMinimumTimeInterval(TimeRange timeRange)
          Rounds a time range up to a minimum interval.
protected  BaseCalendarService service()
          Access this service from the inner classes.
 void setCaching(String value)
          Configuration: set the locks-in-db
 void setEntityManager(EntityManager service)
          Dependency: EntityManager.
 void setIdService(IdService manager)
          Dependency: IdService.
 void setLogger(Logger service)
          Dependency: logging service.
 void setMemoryService(MemoryService service)
          Dependency: MemoryService.
 void setServerConfigurationService(ServerConfigurationService service)
          Dependency: ServerConfigurationService.
protected  TimeRange shrinkTimeRangeToCurrentMonth(TimeRange expandedTimeRange)
          The time ranges that we get from the CalendarAction class have days in the week of the first and last weeks padded out to make a full week.
protected  ArrayList splitTimeRangeIntoListOfSingleDayTimeRanges(TimeRange timeRange, TimeRange dailyTimeRange)
          Returns a list of daily time ranges for every day in a range.
 Object[] storageFields(Entity r)
          Collect the fields that need to be stored outside the XML (for the resource).
 void syncWithSiteChange(Site site, EntityProducer.ChangeType change)
          Synchronize any entities related to the Site given this change in the Site, possibly a structural change where a tool is added or removed, or the site is new, or being deleted.
protected  TimeRange trimTimeRange(TimeRange containingRange, TimeRange rangeToTrim)
          Trim the range that is passed in to the containing time range.
protected  void unlock(String lock, String reference)
          Check security permission.
protected  boolean unlockCheck(String lock, String reference)
          Check security permission.
 boolean willArchiveMerge()
          
 boolean willImport()
          
protected  Element writeStringNodeToDom(Document doc, Element parent, String nodeName, String nodeValue)
          Utility routine to write a string node to the DOM.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_relativeAccessPoint

protected String m_relativeAccessPoint
The initial portion of a relative access point URL.


m_calendarCache

protected Cache m_calendarCache
A Cache object for caching: calendars keyed by reference.


m_eventCaches

protected Hashtable m_eventCaches
A bunch of caches for events: keyed by calendar id, the cache is keyed by event reference.


m_storage

protected BaseCalendarService.Storage m_storage
A Storage object for access to calendars and events.


m_logger

protected Logger m_logger
Dependency: logging service


m_memoryService

protected MemoryService m_memoryService
Dependency: MemoryService.


m_IdService

protected IdService m_IdService
Dependency: IdService.


m_caching

protected boolean m_caching
Configuration: cache, or not.


m_entityManager

protected EntityManager m_entityManager
Dependency: EntityManager.


m_serverConfigurationService

protected ServerConfigurationService m_serverConfigurationService
Dependency: ServerConfigurationService.


DAY_VIEW_XLST_FILENAME

protected static final String DAY_VIEW_XLST_FILENAME
PDF file generation

See Also:
Constant Field Values

LIST_VIEW_XLST_FILENAME

protected static final String LIST_VIEW_XLST_FILENAME
See Also:
Constant Field Values

MONTH_VIEW_XLST_FILENAME

protected static final String MONTH_VIEW_XLST_FILENAME
See Also:
Constant Field Values

WEEK_VIEW_XLST_FILENAME

protected static final String WEEK_VIEW_XLST_FILENAME
See Also:
Constant Field Values

PDF_MIME_TYPE

protected static final String PDF_MIME_TYPE
See Also:
Constant Field Values

MILLISECONDS_IN_DAY

protected static long MILLISECONDS_IN_DAY

MILLISECONDS_IN_HOUR

protected static final long MILLISECONDS_IN_HOUR
See Also:
Constant Field Values

MILLISECONDS_IN_MINUTE

protected static final long MILLISECONDS_IN_MINUTE
See Also:
Constant Field Values

MINIMUM_EVENT_LENGTH_IN_MSECONDS

protected static final long MINIMUM_EVENT_LENGTH_IN_MSECONDS
See Also:
Constant Field Values

SCHEDULE_INTERVAL_IN_MINUTES

protected static final int SCHEDULE_INTERVAL_IN_MINUTES
See Also:
Constant Field Values

MAX_OVERLAPPING_COLUMNS

protected static final int MAX_OVERLAPPING_COLUMNS
See Also:
Constant Field Values

TIMESLOT_FOR_OVERLAP_DETECTION_IN_MINUTES

protected static final int TIMESLOT_FOR_OVERLAP_DETECTION_IN_MINUTES
See Also:
Constant Field Values

TIME_RANGE_PARAMETER_NAME

protected static final String TIME_RANGE_PARAMETER_NAME
See Also:
Constant Field Values

DAILY_START_TIME_PARAMETER_NAME

protected static final String DAILY_START_TIME_PARAMETER_NAME
See Also:
Constant Field Values

USER_NAME_PARAMETER_NAME

protected static final String USER_NAME_PARAMETER_NAME
See Also:
Constant Field Values

CALENDAR_PARAMETER_BASE_NAME

protected static final String CALENDAR_PARAMETER_BASE_NAME
See Also:
Constant Field Values

SCHEDULE_TYPE_PARAMETER_NAME

protected static final String SCHEDULE_TYPE_PARAMETER_NAME
See Also:
Constant Field Values

COLUMN_NODE_NAME

protected static final String COLUMN_NODE_NAME
See Also:
Constant Field Values

EVENT_NODE_NAME

protected static final String EVENT_NODE_NAME
See Also:
Constant Field Values

FACULTY_EVENT_ATTRIBUTE_NAME

protected static final String FACULTY_EVENT_ATTRIBUTE_NAME
See Also:
Constant Field Values

FACULTY_NODE

protected static final String FACULTY_NODE
See Also:
Constant Field Values

DESCRIPTION_NODE

protected static final String DESCRIPTION_NODE
See Also:
Constant Field Values

FROM_ATTRIBUTE_STRING

protected static final String FROM_ATTRIBUTE_STRING
See Also:
Constant Field Values

GROUP_NODE

protected static final String GROUP_NODE
See Also:
Constant Field Values

LIST_DATE_ATTRIBUTE_NAME

protected static final String LIST_DATE_ATTRIBUTE_NAME
See Also:
Constant Field Values

LIST_DAY_OF_WEEK_ATTRIBUTE_NAME

protected static final String LIST_DAY_OF_WEEK_ATTRIBUTE_NAME
See Also:
Constant Field Values

LIST_NODE_NAME

protected static final String LIST_NODE_NAME
See Also:
Constant Field Values

MONTH_NODE_NAME

protected static final String MONTH_NODE_NAME
See Also:
Constant Field Values

MAX_CONCURRENT_EVENTS_NAME

protected static final String MAX_CONCURRENT_EVENTS_NAME
See Also:
Constant Field Values

PLACE_NODE

protected static final String PLACE_NODE
See Also:
Constant Field Values

ROW_NODE_NAME

protected static final String ROW_NODE_NAME
See Also:
Constant Field Values

SCHEDULE_NODE

protected static final String SCHEDULE_NODE
See Also:
Constant Field Values

START_DAY_WEEK_ATTRIBUTE_NAME

protected static final String START_DAY_WEEK_ATTRIBUTE_NAME
See Also:
Constant Field Values

START_TIME_ATTRIBUTE_NAME

protected static final String START_TIME_ATTRIBUTE_NAME
See Also:
Constant Field Values

SUB_EVENT_NODE_NAME

protected static final String SUB_EVENT_NODE_NAME
See Also:
Constant Field Values

TITLE_NODE

protected static final String TITLE_NODE
See Also:
Constant Field Values

TO_ATTRIBUTE_STRING

protected static final String TO_ATTRIBUTE_STRING
See Also:
Constant Field Values

TYPE_NODE

protected static final String TYPE_NODE
See Also:
Constant Field Values

UID_NODE

protected static final String UID_NODE
See Also:
Constant Field Values

HOUR_MINUTE_SEPARATOR

protected static final String HOUR_MINUTE_SEPARATOR
See Also:
Constant Field Values
Constructor Detail

BaseCalendarService

public BaseCalendarService()
Method Detail

service

protected BaseCalendarService service()
Access this service from the inner classes.


newStorage

protected abstract BaseCalendarService.Storage newStorage()
Construct a Storage object.

Returns:
The new storage object.

getAccessPoint

protected String getAccessPoint(boolean relative)
Access the partial URL that forms the root of calendar URLs.

Parameters:
relative - if true, form within the access path only (i.e. starting with /content)
Returns:
the partial URL that forms the root of calendar URLs.

unlockCheck

protected boolean unlockCheck(String lock,
                              String reference)
Check security permission.

Parameters:
lock - The lock id string.
reference - The resource's reference string, or null if no resource is involved.
Returns:
true if permitted, false if not.

unlock

protected void unlock(String lock,
                      String reference)
               throws PermissionException
Check security permission.

Parameters:
lock - The lock id string.
reference - The resource's reference string, or null if no resource is involved.
Throws:
PermissionException - thrown if the user does not have access

calendarReference

public String calendarReference(String context,
                                String id)
Access the internal reference which can be used to access the calendar from within the system.

Specified by:
calendarReference in interface CalendarService
Parameters:
context - The context.
id - The calendar id.
Returns:
The the internal reference which can be used to access the calendar from within the system.

calendarPdfReference

public String calendarPdfReference(String context,
                                   String id,
                                   int scheduleType,
                                   List calendars,
                                   String timeRangeString,
                                   String userName,
                                   TimeRange dailyTimeRange)
Description copied from interface: CalendarService
Access the internal reference which can be used to access the calendar-in-pdf format from within the system.

Specified by:
calendarPdfReference in interface CalendarService
Parameters:
context - The context.
id - The calendar id.
Returns:
The the internal reference which can be used to access the calendar-in-pdf format from within the system.

eventReference

public String eventReference(String context,
                             String calendarId,
                             String id)
Access the internal reference which can be used to access the event from within the system.

Specified by:
eventReference in interface CalendarService
Parameters:
context - The context.
calendarId - The calendar id.
id - The event id.
Returns:
The the internal reference which can be used to access the event from within the system.

getEvents

public CalendarEventVector getEvents(List references,
                                     TimeRange range)
Takes several calendar References and merges their events from within a given time range.

Specified by:
getEvents in interface CalendarService
Parameters:
references - The List of calendar References.
range - The time period to use to select events.
Returns:
CalendarEventVector object with the union of all events from the list of calendars in the given time range.

getUniqueId

protected String getUniqueId()
Access the id generating service and return a unique id.

Returns:
a unique id.

setLogger

public void setLogger(Logger service)
Dependency: logging service.

Parameters:
service - The logging service.

setMemoryService

public void setMemoryService(MemoryService service)
Dependency: MemoryService.

Parameters:
service - The MemoryService.

setIdService

public void setIdService(IdService manager)
Dependency: IdService.

Parameters:
manager - The IdService.

setCaching

public void setCaching(String value)
Configuration: set the locks-in-db


setEntityManager

public void setEntityManager(EntityManager service)
Dependency: EntityManager.

Parameters:
service - The EntityManager.

setServerConfigurationService

public void setServerConfigurationService(ServerConfigurationService service)
Dependency: ServerConfigurationService.

Parameters:
service - The ServerConfigurationService.

init

public void init()
Final initialization, once all dependencies are set.


destroy

public void destroy()
Returns to uninitialized state.


allowAddCalendar

public boolean allowAddCalendar(String ref)
check permissions for addCalendar().

Specified by:
allowAddCalendar in interface CalendarService
Parameters:
ref - A reference for the calendar.
Returns:
true if the user is allowed to addCalendar(ref), false if not.

addCalendar

public CalendarEdit addCalendar(String ref)
                         throws IdUsedException,
                                IdInvalidException,
                                PermissionException
Add a new calendar. Must commitCalendar() to make official, or cancelCalendar() when done!

Specified by:
addCalendar in interface CalendarService
Parameters:
ref - A reference for the calendar.
Returns:
The newly created calendar.
Throws:
IdUsedException - if the id is not unique.
IdInvalidException - if the id is not made up of valid characters.
PermissionException - if the user does not have permission to add a calendar.

allowGetCalendar

public boolean allowGetCalendar(String ref)
check permissions for getCalendar().

Specified by:
allowGetCalendar in interface CalendarService
Parameters:
ref - The calendar reference.
Returns:
true if the user is allowed to getCalendar(calendarId), false if not.

findCalendar

protected Calendar findCalendar(String ref)
Find the calendar, in cache or info store - cache it if newly found.

Parameters:
ref - The calendar reference.
Returns:
The calendar, if found.

getCalendar

public Calendar getCalendar(String ref)
                     throws IdUnusedException,
                            PermissionException
Return a specific calendar.

Specified by:
getCalendar in interface CalendarService
Parameters:
ref - The calendar reference.
Returns:
the Calendar that has the specified name.
Throws:
IdUnusedException - If this name is not defined for any calendar.
PermissionException - If the user does not have any permissions to the calendar.

allowRemoveCalendar

public boolean allowRemoveCalendar(String ref)
check permissions for removeCalendar().

Specified by:
allowRemoveCalendar in interface CalendarService
Parameters:
ref - The calendar reference.
Returns:
true if the user is allowed to removeCalendar(calendarId), false if not.

removeCalendar

public void removeCalendar(CalendarEdit calendar)
                    throws PermissionException
Remove a calendar that is locked for edit.

Specified by:
removeCalendar in interface CalendarService
Parameters:
calendar - The calendar to remove.
Throws:
PermissionException - if the user does not have permission to remove a calendar.

getCalendars

public List getCalendars()
Return a List of all the defined calendars.

Specified by:
getCalendars in interface CalendarService
Returns:
a List of Calendar objects (may be empty)

allowImportCalendar

public boolean allowImportCalendar(String ref)
check permissions for importing calendar events

Specified by:
allowImportCalendar in interface CalendarService
Parameters:
ref - The calendar reference.
Returns:
true if the user is allowed to import events, false if not.

allowUpdateCalendar

public boolean allowUpdateCalendar(String ref)
check permissions for editCalendar()

Specified by:
allowUpdateCalendar in interface CalendarService
Parameters:
ref - The calendar reference.
Returns:
true if the user is allowed to update the calendar, false if not.

editCalendar

public CalendarEdit editCalendar(String ref)
                          throws IdUnusedException,
                                 PermissionException,
                                 InUseException
Get a locked calendar object for editing. Must commitCalendar() to make official, or cancelCalendar() or removeCalendar() when done!

Specified by:
editCalendar in interface CalendarService
Parameters:
ref - The calendar reference.
Returns:
A CalendarEdit object for editing.
Throws:
IdUnusedException - if not found, or if not an CalendarEdit object
PermissionException - if the current user does not have permission to mess with this user.
InUseException - if the Calendar object is locked by someone else.

commitCalendar

public void commitCalendar(CalendarEdit edit)
Commit the changes made to a CalendarEdit object, and release the lock. The CalendarEdit is disabled, and not to be used after this call.

Specified by:
commitCalendar in interface CalendarService
Parameters:
edit - The CalendarEdit object to commit.

cancelCalendar

public void cancelCalendar(CalendarEdit edit)
Cancel the changes made to a CalendarEdit object, and release the lock. The CalendarEdit is disabled, and not to be used after this call.

Specified by:
cancelCalendar in interface CalendarService
Parameters:
edit - The CalendarEdit object to commit.

newRecurrence

public RecurrenceRule newRecurrence(String frequency)
Construct a new recurrence rule who's frequency description matches the frequency parameter.

Specified by:
newRecurrence in interface CalendarService
Parameters:
frequency - The frequency description of the desired rule.
Returns:
A new recurrence rule.

newRecurrence

public RecurrenceRule newRecurrence(String frequency,
                                    int interval)
Construct a new recurrence rule who's frequency description matches the frequency parameter.

Specified by:
newRecurrence in interface CalendarService
Parameters:
frequency - The frequency description of the desired rule.
interval - The recurrence interval.
Returns:
A new recurrence rule.

newRecurrence

public RecurrenceRule newRecurrence(String frequency,
                                    int interval,
                                    int count)
Construct a new recurrence rule who's frequency description matches the frequency parameter.

Specified by:
newRecurrence in interface CalendarService
Parameters:
frequency - The frequency description of the desired rule.
interval - The recurrence interval.
count - The number of reecurrences limit.
Returns:
A new recurrence rule.

newRecurrence

public RecurrenceRule newRecurrence(String frequency,
                                    int interval,
                                    Time until)
Construct a new recurrence rule who's frequency description matches the frequency parameter.

Specified by:
newRecurrence in interface CalendarService
Parameters:
frequency - The frequency description of the desired rule.
interval - The recurrence interval.
until - The time after which recurrences stop.
Returns:
A new recurrence rule.

getLabel

public String getLabel()

Specified by:
getLabel in interface EntityProducer
Returns:
a short string identifying the resources kept here, good for a file name or label.

willArchiveMerge

public boolean willArchiveMerge()

Specified by:
willArchiveMerge in interface EntityProducer
Returns:
true if the serice wants to be part of archive / merge, false if not.

willImport

public boolean willImport()

Specified by:
willImport in interface EntityProducer
Returns:
true if the serice wants to be part of import, false if not.

getHttpAccess

public HttpAccess getHttpAccess()
Get the HttpAccess object that supports entity access via the access servlet for my entities.

Specified by:
getHttpAccess in interface EntityProducer
Returns:
The HttpAccess object for my entities, or null if I do not support access.

parseEntityReference

public boolean parseEntityReference(String reference,
                                    Reference ref)
If the service recognizes the reference as its own, parse it and fill in the Reference

Specified by:
parseEntityReference in interface EntityProducer
Parameters:
reference - The reference string to examine.
ref - The Reference object to set with the results of the parse from a recognized reference.
Returns:
true if the reference belonged to the service, false if not.

getEntityDescription

public String getEntityDescription(Reference ref)
Create an entity description for the entity referenced - the entity will belong to the service.

Specified by:
getEntityDescription in interface EntityProducer
Parameters:
ref - The entity reference.
Returns:
The entity description, or null if one cannot be made.

getEntityResourceProperties

public ResourceProperties getEntityResourceProperties(Reference ref)
Access the resource properties for the referenced entity - the entity will belong to the service.

Specified by:
getEntityResourceProperties in interface EntityProducer
Parameters:
ref - The entity reference.
Returns:
The ResourceProperties object for the entity, or null if it has none.

getEntity

public Entity getEntity(Reference ref)
Access the referenced Entity - the entity will belong to the service.

Specified by:
getEntity in interface EntityProducer
Parameters:
ref - The entity reference.
Returns:
The Entity, or null if not found.

getEntityAuthzGroups

public Collection getEntityAuthzGroups(Reference ref)
Access a collection of authorization group ids for security on the for the referenced entity - the entity will belong to the service.

Specified by:
getEntityAuthzGroups in interface EntityProducer
Parameters:
ref - The entity reference.
Returns:
The entity's collection of authorization group ids, or null if this cannot be done.

getEntityUrl

public String getEntityUrl(Reference ref)
Access a URL for the referenced entity - the entity will belong to the service.

Specified by:
getEntityUrl in interface EntityProducer
Parameters:
ref - The entity reference.
Returns:
The entity's URL, or null if it does not have one.

archive

public String archive(String siteId,
                      Document doc,
                      Stack stack,
                      String archivePath,
                      List attachments)
Archive the resources for the given site.

Specified by:
archive in interface EntityProducer
Parameters:
siteId - the id of the site.
doc - The document to contain the xml.
stack - The stack of elements, the top of which will be the containing element of the "service.name" element.
archivePath - The path to the folder where we are writing auxilary files.
attachments - A list of attachments - add to this if any attachments need to be included in the archive.
Returns:
A log of status messages from the archive.

merge

public String merge(String siteId,
                    Element root,
                    String archivePath,
                    String fromSiteId,
                    Map attachmentNames,
                    Map userIdTrans,
                    Set userListAllowImport)
Merge the resources from the archive into the given site.

Specified by:
merge in interface EntityProducer
Parameters:
siteId - The id of the site getting imported into.
root - The XML DOM tree of content to merge.
attachmentNames - A map of old attachment name (as found in the DOM) to new attachment name.
Returns:
A log of status messages from the merge.

importEntities

public void importEntities(String fromContext,
                           String toContext,
                           List resourceIds)
import tool(s) contents from the source context into the destination context

Specified by:
importEntities in interface EntityProducer
Parameters:
fromContext - The source context
toContext - The destination context
resourceIds - when null, all resources will be imported; otherwise, only resources with those ids will be imported

syncWithSiteChange

public void syncWithSiteChange(Site site,
                               EntityProducer.ChangeType change)
Synchronize any entities related to the Site given this change in the Site, possibly a structural change where a tool is added or removed, or the site is new, or being deleted.

Specified by:
syncWithSiteChange in interface EntityProducer
Parameters:
site - The site that has just changed.
change - The ChangeType for the site (newly added, updated, or just removed).

enableSchedule

protected void enableSchedule(Site site)
Setup a calendar for the site.

Parameters:
site - The site.

disableSchedule

protected void disableSchedule(Site site)
Remove a calendar for the site.

Parameters:
site - The site.

refresh

public Object refresh(Object key,
                      Object oldValue,
                      Event event)
Get a new value for this key whose value has already expired in the cache.

Specified by:
refresh in interface CacheRefresher
Parameters:
key - The key whose value has expired and needs to be refreshed.
oldValue - The old exipred value of the key.
event - The event which triggered this refresh.
Returns:
a new value for use in the cache for this key; if null, the entry will be removed.

newContainer

public Entity newContainer(String ref)
Construct a new continer given just an id.

Specified by:
newContainer in interface StorageUser
Parameters:
ref - The reference for the new object.
Returns:
The new containe Resource.

newContainer

public Entity newContainer(Element element)
Construct a new container resource, from an XML element.

Specified by:
newContainer in interface StorageUser
Parameters:
element - The XML.
Returns:
The new container resource.

newContainer

public Entity newContainer(Entity other)
Construct a new container resource, as a copy of another

Specified by:
newContainer in interface StorageUser
Parameters:
other - The other contianer to copy.
Returns:
The new container resource.

newResource

public Entity newResource(Entity container,
                          String id,
                          Object[] others)
Construct a new rsource given just an id.

Specified by:
newResource in interface StorageUser
Parameters:
container - The Resource that is the container for the new resource (may be null).
id - The id for the new object.
others - (options) array of objects to load into the Resource's fields.
Returns:
The new resource.

newResource

public Entity newResource(Entity container,
                          Element element)
Construct a new resource, from an XML element.

Specified by:
newResource in interface StorageUser
Parameters:
container - The Resource that is the container for the new resource (may be null).
element - The XML.
Returns:
The new resource from the XML.

newResource

public Entity newResource(Entity container,
                          Entity other)
Construct a new resource from another resource of the same type.

Specified by:
newResource in interface StorageUser
Parameters:
container - The Resource that is the container for the new resource (may be null).
other - The other resource.
Returns:
The new resource as a copy of the other.

newContainerEdit

public Edit newContainerEdit(String ref)
Construct a new continer given just an id.

Specified by:
newContainerEdit in interface StorageUser
Parameters:
ref - The reference for the new object.
Returns:
The new containe Resource.

newContainerEdit

public Edit newContainerEdit(Element element)
Construct a new container resource, from an XML element.

Specified by:
newContainerEdit in interface StorageUser
Parameters:
element - The XML.
Returns:
The new container resource.

newContainerEdit

public Edit newContainerEdit(Entity other)
Construct a new container resource, as a copy of another

Specified by:
newContainerEdit in interface StorageUser
Parameters:
other - The other contianer to copy.
Returns:
The new container resource.

newResourceEdit

public Edit newResourceEdit(Entity container,
                            String id,
                            Object[] others)
Construct a new rsource given just an id.

Specified by:
newResourceEdit in interface StorageUser
Parameters:
container - The Resource that is the container for the new resource (may be null).
id - The id for the new object.
others - (options) array of objects to load into the Resource's fields.
Returns:
The new resource.

newResourceEdit

public Edit newResourceEdit(Entity container,
                            Element element)
Construct a new resource, from an XML element.

Specified by:
newResourceEdit in interface StorageUser
Parameters:
container - The Resource that is the container for the new resource (may be null).
element - The XML.
Returns:
The new resource from the XML.

newResourceEdit

public Edit newResourceEdit(Entity container,
                            Entity other)
Construct a new resource from another resource of the same type.

Specified by:
newResourceEdit in interface StorageUser
Parameters:
container - The Resource that is the container for the new resource (may be null).
other - The other resource.
Returns:
The new resource as a copy of the other.

storageFields

public Object[] storageFields(Entity r)
Collect the fields that need to be stored outside the XML (for the resource).

Specified by:
storageFields in interface StorageUser
Returns:
An array of field values to store in the record outside the XML (for the resource).

isDraft

public boolean isDraft(Entity r)
Check if this resource is in draft mode.

Specified by:
isDraft in interface StorageUser
Parameters:
r - The resource.
Returns:
true if the resource is in draft mode, false if not.

getOwnerId

public String getOwnerId(Entity r)
Access the resource owner user id.

Specified by:
getOwnerId in interface StorageUser
Parameters:
r - The resource.
Returns:
The resource owner user id.

getDate

public Time getDate(Entity r)
Access the resource date.

Specified by:
getDate in interface StorageUser
Parameters:
r - The resource.
Returns:
The resource date.

dumpTimeRange

protected String dumpTimeRange(TimeRange timeRange)
Debugging routine to get a string for a TimeRange. This should probably be in the TimeRange class.


generatePDF

protected void generatePDF(Document doc,
                           String xslFileName,
                           OutputStream streamOut)
Takes a DOM structure and renders a PDF

Parameters:
doc - DOM structure
xslFileName - XSL file to use to translate the DOM document to FOP

getFullDayTimeRangeFromYMD

protected TimeRange getFullDayTimeRangeFromYMD(int year,
                                               int month,
                                               int day)
Make a full-day time range given a year, month, and day


makeListViewTimeRangeList

protected List makeListViewTimeRangeList(TimeRange timeRange,
                                         List calendarReferenceList)
Make a list of days for use in generating an XML document for the list view.


generateXMLDocument

protected void generateXMLDocument(int scheduleType,
                                   Document doc,
                                   TimeRange timeRange,
                                   TimeRange dailyTimeRange,
                                   List calendarReferenceList,
                                   String userID)
Parameters:
scheduleType - daily, weekly, monthly, or list (no yearly).
doc - XML output document
timeRange - this is the overall time range. For example, for a weekly schedule, it would be the start/end times for the currently selected week period.
dailyTimeRange - On a weekly time schedule, even if the overall time range is for a week, you're only looking at a portion of the day (e.g., 8 AM to 6 PM, etc.)
userID - This is the name of the user whose schedule is being printed.

trimTimeRange

protected TimeRange trimTimeRange(TimeRange containingRange,
                                  TimeRange rangeToTrim)
Trim the range that is passed in to the containing time range.


roundRangeToMinimumTimeInterval

protected TimeRange roundRangeToMinimumTimeInterval(TimeRange timeRange)
Rounds a time range up to a minimum interval.


generateXMLEvent

protected void generateXMLEvent(Document doc,
                                Element parent,
                                CalendarEvent event,
                                String eventNodeName,
                                TimeRange containingTimeRange,
                                boolean forceMinimumTime,
                                boolean hideGroupIfNoSpace,
                                boolean performEndTimeKludge)
Generates the XML for an event.


getCalendarListFromParameters

protected List getCalendarListFromParameters(Properties parameters)
Given a Properties structure, generates a list of calendar references.


getCalendarListParameters

protected String getCalendarListParameters(List calendars)
Given a list of calendar references, formats a URL fragment of parameters.


getDailyStartTimeFromParameters

protected TimeRange getDailyStartTimeFromParameters(Properties parameters)

getDateFromTime

protected String getDateFromTime(Time time)
Gets the standard date string from the time parameter


getScheduleTypeFromParameterList

protected int getScheduleTypeFromParameterList(Properties parameters)
Gets the schedule type from a Properties object (filled from a URL parameter list).


getSiteName

protected String getSiteName(CalendarEvent event)
Gets a site name given a CalendarEvent


getString

protected String getString(String name,
                           String dflt)
Access some named configuration value as a string.

Parameters:
name - The configuration value name.
dflt - The value to return if not found.
Returns:
The configuration value with this name, or the default value if not found.

getTimeRangeFromParameters

protected TimeRange getTimeRangeFromParameters(Properties parameters)

getTimeRangeListForWeek

protected ArrayList getTimeRangeListForWeek(TimeRange timeRange,
                                            List calendarReferenceList,
                                            TimeRange dailyTimeRange,
                                            boolean skipSaturdayAndSundayIfNoEvents)
Generates a list of time ranges for a week. Each range in the list is a day.

Parameters:
dailyTimeRange - representative daily time range (start hour/minute, end hour/minute)
skipSaturdayAndSundayIfNoEvents - if true, then Saturday and Sundary are skipped if there are no events.

getTimeRangeParameterByName

protected TimeRange getTimeRangeParameterByName(Properties parameters,
                                                String name)
Utility routine to get a time range parameter from the URL parameters store in a Properties object.


getTimeString

protected String getTimeString(Time time)
Gets a standard time string give the time parameter.


getXSLFileNameForScheduleType

protected String getXSLFileNameForScheduleType(int scheduleType)
Given a schedule type, the appropriate XSLT file is returned


performEndMinuteKludge

protected Time performEndMinuteKludge(TimeBreakdown breakDown)
This routine is used to round the end time. The time is stored at one minute less than the actual end time, but the user will expect to see the end time on the hour. For example, an event that ends at 10:00 is actually stored at 9:59. This code should really be in a central place so that the velocity template can see it as well.


printSchedule

protected void printSchedule(Properties parameters,
                             StringBuffer contentType,
                             OutputStream os)
                      throws PermissionException
Called by the servlet to service a get/post requesting a calendar in PDF format.

Throws:
PermissionException

shrinkTimeRangeToCurrentMonth

protected TimeRange shrinkTimeRangeToCurrentMonth(TimeRange expandedTimeRange)
The time ranges that we get from the CalendarAction class have days in the week of the first and last weeks padded out to make a full week. This function will shrink this range to only one month.


getNumberDaysGivenTwoDates

protected long getNumberDaysGivenTwoDates(int startYear,
                                          int startMonth,
                                          int startDay,
                                          int endYear,
                                          int endMonth,
                                          int endDay)
Calculate the number of days in a range of time given two dates.

Parameters:
startMonth - (zero based, 0-11)
startDay - (one based, 1-31)
endYear - (one based, 1-31)
endMonth - (zero based, 0-11

splitTimeRangeIntoListOfSingleDayTimeRanges

protected ArrayList splitTimeRangeIntoListOfSingleDayTimeRanges(TimeRange timeRange,
                                                                TimeRange dailyTimeRange)
Returns a list of daily time ranges for every day in a range.

Parameters:
timeRange - overall time range
dailyTimeRange - representative daily time range (start hour/minute, end hour/minute). If null, this parameter is ignored.

writeStringNodeToDom

protected Element writeStringNodeToDom(Document doc,
                                       Element parent,
                                       String nodeName,
                                       String nodeValue)
Utility routine to write a string node to the DOM.