Source Code Cross Referenced for CalendarAction.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » calendar » tool » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » sakai » org.sakaiproject.calendar.tool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**********************************************************************************
0002:         * $URL: https://source.sakaiproject.org/svn/calendar/tags/sakai_2-4-1/calendar-tool/tool/src/java/org/sakaiproject/calendar/tool/CalendarAction.java $
0003:         * $Id: CalendarAction.java 20878 2007-02-01 20:46:40Z bkirschn@umich.edu $
0004:         ***********************************************************************************
0005:         *
0006:         * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
0007:         * 
0008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
0009:         * you may not use this file except in compliance with the License. 
0010:         * You may obtain a copy of the License at
0011:         * 
0012:         *      http://www.opensource.org/licenses/ecl1.php
0013:         * 
0014:         * Unless required by applicable law or agreed to in writing, software 
0015:         * distributed under the License is distributed on an "AS IS" BASIS, 
0016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
0017:         * See the License for the specific language governing permissions and 
0018:         * limitations under the License.
0019:         *
0020:         **********************************************************************************/package org.sakaiproject.calendar.tool;
0021:
0022:        import java.io.ByteArrayInputStream;
0023:        import java.util.ArrayList;
0024:        import java.util.Arrays;
0025:        import java.util.Collection;
0026:        import java.util.GregorianCalendar;
0027:        import java.util.HashMap;
0028:        import java.util.Iterator;
0029:        import java.util.LinkedHashMap;
0030:        import java.util.List;
0031:        import java.util.Map;
0032:        import java.util.Set;
0033:        import java.util.TimeZone;
0034:        import java.util.Vector;
0035:
0036:        import org.apache.commons.logging.Log;
0037:        import org.apache.commons.logging.LogFactory;
0038:        import org.sakaiproject.authz.api.PermissionsHelper;
0039:        import org.sakaiproject.authz.cover.SecurityService;
0040:        import org.sakaiproject.calendar.api.Calendar;
0041:        import org.sakaiproject.calendar.api.CalendarEdit;
0042:        import org.sakaiproject.calendar.api.CalendarEvent;
0043:        import org.sakaiproject.calendar.api.CalendarEventEdit;
0044:        import org.sakaiproject.calendar.api.CalendarEventVector;
0045:        import org.sakaiproject.calendar.api.RecurrenceRule;
0046:        import org.sakaiproject.calendar.cover.CalendarImporterService;
0047:        import org.sakaiproject.calendar.cover.CalendarService;
0048:        import org.sakaiproject.cheftool.Context;
0049:        import org.sakaiproject.cheftool.JetspeedRunData;
0050:        import org.sakaiproject.cheftool.RunData;
0051:        import org.sakaiproject.cheftool.VelocityPortlet;
0052:        import org.sakaiproject.cheftool.VelocityPortletStateAction;
0053:        import org.sakaiproject.cheftool.api.Menu;
0054:        import org.sakaiproject.cheftool.api.MenuItem;
0055:        import org.sakaiproject.cheftool.menu.MenuEntry;
0056:        import org.sakaiproject.cheftool.menu.MenuImpl;
0057:        import org.sakaiproject.component.cover.ServerConfigurationService;
0058:        import org.sakaiproject.content.api.FilePickerHelper;
0059:        import org.sakaiproject.content.cover.ContentHostingService;
0060:        import org.sakaiproject.content.cover.ContentTypeImageService;
0061:        import org.sakaiproject.entity.api.Reference;
0062:        import org.sakaiproject.entity.api.ResourceProperties;
0063:        import org.sakaiproject.entity.cover.EntityManager;
0064:        import org.sakaiproject.event.api.SessionState;
0065:        import org.sakaiproject.exception.IdInvalidException;
0066:        import org.sakaiproject.exception.IdUnusedException;
0067:        import org.sakaiproject.exception.IdUsedException;
0068:        import org.sakaiproject.exception.ImportException;
0069:        import org.sakaiproject.exception.InUseException;
0070:        import org.sakaiproject.exception.PermissionException;
0071:        import org.sakaiproject.site.api.Group;
0072:        import org.sakaiproject.site.api.Site;
0073:        import org.sakaiproject.site.cover.SiteService;
0074:        import org.sakaiproject.time.api.Time;
0075:        import org.sakaiproject.time.api.TimeBreakdown;
0076:        import org.sakaiproject.time.api.TimeRange;
0077:        import org.sakaiproject.time.cover.TimeService;
0078:        import org.sakaiproject.user.cover.UserDirectoryService;
0079:        import org.sakaiproject.user.api.UserNotDefinedException;
0080:        import org.sakaiproject.util.CalendarUtil;
0081:        import org.sakaiproject.util.FileItem;
0082:        import org.sakaiproject.util.FormattedText;
0083:        import org.sakaiproject.util.MergedList;
0084:        import org.sakaiproject.util.MergedListEntryProviderBase;
0085:        import org.sakaiproject.util.MergedListEntryProviderFixedListWrapper;
0086:        import org.sakaiproject.util.ParameterParser;
0087:        import org.sakaiproject.util.ResourceLoader;
0088:        import org.sakaiproject.util.StringUtil;
0089:        import org.sakaiproject.util.Validator;
0090:        import org.sakaiproject.tool.api.Placement;
0091:        import org.sakaiproject.tool.cover.SessionManager;
0092:        import org.sakaiproject.tool.cover.ToolManager;
0093:
0094:        /**
0095:         * The schedule tool.
0096:         */
0097:        public class CalendarAction extends VelocityPortletStateAction {
0098:            /** Our logger. */
0099:            private static Log M_log = LogFactory.getLog(CalendarAction.class);
0100:
0101:            /** Resource bundle using current language locale */
0102:            private static ResourceLoader rb = new ResourceLoader("calendar");
0103:
0104:            private static final String CONFIRM_IMPORT_WIZARD_STATE = "CONFIRM_IMPORT";
0105:            private static final String WIZARD_IMPORT_FILE = "importFile";
0106:            private static final String GENERIC_SELECT_FILE_IMPORT_WIZARD_STATE = "GENERIC_SELECT_FILE";
0107:            private static final String OTHER_SELECT_FILE_IMPORT_WIZARD_STATE = "OTHER_SELECT_FILE";
0108:            private static final String WIZARD_IMPORT_TYPE = "importType";
0109:            private static final String SELECT_TYPE_IMPORT_WIZARD_STATE = "SELECT_TYPE";
0110:            private static final String IMPORT_WIZARD_SELECT_TYPE_STATE = SELECT_TYPE_IMPORT_WIZARD_STATE;
0111:            private static final String STATE_SCHEDULE_IMPORT = "scheduleImport";
0112:            private static final String CALENDAR_INIT_PARAMETER = "calendar";
0113:            private static final int HOURS_PER_DAY = 24;
0114:            private static final int NUMBER_HOURS_PER_PAGE_FOR_WEEK_VIEW = 10;
0115:
0116:            private static final int FIRST_PAGE_START_HOUR = 0;
0117:            private static final int SECOND_PAGE_START_HOUR = 8;
0118:            private static final int THIRD_PAGE_START_HOUR = 14;
0119:
0120:            private static final String STATE_YEAR = "calYear";
0121:            private static final String STATE_MONTH = "calMonth";
0122:            private static final String STATE_DAY = "calDay";
0123:
0124:            private static final String STATE_REVISE = "revise";
0125:
0126:            private static final String STATE_SET_FREQUENCY = "setFrequency";
0127:            private static final String FREQUENCY_SELECT = "frequencySelect";
0128:            private static final String TEMP_FREQ_SELECT = "tempFrequencySelect";
0129:            private static final String DEFAULT_FREQ = "once";
0130:            private static final String FREQ_ONCE = "once";
0131:
0132:            private static final String SSTATE__RECURRING_RULE = "rule";
0133:            private static final String STATE_BEFORE_SET_RECURRENCE = "state_before_set_recurrence";
0134:
0135:            private final static String TIME_FILTER_OPTION_VAR = "timeFilterOption";
0136:            private final static String TIME_FILTER_SETTING_CUSTOM_START_DATE_VAR = "customStartDate";
0137:            private final static String TIME_FILTER_SETTING_CUSTOM_END_DATE_VAR = "customEndDate";
0138:            private final static String TIME_FILTER_SETTING_CUSTOM_START_YEAR = "customStartYear";
0139:            private final static String TIME_FILTER_SETTING_CUSTOM_END_YEAR = "customEndYear";
0140:            private final static String TIME_FILTER_SETTING_CUSTOM_START_MONTH = "customStartMonth";
0141:            private final static String TIME_FILTER_SETTING_CUSTOM_END_MONTH = "customEndMonth";
0142:            private final static String TIME_FILTER_SETTING_CUSTOM_START_DAY = "customStartDay";
0143:            private final static String TIME_FILTER_SETTING_CUSTOM_END_DAY = "customEndDay";
0144:
0145:            /** state selected view */
0146:            private static final String STATE_SELECTED_VIEW = "state_selected_view";
0147:
0148:            /** DELIMETER used to separate the list of custom fields for this calendar. */
0149:            private final static String ADDFIELDS_DELIMITER = "_,_";
0150:
0151:            protected final static String STATE_INITED = "calendar.state.inited";
0152:
0153:            /** for sorting in list view */
0154:            private static final String STATE_DATE_SORT_DSC = "dateSortedDsc";
0155:
0156:            // for group/section awareness
0157:            private final static String STATE_SCHEDULE_TO = "scheduleTo";
0158:            private final static String STATE_SCHEDULE_TO_GROUPS = "scheduleToGroups";
0159:            private static final String STATE_SELECTED_GROUPS_FILTER = "groups_filters";
0160:
0161:            /**
0162:             * Used by callback to convert channel references to channels.
0163:             */
0164:            private final class CalendarReferenceToChannelConverter
0165:                    implements 
0166:                    MergedListEntryProviderFixedListWrapper.ReferenceToChannelConverter {
0167:                public Object getChannel(String channelReference) {
0168:                    try {
0169:                        return CalendarService.getCalendar(channelReference);
0170:                    } catch (IdUnusedException e) {
0171:                        return null;
0172:                    } catch (PermissionException e) {
0173:                        return null;
0174:                    }
0175:                }
0176:            }
0177:
0178:            /*
0179:             * Callback class so that we can form references in a generic way.
0180:             */
0181:            private final class CalendarChannelReferenceMaker implements 
0182:                    MergedList.ChannelReferenceMaker {
0183:                public String makeReference(String siteId) {
0184:                    return CalendarService.calendarReference(siteId,
0185:                            SiteService.MAIN_CONTAINER);
0186:                }
0187:            }
0188:
0189:            /**
0190:             * Converts a string that is used to store additional attribute fields to an array of strings.
0191:             */
0192:            private String[] fieldStringToArray(String addfields_str,
0193:                    String delimiter) {
0194:                String[] fields = addfields_str.split(delimiter);
0195:                List destStringList = new ArrayList();
0196:
0197:                // Don't copy empty fields.
0198:                for (int i = 0; i < fields.length; i++) {
0199:                    if (fields[i].length() > 0) {
0200:                        destStringList.add(fields[i]);
0201:                    }
0202:                }
0203:
0204:                return (String[]) destStringList
0205:                        .toArray(new String[destStringList.size()]);
0206:            }
0207:
0208:            /**
0209:             * Enable or disable the observer
0210:             * @param enable if true, the observer is enabled, if false, it is disabled
0211:             */
0212:            protected void enableObserver(SessionState sstate, boolean enable) {
0213:                if (enable) {
0214:                    enableObservers(sstate);
0215:                } else {
0216:                    disableObservers(sstate);
0217:                }
0218:            }
0219:
0220:            // myYear class
0221:            public class MyYear {
0222:                private MyMonth[][] yearArray;
0223:
0224:                private int year;
0225:                private MyMonth m;
0226:
0227:                public MyYear() {
0228:                    yearArray = new MyMonth[4][3];
0229:                    m = null;
0230:                    year = 0;
0231:                }
0232:
0233:                public void setMonth(MyMonth m, int x, int y) {
0234:
0235:                    yearArray[x][y] = m;
0236:
0237:                }
0238:
0239:                public MyMonth getMonth(int x, int y) {
0240:                    m = yearArray[x][y];
0241:                    return (m);
0242:                }
0243:
0244:                public void setYear(int y) {
0245:                    year = y;
0246:                }
0247:
0248:                public int getYear() {
0249:                    return year;
0250:                }
0251:
0252:            }// myYear class
0253:
0254:            // my week
0255:            public class MyWeek {
0256:                private MyDate[] week;
0257:                private int weekOfMonth;
0258:
0259:                public MyWeek() {
0260:                    week = new MyDate[7];
0261:                    weekOfMonth = 0;
0262:                }
0263:
0264:                public void setWeek(int i, MyDate date) {
0265:                    week[i] = date;
0266:                }
0267:
0268:                public MyDate getWeek(int i) {
0269:                    return week[i];
0270:                }
0271:
0272:                public String getWeekRange() {
0273:                    String range = null;
0274:                    range = week[0].getTodayDate() + "   " + "-" + " "
0275:                            + week[6].getTodayDate();
0276:                    return range;
0277:                }
0278:
0279:                public void setWeekOfMonth(int w) {
0280:                    weekOfMonth = w;
0281:                }
0282:
0283:                public int getWeekOfMonth() {
0284:                    return weekOfMonth + 1;
0285:                }
0286:
0287:            }
0288:
0289:            // myMonth class
0290:            public class MyMonth {
0291:                private MyDate[][] monthArray;
0292:                // private myDate[] monthArray;
0293:                private MyDate result;
0294:                private String monthName;
0295:                private int month;
0296:                private int row;
0297:                private int numberOfDaysInMonth;
0298:
0299:                public MyMonth() {
0300:                    result = null;
0301:                    monthArray = new MyDate[6][7];
0302:                    //monthArray = new myDate[43];
0303:                    month = 0;
0304:                    row = 0;
0305:                    numberOfDaysInMonth = 0;
0306:                }
0307:
0308:                public void setRow(int r) {
0309:                    row = r;
0310:                }
0311:
0312:                public int getRow() {
0313:                    return row;
0314:                }
0315:
0316:                public void setNumberOfDaysInMonth(int daysInMonth) {
0317:                    numberOfDaysInMonth = daysInMonth;
0318:                }
0319:
0320:                public int getNumberOfDaysInMonth() {
0321:                    return numberOfDaysInMonth;
0322:                }
0323:
0324:                public void setDay(MyDate d, int x, int y) {
0325:                    monthArray[x][y] = d;
0326:                    //monthArray[x] = d;
0327:                }
0328:
0329:                public MyDate getDay(int x, int y) {
0330:                    result = monthArray[x][y];
0331:                    //result = monthArray[x];
0332:                    return (result);
0333:                }
0334:
0335:                public void setMonthName(String name) {
0336:                    monthName = name;
0337:                }
0338:
0339:                public String getMonthName() {
0340:                    return monthName;
0341:                }
0342:
0343:                public void setMonth(int m) {
0344:                    month = m;
0345:                }
0346:
0347:                public int getMonth() {
0348:                    return month;
0349:                }
0350:
0351:            }// myMonth
0352:
0353:            // myDay class
0354:            public class MyDay {
0355:                private String m_data; // data will have the days in the month
0356:                private String m_attachment_data; // data need to be displayed and attached, currently
0357:                // this si a string and it can be any structure in the future.
0358:                private int m_flag; // 0 if it is not a current date , 1 if it is a current date
0359:                private int day;
0360:                private int year;
0361:                private int month;
0362:                private String dayName; // name for each day
0363:                private String todayDate;
0364:
0365:                public MyDay() {
0366:                    m_data = "";
0367:                    m_flag = 0;
0368:                    m_attachment_data = "";
0369:                    day = 0;
0370:                    dayName = "";
0371:                    todayDate = "";
0372:                }
0373:
0374:                public void setDay(int d) {
0375:                    day = d;
0376:                }
0377:
0378:                public int getDay() {
0379:                    return day;
0380:                }
0381:
0382:                public void setFlag(int flag) {
0383:                    m_flag = flag;
0384:                }
0385:
0386:                public void setData(String data) {
0387:                    m_data = data;
0388:                }
0389:
0390:                public int getFlag() {
0391:                    return m_flag;
0392:                }
0393:
0394:                public String getData() {
0395:                    return (m_data);
0396:                }
0397:
0398:                public void setAttachment(String data) {
0399:                    m_attachment_data = data;
0400:                }
0401:
0402:                public String getAttachment() {
0403:                    return (m_attachment_data);
0404:                }
0405:
0406:                public void setDayName(String dname) {
0407:                    dayName = dname;
0408:                }
0409:
0410:                public String getDayName() {
0411:                    return dayName;
0412:                }
0413:
0414:                public void setTodayDate(String date) {
0415:                    todayDate = date;
0416:                }
0417:
0418:                public String getTodayDate() {
0419:                    return todayDate;
0420:                }
0421:
0422:                public void setYear(int y) {
0423:                    year = y;
0424:                }
0425:
0426:                public int getYear() {
0427:                    return year;
0428:                }
0429:
0430:                public void setMonth(int m) {
0431:                    month = m;
0432:                }
0433:
0434:                public int getMonth() {
0435:                    return month;
0436:                }
0437:            }// myDay class
0438:
0439:            public class EventClass {
0440:                private String displayName;
0441:                private long firstTime;
0442:                private String eventId;
0443:
0444:                public EventClass() {
0445:                    displayName = "";
0446:                    firstTime = 0;
0447:                }
0448:
0449:                public void setDisplayName(String name) {
0450:                    displayName = name;
0451:                }
0452:
0453:                public void setFirstTime(long time) {
0454:                    firstTime = time;
0455:                }
0456:
0457:                public String getDisplayName() {
0458:                    return displayName;
0459:                }
0460:
0461:                public long getfirstTime() {
0462:                    return firstTime;
0463:                }
0464:
0465:                public void setId(String id) {
0466:                    eventId = id;
0467:                }
0468:
0469:                public String getId() {
0470:                    return eventId;
0471:                }
0472:            }
0473:
0474:            public class EventDisplayClass {
0475:                private CalendarEvent calendareventobj;
0476:                private boolean eventConflict;
0477:                private int eventPosition;
0478:
0479:                public EventDisplayClass() {
0480:
0481:                    eventConflict = false;
0482:                    calendareventobj = null;
0483:                    eventPosition = 0;
0484:                }
0485:
0486:                public void setEvent(CalendarEvent ce, boolean eventconf,
0487:                        int pos) {
0488:                    eventConflict = eventconf;
0489:                    calendareventobj = ce;
0490:                    eventPosition = pos;
0491:
0492:                }
0493:
0494:                public void setFlag(boolean conflict) {
0495:                    eventConflict = conflict;
0496:                }
0497:
0498:                public void setPosition(int position) {
0499:                    eventPosition = position;
0500:                }
0501:
0502:                public int getPosition() {
0503:                    return eventPosition;
0504:                }
0505:
0506:                public CalendarEvent getEvent() {
0507:                    return calendareventobj;
0508:                }
0509:
0510:                public boolean getFlag() {
0511:                    return eventConflict;
0512:                }
0513:
0514:            }
0515:
0516:            public class MyDate {
0517:                private MyDay day = null;
0518:                private MyMonth month = null;
0519:                private MyYear year = null;
0520:                private String dayName = "";
0521:                private Iterator iteratorObj = null;
0522:                private int flag = -1;
0523:                private Vector eVector;
0524:
0525:                public MyDate() {
0526:                    day = new MyDay();
0527:                    month = new MyMonth();
0528:                    year = new MyYear();
0529:                }
0530:
0531:                public void setTodayDate(int m, int d, int y) {
0532:                    day.setDay(d);
0533:                    month.setMonth(m);
0534:                    year.setYear(y);
0535:                }
0536:
0537:                public void setNumberOfDaysInMonth(int daysInMonth) {
0538:                    month.setNumberOfDaysInMonth(daysInMonth);
0539:                }
0540:
0541:                public int getNumberOfDaysInMonth() {
0542:                    return month.getNumberOfDaysInMonth();
0543:                }
0544:
0545:                public String getTodayDate() {
0546:                    String date = month.getMonth() + "/" + day.getDay() + "/"
0547:                            + year.getYear();
0548:                    return date;
0549:                }
0550:
0551:                public void setFlag(int i) {
0552:                    flag = i;
0553:                }
0554:
0555:                public int getFlag() {
0556:                    return flag;
0557:                }
0558:
0559:                public void setDayName(String name) {
0560:                    dayName = name;
0561:                }
0562:
0563:                public void setNameOfMonth(String name) {
0564:                    month.setMonthName(name);
0565:                }
0566:
0567:                public String getDayName() {
0568:                    return dayName;
0569:                }
0570:
0571:                public int getDay() {
0572:                    return day.getDay();
0573:                }
0574:
0575:                public int getMonth() {
0576:                    return month.getMonth();
0577:                }
0578:
0579:                public String getNameOfMonth() {
0580:                    return month.getMonthName();
0581:                }
0582:
0583:                public int getYear() {
0584:                    return year.getYear();
0585:                }
0586:
0587:                public void setEventBerWeek(Vector eventVector) {
0588:
0589:                    eVector = eventVector;
0590:                }
0591:
0592:                public void setEventBerDay(Vector eventVector) {
0593:
0594:                    eVector = eventVector;
0595:                }
0596:
0597:                public Vector getEventsBerDay(int index) {
0598:                    Vector dayVector = new Vector();
0599:
0600:                    if (eVector != null)
0601:                        dayVector = (Vector) eVector.get(index);
0602:
0603:                    if (dayVector == null)
0604:                        dayVector = new Vector();
0605:
0606:                    return dayVector;
0607:
0608:                }
0609:
0610:                public Vector getEventsBerWeek(int index) {
0611:                    Vector dayVector = new Vector();
0612:                    if (eVector != null)
0613:                        dayVector = (Vector) eVector.get(index);
0614:
0615:                    if (dayVector == null)
0616:                        dayVector = new Vector();
0617:
0618:                    return dayVector;
0619:                }
0620:
0621:                public void setEvents(Iterator t) {
0622:                    iteratorObj = t;
0623:                }
0624:
0625:                public Vector getEvents() {
0626:                    Vector vectorObj = new Vector();
0627:                    int i = 0;
0628:                    if (iteratorObj != null) {
0629:                        while (iteratorObj.hasNext()) {
0630:                            vectorObj.add(i, iteratorObj.next());
0631:                            i++;
0632:                        }
0633:                    }
0634:                    return vectorObj;
0635:                }
0636:
0637:            }
0638:
0639:            public class Helper {
0640:                private int numberOfActivity = 0;
0641:
0642:                public int getduration(long x, int b) {
0643:
0644:                    Long l = new Long(x);
0645:                    int v = l.intValue() / 3600000;
0646:                    return v;
0647:                }
0648:
0649:                public int getFractionIn(long x, int b) {
0650:                    Long ll = new Long(x);
0651:                    int y = (ll.intValue() - (b * 3600000));
0652:                    int m = (y / 60000);
0653:                    return m;
0654:                }
0655:
0656:                public CalendarEvent getActivity(Vector mm) {
0657:                    int size = mm.size();
0658:                    numberOfActivity = size;
0659:
0660:                    CalendarEvent activityEvent, event = null;
0661:
0662:                    if (size > 0) {
0663:                        activityEvent = (CalendarEvent) mm.elementAt(0);
0664:                        long temp = activityEvent.getRange().duration();
0665:                        for (int i = 0; i < size; i++) {
0666:                            activityEvent = (CalendarEvent) mm.elementAt(i);
0667:                            if (temp < activityEvent.getRange().duration()) {
0668:                                temp = activityEvent.getRange().duration();
0669:                                event = activityEvent;
0670:                            }
0671:                        }
0672:                    } else
0673:                        event = null;
0674:
0675:                    return event;
0676:                }
0677:
0678:                public int getNumberOfActivity() {
0679:                    return numberOfActivity;
0680:                }
0681:
0682:                public int getInt(long x) {
0683:                    Long temp = new Long(x);
0684:                    return (temp.intValue());
0685:                }
0686:            }
0687:
0688:            /**
0689:             * An inner class that can be initiated to perform text formatting
0690:             */
0691:            public class CalendarFormattedText {
0692:                // constructor
0693:                public CalendarFormattedText() {
0694:
0695:                }
0696:
0697:                /**
0698:                 * Use of FormattedText object's trimFormattedText function.
0699:                 * @param formattedText The formatted text to trim
0700:                 * @param maxNumOfChars The maximum number of displayed characters in the returned trimmed formatted text.
0701:                 * @return String A String to hold the trimmed formatted text
0702:                 */
0703:                public String trimFormattedText(String formattedText,
0704:                        int maxNumOfChars) {
0705:                    StringBuffer sb = new StringBuffer();
0706:                    FormattedText.trimFormattedText(formattedText,
0707:                            maxNumOfChars, sb);
0708:                    return sb.toString();
0709:                }
0710:            }
0711:
0712:            /**
0713:             * Given a current date via the calendarUtil paramter, returns a TimeRange for the week.
0714:             */
0715:            public TimeRange getWeekTimeRange(CalendarUtil calendarUtil) {
0716:                int dayofweek = 0;
0717:
0718:                dayofweek = calendarUtil.getDay_Of_Week() - 1;
0719:                int tempCurrentYear = calendarUtil.getYear();
0720:                int tempCurrentMonth = calendarUtil.getMonthInteger();
0721:                int tempCurrentDay = calendarUtil.getDayOfMonth();
0722:
0723:                for (int i = dayofweek; i > 0; i--) {
0724:                    calendarUtil.prevDate();
0725:                }
0726:
0727:                Time startTime = TimeService.newTimeLocal(calendarUtil
0728:                        .getYear(), calendarUtil.getMonthInteger(),
0729:                        calendarUtil.getDayOfMonth(), 00, 00, 00, 000);
0730:
0731:                calendarUtil.setDay(tempCurrentYear, tempCurrentMonth,
0732:                        tempCurrentDay);
0733:                dayofweek = calendarUtil.getDay_Of_Week();
0734:
0735:                if (dayofweek < 7) {
0736:                    for (int i = dayofweek; i <= 6; i++) {
0737:                        calendarUtil.nextDate();
0738:                    }
0739:                }
0740:
0741:                Time endTime = TimeService.newTimeLocal(calendarUtil.getYear(),
0742:                        calendarUtil.getMonthInteger(), calendarUtil
0743:                                .getDayOfMonth(), 23, 00, 00, 000);
0744:
0745:                return TimeService.newTimeRange(startTime, endTime, true, true);
0746:
0747:            } // etWeekTimeRange
0748:
0749:            /**
0750:             * Given a current date via the calendarUtil paramter, returns a TimeRange for the month.
0751:             */
0752:            public TimeRange getMonthTimeRange(CalendarUtil calendarUtil) {
0753:
0754:                int dayofweek = 0;
0755:
0756:                calendarUtil.setDay(calendarUtil.getYear(), calendarUtil
0757:                        .getMonthInteger(), 1);
0758:                int numberOfCurrentDays = calendarUtil.getNumberOfDays();
0759:                int tempCurrentMonth = calendarUtil.getMonthInteger();
0760:                int tempCurrentYear = calendarUtil.getYear();
0761:
0762:                // get the index of the first day in the month
0763:                int firstDay_of_Month = calendarUtil.getDay_Of_Week() - 1;
0764:
0765:                // Construct the time range to get all the days in the current month plus the days in the first week in the previous month and
0766:                // the days in the last week from the last month
0767:
0768:                // get the days in the first week that exists in the prev month
0769:                for (int i = firstDay_of_Month; i > 0; i--) {
0770:                    calendarUtil.getPrevDate();
0771:                }
0772:
0773:                Time startTime = TimeService.newTimeLocal(calendarUtil
0774:                        .getYear(), calendarUtil.getMonthInteger(),
0775:                        calendarUtil.getDayOfMonth(), 00, 00, 00, 000);
0776:
0777:                // set the date object to the current month and last day in the current month
0778:                calendarUtil.setDay(tempCurrentYear, tempCurrentMonth,
0779:                        numberOfCurrentDays);
0780:
0781:                // get the index of the last day in the current month
0782:                dayofweek = calendarUtil.getDay_Of_Week();
0783:
0784:                // move the date object to the last day in the last week of the current month , this day will be one of those days in the
0785:                // following month
0786:                if (dayofweek < 7) {
0787:                    for (int i = dayofweek; i <= 6; i++) {
0788:                        calendarUtil.nextDate();
0789:                    }
0790:                }
0791:
0792:                Time endTime = TimeService.newTimeLocal(calendarUtil.getYear(),
0793:                        calendarUtil.getMonthInteger(), calendarUtil
0794:                                .getDayOfMonth(), 23, 00, 00, 000);
0795:                return TimeService.newTimeRange(startTime, endTime, true, true);
0796:            }
0797:
0798:            /**
0799:             * Given a current date in the year, month, and day parameters, returns a TimeRange for the day.
0800:             */
0801:            public TimeRange getDayTimeRange(int year, int month, int day) {
0802:                Time startTime = TimeService.newTimeLocal(year, month, day, 00,
0803:                        00, 00, 000);
0804:                Time endTime = TimeService.newTimeLocal(year, month, day, 23,
0805:                        59, 59, 000);
0806:
0807:                return TimeService.newTimeRange(startTime, endTime, true, true);
0808:            }
0809:
0810:            /**
0811:             * Provides a list of merged calendars by iterating through all
0812:             * available calendars.
0813:             */
0814:            class EntryProvider extends MergedListEntryProviderBase {
0815:                /* (non-Javadoc)
0816:                 * @see org.sakaiproject.util.MergedListEntryProviderBase#makeReference(java.lang.String)
0817:                 */
0818:                public Object makeObjectFromSiteId(String id) {
0819:                    String calendarReference = CalendarService
0820:                            .calendarReference(id, SiteService.MAIN_CONTAINER);
0821:                    Object calendar = null;
0822:
0823:                    if (calendarReference != null) {
0824:                        try {
0825:                            calendar = CalendarService
0826:                                    .getCalendar(calendarReference);
0827:                        } catch (IdUnusedException e) {
0828:                            // The channel isn't there.
0829:                        } catch (PermissionException e) {
0830:                            // We can't see the channel
0831:                        }
0832:                    }
0833:
0834:                    return calendar;
0835:                }
0836:
0837:                /* (non-Javadoc)
0838:                 * @see org.chefproject.actions.MergedEntryList.EntryProvider#allowGet(java.lang.Object)
0839:                 */
0840:                public boolean allowGet(String ref) {
0841:                    return CalendarService.allowGetCalendar(ref);
0842:                }
0843:
0844:                /* (non-Javadoc)
0845:                 * @see org.chefproject.actions.MergedEntryList.EntryProvider#getContext(java.lang.Object)
0846:                 */
0847:                public String getContext(Object obj) {
0848:                    if (obj == null) {
0849:                        return "";
0850:                    }
0851:
0852:                    Calendar calendar = (Calendar) obj;
0853:                    return calendar.getContext();
0854:                }
0855:
0856:                /* (non-Javadoc)
0857:                 * @see org.chefproject.actions.MergedEntryList.EntryProvider#getReference(java.lang.Object)
0858:                 */
0859:                public String getReference(Object obj) {
0860:                    if (obj == null) {
0861:                        return "";
0862:                    }
0863:
0864:                    Calendar calendar = (Calendar) obj;
0865:                    return calendar.getReference();
0866:                }
0867:
0868:                /* (non-Javadoc)
0869:                 * @see org.chefproject.actions.MergedEntryList.EntryProvider#getProperties(java.lang.Object)
0870:                 */
0871:                public ResourceProperties getProperties(Object obj) {
0872:                    if (obj == null) {
0873:                        return null;
0874:                    }
0875:
0876:                    Calendar calendar = (Calendar) obj;
0877:                    return calendar.getProperties();
0878:                }
0879:            }
0880:
0881:            /**
0882:             * This class controls the page that allows the user to customize which
0883:             * calendars will be merged with the current group.
0884:             */
0885:            public class MergePage {
0886:                private final String mergeScheduleButtonHandler = "doMerge";
0887:
0888:                // Name used in the velocity template for the list of merged/non-merged calendars
0889:                private final String mergedCalendarsCollection = "mergedCalendarsCollection";
0890:
0891:                public MergePage() {
0892:                    super ();
0893:                }
0894:
0895:                /**
0896:                 * Build the context for showing merged view
0897:                 */
0898:                public void buildContext(VelocityPortlet portlet,
0899:                        Context context, RunData runData,
0900:                        CalendarActionState state, SessionState sstate) {
0901:                    MergedList calendarList = new MergedList();
0902:
0903:                    EntryProvider entryProvider = new EntryProvider();
0904:
0905:                    calendarList
0906:                            .loadChannelsFromDelimitedString(
0907:                                    isOnWorkspaceTab(),
0908:                                    entryProvider,
0909:                                    StringUtil.trimToZero(SessionManager
0910:                                            .getCurrentSessionUserId()),
0911:
0912:                                    calendarList
0913:                                            .getChannelReferenceArrayFromDelimitedString(
0914:                                                    state
0915:                                                            .getPrimaryCalendarReference(),
0916:                                                    portlet
0917:                                                            .getPortletConfig()
0918:                                                            .getInitParameter(
0919:                                                                    PORTLET_CONFIG_PARM_MERGED_CALENDARS)),
0920:                                    SecurityService.isSuperUser(), ToolManager
0921:                                            .getCurrentPlacement().getContext());
0922:
0923:                    // Place this object in the context so that the velocity template
0924:                    // can get at it.
0925:                    context.put(mergedCalendarsCollection, calendarList);
0926:                    context.put("tlang", rb);
0927:                    sstate.setAttribute(
0928:                            CalendarAction.SSTATE_ATTRIBUTE_MERGED_CALENDARS,
0929:                            calendarList);
0930:                }
0931:
0932:                /**
0933:                 * Action is used when the docancel is requested when the user click on cancel  in the new view
0934:                 */
0935:                public void doCancel(RunData data, Context context,
0936:                        CalendarActionState state, SessionState sstate) {
0937:                    // Go back to whatever state we were in beforehand.
0938:                    state.setReturnState(state.getPrevState());
0939:
0940:                    // cancel the options, release the site lock, cleanup
0941:                    cancelOptions();
0942:
0943:                    // Clear the previous state so that we don't get confused elsewhere.
0944:                    state.setPrevState("");
0945:
0946:                    sstate.removeAttribute(STATE_MODE);
0947:
0948:                    enableObserver(sstate, true);
0949:                } // doCancel
0950:
0951:                /**
0952:                 * Handle the "Merge" button on the toolbar
0953:                 */
0954:                public void doMerge(RunData runData, Context context,
0955:                        CalendarActionState state, SessionState sstate) {
0956:                    // TODO: really?
0957:                    // get a lock on the site and setup for options work
0958:                    //			VelocityPortletPaneledAlert alert = new VelocityPortletPaneledAlert();
0959:                    //			alert.doOptions(runData, context);
0960:                    doOptions(runData, context);
0961:
0962:                    // if we didn't end up in options mode, bail out
0963:                    if (!MODE_OPTIONS.equals(sstate.getAttribute(STATE_MODE)))
0964:                        return;
0965:
0966:                    // Disable the observer
0967:                    enableObserver(sstate, false);
0968:
0969:                    // Save the previous state so that we can get to it after we're done with the options mode.
0970:                    //state.setPrevState(state.getState());
0971:                    // Save the previous state so that we can get to it after we're done with the options mode.
0972:                    // if the previous state is Description, we need to remember one more step back
0973:                    // coz there is a back link in description view
0974:                    if ((state.getState()).equalsIgnoreCase("description")) {
0975:                        state.setPrevState(state.getReturnState()
0976:                                + "!!!fromDescription");
0977:                    } else {
0978:                        state.setPrevState(state.getState());
0979:                    }
0980:
0981:                    state.setState(CalendarAction.STATE_MERGE_CALENDARS);
0982:                } // doMerge
0983:
0984:                /**
0985:                 * Handles the user clicking on the save button on the page to specify which
0986:                 * calendars will be merged into the present schedule.
0987:                 */
0988:                public void doUpdate(RunData runData, Context context,
0989:                        CalendarActionState state, SessionState sstate) {
0990:                    // Get the merged calendar list out of our session state
0991:                    MergedList mergedCalendarList = (MergedList) sstate
0992:                            .getAttribute(CalendarAction.SSTATE_ATTRIBUTE_MERGED_CALENDARS);
0993:
0994:                    if (mergedCalendarList != null) {
0995:                        // Get the information from the run data and load it into
0996:                        // our calendar list that we have in the session state.
0997:                        mergedCalendarList.loadFromRunData(runData
0998:                                .getParameters());
0999:                    }
1000:
1001:                    // update the tool config
1002:                    Placement placement = ToolManager.getCurrentPlacement();
1003:                    if (mergedCalendarList != null) {
1004:                        placement.getPlacementConfig().setProperty(
1005:                                PORTLET_CONFIG_PARM_MERGED_CALENDARS,
1006:                                mergedCalendarList
1007:                                        .getDelimitedChannelReferenceString());
1008:                    } else {
1009:                        placement.getPlacementConfig().remove(
1010:                                PORTLET_CONFIG_PARM_MERGED_CALENDARS);
1011:                    }
1012:
1013:                    // commit the change
1014:                    saveOptions();
1015:
1016:                    updateObservationOfChannel(mergedCalendarList, runData,
1017:                            sstate, state);
1018:
1019:                    // Turn the observer back on.
1020:                    enableObserver(sstate, true);
1021:
1022:                    // Go back to whatever state we were in beforehand.
1023:                    state.setReturnState(state.getPrevState());
1024:
1025:                    // Clear the previous state so that we don't get confused elsewhere.
1026:                    state.setPrevState("");
1027:
1028:                    sstate.removeAttribute(STATE_MODE);
1029:
1030:                } // doUpdate
1031:
1032:                /* (non-Javadoc)
1033:                 * @see org.chefproject.actions.schedulePages.SchedulePage#getMenuHandlerID()
1034:                 */
1035:                public String getButtonHandlerID() {
1036:                    return mergeScheduleButtonHandler;
1037:                }
1038:
1039:                /* (non-Javadoc)
1040:                 * @see org.chefproject.actions.schedulePages.SchedulePage#getMenuText()
1041:                 */
1042:                public String getButtonText() {
1043:                    return rb.getString("java.merge");
1044:                }
1045:
1046:            }
1047:
1048:            /**
1049:             * This class controls the page that allows the user to add arbitrary
1050:             * attributes to the attribute list for the primary calendar that
1051:             * corresponds to the current group.
1052:             */
1053:            public class CustomizeCalendarPage {
1054:
1055:                //This is the session attribute name to store init and current addFields list
1056:
1057:                // Name used in the velocity template for the list of calendar addFields
1058:                private final static String ADDFIELDS_CALENDARS_COLLECTION = "addFieldsCalendarsCollection";
1059:                private final static String ADDFIELDS_CALENDARS_COLLECTION_ISEMPTY = "addFieldsCalendarsCollectionIsEmpty";
1060:                private final static String OPTIONS_BUTTON_HANDLER = "doCustomize";
1061:
1062:                public CustomizeCalendarPage() {
1063:                    super ();
1064:                }
1065:
1066:                /**
1067:                 * Build the context for addfields calendar (Options menu)
1068:                 */
1069:                public void buildContext(VelocityPortlet portlet,
1070:                        Context context, RunData runData,
1071:                        CalendarActionState state, SessionState sstate) {
1072:                    String[] addFieldsCalendarArray = null;
1073:
1074:                    // Get a list of current calendar addFields.  This is a comma-delimited list.
1075:                    if (sstate.getAttribute(
1076:                            CalendarAction.SSTATE_ATTRIBUTE_ADDFIELDS_PAGE)
1077:                            .toString().equals(CalendarAction.PAGE_MAIN)) //when the 'Options' button click
1078:                    {
1079:                        //when the 'Options' button click
1080:
1081:                        Calendar calendarObj = null;
1082:
1083:                        StringBuffer exceptionMessage = new StringBuffer();
1084:
1085:                        String calId = state.getPrimaryCalendarReference();
1086:                        try {
1087:                            calendarObj = CalendarService.getCalendar(calId);
1088:                        } catch (IdUnusedException e) {
1089:                            exceptionMessage.append(rb
1090:                                    .getString("java.alert.thereis"));
1091:                            M_log.debug(".buildCustomizeContext(): " + e);
1092:                        } catch (PermissionException e) {
1093:                            exceptionMessage.append(rb
1094:                                    .getString("java.alert.youdont"));
1095:                            M_log.debug(".buildCustomizeContext(): " + e);
1096:                        }
1097:
1098:                        // Get a current list of add fields.  This is a comma-delimited string.
1099:                        String addfieldsCalendars = calendarObj
1100:                                .getEventFields();
1101:
1102:                        if (addfieldsCalendars != null) {
1103:                            addFieldsCalendarArray = fieldStringToArray(
1104:                                    addfieldsCalendars, ADDFIELDS_DELIMITER);
1105:                        }
1106:
1107:                        sstate
1108:                                .setAttribute(
1109:                                        CalendarAction.SSTATE_ATTRIBUTE_ADDFIELDS_CALENDARS_INIT,
1110:                                        addfieldsCalendars);
1111:                        sstate
1112:                                .setAttribute(
1113:                                        CalendarAction.SSTATE_ATTRIBUTE_ADDFIELDS_CALENDARS,
1114:                                        addfieldsCalendars);
1115:
1116:                        context
1117:                                .put(
1118:                                        "delFields",
1119:                                        (List) sstate
1120:                                                .getAttribute(CalendarAction.SSTATE_ATTRIBUTE_DELFIELDS));
1121:                        sstate
1122:                                .removeAttribute(CalendarAction.SSTATE_ATTRIBUTE_DELFIELDS);
1123:
1124:                        sstate
1125:                                .setAttribute(
1126:                                        CalendarAction.SSTATE_ATTRIBUTE_DELFIELDS_CONFIRM,
1127:                                        "N");
1128:                        state.setDelfieldAlertOff(true);
1129:                    } else //after the 'Options' button click
1130:                    {
1131:                        String addFieldsCollection = (String) sstate
1132:                                .getAttribute(CalendarAction.SSTATE_ATTRIBUTE_ADDFIELDS_CALENDARS);
1133:
1134:                        if (addFieldsCollection != null)
1135:                            addFieldsCalendarArray = fieldStringToArray(
1136:                                    addFieldsCollection, ADDFIELDS_DELIMITER);
1137:                    }
1138:
1139:                    // Place this object in the context so that the velocity template
1140:                    // can get at it.
1141:                    context.put(ADDFIELDS_CALENDARS_COLLECTION,
1142:                            addFieldsCalendarArray);
1143:                    context.put("tlang", rb);
1144:                    if (addFieldsCalendarArray == null)
1145:                        context.put(ADDFIELDS_CALENDARS_COLLECTION_ISEMPTY,
1146:                                Boolean.valueOf(true));
1147:                    else
1148:                        context.put(ADDFIELDS_CALENDARS_COLLECTION_ISEMPTY,
1149:                                Boolean.valueOf(false));
1150:
1151:                } //buildCustomizeCalendarContext
1152:
1153:                /**
1154:                 * Handles the click on the page to add a field to events that will
1155:                 * be added to the calendar. Changes aren't complete until the user
1156:                 * commits changes with a save.
1157:                 */
1158:                public void doAddfield(RunData runData, Context context,
1159:                        CalendarActionState state, SessionState sstate) {
1160:                    String addFields = (String) sstate
1161:                            .getAttribute(CalendarAction.SSTATE_ATTRIBUTE_ADDFIELDS_CALENDARS);
1162:                    String[] addFieldsCalendarList = null;
1163:
1164:                    if (addFields != null)
1165:                        addFieldsCalendarList = fieldStringToArray(addFields,
1166:                                ADDFIELDS_DELIMITER);
1167:
1168:                    // Go back to whatever state we were in beforehand.
1169:                    state.setReturnState(state.getPrevState());
1170:
1171:                    enableObserver(sstate, true);
1172:
1173:                    String addField = "";
1174:                    addField = runData.getParameters().getString("textfield")
1175:                            .trim();
1176:                    String dupAddfield = "N";
1177:
1178:                    //prevent entry of some characters (can cause problem)
1179:                    addField = addField.replaceAll("  ", " ");
1180:                    addField = addField.replaceAll("'", "");
1181:                    addField = addField.replaceAll("\"", "");
1182:
1183:                    if (addField.length() == 0) {
1184:                        addAlert(sstate, rb.getString("java.alert.youneed"));
1185:                    } else {
1186:                        if (addFieldsCalendarList != null) {
1187:                            for (int i = 0; i < addFieldsCalendarList.length; i++) {
1188:                                if (addField.toUpperCase().equals(
1189:                                        addFieldsCalendarList[i].toUpperCase())) {
1190:                                    addAlert(sstate, rb
1191:                                            .getString("java.alert.theadd"));
1192:                                    dupAddfield = "Y";
1193:                                    i = addFieldsCalendarList.length + 1;
1194:                                }
1195:                            }
1196:                            if (dupAddfield.equals("N"))
1197:                                addFieldsCalendarList = fieldStringToArray(
1198:                                        addFields + ADDFIELDS_DELIMITER
1199:                                                + addField, ADDFIELDS_DELIMITER);
1200:                        } else {
1201:                            String[] initString = new String[1];
1202:                            initString[0] = addField;
1203:                            addFieldsCalendarList = initString;
1204:
1205:                        }
1206:
1207:                        if (dupAddfield.equals("N")) {
1208:                            if (addFields != null)
1209:                                addFields = addFields + ADDFIELDS_DELIMITER
1210:                                        + addField;
1211:                            else
1212:                                addFields = addField;
1213:
1214:                            sstate
1215:                                    .setAttribute(
1216:                                            CalendarAction.SSTATE_ATTRIBUTE_ADDFIELDS_CALENDARS,
1217:                                            addFields);
1218:                        }
1219:                    }
1220:
1221:                    sstate.setAttribute(
1222:                            CalendarAction.SSTATE_ATTRIBUTE_ADDFIELDS_PAGE,
1223:                            CalendarAction.PAGE_ADDFIELDS);
1224:
1225:                }
1226:
1227:                /**
1228:                 * Handles a click on the cancel button in the page that allows the
1229:                 * user to add/remove events to/from events that will be added to
1230:                 * the calendar.
1231:                 */
1232:                public void doCancel(RunData data, Context context,
1233:                        CalendarActionState state, SessionState sstate) {
1234:                    // Go back to whatever state we were in beforehand.
1235:                    state.setReturnState(state.getPrevState());
1236:
1237:                    sstate
1238:                            .setAttribute(
1239:                                    CalendarAction.SSTATE_ATTRIBUTE_ADDFIELDS_CALENDARS,
1240:                                    sstate
1241:                                            .getAttribute(CalendarAction.SSTATE_ATTRIBUTE_ADDFIELDS_CALENDARS_INIT));
1242:                    sstate.setAttribute(
1243:                            CalendarAction.SSTATE_ATTRIBUTE_ADDFIELDS_PAGE,
1244:                            CalendarAction.PAGE_MAIN);
1245:                    enableObserver(sstate, true);
1246:                } // doCancel
1247:
1248:                /**
1249:                 * This initiates the page where the user can add/remove additional
1250:                 * properties to/from events that will be added to the calendar.
1251:                 */
1252:                public void doCustomize(RunData runData, Context context,
1253:                        CalendarActionState state, SessionState sstate) {
1254:                    // Disable the observer
1255:                    enableObserver(sstate, false);
1256:
1257:                    // Save the previous state so that we can get to it after we're done with the options mode.
1258:                    // if the previous state is Description, we need to remember one more step back
1259:                    // coz there is a back link in description view
1260:                    if ((state.getState()).equalsIgnoreCase("description")) {
1261:                        state.setPrevState(state.getReturnState()
1262:                                + "!!!fromDescription");
1263:                    } else {
1264:                        state.setPrevState(state.getState());
1265:                    }
1266:
1267:                    state.setState(CalendarAction.STATE_CUSTOMIZE_CALENDAR);
1268:                }
1269:
1270:                /**
1271:                 * Handles the click on the page to remove a field from events in the
1272:                 * calendar. Changes aren't complete until the user commits changes
1273:                 * with a save.
1274:                 */
1275:                public void doDeletefield(RunData runData, Context context,
1276:                        CalendarActionState state, SessionState sstate) {
1277:
1278:                    ParameterParser params = runData.getParameters();
1279:                    String addFields = (String) sstate
1280:                            .getAttribute(CalendarAction.SSTATE_ATTRIBUTE_ADDFIELDS_CALENDARS);
1281:                    String[] addFieldsCalendarList = null, newAddFieldsCalendarList = null;
1282:                    List delFields = new Vector();
1283:
1284:                    int nextNewFieldsIndex = 0;
1285:                    if (addFields != null) {
1286:                        addFieldsCalendarList = fieldStringToArray(addFields,
1287:                                ADDFIELDS_DELIMITER);
1288:
1289:                        // The longest the new array can possibly be is the current size of the list.
1290:                        newAddFieldsCalendarList = new String[addFieldsCalendarList.length];
1291:
1292:                        for (int i = 0; i < addFieldsCalendarList.length; i++) {
1293:                            String fieldName = params
1294:                                    .getString(addFieldsCalendarList[i]);
1295:
1296:                            // If a value is present, then that means that the user has checked
1297:                            // the box for the field to be removed.  Don't add it to the
1298:                            // new list of field names.  If it is not present, then add it
1299:                            // to the new list of field names.
1300:                            if (fieldName == null || fieldName.length() == 0) {
1301:                                newAddFieldsCalendarList[nextNewFieldsIndex++] = addFieldsCalendarList[i];
1302:                            } else {
1303:                                sstate
1304:                                        .setAttribute(
1305:                                                CalendarAction.SSTATE_ATTRIBUTE_DELFIELDS_CONFIRM,
1306:                                                "Y");
1307:                                delFields.add(addFieldsCalendarList[i]);
1308:                            }
1309:                        }
1310:                        addFields = arrayToString(newAddFieldsCalendarList,
1311:                                ADDFIELDS_DELIMITER);
1312:                    }
1313:
1314:                    // Go back to whatever state we were in beforehand.
1315:                    state.setReturnState(state.getPrevState());
1316:
1317:                    enableObserver(sstate, true);
1318:
1319:                    sstate
1320:                            .setAttribute(
1321:                                    CalendarAction.SSTATE_ATTRIBUTE_ADDFIELDS_CALENDARS,
1322:                                    addFields);
1323:                    sstate.setAttribute(
1324:                            CalendarAction.SSTATE_ATTRIBUTE_DELFIELDS,
1325:                            delFields);
1326:
1327:                    sstate.setAttribute(
1328:                            CalendarAction.SSTATE_ATTRIBUTE_ADDFIELDS_PAGE,
1329:                            CalendarAction.PAGE_ADDFIELDS);
1330:
1331:                }
1332:
1333:                /**
1334:                 * Handles the user clicking on the save button on the page to add or
1335:                 * remove additional attributes for all calendar events.
1336:                 */
1337:                public void doUpdate(RunData runData, Context context,
1338:                        CalendarActionState state, SessionState sstate) {
1339:
1340:                    if (sstate.getAttribute(
1341:                            CalendarAction.SSTATE_ATTRIBUTE_DELFIELDS_CONFIRM)
1342:                            .equals("Y")
1343:                            && state.getDelfieldAlertOff()) {
1344:                        String errorCode = rb.getString("java.alert.areyou");
1345:                        List delFields = (List) sstate
1346:                                .getAttribute(SSTATE_ATTRIBUTE_DELFIELDS);
1347:
1348:                        errorCode = errorCode
1349:                                .concat((String) (delFields.get(0)));
1350:                        for (int i = 1; i < delFields.size(); i++) {
1351:                            errorCode = errorCode.concat(", "
1352:                                    + (String) (delFields.get(i)));
1353:                        }
1354:                        errorCode = errorCode.concat(rb
1355:                                .getString("java.alert.ifyes"));
1356:                        addAlert(sstate, errorCode);
1357:                        state.setDelfieldAlertOff(false);
1358:                    } else {
1359:                        state.setDelfieldAlertOff(true);
1360:                        String addfields = (String) sstate
1361:                                .getAttribute(CalendarAction.SSTATE_ATTRIBUTE_ADDFIELDS_CALENDARS);
1362:                        while (addfields.startsWith(ADDFIELDS_DELIMITER)) {
1363:                            addfields = addfields.substring(ADDFIELDS_DELIMITER
1364:                                    .length());
1365:                        }
1366:
1367:                        StringBuffer exceptionMessage = new StringBuffer();
1368:
1369:                        String calId = state.getPrimaryCalendarReference();
1370:                        try {
1371:                            CalendarEdit edit = CalendarService
1372:                                    .editCalendar(calId);
1373:                            edit.setEventFields(addfields);
1374:                            CalendarService.commitCalendar(edit);
1375:                        } catch (IdUnusedException e) {
1376:                            exceptionMessage.append(rb
1377:                                    .getString("java.alert.thereisno"));
1378:                            M_log
1379:                                    .debug(".doUpdate customize calendar IdUnusedException"
1380:                                            + e);
1381:                        } catch (PermissionException e) {
1382:                            exceptionMessage.append(rb
1383:                                    .getString("java.alert.youdonthave"));
1384:                            M_log.debug(".doUpdate customize calendar " + e);
1385:                        } catch (InUseException e) {
1386:                            exceptionMessage.append(rb
1387:                                    .getString("java.alert.someone"));
1388:                            M_log.debug(".doUpdate() for CustomizeCalendar: "
1389:                                    + e);
1390:                        }
1391:
1392:                        sstate
1393:                                .setAttribute(
1394:                                        CalendarAction.SSTATE_ATTRIBUTE_ADDFIELDS_CALENDARS,
1395:                                        addfields);
1396:
1397:                        sstate.setAttribute(
1398:                                CalendarAction.SSTATE_ATTRIBUTE_ADDFIELDS_PAGE,
1399:                                CalendarAction.PAGE_MAIN);
1400:                    }
1401:
1402:                    // Go back to whatever state we were in beforehand.
1403:                    state.setReturnState(state.getPrevState());
1404:                    enableObserver(sstate, true);
1405:
1406:                } // doUpdate
1407:
1408:                /* (non-Javadoc)
1409:                 * @see org.chefproject.actions.schedulePages.SchedulePage#getMenuHandlerID()
1410:                 */
1411:                public String getButtonHandlerID() {
1412:                    return OPTIONS_BUTTON_HANDLER;
1413:                }
1414:
1415:                /* (non-Javadoc)
1416:                 * @see org.chefproject.actions.schedulePages.SchedulePage#getMenuText()
1417:                 */
1418:                public String getButtonText() {
1419:                    return rb.getString("java.fields");
1420:                }
1421:
1422:                /**
1423:                 * Loads additional fields information from the calendar object passed
1424:                 * as a parameter and loads them into the context object for the Velocity
1425:                 * template.
1426:                 */
1427:                public void loadAdditionalFieldsIntoContextFromCalendar(
1428:                        Calendar calendarObj, Context context) {
1429:                    // Get a current list of add fields.  This is a ADDFIELDS_DELIMITER string.
1430:                    String addfieldsCalendars = calendarObj.getEventFields();
1431:
1432:                    String[] addfieldsCalendarArray = null;
1433:
1434:                    if (addfieldsCalendars != null) {
1435:                        addfieldsCalendarArray = fieldStringToArray(
1436:                                addfieldsCalendars, ADDFIELDS_DELIMITER);
1437:                    }
1438:
1439:                    // Place this object in the context so that the velocity template
1440:                    // can get at it.
1441:                    context.put(ADDFIELDS_CALENDARS_COLLECTION,
1442:                            addfieldsCalendarArray);
1443:                    context.put("tlang", rb);
1444:                    if (addfieldsCalendarArray == null)
1445:                        context.put(ADDFIELDS_CALENDARS_COLLECTION_ISEMPTY,
1446:                                Boolean.valueOf(true));
1447:                    else
1448:                        context.put(ADDFIELDS_CALENDARS_COLLECTION_ISEMPTY,
1449:                                Boolean.valueOf(false));
1450:                }
1451:
1452:                /**
1453:                 * Loads additional fields from the run data into a provided map object.
1454:                 */
1455:                public void loadAdditionalFieldsMapFromRunData(RunData rundata,
1456:                        Map addfieldsMap, Calendar calendarObj) {
1457:                    String addfields_str = calendarObj.getEventFields();
1458:                    if (addfields_str != null
1459:                            && addfields_str.trim().length() != 0) {
1460:                        String[] addfields = fieldStringToArray(addfields_str,
1461:                                ADDFIELDS_DELIMITER);
1462:                        String eachfield;
1463:
1464:                        for (int i = 0; i < addfields.length; i++) {
1465:                            eachfield = addfields[i];
1466:                            addfieldsMap.put(eachfield, rundata.getParameters()
1467:                                    .getString(eachfield));
1468:                        }
1469:                    }
1470:                }
1471:            }
1472:
1473:            /**
1474:             * Utility class to figure out permissions for a calendar object.
1475:             */
1476:            static public class CalendarPermissions {
1477:                /**
1478:                 * Priate constructor, doesn't allow instances of this object.
1479:                 */
1480:                private CalendarPermissions() {
1481:                    super ();
1482:                }
1483:
1484:                /**
1485:                 * Returns true if the primary and selected calendar are the same, but not null.
1486:                 */
1487:                static boolean verifyPrimarySelectedMatch(
1488:                        String primaryCalendarReference,
1489:                        String selectedCalendarReference) {
1490:                    //
1491:                    // Both primary and secondary calendar ids must be specified.
1492:                    // These must also match to be able to delete an event
1493:                    //
1494:                    if (primaryCalendarReference == null
1495:                            || selectedCalendarReference == null
1496:                            || !primaryCalendarReference
1497:                                    .equals(selectedCalendarReference)) {
1498:                        return false;
1499:                    } else {
1500:                        return true;
1501:                    }
1502:                }
1503:
1504:                /**
1505:                 * Utility routint to get the calendar for a given calendar id.
1506:                 */
1507:                static private Calendar getTheCalendar(String calendarReference) {
1508:                    Calendar calendarObj = null;
1509:
1510:                    try {
1511:                        calendarObj = CalendarService
1512:                                .getCalendar(calendarReference);
1513:
1514:                        if (calendarObj == null) {
1515:                            // If the calendar isn't there, try adding it.
1516:                            CalendarService.commitCalendar(CalendarService
1517:                                    .addCalendar(calendarReference));
1518:                            calendarObj = CalendarService
1519:                                    .getCalendar(calendarReference);
1520:                        }
1521:                    }
1522:
1523:                    catch (IdUnusedException e) {
1524:                        M_log
1525:                                .debug(
1526:                                        "CalendarPermissions.getTheCalendar(): ",
1527:                                        e);
1528:                    }
1529:
1530:                    catch (PermissionException e) {
1531:                        M_log.debug("CalendarPermissions.getTheCalendar(): "
1532:                                + e);
1533:                    }
1534:
1535:                    catch (IdUsedException e) {
1536:                        M_log.debug("CalendarPermissions.getTheCalendar(): "
1537:                                + e);
1538:                    }
1539:
1540:                    catch (IdInvalidException e) {
1541:                        M_log.debug("CalendarPermissions.getTheCalendar(): "
1542:                                + e);
1543:                    }
1544:
1545:                    return calendarObj;
1546:                }
1547:
1548:                /**
1549:                 * Returns true if the current user can see the events in a calendar.
1550:                 */
1551:                static public boolean allowViewEvents(String calendarReference) {
1552:                    Calendar calendarObj = getTheCalendar(calendarReference);
1553:
1554:                    if (calendarObj == null) {
1555:                        return false;
1556:                    } else {
1557:                        return calendarObj.allowGetEvents();
1558:                    }
1559:                }
1560:
1561:                /**
1562:                 * Returns true if the current user is allowed to delete events on the calendar id
1563:                 * passed in as the selectedCalendarReference parameter.  The selected calendar must match
1564:                 * the primary calendar for this function to return true.
1565:                 * @param primaryCalendarReference calendar id for the default channel
1566:                 * @param selectedCalendarReference calendar id for the event the user has just selected
1567:                 */
1568:                public static boolean allowDeleteEvent(
1569:                        String primaryCalendarReference,
1570:                        String selectedCalendarReference, String eventId) {
1571:                    //
1572:                    // Both primary and secondary calendar ids must be specified.
1573:                    // These must also match to be able to delete an event
1574:                    //
1575:                    if (!verifyPrimarySelectedMatch(primaryCalendarReference,
1576:                            selectedCalendarReference)) {
1577:                        return false;
1578:                    }
1579:
1580:                    Calendar calendarObj = getTheCalendar(primaryCalendarReference);
1581:
1582:                    if (calendarObj == null) {
1583:                        return false;
1584:                    } else {
1585:                        CalendarEvent event = null;
1586:                        try {
1587:                            event = calendarObj.getEvent(eventId);
1588:                        } catch (IdUnusedException e) {
1589:                            M_log
1590:                                    .debug("CalendarPermissions.canDeleteEvent(): "
1591:                                            + e);
1592:                        } catch (PermissionException e) {
1593:                            M_log
1594:                                    .debug("CalendarPermissions.canDeleteEvent(): "
1595:                                            + e);
1596:                        }
1597:
1598:                        if (event == null) {
1599:                            return false;
1600:                        } else {
1601:                            return calendarObj.allowRemoveEvent(event);
1602:                        }
1603:                    }
1604:                }
1605:
1606:                /**
1607:                 * Returns true if the current user is allowed to revise events on the calendar id
1608:                 * passed in as the selectedCalendarReference parameter.  The selected calendar must match
1609:                 * the primary calendar for this function to return true.
1610:                 * @param primaryCalendarReference calendar id for the default channel
1611:                 * @param selectedCalendarReference calendar reference for the event the user has just selected
1612:                 */
1613:                static public boolean allowReviseEvents(
1614:                        String primaryCalendarReference,
1615:                        String selectedCalendarReference, String eventId) {
1616:                    //
1617:                    // Both primary and secondary calendar ids must be specified.
1618:                    // These must also match to be able to delete an event
1619:                    //
1620:                    if (!verifyPrimarySelectedMatch(primaryCalendarReference,
1621:                            selectedCalendarReference)) {
1622:                        return false;
1623:                    }
1624:
1625:                    Calendar calendarObj = getTheCalendar(primaryCalendarReference);
1626:
1627:                    if (calendarObj == null) {
1628:                        return false;
1629:                    } else {
1630:                        return calendarObj.allowEditEvent(eventId);
1631:                    }
1632:                }
1633:
1634:                /**
1635:                 * Returns true if the current user is allowed to create events on the calendar id
1636:                 * passed in as the selectedCalendarReference parameter.  The selected calendar must match
1637:                 * the primary calendar for this function to return true.
1638:                 * @param primaryCalendarReference calendar reference for the default channel
1639:                 * @param selectedCalendarReference calendar reference for the event the user has just selected
1640:                 */
1641:                static public boolean allowCreateEvents(
1642:                        String primaryCalendarReference,
1643:                        String selectedCalendarReference) {
1644:                    // %%% Note: disabling this check as the allow create events should ONLY be on the primary,
1645:                    // we don't care about the selected -ggolden
1646:                    /*
1647:                     //
1648:                     // The primary and selected calendar ids must match, unless the selected calendar
1649:                     // is null or empty.
1650:                     //
1651:                    
1652:                     if ( selectedCalendarReference != null &&
1653:                     selectedCalendarReference.length() > 0 &&
1654:                     !verifyPrimarySelectedMatch(primaryCalendarReference, selectedCalendarReference) )
1655:                     {
1656:                     return false;
1657:                     }
1658:                     */
1659:
1660:                    Calendar calendarObj = getTheCalendar(primaryCalendarReference);
1661:
1662:                    if (calendarObj == null) {
1663:                        return false;
1664:                    } else {
1665:                        return calendarObj.allowAddEvent();
1666:                    }
1667:                }
1668:
1669:                /**
1670:                 * Returns true if the user is allowed to merge events from different calendars
1671:                 * within the default channel.
1672:                 */
1673:                static public boolean allowMergeCalendars(
1674:                        String calendarReference, boolean isOnWorkspaceTab) {
1675:                    // Don't allow merging on the user's own tab.  This currently only works for groups.
1676:                    // Note: if this is really what you want, then check if the "id" (really a reference) is to a user or group site
1677:                    //       (for now, check that the id is "group-" -ggolden
1678:                    //
1679:                    // I wasn't quite sure how to check if the calendar reference that was formerly
1680:                    // passed was a user or a group site.  This seems to do the job, but I'm leaving
1681:                    // Glenn's comment intact in case this needs to be revistied.
1682:                    return !isOnWorkspaceTab
1683:                            && CalendarService
1684:                                    .allowMergeCalendar(calendarReference);
1685:                }
1686:
1687:                /**
1688:                 * Returns true if the use is allowed to modify properties of the calendar itself,
1689:                 * and not just the events within the calendar.
1690:                 */
1691:                static public boolean allowModifyCalendarProperties(
1692:                        String calendarReference) {
1693:                    return CalendarService.allowEditCalendar(calendarReference);
1694:                }
1695:
1696:                /**
1697:                 * Returns true if the use is allowed to import events into the calendar.
1698:                 */
1699:                static public boolean allowImport(String calendarReference) {
1700:                    return CalendarService
1701:                            .allowImportCalendar(calendarReference);
1702:                }
1703:            }
1704:
1705:            private final static String SSTATE_ATTRIBUTE_ADDFIELDS_PAGE = "addfieldsPage";
1706:            private final static String SSTATE_ATTRIBUTE_ADDFIELDS_CALENDARS_INIT = "addfieldsInit";
1707:            private final static String SSTATE_ATTRIBUTE_ADDFIELDS_CALENDARS = "addfields";
1708:            private final static String SSTATE_ATTRIBUTE_DELFIELDS = "delFields";
1709:
1710:            private final static String SSTATE_ATTRIBUTE_DELFIELDS_CONFIRM = "delfieldsConfirm";
1711:
1712:            private final static String STATE_NEW = "new";
1713:
1714:            private static final String EVENT_REFERENCE_PARAMETER = "eventReference";
1715:
1716:            private static final String EVENT_CONTEXT_VAR = "event";
1717:            private static final String NO_EVENT_FLAG_CONTEXT_VAR = "noEvent";
1718:
1719:            //
1720:            // These are variables used in the context for communication between this
1721:            // action class and the Velocity template.
1722:            //
1723:
1724:            // False/true string values are used in the context variables in a number of places.
1725:            private static final String FALSE_STRING = "false";
1726:            private static final String TRUE_STRING = "true";
1727:
1728:            // This is the property name in the portlet config for the list of calendars
1729:            // that are not merged.
1730:            private final static String PORTLET_CONFIG_PARM_MERGED_CALENDARS = "mergedCalendarReferences";
1731:
1732:            private final static String PAGE_MAIN = "main";
1733:            private final static String PAGE_ADDFIELDS = "addFields";
1734:
1735:            /** The flag name and value in state to indicate an update to the portlet is needed. */
1736:            private final static String SSTATE_ATTRIBUTE_MERGED_CALENDARS = "mergedCalendars";
1737:
1738:            // String constants for user interface states
1739:            private final static String STATE_MERGE_CALENDARS = "mergeCalendars";
1740:            private final static String STATE_CUSTOMIZE_CALENDAR = "customizeCalendar";
1741:
1742:            // for detailed event view navigator
1743:            private final static String STATE_PREV_ACT = "toPrevActivity";
1744:            private final static String STATE_NEXT_ACT = "toNextActivity";
1745:            private final static Object STATE_CURRENT_ACT = "toCurrentActivity";
1746:            private final static String STATE_EVENTS_LIST = "eventIds";
1747:            private final static String STATE_NAV_DIRECTION = "navigationDirection";
1748:
1749:            private MergePage mergedCalendarPage = new MergePage();
1750:
1751:            private CustomizeCalendarPage customizeCalendarPage = new CustomizeCalendarPage();
1752:
1753:            /**
1754:             * See if the current tab is the workspace tab.
1755:             * @return true if we are currently on the "My Workspace" tab.
1756:             */
1757:            private static boolean isOnWorkspaceTab() {
1758:                // TODO: return to this question! -ggolden
1759:                // return false;
1760:                // we'll really answer the question - is the current request's site a user site?
1761:                return SiteService.isUserSite(ToolManager.getCurrentPlacement()
1762:                        .getContext());
1763:            }
1764:
1765:            protected Class getStateClass() {
1766:                return CalendarActionState.class;
1767:
1768:            } // getStateClass
1769:
1770:            /**
1771:             * Gets an array of all the calendars whose events we can access.
1772:             */
1773:            private List getCalendarReferenceList(VelocityPortlet portlet,
1774:                    String primaryCalendarReference, boolean isOnWorkspaceTab) {
1775:                MergedList mergedCalendarList = new MergedList();
1776:
1777:                // TODO - MERGE FIX
1778:                String[] channelArray = null;
1779:
1780:                // Figure out the list of channel references that we'll be using.
1781:                // If we're on the workspace tab, we get everything.
1782:                // Don't do this if we're the super-user, since we'd be
1783:                // overwhelmed.
1784:                if (isOnWorkspaceTab() && !SecurityService.isSuperUser()) {
1785:                    channelArray = mergedCalendarList
1786:                            .getAllPermittedChannels(new CalendarChannelReferenceMaker());
1787:                } else {
1788:                    channelArray = mergedCalendarList
1789:                            .getChannelReferenceArrayFromDelimitedString(
1790:                                    primaryCalendarReference,
1791:                                    portlet
1792:                                            .getPortletConfig()
1793:                                            .getInitParameter(
1794:                                                    PORTLET_CONFIG_PARM_MERGED_CALENDARS));
1795:                }
1796:
1797:                mergedCalendarList.loadChannelsFromDelimitedString(
1798:                        isOnWorkspaceTab,
1799:                        new MergedListEntryProviderFixedListWrapper(
1800:                                new EntryProvider(), primaryCalendarReference,
1801:                                channelArray,
1802:                                new CalendarReferenceToChannelConverter()),
1803:                        StringUtil.trimToZero(SessionManager
1804:                                .getCurrentSessionUserId()), channelArray,
1805:                        SecurityService.isSuperUser(), ToolManager
1806:                                .getCurrentPlacement().getContext());
1807:
1808:                return mergedCalendarList.getReferenceList();
1809:            }
1810:
1811:            /**
1812:             * Gets the session state from the Jetspeed RunData
1813:             */
1814:            static private SessionState getSessionState(RunData runData) {
1815:                // access the portlet element id to find our state
1816:                String peid = ((JetspeedRunData) runData).getJs_peid();
1817:                return ((JetspeedRunData) runData).getPortletSessionState(peid);
1818:            }
1819:
1820:            public String buildMainPanelContext(VelocityPortlet portlet,
1821:                    Context context, RunData runData, SessionState sstate) {
1822:                CalendarActionState state = (CalendarActionState) getState(
1823:                        portlet, runData, CalendarActionState.class);
1824:
1825:                String template = (String) getContext(runData).get("template");
1826:
1827:                String stateName = state.getState();
1828:                if (stateName == null)
1829:                    stateName = "";
1830:                if (stateName.equals(STATE_SCHEDULE_IMPORT)) {
1831:                    buildImportContext(portlet, context, runData, state,
1832:                            getSessionState(runData));
1833:                } else if (stateName.equals(STATE_MERGE_CALENDARS)) {
1834:                    // build the context to display the options panel
1835:                    mergedCalendarPage.buildContext(portlet, context, runData,
1836:                            state, getSessionState(runData));
1837:                } else if (stateName.equals(STATE_CUSTOMIZE_CALENDAR)) {
1838:                    // build the context to display the options panel
1839:                    //needed to track when user clicks 'Save' or 'Cancel'
1840:                    String sstatepage = "";
1841:
1842:                    Object statepageAttribute = sstate
1843:                            .getAttribute(SSTATE_ATTRIBUTE_ADDFIELDS_PAGE);
1844:
1845:                    if (statepageAttribute != null) {
1846:                        sstatepage = statepageAttribute.toString();
1847:                    }
1848:
1849:                    if (!sstatepage.equals(PAGE_ADDFIELDS)) {
1850:                        sstate.setAttribute(SSTATE_ATTRIBUTE_ADDFIELDS_PAGE,
1851:                                PAGE_MAIN);
1852:                    }
1853:
1854:                    customizeCalendarPage.buildContext(portlet, context,
1855:                            runData, state, getSessionState(runData));
1856:                } else if ((stateName.equals("revise"))
1857:                        || (stateName.equals("goToReviseCalendar"))) {
1858:                    // build the context for the normal view show
1859:                    buildReviseContext(portlet, context, runData, state);
1860:                } else if (stateName.equals("description")) {
1861:                    // build the context for the basic step of adding file
1862:                    buildDescriptionContext(portlet, context, runData, state);
1863:                } else if (stateName.equals("year")) {
1864:                    // build the context for the advanced step of adding file
1865:                    buildYearContext(portlet, context, runData, state);
1866:                } else if (stateName.equals("month")) {
1867:                    // build the context for the basic step of adding folder
1868:                    buildMonthContext(portlet, context, runData, state);
1869:                } else if (stateName.equals("day")) {
1870:                    // build the context for the basic step of adding simple text
1871:                    buildDayContext(portlet, context, runData, state);
1872:                } else if (stateName.equals("week")) {
1873:                    // build the context for the basic step of delete confirm page
1874:                    buildWeekContext(portlet, context, runData, state);
1875:                } else if (stateName.equals("new")) {
1876:                    // build the context to display the property list
1877:                    buildNewContext(portlet, context, runData, state);
1878:                } else if (stateName.equals("delete")) {
1879:                    // build the context to display the property list
1880:                    buildDeleteContext(portlet, context, runData, state);
1881:                } else if (stateName.equals("list")) {
1882:                    // build the context to display the list view
1883:                    buildListContext(portlet, context, runData, state);
1884:                } else if (stateName.equals(STATE_SET_FREQUENCY)) {
1885:                    buildFrequencyContext(portlet, context, runData, state);
1886:                }
1887:
1888:                TimeZone timeZone = TimeService.getLocalTimeZone();
1889:                context.put("timezone", timeZone.getDisplayName(true,
1890:                        TimeZone.SHORT));
1891:
1892:                // group realted variables
1893:                context.put("siteAccess", CalendarEvent.EventAccess.SITE);
1894:                context.put("groupAccess", CalendarEvent.EventAccess.GROUPED);
1895:
1896:                context.put("message", state.getState());
1897:                context.put("state", state.getKey());
1898:                context.put("tlang", rb);
1899:                return template;
1900:
1901:            } // buildMainPanelContext
1902:
1903:            private void buildImportContext(VelocityPortlet portlet,
1904:                    Context context, RunData runData,
1905:                    CalendarActionState state, SessionState state2) {
1906:                // Place this object in the context so that the velocity template
1907:                // can get at it.
1908:
1909:                // Start at the beginning if nothing is set yet.
1910:                if (state.getImportWizardState() == null) {
1911:                    state.setImportWizardState(IMPORT_WIZARD_SELECT_TYPE_STATE);
1912:                }
1913:
1914:                // Set whatever the current wizard state is.
1915:                context.put("importWizardState", state.getImportWizardState());
1916:                context.put("tlang", rb);
1917:                // Set the imported events into the context.
1918:                context.put("wizardImportedEvents", state
1919:                        .getWizardImportedEvents());
1920:
1921:                String calId = state.getPrimaryCalendarReference();
1922:                StringBuffer exceptionMessage = new StringBuffer();
1923:                try {
1924:                    Calendar calendarObj = CalendarService.getCalendar(calId);
1925:                    String scheduleTo = (String) state2
1926:                            .getAttribute(STATE_SCHEDULE_TO);
1927:                    if (scheduleTo != null && scheduleTo.length() != 0) {
1928:                        context.put("scheduleTo", scheduleTo);
1929:                    } else {
1930:                        if (calendarObj.allowAddEvent()) {
1931:                            // default to make site selection
1932:                            context.put("scheduleTo", "site");
1933:                        } else if (calendarObj.getGroupsAllowAddEvent().size() > 0) {
1934:                            // to group otherwise
1935:                            context.put("scheduleTo", "groups");
1936:                        }
1937:                    }
1938:
1939:                    Collection groups = calendarObj.getGroupsAllowAddEvent();
1940:                    if (groups.size() > 0) {
1941:                        /*
1942:                        String sort = (String) sstate.getAttribute(STATE_CURRENT_SORTED_BY);
1943:                        boolean asc = sstate.getAttribute(STATE_CURRENT_SORT_ASC)!=null?((Boolean) sstate.getAttribute(STATE_CURRENT_SORT_ASC)).booleanValue():true;;
1944:                        if (sort == null || (!sort.equals(SORT_GROUPTITLE) && !sort.equals(SORT_GROUPDESCRIPTION)))
1945:                        {
1946:                        	sort = SORT_GROUPTITLE;
1947:                        	sstate.setAttribute(STATE_CURRENT_SORTED_BY, sort);
1948:                        	state.setCurrentSortedBy(sort);
1949:                        	state.setCurrentSortAsc(Boolean.TRUE.booleanValue());
1950:                        }
1951:                        context.put("groups", new SortedIterator(groups.iterator(), new AnnouncementComparator(sort, asc)));
1952:                         */
1953:                        //TODO:render the group list better
1954:                        context.put("groups", groups);
1955:                    }
1956:                } catch (IdUnusedException e) {
1957:                    exceptionMessage.append(rb.getString("java.alert.thereis"));
1958:                    M_log.debug(".buildImportContext(): " + e);
1959:                } catch (PermissionException e) {
1960:                    exceptionMessage.append(rb.getString("java.alert.youdont"));
1961:                    M_log.debug(".buildImportContext(): " + e);
1962:                }
1963:            }
1964:
1965:            /**
1966:             * Addes the primary calendar reference (this site's default calendar)
1967:             * to the calendar action state object.
1968:             */
1969:            private void setPrimaryCalendarReferenceInState(
1970:                    VelocityPortlet portlet, CalendarActionState state) {
1971:                String calendarReference = state.getPrimaryCalendarReference();
1972:
1973:                if (calendarReference == null) {
1974:
1975:                    calendarReference = StringUtil.trimToNull(portlet
1976:                            .getPortletConfig().getInitParameter(
1977:                                    CALENDAR_INIT_PARAMETER));
1978:                    if (calendarReference == null) {
1979:                        // form a reference to the default calendar for this request's site
1980:                        calendarReference = CalendarService.calendarReference(
1981:                                ToolManager.getCurrentPlacement().getContext(),
1982:                                SiteService.MAIN_CONTAINER);
1983:                        state.setPrimaryCalendarReference(calendarReference);
1984:                    }
1985:                }
1986:            }
1987:
1988:            /**
1989:             * Build the context for editing the frequency
1990:             */
1991:            protected void buildFrequencyContext(VelocityPortlet portlet,
1992:                    Context context, RunData runData, CalendarActionState state) {
1993:                String peid = ((JetspeedRunData) runData).getJs_peid();
1994:                SessionState sstate = ((JetspeedRunData) runData)
1995:                        .getPortletSessionState(peid);
1996:
1997:                // under 3 conditions, we get into this page
1998:                // 1st, brand new event, no freq or rule set up, coming from revise page
1999:                // 2nd, exisitng event, coming from revise page
2000:                // 3rd, new event, stay in this page after changing frequency by calling js function onchange()
2001:                // 4th, existing event, stay in this page after changing frequency by calling js function onchange()
2002:
2003:                // sstate attribute TEMP_FREQ_SELECT is one of the flags
2004:                // if this attribute is not null, means changeFrequency() is called thru onchange().
2005:                // Then rule is another flag, if rule is null, means new event
2006:                // Combination of these 2 flags should cover all the conditions
2007:
2008:                RecurrenceRule rule = (RecurrenceRule) sstate
2009:                        .getAttribute(CalendarAction.SSTATE__RECURRING_RULE);
2010:
2011:                // defaultly set frequency to be once
2012:                // if there is a saved state frequency attribute, replace the default one
2013:                String freq = CalendarAction.DEFAULT_FREQ;
2014:
2015:                if (sstate.getAttribute(TEMP_FREQ_SELECT) != null) {
2016:                    freq = (String) sstate.getAttribute(TEMP_FREQ_SELECT);
2017:                    if (rule != null)
2018:                        context.put("rule", rule);
2019:                    sstate.removeAttribute(TEMP_FREQ_SELECT);
2020:                } else {
2021:                    if (rule != null) {
2022:                        freq = rule.getFrequencyDescription();
2023:                        context.put("rule", rule);
2024:                    }
2025:                }
2026:                context.put("freq", freq);
2027:                context.put("tlang", rb);
2028:                // get the data the user just input in the preview new/revise page
2029:                context.put("savedData", state.getNewData());
2030:
2031:                context.put("realDate", TimeService.newTime());
2032:
2033:            } // buildFrequencyContext
2034:
2035:            /**
2036:             * Build the context for showing revise view
2037:             */
2038:            protected void buildReviseContext(VelocityPortlet portlet,
2039:                    Context context, RunData runData, CalendarActionState state) {
2040:                // to get the content Type Image Service
2041:                context.put("contentTypeImageService", ContentTypeImageService
2042:                        .getInstance());
2043:                context.put("tlang", rb);
2044:                Calendar calendarObj = null;
2045:                CalendarEvent calEvent = null;
2046:                CalendarUtil calObj = new CalendarUtil(); //null;
2047:                MyDate dateObj1 = null;
2048:                dateObj1 = new MyDate();
2049:                boolean getEventsFlag = false;
2050:
2051:                StringBuffer exceptionMessage = new StringBuffer();
2052:
2053:                List attachments = state.getAttachments();
2054:
2055:                String peid = ((JetspeedRunData) runData).getJs_peid();
2056:                SessionState sstate = ((JetspeedRunData) runData)
2057:                        .getPortletSessionState(peid);
2058:
2059:                Time m_time = TimeService.newTime();
2060:                TimeBreakdown b = m_time.breakdownLocal();
2061:                int stateYear = b.getYear();
2062:                int stateMonth = b.getMonth();
2063:                int stateDay = b.getDay();
2064:                if ((sstate.getAttribute(STATE_YEAR) != null)
2065:                        && (sstate.getAttribute(STATE_MONTH) != null)
2066:                        && (sstate.getAttribute(STATE_DAY) != null)) {
2067:                    stateYear = ((Integer) sstate.getAttribute(STATE_YEAR))
2068:                            .intValue();
2069:                    stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH))
2070:                            .intValue();
2071:                    stateDay = ((Integer) sstate.getAttribute(STATE_DAY))
2072:                            .intValue();
2073:                }
2074:                calObj.setDay(stateYear, stateMonth, stateDay);
2075:
2076:                dateObj1.setTodayDate(calObj.getMonthInteger(), calObj
2077:                        .getDayOfMonth(), calObj.getYear());
2078:                String calId = state.getPrimaryCalendarReference();
2079:                if (state.getIsNewCalendar() == false) {
2080:                    if (CalendarService.allowGetCalendar(calId) == false) {
2081:                        exceptionMessage.append(rb
2082:                                .getString("java.alert.younotallow"));
2083:                    } else {
2084:                        try {
2085:                            calendarObj = CalendarService.getCalendar(calId);
2086:
2087:                            if (calendarObj.allowGetEvent(state
2088:                                    .getCalendarEventId())) {
2089:                                calEvent = calendarObj.getEvent(state
2090:                                        .getCalendarEventId());
2091:                                getEventsFlag = true;
2092:                                context.put("selectedGroupRefsCollection",
2093:                                        calEvent.getGroups());
2094:
2095:                                // all the groups the user is allowed to do remove from
2096:                                context.put("allowedRemoveGroups", calendarObj
2097:                                        .getGroupsAllowRemoveEvent(calEvent
2098:                                                .isUserOwner()));
2099:                            } else
2100:                                getEventsFlag = false;
2101:
2102:                            // Add any additional fields in the calendar.
2103:                            customizeCalendarPage
2104:                                    .loadAdditionalFieldsIntoContextFromCalendar(
2105:                                            calendarObj, context);
2106:                            context.put("tlang", rb);
2107:                            context.put("calEventFlag", "true");
2108:                            context.put("new", "false");
2109:                            // if from the metadata view of announcement, the message is already the system resource
2110:                            if (state.getState().equals("goToReviseCalendar")) {
2111:                                context.put("backToRevise", "false");
2112:                            }
2113:                            // if from the attachments editing view or preview view of announcement
2114:                            else if (state.getState().equals("revise")) {
2115:                                context.put("backToRevise", "true");
2116:                            }
2117:
2118:                            //Vector attachments = state.getAttachments();
2119:                            if (attachments != null) {
2120:                                context.put("attachments", attachments);
2121:                            } else {
2122:                                context.put("attachNull", "true");
2123:                            }
2124:
2125:                            //context.put("moreAttachments", moreAttachments.iterator());
2126:                            context.put("fromAttachmentFlag", state
2127:                                    .getfromAttachmentFlag());
2128:                        } catch (IdUnusedException e) {
2129:                            exceptionMessage.append(rb
2130:                                    .getString("java.alert.therenoactv"));
2131:                            M_log.debug(".buildReviseContext(): " + e);
2132:                        } catch (PermissionException e) {
2133:                            exceptionMessage.append(rb
2134:                                    .getString("java.alert.younotperm"));
2135:                            M_log.debug(".buildReviseContext(): " + e);
2136:                        }
2137:                    }
2138:                } else {
2139:                    // if this a new annoucement, get the subject and body from temparory record
2140:                    context.put("new", "true");
2141:                    context.put("tlang", rb);
2142:                    context.put("attachments", attachments);
2143:                    context.put("fromAttachmentFlag", state
2144:                            .getfromAttachmentFlag());
2145:                }
2146:
2147:                // Output for recurring events
2148:
2149:                // for an existing event
2150:                // if the saved recurring rule equals to string FREQ_ONCE, set it as not recurring
2151:                // if there is a saved recurring rule in sstate, display it
2152:                // otherwise, output the event's rule instead
2153:                if ((((String) sstate.getAttribute(FREQUENCY_SELECT)) != null)
2154:                        && (((String) sstate.getAttribute(FREQUENCY_SELECT))
2155:                                .equals(FREQ_ONCE))) {
2156:                    context.put("rule", null);
2157:                } else {
2158:                    RecurrenceRule rule = (RecurrenceRule) sstate
2159:                            .getAttribute(CalendarAction.SSTATE__RECURRING_RULE);
2160:                    if (rule == null) {
2161:                        rule = calEvent.getRecurrenceRule();
2162:                    } else
2163:                        context.put("rule", rule);
2164:
2165:                    if (rule != null) {
2166:                        context.put("freq", rule.getFrequencyDescription());
2167:                    } // if (rule != null)
2168:                } //if ((String) sstate.getAttribute(FREQUENCY_SELECT).equals(FREQ_ONCE))
2169:
2170:                try {
2171:                    calendarObj = CalendarService.getCalendar(calId);
2172:
2173:                    String scheduleTo = (String) sstate
2174:                            .getAttribute(STATE_SCHEDULE_TO);
2175:                    if (scheduleTo != null && scheduleTo.length() != 0) {
2176:                        context.put("scheduleTo", scheduleTo);
2177:                    } else {
2178:                        if (calendarObj.allowAddCalendarEvent()) {
2179:                            // default to make site selection
2180:                            context.put("scheduleTo", "site");
2181:                        } else if (calendarObj.getGroupsAllowAddEvent().size() > 0) {
2182:                            // to group otherwise
2183:                            context.put("scheduleTo", "groups");
2184:                        }
2185:                    }
2186:
2187:                    Collection groups = calendarObj.getGroupsAllowAddEvent();
2188:
2189:                    // add to these any groups that the message already has
2190:                    calEvent = calendarObj.getEvent(state.getCalendarEventId());
2191:                    if (calEvent != null) {
2192:                        Collection otherGroups = calEvent.getGroupObjects();
2193:                        for (Iterator i = otherGroups.iterator(); i.hasNext();) {
2194:                            Group g = (Group) i.next();
2195:
2196:                            if (!groups.contains(g)) {
2197:                                groups.add(g);
2198:                            }
2199:                        }
2200:                    }
2201:
2202:                    if (groups.size() > 0) {
2203:                        context.put("groups", groups);
2204:                    }
2205:                } catch (IdUnusedException e) {
2206:                    exceptionMessage.append(rb.getString("java.alert.thereis"));
2207:                    M_log.debug(".buildNewContext(): " + e);
2208:                } catch (PermissionException e) {
2209:                    exceptionMessage.append(rb.getString("java.alert.youdont"));
2210:                    M_log.debug(".buildNewContext(): " + e);
2211:                }
2212:                context.put("tlang", rb);
2213:                context.put("event", calEvent);
2214:                context.put("helper", new Helper());
2215:                context.put("message", "revise");
2216:                context.put("savedData", state.getNewData());
2217:                context.put("getEventsFlag", Boolean.valueOf(getEventsFlag));
2218:
2219:                if (state.getIsNewCalendar() == true)
2220:                    context.put("vmtype", "new");
2221:                else
2222:                    context.put("vmtype", "revise");
2223:
2224:                context.put("service", ContentHostingService.getInstance());
2225:
2226:                // output the real time
2227:                context.put("realDate", TimeService.newTime());
2228:
2229:            } // buildReviseContext
2230:
2231:            /**
2232:             * Build the context for showing description for events
2233:             */
2234:            protected void buildDescriptionContext(VelocityPortlet portlet,
2235:                    Context context, RunData runData, CalendarActionState state) {
2236:
2237:                // to get the content Type Image Service
2238:                context.put("contentTypeImageService", ContentTypeImageService
2239:                        .getInstance());
2240:                context.put("tlang", rb);
2241:                context.put("Context", ToolManager.getCurrentPlacement()
2242:                        .getContext());
2243:                context.put("CalendarService", CalendarService.getInstance());
2244:                context.put("SiteService", SiteService.getInstance());
2245:
2246:                Calendar calendarObj = null;
2247:                CalendarEvent calEvent = null;
2248:
2249:                MyDate dateObj1 = null;
2250:                dateObj1 = new MyDate();
2251:
2252:                StringBuffer exceptionMessage = new StringBuffer();
2253:
2254:                String peid = ((JetspeedRunData) runData).getJs_peid();
2255:                SessionState sstate = ((JetspeedRunData) runData)
2256:                        .getPortletSessionState(peid);
2257:
2258:                navigatorContextControl(portlet, context, runData,
2259:                        (String) sstate.getAttribute(STATE_NAV_DIRECTION));
2260:                boolean prevAct = sstate.getAttribute(STATE_PREV_ACT) != null;
2261:                boolean nextAct = sstate.getAttribute(STATE_NEXT_ACT) != null;
2262:                context.put("prevAct", new Boolean(prevAct));
2263:                context.put("nextAct", new Boolean(nextAct));
2264:
2265:                Time m_time = TimeService.newTime();
2266:                TimeBreakdown b = m_time.breakdownLocal();
2267:                int stateYear = b.getYear();
2268:                int stateMonth = b.getMonth();
2269:                int stateDay = b.getDay();
2270:                if ((sstate.getAttribute(STATE_YEAR) != null)
2271:                        && (sstate.getAttribute(STATE_MONTH) != null)
2272:                        && (sstate.getAttribute(STATE_DAY) != null)) {
2273:                    stateYear = ((Integer) sstate.getAttribute(STATE_YEAR))
2274:                            .intValue();
2275:                    stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH))
2276:                            .intValue();
2277:                    stateDay = ((Integer) sstate.getAttribute(STATE_DAY))
2278:                            .intValue();
2279:                }
2280:                CalendarUtil calObj = new CalendarUtil();
2281:                calObj.setDay(stateYear, stateMonth, stateDay);
2282:
2283:                // get the today date in month/day/year format
2284:                dateObj1.setTodayDate(calObj.getMonthInteger(), calObj
2285:                        .getDayOfMonth(), calObj.getYear());
2286:
2287:                // get the event id from the CalendarService.
2288:                // send the event to the vm
2289:                String ce = state.getCalendarEventId();
2290:
2291:                String selectedCalendarReference = state
2292:                        .getSelectedCalendarReference();
2293:
2294:                if (!CalendarPermissions
2295:                        .allowViewEvents(selectedCalendarReference)) {
2296:                    exceptionMessage.append(rb
2297:                            .getString("java.alert.younotallow"));
2298:                    M_log.debug("here in buildDescription not showing event");
2299:                } else {
2300:                    try {
2301:                        calendarObj = CalendarService
2302:                                .getCalendar(selectedCalendarReference);
2303:                        calEvent = calendarObj.getEvent(ce);
2304:
2305:                        // Add any additional fields in the calendar.
2306:                        customizeCalendarPage
2307:                                .loadAdditionalFieldsIntoContextFromCalendar(
2308:                                        calendarObj, context);
2309:
2310:                        context.put(EVENT_CONTEXT_VAR, calEvent);
2311:                        context.put("tlang", rb);
2312:
2313:                        String ownerId = calEvent.getCreator();
2314:                        if (ownerId != null && !ownerId.equals("")) {
2315:                            String ownerName = UserDirectoryService.getUser(
2316:                                    ownerId).getDisplayName();
2317:                            context.put("owner_name", ownerName);
2318:                        }
2319:
2320:                        RecurrenceRule rule = calEvent.getRecurrenceRule();
2321:                        // for a brand new event, there is no saved recurring rule
2322:                        if (rule != null) {
2323:                            context.put("freq", rule.getFrequencyDescription());
2324:
2325:                            context.put("rule", rule);
2326:                        }
2327:
2328:                        // show all the groups in this calendar that user has get event in
2329:                        Collection groups = calendarObj
2330:                                .getGroupsAllowGetEvent();
2331:                        if (groups != null) {
2332:                            context.put("groupRange", calEvent
2333:                                    .getGroupRangeForDisplay(calendarObj));
2334:                        }
2335:                    } catch (IdUnusedException e) {
2336:                        M_log.debug(".buildDescriptionContext(): " + e);
2337:                        context.put(NO_EVENT_FLAG_CONTEXT_VAR, TRUE_STRING);
2338:                    } catch (PermissionException e) {
2339:                        exceptionMessage.append(rb
2340:                                .getString("java.alert.younotpermadd"));
2341:                        M_log.debug(".buildDescriptionContext(): " + e);
2342:                    } catch (UserNotDefinedException e) {
2343:                        exceptionMessage.append(rb
2344:                                .getString("java.alert.younotpermadd"));
2345:                        M_log.debug(".buildDescriptionContext(): " + e);
2346:                    }
2347:                }
2348:
2349:                buildMenu(portlet, context, runData, state, CalendarPermissions
2350:                        .allowCreateEvents(state.getPrimaryCalendarReference(),
2351:                                state.getSelectedCalendarReference()),
2352:                        CalendarPermissions.allowDeleteEvent(state
2353:                                .getPrimaryCalendarReference(), state
2354:                                .getSelectedCalendarReference(), state
2355:                                .getCalendarEventId()), CalendarPermissions
2356:                                .allowReviseEvents(state
2357:                                        .getPrimaryCalendarReference(), state
2358:                                        .getSelectedCalendarReference(), state
2359:                                        .getCalendarEventId()),
2360:                        CalendarPermissions.allowMergeCalendars(state
2361:                                .getPrimaryCalendarReference(),
2362:                                isOnWorkspaceTab()), CalendarPermissions
2363:                                .allowModifyCalendarProperties(state
2364:                                        .getPrimaryCalendarReference()),
2365:                        CalendarPermissions.allowImport(state
2366:                                .getPrimaryCalendarReference()));
2367:
2368:                context.put("allowDelete", new Boolean(CalendarPermissions
2369:                        .allowDeleteEvent(state.getPrimaryCalendarReference(),
2370:                                state.getSelectedCalendarReference(), state
2371:                                        .getCalendarEventId())));
2372:                context.put("allowRevise", new Boolean(CalendarPermissions
2373:                        .allowReviseEvents(state.getPrimaryCalendarReference(),
2374:                                state.getSelectedCalendarReference(), state
2375:                                        .getCalendarEventId())));
2376:
2377:            } // buildDescriptionContext
2378:
2379:            /**
2380:             * Build the context for showing Year view
2381:             */
2382:            protected void buildYearContext(VelocityPortlet portlet,
2383:                    Context context, RunData runData, CalendarActionState state) {
2384:                CalendarUtil calObj = new CalendarUtil();
2385:                MyYear yearObj = null;
2386:                MyMonth monthObj1, monthObj2 = null;
2387:                MyDay dayObj = null;
2388:                MyDate dateObj1 = null;
2389:                boolean allowed = false;
2390:                CalendarEventVector CalendarEventVectorObj = null;
2391:
2392:                // new objects of myYear, myMonth, myDay, myWeek classes
2393:                yearObj = new MyYear();
2394:                monthObj1 = new MyMonth();
2395:                dayObj = new MyDay();
2396:                dateObj1 = new MyDate();
2397:                StringBuffer exceptionMessage = new StringBuffer();
2398:
2399:                int month = 1;
2400:                int col = 3;
2401:                int row = 4;
2402:
2403:                String peid = ((JetspeedRunData) runData).getJs_peid();
2404:                SessionState sstate = ((JetspeedRunData) runData)
2405:                        .getPortletSessionState(peid);
2406:
2407:                Time m_time = TimeService.newTime();
2408:                TimeBreakdown b = m_time.breakdownLocal();
2409:                int stateYear = b.getYear();
2410:                int stateMonth = b.getMonth();
2411:                int stateDay = b.getDay();
2412:                if ((sstate.getAttribute(STATE_YEAR) != null)
2413:                        && (sstate.getAttribute(STATE_MONTH) != null)
2414:                        && (sstate.getAttribute(STATE_DAY) != null)) {
2415:                    stateYear = ((Integer) sstate.getAttribute(STATE_YEAR))
2416:                            .intValue();
2417:                    stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH))
2418:                            .intValue();
2419:                    stateDay = ((Integer) sstate.getAttribute(STATE_DAY))
2420:                            .intValue();
2421:                }
2422:                calObj.setDay(stateYear, stateMonth, stateDay);
2423:
2424:                dateObj1.setTodayDate(calObj.getMonthInteger(), calObj
2425:                        .getDayOfMonth(), calObj.getYear());
2426:                yearObj.setYear(calObj.getYear());
2427:                monthObj1.setMonth(calObj.getMonthInteger());
2428:                dayObj.setDay(calObj.getDayOfMonth());
2429:
2430:                if (CalendarService.allowGetCalendar(state
2431:                        .getPrimaryCalendarReference()) == false) {
2432:                    allowed = false;
2433:                    exceptionMessage.append(rb
2434:                            .getString("java.alert.younotallowsee"));
2435:                    CalendarEventVectorObj = new CalendarEventVector();
2436:                } else {
2437:                    try {
2438:                        allowed = CalendarService.getCalendar(
2439:                                state.getPrimaryCalendarReference())
2440:                                .allowAddEvent();
2441:                    } catch (IdUnusedException e) {
2442:                        exceptionMessage.append(rb
2443:                                .getString("java.alert.therenoactv"));
2444:                        M_log.debug(".buildYearContext(): " + e);
2445:                    } catch (PermissionException e) {
2446:                        exceptionMessage.append(rb
2447:                                .getString("java.alert.younotperm"));
2448:                        M_log.debug(".buildYearContext(): " + e);
2449:                    }
2450:                }
2451:
2452:                for (int r = 0; r < row; r++) {
2453:                    for (int c = 0; c < col; c++) {
2454:                        monthObj2 = new MyMonth();
2455:                        calObj.setDay(dateObj1.getYear(), month, 1);
2456:
2457:                        CalendarEventVectorObj = CalendarService.getEvents(
2458:                                getCalendarReferenceList(portlet, state
2459:                                        .getPrimaryCalendarReference(),
2460:                                        isOnWorkspaceTab()),
2461:                                getMonthTimeRange(calObj));
2462:
2463:                        calObj.setDay(dateObj1.getYear(), dateObj1.getMonth(),
2464:                                dateObj1.getDay());
2465:                        monthObj2 = calMonth(month, calObj, state,
2466:                                CalendarEventVectorObj);
2467:
2468:                        month++;
2469:                        yearObj.setMonth(monthObj2, r, c);
2470:                    }
2471:                }
2472:                calObj.setDay(dateObj1.getYear(), dateObj1.getMonth(), dateObj1
2473:                        .getDay());
2474:                context.put("tlang", rb);
2475:                context.put("yearArray", yearObj);
2476:                context.put("year", new Integer(calObj.getYear()));
2477:                context.put("date", dateObj1);
2478:                state.setState("year");
2479:
2480:                buildMenu(portlet, context, runData, state, CalendarPermissions
2481:                        .allowCreateEvents(state.getPrimaryCalendarReference(),
2482:                                state.getSelectedCalendarReference()),
2483:                        CalendarPermissions.allowDeleteEvent(state
2484:                                .getPrimaryCalendarReference(), state
2485:                                .getSelectedCalendarReference(), state
2486:                                .getCalendarEventId()), CalendarPermissions
2487:                                .allowReviseEvents(state
2488:                                        .getPrimaryCalendarReference(), state
2489:                                        .getSelectedCalendarReference(), state
2490:                                        .getCalendarEventId()),
2491:                        CalendarPermissions.allowMergeCalendars(state
2492:                                .getPrimaryCalendarReference(),
2493:                                isOnWorkspaceTab()), CalendarPermissions
2494:                                .allowModifyCalendarProperties(state
2495:                                        .getPrimaryCalendarReference()),
2496:                        CalendarPermissions.allowImport(state
2497:                                .getPrimaryCalendarReference()));
2498:
2499:                // added by zqian for toolbar
2500:                context.put("allow_new", Boolean.valueOf(allowed));
2501:                context.put("allow_delete", Boolean.valueOf(false));
2502:                context.put("allow_revise", Boolean.valueOf(false));
2503:                context.put("tlang", rb);
2504:                context.put(Menu.CONTEXT_ACTION, "CalendarAction");
2505:
2506:                context.put("selectedView", rb.getString("java.byyear"));
2507:
2508:            } // buildYearContext
2509:
2510:            /**
2511:             * Build the context for showing month view
2512:             */
2513:
2514:            protected void buildMonthContext(VelocityPortlet portlet,
2515:                    Context context, RunData runData, CalendarActionState state) {
2516:                MyMonth monthObj2 = null;
2517:
2518:                MyDate dateObj1 = null;
2519:                StringBuffer exceptionMessage = new StringBuffer();
2520:                CalendarEventVector CalendarEventVectorObj = null;
2521:
2522:                dateObj1 = new MyDate();
2523:
2524:                // read calendar object saved in state object
2525:                //calObj = state.getCalObj();
2526:                String peid = ((JetspeedRunData) runData).getJs_peid();
2527:                SessionState sstate = ((JetspeedRunData) runData)
2528:                        .getPortletSessionState(peid);
2529:
2530:                Time m_time = TimeService.newTime();
2531:                TimeBreakdown b = m_time.breakdownLocal();
2532:                int stateYear = b.getYear();
2533:                int stateMonth = b.getMonth();
2534:                int stateDay = b.getDay();
2535:                if ((sstate.getAttribute(STATE_YEAR) != null)
2536:                        && (sstate.getAttribute(STATE_MONTH) != null)
2537:                        && (sstate.getAttribute(STATE_DAY) != null)) {
2538:                    stateYear = ((Integer) sstate.getAttribute(STATE_YEAR))
2539:                            .intValue();
2540:                    stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH))
2541:                            .intValue();
2542:                    stateDay = ((Integer) sstate.getAttribute(STATE_DAY))
2543:                            .intValue();
2544:                }
2545:
2546:                CalendarUtil calObj = new CalendarUtil();
2547:                calObj.setDay(stateYear, stateMonth, stateDay);
2548:
2549:                dateObj1.setTodayDate(calObj.getMonthInteger(), calObj
2550:                        .getDayOfMonth(), calObj.getYear());
2551:
2552:                // fill this month object with all days avilable for this month
2553:                if (CalendarService.allowGetCalendar(state
2554:                        .getPrimaryCalendarReference()) == false) {
2555:                    exceptionMessage.append(rb
2556:                            .getString("java.alert.younotallow"));
2557:                    CalendarEventVectorObj = new CalendarEventVector();
2558:
2559:                }
2560:
2561:                CalendarEventVectorObj = CalendarService.getEvents(
2562:                        getCalendarReferenceList(portlet, state
2563:                                .getPrimaryCalendarReference(),
2564:                                isOnWorkspaceTab()), getMonthTimeRange(calObj));
2565:
2566:                calObj.setDay(dateObj1.getYear(), dateObj1.getMonth(), dateObj1
2567:                        .getDay());
2568:
2569:                monthObj2 = calMonth(calObj.getMonthInteger(), calObj, state,
2570:                        CalendarEventVectorObj);
2571:
2572:                calObj.setDay(dateObj1.getYear(), dateObj1.getMonth(), dateObj1
2573:                        .getDay());
2574:
2575:                // retrieve the information from day, month and year to calObj again since calObj changed during the process of CalMonth().
2576:                context.put("nameOfMonth", calendarUtilGetMonth(calObj
2577:                        .getMonthInteger()));
2578:                context.put("year", new Integer(calObj.getYear()));
2579:                context.put("monthArray", monthObj2);
2580:                context.put("tlang", rb);
2581:                int row = 5;
2582:                context.put("row", new Integer(row));
2583:                context.put("date", dateObj1);
2584:                context.put("realDate", TimeService.newTime());
2585:
2586:                buildMenu(portlet, context, runData, state, CalendarPermissions
2587:                        .allowCreateEvents(state.getPrimaryCalendarReference(),
2588:                                state.getSelectedCalendarReference()),
2589:                        CalendarPermissions.allowDeleteEvent(state
2590:                                .getPrimaryCalendarReference(), state
2591:                                .getSelectedCalendarReference(), state
2592:                                .getCalendarEventId()), CalendarPermissions
2593:                                .allowReviseEvents(state
2594:                                        .getPrimaryCalendarReference(), state
2595:                                        .getSelectedCalendarReference(), state
2596:                                        .getCalendarEventId()),
2597:                        CalendarPermissions.allowMergeCalendars(state
2598:                                .getPrimaryCalendarReference(),
2599:                                isOnWorkspaceTab()), CalendarPermissions
2600:                                .allowModifyCalendarProperties(state
2601:                                        .getPrimaryCalendarReference()),
2602:                        CalendarPermissions.allowImport(state
2603:                                .getPrimaryCalendarReference()));
2604:
2605:                state.setState("month");
2606:
2607:                context.put("selectedView", rb.getString("java.bymonth"));
2608:
2609:            } // buildMonthContext
2610:
2611:            protected Vector getNewEvents(int year, int month, int day,
2612:                    CalendarActionState state, RunData rundata, int time,
2613:                    int numberofcycles, Context context,
2614:                    CalendarEventVector CalendarEventVectorObj) {
2615:                boolean firstTime = true;
2616:                Vector events = new Vector();
2617:
2618:                Time timeObj = TimeService.newTimeLocal(year, month, day, time,
2619:                        00, 00, 000);
2620:
2621:                long duration = ((30 * 60) * (1000));
2622:                Time updatedTime = TimeService.newTime(timeObj.getTime()
2623:                        + duration);
2624:
2625:                /*** include the start time ***/
2626:                TimeRange timeRangeObj = TimeService.newTimeRange(timeObj,
2627:                        updatedTime, true, false);
2628:
2629:                for (int range = 0; range <= numberofcycles; range++) {
2630:                    Iterator calEvent = null;
2631:
2632:                    calEvent = CalendarEventVectorObj.getEvents(timeRangeObj);
2633:
2634:                    Vector vectorObj = new Vector();
2635:                    EventDisplayClass eventDisplayObj;
2636:                    Vector newVectorObj = null;
2637:                    boolean swapflag = true;
2638:                    EventDisplayClass eventdisplayobj = null;
2639:
2640:                    if (calEvent.hasNext()) {
2641:                        int i = 0;
2642:                        while (calEvent.hasNext()) {
2643:                            eventdisplayobj = new EventDisplayClass();
2644:                            eventdisplayobj.setEvent((CalendarEvent) calEvent
2645:                                    .next(), false, i);
2646:
2647:                            vectorObj.add(i, eventdisplayobj);
2648:                            i++;
2649:                        } // while
2650:
2651:                        if (firstTime) {
2652:                            events.add(range, vectorObj);
2653:                            firstTime = false;
2654:                        } else {
2655:                            while (swapflag == true) {
2656:                                swapflag = false;
2657:                                for (int mm = 0; mm < events.size(); mm++) {
2658:                                    int eom, mv = 0;
2659:                                    Vector evectorObj = (Vector) events
2660:                                            .elementAt(mm);
2661:                                    if (evectorObj.isEmpty() == false) {
2662:                                        for (eom = 0; eom < evectorObj.size(); eom++) {
2663:                                            if (evectorObj.elementAt(eom) != "") {
2664:                                                String eomId = (((EventDisplayClass) evectorObj
2665:                                                        .elementAt(eom))
2666:                                                        .getEvent()).getId();
2667:                                                newVectorObj = new Vector();
2668:                                                for (mv = 0; mv < vectorObj
2669:                                                        .size(); mv++) {
2670:                                                    if (vectorObj.elementAt(mv) != "") {
2671:                                                        String vectorId = (((EventDisplayClass) vectorObj
2672:                                                                .elementAt(mv))
2673:                                                                .getEvent())
2674:                                                                .getId();
2675:                                                        if (vectorId
2676:                                                                .equals(eomId)) {
2677:                                                            eventDisplayObj = (EventDisplayClass) vectorObj
2678:                                                                    .elementAt(mv);
2679:                                                            eventDisplayObj
2680:                                                                    .setFlag(true);
2681:                                                            if (mv != eom) {
2682:                                                                swapflag = true;
2683:                                                                vectorObj
2684:                                                                        .removeElementAt(mv);
2685:                                                                for (int x = 0; x < eom; x++) {
2686:                                                                    if (vectorObj
2687:                                                                            .isEmpty() == false) {
2688:                                                                        newVectorObj
2689:                                                                                .add(
2690:                                                                                        x,
2691:                                                                                        vectorObj
2692:                                                                                                .elementAt(0));
2693:                                                                        vectorObj
2694:                                                                                .removeElementAt(0);
2695:                                                                    } else {
2696:                                                                        newVectorObj
2697:                                                                                .add(
2698:                                                                                        x,
2699:                                                                                        "");
2700:                                                                    }
2701:                                                                }// for
2702:                                                                newVectorObj
2703:                                                                        .add(
2704:                                                                                eom,
2705:                                                                                eventDisplayObj);
2706:                                                                int neweom = eom;
2707:                                                                neweom = neweom + 1;
2708:
2709:                                                                while (vectorObj
2710:                                                                        .isEmpty() == false) {
2711:                                                                    newVectorObj
2712:                                                                            .add(
2713:                                                                                    neweom,
2714:                                                                                    vectorObj
2715:                                                                                            .elementAt(0));
2716:                                                                    vectorObj
2717:                                                                            .removeElementAt(0);
2718:                                                                    neweom++;
2719:                                                                }
2720:
2721:                                                                for (int vv = 0; vv < newVectorObj
2722:                                                                        .size(); vv++) {
2723:                                                                    vectorObj
2724:                                                                            .add(
2725:                                                                                    vv,
2726:                                                                                    newVectorObj
2727:                                                                                            .elementAt(vv));
2728:                                                                }
2729:                                                            } // if
2730:                                                        } // if
2731:                                                    } // if
2732:                                                } //for
2733:                                            } // if
2734:                                        } // for
2735:                                    } // if
2736:                                } // for
2737:                            } // while
2738:
2739:                            if (vectorObj.isEmpty()) {
2740:                                events.add(range, vectorObj);
2741:                            } else {
2742:                                events.add(range, vectorObj);
2743:                            }
2744:                        } // if - else firstTime
2745:
2746:                        timeRangeObj.shiftForward(1800000);
2747:                    } else {
2748:                        events.add(range, vectorObj);
2749:                        timeRangeObj.shiftForward(1800000);
2750:                    }
2751:                } // for
2752:                return events;
2753:            } // getNewEvents
2754:
2755:            /**
2756:             * Build the context for showing day view
2757:             */
2758:            protected void buildDayContext(VelocityPortlet portlet,
2759:                    Context context, RunData runData, CalendarActionState state) {
2760:
2761:                Calendar calendarObj = null;
2762:                boolean allowed = false;
2763:                MyDate dateObj1 = null;
2764:                StringBuffer exceptionMessage = new StringBuffer();
2765:                CalendarEventVector CalendarEventVectorObj = null;
2766:
2767:                String peid = ((JetspeedRunData) runData).getJs_peid();
2768:                SessionState sstate = ((JetspeedRunData) runData)
2769:                        .getPortletSessionState(peid);
2770:
2771:                Time m_time = TimeService.newTime();
2772:                TimeBreakdown b = m_time.breakdownLocal();
2773:                int stateYear = b.getYear();
2774:                int stateMonth = b.getMonth();
2775:                int stateDay = b.getDay();
2776:                context.put("todayYear", new Integer(stateYear));
2777:                context.put("todayMonth", new Integer(stateMonth));
2778:                context.put("todayDay", new Integer(stateDay));
2779:
2780:                if ((sstate.getAttribute(STATE_YEAR) != null)
2781:                        && (sstate.getAttribute(STATE_MONTH) != null)
2782:                        && (sstate.getAttribute(STATE_DAY) != null)) {
2783:                    stateYear = ((Integer) sstate.getAttribute(STATE_YEAR))
2784:                            .intValue();
2785:                    stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH))
2786:                            .intValue();
2787:                    stateDay = ((Integer) sstate.getAttribute(STATE_DAY))
2788:                            .intValue();
2789:                }
2790:                CalendarUtil calObj = new CalendarUtil();
2791:                calObj.setDay(stateYear, stateMonth, stateDay);
2792:
2793:                // new objects of myYear, myMonth, myDay, myWeek classes
2794:                dateObj1 = new MyDate();
2795:                dateObj1.setTodayDate(calObj.getMonthInteger(), calObj
2796:                        .getDayOfMonth(), calObj.getYear());
2797:
2798:                int year = dateObj1.getYear();
2799:                int month = dateObj1.getMonth();
2800:                int day = dateObj1.getDay();
2801:
2802:                Vector eventVector = new Vector();
2803:
2804:                String calId = state.getPrimaryCalendarReference();
2805:
2806:                if (CalendarService.allowGetCalendar(calId) == false) {
2807:                    allowed = false;
2808:                    exceptionMessage.append(rb
2809:                            .getString("java.alert.younotallow"));
2810:                } else {
2811:                    try {
2812:                        calendarObj = CalendarService.getCalendar(calId);
2813:                        allowed = calendarObj.allowAddEvent();
2814:
2815:                        CalendarEventVectorObj = CalendarService.getEvents(
2816:                                getCalendarReferenceList(portlet, state
2817:                                        .getPrimaryCalendarReference(),
2818:                                        isOnWorkspaceTab()), getDayTimeRange(
2819:                                        year, month, day));
2820:
2821:                        String currentPage = state.getCurrentPage();
2822:
2823:                        // if coming from clicking the the day number in month view, year view or list view
2824:                        // select the time slot first, go to the slot containing earliest event on that day
2825:
2826:                        if (state.getPrevState() != null) {
2827:                            if ((state.getPrevState()).equalsIgnoreCase("list")
2828:                                    || (state.getPrevState())
2829:                                            .equalsIgnoreCase("month")
2830:                                    || (state.getPrevState())
2831:                                            .equalsIgnoreCase("year")) {
2832:                                CalendarEventVector vec = null;
2833:                                Time timeObj = TimeService.newTimeLocal(year,
2834:                                        month, day, FIRST_PAGE_START_HOUR, 00,
2835:                                        00, 000);
2836:                                Time timeObj2 = TimeService.newTimeLocal(year,
2837:                                        month, day, 7, 59, 59, 000);
2838:                                TimeRange timeRangeObj = TimeService
2839:                                        .newTimeRange(timeObj, timeObj2);
2840:                                vec = CalendarService.getEvents(
2841:                                        getCalendarReferenceList(portlet, state
2842:                                                .getPrimaryCalendarReference(),
2843:                                                isOnWorkspaceTab()),
2844:                                        timeRangeObj);
2845:
2846:                                if (vec.size() > 0)
2847:                                    currentPage = "first";
2848:                                else {
2849:                                    timeObj = TimeService.newTimeLocal(year,
2850:                                            month, day, SECOND_PAGE_START_HOUR,
2851:                                            00, 00, 000);
2852:                                    timeObj2 = TimeService.newTimeLocal(year,
2853:                                            month, day, 17, 59, 59, 000);
2854:                                    timeRangeObj = TimeService.newTimeRange(
2855:                                            timeObj, timeObj2);
2856:                                    vec = CalendarService
2857:                                            .getEvents(
2858:                                                    getCalendarReferenceList(
2859:                                                            portlet,
2860:                                                            state
2861:                                                                    .getPrimaryCalendarReference(),
2862:                                                            isOnWorkspaceTab()),
2863:                                                    timeRangeObj);
2864:
2865:                                    if (vec.size() > 0)
2866:                                        currentPage = "second";
2867:                                    else {
2868:                                        timeObj = TimeService.newTimeLocal(
2869:                                                year, month, day,
2870:                                                THIRD_PAGE_START_HOUR, 00, 00,
2871:                                                000);
2872:                                        timeObj2 = TimeService.newTimeLocal(
2873:                                                year, month, day, 23, 59, 59,
2874:                                                000);
2875:                                        timeRangeObj = TimeService
2876:                                                .newTimeRange(timeObj, timeObj2);
2877:                                        vec = CalendarService
2878:                                                .getEvents(
2879:                                                        getCalendarReferenceList(
2880:                                                                portlet,
2881:                                                                state
2882:                                                                        .getPrimaryCalendarReference(),
2883:                                                                isOnWorkspaceTab()),
2884:                                                        timeRangeObj);
2885:
2886:                                        if (vec.size() > 0)
2887:                                            currentPage = "third";
2888:                                        else
2889:                                            currentPage = "second";
2890:                                    }
2891:                                }
2892:                                state.setCurrentPage(currentPage);
2893:                            }
2894:                        }
2895:
2896:                        if (currentPage.equals("third")) {
2897:                            eventVector = getNewEvents(year, month, day, state,
2898:                                    runData, THIRD_PAGE_START_HOUR, 19,
2899:                                    context, CalendarEventVectorObj);
2900:                        } else if (currentPage.equals("second")) {
2901:                            eventVector = getNewEvents(year, month, day, state,
2902:                                    runData, SECOND_PAGE_START_HOUR, 19,
2903:                                    context, CalendarEventVectorObj);
2904:                        } else {
2905:                            eventVector = getNewEvents(year, month, day, state,
2906:                                    runData, FIRST_PAGE_START_HOUR, 19,
2907:                                    context, CalendarEventVectorObj);
2908:                        }
2909:
2910:                        dateObj1.setEventBerDay(eventVector);
2911:                    } catch (IdUnusedException e) {
2912:                        exceptionMessage.append(rb
2913:                                .getString("java.alert.therenoactv"));
2914:                        M_log.debug(".buildDayContext(): " + e);
2915:
2916:                        for (int i = 0; i < 20; i++)
2917:                            eventVector.add(i, new Vector());
2918:
2919:                        dateObj1.setEventBerDay(eventVector);
2920:                    } catch (PermissionException e) {
2921:                        exceptionMessage.append(rb
2922:                                .getString("java.alert.younotperm"));
2923:                        M_log.debug(".buildDayContext(): " + e);
2924:
2925:                        for (int i = 0; i < 20; i++)
2926:                            eventVector.add(i, new Vector());
2927:
2928:                        dateObj1.setEventBerDay(eventVector);
2929:                    }
2930:                }
2931:
2932:                context.put("nameOfMonth", calendarUtilGetMonth(calObj
2933:                        .getMonthInteger()));
2934:                context.put("monthInt", new Integer(calObj.getMonthInteger()));
2935:                context.put("firstpage", "true");
2936:                context.put("secondpage", "false");
2937:                context.put("page", state.getCurrentPage());
2938:                context.put("date", dateObj1);
2939:                context.put("helper", new Helper());
2940:                context.put("calObj", calObj);
2941:                context.put("tlang", rb);
2942:                state.setState("day");
2943:                context.put("message", state.getState());
2944:
2945:                state.setPrevState("");
2946:
2947:                buildMenu(portlet, context, runData, state, CalendarPermissions
2948:                        .allowCreateEvents(state.getPrimaryCalendarReference(),
2949:                                state.getSelectedCalendarReference()),
2950:                        CalendarPermissions.allowDeleteEvent(state
2951:                                .getPrimaryCalendarReference(), state
2952:                                .getSelectedCalendarReference(), state
2953:                                .getCalendarEventId()), CalendarPermissions
2954:                                .allowReviseEvents(state
2955:                                        .getPrimaryCalendarReference(), state
2956:                                        .getSelectedCalendarReference(), state
2957:                                        .getCalendarEventId()),
2958:                        CalendarPermissions.allowMergeCalendars(state
2959:                                .getPrimaryCalendarReference(),
2960:                                isOnWorkspaceTab()), CalendarPermissions
2961:                                .allowModifyCalendarProperties(state
2962:                                        .getPrimaryCalendarReference()),
2963:                        CalendarPermissions.allowImport(state
2964:                                .getPrimaryCalendarReference()));
2965:
2966:                context.put("permissionallowed", Boolean.valueOf(allowed));
2967:                context.put("tlang", rb);
2968:
2969:                context.put("selectedView", rb.getString("java.byday"));
2970:
2971:            } // buildDayContext
2972:
2973:            /**
2974:             * Build the context for showing week view
2975:             */
2976:            protected void buildWeekContext(VelocityPortlet portlet,
2977:                    Context context, RunData runData, CalendarActionState state) {
2978:                Calendar calendarObj = null;
2979:                //Time st,et = null;
2980:                //CalendarUtil calObj= null;
2981:                MyYear yearObj = null;
2982:                MyMonth monthObj1 = null;
2983:                MyWeek weekObj = null;
2984:                MyDay dayObj = null;
2985:                MyDate dateObj1, dateObj2 = null;
2986:                boolean allowed = false;
2987:                int dayofweek = 0;
2988:
2989:                // new objects of myYear, myMonth, myDay, myWeek classes
2990:                yearObj = new MyYear();
2991:                monthObj1 = new MyMonth();
2992:                weekObj = new MyWeek();
2993:                dayObj = new MyDay();
2994:                dateObj1 = new MyDate();
2995:                CalendarEventVector CalendarEventVectorObj = null;
2996:
2997:                //calObj = state.getCalObj();
2998:                String peid = ((JetspeedRunData) runData).getJs_peid();
2999:                SessionState sstate = ((JetspeedRunData) runData)
3000:                        .getPortletSessionState(peid);
3001:
3002:                Time m_time = TimeService.newTime();
3003:                TimeBreakdown b = m_time.breakdownLocal();
3004:                int stateYear = b.getYear();
3005:                int stateMonth = b.getMonth();
3006:                int stateDay = b.getDay();
3007:                if ((sstate.getAttribute(STATE_YEAR) != null)
3008:                        && (sstate.getAttribute(STATE_MONTH) != null)
3009:                        && (sstate.getAttribute(STATE_DAY) != null)) {
3010:                    stateYear = ((Integer) sstate.getAttribute(STATE_YEAR))
3011:                            .intValue();
3012:                    stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH))
3013:                            .intValue();
3014:                    stateDay = ((Integer) sstate.getAttribute(STATE_DAY))
3015:                            .intValue();
3016:                }
3017:
3018:                CalendarUtil calObj = new CalendarUtil();
3019:                calObj.setDay(stateYear, stateMonth, stateDay);
3020:                int iii = 0;
3021:
3022:                dateObj1.setTodayDate(calObj.getMonthInteger(), calObj
3023:                        .getDayOfMonth(), calObj.getYear());
3024:                yearObj.setYear(calObj.getYear());
3025:                monthObj1.setMonth(calObj.getMonthInteger());
3026:                dayObj.setDay(calObj.getDayOfMonth());
3027:                String calId = state.getPrimaryCalendarReference();
3028:
3029:                StringBuffer exceptionMessage = new StringBuffer();
3030:
3031:                // this loop will move the calendar to the begining of the week
3032:
3033:                if (CalendarService.allowGetCalendar(calId) == false) {
3034:                    allowed = false;
3035:                    exceptionMessage.append(rb
3036:                            .getString("java.alert.younotallow"));
3037:                } else {
3038:                    try {
3039:                        calendarObj = CalendarService.getCalendar(calId);
3040:                        allowed = true;
3041:                    } catch (IdUnusedException e) {
3042:                        try {
3043:                            CalendarService.commitCalendar(CalendarService
3044:                                    .addCalendar(calId));
3045:                            calendarObj = CalendarService.getCalendar(calId);
3046:                            allowed = true;
3047:                        } catch (PermissionException err) {
3048:                            M_log.debug(".buildWeekContext(): " + err);
3049:                        } catch (IdUsedException err) {
3050:                            M_log.debug(".buildWeekContext(): " + err);
3051:                        } catch (IdInvalidException err) {
3052:                            M_log.debug(".buildWeekContext(): " + err);
3053:                        } catch (IdUnusedException err) {
3054:                            M_log.debug(".buildWeekContext(): " + err);
3055:                        }
3056:                    } catch (PermissionException e) {
3057:                        M_log.debug(".buildWeekContext(): " + e);
3058:                        allowed = false;
3059:                    }
3060:                }
3061:
3062:                if ((allowed == true)
3063:                        && (exceptionMessage.toString().length() <= 0)) {
3064:                    if (calendarObj.allowGetEvents() == true) {
3065:                        CalendarEventVectorObj = CalendarService.getEvents(
3066:                                getCalendarReferenceList(portlet, state
3067:                                        .getPrimaryCalendarReference(),
3068:                                        isOnWorkspaceTab()),
3069:                                getWeekTimeRange(calObj));
3070:                    } else {
3071:                        CalendarEventVectorObj = new CalendarEventVector();
3072:                    }
3073:                } else {
3074:                    CalendarEventVectorObj = new CalendarEventVector();
3075:                }
3076:
3077:                calObj.setDay(dateObj1.getYear(), dateObj1.getMonth(), dateObj1
3078:                        .getDay());
3079:                dayofweek = calObj.getDay_Of_Week();
3080:
3081:                for (int i = dayofweek; i > 1; i--) {
3082:                    calObj.getPrevDate();
3083:                }
3084:
3085:                dayofweek = calObj.getDay_Of_Week();
3086:
3087:                Time[] pageStartTime = new Time[7];
3088:                Time[] pageEndTime = new Time[7];
3089:                //Vector pageStartTimeVec = new Vector();
3090:                //Vector pageEndTimeVec = new Vector();
3091:
3092:                for (int i = 7; i >= dayofweek; i--) {
3093:
3094:                    Vector eventVector = new Vector();
3095:                    Vector eventVector1;
3096:                    dateObj2 = new MyDate();
3097:                    dateObj2.setTodayDate(calObj.getMonthInteger(), calObj
3098:                            .getDayOfMonth(), calObj.getYear());
3099:                    dateObj2.setDayName(calendarUtilGetDay(calObj
3100:                            .getDay_Of_Week()));
3101:                    dateObj2.setNameOfMonth(calendarUtilGetMonth(calObj
3102:                            .getMonthInteger()));
3103:
3104:                    if (calObj.getDayOfMonth() == dayObj.getDay())
3105:                        dateObj2.setFlag(1);
3106:
3107:                    if (state.getCurrentPage().equals("third")) {
3108:                        eventVector1 = new Vector();
3109:                        // JS -- the third page starts at 2PM(14 o'clock), and lasts 20 half-hour
3110:                        eventVector = getNewEvents(calObj.getYear(), calObj
3111:                                .getMonthInteger(), calObj.getDayOfMonth(),
3112:                                state, runData, THIRD_PAGE_START_HOUR, 19,
3113:                                context, CalendarEventVectorObj);
3114:
3115:                        for (int index = 0; index < eventVector1.size(); index++) {
3116:                            eventVector.add(eventVector.size(), eventVector1
3117:                                    .get(index));
3118:                        }
3119:
3120:                        // Reminder: weekview vm is using 0..6
3121:                        pageStartTime[i - 1] = TimeService.newTimeLocal(calObj
3122:                                .getYear(), calObj.getMonthInteger(), calObj
3123:                                .getDayOfMonth(), THIRD_PAGE_START_HOUR, 0, 0,
3124:                                0);
3125:                        pageEndTime[i - 1] = TimeService.newTimeLocal(calObj
3126:                                .getYear(), calObj.getMonthInteger(), calObj
3127:                                .getDayOfMonth(), 23, 59, 0, 0);
3128:
3129:                    } else if (state.getCurrentPage().equals("second")) {
3130:                        eventVector = getNewEvents(calObj.getYear(), calObj
3131:                                .getMonthInteger(), calObj.getDayOfMonth(),
3132:                                state, runData, SECOND_PAGE_START_HOUR, 19,
3133:                                context, CalendarEventVectorObj);
3134:                        // Reminder: weekview vm is using 0..6
3135:                        pageStartTime[i - 1] = TimeService.newTimeLocal(calObj
3136:                                .getYear(), calObj.getMonthInteger(), calObj
3137:                                .getDayOfMonth(), SECOND_PAGE_START_HOUR, 0, 0,
3138:                                0);
3139:                        pageEndTime[i - 1] = TimeService.newTimeLocal(calObj
3140:                                .getYear(), calObj.getMonthInteger(), calObj
3141:                                .getDayOfMonth(), 17, 59, 0, 0);
3142:
3143:                    } else {
3144:                        eventVector1 = new Vector();
3145:                        // JS -- the first page starts at 12AM(0 o'clock), and lasts 20 half-hour
3146:                        eventVector1 = getNewEvents(calObj.getYear(), calObj
3147:                                .getMonthInteger(), calObj.getDayOfMonth(),
3148:                                state, runData, FIRST_PAGE_START_HOUR, 19,
3149:                                context, CalendarEventVectorObj);
3150:
3151:                        for (int index = 0; index < eventVector1.size(); index++) {
3152:                            eventVector.insertElementAt(
3153:                                    eventVector1.get(index), index);
3154:                        }
3155:
3156:                        // Reminder: weekview vm is using 0..6
3157:                        pageStartTime[i - 1] = TimeService.newTimeLocal(calObj
3158:                                .getYear(), calObj.getMonthInteger(), calObj
3159:                                .getDayOfMonth(), 0, 0, 0, 0);
3160:                        pageEndTime[i - 1] = TimeService.newTimeLocal(calObj
3161:                                .getYear(), calObj.getMonthInteger(), calObj
3162:                                .getDayOfMonth(), 9, 59, 0, 0);
3163:
3164:                    }
3165:                    dateObj2.setEventBerWeek(eventVector);
3166:                    weekObj.setWeek(7 - i, dateObj2);
3167:
3168:                    // the purpose of this if condition is to check if we reached day 7 if yes do not
3169:                    // call next day.
3170:                    if (i > dayofweek)
3171:                        calObj.nextDate();
3172:                }
3173:
3174:                calObj.setDay(yearObj.getYear(), monthObj1.getMonth(), dayObj
3175:                        .getDay());
3176:                context.put("week", weekObj);
3177:                context.put("helper", new Helper());
3178:                context.put("date", dateObj1);
3179:                context.put("page", state.getCurrentPage());
3180:                state.setState("week");
3181:                context.put("tlang", rb);
3182:                //state.setCalObj(calObj);
3183:
3184:                context.put("message", state.getState());
3185:
3186:                buildMenu(portlet, context, runData, state, CalendarPermissions
3187:                        .allowCreateEvents(state.getPrimaryCalendarReference(),
3188:                                state.getSelectedCalendarReference()),
3189:                        CalendarPermissions.allowDeleteEvent(state
3190:                                .getPrimaryCalendarReference(), state
3191:                                .getSelectedCalendarReference(), state
3192:                                .getCalendarEventId()), CalendarPermissions
3193:                                .allowReviseEvents(state
3194:                                        .getPrimaryCalendarReference(), state
3195:                                        .getSelectedCalendarReference(), state
3196:                                        .getCalendarEventId()),
3197:                        CalendarPermissions.allowMergeCalendars(state
3198:                                .getPrimaryCalendarReference(),
3199:                                isOnWorkspaceTab()), CalendarPermissions
3200:                                .allowModifyCalendarProperties(state
3201:                                        .getPrimaryCalendarReference()),
3202:                        CalendarPermissions.allowImport(state
3203:                                .getPrimaryCalendarReference()));
3204:
3205:                calObj.setDay(yearObj.getYear(), monthObj1.getMonth(), dayObj
3206:                        .getDay());
3207:
3208:                context.put("realDate", TimeService.newTime());
3209:                context.put("tlang", rb);
3210:                Vector vec = new Vector();
3211:                context.put("vec", vec);
3212:                Vector conflictVec = new Vector();
3213:                context.put("conflictVec", conflictVec);
3214:                Vector calVec = new Vector();
3215:                context.put("calVec", calVec);
3216:                HashMap hm = new HashMap();
3217:                context.put("hm", hm);
3218:                Integer intObj = new Integer(0);
3219:                context.put("intObj", intObj);
3220:
3221:                context.put("pageStartTime", pageStartTime);
3222:                context.put("pageEndTime", pageEndTime);
3223:
3224:                context.put("selectedView", rb.getString("java.byweek"));
3225:
3226:            } // buildWeekContext
3227:
3228:            /**
3229:             * Build the context for showing New view
3230:             */
3231:            protected void buildNewContext(VelocityPortlet portlet,
3232:                    Context context, RunData runData, CalendarActionState state) {
3233:                context.put("tlang", rb);
3234:                // to get the content Type Image Service
3235:                context.put("contentTypeImageService", ContentTypeImageService
3236:                        .getInstance());
3237:
3238:                MyDate dateObj1 = new MyDate();
3239:
3240:                CalendarUtil calObj = new CalendarUtil();
3241:
3242:                // set real today's date as default
3243:                Time m_time = TimeService.newTime();
3244:                TimeBreakdown b = m_time.breakdownLocal();
3245:                calObj.setDay(b.getYear(), b.getMonth(), b.getDay());
3246:
3247:                dateObj1.setTodayDate(calObj.getMonthInteger(), calObj
3248:                        .getDayOfMonth(), calObj.getYear());
3249:
3250:                // get the event id from the CalendarService.
3251:                // send the event to the vm
3252:                dateObj1.setNumberOfDaysInMonth(calObj.getNumberOfDays());
3253:                List attachments = state.getAttachments();
3254:                context.put("attachments", attachments);
3255:
3256:                String calId = state.getPrimaryCalendarReference();
3257:                Calendar calendarObj = null;
3258:                StringBuffer exceptionMessage = new StringBuffer();
3259:
3260:                try {
3261:                    calendarObj = CalendarService.getCalendar(calId);
3262:                    Collection groups = calendarObj.getGroupsAllowAddEvent();
3263:
3264:                    String peid = ((JetspeedRunData) runData).getJs_peid();
3265:                    SessionState sstate = ((JetspeedRunData) runData)
3266:                            .getPortletSessionState(peid);
3267:
3268:                    String scheduleTo = (String) sstate
3269:                            .getAttribute(STATE_SCHEDULE_TO);
3270:                    if (scheduleTo != null && scheduleTo.length() != 0) {
3271:                        context.put("scheduleTo", scheduleTo);
3272:                    } else {
3273:                        if (calendarObj.allowAddCalendarEvent()) {
3274:                            // default to make site selection
3275:                            context.put("scheduleTo", "site");
3276:                        } else if (groups.size() > 0) {
3277:                            // to group otherwise
3278:                            context.put("scheduleTo", "groups");
3279:                        }
3280:                    }
3281:
3282:                    if (groups.size() > 0) {
3283:                        List schToGroups = (List) (sstate
3284:                                .getAttribute(STATE_SCHEDULE_TO_GROUPS));
3285:                        context.put("scheduleToGroups", schToGroups);
3286:
3287:                        context.put("groups", groups);
3288:                    }
3289:                } catch (IdUnusedException e) {
3290:                    exceptionMessage.append(rb.getString("java.alert.thereis"));
3291:                    M_log.debug(".buildNewContext(): " + e);
3292:                } catch (PermissionException e) {
3293:                    exceptionMessage.append(rb.getString("java.alert.youdont"));
3294:                    M_log.debug(".buildNewContext(): " + e);
3295:                }
3296:
3297:                // Add any additional fields in the calendar.
3298:                customizeCalendarPage
3299:                        .loadAdditionalFieldsIntoContextFromCalendar(
3300:                                calendarObj, context);
3301:
3302:                // Output for recurring events
3303:                String peid = ((JetspeedRunData) runData).getJs_peid();
3304:                SessionState sstate = ((JetspeedRunData) runData)
3305:                        .getPortletSessionState(peid);
3306:
3307:                // if the saved recurring rule equals to string FREQ_ONCE, set it as not recurring
3308:                // if there is a saved recurring rule in sstate, display it		
3309:                RecurrenceRule rule = (RecurrenceRule) sstate
3310:                        .getAttribute(CalendarAction.SSTATE__RECURRING_RULE);
3311:
3312:                if (rule != null) {
3313:                    context.put("freq", rule.getFrequencyDescription());
3314:
3315:                    context.put("rule", rule);
3316:                }
3317:
3318:                context.put("date", dateObj1);
3319:                context.put("savedData", state.getNewData());
3320:                context.put("helper", new Helper());
3321:                context.put("realDate", TimeService.newTime());
3322:
3323:            } // buildNewContext
3324:
3325:            /**
3326:             * Build the context for showing delete view
3327:             */
3328:            protected void buildDeleteContext(VelocityPortlet portlet,
3329:                    Context context, RunData runData, CalendarActionState state) {
3330:                context.put("tlang", rb);
3331:                // to get the content Type Image Service
3332:                context.put("contentTypeImageService", ContentTypeImageService
3333:                        .getInstance());
3334:
3335:                Calendar calendarObj = null;
3336:                CalendarEvent calEvent = null;
3337:                StringBuffer exceptionMessage = new StringBuffer();
3338:
3339:                // get the event id from the CalendarService.
3340:                // send the event to the vm
3341:                String calId = state.getPrimaryCalendarReference();
3342:                String calendarEventObj = state.getCalendarEventId();
3343:
3344:                try {
3345:                    calendarObj = CalendarService.getCalendar(calId);
3346:                    calEvent = calendarObj.getEvent(calendarEventObj);
3347:
3348:                    RecurrenceRule rule = calEvent.getRecurrenceRule();
3349:                    // for a brand new event, there is no saved recurring rule
3350:                    if (rule != null) {
3351:                        context.put("freq", rule.getFrequencyDescription());
3352:                        context.put("rule", rule);
3353:                    }
3354:
3355:                    context.put("message", "delete");
3356:                    context.put("event", calEvent);
3357:
3358:                    // show all the groups in this calendar that user has get event in
3359:                    Collection groups = calendarObj.getGroupsAllowGetEvent();
3360:                    if (groups != null) {
3361:                        context.put("groupRange", calEvent
3362:                                .getGroupRangeForDisplay(calendarObj));
3363:                    }
3364:                } catch (IdUnusedException e) {
3365:                    exceptionMessage.append(rb.getString("java.alert.noexist"));
3366:                    M_log.debug(".buildDeleteContext(): " + e);
3367:                } catch (PermissionException e) {
3368:                    exceptionMessage.append(rb
3369:                            .getString("java.alert.youcreate"));
3370:                    M_log.debug(".buildDeleteContext(): " + e);
3371:                }
3372:            } // buildDeleteContext
3373:
3374:            /**
3375:             * calculate the days in the month and there events if any
3376:             * @param month is int
3377:             * @param m_calObj is object of calendar
3378:             */
3379:            public MyMonth calMonth(int month, CalendarUtil m_calObj,
3380:                    CalendarActionState state,
3381:                    CalendarEventVector CalendarEventVectorObj) {
3382:                int numberOfDays = 0;
3383:                int firstDay_of_Month = 0;
3384:                boolean start = true;
3385:                MyMonth monthObj = null;
3386:                MyDate dateObj = null;
3387:                Iterator eventList = null;
3388:                Time startTime = null;
3389:                Time endTime = null;
3390:                TimeRange timeRange = null;
3391:                StringBuffer exceptionMessage = new StringBuffer();
3392:
3393:                // new objects of myYear, myMonth, myDay, myWeek classes.
3394:                monthObj = new MyMonth();
3395:
3396:                // set the calendar to the begining of the month
3397:                m_calObj.setDay(m_calObj.getYear(), month, 1);
3398:                numberOfDays = m_calObj.getNumberOfDays();
3399:
3400:                // get the index of the first day in the month
3401:                firstDay_of_Month = m_calObj.getDay_Of_Week() - 1;
3402:
3403:                // get the index of the day
3404:                monthObj.setMonthName(calendarUtilGetMonth(m_calObj
3405:                        .getMonthInteger()));
3406:
3407:                for (int i = firstDay_of_Month; i >= 0; i--) {
3408:                    m_calObj.getPrevDate();
3409:                }
3410:
3411:                for (int weekInMonth = 0; weekInMonth < 1; weekInMonth++) {
3412:                    // got the seven days in the first week of the month do..
3413:                    for (int dayInWeek = 0; dayInWeek < 7; dayInWeek++) {
3414:                        dateObj = new MyDate();
3415:                        m_calObj.nextDate();
3416:                        // check if reach the first day of the month.
3417:                        if ((dayInWeek == firstDay_of_Month)
3418:                                || (start == false)) {
3419:                            // check if the current day of the month has been match, if yes set the flag to highlight the day in the
3420:                            // user interface.
3421:                            if ((m_calObj.getDayOfMonth() == state
3422:                                    .getcurrentDay())
3423:                                    && (state.getcurrentMonth() == m_calObj
3424:                                            .getMonthInteger())
3425:                                    && (state.getcurrentYear() == m_calObj
3426:                                            .getYear())) {
3427:                                dateObj.setFlag(1);
3428:                            }
3429:
3430:                            // Each monthObj contains dayObjs for the number of the days in the month.
3431:                            dateObj.setTodayDate(m_calObj.getMonthInteger(),
3432:                                    m_calObj.getDayOfMonth(), m_calObj
3433:                                            .getYear());
3434:
3435:                            //qz if(state.getState()!="year") {
3436:                            //startTime = TimeService.newTimeLocal(m_calObj.getYear(),m_calObj.getMonthInteger(),m_calObj.getDayOfMonth(),01,00,00,000);
3437:                            startTime = TimeService.newTimeLocal(m_calObj
3438:                                    .getYear(), m_calObj.getMonthInteger(),
3439:                                    m_calObj.getDayOfMonth(), 00, 00, 00, 001);
3440:                            //endTime = TimeService.newTimeLocal(m_calObj.getYear(),m_calObj.getMonthInteger(),m_calObj.getDayOfMonth(),24,00,00,000);
3441:                            endTime = TimeService.newTimeLocal(m_calObj
3442:                                    .getYear(), m_calObj.getMonthInteger(),
3443:                                    m_calObj.getDayOfMonth(), 23, 59, 00, 000);
3444:
3445:                            eventList = CalendarEventVectorObj
3446:                                    .getEvents(TimeService.newTimeRange(
3447:                                            startTime, endTime, true, true));
3448:
3449:                            dateObj.setEvents(eventList);
3450:                            //qz }
3451:
3452:                            // keep iterator of events in the dateObj
3453:                            numberOfDays--;
3454:                            monthObj.setDay(dateObj, weekInMonth, dayInWeek);
3455:                            start = false;
3456:
3457:                        } else if (start == true) {
3458:                            // fill empty spaces for the first days in the first week in the month before reach the first day of the month
3459:                            dateObj.setTodayDate(m_calObj.getMonthInteger(),
3460:                                    m_calObj.getDayOfMonth(), m_calObj
3461:                                            .getYear());
3462:
3463:                            startTime = TimeService.newTimeLocal(m_calObj
3464:                                    .getYear(), m_calObj.getMonthInteger(),
3465:                                    m_calObj.getDayOfMonth(), 00, 00, 00, 001);
3466:                            endTime = TimeService.newTimeLocal(m_calObj
3467:                                    .getYear(), m_calObj.getMonthInteger(),
3468:                                    m_calObj.getDayOfMonth(), 23, 59, 00, 000);
3469:
3470:                            timeRange = TimeService.newTimeRange(startTime,
3471:                                    endTime, true, true);
3472:
3473:                            eventList = CalendarEventVectorObj
3474:                                    .getEvents(timeRange);
3475:                            dateObj.setEvents(eventList);
3476:
3477:                            monthObj.setDay(dateObj, weekInMonth, dayInWeek);
3478:                            dateObj.setFlag(0);
3479:                        }// end else
3480:                    }// end for m
3481:                }// end for i
3482:
3483:                // Construct the weeks left in the month and save it in the monthObj.
3484:                // row is the max number of rows in the month., Col is equal to 7 which is the max number of col in the month.
3485:                for (int row = 1; row < 6; row++) {
3486:                    // Col is equal to 7 which is the max number of col in tin he month.
3487:                    for (int col = 0; col < 7; col++) {
3488:                        if (numberOfDays != 0) {
3489:                            dateObj = new MyDate();
3490:                            m_calObj.nextDate();
3491:                            if ((m_calObj.getDayOfMonth() == state
3492:                                    .getcurrentDay())
3493:                                    && (state.getcurrentMonth() == m_calObj
3494:                                            .getMonthInteger())
3495:                                    && (state.getcurrentYear() == m_calObj
3496:                                            .getYear()))
3497:                                dateObj.setFlag(1);
3498:
3499:                            dateObj.setTodayDate(m_calObj.getMonthInteger(),
3500:                                    m_calObj.getDayOfMonth(), m_calObj
3501:                                            .getYear());
3502:                            //qz if(state.getState()!="year") {
3503:                            //startTime = TimeService.newTimeLocal(m_calObj.getYear(),m_calObj.getMonthInteger(),m_calObj.getDayOfMonth(),01,00,00,000);
3504:                            startTime = TimeService.newTimeLocal(m_calObj
3505:                                    .getYear(), m_calObj.getMonthInteger(),
3506:                                    m_calObj.getDayOfMonth(), 00, 00, 00, 001);
3507:                            //endTime = TimeService.newTimeLocal(m_calObj.getYear(),m_calObj.getMonthInteger(),m_calObj.getDayOfMonth(),24,00,00,000);
3508:                            endTime = TimeService.newTimeLocal(m_calObj
3509:                                    .getYear(), m_calObj.getMonthInteger(),
3510:                                    m_calObj.getDayOfMonth(), 23, 59, 00, 000);
3511:
3512:                            timeRange = TimeService.newTimeRange(startTime,
3513:                                    endTime, true, true);
3514:                            eventList = CalendarEventVectorObj
3515:                                    .getEvents(timeRange);
3516:                            dateObj.setEvents(eventList);
3517:
3518:                            //qz }
3519:                            numberOfDays--;
3520:                            monthObj.setDay(dateObj, row, col);
3521:                            monthObj.setRow(row);
3522:                        } else // if it is not the end of week , complete the week wih days from next month.
3523:                        {
3524:                            if ((m_calObj.getDay_Of_Week()) == 7) // if end of week, exit the loop
3525:                            {
3526:                                row = 7;
3527:                                col = SECOND_PAGE_START_HOUR;
3528:                            } else // if it is not the end of week, complete with days from next month
3529:                            {
3530:                                dateObj = new MyDate();
3531:                                m_calObj.nextDate();
3532:                                dateObj.setTodayDate(
3533:                                        m_calObj.getMonthInteger(), m_calObj
3534:                                                .getDayOfMonth(), m_calObj
3535:                                                .getYear());
3536:
3537:                                //qz if(state.getState()!="year") {
3538:                                //startTime = TimeService.newTimeLocal(m_calObj.getYear(),m_calObj.getMonthInteger(),m_calObj.getDayOfMonth(),01,00,00,000);
3539:                                startTime = TimeService.newTimeLocal(m_calObj
3540:                                        .getYear(), m_calObj.getMonthInteger(),
3541:                                        m_calObj.getDayOfMonth(), 00, 00, 00,
3542:                                        001);
3543:                                //endTime = TimeService.newTimeLocal(m_calObj.getYear(),m_calObj.getMonthInteger(),m_calObj.getDayOfMonth(),24,00,00,000);
3544:                                endTime = TimeService.newTimeLocal(m_calObj
3545:                                        .getYear(), m_calObj.getMonthInteger(),
3546:                                        m_calObj.getDayOfMonth(), 23, 59, 00,
3547:                                        000);
3548:
3549:                                timeRange = TimeService.newTimeRange(startTime,
3550:                                        endTime, true, true);
3551:
3552:                                eventList = CalendarEventVectorObj
3553:                                        .getEvents(timeRange);
3554:                                dateObj.setEvents(eventList);
3555:                                //qz }
3556:                                monthObj.setDay(dateObj, row, col);
3557:                                monthObj.setRow(row);
3558:                                dateObj.setFlag(0);
3559:                            }
3560:                        }
3561:                    }// end for
3562:                }// end for
3563:
3564:                return monthObj;
3565:            }
3566:
3567:            public void doAttachments(RunData rundata, Context context) {
3568:                // get into helper mode with this helper tool
3569:                startHelper(rundata.getRequest(), "sakai.filepicker");
3570:
3571:                // setup the parameters for the helper
3572:                SessionState state = ((JetspeedRunData) rundata)
3573:                        .getPortletSessionState(((JetspeedRunData) rundata)
3574:                                .getJs_peid());
3575:                CalendarActionState State = (CalendarActionState) getState(
3576:                        context, rundata, CalendarActionState.class);
3577:
3578:                int houri;
3579:
3580:                // put a the real attachments into the stats - let the helper update it directly if the user chooses to save their attachment editing.
3581:                List attachments = State.getAttachments();
3582:                state.setAttribute(FilePickerHelper.FILE_PICKER_ATTACHMENTS,
3583:                        attachments);
3584:
3585:                String hour = "";
3586:                hour = rundata.getParameters().getString("startHour");
3587:                String title = "";
3588:                title = rundata.getParameters().getString("activitytitle");
3589:                String minute = "";
3590:                minute = rundata.getParameters().getString("startMinute");
3591:                String dhour = "";
3592:                dhour = rundata.getParameters().getString("duHour");
3593:                String dminute = "";
3594:                dminute = rundata.getParameters().getString("duMinute");
3595:                String description = "";
3596:                description = rundata.getParameters().getString("description");
3597:                description = processFormattedTextFromBrowser(state,
3598:                        description);
3599:                String month = "";
3600:                month = rundata.getParameters().getString("month");
3601:
3602:                String day = "";
3603:                day = rundata.getParameters().getString("day");
3604:                String year = "";
3605:                year = rundata.getParameters().getString("yearSelect");
3606:                String timeType = "";
3607:                timeType = rundata.getParameters().getString("startAmpm");
3608:                String type = "";
3609:                type = rundata.getParameters().getString("eventType");
3610:                String location = "";
3611:                location = rundata.getParameters().getString("location");
3612:
3613:                readEventGroupForm(rundata, context);
3614:
3615:                // read the recurrence modification intention
3616:                String intentionStr = rundata.getParameters().getString(
3617:                        "intention");
3618:                if (intentionStr == null)
3619:                    intentionStr = "";
3620:
3621:                Calendar calendarObj = null;
3622:                StringBuffer exceptionMessage = new StringBuffer();
3623:
3624:                String calId = State.getPrimaryCalendarReference();
3625:                try {
3626:                    calendarObj = CalendarService.getCalendar(calId);
3627:                } catch (IdUnusedException e) {
3628:                    exceptionMessage.append(rb.getString("java.alert.thereis"));
3629:                    M_log.debug(".buildCustomizeContext(): " + e);
3630:                } catch (PermissionException e) {
3631:                    exceptionMessage.append(rb.getString("java.alert.youdont"));
3632:                    M_log.debug(".buildCustomizeContext(): " + e);
3633:                }
3634:
3635:                Map addfieldsMap = new HashMap();
3636:
3637:                // Add any additional fields in the calendar.
3638:                customizeCalendarPage.loadAdditionalFieldsMapFromRunData(
3639:                        rundata, addfieldsMap, calendarObj);
3640:
3641:                if (timeType.equals("pm")) {
3642:                    if (Integer.parseInt(hour) > 11)
3643:                        houri = Integer.parseInt(hour);
3644:                    else
3645:                        houri = Integer.parseInt(hour) + 12;
3646:                } else if (timeType.equals("am")
3647:                        && Integer.parseInt(hour) == 12) {
3648:                    houri = 24;
3649:                } else {
3650:                    houri = Integer.parseInt(hour);
3651:                }
3652:
3653:                State.clearData();
3654:                State.setNewData(State.getPrimaryCalendarReference(), title,
3655:                        description, Integer.parseInt(month), Integer
3656:                                .parseInt(day), year, houri, Integer
3657:                                .parseInt(minute), Integer.parseInt(dhour),
3658:                        Integer.parseInt(dminute), type, timeType, location,
3659:                        addfieldsMap, intentionStr);
3660:
3661:                // **************** changed for the new attachment editor **************************
3662:
3663:            } // doAttachments
3664:
3665:            /**
3666:             * Action is used when doMonth requested in the menu
3667:             */
3668:
3669:            public void doMonth(RunData data, Context context) {
3670:
3671:                CalendarActionState state = (CalendarActionState) getState(
3672:                        context, data, CalendarActionState.class);
3673:                String peid = ((JetspeedRunData) data).getJs_peid();
3674:                SessionState sstate = ((JetspeedRunData) data)
3675:                        .getPortletSessionState(peid);
3676:
3677:                state.setState("month");
3678:
3679:            } // doMonth
3680:
3681:            /**
3682:             * Action is used when doDescription is requested when the user click on an event
3683:             */
3684:            public void doDescription(RunData data, Context context) {
3685:                CalendarEvent calendarEventObj = null;
3686:                Calendar calendarObj = null;
3687:
3688:                CalendarActionState state = (CalendarActionState) getState(
3689:                        context, data, CalendarActionState.class);
3690:                String peid = ((JetspeedRunData) data).getJs_peid();
3691:                SessionState sstate = ((JetspeedRunData) data)
3692:                        .getPortletSessionState(peid);
3693:
3694:                state.setPrevState(state.getState());
3695:
3696:                // store the state coming from, like day view, week view, month view or list view
3697:                String returnState = state.getState();
3698:                state.setReturnState(returnState);
3699:
3700:                state.setState("description");
3701:
3702:                // "crack" the reference (a.k.a dereference, i.e. make a Reference)
3703:                // and get the event id and calendar reference
3704:                Reference ref = EntityManager.newReference(data.getParameters()
3705:                        .getString(EVENT_REFERENCE_PARAMETER));
3706:                String eventId = ref.getId();
3707:                String calId = CalendarService.calendarReference(ref
3708:                        .getContext(), ref.getContainer());
3709:
3710:                state.setAttachments(null);
3711:                state.setCalendarEventId(calId, eventId);
3712:
3713:                // %%% get the event object from the reference new Reference(data.getParameters().getString(EVENT_REFERENCE_PARAMETER)).getResource() -ggolden
3714:                try {
3715:                    calendarObj = CalendarService.getCalendar(calId);
3716:                    try {
3717:                        //calendarObj.getEvent(eventId);
3718:                        calendarEventObj = calendarObj.getEvent(eventId);
3719:
3720:                        TimeBreakdown b = calendarEventObj.getRange()
3721:                                .firstTime().breakdownLocal();
3722:                        //CalendarUtil m_calObj = state.getCalObj();
3723:                        //m_calObj.setDay(b.getYear(), b.getMonth(), b.getDay());
3724:                        //state.setCalObj(m_calObj);
3725:
3726:                        sstate.setAttribute(STATE_YEAR,
3727:                                new Integer(b.getYear()));
3728:                        sstate.setAttribute(STATE_MONTH, new Integer(b
3729:                                .getMonth()));
3730:                        sstate.setAttribute(STATE_DAY, new Integer(b.getDay()));
3731:
3732:                        sstate.setAttribute(STATE_NAV_DIRECTION,
3733:                                STATE_CURRENT_ACT);
3734:
3735:                    } catch (IdUnusedException err) {
3736:                        // if this event doesn't exist, let user not go to the detail view
3737:                        // set the state recorded ID as null
3738:                        // show the alert message
3739:                        M_log.debug(".IdUnusedException " + err);
3740:                        //state.setState("returnState");
3741:                        state.setCalendarEventId("", "");
3742:                        String errorCode = rb.getString("java.error");
3743:                        addAlert(sstate, errorCode);
3744:                    } catch (PermissionException err) {
3745:                        M_log.debug(".PermissionException " + err);
3746:                    }
3747:                } catch (IdUnusedException e) {
3748:                    addAlert(sstate, rb.getString("java.alert.noexist"));
3749:                } catch (PermissionException e) {
3750:                    addAlert(sstate, rb.getString("java.alert.youcreate"));
3751:                }
3752:            } // doDescription
3753:
3754:            /**
3755:             * Action is used when doGomonth requested in the year/list view
3756:             */
3757:            public void doGomonth(RunData data, Context context) {
3758:                CalendarActionState state = (CalendarActionState) getState(
3759:                        context, data, CalendarActionState.class);
3760:                String peid = ((JetspeedRunData) data).getJs_peid();
3761:                SessionState sstate = ((JetspeedRunData) data)
3762:                        .getPortletSessionState(peid);
3763:
3764:                Time m_time = TimeService.newTime();
3765:                TimeBreakdown b = m_time.breakdownLocal();
3766:                int stateYear = b.getYear();
3767:                int stateMonth = b.getMonth();
3768:                int stateDay = b.getDay();
3769:                if ((sstate.getAttribute(STATE_YEAR) != null)
3770:                        && (sstate.getAttribute(STATE_MONTH) != null)
3771:                        && (sstate.getAttribute(STATE_DAY) != null)) {
3772:                    stateYear = ((Integer) sstate.getAttribute(STATE_YEAR))
3773:                            .intValue();
3774:                    stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH))
3775:                            .intValue();
3776:                    stateDay = ((Integer) sstate.getAttribute(STATE_DAY))
3777:                            .intValue();
3778:                }
3779:                CalendarUtil m_calObj = new CalendarUtil();
3780:                m_calObj.setDay(stateYear, stateMonth, stateDay);
3781:
3782:                String month = "";
3783:                month = data.getParameters().getString("month");
3784:                m_calObj.setMonth(Integer.parseInt(month));
3785:
3786:                // if this function is called from list view
3787:                // the value of year must be caught also
3788:                int yearInt = m_calObj.getYear();
3789:
3790:                String currentState = state.getState();
3791:                if (currentState.equalsIgnoreCase("list")) {
3792:                    String year = "";
3793:                    year = data.getParameters().getString("year");
3794:
3795:                    yearInt = Integer.parseInt(year);
3796:                }
3797:
3798:                m_calObj.setDay(yearInt, m_calObj.getMonthInteger(), m_calObj
3799:                        .getDayOfMonth());
3800:
3801:                sstate.setAttribute(STATE_YEAR, new Integer(yearInt));
3802:                sstate.setAttribute(STATE_MONTH, new Integer(m_calObj
3803:                        .getMonthInteger()));
3804:                sstate.setAttribute(STATE_DAY, new Integer(m_calObj
3805:                        .getDayOfMonth()));
3806:
3807:                state.setState("month");
3808:
3809:            } // doGomonth
3810:
3811:            /**
3812:             * Action is used when doGoyear requested in the list view
3813:             */
3814:            public void doGoyear(RunData data, Context context) {
3815:                CalendarActionState state = (CalendarActionState) getState(
3816:                        context, data, CalendarActionState.class);
3817:                String peid = ((JetspeedRunData) data).getJs_peid();
3818:                SessionState sstate = ((JetspeedRunData) data)
3819:                        .getPortletSessionState(peid);
3820:
3821:                Time m_time = TimeService.newTime();
3822:                TimeBreakdown b = m_time.breakdownLocal();
3823:                int stateYear = b.getYear();
3824:                int stateMonth = b.getMonth();
3825:                int stateDay = b.getDay();
3826:                if ((sstate.getAttribute(STATE_YEAR) != null)
3827:                        && (sstate.getAttribute(STATE_MONTH) != null)
3828:                        && (sstate.getAttribute(STATE_DAY) != null)) {
3829:                    stateYear = ((Integer) sstate.getAttribute(STATE_YEAR))
3830:                            .intValue();
3831:                    stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH))
3832:                            .intValue();
3833:                    stateDay = ((Integer) sstate.getAttribute(STATE_DAY))
3834:                            .intValue();
3835:                }
3836:                CalendarUtil m_calObj = new CalendarUtil();
3837:                CalendarUtil calObj = new CalendarUtil();
3838:
3839:                calObj.setDay(stateYear, stateMonth, stateDay);
3840:                m_calObj.setDay(stateYear, stateMonth, stateDay);
3841:
3842:                // catch the year value from the list view
3843:                int yearInt = m_calObj.getYear();
3844:                String currentState = state.getState();
3845:                if (currentState.equalsIgnoreCase("list")) {
3846:                    String year = "";
3847:                    year = data.getParameters().getString("year");
3848:
3849:                    yearInt = Integer.parseInt(year);
3850:                }
3851:
3852:                m_calObj.setDay(yearInt, m_calObj.getMonthInteger(), m_calObj
3853:                        .getDayOfMonth());
3854:
3855:                //state.setCalObj(m_calObj);
3856:                sstate.setAttribute(STATE_YEAR, new Integer(yearInt));
3857:                sstate.setAttribute(STATE_MONTH, new Integer(m_calObj
3858:                        .getMonthInteger()));
3859:                sstate.setAttribute(STATE_DAY, new Integer(m_calObj
3860:                        .getDayOfMonth()));
3861:
3862:                state.setState("year");
3863:
3864:            } // doGoyear
3865:
3866:            /**
3867:             * Action is used when doOk is requested when user click on Back button
3868:             */
3869:            public void doOk(RunData data, Context context) {
3870:                CalendarActionState state = (CalendarActionState) getState(
3871:                        context, data, CalendarActionState.class);
3872:                String peid = ((JetspeedRunData) data).getJs_peid();
3873:                SessionState sstate = ((JetspeedRunData) data)
3874:                        .getPortletSessionState(peid);
3875:
3876:                // return to the state coming from
3877:                String returnState = state.getReturnState();
3878:                state.setState(returnState);
3879:            }
3880:
3881:            /**
3882:             * Action is used when the user click on the doRevise in the menu
3883:             */
3884:            public void doRevise(RunData data, Context context) {
3885:                CalendarEvent calendarEventObj = null;
3886:                Calendar calendarObj = null;
3887:
3888:                CalendarActionState state = (CalendarActionState) getState(
3889:                        context, data, CalendarActionState.class);
3890:                String peid = ((JetspeedRunData) data).getJs_peid();
3891:                SessionState sstate = ((JetspeedRunData) data)
3892:                        .getPortletSessionState(peid);
3893:
3894:                String calId = state.getPrimaryCalendarReference();
3895:                state.setPrevState(state.getState());
3896:                state.setState("goToReviseCalendar");
3897:                state.setIsNewCalendar(false);
3898:                state.setfromAttachmentFlag("false");
3899:                sstate.setAttribute(FREQUENCY_SELECT, null);
3900:                sstate
3901:                        .setAttribute(CalendarAction.SSTATE__RECURRING_RULE,
3902:                                null);
3903:
3904:                state.clearData();
3905:
3906:                try {
3907:                    calendarObj = CalendarService.getCalendar(calId);
3908:                    try {
3909:                        String eventId = state.getCalendarEventId();
3910:                        // get the edit object, and lock the event for the furthur revise
3911:                        CalendarEventEdit edit = calendarObj
3912:                                .getEditEvent(
3913:                                        eventId,
3914:                                        org.sakaiproject.calendar.api.CalendarService.EVENT_MODIFY_CALENDAR);
3915:                        state.setEdit(edit);
3916:                        state.setPrimaryCalendarEdit(edit);
3917:                        calendarEventObj = calendarObj.getEvent(eventId);
3918:                        state.setAttachments(calendarEventObj.getAttachments());
3919:                    } catch (IdUnusedException err) {
3920:                        // if this event doesn't exist, let user stay in activity view
3921:                        // set the state recorded ID as null
3922:                        // show the alert message
3923:                        // reset the menu button display, no revise/delete
3924:                        M_log.debug(".IdUnusedException " + err);
3925:                        state.setState("description");
3926:                        state.setCalendarEventId("", "");
3927:                        String errorCode = rb.getString("java.alert.event");
3928:                        addAlert(sstate, errorCode);
3929:                    } catch (PermissionException err) {
3930:                        M_log.debug(".PermissionException " + err);
3931:                    } catch (InUseException err) {
3932:                        M_log.debug(".InUseException " + err);
3933:                        state.setState("description");
3934:                        String errorCode = rb
3935:                                .getString("java.alert.eventbeing");
3936:                        addAlert(sstate, errorCode);
3937:                    }
3938:                } catch (IdUnusedException e) {
3939:                    addAlert(sstate, rb.getString("java.alert.noexist"));
3940:                } catch (PermissionException e) {
3941:                    addAlert(sstate, rb.getString("java.alert.youcreate"));
3942:                }
3943:
3944:            } // doRevise
3945:
3946:            /**
3947:             * Handle the "continue" button on the schedule import wizard.
3948:             */
3949:            public void doScheduleContinue(RunData data, Context context) {
3950:                CalendarActionState state = (CalendarActionState) getState(
3951:                        context, data, CalendarActionState.class);
3952:                String peid = ((JetspeedRunData) data).getJs_peid();
3953:                SessionState sstate = ((JetspeedRunData) data)
3954:                        .getPortletSessionState(peid);
3955:
3956:                if (SELECT_TYPE_IMPORT_WIZARD_STATE.equals(state
3957:                        .getImportWizardState())) {
3958:                    // If the type is Outlook or MeetingMaker, the next state is
3959:                    // the "other" file select mode where we just select a file without
3960:                    // all of the extra info on the generic import page.
3961:
3962:                    String importType = data.getParameters().getString(
3963:                            WIZARD_IMPORT_TYPE);
3964:
3965:                    if (CalendarImporterService.OUTLOOK_IMPORT
3966:                            .equals(importType)
3967:                            || CalendarImporterService.MEETINGMAKER_IMPORT
3968:                                    .equals(importType)) {
3969:                        if (CalendarImporterService.OUTLOOK_IMPORT
3970:                                .equals(importType)) {
3971:                            state
3972:                                    .setImportWizardType(CalendarImporterService.OUTLOOK_IMPORT);
3973:                        } else {
3974:                            state
3975:                                    .setImportWizardType(CalendarImporterService.MEETINGMAKER_IMPORT);
3976:                        }
3977:
3978:                        state
3979:                                .setImportWizardState(OTHER_SELECT_FILE_IMPORT_WIZARD_STATE);
3980:                    } else {
3981:                        // Remember the type we're importing
3982:                        state
3983:                                .setImportWizardType(CalendarImporterService.CSV_IMPORT);
3984:
3985:                        state
3986:                                .setImportWizardState(GENERIC_SELECT_FILE_IMPORT_WIZARD_STATE);
3987:                    }
3988:                } else if (GENERIC_SELECT_FILE_IMPORT_WIZARD_STATE.equals(state
3989:                        .getImportWizardState())) {
3990:                    boolean importSucceeded = false;
3991:
3992:                    // Do the import and send us to the confirm page
3993:                    FileItem importFile = data.getParameters().getFileItem(
3994:                            WIZARD_IMPORT_FILE);
3995:
3996:                    try {
3997:                        Map columnMap = CalendarImporterService
3998:                                .getDefaultColumnMap(CalendarImporterService.CSV_IMPORT);
3999:
4000:                        String[] addFieldsCalendarArray = getCustomFieldsArray(
4001:                                state, sstate);
4002:
4003:                        if (addFieldsCalendarArray != null) {
4004:                            // Add all custom columns.  Assume that there will be no 
4005:                            // name collisions. (Maybe a marginal assumption.)
4006:                            for (int i = 0; i < addFieldsCalendarArray.length; i++) {
4007:                                columnMap.put(addFieldsCalendarArray[i],
4008:                                        addFieldsCalendarArray[i]);
4009:                            }
4010:                        }
4011:
4012:                        state.setWizardImportedEvents(CalendarImporterService
4013:                                .doImport(CalendarImporterService.CSV_IMPORT,
4014:                                        new ByteArrayInputStream(importFile
4015:                                                .get()), columnMap,
4016:                                        addFieldsCalendarArray));
4017:
4018:                        importSucceeded = true;
4019:                    } catch (ImportException e) {
4020:                        addAlert(sstate, e.getMessage());
4021:                    }
4022:
4023:                    if (importSucceeded) {
4024:                        // If all is well, go on to the confirmation page. 
4025:                        state.setImportWizardState(CONFIRM_IMPORT_WIZARD_STATE);
4026:                    } else {
4027:                        // If there are errors, send us back to the file selection page.
4028:                        state
4029:                                .setImportWizardState(GENERIC_SELECT_FILE_IMPORT_WIZARD_STATE);
4030:                    }
4031:                } else if (OTHER_SELECT_FILE_IMPORT_WIZARD_STATE.equals(state
4032:                        .getImportWizardState())) {
4033:                    boolean importSucceeded = false;
4034:
4035:                    // Do the import and send us to the confirm page
4036:                    FileItem importFile = data.getParameters().getFileItem(
4037:                            WIZARD_IMPORT_FILE);
4038:
4039:                    String[] addFieldsCalendarArray = getCustomFieldsArray(
4040:                            state, sstate);
4041:
4042:                    try {
4043:                        state.setWizardImportedEvents(CalendarImporterService
4044:                                .doImport(state.getImportWizardType(),
4045:                                        new ByteArrayInputStream(importFile
4046:                                                .get()), null,
4047:                                        addFieldsCalendarArray));
4048:
4049:                        importSucceeded = true;
4050:                    } catch (ImportException e) {
4051:                        addAlert(sstate, e.getMessage());
4052:                    }
4053:
4054:                    if (importSucceeded) {
4055:                        // If all is well, go on to the confirmation page. 
4056:                        state.setImportWizardState(CONFIRM_IMPORT_WIZARD_STATE);
4057:                    } else {
4058:                        // If there are errors, send us back to the file selection page.
4059:                        state
4060:                                .setImportWizardState(OTHER_SELECT_FILE_IMPORT_WIZARD_STATE);
4061:                    }
4062:                } else if (CONFIRM_IMPORT_WIZARD_STATE.equals(state
4063:                        .getImportWizardState())) {
4064:                    // If there are errors, send us back to Either
4065:                    // the OTHER_SELECT_FILE or GENERIC_SELECT_FILE states.
4066:                    // Otherwise, we're done.
4067:
4068:                    List wizardCandidateEventList = state
4069:                            .getWizardImportedEvents();
4070:
4071:                    // for group awareness - read user selection
4072:                    readEventGroupForm(data, context);
4073:
4074:                    String scheduleTo = (String) sstate
4075:                            .getAttribute(STATE_SCHEDULE_TO);
4076:                    Collection groupChoice = (Collection) sstate
4077:                            .getAttribute(STATE_SCHEDULE_TO_GROUPS);
4078:
4079:                    if (scheduleTo.equals("site")
4080:                            || (scheduleTo.equals("groups") && ((groupChoice != null) || (groupChoice
4081:                                    .size() > 0)))) {
4082:                        for (int i = 0; i < wizardCandidateEventList.size(); i++) {
4083:                            // The line numbers are one-based.
4084:                            String selectionName = "eventSelected" + (i + 1);
4085:                            String selectdValue = data.getParameters()
4086:                                    .getString(selectionName);
4087:
4088:                            if (TRUE_STRING.equals(selectdValue)) {
4089:                                // Add the events
4090:                                String calId = state
4091:                                        .getPrimaryCalendarReference();
4092:                                try {
4093:                                    Calendar calendarObj = CalendarService
4094:                                            .getCalendar(calId);
4095:                                    CalendarEvent event = (CalendarEvent) wizardCandidateEventList
4096:                                            .get(i);
4097:
4098:                                    CalendarEventEdit newEvent = calendarObj
4099:                                            .addEvent();
4100:                                    state.setEdit(newEvent);
4101:
4102:                                    if (event.getDescriptionFormatted() != null) {
4103:                                        newEvent.setDescriptionFormatted(event
4104:                                                .getDescriptionFormatted());
4105:                                    }
4106:
4107:                                    // Range must be present at this point, so don't check for null.
4108:                                    newEvent.setRange(event.getRange());
4109:
4110:                                    if (event.getDisplayName() != null) {
4111:                                        newEvent.setDisplayName(event
4112:                                                .getDisplayName());
4113:                                    }
4114:
4115:                                    // The type must have either been set or defaulted by this point.
4116:                                    newEvent.setType(event.getType());
4117:
4118:                                    if (event.getLocation() != null) {
4119:                                        newEvent.setLocation(event
4120:                                                .getLocation());
4121:                                    }
4122:
4123:                                    if (event.getRecurrenceRule() != null) {
4124:                                        newEvent.setRecurrenceRule(event
4125:                                                .getRecurrenceRule());
4126:                                    }
4127:
4128:                                    String[] customFields = getCustomFieldsArray(
4129:                                            state, sstate);
4130:
4131:                                    // Set the creator
4132:                                    newEvent.setCreator();
4133:
4134:                                    // Copy any custom fields.
4135:                                    if (customFields != null) {
4136:                                        for (int j = 0; j < customFields.length; j++) {
4137:                                            newEvent
4138:                                                    .setField(
4139:                                                            customFields[j],
4140:                                                            event
4141:                                                                    .getField(customFields[j]));
4142:                                        }
4143:                                    }
4144:
4145:                                    // group awareness
4146:                                    try {
4147:                                        // for site event
4148:                                        if (scheduleTo.equals("site")) {
4149:                                            newEvent.clearGroupAccess();
4150:                                        }
4151:
4152:                                        // for grouped event
4153:                                        else if (scheduleTo.equals("groups")) {
4154:                                            Site site = SiteService
4155:                                                    .getSite(calendarObj
4156:                                                            .getContext());
4157:
4158:                                            // make a collection of Group objects from the collection of group ref strings
4159:                                            Collection groups = new Vector();
4160:                                            for (Iterator iGroups = groupChoice
4161:                                                    .iterator(); iGroups
4162:                                                    .hasNext();) {
4163:                                                String groupRef = (String) iGroups
4164:                                                        .next();
4165:                                                groups.add(site
4166:                                                        .getGroup(groupRef));
4167:                                            }
4168:
4169:                                            newEvent.setGroupAccess(groups,
4170:                                                    true);
4171:                                        }
4172:                                    } catch (Exception e) {
4173:                                        M_log.warn("doScheduleContinue: " + e);
4174:                                    }
4175:
4176:                                    calendarObj.commitEvent(newEvent);
4177:                                    state.setEdit(null);
4178:                                } catch (IdUnusedException e) {
4179:                                    addAlert(sstate, e.getMessage());
4180:                                    M_log.debug(".doScheduleContinue(): " + e);
4181:                                    break;
4182:                                } catch (PermissionException e) {
4183:                                    addAlert(sstate, e.getMessage());
4184:                                    M_log.debug(".doScheduleContinue(): " + e);
4185:                                    break;
4186:                                }
4187:                            }
4188:                        }
4189:
4190:                        // Cancel wizard mode.
4191:                        doCancelImportWizard(data, context);
4192:                    } else {
4193:                        addAlert(sstate, rb
4194:                                .getString("java.alert.youchoosegroup "));
4195:                    }
4196:                }
4197:
4198:            }
4199:
4200:            /**
4201:             * Get an array of custom field names (if any)
4202:             */
4203:            private String[] getCustomFieldsArray(CalendarActionState state,
4204:                    SessionState sstate) {
4205:                Calendar calendarObj = null;
4206:
4207:                try {
4208:                    calendarObj = CalendarService.getCalendar(state
4209:                            .getPrimaryCalendarReference());
4210:                } catch (IdUnusedException e1) {
4211:                    // Ignore
4212:                } catch (PermissionException e) {
4213:                    addAlert(sstate, e.getMessage());
4214:                }
4215:
4216:                // Get a current list of add fields.  This is a comma-delimited string.
4217:                String[] addFieldsCalendarArray = null;
4218:
4219:                if (calendarObj != null) {
4220:                    String addfieldsCalendars = calendarObj.getEventFields();
4221:                    if (addfieldsCalendars != null) {
4222:                        addFieldsCalendarArray = fieldStringToArray(
4223:                                addfieldsCalendars, ADDFIELDS_DELIMITER);
4224:                    }
4225:                }
4226:                return addFieldsCalendarArray;
4227:            }
4228:
4229:            /**
4230:             * Handle the back button on the schedule import wizard
4231:             */
4232:            public void doScheduleBack(RunData data, Context context) {
4233:                CalendarActionState state = (CalendarActionState) getState(
4234:                        context, data, CalendarActionState.class);
4235:
4236:                if (GENERIC_SELECT_FILE_IMPORT_WIZARD_STATE.equals(state
4237:                        .getImportWizardState())
4238:                        || OTHER_SELECT_FILE_IMPORT_WIZARD_STATE.equals(state
4239:                                .getImportWizardState())) {
4240:                    state.setImportWizardState(SELECT_TYPE_IMPORT_WIZARD_STATE);
4241:                } else if (CONFIRM_IMPORT_WIZARD_STATE.equals(state
4242:                        .getImportWizardState())) {
4243:                    if (CalendarImporterService.OUTLOOK_IMPORT.equals(state
4244:                            .getImportWizardType())
4245:                            || CalendarImporterService.MEETINGMAKER_IMPORT
4246:                                    .equals(state.getImportWizardType())) {
4247:                        state
4248:                                .setImportWizardState(OTHER_SELECT_FILE_IMPORT_WIZARD_STATE);
4249:                    } else {
4250:                        state
4251:                                .setImportWizardState(GENERIC_SELECT_FILE_IMPORT_WIZARD_STATE);
4252:                    }
4253:                }
4254:            }
4255:
4256:            /**
4257:             * Called when the user cancels the import wizard.
4258:             */
4259:            public void doCancelImportWizard(RunData data, Context context) {
4260:                CalendarActionState state = (CalendarActionState) getState(
4261:                        context, data, CalendarActionState.class);
4262:
4263:                // Get rid of any events
4264:                state.setWizardImportedEvents(null);
4265:
4266:                // Make sure that we start the wizard at the beginning.
4267:                state.setImportWizardState(null);
4268:
4269:                // Return to the previous state.
4270:                state.setState(state.getPrevState());
4271:            }
4272:
4273:            /**
4274:             * Action is used when the docancel is requested when the user click on cancel  in the new view
4275:             */
4276:            public void doCancel(RunData data, Context context) {
4277:                CalendarActionState state = (CalendarActionState) getState(
4278:                        context, data, CalendarActionState.class);
4279:                String peid = ((JetspeedRunData) data).getJs_peid();
4280:                SessionState sstate = ((JetspeedRunData) data)
4281:                        .getPortletSessionState(peid);
4282:
4283:                Calendar calendarObj = null;
4284:                StringBuffer exceptionMessage = new StringBuffer();
4285:                String currentState = state.getState();
4286:                String returnState = state.getReturnState();
4287:
4288:                if (currentState.equals(STATE_NEW)) {
4289:                    // no need to release the lock. 
4290:                    // clear the saved recurring rule and the selected frequency
4291:                    sstate.setAttribute(CalendarAction.SSTATE__RECURRING_RULE,
4292:                            null);
4293:                    sstate.setAttribute(FREQUENCY_SELECT, null);
4294:                } else if (currentState.equals(STATE_CUSTOMIZE_CALENDAR)) {
4295:                    customizeCalendarPage.doCancel(data, context, state,
4296:                            getSessionState(data));
4297:                    returnState = state.getPrevState();
4298:                    if (returnState.endsWith("!!!fromDescription")) {
4299:                        state.setReturnState(returnState.substring(0,
4300:                                returnState.indexOf("!!!fromDescription")));
4301:                        returnState = "description";
4302:                    }
4303:                } else if (currentState.equals(STATE_MERGE_CALENDARS)) {
4304:                    mergedCalendarPage.doCancel(data, context, state,
4305:                            getSessionState(data));
4306:                    //returnState=state.getPrevState();
4307:                    returnState = state.getReturnState();
4308:
4309:                    if (returnState.endsWith("!!!fromDescription")) {
4310:                        state.setReturnState(returnState.substring(0,
4311:                                returnState.indexOf("!!!fromDescription")));
4312:                        returnState = "description";
4313:                    }
4314:                } else // in revise view, state name varies
4315:                if ((currentState.equals("revise"))
4316:                        || (currentState.equals("goToReviseCalendar"))) {
4317:                    String calId = state.getPrimaryCalendarReference();
4318:
4319:                    if (state.getPrimaryCalendarEdit() != null) {
4320:                        try {
4321:                            calendarObj = CalendarService.getCalendar(calId);
4322:
4323:                            // the event is locked, now we need to release the lock
4324:                            calendarObj.cancelEvent(state
4325:                                    .getPrimaryCalendarEdit());
4326:                            state.setPrimaryCalendarEdit(null);
4327:                            state.setEdit(null);
4328:                        } catch (IdUnusedException e) {
4329:                            addAlert(sstate, rb.getString("java.alert.noexist"));
4330:                        } catch (PermissionException e) {
4331:                            addAlert(sstate, rb
4332:                                    .getString("java.alert.youcreate"));
4333:                        }
4334:                    }
4335:                    // clear the saved recurring rule and the selected frequency
4336:                    sstate.setAttribute(CalendarAction.SSTATE__RECURRING_RULE,
4337:                            null);
4338:                    sstate.setAttribute(FREQUENCY_SELECT, null);
4339:                } else if (currentState.equals(STATE_SET_FREQUENCY))// cancel at frequency editing page
4340:                {
4341:                    returnState = (String) sstate
4342:                            .getAttribute(STATE_BEFORE_SET_RECURRENCE);
4343:                }
4344:
4345:                state.setState(returnState);
4346:
4347:                state.setAttachments(null);
4348:            } // doCancel
4349:
4350:            /**
4351:             * Action is used when the doBack is called when the user click on the back on the EventActivity view
4352:             */
4353:            public void doBack(RunData data, Context context) {
4354:                CalendarActionState state = (CalendarActionState) getState(
4355:                        context, data, CalendarActionState.class);
4356:                String peid = ((JetspeedRunData) data).getJs_peid();
4357:                SessionState sstate = ((JetspeedRunData) data)
4358:                        .getPortletSessionState(peid);
4359:
4360:                Calendar calendarObj = null;
4361:                String calId = state.getPrimaryCalendarReference();
4362:                StringBuffer exceptionMessage = new StringBuffer();
4363:
4364:                try {
4365:                    calendarObj = CalendarService.getCalendar(calId);
4366:
4367:                    // the event is locked, now we need to release the lock
4368:                    calendarObj.cancelEvent(state.getPrimaryCalendarEdit());
4369:                    state.setPrimaryCalendarEdit(null);
4370:                    state.setEdit(null);
4371:                } catch (IdUnusedException e) {
4372:                    addAlert(sstate, rb.getString("java.alert.noexist"));
4373:                } catch (PermissionException e) {
4374:                    addAlert(sstate, rb.getString("java.alert.youcreate"));
4375:                }
4376:
4377:                String returnState = state.getReturnState();
4378:                state.setState(returnState);
4379:
4380:            } // doBack
4381:
4382:            /**
4383:             * Action is used when the doDelete is called when the user click on delete in menu
4384:             */
4385:
4386:            public void doDelete(RunData data, Context context) {
4387:                CalendarActionState state = (CalendarActionState) getState(
4388:                        context, data, CalendarActionState.class);
4389:                String peid = ((JetspeedRunData) data).getJs_peid();
4390:                SessionState sstate = ((JetspeedRunData) data)
4391:                        .getPortletSessionState(peid);
4392:
4393:                CalendarEvent calendarEventObj = null;
4394:                Calendar calendarObj = null;
4395:                String calId = state.getPrimaryCalendarReference();
4396:                StringBuffer exceptionMessage = new StringBuffer();
4397:
4398:                try {
4399:                    calendarObj = CalendarService.getCalendar(calId);
4400:
4401:                    try {
4402:                        String eventId = state.getCalendarEventId();
4403:                        // get the edit object, and lock the event for the furthur revise
4404:                        CalendarEventEdit edit = calendarObj
4405:                                .getEditEvent(
4406:                                        eventId,
4407:                                        org.sakaiproject.calendar.api.CalendarService.EVENT_REMOVE_CALENDAR);
4408:                        state.setEdit(edit);
4409:                        state.setPrimaryCalendarEdit(edit);
4410:                        calendarEventObj = calendarObj.getEvent(eventId);
4411:                        state.setAttachments(calendarEventObj.getAttachments());
4412:
4413:                        // after deletion, it needs to go back to previous page
4414:                        // if coming from description, it won't go back to description
4415:                        // but the state one step ealier
4416:                        String returnState = state.getState();
4417:                        if (!returnState.equals("description")) {
4418:                            state.setReturnState(returnState);
4419:                        }
4420:                        state.setState("delete");
4421:                    } catch (IdUnusedException err) {
4422:                        // if this event doesn't exist, let user stay in activity view
4423:                        // set the state recorded ID as null
4424:                        // show the alert message
4425:                        // reset the menu button display, no revise/delete
4426:                        M_log.debug(".IdUnusedException " + err);
4427:                        state.setState("description");
4428:                        state.setCalendarEventId("", "");
4429:                        String errorCode = rb.getString("java.alert.event");
4430:                        addAlert(sstate, errorCode);
4431:                    } catch (PermissionException err) {
4432:                        M_log.debug(".PermissionException " + err);
4433:                    } catch (InUseException err) {
4434:                        M_log.debug(".InUseException delete" + err);
4435:                        state.setState("description");
4436:                        String errorCode = rb
4437:                                .getString("java.alert.eventbeing");
4438:                        addAlert(sstate, errorCode);
4439:                    }
4440:                } catch (IdUnusedException e) {
4441:                    addAlert(sstate, rb.getString("java.alert.noexist"));
4442:                } catch (PermissionException e) {
4443:                    addAlert(sstate, rb.getString("java.alert.youcreate"));
4444:                }
4445:            } // doDelete
4446:
4447:            /**
4448:             * Action is used when the doConfirm is called when the user click on confirm to delete event in the delete view.
4449:             */
4450:
4451:            public void doConfirm(RunData data, Context context) {
4452:                Calendar calendarObj = null;
4453:                CalendarActionState state = (CalendarActionState) getState(
4454:                        context, data, CalendarActionState.class);
4455:                String peid = ((JetspeedRunData) data).getJs_peid();
4456:                SessionState sstate = ((JetspeedRunData) data)
4457:                        .getPortletSessionState(peid);
4458:
4459:                // read the intention field
4460:                String intentionStr = data.getParameters().getString(
4461:                        "intention");
4462:                int intention = CalendarService.MOD_NA;
4463:                if ("t".equals(intentionStr))
4464:                    intention = CalendarService.MOD_THIS;
4465:
4466:                StringBuffer exceptionMessage = new StringBuffer();
4467:
4468:                String calId = state.getPrimaryCalendarReference();
4469:
4470:                try {
4471:                    calendarObj = CalendarService.getCalendar(calId);
4472:                    CalendarEventEdit edit = state.getPrimaryCalendarEdit();
4473:                    calendarObj.removeEvent(edit, intention);
4474:                    state.setPrimaryCalendarEdit(null);
4475:                } catch (IdUnusedException e) {
4476:                    addAlert(sstate, rb.getString("java.alert.noexist"));
4477:                    M_log.debug(".doConfirm(): " + e);
4478:                } catch (PermissionException e) {
4479:                    addAlert(sstate, rb.getString("java.alert.youcreate"));
4480:                    M_log.debug(".doConfirm(): " + e);
4481:                }
4482:
4483:                String returnState = state.getReturnState();
4484:                state.setState(returnState);
4485:
4486:            } // doConfirm
4487:
4488:            public void doView(RunData data, Context context) {
4489:                SessionState state = ((JetspeedRunData) data)
4490:                        .getPortletSessionState(((JetspeedRunData) data)
4491:                                .getJs_peid());
4492:
4493:                String viewMode = data.getParameters().getString("view");
4494:
4495:                if (viewMode.equalsIgnoreCase(rb.getString("java.byday"))) {
4496:                    doMenueday(data, context);
4497:                } else if (viewMode.equalsIgnoreCase(rb
4498:                        .getString("java.byweek"))) {
4499:                    doWeek(data, context);
4500:                } else if (viewMode.equalsIgnoreCase(rb
4501:                        .getString("java.bymonth"))) {
4502:                    doMonth(data, context);
4503:                } else if (viewMode.equalsIgnoreCase(rb
4504:                        .getString("java.byyear"))) {
4505:                    doYear(data, context);
4506:                } else if (viewMode.equalsIgnoreCase(rb
4507:                        .getString("java.listeve"))) {
4508:                    doList(data, context);
4509:                }
4510:                state.setAttribute(STATE_SELECTED_VIEW, viewMode);
4511:
4512:            } // doView
4513:
4514:            /**
4515:             * Action doYear is requested when the user click on Year on menu
4516:             */
4517:
4518:            public void doYear(RunData data, Context context) {
4519:
4520:                CalendarActionState state = (CalendarActionState) getState(
4521:                        context, data, CalendarActionState.class);
4522:                String peid = ((JetspeedRunData) data).getJs_peid();
4523:                SessionState sstate = ((JetspeedRunData) data)
4524:                        .getPortletSessionState(peid);
4525:
4526:                state.setState("year");
4527:            } // doYear
4528:
4529:            /**
4530:             * Action doWeek is requested when the user click on the week item in then menu
4531:             */
4532:
4533:            public void doWeek(RunData data, Context context) {
4534:                CalendarActionState state = (CalendarActionState) getState(
4535:                        context, data, CalendarActionState.class);
4536:                String peid = ((JetspeedRunData) data).getJs_peid();
4537:                SessionState sstate = ((JetspeedRunData) data)
4538:                        .getPortletSessionState(peid);
4539:
4540:                state.setState("week");
4541:            } // doWeek
4542:
4543:            /**
4544:             * Action doDay is requested when the user click on the day item in the menue
4545:             */
4546:
4547:            public void doDay(RunData data, Context context) {
4548:
4549:                String year = null;
4550:                year = data.getParameters().getString("year");
4551:                String month = null;
4552:                month = data.getParameters().getString("month");
4553:                String day = null;
4554:                day = data.getParameters().getString("day");
4555:
4556:                CalendarActionState state = (CalendarActionState) getState(
4557:                        context, data, CalendarActionState.class);
4558:                String peid = ((JetspeedRunData) data).getJs_peid();
4559:                SessionState sstate = ((JetspeedRunData) data)
4560:                        .getPortletSessionState(peid);
4561:
4562:                //CalendarUtil m_calObj = state.getCalObj();
4563:                //m_calObj.setDay(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day));
4564:                //state.setCalObj(m_calObj);
4565:
4566:                sstate.setAttribute(STATE_YEAR, new Integer(Integer
4567:                        .parseInt(year)));
4568:                sstate.setAttribute(STATE_MONTH, new Integer(Integer
4569:                        .parseInt(month)));
4570:                sstate.setAttribute(STATE_DAY, new Integer(Integer
4571:                        .parseInt(day)));
4572:
4573:                state.setPrevState(state.getState()); // remember the coming state from Month, Year or List
4574:                state.setState("day");
4575:            } // doDay
4576:
4577:            /**
4578:             * Action doToday is requested when the user click on "Go to today" button
4579:             */
4580:            public void doToday(RunData data, Context context) {
4581:                CalendarActionState state = (CalendarActionState) getState(
4582:                        context, data, CalendarActionState.class);
4583:                String peid = ((JetspeedRunData) data).getJs_peid();
4584:                SessionState sstate = ((JetspeedRunData) data)
4585:                        .getPortletSessionState(peid);
4586:
4587:                CalendarUtil m_calObj = new CalendarUtil();
4588:
4589:                Time m_time = TimeService.newTime();
4590:                TimeBreakdown b = m_time.breakdownLocal();
4591:                m_calObj.setDay(b.getYear(), b.getMonth(), b.getDay());
4592:
4593:                sstate.setAttribute(STATE_YEAR, new Integer(b.getYear()));
4594:                sstate.setAttribute(STATE_MONTH, new Integer(b.getMonth()));
4595:                sstate.setAttribute(STATE_DAY, new Integer(b.getDay()));
4596:
4597:                state.setState("day");
4598:
4599:                //for dropdown menu display purpose
4600:                sstate.setAttribute(STATE_SELECTED_VIEW, rb
4601:                        .getString("java.byday"));
4602:
4603:            } // doToday
4604:
4605:            /**
4606:             * Action doCustomDate is requested when the user specifies a start/end date
4607:             * to filter the list view.
4608:             */
4609:            public void doCustomdate(RunData data, Context context) {
4610:                CalendarActionState state = (CalendarActionState) getState(
4611:                        context, data, CalendarActionState.class);
4612:                String peid = ((JetspeedRunData) data).getJs_peid();
4613:                SessionState sstate = ((JetspeedRunData) data)
4614:                        .getPortletSessionState(peid);
4615:
4616:                String sY = data.getParameters().getString(
4617:                        TIME_FILTER_SETTING_CUSTOM_START_YEAR);
4618:                String sM = data.getParameters().getString(
4619:                        TIME_FILTER_SETTING_CUSTOM_START_MONTH);
4620:                String sD = data.getParameters().getString(
4621:                        TIME_FILTER_SETTING_CUSTOM_START_DAY);
4622:                String eY = data.getParameters().getString(
4623:                        TIME_FILTER_SETTING_CUSTOM_END_YEAR);
4624:                String eM = data.getParameters().getString(
4625:                        TIME_FILTER_SETTING_CUSTOM_END_MONTH);
4626:                String eD = data.getParameters().getString(
4627:                        TIME_FILTER_SETTING_CUSTOM_END_DAY);
4628:                if (sM.length() == 1)
4629:                    sM = "0" + sM;
4630:                if (eM.length() == 1)
4631:                    eM = "0" + eM;
4632:                if (sD.length() == 1)
4633:                    sD = "0" + sD;
4634:                if (eD.length() == 1)
4635:                    eD = "0" + eD;
4636:                sY = sY.substring(2);
4637:                eY = eY.substring(2);
4638:
4639:                String startingDateStr = sM + "/" + sD + "/" + sY;
4640:                String endingDateStr = eM + "/" + eD + "/" + eY;
4641:
4642:                // Pass in a buffer for a possible error message.
4643:                StringBuffer errorMessage = new StringBuffer();
4644:
4645:                // Try to simultaneously set the start/end dates.
4646:                // If that doesn't work, add an error message.
4647:                if (!state.getCalendarFilter().setStartAndEndListViewDates(
4648:                        startingDateStr, endingDateStr, errorMessage)) {
4649:                    addAlert(sstate, errorMessage.toString());
4650:                }
4651:
4652:            } // doCustomdate
4653:
4654:            /**
4655:             * Action doFilter is requested when the user clicks on the list box
4656:             * to select a filtering mode for the list view.
4657:             */
4658:            public void doFilter(RunData data, Context context) {
4659:                CalendarActionState state = (CalendarActionState) getState(
4660:                        context, data, CalendarActionState.class);
4661:
4662:                state.getCalendarFilter().setListViewFilterMode(
4663:                        data.getParameters().getString(TIME_FILTER_OPTION_VAR));
4664:
4665:            } // doFilter
4666:
4667:            /**
4668:             * Action is requestd when the user select day from the menu avilable in some views.
4669:             */
4670:
4671:            public void doMenueday(RunData data, Context context) {
4672:                CalendarActionState state = (CalendarActionState) getState(
4673:                        context, data, CalendarActionState.class);
4674:                String peid = ((JetspeedRunData) data).getJs_peid();
4675:                SessionState sstate = ((JetspeedRunData) data)
4676:                        .getPortletSessionState(peid);
4677:
4678:                state.setState("day");
4679:            } // doMenueday
4680:
4681:            /**
4682:             * Action is requsted when the user select day from menu in Activityevent view.
4683:             */
4684:
4685:            public void doActivityday(RunData data, Context context) {
4686:
4687:                CalendarEvent ce = null;
4688:                Calendar calendarObj = null;
4689:
4690:                CalendarActionState state = (CalendarActionState) getState(
4691:                        context, data, CalendarActionState.class);
4692:                String peid = ((JetspeedRunData) data).getJs_peid();
4693:                SessionState sstate = ((JetspeedRunData) data)
4694:                        .getPortletSessionState(peid);
4695:
4696:                CalendarUtil m_calObj = new CalendarUtil();
4697:
4698:                StringBuffer exceptionMessage = new StringBuffer();
4699:                String id = state.getCalendarEventId();
4700:
4701:                String calId = state.getPrimaryCalendarReference();
4702:
4703:                try {
4704:                    calendarObj = CalendarService.getCalendar(calId);
4705:                    ce = calendarObj.getEvent(id);
4706:                } catch (IdUnusedException e) {
4707:                    addAlert(sstate, rb.getString("java.alert.noexist"));
4708:                    M_log.debug(".doActivityday(): " + e);
4709:                } catch (PermissionException e) {
4710:                    addAlert(sstate, rb.getString("java.alert.youcreate"));
4711:                    M_log.debug(".doActivityday(): " + e);
4712:                }
4713:
4714:                TimeRange tr = ce.getRange();
4715:                Time t = tr.firstTime();
4716:                TimeBreakdown b = t.breakdownLocal();
4717:                m_calObj.setDay(b.getYear(), b.getMonth(), b.getDay());
4718:
4719:                sstate.setAttribute(STATE_YEAR, new Integer(b.getYear()));
4720:                sstate.setAttribute(STATE_MONTH, new Integer(b.getMonth()));
4721:                sstate.setAttribute(STATE_DAY, new Integer(b.getDay()));
4722:
4723:                state.setState("day");
4724:
4725:            } // doActivityDay
4726:
4727:            /**
4728:             * Action doNext is called when the user click on next button to move to next day, next week, next month or next year.
4729:             */
4730:
4731:            public void doNext(RunData data, Context context) {
4732:                CalendarActionState state = (CalendarActionState) getState(
4733:                        context, data, CalendarActionState.class);
4734:                String peid = ((JetspeedRunData) data).getJs_peid();
4735:                SessionState sstate = ((JetspeedRunData) data)
4736:                        .getPortletSessionState(peid);
4737:
4738:                String currentstate = state.getState();
4739:
4740:                Time m_time = TimeService.newTime();
4741:                TimeBreakdown b = m_time.breakdownLocal();
4742:                int stateYear = b.getYear();
4743:                int stateMonth = b.getMonth();
4744:                int stateDay = b.getDay();
4745:                if ((sstate.getAttribute(STATE_YEAR) != null)
4746:                        && (sstate.getAttribute(STATE_MONTH) != null)
4747:                        && (sstate.getAttribute(STATE_DAY) != null)) {
4748:                    stateYear = ((Integer) sstate.getAttribute(STATE_YEAR))
4749:                            .intValue();
4750:                    stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH))
4751:                            .intValue();
4752:                    stateDay = ((Integer) sstate.getAttribute(STATE_DAY))
4753:                            .intValue();
4754:                }
4755:                CalendarUtil m_calObj = new CalendarUtil();
4756:
4757:                m_calObj.setDay(stateYear, stateMonth, stateDay);
4758:
4759:                if (currentstate.equals("month")) {
4760:                    m_calObj.getNextMonth();
4761:                }
4762:
4763:                if (currentstate.equals("year")) {
4764:                    m_calObj.setNextYear();
4765:                }
4766:
4767:                if (currentstate.equals("day")) {
4768:                    String date = m_calObj.getNextDate();
4769:                    state.setnextDate(date);
4770:                }
4771:
4772:                if (currentstate.equals("week")) {
4773:                    m_calObj.setNextWeek();
4774:                }
4775:
4776:                sstate
4777:                        .setAttribute(STATE_YEAR, new Integer(m_calObj
4778:                                .getYear()));
4779:                sstate.setAttribute(STATE_MONTH, new Integer(m_calObj
4780:                        .getMonthInteger()));
4781:                sstate.setAttribute(STATE_DAY, new Integer(m_calObj
4782:                        .getDayOfMonth()));
4783:
4784:            } // doNext
4785:
4786:            /**
4787:             * Action doNextday is called when the user click on "Tomorrow" link in day view
4788:             */
4789:
4790:            public void doNextday(RunData data, Context context) {
4791:                CalendarActionState state = (CalendarActionState) getState(
4792:                        context, data, CalendarActionState.class);
4793:                String peid = ((JetspeedRunData) data).getJs_peid();
4794:                SessionState sstate = ((JetspeedRunData) data)
4795:                        .getPortletSessionState(peid);
4796:
4797:                String currentstate = state.getState();
4798:
4799:                Time m_time = TimeService.newTime();
4800:                TimeBreakdown b = m_time.breakdownLocal();
4801:                int stateYear = b.getYear();
4802:                int stateMonth = b.getMonth();
4803:                int stateDay = b.getDay();
4804:                if ((sstate.getAttribute(STATE_YEAR) != null)
4805:                        && (sstate.getAttribute(STATE_MONTH) != null)
4806:                        && (sstate.getAttribute(STATE_DAY) != null)) {
4807:                    stateYear = ((Integer) sstate.getAttribute(STATE_YEAR))
4808:                            .intValue();
4809:                    stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH))
4810:                            .intValue();
4811:                    stateDay = ((Integer) sstate.getAttribute(STATE_DAY))
4812:                            .intValue();
4813:                }
4814:                CalendarUtil m_calObj = new CalendarUtil(); //null;
4815:                m_calObj.setDay(stateYear, stateMonth, stateDay);
4816:
4817:                if (currentstate.equals("day")) {
4818:                    String date = m_calObj.getNextDate();
4819:                    state.setnextDate(date);
4820:
4821:                    sstate.setAttribute(STATE_YEAR, new Integer(m_calObj
4822:                            .getYear()));
4823:                    sstate.setAttribute(STATE_MONTH, new Integer(m_calObj
4824:                            .getMonthInteger()));
4825:                    sstate.setAttribute(STATE_DAY, new Integer(m_calObj
4826:                            .getDayOfMonth()));
4827:
4828:                    // if this function is called thru "tomorrow" link
4829:                    // the default page has to be changed to "first"
4830:                    state.setCurrentPage("first");
4831:                }
4832:            } // doNextday
4833:
4834:            /**
4835:             * Action doPrev is requested when the user click on the prev button to move into pre day, month, year, or week.
4836:             */
4837:
4838:            public void doPrev(RunData data, Context context) {
4839:                CalendarActionState state = (CalendarActionState) getState(
4840:                        context, data, CalendarActionState.class);
4841:                String peid = ((JetspeedRunData) data).getJs_peid();
4842:                SessionState sstate = ((JetspeedRunData) data)
4843:                        .getPortletSessionState(peid);
4844:
4845:                Time m_time = TimeService.newTime();
4846:                TimeBreakdown b = m_time.breakdownLocal();
4847:                int stateYear = b.getYear();
4848:                int stateMonth = b.getMonth();
4849:                int stateDay = b.getDay();
4850:                if ((sstate.getAttribute(STATE_YEAR) != null)
4851:                        && (sstate.getAttribute(STATE_MONTH) != null)
4852:                        && (sstate.getAttribute(STATE_DAY) != null)) {
4853:                    stateYear = ((Integer) sstate.getAttribute(STATE_YEAR))
4854:                            .intValue();
4855:                    stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH))
4856:                            .intValue();
4857:                    stateDay = ((Integer) sstate.getAttribute(STATE_DAY))
4858:                            .intValue();
4859:                }
4860:                CalendarUtil m_calObj = new CalendarUtil();
4861:                m_calObj.setDay(stateYear, stateMonth, stateDay);
4862:
4863:                String currentstate = state.getState();
4864:
4865:                if (currentstate.equals("month")) {
4866:                    m_calObj.getPrevMonth();
4867:                    //state.setCalObj(m_calObj);
4868:                }
4869:
4870:                if (currentstate.equals("year")) {
4871:                    m_calObj.setPrevYear();
4872:                    //state.setCalObj(m_calObj);
4873:                }
4874:
4875:                if (currentstate.equals("day")) {
4876:                    String date = m_calObj.getPrevDate();
4877:                    //state.setCalObj(m_calObj);
4878:                    state.setprevDate(date);
4879:                }
4880:
4881:                if (currentstate.equals("week")) {
4882:                    m_calObj.setPrevWeek();
4883:                    //state.setCalObj(m_calObj);
4884:                }
4885:                sstate
4886:                        .setAttribute(STATE_YEAR, new Integer(m_calObj
4887:                                .getYear()));
4888:                sstate.setAttribute(STATE_MONTH, new Integer(m_calObj
4889:                        .getMonthInteger()));
4890:                sstate.setAttribute(STATE_DAY, new Integer(m_calObj
4891:                        .getDayOfMonth()));
4892:
4893:            } // doPrev
4894:
4895:            /**
4896:             * Action doPreday is called when the user click on "Yesterday" link in day view
4897:             */
4898:
4899:            public void doPreday(RunData data, Context context) {
4900:                CalendarActionState state = (CalendarActionState) getState(
4901:                        context, data, CalendarActionState.class);
4902:                String peid = ((JetspeedRunData) data).getJs_peid();
4903:                SessionState sstate = ((JetspeedRunData) data)
4904:                        .getPortletSessionState(peid);
4905:
4906:                String currentstate = state.getState();
4907:
4908:                Time m_time = TimeService.newTime();
4909:                TimeBreakdown b = m_time.breakdownLocal();
4910:                int stateYear = b.getYear();
4911:                int stateMonth = b.getMonth();
4912:                int stateDay = b.getDay();
4913:                if ((sstate.getAttribute(STATE_YEAR) != null)
4914:                        && (sstate.getAttribute(STATE_MONTH) != null)
4915:                        && (sstate.getAttribute(STATE_DAY) != null)) {
4916:                    stateYear = ((Integer) sstate.getAttribute(STATE_YEAR))
4917:                            .intValue();
4918:                    stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH))
4919:                            .intValue();
4920:                    stateDay = ((Integer) sstate.getAttribute(STATE_DAY))
4921:                            .intValue();
4922:                }
4923:                CalendarUtil m_calObj = new CalendarUtil(); //null;
4924:                m_calObj.setDay(stateYear, stateMonth, stateDay);
4925:
4926:                if (currentstate.equals("day")) {
4927:                    String date = m_calObj.getPrevDate();
4928:                    //state.setCalObj(m_calObj);
4929:
4930:                    sstate.setAttribute(STATE_YEAR, new Integer(m_calObj
4931:                            .getYear()));
4932:                    sstate.setAttribute(STATE_MONTH, new Integer(m_calObj
4933:                            .getMonthInteger()));
4934:                    sstate.setAttribute(STATE_DAY, new Integer(m_calObj
4935:                            .getDayOfMonth()));
4936:
4937:                    state.setprevDate(date);
4938:
4939:                    // if this function is called thru "Yesterday" link, it goes the last page of yesterday
4940:                    // the default page has to be changed to "third"
4941:                    state.setCurrentPage("third");
4942:                }
4943:            } // doPreday
4944:
4945:            /**
4946:             * Enter the schedule import wizard
4947:             */
4948:            public void doImport(RunData data, Context context) {
4949:                CalendarActionState state = (CalendarActionState) getState(
4950:                        context, data, CalendarActionState.class);
4951:                String peid = ((JetspeedRunData) data).getJs_peid();
4952:                SessionState sstate = ((JetspeedRunData) data)
4953:                        .getPortletSessionState(peid);
4954:
4955:                sstate.removeAttribute(STATE_SCHEDULE_TO);
4956:                sstate.removeAttribute(STATE_SCHEDULE_TO_GROUPS);
4957:
4958:                // Remember the state prior to entering the wizard.
4959:                state.setPrevState(state.getState());
4960:
4961:                // Enter wizard mode.
4962:                state.setState(STATE_SCHEDULE_IMPORT);
4963:
4964:            } // doImport
4965:
4966:            /**
4967:             * Action doNew is requested when the user click on New in the menu
4968:             */
4969:
4970:            public void doNew(RunData data, Context context) {
4971:                CalendarActionState state = (CalendarActionState) getState(
4972:                        context, data, CalendarActionState.class);
4973:                String peid = ((JetspeedRunData) data).getJs_peid();
4974:                SessionState sstate = ((JetspeedRunData) data)
4975:                        .getPortletSessionState(peid);
4976:
4977:                //clean group awareness state info
4978:                sstate.removeAttribute(STATE_SCHEDULE_TO);
4979:                sstate.removeAttribute(STATE_SCHEDULE_TO_GROUPS);
4980:
4981:                // store the state coming from
4982:                String returnState = state.getState();
4983:                if (returnState.equals("description")) {
4984:                } else {
4985:                    state.setReturnState(returnState);
4986:                }
4987:
4988:                state.clearData();
4989:                state.setAttachments(null);
4990:                state.setPrevState(state.getState());
4991:                state.setState("new");
4992:                state.setCalendarEventId("", "");
4993:                state.setIsNewCalendar(true);
4994:                state.setIsPastAlertOff(true);
4995:                sstate.setAttribute(FREQUENCY_SELECT, null);
4996:                sstate
4997:                        .setAttribute(CalendarAction.SSTATE__RECURRING_RULE,
4998:                                null);
4999:
5000:            } // doNew
5001:
5002:            /**
5003:             * Read user inputs in announcement form
5004:             * @param data
5005:             * @param checkForm need to check form data or not
5006:             */
5007:            protected void readEventGroupForm(RunData rundata, Context context) {
5008:                String peid = ((JetspeedRunData) rundata).getJs_peid();
5009:                SessionState state = ((JetspeedRunData) rundata)
5010:                        .getPortletSessionState(peid);
5011:
5012:                String scheduleTo = rundata.getParameters().getString(
5013:                        "scheduleTo");
5014:                state.setAttribute(STATE_SCHEDULE_TO, scheduleTo);
5015:                if (scheduleTo.equals("groups")) {
5016:                    String[] groupChoice = rundata.getParameters().getStrings(
5017:                            "selectedGroups");
5018:                    if (groupChoice != null) {
5019:                        state.setAttribute(STATE_SCHEDULE_TO_GROUPS,
5020:                                new ArrayList(Arrays.asList(groupChoice)));
5021:                    }
5022:
5023:                    if (groupChoice == null || groupChoice.length == 0) {
5024:                        state.removeAttribute(STATE_SCHEDULE_TO_GROUPS);
5025:                    }
5026:                } else {
5027:                    state.removeAttribute(STATE_SCHEDULE_TO_GROUPS);
5028:                }
5029:
5030:            } // readEventGroupForm
5031:
5032:            /**
5033:             * Action doAdd is requested when the user click on the add in the new view to add an event into a calendar.
5034:             */
5035:
5036:            public void doAdd(RunData runData, Context context) {
5037:                CalendarUtil m_calObj = new CalendarUtil();// null;
5038:                Calendar calendarObj = null;
5039:                int houri;
5040:
5041:                CalendarActionState state = (CalendarActionState) getState(
5042:                        context, runData, CalendarActionState.class);
5043:                String peid = ((JetspeedRunData) runData).getJs_peid();
5044:                SessionState sstate = ((JetspeedRunData) runData)
5045:                        .getPortletSessionState(peid);
5046:
5047:                StringBuffer exceptionMessage = new StringBuffer();
5048:
5049:                Time m_time = TimeService.newTime();
5050:                TimeBreakdown b = m_time.breakdownLocal();
5051:                int stateYear = b.getYear();
5052:                int stateMonth = b.getMonth();
5053:                int stateDay = b.getDay();
5054:                if ((sstate.getAttribute(STATE_YEAR) != null)
5055:                        && (sstate.getAttribute(STATE_MONTH) != null)
5056:                        && (sstate.getAttribute(STATE_DAY) != null)) {
5057:                    stateYear = ((Integer) sstate.getAttribute(STATE_YEAR))
5058:                            .intValue();
5059:                    stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH))
5060:                            .intValue();
5061:                    stateDay = ((Integer) sstate.getAttribute(STATE_DAY))
5062:                            .intValue();
5063:                }
5064:                m_calObj.setDay(stateYear, stateMonth, stateDay);
5065:
5066:                String hour = "";
5067:                hour = runData.getParameters().getString("startHour");
5068:                String title = "";
5069:                title = runData.getParameters().getString("activitytitle");
5070:                String minute = "";
5071:                minute = runData.getParameters().getString("startMinute");
5072:                String dhour = "";
5073:                dhour = runData.getParameters().getString("duHour");
5074:                String dminute = "";
5075:                dminute = runData.getParameters().getString("duMinute");
5076:                String description = "";
5077:                description = runData.getParameters().getString("description");
5078:                description = processFormattedTextFromBrowser(sstate,
5079:                        description);
5080:                String month = "";
5081:                month = runData.getParameters().getString("month");
5082:
5083:                String day = "";
5084:                day = runData.getParameters().getString("day");
5085:                String year = "";
5086:                year = runData.getParameters().getString("yearSelect");
5087:                String timeType = "";
5088:                timeType = runData.getParameters().getString("startAmpm");
5089:                String type = "";
5090:                type = runData.getParameters().getString("eventType");
5091:                String location = "";
5092:                location = runData.getParameters().getString("location");
5093:
5094:                String calId = state.getPrimaryCalendarReference();
5095:                try {
5096:                    calendarObj = CalendarService.getCalendar(calId);
5097:                } catch (IdUnusedException e) {
5098:                    exceptionMessage.append(rb
5099:                            .getString("java.alert.thereisno"));
5100:                    M_log.debug(".doAdd(): " + e);
5101:                } catch (PermissionException e) {
5102:                    exceptionMessage.append(rb.getString("java.alert.youdont"));
5103:                    M_log.debug(".doAdd(): " + e);
5104:                }
5105:
5106:                // for section awareness - read user selection
5107:                readEventGroupForm(runData, context);
5108:
5109:                Map addfieldsMap = new HashMap();
5110:
5111:                // Add any additional fields in the calendar.
5112:                customizeCalendarPage.loadAdditionalFieldsMapFromRunData(
5113:                        runData, addfieldsMap, calendarObj);
5114:
5115:                if (timeType.equals("pm")) {
5116:                    if (Integer.parseInt(hour) > 11)
5117:                        houri = Integer.parseInt(hour);
5118:                    else
5119:                        houri = Integer.parseInt(hour) + 12;
5120:                } else if (timeType.equals("am")
5121:                        && Integer.parseInt(hour) == 12) {
5122:                    // set 12 AM as the beginning of one day
5123:                    houri = 0;
5124:                } else {
5125:                    houri = Integer.parseInt(hour);
5126:                }
5127:
5128:                Time now_time = TimeService.newTime();
5129:                Time event_startTime = TimeService.newTimeLocal(Integer
5130:                        .parseInt(year), Integer.parseInt(month), Integer
5131:                        .parseInt(day), houri, Integer.parseInt(minute), 0, 0);
5132:
5133:                // conditions for an new event:
5134:                // 1st, frequency not touched, no save state rule or state freq (0, 0)
5135:                // --> non-recurring, no alert needed (0)
5136:                // 2st, frequency revised, there is a state-saved rule, and state-saved freq exists (1, 1)
5137:                // --> no matter if the start has been modified, compare the ending and starting date, show alert if needed (1)
5138:                // 3th, frequency revised, the state saved rule is null, but state-saved freq exists (0, 1)
5139:                // --> non-recurring, no alert needed (0)
5140:                // so the only possiblityto show the alert is under condistion 2.
5141:
5142:                boolean earlierEnding = false;
5143:
5144:                String freq = "";
5145:                if (((freq = (String) sstate.getAttribute(FREQUENCY_SELECT)) != null)
5146:                        && (!(freq.equals(FREQ_ONCE)))) {
5147:                    RecurrenceRule rule = (RecurrenceRule) sstate
5148:                            .getAttribute(CalendarAction.SSTATE__RECURRING_RULE);
5149:                    if (rule != null) {
5150:                        Time startingTime = TimeService.newTimeLocal(Integer
5151:                                .parseInt(year), Integer.parseInt(month),
5152:                                Integer.parseInt(day), houri, Integer
5153:                                        .parseInt(minute), 00, 000);
5154:
5155:                        Time endingTime = rule.getUntil();
5156:                        if ((endingTime != null)
5157:                                && endingTime.before(startingTime))
5158:                            earlierEnding = true;
5159:                    } // if (rule != null)
5160:                } // if state saved freq is not null, and it not equals "once"
5161:
5162:                String intentionStr = ""; // there is no recurrence modification intention for new event
5163:
5164:                String scheduleTo = (String) sstate
5165:                        .getAttribute(STATE_SCHEDULE_TO);
5166:                Collection groupChoice = (Collection) sstate
5167:                        .getAttribute(STATE_SCHEDULE_TO_GROUPS);
5168:
5169:                if (title.length() == 0) {
5170:                    String errorCode = rb.getString("java.pleasetitle");
5171:                    addAlert(sstate, errorCode);
5172:
5173:                    state.setNewData(state.getPrimaryCalendarReference(),
5174:                            title, description, Integer.parseInt(month),
5175:                            Integer.parseInt(day), year, houri, Integer
5176:                                    .parseInt(minute), Integer.parseInt(dhour),
5177:                            Integer.parseInt(dminute), type, timeType,
5178:                            location, addfieldsMap, intentionStr);
5179:                    state.setState("new");
5180:                } else if (hour.equals("100") || minute.equals("100")) {
5181:                    String errorCode = rb.getString("java.pleasetime");
5182:                    addAlert(sstate, errorCode);
5183:
5184:                    state.setNewData(state.getPrimaryCalendarReference(),
5185:                            title, description, Integer.parseInt(month),
5186:                            Integer.parseInt(day), year, houri, Integer
5187:                                    .parseInt(minute), Integer.parseInt(dhour),
5188:                            Integer.parseInt(dminute), type, timeType,
5189:                            location, addfieldsMap, intentionStr);
5190:                    state.setState("new");
5191:                } else if (earlierEnding) // if ending date is earlier than the starting date, show alert
5192:                {
5193:                    addAlert(sstate, rb.getString("java.theend"));
5194:
5195:                    state.setNewData(calId, title, description, Integer
5196:                            .parseInt(month), Integer.parseInt(day), year,
5197:                            houri, Integer.parseInt(minute), Integer
5198:                                    .parseInt(dhour),
5199:                            Integer.parseInt(dminute), type, timeType,
5200:                            location, addfieldsMap, intentionStr);
5201:                    state.setState("new");
5202:                } else if (event_startTime.before(now_time)
5203:                        && state.getIsPastAlertOff()) {
5204:                    // IsPastAlertOff
5205:                    // true: no alert shown -> then show the alert, set false;
5206:                    // false: Alert shown, if user click ADD - doAdd again -> accept it, set true, set alert empty;
5207:
5208:                    String errorCode = rb.getString("java.alert.past");
5209:                    addAlert(sstate, errorCode);
5210:
5211:                    state.setNewData(state.getPrimaryCalendarReference(),
5212:                            title, description, Integer.parseInt(month),
5213:                            Integer.parseInt(day), year, houri, Integer
5214:                                    .parseInt(minute), Integer.parseInt(dhour),
5215:                            Integer.parseInt(dminute), type, timeType,
5216:                            location, addfieldsMap, intentionStr);
5217:                    state.setState("new");
5218:                    state.setIsPastAlertOff(false);
5219:                } else if (!Validator.checkDate(Integer.parseInt(day), Integer
5220:                        .parseInt(month), Integer.parseInt(year))) {
5221:                    addAlert(sstate, rb.getString("date.invalid"));
5222:                    state.setNewData(state.getPrimaryCalendarReference(),
5223:                            title, description, Integer.parseInt(month),
5224:                            Integer.parseInt(day), year, houri, Integer
5225:                                    .parseInt(minute), Integer.parseInt(dhour),
5226:                            Integer.parseInt(dminute), type, timeType,
5227:                            location, addfieldsMap, intentionStr);
5228:                    state.setState("new");
5229:                } else if (scheduleTo.equals("groups")
5230:                        && ((groupChoice == null) || (groupChoice.size() == 0))) {
5231:                    state.setNewData(state.getPrimaryCalendarReference(),
5232:                            title, description, Integer.parseInt(month),
5233:                            Integer.parseInt(day), year, houri, Integer
5234:                                    .parseInt(minute), Integer.parseInt(dhour),
5235:                            Integer.parseInt(dminute), type, timeType,
5236:                            location, addfieldsMap, intentionStr);
5237:                    state.setState("new");
5238:                    addAlert(sstate, rb.getString("java.alert.youchoosegroup "));
5239:                } else {
5240:                    try {
5241:                        calendarObj = CalendarService.getCalendar(calId);
5242:
5243:                        Time timeObj = TimeService.newTimeLocal(Integer
5244:                                .parseInt(year), Integer.parseInt(month),
5245:                                Integer.parseInt(day), houri, Integer
5246:                                        .parseInt(minute), 00, 000);
5247:
5248:                        long du = (((Integer.parseInt(dhour) * 60) * 60) * 1000)
5249:                                + ((Integer.parseInt(dminute) * 60) * (1000));
5250:                        Time endTime = TimeService.newTime(timeObj.getTime()
5251:                                + du);
5252:                        boolean includeEndTime = false;
5253:                        if (du == 0) {
5254:                            includeEndTime = true;
5255:                        }
5256:                        TimeRange range = TimeService.newTimeRange(timeObj,
5257:                                endTime, true, includeEndTime);
5258:                        //TimeRange range = TimeService.newTimeRange(timeObj.getTime(),du);
5259:                        List attachments = state.getAttachments();
5260:
5261:                        // prepare to create the event
5262:                        Collection groups = new Vector();
5263:                        CalendarEvent.EventAccess access = CalendarEvent.EventAccess.GROUPED;
5264:                        if (scheduleTo.equals("site"))
5265:                            access = CalendarEvent.EventAccess.SITE;
5266:
5267:                        if (access == CalendarEvent.EventAccess.GROUPED) {
5268:                            // make a collection of Group objects from the collection of group ref strings
5269:                            Site site = SiteService.getSite(calendarObj
5270:                                    .getContext());
5271:                            for (Iterator iGroups = groupChoice.iterator(); iGroups
5272:                                    .hasNext();) {
5273:                                String groupRef = (String) iGroups.next();
5274:                                groups.add(site.getGroup(groupRef));
5275:                            }
5276:                        }
5277:
5278:                        // create the event = must create it with grouping / access to start with
5279:                        CalendarEvent event = calendarObj.addEvent(range,
5280:                                title, "", type, location, access, groups,
5281:                                attachments);
5282:
5283:                        // edit it further
5284:                        CalendarEventEdit edit = calendarObj
5285:                                .getEditEvent(
5286:                                        event.getId(),
5287:                                        org.sakaiproject.calendar.api.CalendarService.EVENT_ADD_CALENDAR);
5288:                        edit.setDescriptionFormatted(description);
5289:                        edit.setCreator();
5290:                        setFields(edit, addfieldsMap);
5291:
5292:                        RecurrenceRule rule = (RecurrenceRule) sstate
5293:                                .getAttribute(CalendarAction.SSTATE__RECURRING_RULE);
5294:                        // for a brand new event, there is no saved recurring rule
5295:                        if (rule != null)
5296:                            edit.setRecurrenceRule(rule);
5297:                        else
5298:                            edit.setRecurrenceRule(null);
5299:
5300:                        // save it
5301:                        calendarObj.commitEvent(edit);
5302:                        state.setEdit(null);
5303:
5304:                        state.setIsNewCalendar(false);
5305:
5306:                        m_calObj.setDay(Integer.parseInt(year), Integer
5307:                                .parseInt(month), Integer.parseInt(day));
5308:
5309:                        //state.setCalObj(m_calObj);
5310:                        sstate.setAttribute(STATE_YEAR, new Integer(m_calObj
5311:                                .getYear()));
5312:                        sstate.setAttribute(STATE_MONTH, new Integer(m_calObj
5313:                                .getMonthInteger()));
5314:                        sstate.setAttribute(STATE_DAY, new Integer(m_calObj
5315:                                .getDayOfMonth()));
5316:
5317:                        // clear the saved recurring rule and the selected frequency
5318:                        sstate.setAttribute(
5319:                                CalendarAction.SSTATE__RECURRING_RULE, null);
5320:                        sstate.setAttribute(FREQUENCY_SELECT, null);
5321:
5322:                        // set the return state to be the state before new/revise
5323:                        String returnState = state.getReturnState();
5324:                        if (returnState != null) {
5325:                            state.setState(returnState);
5326:                        } else {
5327:                            state.setState("week");
5328:                        }
5329:
5330:                        // if going back to week/day view, we need to know which slot to go
5331:                        // -- the slot containing the starting time of the new added event
5332:                        if (state.getState().equals("week")
5333:                                || state.getState().equals("day")) {
5334:                            Time timeObj_p1 = TimeService.newTimeLocal(Integer
5335:                                    .parseInt(year), Integer.parseInt(month),
5336:                                    Integer.parseInt(day),
5337:                                    FIRST_PAGE_START_HOUR, 00, 00, 000);
5338:                            Time timeObj_p2 = TimeService.newTimeLocal(Integer
5339:                                    .parseInt(year), Integer.parseInt(month),
5340:                                    Integer.parseInt(day),
5341:                                    SECOND_PAGE_START_HOUR, 00, 00, 000);
5342:                            Time timeObj_p3 = TimeService.newTimeLocal(Integer
5343:                                    .parseInt(year), Integer.parseInt(month),
5344:                                    Integer.parseInt(day),
5345:                                    THIRD_PAGE_START_HOUR, 00, 00, 000);
5346:
5347:                            if (timeObj.after(timeObj_p2)
5348:                                    && timeObj.before(timeObj_p3))
5349:                                state.setCurrentPage("second");
5350:                            else if (timeObj.before(timeObj_p2))
5351:                                state.setCurrentPage("first");
5352:                            else if (timeObj.after(timeObj_p3))
5353:                                state.setCurrentPage("third");
5354:                        }
5355:                    } catch (IdUnusedException e) {
5356:                        addAlert(sstate, rb.getString("java.alert.noexist"));
5357:                        M_log.debug(".doAdd(): " + e);
5358:                    }
5359:
5360:                    catch (PermissionException e) {
5361:                        addAlert(sstate, rb.getString("java.alert.youcreate"));
5362:                        M_log.debug(".doAdd(): " + e);
5363:                    }
5364:
5365:                    catch (InUseException e) {
5366:                        addAlert(sstate, rb.getString("java.alert.noexist"));
5367:                        M_log.debug(".doAdd(): " + e);
5368:                    }
5369:
5370:                } // elseif
5371:            } // doAdd
5372:
5373:            /**
5374:             * Action doUpdateGroupView is requested when the user click on the Update button on the list view.
5375:             */
5376:
5377:            public void doUpdateGroupView(RunData runData, Context context) {
5378:                String peid = ((JetspeedRunData) runData).getJs_peid();
5379:                SessionState sstate = ((JetspeedRunData) runData)
5380:                        .getPortletSessionState(peid);
5381:
5382:                readEventGroupForm(runData, context);
5383:
5384:                //stay at the list view
5385:            }
5386:
5387:            /**
5388:             * Action doUpdate is requested when the user click on the save button on the revise screen.
5389:             */
5390:
5391:            public void doUpdate(RunData runData, Context context) {
5392:                CalendarActionState state = (CalendarActionState) getState(
5393:                        context, runData, CalendarActionState.class);
5394:                String peid = ((JetspeedRunData) runData).getJs_peid();
5395:                SessionState sstate = ((JetspeedRunData) runData)
5396:                        .getPortletSessionState(peid);
5397:
5398:                CalendarUtil m_calObj = new CalendarUtil();
5399:
5400:                // read the intention field
5401:                String intentionStr = runData.getParameters().getString(
5402:                        "intention");
5403:                int intention = CalendarService.MOD_NA;
5404:                if ("t".equals(intentionStr))
5405:                    intention = CalendarService.MOD_THIS;
5406:
5407:                // See if we're in the "options" state.
5408:                if (state.getState().equalsIgnoreCase(STATE_MERGE_CALENDARS)) {
5409:                    mergedCalendarPage.doUpdate(runData, context, state,
5410:                            getSessionState(runData));
5411:
5412:                    // ReturnState was set up above.  Switch states now.
5413:                    String returnState = state.getReturnState();
5414:                    if (returnState.endsWith("!!!fromDescription")) {
5415:                        state.setReturnState(returnState.substring(0,
5416:                                returnState.indexOf("!!!fromDescription")));
5417:                        state.setState("description");
5418:                    } else {
5419:                        state.setReturnState("");
5420:                        state.setState(returnState);
5421:                    }
5422:
5423:                } else if (state.getState().equalsIgnoreCase(
5424:                        STATE_CUSTOMIZE_CALENDAR)) {
5425:                    customizeCalendarPage.doDeletefield(runData, context,
5426:                            state, getSessionState(runData));
5427:                    customizeCalendarPage.doUpdate(runData, context, state,
5428:                            getSessionState(runData));
5429:
5430:                    if (!state.getDelfieldAlertOff()) {
5431:                        state.setState(CalendarAction.STATE_CUSTOMIZE_CALENDAR);
5432:                    } else {
5433:                        // ReturnState was set up above.  Switch states now.
5434:                        String returnState = state.getReturnState();
5435:                        if (returnState.endsWith("!!!fromDescription")) {
5436:                            state.setReturnState(returnState.substring(0,
5437:                                    returnState.indexOf("!!!fromDescription")));
5438:                            state.setState("description");
5439:                        } else {
5440:                            state.setReturnState("");
5441:                            state.setState(returnState);
5442:                        }
5443:                    } // if (!state.getDelfieldAlertOff())
5444:                } else {
5445:                    int houri;
5446:                    Calendar calendarObj = null;
5447:
5448:                    StringBuffer exceptionMessage = new StringBuffer();
5449:
5450:                    String hour = "";
5451:                    hour = runData.getParameters().getString("startHour");
5452:                    String title = "";
5453:                    title = runData.getParameters().getString("activitytitle");
5454:                    String minute = "";
5455:                    minute = runData.getParameters().getString("startMinute");
5456:                    String dhour = "";
5457:                    dhour = runData.getParameters().getString("duHour");
5458:                    String dminute = "";
5459:                    dminute = runData.getParameters().getString("duMinute");
5460:                    String description = "";
5461:                    description = runData.getParameters().getString(
5462:                            "description");
5463:                    description = processFormattedTextFromBrowser(sstate,
5464:                            description);
5465:                    String month = "";
5466:                    month = runData.getParameters().getString("month");
5467:                    String day = "";
5468:                    day = runData.getParameters().getString("day");
5469:                    String year = "";
5470:                    year = runData.getParameters().getString("yearSelect");
5471:                    String timeType = "";
5472:                    timeType = runData.getParameters().getString("startAmpm");
5473:                    String type = "";
5474:                    type = runData.getParameters().getString("eventType");
5475:                    String location = "";
5476:                    location = runData.getParameters().getString("location");
5477:
5478:                    String calId = state.getPrimaryCalendarReference();
5479:                    try {
5480:                        calendarObj = CalendarService.getCalendar(calId);
5481:                    } catch (IdUnusedException e) {
5482:                        exceptionMessage.append(rb
5483:                                .getString("java.alert.theresisno"));
5484:                        M_log.debug(".doUpdate() Other: " + e);
5485:                    } catch (PermissionException e) {
5486:                        exceptionMessage.append(rb
5487:                                .getString("java.alert.youdont"));
5488:                        M_log.debug(".doUpdate() Other: " + e);
5489:                    }
5490:
5491:                    // for group/section awareness
5492:                    readEventGroupForm(runData, context);
5493:
5494:                    String scheduleTo = (String) sstate
5495:                            .getAttribute(STATE_SCHEDULE_TO);
5496:                    Collection groupChoice = (Collection) sstate
5497:                            .getAttribute(STATE_SCHEDULE_TO_GROUPS);
5498:
5499:                    Map addfieldsMap = new HashMap();
5500:
5501:                    // Add any additional fields in the calendar.
5502:                    customizeCalendarPage.loadAdditionalFieldsMapFromRunData(
5503:                            runData, addfieldsMap, calendarObj);
5504:
5505:                    if (timeType.equals("pm")) {
5506:                        if (Integer.parseInt(hour) > 11)
5507:                            houri = Integer.parseInt(hour);
5508:                        else
5509:                            houri = Integer.parseInt(hour) + 12;
5510:                    } else if (timeType.equals("am")
5511:                            && Integer.parseInt(hour) == 12) {
5512:                        houri = 0;
5513:                    } else {
5514:                        houri = Integer.parseInt(hour);
5515:                    }
5516:
5517:                    // conditions for an existing event: (if recurring event, if state-saved-rule exists, if state-saved-freq exists)
5518:                    // 1st, an existing recurring one, just revised without frequency change, no save state rule or state freq (1, 0, 0)
5519:                    // --> the starting time might has been modified, compare the ending and starting date, show alert if needed (1)
5520:                    // 2st, and existing non-recurring one, just revised, no save state rule or state freq (0, 0, 0)
5521:                    // --> non-recurring, no alert needed (0)
5522:                    // 3rd, an existing recurring one, frequency revised, there is a state-saved rule, and state-saved freq exists (1, 1, 1)
5523:                    // --> no matter if the start has been modified, compare the ending and starting date, show alert if needed (1)
5524:                    // 4th, an existing recurring one, changed to non-recurring, the state saved rule is null, but state-saved freq exists (1, 0, 1)
5525:                    // --> non-recurring, no alert needed (0)
5526:                    // 5th, an existing non-recurring one, changed but kept as non-recurring, the state-saved rule is null, but state-saved freq exists (1, 0, 1)
5527:                    // --> non-recurring, no alert needed (0)
5528:                    // 6th, an existing recurring one, changed only the starting time, showed alert for ealier ending time, 
5529:                    // so the only possiblity to show the alert is under condistion 1 & 3: recurring one stays as recurring
5530:
5531:                    boolean earlierEnding = false;
5532:
5533:                    CalendarEventEdit edit = state.getPrimaryCalendarEdit();
5534:                    if (edit != null) {
5535:                        RecurrenceRule editRule = edit.getRecurrenceRule();
5536:                        if (editRule != null) {
5537:                            String freq = (String) sstate
5538:                                    .getAttribute(FREQUENCY_SELECT);
5539:                            RecurrenceRule rule = (RecurrenceRule) sstate
5540:                                    .getAttribute(CalendarAction.SSTATE__RECURRING_RULE);
5541:                            boolean comparisonNeeded = false;
5542:
5543:                            if ((freq == null) && (rule == null)) {
5544:                                // condition 1: recurring without frequency touched, but the starting might change
5545:                                rule = editRule;
5546:                                comparisonNeeded = true;
5547:                            } else if ((freq != null)
5548:                                    && (!(freq.equals(FREQ_ONCE)))) {
5549:                                // condition 3: recurring with frequency changed, and stays at recurring
5550:                                comparisonNeeded = true;
5551:                            }
5552:                            if (comparisonNeeded) // if under condition 1 or 3
5553:                            {
5554:                                if (rule != null) {
5555:                                    Time startingTime = TimeService
5556:                                            .newTimeLocal(Integer
5557:                                                    .parseInt(year), Integer
5558:                                                    .parseInt(month), Integer
5559:                                                    .parseInt(day), houri,
5560:                                                    Integer.parseInt(minute),
5561:                                                    00, 000);
5562:
5563:                                    Time endingTime = rule.getUntil();
5564:                                    if ((endingTime != null)
5565:                                            && endingTime.before(startingTime))
5566:                                        earlierEnding = true;
5567:                                } // if (editRule != null)
5568:                            } // if (comparisonNeeded) // if under condition 1 or 3
5569:                        } // if (calEvent.getRecurrenceRule() != null)
5570:                    } // if (edit != null)
5571:
5572:                    if (title.length() == 0) {
5573:                        String errorCode = rb.getString("java.pleasetitle");
5574:                        addAlert(sstate, errorCode);
5575:
5576:                        state.setNewData(calId, title, description, Integer
5577:                                .parseInt(month), Integer.parseInt(day), year,
5578:                                houri, Integer.parseInt(minute), Integer
5579:                                        .parseInt(dhour), Integer
5580:                                        .parseInt(dminute), type, timeType,
5581:                                location, addfieldsMap, intentionStr);
5582:                        state.setState("revise");
5583:                    }
5584:                    /*
5585:                    else if(hour.equals("0") && minute.equals("0"))
5586:                    {
5587:                    	String errorCode = "Please enter a time";
5588:                    	addAlert(sstate, errorCode);
5589:                    	
5590:                    	state.setNewData(calId, title,description,Integer.parseInt(month),Integer.parseInt(day),year,houri,Integer.parseInt(minute),Integer.parseInt(dhour),Integer.parseInt(dminute),type,timeType,location, addfieldsMap);
5591:                    	state.setState("revise");
5592:                    }
5593:                     */
5594:                    else if (earlierEnding) // if ending date is earlier than the starting date, show alert
5595:                    {
5596:                        addAlert(sstate, rb.getString("java.theend"));
5597:
5598:                        state.setNewData(calId, title, description, Integer
5599:                                .parseInt(month), Integer.parseInt(day), year,
5600:                                houri, Integer.parseInt(minute), Integer
5601:                                        .parseInt(dhour), Integer
5602:                                        .parseInt(dminute), type, timeType,
5603:                                location, addfieldsMap, intentionStr);
5604:                        state.setState("revise");
5605:                    } else if (!Validator.checkDate(Integer.parseInt(day),
5606:                            Integer.parseInt(month), Integer.parseInt(year))) {
5607:                        addAlert(sstate, rb.getString("date.invalid"));
5608:                        state.setNewData(calId, title, description, Integer
5609:                                .parseInt(month), Integer.parseInt(day), year,
5610:                                houri, Integer.parseInt(minute), Integer
5611:                                        .parseInt(dhour), Integer
5612:                                        .parseInt(dminute), type, timeType,
5613:                                location, addfieldsMap, intentionStr);
5614:                        state.setState("revise");
5615:                    } else if (scheduleTo.equals("groups")
5616:                            && ((groupChoice == null) || (groupChoice.size() == 0))) {
5617:                        state.setNewData(state.getPrimaryCalendarReference(),
5618:                                title, description, Integer.parseInt(month),
5619:                                Integer.parseInt(day), year, houri, Integer
5620:                                        .parseInt(minute), Integer
5621:                                        .parseInt(dhour), Integer
5622:                                        .parseInt(dminute), type, timeType,
5623:                                location, addfieldsMap, intentionStr);
5624:                        state.setState("revise");
5625:                        addAlert(sstate, rb
5626:                                .getString("java.alert.youchoosegroup "));
5627:                    } else {
5628:                        try {
5629:                            calendarObj = CalendarService.getCalendar(calId);
5630:                            Time timeObj = TimeService.newTimeLocal(Integer
5631:                                    .parseInt(year), Integer.parseInt(month),
5632:                                    Integer.parseInt(day), houri, Integer
5633:                                            .parseInt(minute), 00, 000);
5634:
5635:                            long du = (((Integer.parseInt(dhour) * 60) * 60) * 1000)
5636:                                    + ((Integer.parseInt(dminute) * 60) * (1000));
5637:                            Time endTime = TimeService.newTime(timeObj
5638:                                    .getTime()
5639:                                    + du);
5640:                            boolean includeEndTime = false;
5641:                            TimeRange range = null;
5642:                            if (du == 0) {
5643:                                range = TimeService.newTimeRange(timeObj);
5644:                            } else {
5645:                                range = TimeService.newTimeRange(timeObj,
5646:                                        endTime, true, includeEndTime);
5647:                            }
5648:                            List attachments = state.getAttachments();
5649:
5650:                            if (edit != null) {
5651:                                edit.setRange(range);
5652:                                edit.setDescriptionFormatted(description);
5653:                                edit.setDisplayName(title);
5654:                                edit.setType(type);
5655:                                edit.setLocation(location);
5656:
5657:                                setFields(edit, addfieldsMap);
5658:                                edit.replaceAttachments(attachments);
5659:
5660:                                RecurrenceRule rule = (RecurrenceRule) sstate
5661:                                        .getAttribute(CalendarAction.SSTATE__RECURRING_RULE);
5662:
5663:                                // conditions:
5664:                                // 1st, an existing recurring one, just revised, no save state rule or state freq (0, 0)
5665:                                // --> let edit rule untouched 
5666:                                // 2st, and existing non-recurring one, just revised, no save state rule or state freq (0, 0)
5667:                                // --> let edit rule untouched 
5668:                                // 3rd, an existing recurring one, frequency revised, there is a state-saved rule, and state-saved freq exists (1, 1)
5669:                                // --> replace the edit rule with state-saved rule
5670:                                // 4th, and existing recurring one, changed to non-recurring, the state saved rule is null, but state-saved freq exists (0, 1)
5671:                                // --> replace the edit rule with state-saved rule
5672:                                // 5th, and existing non-recurring one, changed but kept as non-recurring, the state-saved rule is null, but state-saved freq exists (0, 1)
5673:                                // --> replace the edit rule with state-saved rule
5674:                                // so if the state-saved freq exists, replace the event rule
5675:
5676:                                String freq = (String) sstate
5677:                                        .getAttribute(FREQUENCY_SELECT);
5678:                                if (sstate.getAttribute(FREQUENCY_SELECT) != null) {
5679:                                    edit.setRecurrenceRule(rule);
5680:                                }
5681:
5682:                                // section awareness
5683:                                try {
5684:                                    // for site event
5685:                                    if (scheduleTo.equals("site")) {
5686:                                        edit.clearGroupAccess();
5687:                                    }
5688:
5689:                                    // for grouped event
5690:                                    else if (scheduleTo.equals("groups")) {
5691:                                        Site site = SiteService
5692:                                                .getSite(calendarObj
5693:                                                        .getContext());
5694:
5695:                                        // make a collection of Group objects from the collection of group ref strings
5696:                                        Collection groups = new Vector();
5697:                                        for (Iterator iGroups = groupChoice
5698:                                                .iterator(); iGroups.hasNext();) {
5699:                                            String groupRef = (String) iGroups
5700:                                                    .next();
5701:                                            groups.add(site.getGroup(groupRef));
5702:                                        }
5703:
5704:                                        edit.setGroupAccess(groups, edit
5705:                                                .isUserOwner());
5706:                                    }
5707:                                } catch (Exception e) {
5708:                                    M_log.warn("doUpdate", e);
5709:                                }
5710:
5711:                                calendarObj.commitEvent(edit, intention);
5712:                                state.setPrimaryCalendarEdit(null);
5713:                                state.setEdit(null);
5714:                                state.setIsNewCalendar(false);
5715:                            } // if (edit != null)
5716:
5717:                            m_calObj.setDay(Integer.parseInt(year), Integer
5718:                                    .parseInt(month), Integer.parseInt(day));
5719:
5720:                            sstate.setAttribute(STATE_YEAR, new Integer(
5721:                                    m_calObj.getYear()));
5722:                            sstate.setAttribute(STATE_MONTH, new Integer(
5723:                                    m_calObj.getMonthInteger()));
5724:                            sstate.setAttribute(STATE_DAY, new Integer(m_calObj
5725:                                    .getDayOfMonth()));
5726:
5727:                            // clear the saved recurring rule and the selected frequency
5728:                            sstate
5729:                                    .setAttribute(
5730:                                            CalendarAction.SSTATE__RECURRING_RULE,
5731:                                            null);
5732:                            sstate.setAttribute(FREQUENCY_SELECT, null);
5733:
5734:                            // set the return state as the one before new/revise
5735:                            String returnState = state.getReturnState();
5736:                            if (returnState != null) {
5737:                                state.setState(returnState);
5738:                            } else {
5739:                                state.setState("week");
5740:                            }
5741:                        } catch (IdUnusedException e) {
5742:                            addAlert(sstate, rb.getString("java.alert.noexist"));
5743:                            M_log.debug(".doUpdate(): " + e);
5744:                        } catch (PermissionException e) {
5745:                            addAlert(sstate, rb
5746:                                    .getString("java.alert.youcreate"));
5747:                            M_log.debug(".doUpdate(): " + e);
5748:                        } // try-catch
5749:                    } // if(title.length()==0)
5750:                } // if (state.getState().equalsIgnoreCase(STATE_CUSTOMIZE_CALENDAR))
5751:
5752:            } // doUpdate
5753:
5754:            public void doDeletefield(RunData runData, Context context) {
5755:                CalendarActionState state = (CalendarActionState) getState(
5756:                        context, runData, CalendarActionState.class);
5757:                String peid = ((JetspeedRunData) runData).getJs_peid();
5758:                SessionState sstate = ((JetspeedRunData) runData)
5759:                        .getPortletSessionState(peid);
5760:
5761:                customizeCalendarPage.doDeletefield(runData, context, state,
5762:                        getSessionState(runData));
5763:            }
5764:
5765:            /**
5766:             * Handle the button click to add a field to the list of optional attributes.
5767:             */
5768:            public void doAddfield(RunData runData, Context context) {
5769:                CalendarActionState state = (CalendarActionState) getState(
5770:                        context, runData, CalendarActionState.class);
5771:                String peid = ((JetspeedRunData) runData).getJs_peid();
5772:                SessionState sstate = ((JetspeedRunData) runData)
5773:                        .getPortletSessionState(peid);
5774:
5775:                customizeCalendarPage.doAddfield(runData, context, state,
5776:                        getSessionState(runData));
5777:            }
5778:
5779:            /**
5780:             * Action doNpagew is requested when the user click on the next arrow to move to the next page in the week view.
5781:             */
5782:
5783:            public void doNpagew(RunData runData, Context context) {
5784:                CalendarActionState state = (CalendarActionState) getState(
5785:                        context, runData, CalendarActionState.class);
5786:                String peid = ((JetspeedRunData) runData).getJs_peid();
5787:                SessionState sstate = ((JetspeedRunData) runData)
5788:                        .getPortletSessionState(peid);
5789:
5790:                if (state.getCurrentPage().equals("third"))
5791:                    state.setCurrentPage("first");
5792:                else if (state.getCurrentPage().equals("second"))
5793:                    state.setCurrentPage("third");
5794:                else if (state.getCurrentPage().equals("first"))
5795:                    state.setCurrentPage("second");
5796:                state.setState("week");
5797:            }
5798:
5799:            /**
5800:             * Action doPpagew is requested when the user click on the previous arrow to move to the previous page in week view.
5801:             */
5802:
5803:            public void doPpagew(RunData runData, Context context) {
5804:                CalendarActionState state = (CalendarActionState) getState(
5805:                        context, runData, CalendarActionState.class);
5806:                String peid = ((JetspeedRunData) runData).getJs_peid();
5807:                SessionState sstate = ((JetspeedRunData) runData)
5808:                        .getPortletSessionState(peid);
5809:
5810:                if (state.getCurrentPage().equals("first"))
5811:                    state.setCurrentPage("third");
5812:                else if (state.getCurrentPage().equals("third"))
5813:                    state.setCurrentPage("second");
5814:                else if (state.getCurrentPage().equals("second"))
5815:                    state.setCurrentPage("first");
5816:                state.setState("week");
5817:            }
5818:
5819:            /**
5820:             * Action doDpagen is requested when the user click on the next arrow to move to the next page in day view.
5821:             */
5822:
5823:            public void doDpagen(RunData runData, Context context) {
5824:                CalendarActionState state = (CalendarActionState) getState(
5825:                        context, runData, CalendarActionState.class);
5826:                String peid = ((JetspeedRunData) runData).getJs_peid();
5827:                SessionState sstate = ((JetspeedRunData) runData)
5828:                        .getPortletSessionState(peid);
5829:
5830:                if (state.getCurrentPage().equals("third"))
5831:                    state.setCurrentPage("first");
5832:                else if (state.getCurrentPage().equals("second"))
5833:                    state.setCurrentPage("third");
5834:                else if (state.getCurrentPage().equals("first"))
5835:                    state.setCurrentPage("second");
5836:                state.setState("day");
5837:            }
5838:
5839:            /**
5840:             * Action doDpagep is requested when the user click on the upper arrow to move to the previous page in day view.
5841:             */
5842:
5843:            public void doDpagep(RunData runData, Context context) {
5844:                CalendarActionState state = (CalendarActionState) getState(
5845:                        context, runData, CalendarActionState.class);
5846:                String peid = ((JetspeedRunData) runData).getJs_peid();
5847:                SessionState sstate = ((JetspeedRunData) runData)
5848:                        .getPortletSessionState(peid);
5849:
5850:                if (state.getCurrentPage().equals("first"))
5851:                    state.setCurrentPage("third");
5852:                else if (state.getCurrentPage().equals("third"))
5853:                    state.setCurrentPage("second");
5854:                else if (state.getCurrentPage().equals("second"))
5855:                    state.setCurrentPage("first");
5856:                state.setState("day");
5857:            } // doDpagep
5858:
5859:            /**
5860:             * Action doPrev_activity is requested when the user navigates to the previous message in the detailed view.
5861:             */
5862:
5863:            public void doPrev_activity(RunData runData, Context context) {
5864:                String peid = ((JetspeedRunData) runData).getJs_peid();
5865:                SessionState sstate = ((JetspeedRunData) runData)
5866:                        .getPortletSessionState(peid);
5867:
5868:                sstate.setAttribute(STATE_NAV_DIRECTION, STATE_PREV_ACT);
5869:            } //doPrev_activity
5870:
5871:            /**
5872:             * Action doNext_activity is requested when the user navigates to the previous message in the detailed view.
5873:             */
5874:            public void doNext_activity(RunData runData, Context context) {
5875:                String peid = ((JetspeedRunData) runData).getJs_peid();
5876:                SessionState sstate = ((JetspeedRunData) runData)
5877:                        .getPortletSessionState(peid);
5878:
5879:                sstate.setAttribute(STATE_NAV_DIRECTION, STATE_NEXT_ACT);
5880:            } // doNext_activity
5881:
5882:            /*
5883:             * detailNavigatorControl will handle the goNext/goPrev buttons in detailed view,
5884:             * as well as figure out the prev/next message if available
5885:             */
5886:            private void navigatorContextControl(VelocityPortlet portlet,
5887:                    Context context, RunData runData, String direction) {
5888:                String peid = ((JetspeedRunData) runData).getJs_peid();
5889:                SessionState sstate = ((JetspeedRunData) runData)
5890:                        .getPortletSessionState(peid);
5891:
5892:                CalendarActionState state = (CalendarActionState) getState(
5893:                        context, runData, CalendarActionState.class);
5894:
5895:                String eventId = state.getCalendarEventId();
5896:
5897:                List events = prepEventList(portlet, context, runData);
5898:
5899:                int index = -1;
5900:                int size = events.size();
5901:                for (int i = 0; i < size; i++) {
5902:                    CalendarEvent e = (CalendarEvent) events.get(i);
5903:                    if (e.getId().equals(eventId))
5904:                        index = i;
5905:                }
5906:
5907:                CalendarEvent ce = null;
5908:
5909:                if (direction.equals(STATE_PREV_ACT)) {
5910:                    // navigate to the previous activity
5911:                    if (index > 0) {
5912:                        ce = (CalendarEvent) events.get(index - 1);
5913:                    }
5914:                    Reference ref = EntityManager.newReference(ce
5915:                            .getReference());
5916:                    eventId = ref.getId();
5917:                    String calId = CalendarService.calendarReference(ref
5918:                            .getContext(), ref.getContainer());
5919:
5920:                    state.setCalendarEventId(calId, eventId);
5921:                    state.setAttachments(null);
5922:                    index--;
5923:                } else if (direction.equals(STATE_NEXT_ACT)) {
5924:                    // navigate to the next activity
5925:                    if (index < size - 1) {
5926:                        ce = (CalendarEvent) events.get(index + 1);
5927:                    }
5928:                    Reference ref = EntityManager.newReference(ce
5929:                            .getReference());
5930:                    eventId = ref.getId();
5931:                    String calId = CalendarService.calendarReference(ref
5932:                            .getContext(), ref.getContainer());
5933:
5934:                    state.setCalendarEventId(calId, eventId);
5935:                    state.setAttachments(null);
5936:                    index++;
5937:                }
5938:
5939:                if (index > 0)
5940:                    sstate.setAttribute(STATE_PREV_ACT, "");
5941:                else
5942:                    sstate.removeAttribute(STATE_PREV_ACT);
5943:
5944:                if (index < size - 1)
5945:                    sstate.setAttribute(STATE_NEXT_ACT, "");
5946:                else
5947:                    sstate.removeAttribute(STATE_NEXT_ACT);
5948:
5949:                sstate.setAttribute(STATE_NAV_DIRECTION, STATE_CURRENT_ACT);
5950:
5951:            } // navigatorControl
5952:
5953:            private CalendarEventVector prepEventList(VelocityPortlet portlet,
5954:                    Context context, RunData runData) {
5955:                String peid = ((JetspeedRunData) runData).getJs_peid();
5956:                SessionState sstate = ((JetspeedRunData) runData)
5957:                        .getPortletSessionState(peid);
5958:
5959:                CalendarActionState state = (CalendarActionState) getState(
5960:                        context, runData, CalendarActionState.class);
5961:
5962:                List events = new Vector();
5963:
5964:                TimeRange fullTimeRange = TimeService.newTimeRange(TimeService
5965:                        .newTimeLocal(CalendarFilter.LIST_VIEW_STARTING_YEAR,
5966:                                1, 1, 0, 0, 0, 0), TimeService.newTimeLocal(
5967:                        CalendarFilter.LIST_VIEW_ENDING_YEAR, 12, 31, 23, 59,
5968:                        59, 999));
5969:
5970:                // We need to get events from all calendars for the full time range.
5971:                CalendarEventVector masterEventVectorObj = CalendarService
5972:                        .getEvents(getCalendarReferenceList(portlet, state
5973:                                .getPrimaryCalendarReference(),
5974:                                isOnWorkspaceTab()), fullTimeRange);
5975:
5976:                /*
5977:                Vector eventsIdVector = new Vector();
5978:                for (int i=0; i< masterEventVectorObj.size(); i++)
5979:                {
5980:                	eventsIdVector.add(((CalendarEvent)masterEventVectorObj.get(i)).getId());
5981:                }
5982:                 */
5983:                sstate.setAttribute(STATE_EVENTS_LIST, masterEventVectorObj);
5984:                return masterEventVectorObj;
5985:
5986:            } // eventList
5987:
5988:            /**
5989:             * Action is to parse the function calls
5990:             **/
5991:            public void doParse(RunData data, Context context) {
5992:                ParameterParser params = data.getParameters();
5993:
5994:                String source = params.getString("source");
5995:                if (source.equalsIgnoreCase("new")) {
5996:                    // create new event
5997:                    doNew(data, context);
5998:                } else if (source.equalsIgnoreCase("revise")) {
5999:                    // revise an event
6000:                    doRevise(data, context);
6001:                } else if (source.equalsIgnoreCase("delete")) {
6002:                    // delete event
6003:                    doDelete(data, context);
6004:                } else if (source.equalsIgnoreCase("byday")) {
6005:                    // view by day
6006:                    doMenueday(data, context);
6007:                } else if (source.equalsIgnoreCase("byweek")) {
6008:                    // view by week
6009:                    doWeek(data, context);
6010:                } else if (source.equalsIgnoreCase("bymonth")) {
6011:                    // view by month
6012:                    doMonth(data, context);
6013:                } else if (source.equalsIgnoreCase("byyear")) {
6014:                    // view by year
6015:                    doYear(data, context);
6016:                } else if (source.equalsIgnoreCase("prev")) {
6017:                    // go previous
6018:                    doPrev(data, context);
6019:                } else if (source.equalsIgnoreCase("next")) {
6020:                    // go next
6021:                    doNext(data, context);
6022:                } else if (source.equalsIgnoreCase("bylist")) {
6023:                    // view by list
6024:                    doList(data, context);
6025:                }
6026:
6027:            } // doParse
6028:
6029:            /**
6030:             * Action doList is requested when the user click on the list in the toolbar
6031:             */
6032:            public void doList(RunData data, Context context) {
6033:                CalendarActionState state = (CalendarActionState) getState(
6034:                        context, data, CalendarActionState.class);
6035:                String peid = ((JetspeedRunData) data).getJs_peid();
6036:                SessionState sstate = ((JetspeedRunData) data)
6037:                        .getPortletSessionState(peid);
6038:
6039:                Time m_time = TimeService.newTime();
6040:                TimeBreakdown b = m_time.breakdownLocal();
6041:                int stateYear = b.getYear();
6042:                int stateMonth = b.getMonth();
6043:                int stateDay = b.getDay();
6044:                if ((sstate.getAttribute(STATE_YEAR) != null)
6045:                        && (sstate.getAttribute(STATE_MONTH) != null)
6046:                        && (sstate.getAttribute(STATE_DAY) != null)) {
6047:                    stateYear = ((Integer) sstate.getAttribute(STATE_YEAR))
6048:                            .intValue();
6049:                    stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH))
6050:                            .intValue();
6051:                    stateDay = ((Integer) sstate.getAttribute(STATE_DAY))
6052:                            .intValue();
6053:                }
6054:
6055:                String sM;
6056:                String eM;
6057:                String sD;
6058:                String eD;
6059:                String sY;
6060:                String eY;
6061:
6062:                CalendarUtil calObj = new CalendarUtil();
6063:                calObj.setDay(stateYear, stateMonth, stateDay);
6064:
6065:                String prevState = state.getState().toString();
6066:                if (prevState.equals("day")) {
6067:                    sY = new Integer(calObj.getYear()).toString();
6068:                    sM = new Integer(calObj.getMonthInteger()).toString();
6069:                    sD = new Integer(calObj.getDayOfMonth()).toString();
6070:                    eY = new Integer(calObj.getYear()).toString();
6071:                    eM = new Integer(calObj.getMonthInteger()).toString();
6072:                    eD = new Integer(calObj.getDayOfMonth()).toString();
6073:                } else if (prevState.equals("week")) {
6074:                    int dayofweek = calObj.getDay_Of_Week();
6075:                    for (int i = dayofweek; i > 1; i--) {
6076:                        calObj.getPrevDate();
6077:                    }
6078:                    sY = new Integer(calObj.getYear()).toString();
6079:                    sM = new Integer(calObj.getMonthInteger()).toString();
6080:                    sD = new Integer(calObj.getDayOfMonth()).toString();
6081:
6082:                    for (int i = 0; i < 6; i++) {
6083:                        calObj.getNextDate();
6084:                    }
6085:                    eY = new Integer(calObj.getYear()).toString();
6086:                    eM = new Integer(calObj.getMonthInteger()).toString();
6087:                    eD = new Integer(calObj.getDayOfMonth()).toString();
6088:                } else if (prevState.equals("month")) {
6089:                    sY = new Integer(calObj.getYear()).toString();
6090:                    sM = new Integer(calObj.getMonthInteger()).toString();
6091:                    sD = new String("1");
6092:                    calObj.setDay(stateYear, stateMonth, 1);
6093:
6094:                    GregorianCalendar cal = new GregorianCalendar(calObj
6095:                            .getYear(), calObj.getMonthInteger() - 1, 1);
6096:                    int daysInMonth = cal
6097:                            .getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
6098:                    for (int i = 1; i < daysInMonth; i++)
6099:                        calObj.getNextDate();
6100:                    eY = new Integer(calObj.getYear()).toString();
6101:                    eM = new Integer(calObj.getMonthInteger()).toString();
6102:                    eD = new Integer(calObj.getDayOfMonth()).toString();
6103:                } else {
6104:                    // for other conditions: show the current year
6105:                    sY = new Integer(stateYear).toString();
6106:                    sM = "1";
6107:                    sD = "1";
6108:                    eY = new Integer(stateYear).toString();
6109:                    eM = "12";
6110:                    eD = "31";
6111:                }
6112:
6113:                if (sM.length() == 1)
6114:                    sM = "0" + sM;
6115:                if (eM.length() == 1)
6116:                    eM = "0" + eM;
6117:                if (sD.length() == 1)
6118:                    sD = "0" + sD;
6119:                if (eD.length() == 1)
6120:                    eD = "0" + eD;
6121:                sY = sY.substring(2);
6122:                eY = eY.substring(2);
6123:
6124:                String startingDateStr = sM + "/" + sD + "/" + sY;
6125:                String endingDateStr = eM + "/" + eD + "/" + eY;
6126:                state.getCalendarFilter().setListViewFilterMode(
6127:                        CalendarFilter.SHOW_CUSTOM_RANGE);
6128:
6129:                sstate.removeAttribute(STATE_SCHEDULE_TO);
6130:                sstate.removeAttribute(STATE_SCHEDULE_TO_GROUPS);
6131:
6132:                // Pass in a buffer for a possible error message.
6133:                StringBuffer errorMessage = new StringBuffer();
6134:
6135:                // Try to simultaneously set the start/end dates.
6136:                // If that doesn't work, add an error message.
6137:                if (!state.getCalendarFilter().setStartAndEndListViewDates(
6138:                        startingDateStr, endingDateStr, errorMessage)) {
6139:                    addAlert(sstate, errorMessage.toString());
6140:                }
6141:
6142:                state.setState("list");
6143:            } // doList
6144:
6145:            /**
6146:             * Action doSort_by_date_toggle is requested when the user click on the sorting icon in the list view
6147:             */
6148:            public void doSort_by_date_toggle(RunData data, Context context) {
6149:                CalendarActionState state = (CalendarActionState) getState(
6150:                        context, data, CalendarActionState.class);
6151:                String peid = ((JetspeedRunData) data).getJs_peid();
6152:                SessionState sstate = ((JetspeedRunData) data)
6153:                        .getPortletSessionState(peid);
6154:
6155:                boolean dateDsc = sstate.getAttribute(STATE_DATE_SORT_DSC) != null;
6156:                if (dateDsc)
6157:                    sstate.removeAttribute(STATE_DATE_SORT_DSC);
6158:                else
6159:                    sstate.setAttribute(STATE_DATE_SORT_DSC, "");
6160:
6161:            } // doSort_by_date_toggle
6162:
6163:            /**
6164:             * Handle a request from the "merge" page to merge calendars from other groups into this group's Schedule display.
6165:             */
6166:            public void doMerge(RunData runData, Context context) {
6167:                CalendarActionState state = (CalendarActionState) getState(
6168:                        context, runData, CalendarActionState.class);
6169:                String peid = ((JetspeedRunData) runData).getJs_peid();
6170:                SessionState sstate = ((JetspeedRunData) runData)
6171:                        .getPortletSessionState(peid);
6172:
6173:                mergedCalendarPage.doMerge(runData, context, state,
6174:                        getSessionState(runData));
6175:            } // doMerge
6176:
6177:            /**
6178:             * Handle a request to set options.
6179:             */
6180:            public void doCustomize(RunData runData, Context context) {
6181:                CalendarActionState state = (CalendarActionState) getState(
6182:                        context, runData, CalendarActionState.class);
6183:
6184:                customizeCalendarPage.doCustomize(runData, context, state,
6185:                        getSessionState(runData));
6186:            }
6187:
6188:            /**
6189:             * Build the context for showing list view
6190:             */
6191:            protected void buildListContext(VelocityPortlet portlet,
6192:                    Context context, RunData runData, CalendarActionState state) {
6193:                // to get the content Type Image Service
6194:                context.put("contentTypeImageService", ContentTypeImageService
6195:                        .getInstance());
6196:                context.put("tlang", rb);
6197:                MyMonth monthObj2 = null;
6198:                MyDate dateObj1 = new MyDate();
6199:                StringBuffer exceptionMessage = new StringBuffer();
6200:                CalendarEventVector calendarEventVectorObj = null;
6201:                boolean allowed = false;
6202:                LinkedHashMap yearMap = new LinkedHashMap();
6203:
6204:                String peid = ((JetspeedRunData) runData).getJs_peid();
6205:                SessionState sstate = ((JetspeedRunData) runData)
6206:                        .getPortletSessionState(peid);
6207:
6208:                Time m_time = TimeService.newTime();
6209:                TimeBreakdown b = m_time.breakdownLocal();
6210:                int stateYear = b.getYear();
6211:                int stateMonth = b.getMonth();
6212:                int stateDay = b.getDay();
6213:                if ((sstate.getAttribute(STATE_YEAR) != null)
6214:                        && (sstate.getAttribute(STATE_MONTH) != null)
6215:                        && (sstate.getAttribute(STATE_DAY) != null)) {
6216:                    stateYear = ((Integer) sstate.getAttribute(STATE_YEAR))
6217:                            .intValue();
6218:                    stateMonth = ((Integer) sstate.getAttribute(STATE_MONTH))
6219:                            .intValue();
6220:                    stateDay = ((Integer) sstate.getAttribute(STATE_DAY))
6221:                            .intValue();
6222:                }
6223:
6224:                // Set up list filtering information in the context.
6225:                context.put(TIME_FILTER_OPTION_VAR, state.getCalendarFilter()
6226:                        .getListViewFilterMode());
6227:
6228:                //
6229:                // Fill in the custom dates
6230:                //
6231:                String sDate; // starting date
6232:                String eDate; // ending date
6233:
6234:                java.util.Calendar userCal = java.util.Calendar.getInstance();
6235:                context.put("ddStartYear", new Integer(userCal
6236:                        .get(java.util.Calendar.YEAR) - 3));
6237:                context.put("ddEndYear", new Integer(userCal
6238:                        .get(java.util.Calendar.YEAR) + 4));
6239:
6240:                String sM;
6241:                String eM;
6242:                String sD;
6243:                String eD;
6244:                String sY;
6245:                String eY;
6246:
6247:                if (state.getCalendarFilter().isCustomListViewDates()) {
6248:                    sDate = state.getCalendarFilter()
6249:                            .getStartingListViewDateString();
6250:                    eDate = state.getCalendarFilter()
6251:                            .getEndingListViewDateString();
6252:
6253:                    sM = sDate.substring(0, 2);
6254:                    eM = eDate.substring(0, 2);
6255:                    sD = sDate.substring(3, 5);
6256:                    eD = eDate.substring(3, 5);
6257:                    sY = "20" + sDate.substring(6);
6258:                    eY = "20" + eDate.substring(6);
6259:                } else {
6260:                    //default to current week
6261:                    CalendarUtil calObj = new CalendarUtil();
6262:                    calObj.setDay(stateYear, stateMonth, stateDay);
6263:
6264:                    int dayofweek = calObj.getDay_Of_Week();
6265:
6266:                    String ssdate = calObj.getTodayDate();
6267:                    String eedate = calObj.getTodayDate();
6268:
6269:                    for (int i = dayofweek; i > 1; i--) {
6270:                        calObj.getPrevDate();
6271:                    }
6272:                    sY = new Integer(calObj.getYear()).toString();
6273:                    if (calObj.getMonthInteger() < 10)
6274:                        sM = "0"
6275:                                + new Integer(calObj.getMonthInteger())
6276:                                        .toString();
6277:                    else
6278:                        sM = new Integer(calObj.getMonthInteger()).toString();
6279:
6280:                    sD = new Integer(calObj.getDayOfMonth()).toString();
6281:
6282:                    for (int i = 0; i < 6; i++) {
6283:                        calObj.getNextDate();
6284:                    }
6285:                    eY = new Integer(calObj.getYear()).toString();
6286:                    if (calObj.getMonthInteger() < 10)
6287:                        eM = "0"
6288:                                + new Integer(calObj.getMonthInteger())
6289:                                        .toString();
6290:                    else
6291:                        eM = new Integer(calObj.getMonthInteger()).toString();
6292:
6293:                    eD = new Integer(calObj.getDayOfMonth()).toString();
6294:                }
6295:
6296:                context.put(TIME_FILTER_SETTING_CUSTOM_START_YEAR, Integer
6297:                        .valueOf(sY));
6298:                context.put(TIME_FILTER_SETTING_CUSTOM_END_YEAR, Integer
6299:                        .valueOf(eY));
6300:                context.put(TIME_FILTER_SETTING_CUSTOM_START_MONTH, Integer
6301:                        .valueOf(sM));
6302:                context.put(TIME_FILTER_SETTING_CUSTOM_END_MONTH, Integer
6303:                        .valueOf(eM));
6304:                context.put(TIME_FILTER_SETTING_CUSTOM_START_DAY, Integer
6305:                        .valueOf(sD));
6306:                context.put(TIME_FILTER_SETTING_CUSTOM_END_DAY, Integer
6307:                        .valueOf(eD));
6308:
6309:                CalendarUtil calObj = new CalendarUtil();
6310:                calObj.setDay(stateYear, stateMonth, stateDay);
6311:                dateObj1.setTodayDate(calObj.getMonthInteger(), calObj
6312:                        .getDayOfMonth(), calObj.getYear());
6313:
6314:                // fill this month object with all days avilable for this month
6315:                if (CalendarService.allowGetCalendar(state
6316:                        .getPrimaryCalendarReference()) == false) {
6317:                    allowed = false;
6318:                    exceptionMessage.append(rb
6319:                            .getString("java.alert.younotallow"));
6320:                    calendarEventVectorObj = new CalendarEventVector();
6321:                } else {
6322:                    try {
6323:                        allowed = CalendarService.getCalendar(
6324:                                state.getPrimaryCalendarReference())
6325:                                .allowAddEvent();
6326:                    } catch (IdUnusedException e) {
6327:                        M_log.debug(".buildMonthContext(): " + e);
6328:                    } catch (PermissionException e) {
6329:                        M_log.debug(".buildMonthContext(): " + e);
6330:                    }
6331:                }
6332:
6333:                int yearInt, monthInt, dayInt = 1;
6334:
6335:                TimeRange fullTimeRange = TimeService.newTimeRange(TimeService
6336:                        .newTimeLocal(CalendarFilter.LIST_VIEW_STARTING_YEAR,
6337:                                1, 1, 0, 0, 0, 0), TimeService.newTimeLocal(
6338:                        CalendarFilter.LIST_VIEW_ENDING_YEAR, 12, 31, 23, 59,
6339:                        59, 999));
6340:
6341:                // We need to get events from all calendars for the full time range.
6342:                CalendarEventVector masterEventVectorObj = CalendarService
6343:                        .getEvents(getCalendarReferenceList(portlet, state
6344:                                .getPrimaryCalendarReference(),
6345:                                isOnWorkspaceTab()), fullTimeRange);
6346:
6347:                // groups awareness - filtering
6348:                String calId = state.getPrimaryCalendarReference();
6349:                String scheduleTo = (String) sstate
6350:                        .getAttribute(STATE_SCHEDULE_TO);
6351:
6352:                try {
6353:                    Calendar calendarObj = CalendarService.getCalendar(calId);
6354:                    context.put("cal", calendarObj);
6355:
6356:                    if (scheduleTo != null && scheduleTo.length() != 0) {
6357:                        context.put("scheduleTo", scheduleTo);
6358:                    } else {
6359:                        if (calendarObj.allowGetEvents()) {
6360:                            // default to make site selection
6361:                            context.put("scheduleTo", "site");
6362:                        } else if (calendarObj.getGroupsAllowGetEvent().size() > 0) {
6363:                            // to group otherwise
6364:                            context.put("scheduleTo", "groups");
6365:                        }
6366:                    }
6367:
6368:                    Collection groups = calendarObj.getGroupsAllowGetEvent();
6369:                    if (groups.size() > 0) {
6370:                        context.put("groups", groups);
6371:
6372:                    }
6373:                    List schToGroups = (List) (sstate
6374:                            .getAttribute(STATE_SCHEDULE_TO_GROUPS));
6375:                    context.put("scheduleToGroups", schToGroups);
6376:
6377:                    CalendarEventVector newEventVectorObj = new CalendarEventVector();
6378:                    newEventVectorObj.addAll(masterEventVectorObj);
6379:
6380:                    for (Iterator i = masterEventVectorObj.iterator(); i
6381:                            .hasNext();) {
6382:                        CalendarEvent e = (CalendarEvent) (i.next());
6383:
6384:                        String origSiteId = (CalendarService.getCalendar(e
6385:                                .getCalendarReference())).getContext();
6386:                        if (!origSiteId.equals(ToolManager
6387:                                .getCurrentPlacement().getContext())) {
6388:                            context.put("fromColExist", Boolean.TRUE);
6389:                        }
6390:
6391:                        if ((schToGroups != null) && (schToGroups.size() > 0)) {
6392:                            for (Iterator j = schToGroups.iterator(); j
6393:                                    .hasNext();) {
6394:                                String groupRangeForDispaly = e
6395:                                        .getGroupRangeForDisplay(calendarObj);
6396:                                String groupId = j.next().toString();
6397:                                try {
6398:                                    Site site = SiteService.getSite(calendarObj
6399:                                            .getContext());
6400:                                    Group group = site.getGroup(groupId);
6401:                                    if (groupRangeForDispaly.equals("")
6402:                                            || groupRangeForDispaly
6403:                                                    .equals("site"))
6404:                                        break;
6405:                                    if (groupRangeForDispaly.indexOf(group
6406:                                            .getTitle()) == -1) {
6407:                                        newEventVectorObj.remove(e);
6408:                                        break;
6409:                                    }
6410:                                } catch (Exception ignore) {
6411:                                }
6412:                            }
6413:                        }
6414:                    }
6415:
6416:                    if ((schToGroups != null) && (schToGroups.size() > 0)) {
6417:                        masterEventVectorObj.clear();
6418:                        masterEventVectorObj.addAll(newEventVectorObj);
6419:                    }
6420:                } catch (IdUnusedException e) {
6421:                    M_log.debug(".buildListContext(): " + e);
6422:                } catch (PermissionException e) {
6423:                    M_log.debug(".buildListContext(): " + e);
6424:                }
6425:
6426:                boolean dateDsc = sstate.getAttribute(STATE_DATE_SORT_DSC) != null;
6427:                context.put("currentDateSortAsc", new Boolean(!dateDsc));
6428:
6429:                if (!dateDsc) {
6430:                    for (yearInt = CalendarFilter.LIST_VIEW_STARTING_YEAR; yearInt <= CalendarFilter.LIST_VIEW_ENDING_YEAR; yearInt++) {
6431:                        Vector arrayOfMonths = new Vector(20);
6432:                        for (monthInt = 1; monthInt < 13; monthInt++) {
6433:                            CalendarUtil AcalObj = new CalendarUtil();
6434:
6435:                            monthObj2 = new MyMonth();
6436:                            AcalObj.setDay(yearInt, monthInt, dayInt);
6437:
6438:                            dateObj1.setTodayDate(AcalObj.getMonthInteger(),
6439:                                    AcalObj.getDayOfMonth(), AcalObj.getYear());
6440:
6441:                            // Get the events for the particular month from the
6442:                            // master list of events.
6443:                            calendarEventVectorObj = new CalendarEventVector(
6444:                                    state
6445:                                            .getCalendarFilter()
6446:                                            .filterEvents(
6447:                                                    masterEventVectorObj
6448:                                                            .getEvents(getMonthTimeRange((CalendarUtil) AcalObj))));
6449:
6450:                            if (!calendarEventVectorObj.isEmpty()) {
6451:                                AcalObj.setDay(dateObj1.getYear(), dateObj1
6452:                                        .getMonth(), dateObj1.getDay());
6453:
6454:                                monthObj2 = calMonth(monthInt,
6455:                                        (CalendarUtil) AcalObj, state,
6456:                                        calendarEventVectorObj);
6457:
6458:                                AcalObj.setDay(dateObj1.getYear(), dateObj1
6459:                                        .getMonth(), dateObj1.getDay());
6460:
6461:                                if (!calendarEventVectorObj.isEmpty())
6462:                                    arrayOfMonths.addElement(monthObj2);
6463:                            }
6464:                        }
6465:                        if (!arrayOfMonths.isEmpty())
6466:                            yearMap.put(new Integer(yearInt), arrayOfMonths
6467:                                    .iterator());
6468:                    }
6469:                } else {
6470:                    for (yearInt = CalendarFilter.LIST_VIEW_ENDING_YEAR; yearInt >= CalendarFilter.LIST_VIEW_STARTING_YEAR; yearInt--) {
6471:                        Vector arrayOfMonths = new Vector(20);
6472:                        for (monthInt = 12; monthInt >= 1; monthInt--) {
6473:                            CalendarUtil AcalObj = new CalendarUtil();
6474:
6475:                            monthObj2 = new MyMonth();
6476:                            AcalObj.setDay(yearInt, monthInt, dayInt);
6477:
6478:                            dateObj1.setTodayDate(AcalObj.getMonthInteger(),
6479:                                    AcalObj.getDayOfMonth(), AcalObj.getYear());
6480:
6481:                            // Get the events for the particular month from the
6482:                            // master list of events.
6483:                            calendarEventVectorObj = new CalendarEventVector(
6484:                                    state
6485:                                            .getCalendarFilter()
6486:                                            .filterEvents(
6487:                                                    masterEventVectorObj
6488:                                                            .getEvents(getMonthTimeRange((CalendarUtil) AcalObj))));
6489:
6490:                            if (!calendarEventVectorObj.isEmpty()) {
6491:                                AcalObj.setDay(dateObj1.getYear(), dateObj1
6492:                                        .getMonth(), dateObj1.getDay());
6493:
6494:                                monthObj2 = calMonth(monthInt,
6495:                                        (CalendarUtil) AcalObj, state,
6496:                                        calendarEventVectorObj);
6497:
6498:                                AcalObj.setDay(dateObj1.getYear(), dateObj1
6499:                                        .getMonth(), dateObj1.getDay());
6500:
6501:                                if (!calendarEventVectorObj.isEmpty())
6502:                                    arrayOfMonths.addElement(monthObj2);
6503:                            }
6504:                        }
6505:                        if (!arrayOfMonths.isEmpty())
6506:                            yearMap.put(new Integer(yearInt), arrayOfMonths
6507:                                    .iterator());
6508:                    }
6509:                }
6510:
6511:                context.put("yearMap", yearMap);
6512:
6513:                int row = 5;
6514:                context.put("row", new Integer(row));
6515:                calObj.setDay(stateYear, stateMonth, stateDay);
6516:
6517:                // using session state stored year-month-day to replace saving calObj
6518:                sstate.setAttribute(STATE_YEAR, new Integer(stateYear));
6519:                sstate.setAttribute(STATE_MONTH, new Integer(stateMonth));
6520:                sstate.setAttribute(STATE_DAY, new Integer(stateDay));
6521:
6522:                state.setState("list");
6523:                context.put("date", dateObj1);
6524:
6525:                // output CalendarService and SiteService
6526:                context.put("CalendarService", CalendarService.getInstance());
6527:                context.put("SiteService", SiteService.getInstance());
6528:                context.put("Context", ToolManager.getCurrentPlacement()
6529:                        .getContext());
6530:
6531:                buildMenu(portlet, context, runData, state, CalendarPermissions
6532:                        .allowCreateEvents(state.getPrimaryCalendarReference(),
6533:                                state.getSelectedCalendarReference()),
6534:                        CalendarPermissions.allowDeleteEvent(state
6535:                                .getPrimaryCalendarReference(), state
6536:                                .getSelectedCalendarReference(), state
6537:                                .getCalendarEventId()), CalendarPermissions
6538:                                .allowReviseEvents(state
6539:                                        .getPrimaryCalendarReference(), state
6540:                                        .getSelectedCalendarReference(), state
6541:                                        .getCalendarEventId()),
6542:                        CalendarPermissions.allowMergeCalendars(state
6543:                                .getPrimaryCalendarReference(),
6544:                                isOnWorkspaceTab()), CalendarPermissions
6545:                                .allowModifyCalendarProperties(state
6546:                                        .getPrimaryCalendarReference()),
6547:                        CalendarPermissions.allowImport(state
6548:                                .getPrimaryCalendarReference()));
6549:
6550:                // added by zqian for toolbar
6551:                context.put("allow_new", Boolean.valueOf(allowed));
6552:                context.put("allow_delete", Boolean.valueOf(false));
6553:                context.put("allow_revise", Boolean.valueOf(false));
6554:                context.put("realDate", TimeService.newTime());
6555:
6556:                context.put("selectedView", rb.getString("java.listeve"));
6557:                context.put("tlang", rb);
6558:
6559:                context.put("calendarFormattedText",
6560:                        new CalendarFormattedText());
6561:
6562:            } // buildListContext
6563:
6564:            /**
6565:             * Build the menu.
6566:             */
6567:            private void buildMenu(VelocityPortlet portlet, Context context,
6568:                    RunData runData, CalendarActionState state,
6569:                    boolean allow_new, boolean allow_delete,
6570:                    boolean allow_revise, boolean allow_merge_calendars,
6571:                    boolean allow_modify_calendar_properties,
6572:                    boolean allow_import) {
6573:                Menu bar = new MenuImpl(portlet, runData, "CalendarAction");
6574:
6575:                String status = state.getState();
6576:
6577:                if ((status.equals("day")) || (status.equals("week"))
6578:                        || (status.equals("month")) || (status.equals("year"))
6579:                        || (status.equals("list"))) {
6580:                    allow_revise = false;
6581:                    allow_delete = false;
6582:                }
6583:
6584:                bar.add(new MenuEntry(rb.getString("java.new"), null,
6585:                        allow_new, MenuItem.CHECKED_NA, "doNew"));
6586:
6587:                //
6588:                // Don't allow the user to customize the "My Workspace" tab.
6589:                //
6590:                if (!isOnWorkspaceTab()) {
6591:                    bar.add(new MenuEntry(mergedCalendarPage.getButtonText(),
6592:                            null, allow_merge_calendars, MenuItem.CHECKED_NA,
6593:                            mergedCalendarPage.getButtonHandlerID()));
6594:                }
6595:
6596:                // See if we are allowed to import items.
6597:                if (allow_import) {
6598:                    bar.add(new MenuEntry(rb.getString("java.import"), null,
6599:                            allow_new, MenuItem.CHECKED_NA, "doImport"));
6600:                }
6601:
6602:                // 2nd menu bar for the PDF print only
6603:                Menu bar_PDF = new MenuImpl(portlet, runData, "CalendarAction");
6604:
6605:                String stateName = state.getState();
6606:
6607:                if (stateName.equals("month") || stateName.equals("day")
6608:                        || stateName.equals("week") || stateName.equals("list")) {
6609:                    int printType = CalendarService.UNKNOWN_VIEW;
6610:                    String timeRangeString = "";
6611:
6612:                    TimeRange dailyStartTime = null;
6613:                    int startHour = 0, startMinute = 0;
6614:                    int endHour = 0, endMinute = 0;
6615:                    int endSeconds = 0, endMSeconds = 0;
6616:
6617:                    //
6618:                    // Depending what page we are on, there will be
6619:                    // a different time of the day on which we start.
6620:                    //
6621:                    if (state.getCurrentPage().equals("first")) {
6622:                        startHour = FIRST_PAGE_START_HOUR;
6623:                        endHour = startHour
6624:                                + NUMBER_HOURS_PER_PAGE_FOR_WEEK_VIEW;
6625:                    } else if (state.getCurrentPage().equals("second")) {
6626:                        startHour = SECOND_PAGE_START_HOUR;
6627:                        endHour = startHour
6628:                                + NUMBER_HOURS_PER_PAGE_FOR_WEEK_VIEW;
6629:                    } else if (state.getCurrentPage().equals("third")) {
6630:                        startHour = THIRD_PAGE_START_HOUR;
6631:                        endHour = startHour
6632:                                + NUMBER_HOURS_PER_PAGE_FOR_WEEK_VIEW;
6633:                    } else {
6634:                        startHour = 0;
6635:                        endHour = startHour + HOURS_PER_DAY;
6636:                    }
6637:
6638:                    // If we go over twenty-four hours, stop at the end of the day.
6639:                    if (endHour >= HOURS_PER_DAY) {
6640:                        endHour = 23;
6641:                        endMinute = 59;
6642:                        endSeconds = 59;
6643:                        endMSeconds = 999;
6644:                    }
6645:
6646:                    dailyStartTime = TimeService.newTimeRange(TimeService
6647:                            .newTimeLocal(state.getcurrentYear(), state
6648:                                    .getcurrentMonth(), state.getcurrentDay(),
6649:                                    startHour, startMinute, 00, 000),
6650:                            TimeService.newTimeLocal(state.getcurrentYear(),
6651:                                    state.getcurrentMonth(), state
6652:                                            .getcurrentDay(), endHour,
6653:                                    endMinute, endSeconds, endMSeconds));
6654:
6655:                    String peid = ((JetspeedRunData) runData).getJs_peid();
6656:                    SessionState sstate = ((JetspeedRunData) runData)
6657:                            .getPortletSessionState(peid);
6658:
6659:                    Time m_time = TimeService.newTime();
6660:                    TimeBreakdown b = m_time.breakdownLocal();
6661:                    int stateYear = b.getYear();
6662:                    int stateMonth = b.getMonth();
6663:                    int stateDay = b.getDay();
6664:                    if ((sstate.getAttribute(STATE_YEAR) != null)
6665:                            && (sstate.getAttribute(STATE_MONTH) != null)
6666:                            && (sstate.getAttribute(STATE_DAY) != null)) {
6667:                        stateYear = ((Integer) sstate.getAttribute(STATE_YEAR))
6668:                                .intValue();
6669:                        stateMonth = ((Integer) sstate
6670:                                .getAttribute(STATE_MONTH)).intValue();
6671:                        stateDay = ((Integer) sstate.getAttribute(STATE_DAY))
6672:                                .intValue();
6673:                    }
6674:
6675:                    CalendarUtil calObj = new CalendarUtil();
6676:                    calObj.setDay(stateYear, stateMonth, stateDay);
6677:
6678:                    if (stateName.equals("month")) {
6679:                        printType = CalendarService.MONTH_VIEW;
6680:                        timeRangeString = getMonthTimeRange(calObj).toString();
6681:                    } else if (stateName.equals("day")) {
6682:                        printType = CalendarService.DAY_VIEW;
6683:
6684:                        timeRangeString = getDayTimeRange(calObj.getYear(),
6685:                                calObj.getMonthInteger(),
6686:                                calObj.getDayOfMonth()).toString();
6687:                    } else if (stateName.equals("week")) {
6688:                        printType = CalendarService.WEEK_VIEW;
6689:                        timeRangeString = getWeekTimeRange(calObj).toString();
6690:                    } else if (stateName.equals("list")) {
6691:                        printType = CalendarService.LIST_VIEW;
6692:
6693:                        timeRangeString = TimeService.newTimeRange(
6694:                                state.getCalendarFilter()
6695:                                        .getListViewStartingTime(),
6696:                                state.getCalendarFilter()
6697:                                        .getListViewEndingTime()).toString();
6698:                    }
6699:
6700:                    Reference calendarRef = EntityManager.newReference(state
6701:                            .getPrimaryCalendarReference());
6702:
6703:                    String accessPointUrl = ServerConfigurationService
6704:                            .getAccessUrl()
6705:                            + CalendarService.calendarPdfReference(calendarRef
6706:                                    .getContext(), calendarRef.getId(),
6707:                                    printType, timeRangeString,
6708:                                    UserDirectoryService.getCurrentUser()
6709:                                            .getDisplayName(), dailyStartTime);
6710:
6711:                    // set the actual list of calendars into the user's session:
6712:                    List calRefList = getCalendarReferenceList(portlet, state
6713:                            .getPrimaryCalendarReference(), isOnWorkspaceTab());
6714:
6715:                    SessionManager.getCurrentSession().setAttribute(
6716:                            CalendarService.SESSION_CALENDAR_LIST, calRefList);
6717:
6718:                    bar_PDF.add(new MenuEntry(rb.getString("java.print"), "")
6719:                            .setUrl(accessPointUrl));
6720:                }
6721:
6722:                bar.add(new MenuEntry(customizeCalendarPage.getButtonText(),
6723:                        null, allow_modify_calendar_properties,
6724:                        MenuItem.CHECKED_NA, customizeCalendarPage
6725:                                .getButtonHandlerID()));
6726:
6727:                // add permissions, if allowed
6728:                if (SiteService.allowUpdateSite(ToolManager
6729:                        .getCurrentPlacement().getContext())) {
6730:                    bar.add(new MenuEntry(rb.getString("java.permissions"),
6731:                            "doPermissions"));
6732:                }
6733:
6734:                // Set menu state attribute
6735:                SessionState stateForMenus = ((JetspeedRunData) runData)
6736:                        .getPortletSessionState(portlet.getID());
6737:                stateForMenus.setAttribute(MenuItem.STATE_MENU, bar);
6738:                context.put("tlang", rb);
6739:                context.put(Menu.CONTEXT_MENU, bar);
6740:                context.put("menu_PDF", bar_PDF);
6741:                context.put(Menu.CONTEXT_ACTION, "CalendarAction");
6742:
6743:            } // buildMenu
6744:
6745:            /**
6746:             * Align the edit's fields with these values.
6747:             * @param edit The CalendarEventEdit.
6748:             * @param values The map of name-value pairs.
6749:             */
6750:            private void setFields(CalendarEventEdit edit, Map values) {
6751:                Set keys = values.keySet();
6752:                for (Iterator it = keys.iterator(); it.hasNext();) {
6753:                    String name = (String) it.next();
6754:                    String value = (String) values.get(name);
6755:                    edit.setField(name, value);
6756:                }
6757:
6758:            } // setFields
6759:
6760:            /**
6761:             * Fire up the permissions editor
6762:             */
6763:            public void doPermissions(RunData data, Context context) {
6764:                // get into helper mode with this helper tool
6765:                startHelper(data.getRequest(), "sakai.permissions.helper");
6766:
6767:                // setup the parameters for the helper
6768:                SessionState state = ((JetspeedRunData) data)
6769:                        .getPortletSessionState(((JetspeedRunData) data)
6770:                                .getJs_peid());
6771:                CalendarActionState cstate = (CalendarActionState) getState(
6772:                        context, data, CalendarActionState.class);
6773:
6774:                String calendarRefStr = cstate.getPrimaryCalendarReference();
6775:                Reference calendarRef = EntityManager
6776:                        .newReference(calendarRefStr);
6777:                String siteRef = SiteService.siteReference(calendarRef
6778:                        .getContext());
6779:
6780:                // setup for editing the permissions of the site for this tool, using the roles of this site, too
6781:                state.setAttribute(PermissionsHelper.TARGET_REF, siteRef);
6782:
6783:                // ... with this description
6784:                state.setAttribute(PermissionsHelper.DESCRIPTION, rb
6785:                        .getString("java.set")
6786:                        + SiteService.getSiteDisplay(calendarRef.getContext()));
6787:
6788:                // ... showing only locks that are prpefixed with this
6789:                state.setAttribute(PermissionsHelper.PREFIX, "calendar.");
6790:            }
6791:
6792:            /**
6793:             * Action doFrequency is requested when "set Frequency" button is clicked in new/revise page
6794:             */
6795:
6796:            public void doEditfrequency(RunData rundata, Context context) {
6797:                CalendarActionState state = (CalendarActionState) getState(
6798:                        context, rundata, CalendarActionState.class);
6799:
6800:                String peid = ((JetspeedRunData) rundata).getJs_peid();
6801:                SessionState sstate = ((JetspeedRunData) rundata)
6802:                        .getPortletSessionState(peid);
6803:
6804:                String calId = "";
6805:                Calendar calendarObj = null;
6806:
6807:                String eventId = state.getCalendarEventId();
6808:
6809:                try {
6810:                    calId = state.getPrimaryCalendarReference();
6811:                    calendarObj = CalendarService.getCalendar(calId);
6812:
6813:                    String freq = (String) sstate
6814:                            .getAttribute(FREQUENCY_SELECT);
6815:
6816:                    // conditions when the doEditfrequency is called:
6817:                    // 1. new/existing event, in create-new/revise page first time: freq is null.
6818:                    //    It has been set to null in both doNew & doRevise.
6819:                    //    Make sure to re-set the freq in this step.
6820:                    // 2. new/existing event, back from cancel/save-frequency-setting page: freq is sth, because when
6821:                    // the first time doEditfrequency is called, there is a freq set up already
6822:
6823:                    // condition 1 -
6824:                    if ((freq == null) || (freq.equals(""))) {
6825:                        // if a new event
6826:                        if ((eventId == null) || (eventId.equals(""))) {
6827:                            // set the frequency to be default "once", rule to be null
6828:                            sstate.setAttribute(FREQUENCY_SELECT, DEFAULT_FREQ);
6829:                            sstate
6830:                                    .setAttribute(
6831:                                            CalendarAction.SSTATE__RECURRING_RULE,
6832:                                            null);
6833:                        } else { // exiting event
6834:                            try {
6835:                                if (calendarObj.allowGetEvents()) {
6836:                                    CalendarEvent event = calendarObj
6837:                                            .getEvent(eventId);
6838:                                    RecurrenceRule rule = event
6839:                                            .getRecurrenceRule();
6840:                                    if (rule == null) {
6841:                                        // not recurring, i.e., frequency is once
6842:                                        sstate.setAttribute(FREQUENCY_SELECT,
6843:                                                DEFAULT_FREQ);
6844:                                        sstate
6845:                                                .setAttribute(
6846:                                                        CalendarAction.SSTATE__RECURRING_RULE,
6847:                                                        null);
6848:                                    } else {
6849:                                        sstate
6850:                                                .setAttribute(
6851:                                                        CalendarAction.SSTATE__RECURRING_RULE,
6852:                                                        rule);
6853:                                        sstate.setAttribute(FREQUENCY_SELECT,
6854:                                                rule.getFrequencyDescription());
6855:                                    } // if (rule==null)
6856:                                } // if allowGetEvents
6857:                            } // try
6858:                            catch (IdUnusedException e) {
6859:                                M_log
6860:                                        .debug(".doEditfrequency() + calendarObj.getEvent(): "
6861:                                                + e);
6862:                            } // try-cath
6863:                        } // if ((eventId == null)||(eventId.equals(""))
6864:                    } else {
6865:                        // condition 2, state freq is set, and state rule is set already
6866:                    }
6867:                } // try
6868:                catch (IdUnusedException e) {
6869:                    M_log
6870:                            .debug(".doEditfrequency() + CalendarService.getCalendar(): "
6871:                                    + e);
6872:                } catch (PermissionException e) {
6873:                    M_log
6874:                            .debug(".doEditfrequency() + CalendarService.getCalendar(): "
6875:                                    + e);
6876:                }
6877:
6878:                int houri;
6879:
6880:                String hour = "";
6881:                hour = rundata.getParameters().getString("startHour");
6882:                String title = "";
6883:                title = rundata.getParameters().getString("activitytitle");
6884:                String minute = "";
6885:                minute = rundata.getParameters().getString("startMinute");
6886:                String dhour = "";
6887:                dhour = rundata.getParameters().getString("duHour");
6888:                String dminute = "";
6889:                dminute = rundata.getParameters().getString("duMinute");
6890:                String description = "";
6891:                description = rundata.getParameters().getString("description");
6892:                description = processFormattedTextFromBrowser(sstate,
6893:                        description);
6894:                String month = "";
6895:                month = rundata.getParameters().getString("month");
6896:
6897:                String day = "";
6898:                day = rundata.getParameters().getString("day");
6899:                String year = "";
6900:                year = rundata.getParameters().getString("yearSelect");
6901:                String timeType = "";
6902:                timeType = rundata.getParameters().getString("startAmpm");
6903:                String type = "";
6904:                type = rundata.getParameters().getString("eventType");
6905:                String location = "";
6906:                location = rundata.getParameters().getString("location");
6907:
6908:                readEventGroupForm(rundata, context);
6909:
6910:                // read the recurrence modification intention
6911:                String intentionStr = rundata.getParameters().getString(
6912:                        "intention");
6913:                if (intentionStr == null)
6914:                    intentionStr = "";
6915:
6916:                StringBuffer exceptionMessage = new StringBuffer();
6917:
6918:                try {
6919:                    calendarObj = CalendarService.getCalendar(calId);
6920:                    Map addfieldsMap = new HashMap();
6921:
6922:                    // Add any additional fields in the calendar.
6923:                    customizeCalendarPage.loadAdditionalFieldsMapFromRunData(
6924:                            rundata, addfieldsMap, calendarObj);
6925:
6926:                    if (timeType.equals("pm")) {
6927:                        if (Integer.parseInt(hour) > 11)
6928:                            houri = Integer.parseInt(hour);
6929:                        else
6930:                            houri = Integer.parseInt(hour) + 12;
6931:                    } else if (timeType.equals("am")
6932:                            && Integer.parseInt(hour) == 12) {
6933:                        houri = 24;
6934:                    } else {
6935:                        houri = Integer.parseInt(hour);
6936:                    }
6937:                    state.clearData();
6938:                    state.setNewData(state.getPrimaryCalendarReference(),
6939:                            title, description, Integer.parseInt(month),
6940:                            Integer.parseInt(day), year, houri, Integer
6941:                                    .parseInt(minute), Integer.parseInt(dhour),
6942:                            Integer.parseInt(dminute), type, timeType,
6943:                            location, addfieldsMap, intentionStr);
6944:                } catch (IdUnusedException e) {
6945:                    exceptionMessage.append(rb.getString("java.alert.thereis"));
6946:                    M_log.debug(".doEditfrequency(): " + e);
6947:                } catch (PermissionException e) {
6948:                    exceptionMessage.append(rb.getString("java.alert.youdont"));
6949:                    M_log.debug(".doEditfrequency(): " + e);
6950:                }
6951:
6952:                sstate.setAttribute(STATE_BEFORE_SET_RECURRENCE, state
6953:                        .getState());
6954:                state.setState(STATE_SET_FREQUENCY);
6955:
6956:            } // doEditfrequency
6957:
6958:            /**
6959:             * Action doChangefrequency is requested when the user changes the selected frequency at the frequency setting page
6960:             */
6961:
6962:            public void doChangefrequency(RunData rundata, Context context) {
6963:                CalendarActionState state = (CalendarActionState) getState(
6964:                        context, rundata, CalendarActionState.class);
6965:
6966:                String freqSelect = rundata.getParameters().getString(
6967:                        FREQUENCY_SELECT);
6968:
6969:                String peid = ((JetspeedRunData) rundata).getJs_peid();
6970:                SessionState sstate = ((JetspeedRunData) rundata)
6971:                        .getPortletSessionState(peid);
6972:
6973:                sstate.setAttribute(FREQUENCY_SELECT, freqSelect);
6974:
6975:                //TEMP_FREQ_SELECT only works for the onchange javascript function when user changes the frequency selection
6976:                // and will be discarded when buildFrequecyContext has caught its value
6977:                sstate.setAttribute(TEMP_FREQ_SELECT, freqSelect);
6978:
6979:                state.setState(STATE_SET_FREQUENCY);
6980:
6981:            } // doChangefrequency
6982:
6983:            /**
6984:             * Action doSavefrequency is requested when the user click on the "Save" button in the frequency setting page
6985:             */
6986:
6987:            public void doSavefrequency(RunData rundata, Context context) {
6988:                CalendarActionState state = (CalendarActionState) getState(
6989:                        context, rundata, CalendarActionState.class);
6990:
6991:                String peid = ((JetspeedRunData) rundata).getJs_peid();
6992:                SessionState sstate = ((JetspeedRunData) rundata)
6993:                        .getPortletSessionState(peid);
6994:
6995:                String returnState = (String) sstate
6996:                        .getAttribute(STATE_BEFORE_SET_RECURRENCE);
6997:
6998:                // if by any chance, the returnState is not available, 
6999:                // then reset it as either "new" or "revise". 
7000:                // For new event, the id is null or empty string
7001:                if ((returnState == null) || (returnState.equals(""))) {
7002:                    String eventId = state.getCalendarEventId();
7003:                    if ((eventId == null) || (eventId.equals("")))
7004:                        returnState = "new";
7005:                    else
7006:                        returnState = "revise";
7007:                }
7008:                state.setState(returnState);
7009:
7010:                // get the current frequency setting the user has selected - daily, weekly, or etc.
7011:                String freq = (String) rundata.getParameters().getString(
7012:                        FREQUENCY_SELECT);
7013:
7014:                if ((freq == null) || (freq.equals(FREQ_ONCE))) {
7015:                    sstate.setAttribute(CalendarAction.SSTATE__RECURRING_RULE,
7016:                            null);
7017:                    sstate.setAttribute(FREQUENCY_SELECT, FREQ_ONCE);
7018:                } else {
7019:                    sstate.setAttribute(FREQUENCY_SELECT, freq);
7020:
7021:                    String interval = rundata.getParameters().getString(
7022:                            "interval");
7023:                    int intInterval = Integer.parseInt(interval);
7024:
7025:                    RecurrenceRule rule = null;
7026:
7027:                    String CountOrTill = rundata.getParameters().getString(
7028:                            "CountOrTill");
7029:                    if (CountOrTill.equals("Never")) {
7030:                        rule = CalendarService.newRecurrence(freq, intInterval);
7031:                    } else if (CountOrTill.equals("Till")) {
7032:                        String endMonth = rundata.getParameters().getString(
7033:                                "endMonth");
7034:                        String endDay = rundata.getParameters().getString(
7035:                                "endDay");
7036:                        String endYear = rundata.getParameters().getString(
7037:                                "endYear");
7038:                        int intEndMonth = Integer.parseInt(endMonth);
7039:                        int intEndDay = Integer.parseInt(endDay);
7040:                        int intEndYear = Integer.parseInt(endYear);
7041:
7042:                        //construct time object from individual ints, GMT values
7043:                        Time endTime = TimeService.newTimeGmt(intEndYear,
7044:                                intEndMonth, intEndDay, 23, 59, 59, 999);
7045:                        rule = CalendarService.newRecurrence(freq, intInterval,
7046:                                endTime);
7047:                    } else if (CountOrTill.equals("Count")) {
7048:                        String count = rundata.getParameters().getString(
7049:                                "count");
7050:                        int intCount = Integer.parseInt(count);
7051:                        rule = CalendarService.newRecurrence(freq, intInterval,
7052:                                intCount);
7053:                    }
7054:                    sstate.setAttribute(CalendarAction.SSTATE__RECURRING_RULE,
7055:                            rule);
7056:                } // if (freq.equals(FREQ_ONCE))
7057:
7058:            } // doSavefrequency
7059:
7060:            /**
7061:             * Populate the state object, if needed.
7062:             */
7063:            protected void initState(SessionState state,
7064:                    VelocityPortlet portlet, JetspeedRunData rundata) {
7065:                super .initState(state, portlet, rundata);
7066:
7067:                // retrieve the state from state object
7068:                CalendarActionState calState = (CalendarActionState) getState(
7069:                        portlet, rundata, CalendarActionState.class);
7070:
7071:                setPrimaryCalendarReferenceInState(portlet, calState);
7072:
7073:                //String channel = StringUtil.trimToNull(config.getInitParameter(PARAM_CHANNEL));
7074:                // setup the observer to notify our main panel
7075:                if (state.getAttribute(STATE_INITED) == null) {
7076:                    state.setAttribute(STATE_INITED, STATE_INITED);
7077:                    //			// the delivery location for this tool
7078:                    //			String deliveryId = clientWindowId(state, portlet.getID());
7079:                    //
7080:                    //			// the html element to update on delivery
7081:                    //			String elementId = mainPanelUpdateId(portlet.getID());
7082:                    //
7083:                    //			// the event resource reference pattern to watch for
7084:                    //			EventsObservingCourier observer =
7085:                    //				new EventsObservingCourier(
7086:                    //					deliveryId,
7087:                    //					elementId,
7088:                    //					calState.getPrimaryCalendarReference());
7089:                    //			
7090:                    //			state.setAttribute(STATE_OBSERVER, observer);
7091:
7092:                    MergedList mergedCalendarList = new MergedList();
7093:
7094:                    String[] channelArray = null;
7095:
7096:                    // Figure out the list of channel references that we'll be using.
7097:                    // If we're on the workspace tab, we get everything.
7098:                    // Don't do this if we're the super-user, since we'd be
7099:                    // overwhelmed.
7100:                    if (isOnWorkspaceTab() && !SecurityService.isSuperUser()) {
7101:                        channelArray = mergedCalendarList
7102:                                .getAllPermittedChannels(new CalendarChannelReferenceMaker());
7103:                    } else {
7104:                        // Get the list of merged calendar sources.
7105:                        // TODO - MERGE FIX
7106:                        channelArray = mergedCalendarList
7107:                                .getChannelReferenceArrayFromDelimitedString(
7108:                                        calState.getPrimaryCalendarReference(),
7109:                                        portlet
7110:                                                .getPortletConfig()
7111:                                                .getInitParameter(
7112:                                                        PORTLET_CONFIG_PARM_MERGED_CALENDARS));
7113:                    }
7114:
7115:                    mergedCalendarList.loadChannelsFromDelimitedString(
7116:                            isOnWorkspaceTab(),
7117:                            new MergedListEntryProviderFixedListWrapper(
7118:                                    new EntryProvider(), calState
7119:                                            .getPrimaryCalendarReference(),
7120:                                    channelArray,
7121:                                    new CalendarReferenceToChannelConverter()),
7122:                            StringUtil.trimToZero(SessionManager
7123:                                    .getCurrentSessionUserId()), channelArray,
7124:                            SecurityService.isSuperUser(), ToolManager
7125:                                    .getCurrentPlacement().getContext());
7126:
7127:                    // make sure the observer is in sync with state
7128:                    updateObservationOfChannel(mergedCalendarList, rundata,
7129:                            state, calState);
7130:                }
7131:
7132:            } // initState
7133:
7134:            //	/**
7135:            //	 * Adds the merged sites to the list of events that we're interested
7136:            //	 * in watching.
7137:            //	 */
7138:            //	private void addMergedCalendarsToObserver(MergedList mergedCalendarList, CalendarActionState calendarActionState, EventsObservingCourier observer)
7139:            //	{
7140:            //		Iterator it = mergedCalendarList.iterator();
7141:            //		
7142:            //		while (it.hasNext())
7143:            //		{
7144:            //			MergedList.MergedEntry entry = (MergedList.MergedEntry) it.next();
7145:            //
7146:            //			if ( entry.isMerged() )
7147:            //			{
7148:            //				Reference ref = new Reference(entry.getReference());
7149:            //			
7150:            //				String pattern =
7151:            //				CalendarService.eventReference(ref.getContext(), ref.getId(), "");
7152:            //				
7153:            //				observer.addResourcePattern(pattern);				
7154:            //			}
7155:            //		}
7156:            //	}
7157:
7158:            /**
7159:             * Setup our observer to be watching for change events for our channel.
7160:             */
7161:            private void updateObservationOfChannel(
7162:                    MergedList mergedCalendarList, RunData runData,
7163:                    SessionState state, CalendarActionState calState) {
7164:                //		String peid = ((JetspeedRunData) runData).getJs_peid();
7165:                //		
7166:                //		EventsObservingCourier observer =
7167:                //		(EventsObservingCourier) state.getAttribute(STATE_OBSERVER);
7168:                //
7169:                //		addMergedCalendarsToObserver(mergedCalendarList, calState, observer);
7170:                //
7171:                //		// the delivery location for this tool
7172:                //		String deliveryId = clientWindowId(state, peid);
7173:                //		observer.setDeliveryId(deliveryId);
7174:
7175:            } // updateObservationOfChannel
7176:
7177:            /**
7178:             *  Takes an array of tokens and converts into separator-separated string.
7179:             *
7180:             * @param String[] The array of strings input.
7181:             * @param String The string separator.
7182:             * @return String A string containing tokens separated by seperator.
7183:             */
7184:            protected String arrayToString(String[] array, String separators) {
7185:                StringBuffer sb = new StringBuffer("");
7186:                String empty = "";
7187:
7188:                if (array == null)
7189:                    return empty;
7190:
7191:                if (separators == null)
7192:                    separators = ",";
7193:
7194:                for (int ix = 0; ix < array.length; ix++) {
7195:                    if (array[ix] != null && !array[ix].equals("")) {
7196:                        sb.append(array[ix] + separators);
7197:                    }
7198:                }
7199:                String str = sb.toString();
7200:                if (!str.equals("")) {
7201:                    str = str
7202:                            .substring(0, (str.length() - separators.length()));
7203:                }
7204:                return str;
7205:            }
7206:
7207:            /**
7208:             * Processes formatted text that is coming back from the browser 
7209:             * (from the formatted text editing widget).
7210:             * @param state Used to pass in any user-visible alerts or errors when processing the text
7211:             * @param strFromBrowser The string from the browser
7212:             * @return The formatted text
7213:             */
7214:            private String processFormattedTextFromBrowser(SessionState state,
7215:                    String strFromBrowser) {
7216:                StringBuffer alertMsg = new StringBuffer();
7217:                try {
7218:                    String text = FormattedText.processFormattedText(
7219:                            strFromBrowser, alertMsg);
7220:                    if (alertMsg.length() > 0)
7221:                        addAlert(state, alertMsg.toString());
7222:                    return text;
7223:                } catch (Exception e) {
7224:                    M_log.warn(" ", e);
7225:                    return strFromBrowser;
7226:                }
7227:            }
7228:
7229:            /**
7230:             * Access the current month as a string.
7231:             * @return the current month as a string.
7232:             */
7233:            public String calendarUtilGetMonth(int l_month) {
7234:                // get the index for the month. Note, the index is increased by 1, u need to deduct 1 first
7235:                String[] months = new String[] { rb.getString("java.jan"),
7236:                        rb.getString("java.feb"), rb.getString("java.mar"),
7237:                        rb.getString("java.apr"), rb.getString("java.may"),
7238:                        rb.getString("java.jun"), rb.getString("java.jul"),
7239:                        rb.getString("java.aug"), rb.getString("java.sep"),
7240:                        rb.getString("java.oct"), rb.getString("java.nov"),
7241:                        rb.getString("java.dec") };
7242:
7243:                if (l_month > 12) {
7244:                    return rb.getString("java.thismonth");
7245:                }
7246:
7247:                return months[l_month - 1];
7248:
7249:            } // getMonth
7250:
7251:            /**
7252:             * Get the name of the day.
7253:             * @return the name of the day.
7254:             */
7255:            public String calendarUtilGetDay(int dayofweek) {
7256:                String[] l_ndays = new String[] { rb.getString("java.sun"),
7257:                        rb.getString("java.mon"), rb.getString("java.tue"),
7258:                        rb.getString("java.wed"), rb.getString("java.thu"),
7259:                        rb.getString("java.fri"), rb.getString("java.sat") };
7260:
7261:                if (dayofweek > 7) {
7262:                    dayofweek = 1;
7263:                } else if (dayofweek <= 0) {
7264:                    dayofweek = 7;
7265:                }
7266:
7267:                return l_ndays[dayofweek - 1];
7268:
7269:            } // getDay
7270:
7271:        } // CalendarAction
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.