Talk:Team:IvyTech-South Bend/Notebook

From 2010.igem.org

< Talk:Team:IvyTech-South Bend(Difference between revisions)
 
(One intermediate revision not shown)
Line 31: Line 31:
   <!-- End Wrapper -->
   <!-- End Wrapper -->
-
   package com.hurlbert.jspwiki.plugin;
+
    
-
 
+
-
import java.io.*;
+
-
import java.text.*;
+
-
import java.util.*;
+
-
import java.lang.IllegalArgumentException;
+
-
 
+
-
import org.apache.log4j.Category;
+
-
 
+
-
import com.ecyrd.jspwiki.WikiContext;
+
-
import com.ecyrd.jspwiki.WikiEngine;
+
-
import com.ecyrd.jspwiki.plugin.PluginException;
+
-
import com.ecyrd.jspwiki.plugin.WikiPlugin;
+
-
 
+
-
public class CalendarList
+
-
implements WikiPlugin
+
-
{
+
-
private static Category log = Category.getInstance(CalendarList.class);
+
-
+
-
private static final String FORMAT_LIST = "LIST";
+
-
private static final String FORMAT_WEEKLY_CALENDAR = "WEEKLY";
+
-
+
-
public String execute( WikiContext context, Map params )
+
-
throws PluginException
+
-
{
+
-
String htmlOutput = null;
+
-
SchedProps schedProps = null;
+
-
ArrayList entryList  = null;
+
-
PropertiesManager propertiesManager = null;
+
-
+
-
schedProps = new PropertiesManager().getProperties(context, params);
+
-
 
+
-
DateRange visibleDateRange = getVisibleDateRange(schedProps);
+
-
+
-
// DateRange calendarDateRange = getCalendarDateRange(visibleDateRange);
+
-
 
+
-
entryList = getEvents(context, schedProps, visibleDateRange);
+
-
 
+
-
Collections.sort(entryList, new EventComparator());
+
-
+
-
log.debug("Items in the list: " + entryList.size());
+
-
 
+
-
if( FORMAT_LIST.equalsIgnoreCase(schedProps.format) )
+
-
{
+
-
return buildSimpleTable( context, schedProps, entryList.iterator() );
+
-
}
+
-
else if( FORMAT_WEEKLY_CALENDAR.equalsIgnoreCase(schedProps.format) )
+
-
{
+
-
// return weeklySchedule(visibleDateRange, schedProps, entryList);
+
-
return buildWeeklyCal( context, visibleDateRange, schedProps, entryList );
+
-
}
+
-
else
+
-
{
+
-
return "Unknown format.  Adjust the format parameter. list or weekly";
+
-
}
+
-
}
+
-
+
-
 
+
-
/*
+
-
* This routine builds a weekly calendar in an HTML table.  It has several assumptions:
+
-
*
+
-
* - Weeks begin on Monday.
+
-
* - A minimum of one week will be shown.
+
-
*/
+
-
private String buildWeeklyCal( WikiContext p_context,
+
-
DateRange p_daterange,
+
-
SchedProps p_schedProps,
+
-
ArrayList p_entryList )
+
-
throws PluginException
+
-
{
+
-
StringBuffer calTable = new StringBuffer("<table class=\""
+
-
+ p_schedProps.stylePrefix + "CalendarList\" cellpadding=\"0\" cellspacing=\"0\">");
+
-
 
+
-
int offset = 0;
+
-
boolean firstDay = true;
+
-
Date currentDay = null;
+
-
CalWeek  calWeek = null;
+
-
 
+
-
// Check the prerequisites - can't work with a null date range.
+
-
if( p_daterange == null || p_daterange.end == null || p_daterange.start == null )
+
-
{
+
-
throw new PluginException("Invalid daterange parameter: null values passed.");
+
-
}
+
-
+
-
// Start with the 'currentDay' being the first in our date range.
+
-
currentDay = new Date( p_daterange.start.getYear(),
+
-
p_daterange.start.getMonth(),
+
-
p_daterange.start.getDate() );
+
-
 
+
-
calWeek = new CalWeek(p_context, currentDay, p_schedProps );
+
-
+
-
calTable.append(calWeek.getHeader());
+
-
 
+
-
offset = 0;
+
-
firstDay = true;
+
-
+
-
try
+
-
{
+
-
while( ! currentDay.after(p_daterange.end) )
+
-
{
+
-
if( currentDay.getDay() == 1 && !firstDay )
+
-
{
+
-
// Add events to this week.
+
-
calWeek.addEvents(p_context, p_schedProps, p_entryList);
+
-
 
+
-
+
-
//TODO: Add a flag to determine if there is text, this is too slow.
+
-
 
+
-
String calWeekHTML = calWeek.toString();
+
-
+
-
if( calWeekHTML != null )
+
-
{
+
-
// Add this week to the HTML calendar.
+
-
calTable.append(calWeekHTML);
+
-
}
+
-
 
+
-
// Start a new week.
+
-
calWeek = new CalWeek(p_context, currentDay, p_schedProps);
+
-
}
+
-
+
-
// Go forward another day.
+
-
offset++;
+
-
currentDay = new Date( p_daterange.start.getYear(),
+
-
p_daterange.start.getMonth(),
+
-
p_daterange.start.getDate() + offset );
+
-
firstDay = false;
+
-
}
+
-
}
+
-
catch( Exception ex )
+
-
{
+
-
throw new PluginException("buildWeeklyCal failed: " + ex.getMessage());
+
-
}
+
-
+
-
calTable.append("</table>");
+
-
+
-
return calTable.toString();
+
-
}
+
-
 
+
-
 
+
-
// private DateRange getCalendarDateRange(DateRange p_dateRange)
+
-
// throws PluginException
+
-
// {
+
-
// int offset = 0;
+
-
//
+
-
// Date firstCalDate = null;
+
-
// Date lastCalDate  = null;
+
-
//
+
-
// DateRange calDateRange  = null;
+
-
//
+
-
// // Get the number of days from the previous monday and start the calendar there.
+
-
// offset = getDayNum(p_dateRange.start);
+
-
//
+
-
// firstCalDate = new Date( p_dateRange.start.getYear(),
+
-
// p_dateRange.start.getMonth(),
+
-
// p_dateRange.start.getDate() - offset );
+
-
//
+
-
// lastCalDate = new Date( p_dateRange.end.getYear(),
+
-
// p_dateRange.end.getMonth(),
+
-
// p_dateRange.end.getDate() );
+
-
//
+
-
// // Get the number of days to the sunday after the last event and end the calendar there.
+
-
// offset = 6 - getDayNum(lastCalDate);
+
-
//
+
-
// lastCalDate = new Date( p_dateRange.end.getYear(),
+
-
// p_dateRange.end.getMonth(),
+
-
// p_dateRange.end.getDate() + offset );
+
-
//
+
-
// calDateRange = new DateRange(firstCalDate, lastCalDate);
+
-
//
+
-
// log.debug("Cal Start: " + calDateRange.start.toString() + "  Cal End: " + calDateRange.end.toString());
+
-
//
+
-
// return calDateRange ;
+
-
// }
+
-
+
-
+
-
private int getDayNum(Date p_date)
+
-
{
+
-
if( p_date.getDay() == 0 )
+
-
{
+
-
return 6;
+
-
}
+
-
else
+
-
{
+
-
return p_date.getDay() - 1 ;
+
-
}
+
-
}
+
-
+
-
+
-
public DateRange getVisibleDateRange(SchedProps p_schedProps)
+
-
{
+
-
int year  = new Date().getYear();
+
-
int month = new Date().getMonth();
+
-
int dom  = new Date().getDate(); // day of the month, 1=1st 30=30th
+
-
+
-
DateRange daterange = new DateRange();
+
-
+
-
daterange.start = new Date( year, month, dom - p_schedProps.pastDays );
+
-
daterange.end  = new Date( year, month, dom + p_schedProps.futureDays );
+
-
+
-
return daterange;
+
-
}
+
-
+
-
 
+
-
public class DateRange
+
-
{
+
-
Date start = new Date();
+
-
Date end  = new Date();
+
-
+
-
public DateRange()
+
-
{
+
-
}
+
-
+
-
public DateRange(Date p_start, Date p_end)
+
-
{
+
-
start = p_start;
+
-
end  = p_end;
+
-
}
+
-
+
-
public boolean before(Date date)
+
-
{
+
-
if( date == null )
+
-
{
+
-
throw new IllegalArgumentException("Cannot except a null date.");
+
-
}
+
-
else
+
-
{
+
-
return date.before(start);
+
-
}
+
-
}
+
-
+
-
public boolean after(Date date)
+
-
{
+
-
if( date == null )
+
-
{
+
-
throw new IllegalArgumentException("Cannot except a null date.");
+
-
}
+
-
else
+
-
{
+
-
return date.after(end);
+
-
}
+
-
}
+
-
+
-
public boolean contains(Date date)
+
-
{
+
-
return (!before(date) & !after(date)) ;
+
-
}
+
-
}
+
-
+
-
+
-
public class Event
+
-
{
+
-
public Event(Date p_date, String p_desc)
+
-
{
+
-
date = p_date;
+
-
desc = p_desc;
+
-
}
+
-
 
+
-
public Date  date = null;
+
-
public String desc = null;
+
-
+
-
public Date getDayDate()
+
-
{
+
-
return new Date( date.getYear(), date.getMonth(), date.getDate() );
+
-
}
+
-
}
+
-
+
-
+
-
public class EventComparator implements Comparator
+
-
{
+
-
public int compare( Object o1, Object o2 )
+
-
{
+
-
if( o1 == null || o2 == null )
+
-
{
+
-
return 0;
+
-
}
+
-
           
+
-
Event event1 = (Event) o1;
+
-
Event event2 = (Event) o2;
+
-
 
+
-
return event1.date.compareTo(event2.date);
+
-
}
+
-
}
+
-
 
+
-
+
-
// /**
+
-
// * This class decodes the event types and allows for the addition of custom
+
-
// * start and end tags.  Each of these tags is a div with a special class to
+
-
// * identify the event type.
+
-
// */
+
-
// public class EventType
+
-
// {
+
-
// String startTag = "";
+
-
// String endTag = "";
+
-
//
+
-
// public EventType( Event pEvent )
+
-
// {
+
-
//
+
-
// String content = m_context.getEngine().textToHTML(m_context, pEvent.desc);
+
-
//
+
-
// if( content != null && content.length() > 0 )
+
-
// {
+
-
// // Check for Scott Events.
+
-
// if( content.indexOf("(S)") > 0 )
+
-
// {
+
-
// content = "<div class=\"ScottEvent"
+
-
// }
+
-
// }
+
-
// else
+
-
// {
+
-
// content = "";
+
-
// }
+
-
//
+
-
// return content;
+
-
// }
+
-
//
+
-
//
+
-
//
+
-
//
+
-
// }
+
-
//
+
-
// public String getStartTag()
+
-
// {
+
-
// return startTag;
+
-
// }
+
-
//
+
-
// public String getEndTag()
+
-
// {
+
-
// return endTag;
+
-
// }
+
-
// }
+
-
+
-
public class CalDay
+
-
{
+
-
private SimpleDateFormat dowFormatter  = new SimpleDateFormat( "EEE");
+
-
private SimpleDateFormat monthNameFormatter = new SimpleDateFormat( "MMMMMMMMMMMMMMMM");
+
-
private SimpleDateFormat timeFormatter = new SimpleDateFormat( "hh:mm a");
+
-
 
+
-
public SchedProps m_schedProps = null;
+
-
public Date m_date = null;
+
-
public String m_event = null;
+
-
private ArrayList m_events = new ArrayList();
+
-
private WikiContext m_context = null;
+
-
+
-
public CalDay(WikiContext p_context, Date p_calDate, SchedProps p_schedProps)
+
-
{
+
-
if( p_calDate != null )
+
-
{
+
-
m_date = p_calDate;
+
-
}
+
-
else
+
-
{
+
-
throw new IllegalArgumentException("calDate cannot be null.");
+
-
}
+
-
+
-
if( p_schedProps != null )
+
-
{
+
-
m_schedProps = p_schedProps;
+
-
}
+
-
else
+
-
{
+
-
throw new IllegalArgumentException("calDate cannot be null.");
+
-
}
+
-
+
-
if( p_context != null )
+
-
{
+
-
m_context = p_context;
+
-
}
+
-
else
+
-
{
+
-
throw new IllegalArgumentException("calDate cannot be null.");
+
-
}
+
-
}
+
-
+
-
public String getEvents()
+
-
{
+
-
StringBuffer eventsHTML = new StringBuffer();
+
-
+
-
addEventsHeader( eventsHTML );
+
-
 
+
-
if( isToday() )
+
-
{
+
-
eventsHTML.append( "<div class=\"" + m_schedProps.stylePrefix + "DayEvents " + m_schedProps.stylePrefix + "TodayEvents\">");
+
-
}
+
-
else
+
-
{
+
-
eventsHTML.append( "<div class=\"" + m_schedProps.stylePrefix + "DayEvents\">");
+
-
}
+
-
+
-
Collections.sort(m_events, new EventComparator());
+
-
+
-
Iterator iterator = m_events.iterator();
+
-
+
-
if( !iterator.hasNext() )
+
-
{
+
-
addEmptyEventToHTML( eventsHTML );
+
-
}
+
-
else
+
-
{
+
-
while( iterator.hasNext() )
+
-
{
+
-
addEventToHTML( eventsHTML, (Event) iterator.next() );
+
-
}
+
-
}
+
-
+
-
eventsHTML.append( "</div>" );
+
-
 
+
-
return eventsHTML.toString();
+
-
}
+
-
+
-
public void addEventsHeader( StringBuffer pEventsHTML )
+
-
{
+
-
pEventsHTML.append( "<div class=\"" + m_schedProps.stylePrefix + "DayHeader"
+
-
+ ((isWeekDay()) ? " " + m_schedProps.stylePrefix + "WeekDayDayHeader" : " " + m_schedProps.stylePrefix + "WeekEndDayHeader")
+
-
+ ((isToday()) ? " " + m_schedProps.stylePrefix + "TodayDayHeader" : "")
+
-
+ "\">" );
+
-
+
-
if( m_date.getDate() == 1 )
+
-
{
+
-
pEventsHTML.append( "<span class=\"" + m_schedProps.stylePrefix + "MonthName\" >"
+
-
+ monthNameFormatter.format(m_date).trim() + " " + "</span>");
+
-
}
+
-
 
+
-
pEventsHTML.append( "<span class=\"" + m_schedProps.stylePrefix + "DayNumber\" >"
+
-
+ Integer.toString(m_date.getDate()) + "</span>");
+
-
 
+
-
pEventsHTML.append("</div>");
+
-
 
+
-
}
+
-
 
+
-
public void addEventToHTML( StringBuffer pEventsHTML, Event pEvent )
+
-
{
+
-
if( pEvent == null )
+
-
{
+
-
addEmptyEventToHTML( pEventsHTML );
+
-
}
+
-
else
+
-
{
+
-
// TODO:Fix -- Change this to use a flag -- .isUntimed() or something
+
-
 
+
-
if( timeFormatter.format(pEvent.date).toLowerCase().indexOf("12:00 am") > -1 )
+
-
{
+
-
pEventsHTML.append( "<div class=\"" + m_schedProps.stylePrefix + "UntimedEventDesc"
+
-
+ ((isWeekDay()) ? " " + m_schedProps.stylePrefix + "WeekDayUntimedEventDesc" : " " + m_schedProps.stylePrefix + "WeekEndUntimedEventDesc")
+
-
+ ((isToday())  ? " " + m_schedProps.stylePrefix + "TodayUntimedEventDesc" : "")
+
-
+ "\">" );
+
-
pEventsHTML.append( m_context.getEngine().textToHTML(m_context, pEvent.desc) );
+
-
pEventsHTML.append( "</div>" );
+
-
}
+
-
else
+
-
{
+
-
pEventsHTML.append( "<div class=\"" + m_schedProps.stylePrefix + "TimedEventDate"
+
-
+ ((isWeekDay()) ? " " + m_schedProps.stylePrefix + "WeekDayTimedEventDate" : " " + m_schedProps.stylePrefix + "WeekEndTimedEventDate")
+
-
+ ((isToday()) ? " " + m_schedProps.stylePrefix + "TodayTimedEventDate" : "")
+
-
+ "\">" );
+
-
pEventsHTML.append( timeFormatter.format(pEvent.date).toLowerCase() + "" );
+
-
pEventsHTML.append( "</div>" );
+
-
+
-
pEventsHTML.append( "<div class=\"" + m_schedProps.stylePrefix + "TimedEventDesc"
+
-
+ ((isWeekDay()) ? " " + m_schedProps.stylePrefix + "WeekDayTimedEventDesc" : " " + m_schedProps.stylePrefix + "WeekEndTimedEventDesc")
+
-
+ ((isToday()) ? " " + m_schedProps.stylePrefix + "TodayTimedEventDesc" : "")
+
-
+ "\">" );
+
-
pEventsHTML.append( m_context.getEngine().textToHTML(m_context, pEvent.desc) );
+
-
pEventsHTML.append( "</div>" );
+
-
}
+
-
}
+
-
}
+
-
+
-
public void addEmptyEventToHTML( StringBuffer pEventsHTML )
+
-
{
+
-
if( isToday() )
+
-
{
+
-
pEventsHTML.append("<div class=\"" + m_schedProps.stylePrefix + "TodayEmptyEvent\"></div>");
+
-
}
+
-
else
+
-
{
+
-
pEventsHTML.append("<div class=\"" + m_schedProps.stylePrefix + "EmptyEvent\"></div>");
+
-
}
+
-
 
+
-
}
+
-
+
-
public void addEvent(WikiContext p_context, Event p_event)
+
-
{
+
-
m_events.add(p_event);
+
-
}
+
-
+
-
+
-
public boolean isToday()
+
-
{
+
-
return isSameDay( new Date(new Date().getYear(), new Date().getMonth(), new Date().getDate()) );
+
-
}
+
-
+
-
public boolean isSameDay(Date p_date)
+
-
{
+
-
return m_date.equals(p_date);
+
-
}
+
-
+
-
private boolean isWeekDay()
+
-
{
+
-
return ( m_date.getDay() > 0 & m_date.getDay() < 6 );
+
-
}
+
-
}
+
-
+
-
+
-
public class CalWeek
+
-
{
+
-
public CalDay mon = null;
+
-
public CalDay tue = null;
+
-
public CalDay wed = null;
+
-
public CalDay thu = null;
+
-
public CalDay fri = null;
+
-
public CalDay sat = null;
+
-
public CalDay sun = null;
+
-
+
-
private SchedProps m_schedProps = null;
+
-
+
-
/*
+
-
* This constructor initializes each day of the week so we don't have to
+
-
* be concerned with null days later.
+
-
*
+
-
* The date passed is supposed to be the MONDAY WHICH STARTS THE WEEK. 
+
-
* However, if it's not, to draw the calendar correctly, we backup until
+
-
* we find the previous monday and fill in each of the days for the week.
+
-
*/
+
-
public CalWeek(WikiContext p_context, Date p_date, SchedProps p_schedProps)
+
-
{
+
-
if( p_schedProps != null )
+
-
{
+
-
m_schedProps = p_schedProps;
+
-
}
+
-
else
+
-
{
+
-
throw new IllegalArgumentException("calDate cannot be null.");
+
-
}
+
-
+
-
SimpleDateFormat dowFormatter = new SimpleDateFormat( "EEE");
+
-
 
+
-
CalDay calDay = null;
+
-
+
-
Date currentDay = null;
+
-
Date startingMonday = null;
+
-
 
+
-
startingMonday = p_date;
+
-
//
+
-
// If this isn't monday, back up until we find the previous monday.
+
-
//
+
-
while( ! "MON".equalsIgnoreCase(dowFormatter.format(startingMonday)) )
+
-
{
+
-
startingMonday = new Date( startingMonday.getYear(),
+
-
startingMonday.getMonth(),
+
-
startingMonday.getDate() - 1 );
+
-
}
+
-
+
-
for(int i = 0; i < 7; i++)
+
-
{
+
-
currentDay = new Date( startingMonday.getYear(),
+
-
startingMonday.getMonth(),
+
-
startingMonday.getDate() + i );
+
-
 
+
-
calDay = new CalDay(p_context, currentDay, p_schedProps );
+
-
 
+
-
try
+
-
{
+
-
updateDay( calDay );
+
-
}
+
-
catch( PluginException pe )
+
-
{
+
-
// ignore
+
-
}
+
-
}
+
-
}
+
-
+
-
public void updateDay(CalDay p_calDay)
+
-
throws PluginException
+
-
{
+
-
if( p_calDay != null && p_calDay.m_date != null )
+
-
{
+
-
switch(p_calDay.m_date.getDay())
+
-
{
+
-
case 1:
+
-
mon = p_calDay;
+
-
break;
+
-
case 2:
+
-
tue = p_calDay;
+
-
break;
+
-
case 3:
+
-
wed = p_calDay;
+
-
break;
+
-
case 4:
+
-
thu = p_calDay;
+
-
break;
+
-
case 5:
+
-
fri = p_calDay;
+
-
break;
+
-
case 6:
+
-
sat = p_calDay;
+
-
break;
+
-
case 0:
+
-
sun = p_calDay;
+
-
break;
+
-
default:
+
-
throw new PluginException("updateDay did not recieve a valid calDay parameter.");
+
-
}
+
-
}
+
-
}
+
-
+
-
public void addEvents(WikiContext p_context, SchedProps p_oSchedProps, ArrayList p_entryList)
+
-
throws PluginException
+
-
{
+
-
String dateString = null;
+
-
String eventDesc = null;
+
-
String inputLine = null;
+
-
+
-
Date datetime = null;
+
-
Date eventDay = null;
+
-
+
-
Event event = null;
+
-
 
+
-
try
+
-
{
+
-
Iterator iterator = p_entryList.iterator();
+
-
+
-
while( iterator.hasNext() )
+
-
{
+
-
event = (Event) iterator.next();
+
-
+
-
if( event != null )
+
-
{
+
-
eventDay = event.getDayDate();
+
-
+
-
if( mon.isSameDay(eventDay) )
+
-
{
+
-
mon.addEvent(p_context, event);
+
-
}
+
-
else if( tue.isSameDay(eventDay) )
+
-
{
+
-
tue.addEvent(p_context, event);
+
-
}
+
-
else if( wed.isSameDay(eventDay) )
+
-
{
+
-
wed.addEvent(p_context, event);
+
-
}
+
-
else if( thu.isSameDay(eventDay) )
+
-
{
+
-
thu.addEvent(p_context, event);
+
-
}
+
-
else if( fri.isSameDay(eventDay) )
+
-
{
+
-
fri.addEvent(p_context, event);
+
-
}
+
-
else if( sat.isSameDay(eventDay) )
+
-
{
+
-
sat.addEvent(p_context, event);
+
-
}
+
-
else if( sun.isSameDay(eventDay) )
+
-
{
+
-
sun.addEvent(p_context, event);
+
-
}
+
-
 
+
-
} // if( event != null )
+
-
+
-
} // while( iterator.hasNext() )
+
-
}
+
-
catch( Exception ex )
+
-
{
+
-
throw new PluginException("addEvents failed: " + ex.getMessage());
+
-
}
+
-
}
+
-
+
-
private String getTodayClassName( CalDay pCalDay)
+
-
{
+
-
String className = "";
+
-
+
-
    if( pCalDay != null )
+
-
    {
+
-
    if( pCalDay.isToday() )
+
-
    {
+
-
    className = " " + m_schedProps.stylePrefix + "Today";
+
-
    }
+
-
    }
+
-
   
+
-
    return className;
+
-
}
+
-
 
+
-
public String toString()
+
-
{
+
-
StringBuffer out = new StringBuffer("");
+
-
 
+
-
out.append("<tr class=\"" + m_schedProps.stylePrefix + "Week\">");
+
-
 
+
-
    out.append("<td  class=\"" + m_schedProps.stylePrefix + "WeekDay " + m_schedProps.stylePrefix + "Mon" + getTodayClassName(mon) + "\">");
+
-
    out.append("<div class=\"" + m_schedProps.stylePrefix + "WeekDay " + m_schedProps.stylePrefix + "Mon" + getTodayClassName(mon) + "\">");
+
-
out.append((mon != null) ? mon.getEvents() : "");
+
-
out.append("</div></td>");
+
-
+
-
    out.append("<td  class=\"" + m_schedProps.stylePrefix + "WeekDay " + m_schedProps.stylePrefix + "Tue" + getTodayClassName(tue) + "\">");
+
-
    out.append("<div class=\"" + m_schedProps.stylePrefix + "WeekDay " + m_schedProps.stylePrefix + "Tue" + getTodayClassName(tue) + "\">");
+
-
out.append((tue != null) ? tue.getEvents() : "");
+
-
out.append("</div></td>");
+
-
 
+
-
    out.append("<td  class=\"" + m_schedProps.stylePrefix + "WeekDay " + m_schedProps.stylePrefix + "Wed" + getTodayClassName(wed) + "\">");
+
-
    out.append("<div class=\"" + m_schedProps.stylePrefix + "WeekDay " + m_schedProps.stylePrefix + "Wed" + getTodayClassName(wed) + "\">");
+
-
out.append((wed != null) ? wed.getEvents() : "");
+
-
out.append("</div></td>");
+
-
+
-
    out.append("<td  class=\"" + m_schedProps.stylePrefix + "WeekDay " + m_schedProps.stylePrefix + "Thu" + getTodayClassName(thu) + "\">");
+
-
    out.append("<div class=\"" + m_schedProps.stylePrefix + "WeekDay " + m_schedProps.stylePrefix + "Thu" + getTodayClassName(thu) + "\">");
+
-
out.append((thu != null) ? thu.getEvents() : "");
+
-
out.append("</div></td>");
+
-
 
+
-
    out.append("<td  class=\"" + m_schedProps.stylePrefix + "WeekDay " + m_schedProps.stylePrefix + "Fri" + getTodayClassName(fri) + "\">");
+
-
    out.append("<div class=\"" + m_schedProps.stylePrefix + "WeekDay " + m_schedProps.stylePrefix + "Fri" + getTodayClassName(fri) + "\">");
+
-
out.append((fri != null) ? fri.getEvents() : "");
+
-
out.append("</div></td>");
+
-
 
+
-
    out.append("<td  class=\"" + m_schedProps.stylePrefix + "WeekEnd " + m_schedProps.stylePrefix + "Sat" + getTodayClassName(sat) + "\">");
+
-
    out.append("<div class=\"" + m_schedProps.stylePrefix + "WeekEnd " + m_schedProps.stylePrefix + "Sat" + getTodayClassName(sat) + "\">");
+
-
out.append((sat != null) ? sat.getEvents() : "");
+
-
out.append("</div></td>");
+
-
 
+
-
    out.append("<td  class=\"" + m_schedProps.stylePrefix + "WeekEnd " + m_schedProps.stylePrefix + "Sun" + getTodayClassName(sun) + "\">");
+
-
    out.append("<div class=\"" + m_schedProps.stylePrefix + "WeekEnd " + m_schedProps.stylePrefix + "Sun" + getTodayClassName(sun) + "\">");
+
-
out.append((sun != null) ? sun.getEvents() : "");
+
-
out.append("</div></td>");
+
-
+
-
out.append("</tr>");
+
-
 
+
-
return out.toString();
+
-
}
+
-
+
-
public String getHeader()
+
-
{
+
-
StringBuffer out = new StringBuffer("");
+
-
 
+
-
out.append("<tr id=\"" + m_schedProps.stylePrefix + "DOWHeader\">");
+
-
out.append("<div class=\"" + m_schedProps.stylePrefix + "DOWHeader\">");
+
-
out.append("<th class=\"" + m_schedProps.stylePrefix + "DOWWeekDayColHeader\"><div class=\"" + m_schedProps.stylePrefix + "DOWWeekDayHeader\">Mon</div></th>");
+
-
out.append("<th class=\"" + m_schedProps.stylePrefix + "DOWWeekDayColHeader\"><div class=\"" + m_schedProps.stylePrefix + "DOWWeekDayHeader\">Tue</div></th>");
+
-
out.append("<th class=\"" + m_schedProps.stylePrefix + "DOWWeekDayColHeader\"><div class=\"" + m_schedProps.stylePrefix + "DOWWeekDayHeader\">Wed</div></th>");
+
-
out.append("<th class=\"" + m_schedProps.stylePrefix + "DOWWeekDayColHeader\"><div class=\"" + m_schedProps.stylePrefix + "DOWWeekDayHeader\">Thu</div></th>");
+
-
out.append("<th class=\"" + m_schedProps.stylePrefix + "DOWWeekDayColHeader\"><div class=\"" + m_schedProps.stylePrefix + "DOWWeekDayHeader\">Fri</div></th>");
+
-
out.append("<th class=\"" + m_schedProps.stylePrefix + "DOWWeekEndColHeader\"><div class=\"" + m_schedProps.stylePrefix + "DOWWeekEndHeader\">Sat</div></th>");
+
-
out.append("<th class=\"" + m_schedProps.stylePrefix + "DOWWeekEndColHeader\"><div class=\"" + m_schedProps.stylePrefix + "DOWWeekEndHeader\">Sun</div></th>");
+
-
out.append("</div>");
+
-
out.append("</tr>");
+
-
 
+
-
return out.toString();
+
-
}
+
-
}
+
-
+
-
+
-
private String buildSimpleTable( WikiContext p_context,
+
-
  SchedProps p_oSchedProps,
+
-
  Iterator p_iterator)
+
-
throws PluginException
+
-
{
+
-
String inputLine = null;
+
-
String dateString = null;
+
-
String eventDesc = null;
+
-
String begCellFormat = null;
+
-
String endCellFormat = null;
+
-
 
+
-
StringBuffer entriesAsHTML = new StringBuffer();
+
-
+
-
ArrayList entryList = null;
+
-
+
-
Event event = null;
+
-
+
-
int daysDiff  = 0;
+
-
+
-
Date datetime = null;
+
-
Date now = new Date();
+
-
Date today = null;
+
-
 
+
-
// ----------------------------------------------------------------------------------- //
+
-
 
+
-
WikiEngine engine = p_context.getEngine();
+
-
+
-
entriesAsHTML = new StringBuffer();
+
-
+
-
today = new Date( new Date().getYear(), new Date().getMonth(), new Date().getDate());
+
-
 
+
-
entriesAsHTML.append("<DIV CLASS=\"" + p_oSchedProps.stylePrefix + "calendarList\">\n");
+
-
entriesAsHTML.append("<table class=\"" + p_oSchedProps.stylePrefix + "calendarListTable\" border=1 cellspacing=0>");
+
-
 
+
-
while( p_iterator.hasNext())
+
-
{
+
-
event = (Event) p_iterator.next();
+
-
 
+
-
Date eventDay = event.getDayDate();
+
-
 
+
-
Double daysUntilDue = new Double( (((eventDay.getTime() - today.getTime() ) / (1000*60*60))/24.0) );
+
-
 
+
-
daysDiff = (int) Math.round( daysUntilDue.doubleValue() ) ;
+
-
+
-
begCellFormat = "";
+
-
endCellFormat = "";
+
-
+
-
if( daysDiff <= p_oSchedProps.futureDays && daysDiff >= ( p_oSchedProps.pastDays * -1 ) )
+
-
{
+
-
entriesAsHTML.append("<tr>");
+
-
+
-
if( p_oSchedProps.boldToday && daysDiff == 0 )
+
-
{
+
-
begCellFormat = begCellFormat + "<b>";
+
-
endCellFormat = "</font></b>";
+
-
}
+
-
 
+
-
if( daysDiff <= p_oSchedProps.hotDays && daysDiff >= 0)
+
-
{
+
-
begCellFormat = begCellFormat + "<font color=\"" + p_oSchedProps.hotColor + "\">";
+
-
}
+
-
else if( daysDiff <= p_oSchedProps.warmDays && daysDiff >= 0 )
+
-
{
+
-
begCellFormat = begCellFormat + "<font color=\"" + p_oSchedProps.warmColor + "\">";
+
-
}
+
-
else if( daysDiff <= p_oSchedProps.coldDays && daysDiff >= 0 )
+
-
{
+
-
begCellFormat = begCellFormat + "<font color=\"" + p_oSchedProps.coldColor + "\">";
+
-
}
+
-
else
+
-
{
+
-
begCellFormat = begCellFormat + "<font color=\"" + p_oSchedProps.listColor + "\">";
+
-
}
+
-
+
-
entriesAsHTML.append( "<td>" + begCellFormat + "( due in " + daysDiff + " days )"                + endCellFormat + "</td>"  );
+
-
entriesAsHTML.append( "<td>" + begCellFormat + p_oSchedProps.outputDateFormatter.format(event.date)  + endCellFormat + "</td>" );
+
-
entriesAsHTML.append( "<td>" + begCellFormat + engine.textToHTML(p_context, event.desc)            + endCellFormat + "</td>" );
+
-
entriesAsHTML.append("</tr>");
+
-
}
+
-
}
+
-
 
+
-
entriesAsHTML.append("</table>");
+
-
entriesAsHTML.append("</DIV>\n");
+
-
+
-
return entriesAsHTML.toString();
+
-
}
+
-
+
-
 
+
-
private ArrayList getEvents(WikiContext p_context, SchedProps p_oSchedProps, DateRange dateRange)
+
-
throws PluginException
+
-
{
+
-
String pageContent = null;
+
-
String inputLine = null;
+
-
String dateString = null;
+
-
String eventDesc = null;
+
-
+
-
Date datetime = null;
+
-
+
-
ArrayList entryList = new ArrayList();
+
-
+
-
CalendarList.Event event = null;
+
-
+
-
StringReader oSR = null;
+
-
BufferedReader oBR = null;
+
-
 
+
-
WikiEngine engine = p_context.getEngine();
+
-
+
-
pageContent = engine.getText(p_context, engine.getPage(p_oSchedProps.listPageName)) ;
+
-
+
-
oSR = new StringReader(pageContent);
+
-
oBR = new BufferedReader(oSR);
+
-
 
+
-
try
+
-
{
+
-
while( (inputLine = oBR.readLine()) != null )
+
-
{
+
-
// Verify the basic imput format of the events (should be in a table and non blank)
+
-
if( inputLine != null && inputLine.indexOf("|") > -1 && inputLine.indexOf("|", 2) > 0 )
+
-
{
+
-
+
-
dateString = inputLine.substring(inputLine.indexOf("|") + 1, inputLine.indexOf("|", 2));
+
-
eventDesc = inputLine.substring(inputLine.indexOf("|", 2) + 1);
+
-
+
-
try
+
-
{
+
-
if( dateString.length() == 17 )
+
-
{
+
-
datetime = p_oSchedProps.dateTimeFormatter.parse(dateString);
+
-
}
+
-
else if( dateString.length() == 8 )
+
-
{
+
-
datetime = p_oSchedProps.dateFormatter.parse(dateString);
+
-
}
+
-
else
+
-
{
+
-
throw new PluginException("unparseable dateString, must be 17 char or 8 chars: " + dateString);
+
-
}
+
-
+
-
if( datetime != null && eventDesc != null )
+
-
{
+
-
if( dateRange.contains(datetime) )
+
-
{
+
-
event = new Event(datetime, eventDesc);
+
-
+
-
entryList.add(event);
+
-
}
+
-
else
+
-
{
+
-
log.debug(datetime.toString() + " was found to be outside the range (" + dateRange.start.toString() + ", " + dateRange.end.toString() );
+
-
}
+
-
}
+
-
}
+
-
catch (ParseException e)
+
-
{
+
-
throw new PluginException("unparseable dateString: " + dateString);
+
-
}
+
-
}
+
-
}
+
-
+
-
oSR.close( );
+
-
+
-
// Collections.sort( entryList );
+
-
 
+
-
}
+
-
catch(IOException ioex)
+
-
{
+
-
throw new PluginException("oops, something happened.  " + ioex.getMessage());
+
-
}
+
-
catch( Exception ex )
+
-
{
+
-
throw new PluginException("oops, here's what we know at this time: " + ex.getMessage());
+
-
}
+
-
 
+
-
return entryList;
+
-
}
+
-
+
-
+
-
public class SchedProps
+
-
{
+
-
public String listPageName = null;
+
-
public String pastColor = null;
+
-
public String hotColor = null;
+
-
public String warmColor = null;
+
-
public String coldColor = null;
+
-
public String listColor = null;
+
-
public String todayBgColor = null;
+
-
public String dayBgColor = null;
+
-
public String headerBgColor = null;
+
-
public String todayHeaderBgColor = null;
+
-
public String format = null;
+
-
+
-
public int futureDays = 0;
+
-
public int pastDays  = 0;
+
-
+
-
public int hotDays  = 0;
+
-
public int warmDays = 0;
+
-
public int coldDays = 0;
+
-
+
-
public boolean boldToday = true;
+
-
 
+
-
public SimpleDateFormat dateTimeFormatter = new SimpleDateFormat ("MM/dd/yy hh:mm a");
+
-
public SimpleDateFormat dateFormatter = new SimpleDateFormat ("MM/dd/yy");
+
-
public SimpleDateFormat outputDateFormatter = new SimpleDateFormat( "EEE, MMM dd 'at' hh:mm a");
+
-
+
-
public String stylePrefix = null;
+
-
}
+
-
+
-
+
-
/*
+
-
* This is some sort of DTO to organize all these options.
+
-
*/
+
-
public class PropertiesManager
+
-
{
+
-
private String PARAM_CALENDAR_LIST_PAGE_NAME = "listpagename";
+
-
private String PARAM_FUTURE_DAYS = "futuredays";
+
-
private String PARAM_PAST_DAYS = "pastdays";
+
-
+
-
private String PARAM_STYLE_PREFIX = "stylename";
+
-
 
+
-
private String PARAM_HOT_DAYS  = "hotdays";
+
-
private String PARAM_WARM_DAYS = "warmdays";
+
-
private String PARAM_COLD_DAYS = "colddays";
+
-
 
+
-
private String PARAM_PAST_COLOR = "pastcolor";
+
-
private String PARAM_HOT_COLOR  = "hotcolor";
+
-
private String PARAM_WARM_COLOR  = "warmcolor";
+
-
private String PARAM_COLD_COLOR  = "coldcolor";
+
-
private String PARAM_LIST_COLOR  = "listcolor";
+
-
private String PARAM_TODAY_BGCOLOR = "todaybgcolor";
+
-
private String PARAM_TODAY_HEADER_BGCOLOR = "todayheaderbgcolor";
+
-
private String PARAM_HEADER_BGCOLOR = "headerbgcolor";
+
-
private String PARAM_DAY_BGCOLOR = "daybgcolor";
+
-
+
-
private String PARAM_BOLD_TODAY = "boldtoday";
+
-
+
-
private String PARAM_FORMAT = "format";
+
-
 
+
-
private int DEFAULT_PAST_DAYS  = 1;
+
-
private int DEFAULT_FUTURE_DAYS = 3;
+
-
 
+
-
private String DEFAULT_PAST_COLOR = "#999999";
+
-
private String DEFAULT_HOT_COLOR  = "red";
+
-
private String DEFAULT_WARM_COLOR = "brown";
+
-
private String DEFAULT_COLD_COLOR = "black";
+
-
private String DEFAULT_LIST_COLOR = "lightgrey";
+
-
private String DEFAULT_TODAY_BGCOLOR = "lightblue";
+
-
private String DEFAULT_DAY_BGCOLOR = "#FOFOFO"; // grey
+
-
private String DEFAULT_HEADER_BGCOLOR = "#FOFOFO"; // dark grey
+
-
private String DEFAULT_TODAY_HEADER_BGCOLOR = "lightblue"; // dark grey
+
-
+
-
private String DEFAULT_FORMAT = "list";
+
-
+
-
private int DEFAULT_HOT_DAYS  =  1;
+
-
private int DEFAULT_WARM_DAYS =  7;
+
-
private int DEFAULT_COLD_DAYS = 14;
+
-
+
-
private boolean DEFAULT_BOLD_TODAY = true;
+
-
+
-
private String DEFAULT_STYLE_PREFIX = "";
+
-
+
-
public PropertiesManager()
+
-
{
+
-
}
+
-
+
-
public SchedProps getProperties(WikiContext p_context, Map p_params)
+
-
throws PluginException
+
-
{
+
-
SchedProps schedProps = new SchedProps();
+
-
 
+
-
String futureDaysString = null;
+
-
String pastDaysString = null;
+
-
String hotDaysString  = null;
+
-
String warmDaysString = null;
+
-
String coldDaysString = null;
+
-
String boldTodayString  = null;
+
-
+
-
schedProps.listPageName = (String) p_params.get( PARAM_CALENDAR_LIST_PAGE_NAME );
+
-
 
+
-
futureDaysString = (String) p_params.get( PARAM_FUTURE_DAYS );
+
-
pastDaysString = (String) p_params.get( PARAM_PAST_DAYS );
+
-
 
+
-
schedProps.pastColor  = (String) p_params.get( PARAM_PAST_COLOR  );
+
-
schedProps.hotColor  = (String) p_params.get( PARAM_HOT_COLOR  );
+
-
schedProps.warmColor = (String) p_params.get( PARAM_WARM_COLOR );
+
-
schedProps.coldColor = (String) p_params.get( PARAM_COLD_COLOR );
+
-
schedProps.listColor = (String) p_params.get( PARAM_LIST_COLOR );
+
-
schedProps.todayBgColor = (String) p_params.get( PARAM_TODAY_BGCOLOR );
+
-
schedProps.dayBgColor = (String) p_params.get( PARAM_DAY_BGCOLOR );
+
-
schedProps.headerBgColor = (String) p_params.get( PARAM_HEADER_BGCOLOR );
+
-
schedProps.todayHeaderBgColor = (String) p_params.get( PARAM_TODAY_HEADER_BGCOLOR );
+
-
   
+
-
hotDaysString  = (String) p_params.get( PARAM_HOT_DAYS  );
+
-
warmDaysString = (String) p_params.get( PARAM_WARM_DAYS );
+
-
coldDaysString = (String) p_params.get( PARAM_COLD_DAYS );
+
-
+
-
schedProps.format = (String) p_params.get( PARAM_FORMAT );
+
-
+
-
boldTodayString = (String) p_params.get( PARAM_BOLD_TODAY );
+
-
+
-
schedProps.stylePrefix = (String) p_params.get( PARAM_STYLE_PREFIX );
+
-
//
+
-
// Check prerequisites
+
-
//
+
-
 
+
-
if( schedProps.listPageName == null || schedProps.listPageName.length() < 1 )
+
-
{
+
-
throw new PluginException("Mandatory 'listpagename' parameter not found.");
+
-
}
+
-
+
-
if( futureDaysString == null || futureDaysString.length() < 1 )
+
-
{
+
-
schedProps.futureDays = DEFAULT_FUTURE_DAYS;
+
-
}
+
-
else
+
-
{
+
-
schedProps.futureDays = Integer.valueOf(futureDaysString).intValue();
+
-
}
+
-
 
+
-
if( pastDaysString == null || pastDaysString.length() < 1 )
+
-
{
+
-
schedProps.pastDays = DEFAULT_PAST_DAYS;
+
-
}
+
-
else
+
-
{
+
-
schedProps.pastDays = Integer.valueOf(pastDaysString).intValue();
+
-
}
+
-
+
-
if( schedProps.pastDays < 0 || schedProps.futureDays < 0 )
+
-
{
+
-
throw new PluginException("Invalid values for pastdays or futuredays.");
+
-
}
+
-
 
+
-
if( hotDaysString == null || hotDaysString.length() < 1 )
+
-
{
+
-
schedProps.hotDays = DEFAULT_HOT_DAYS;
+
-
}
+
-
else
+
-
{
+
-
schedProps.hotDays = Integer.valueOf(hotDaysString).intValue();
+
-
}
+
-
+
-
if( warmDaysString == null || warmDaysString.length() < 1 )
+
-
{
+
-
schedProps.warmDays = DEFAULT_WARM_DAYS;
+
-
}
+
-
else
+
-
{
+
-
schedProps.warmDays = Integer.valueOf(warmDaysString).intValue();
+
-
}
+
-
+
-
if( coldDaysString == null || coldDaysString.length() < 1 )
+
-
{
+
-
schedProps.coldDays = DEFAULT_COLD_DAYS;
+
-
}
+
-
else
+
-
{
+
-
schedProps.coldDays = Integer.valueOf(coldDaysString).intValue();
+
-
}
+
-
+
-
if( schedProps.pastColor == null || schedProps.pastColor.length() < 1 )
+
-
{
+
-
schedProps.pastColor = DEFAULT_PAST_COLOR;
+
-
}
+
-
+
-
if( schedProps.hotColor == null || schedProps.hotColor.length() < 1 )
+
-
{
+
-
schedProps.hotColor = DEFAULT_HOT_COLOR;
+
-
}
+
-
+
-
if( schedProps.warmColor == null || schedProps.warmColor.length() < 1 )
+
-
{
+
-
schedProps.warmColor = DEFAULT_WARM_COLOR;
+
-
}
+
-
+
-
if( schedProps.coldColor == null || schedProps.coldColor.length() < 1 )
+
-
{
+
-
schedProps.coldColor = DEFAULT_COLD_COLOR;
+
-
}
+
-
+
-
if( schedProps.listColor == null || schedProps.listColor.length() < 1 )
+
-
{
+
-
schedProps.listColor = DEFAULT_LIST_COLOR;
+
-
}
+
-
+
-
if( schedProps.todayBgColor == null || schedProps.todayBgColor.length() < 1 )
+
-
{
+
-
schedProps.todayBgColor = DEFAULT_TODAY_BGCOLOR;
+
-
}
+
-
+
-
if( schedProps.dayBgColor == null || schedProps.dayBgColor.length() < 1 )
+
-
{
+
-
schedProps.dayBgColor = DEFAULT_DAY_BGCOLOR;
+
-
}
+
-
+
-
if( schedProps.headerBgColor == null || schedProps.headerBgColor.length() < 1 )
+
-
{
+
-
schedProps.headerBgColor = DEFAULT_HEADER_BGCOLOR;
+
-
}
+
-
+
-
if( schedProps.todayHeaderBgColor == null || schedProps.todayHeaderBgColor.length() < 1 )
+
-
{
+
-
schedProps.todayHeaderBgColor = DEFAULT_TODAY_HEADER_BGCOLOR;
+
-
}
+
-
+
-
if( schedProps.format == null || schedProps.format.length() < 1 )
+
-
{
+
-
schedProps.format = DEFAULT_FORMAT;
+
-
}
+
-
+
-
if( boldTodayString == null || boldTodayString.length() < 1 )
+
-
{
+
-
schedProps.boldToday = DEFAULT_BOLD_TODAY;
+
-
}
+
-
else
+
-
{
+
-
if( boldTodayString.equalsIgnoreCase("NO")
+
-
|| boldTodayString.equalsIgnoreCase("N")
+
-
|| boldTodayString.equalsIgnoreCase("FALSE") )
+
-
{
+
-
schedProps.boldToday = false;
+
-
}
+
-
else if( boldTodayString.equalsIgnoreCase("YES")
+
-
|| boldTodayString.equalsIgnoreCase("Y")
+
-
|| boldTodayString.equalsIgnoreCase("TRUE"))
+
-
{
+
-
schedProps.boldToday = true;
+
-
}
+
-
else
+
-
{
+
-
schedProps.boldToday = DEFAULT_BOLD_TODAY;
+
-
}
+
-
}
+
-
+
-
if( schedProps.stylePrefix != null )
+
-
{
+
-
schedProps.stylePrefix = schedProps.stylePrefix.trim();
+
-
}
+
-
if( schedProps.stylePrefix == null || schedProps.stylePrefix.length() < 1 )
+
-
{
+
-
schedProps.stylePrefix = DEFAULT_STYLE_PREFIX;
+
-
}
+
-
+
-
return schedProps;
+
-
}
+
-
}
+
-
}
+
-
 
+
</body>
</body>
Line 1,238: Line 42:
</html>
</html>
-
 
+
<!-- *** End of the alert box *** -->
-
{|align="justify"
+
-
{{ #calendar: title=Talk:Team:IvyTech-South_Bend/Notebook |year=2010 | month=06 }}{{ #calendar: title=Talk:Team:IvyTech-South_Bend/Notebook |year=2010 | month=07 }}{{ #calendar: title=Talk:Team:IvyTech-South_Bend/Notebook |year=2010 | month=08 }}
+
-
 
+
-
 
+
-
{{ #calendar: title=Talk:Team:IvyTech-South_Bend/Notebook |year=2010 | month=09 }}{{ #calendar: title=Talk:Team:IvyTech-South_Bend/Notebook |year=2010 | month=10 }}{{ #calendar: title=Talk:Team:IvyTech-South_Bend/Notebook |year=2010 | month=11 }}
+
-
|}
+

Latest revision as of 12:40, 29 September 2010