HashMap headerList = new HashMap();
HashMap headerLinkList = new HashMap();
HashMap dateList = new HashMap();
ArrayList calendarNavBarList = new ArrayList();
Calendar currentCalendar = Calendar.getInstance();
int thisDayOfMonth = currentCalendar.get(Calendar.DAY_OF_MONTH);
int thisMonthOfYear = currentCalendar.get(Calendar.MONTH);
String thisMonth = getCalenderMonthName(thisMonthOfYear);
int thisYear = currentCalendar.get(Calendar.YEAR);
if (calendarType != null && (calendarType.equals("DAILY") || calendarType.equals(""))) {
int previousDailyDay = 0;
String previousDailyMonth = "";
int previousDailyYear = 0;
if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
Calendar previousCalendarWeek = Calendar.getInstance();
previousCalendarWeek.set(currentYear, currentMonth, currentDay);
previousCalendarWeek.add(Calendar.DATE, -1);
previousDailyDay = previousCalendarWeek.get(Calendar.DATE);
int intYearOfMonth = previousCalendarWeek.get(Calendar.MONTH);
previousDailyMonth = getCalenderMonthName(intYearOfMonth);
previousDailyYear = previousCalendarWeek.get(Calendar.YEAR);
}
int nextDailyDay = 0;
String nextDailyMonth = "";
int nextDailyYear = 0;
if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
Calendar nextCalendarWeek = Calendar.getInstance();
nextCalendarWeek.set(currentYear, currentMonth, currentDay);
nextCalendarWeek.add(Calendar.DATE, +1);
nextDailyDay = nextCalendarWeek.get(Calendar.DATE);
int intYearOfMonth = nextCalendarWeek.get(Calendar.MONTH);
nextDailyYear = nextCalendarWeek.get(Calendar.YEAR);
nextDailyMonth = getCalenderMonthName(intYearOfMonth);
}
StringBuffer previous = new StringBuffer();
previous.append("c_goTo('/calendar.do?Type=DAILY&selectedDay=" + previousDailyDay);
previous.append("&selectedMonthName=" + previousDailyMonth + "&selectedYear=" + previousDailyYear + "');");
StringBuffer current = new StringBuffer();
current.append("c_goTo('/calendar.do?Type=DAILY&selectedDay=" + thisDayOfMonth);
current.append("&selectedMonthName=" + thisMonth + "&selectedYear=" + thisYear + "');");
StringBuffer next = new StringBuffer();
next.append("c_goTo('/calendar.do?Type=DAILY&selectedDay=" + nextDailyDay);
next.append("&selectedMonthName=" + nextDailyMonth + "&selectedYear=" + nextDailyYear + "');");
calendarNavBarList.add(new DDNameValue("Previous", previous.toString()));
calendarNavBarList.add(new DDNameValue("Today", current.toString()));
calendarNavBarList.add(new DDNameValue("Next", next.toString()));
} else if (calendarType != null && (calendarType.equals("WEEKLY") || calendarType.equals("WEEKLYCOLUMNS"))) {
int previousWeekDate = 0;
String previousWeekMonth = "";
int previousWeekYear = 0;
if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
Calendar previousCalendarWeek = Calendar.getInstance();
previousCalendarWeek.set(currentYear, currentMonth, currentDay);
previousCalendarWeek.add(Calendar.DATE, -7);
previousWeekDate = previousCalendarWeek.get(Calendar.DATE);
int intYearOfMonth = previousCalendarWeek.get(Calendar.MONTH);
previousWeekMonth = getCalenderMonthName(intYearOfMonth);
previousWeekYear = previousCalendarWeek.get(Calendar.YEAR);
}
int nextWeekDay = 0;
String nextWeekMonth = "";
int nextWeekYear = 0;
if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
Calendar nextCalendarWeek = Calendar.getInstance();
nextCalendarWeek.set(currentYear, currentMonth, currentDay);
nextCalendarWeek.add(Calendar.DATE, +7);
nextWeekDay = nextCalendarWeek.get(Calendar.DATE);
int intYearOfMonth = nextCalendarWeek.get(Calendar.MONTH);
nextWeekYear = nextCalendarWeek.get(Calendar.YEAR);
nextWeekMonth = getCalenderMonthName(intYearOfMonth);
}
StringBuffer previous = new StringBuffer();
previous.append("c_goTo('/calendar.do?Type=" + calendarType + "&selectedDay=" + previousWeekDate);
previous.append("&selectedMonthName=" + previousWeekMonth + "&selectedYear=" + previousWeekYear + "');");
StringBuffer current = new StringBuffer();
current.append("c_goTo('/calendar.do?Type=" + calendarType + "&selectedDay=" + thisDayOfMonth);
current.append("&selectedMonthName=" + thisMonth + "&selectedYear=" + thisYear + "');");
StringBuffer next = new StringBuffer();
next.append("c_goTo('/calendar.do?Type=" + calendarType + "&selectedDay=" + nextWeekDay);
next.append("&selectedMonthName=" + nextWeekMonth + "&selectedYear=" + nextWeekYear + "');");
calendarNavBarList.add(new DDNameValue("Previous", previous.toString()));
calendarNavBarList.add(new DDNameValue("Current Week", current.toString()));
calendarNavBarList.add(new DDNameValue("Next", next.toString()));
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd");
String dailyGo = "c_goTo('/calendar.do?Type=DAILY";
if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
Calendar headerCalendarWeek = Calendar.getInstance();
headerCalendarWeek.set(currentYear, currentMonth, currentDay);
int dayOfWeek = headerCalendarWeek.get(Calendar.DAY_OF_WEEK);
// Subtracting it with 2 coz in the Calendar Starting Day is Monday.
int offset = dayOfWeek - 2;
if (offset < 0) {
int daysInWeek = 7;
// if we are before the current day of the week, we need to fall all
// the way back to the previous beginning of the week. calculating our
// offset in this way will give us the right num of days to the
// previous start. this makes it easy to just add it to the
// currentDate.
offset = daysInWeek + offset;
}
int currentDate = headerCalendarWeek.get(Calendar.DATE);
headerCalendarWeek.set(Calendar.DATE, currentDate - offset);
int headerDayOfMonth = headerCalendarWeek.get(Calendar.DATE);
int headerMonthOfYear = headerCalendarWeek.get(Calendar.MONTH);
int headerYear = headerCalendarWeek.get(Calendar.YEAR);
try {
// This is used in the columnar weekly view for calculating the
// date to be filled in when you click on a empty cell.
calendarNavBarMap.put("startDayOfWeek", new Integer(headerDayOfMonth));
} catch (NumberFormatException nfe) {
logger.info("[setCalendarNavBar]: The offset for the clickable weekly view boxes will probably be broken.");
calendarNavBarMap.put("startDayOfWeek", new Integer(0));
}
String dateString = headerYear + ",'" + getCalenderMonthName(headerMonthOfYear) + "'," + headerDayOfMonth;
String headerDate = formatter.format(headerCalendarWeek.getTime());
String dailyDate = "&selectedDay=" + headerDayOfMonth + "&selectedMonthName=" + getCalenderMonthName(headerMonthOfYear) + "&selectedYear="
+ headerYear;
String action = "ScheduleActivity(" + dateString + ",'','');";
dateList.put(String.valueOf(0), action);
headerLinkList.put(String.valueOf(0), dailyGo + dailyDate + "');");
headerList.put(String.valueOf(0), headerDate);
int count = 1;
for (int i = 0; i < 6; i++) {
headerCalendarWeek.add(Calendar.DATE, 1);
headerDayOfMonth = headerCalendarWeek.get(Calendar.DAY_OF_MONTH);
headerMonthOfYear = headerCalendarWeek.get(Calendar.MONTH);
headerYear = headerCalendarWeek.get(Calendar.YEAR);
dateString = headerYear + ",'" + getCalenderMonthName(headerMonthOfYear) + "'," + headerDayOfMonth;
action = "ScheduleActivity(" + dateString + ",'','');";
dateList.put(String.valueOf(count), action);
headerDate = formatter.format(headerCalendarWeek.getTime());
headerList.put(String.valueOf(count), headerDate);
dailyDate = "&selectedDay=" + headerDayOfMonth + "&selectedMonthName=" + getCalenderMonthName(headerMonthOfYear) + "&selectedYear="
+ headerYear;
headerLinkList.put(String.valueOf(count), dailyGo + dailyDate + "');");
count++;
}
}
} else if (calendarType != null && calendarType.equals("MONTHLY")) {
int previousMonthlyDay = 0;
String previousMonthlyMonth = "";
int previousMonthlyYear = 0;
if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
Calendar previousCalendarWeek = Calendar.getInstance();
previousCalendarWeek.set(currentYear, currentMonth, currentDay);
previousCalendarWeek.add(Calendar.MONTH, -1);
previousMonthlyDay = previousCalendarWeek.get(Calendar.DATE);
int intYearOfMonth = previousCalendarWeek.get(Calendar.MONTH);
previousMonthlyMonth = getCalenderMonthName(intYearOfMonth);
previousMonthlyYear = previousCalendarWeek.get(Calendar.YEAR);
}
int nextMonthlyDay = 0;
String nextMonthlyMonth = "";
int nextMonthlyYear = 0;
if (currentDay != 0 && currentMonth >= 0 && currentYear != 0) {
Calendar nextCalendarWeek = Calendar.getInstance();
nextCalendarWeek.set(currentYear, currentMonth, currentDay);
nextCalendarWeek.add(Calendar.MONTH, 1);
nextMonthlyDay = nextCalendarWeek.get(Calendar.DATE);
int intYearOfMonth = nextCalendarWeek.get(Calendar.MONTH);
nextMonthlyYear = nextCalendarWeek.get(Calendar.YEAR);
nextMonthlyMonth = getCalenderMonthName(intYearOfMonth);
}
StringBuffer previous = new StringBuffer();
previous.append("c_goTo('/calendar.do?Type=MONTHLY&selectedDay=" + previousMonthlyDay);
previous.append("&selectedMonthName=" + previousMonthlyMonth + "&selectedYear=" + previousMonthlyYear + "');");