Source Code Cross Referenced for SiteAction.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » site » 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.site.tool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


00001:        /**********************************************************************************
00002:         * $URL: https://source.sakaiproject.org/svn/site-manage/tags/sakai_2-4-1/site-manage-tool/tool/src/java/org/sakaiproject/site/tool/SiteAction.java $
00003:         * $Id: SiteAction.java 30494 2007-05-14 17:52:38Z ajpoland@iupui.edu $
00004:         ***********************************************************************************
00005:         *
00006:         * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
00007:         * 
00008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
00009:         * you may not use this file except in compliance with the License. 
00010:         * You may obtain a copy of the License at
00011:         * 
00012:         *      http://www.opensource.org/licenses/ecl1.php
00013:         * 
00014:         * Unless required by applicable law or agreed to in writing, software 
00015:         * distributed under the License is distributed on an "AS IS" BASIS, 
00016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
00017:         * See the License for the specific language governing permissions and 
00018:         * limitations under the License.
00019:         *
00020:         **********************************************************************************/package org.sakaiproject.site.tool;
00021:
00022:        import java.lang.reflect.Method;
00023:        import java.net.MalformedURLException;
00024:        import java.net.URL;
00025:        import java.text.Collator;
00026:        import java.util.ArrayList;
00027:        import java.util.Arrays;
00028:        import java.util.Calendar;
00029:        import java.util.Collection;
00030:        import java.util.Collections;
00031:        import java.util.Comparator;
00032:        import java.util.HashMap;
00033:        import java.util.HashSet;
00034:        import java.util.Hashtable;
00035:        import java.util.Iterator;
00036:        import java.util.List;
00037:        import java.util.ListIterator;
00038:        import java.util.Map;
00039:        import java.util.Random;
00040:        import java.util.Set;
00041:        import java.util.Vector;
00042:
00043:        import org.apache.commons.logging.Log;
00044:        import org.apache.commons.logging.LogFactory;
00045:        import org.sakaiproject.alias.api.Alias;
00046:        import org.sakaiproject.alias.cover.AliasService;
00047:        import org.sakaiproject.archive.api.ImportMetadata;
00048:        import org.sakaiproject.archive.cover.ArchiveService;
00049:        import org.sakaiproject.authz.api.AuthzGroup;
00050:        import org.sakaiproject.authz.api.AuthzPermissionException;
00051:        import org.sakaiproject.authz.api.GroupNotDefinedException;
00052:        import org.sakaiproject.authz.api.Member;
00053:        import org.sakaiproject.authz.api.PermissionsHelper;
00054:        import org.sakaiproject.authz.api.Role;
00055:        import org.sakaiproject.authz.cover.AuthzGroupService;
00056:        import org.sakaiproject.authz.cover.SecurityService;
00057:        import org.sakaiproject.cheftool.Context;
00058:        import org.sakaiproject.cheftool.JetspeedRunData;
00059:        import org.sakaiproject.cheftool.PagedResourceActionII;
00060:        import org.sakaiproject.cheftool.PortletConfig;
00061:        import org.sakaiproject.cheftool.RunData;
00062:        import org.sakaiproject.cheftool.VelocityPortlet;
00063:        import org.sakaiproject.cheftool.api.Menu;
00064:        import org.sakaiproject.cheftool.api.MenuItem;
00065:        import org.sakaiproject.cheftool.menu.MenuEntry;
00066:        import org.sakaiproject.cheftool.menu.MenuImpl;
00067:        import org.sakaiproject.component.cover.ComponentManager;
00068:        import org.sakaiproject.component.cover.ServerConfigurationService;
00069:        import org.sakaiproject.content.cover.ContentHostingService;
00070:        import org.sakaiproject.email.cover.EmailService;
00071:        import org.sakaiproject.entity.api.EntityProducer;
00072:        import org.sakaiproject.entity.api.EntityPropertyNotDefinedException;
00073:        import org.sakaiproject.entity.api.EntityPropertyTypeException;
00074:        import org.sakaiproject.entity.api.EntityTransferrer;
00075:        import org.sakaiproject.entity.api.ResourceProperties;
00076:        import org.sakaiproject.entity.api.ResourcePropertiesEdit;
00077:        import org.sakaiproject.entity.cover.EntityManager;
00078:        import org.sakaiproject.event.api.SessionState;
00079:        import org.sakaiproject.exception.IdInvalidException;
00080:        import org.sakaiproject.exception.IdUnusedException;
00081:        import org.sakaiproject.exception.IdUsedException;
00082:        import org.sakaiproject.exception.PermissionException;
00083:        import org.sakaiproject.id.cover.IdManager;
00084:        import org.sakaiproject.javax.PagingPosition;
00085:        import org.sakaiproject.mailarchive.api.MailArchiveService;
00086:        import org.sakaiproject.site.api.Group;
00087:        import org.sakaiproject.site.api.Site;
00088:        import org.sakaiproject.site.api.SitePage;
00089:        import org.sakaiproject.site.api.ToolConfiguration;
00090:        import org.sakaiproject.site.api.SiteService.SortType;
00091:        import org.sakaiproject.site.cover.SiteService;
00092:        import org.sakaiproject.sitemanage.api.SectionField;
00093:        import org.sakaiproject.sitemanage.api.SectionFieldManager;
00094:        import org.sakaiproject.util.SubjectAffiliates;
00095:        import org.sakaiproject.time.api.Time;
00096:        import org.sakaiproject.time.api.TimeBreakdown;
00097:        import org.sakaiproject.time.cover.TimeService;
00098:        import org.sakaiproject.tool.api.Tool;
00099:        import org.sakaiproject.tool.cover.SessionManager;
00100:        import org.sakaiproject.tool.cover.ToolManager;
00101:        import org.sakaiproject.user.api.User;
00102:        import org.sakaiproject.user.api.UserAlreadyDefinedException;
00103:        import org.sakaiproject.user.api.UserEdit;
00104:        import org.sakaiproject.user.api.UserIdInvalidException;
00105:        import org.sakaiproject.user.api.UserNotDefinedException;
00106:        import org.sakaiproject.user.api.UserPermissionException;
00107:        import org.sakaiproject.user.cover.UserDirectoryService;
00108:        import org.sakaiproject.util.ArrayUtil; // import org.sakaiproject.util.CourseIdGenerator;
00109:        import org.sakaiproject.util.FileItem;
00110:        import org.sakaiproject.util.ParameterParser;
00111:        import org.sakaiproject.util.ResourceLoader;
00112:        import org.sakaiproject.util.SortedIterator;
00113:        import org.sakaiproject.util.StringUtil;
00114:        import org.sakaiproject.util.Validator;
00115:
00116:        import org.sakaiproject.importer.api.ImportService;
00117:        import org.sakaiproject.importer.api.ImportDataSource;
00118:        import org.sakaiproject.importer.api.SakaiArchive;
00119:
00120:        import org.sakaiproject.coursemanagement.api.AcademicSession;
00121:        import org.sakaiproject.coursemanagement.api.CourseOffering;
00122:        import org.sakaiproject.coursemanagement.api.Section;
00123:        import org.sakaiproject.coursemanagement.api.Enrollment;
00124:        import org.sakaiproject.coursemanagement.api.Membership;
00125:        import org.sakaiproject.coursemanagement.api.exception.IdNotFoundException;
00126:        import org.sakaiproject.authz.api.GroupProvider;
00127:        import org.apache.velocity.tools.generic.SortTool;
00128:
00129:        /**
00130:         * <p>
00131:         * SiteAction controls the interface for worksite setup.
00132:         * </p>
00133:         */
00134:        public class SiteAction extends PagedResourceActionII {
00135:            /** Our logger. */
00136:            private static Log M_log = LogFactory.getLog(SiteAction.class);
00137:
00138:            private ImportService importService = org.sakaiproject.importer.cover.ImportService
00139:                    .getInstance();
00140:
00141:            /** portlet configuration parameter values* */
00142:            /** Resource bundle using current language locale */
00143:            private static ResourceLoader rb = new ResourceLoader(
00144:                    "sitesetupgeneric");
00145:
00146:            private org.sakaiproject.coursemanagement.api.CourseManagementService cms = (org.sakaiproject.coursemanagement.api.CourseManagementService) ComponentManager
00147:                    .get(org.sakaiproject.coursemanagement.api.CourseManagementService.class);
00148:
00149:            private org.sakaiproject.authz.api.GroupProvider groupProvider = (org.sakaiproject.authz.api.GroupProvider) ComponentManager
00150:                    .get(org.sakaiproject.authz.api.GroupProvider.class);
00151:
00152:            private org.sakaiproject.authz.api.AuthzGroupService authzGroupService = (org.sakaiproject.authz.api.AuthzGroupService) ComponentManager
00153:                    .get(org.sakaiproject.authz.api.AuthzGroupService.class);
00154:
00155:            private org.sakaiproject.sitemanage.api.SectionFieldManager sectionFieldManager = (org.sakaiproject.sitemanage.api.SectionFieldManager) ComponentManager
00156:                    .get(org.sakaiproject.sitemanage.api.SectionFieldManager.class);
00157:
00158:            private static final String SITE_MODE_SITESETUP = "sitesetup";
00159:
00160:            private static final String SITE_MODE_SITEINFO = "siteinfo";
00161:
00162:            private static final String STATE_SITE_MODE = "site_mode";
00163:
00164:            protected final static String[] TEMPLATE = {
00165:                    "-list",// 0
00166:                    "-type",
00167:                    "-newSiteInformation",
00168:                    "-newSiteFeatures",
00169:                    "-addRemoveFeature",
00170:                    "-addParticipant",
00171:                    "-removeParticipants",
00172:                    "-changeRoles",
00173:                    "-siteDeleteConfirm",
00174:                    "-publishUnpublish",
00175:                    "-newSiteConfirm",// 10
00176:                    "-newSitePublishUnpublish",
00177:                    "-siteInfo-list",// 12
00178:                    "-siteInfo-editInfo",
00179:                    "-siteInfo-editInfoConfirm",
00180:                    "-addRemoveFeatureConfirm",// 15
00181:                    "-publishUnpublish-sendEmail",
00182:                    "-publishUnpublish-confirm",
00183:                    "-siteInfo-editAccess",
00184:                    "-addParticipant-sameRole",
00185:                    "-addParticipant-differentRole",// 20
00186:                    "-addParticipant-notification",
00187:                    "-addParticipant-confirm",
00188:                    "-siteInfo-editAccess-globalAccess",
00189:                    "-siteInfo-editAccess-globalAccess-confirm",
00190:                    "-changeRoles-confirm",// 25
00191:                    "-modifyENW", "-importSites",
00192:                    "-siteInfo-import",
00193:                    "-siteInfo-duplicate",
00194:                    "",// 30
00195:                    "",// 31
00196:                    "",// 32
00197:                    "",// 33
00198:                    "",// 34
00199:                    "",// 35
00200:                    "-newSiteCourse",// 36
00201:                    "-newSiteCourseManual",// 37
00202:                    "",// 38
00203:                    "",// 39
00204:                    "",// 40
00205:                    "",// 41
00206:                    "-gradtoolsConfirm",// 42
00207:                    "-siteInfo-editClass",// 43
00208:                    "-siteInfo-addCourseConfirm",// 44
00209:                    "-siteInfo-importMtrlMaster", // 45 -- htripath for import
00210:                    // material from a file
00211:                    "-siteInfo-importMtrlCopy", // 46
00212:                    "-siteInfo-importMtrlCopyConfirm",
00213:                    "-siteInfo-importMtrlCopyConfirmMsg", // 48
00214:                    "-siteInfo-group", // 49
00215:                    "-siteInfo-groupedit", // 50
00216:                    "-siteInfo-groupDeleteConfirm", // 51,
00217:                    "", // 52 - no template; used by daisyf. for remove course section
00218:                    "-findCourse" // 53
00219:            };
00220:
00221:            /** Name of state attribute for Site instance id */
00222:            private static final String STATE_SITE_INSTANCE_ID = "site.instance.id";
00223:
00224:            /** Name of state attribute for Site Information */
00225:            private static final String STATE_SITE_INFO = "site.info";
00226:
00227:            /** Name of state attribute for CHEF site type */
00228:            private static final String STATE_SITE_TYPE = "site-type";
00229:
00230:            /** Name of state attribute for poissible site types */
00231:            private static final String STATE_SITE_TYPES = "site_types";
00232:
00233:            private static final String STATE_DEFAULT_SITE_TYPE = "default_site_type";
00234:
00235:            private static final String STATE_PUBLIC_CHANGEABLE_SITE_TYPES = "changeable_site_types";
00236:
00237:            private static final String STATE_PUBLIC_SITE_TYPES = "public_site_types";
00238:
00239:            private static final String STATE_PRIVATE_SITE_TYPES = "private_site_types";
00240:
00241:            private static final String STATE_DISABLE_JOINABLE_SITE_TYPE = "disable_joinable_site_types";
00242:
00243:            // Names of state attributes corresponding to properties of a site
00244:            private final static String PROP_SITE_CONTACT_EMAIL = "contact-email";
00245:
00246:            private final static String PROP_SITE_CONTACT_NAME = "contact-name";
00247:
00248:            private final static String PROP_SITE_TERM = "term";
00249:
00250:            private final static String PROP_SITE_TERM_EID = "term_eid";
00251:
00252:            /**
00253:             * Name of the state attribute holding the site list column list is sorted
00254:             * by
00255:             */
00256:            private static final String SORTED_BY = "site.sorted.by";
00257:
00258:            /** the list of criteria for sorting */
00259:            private static final String SORTED_BY_TITLE = "title";
00260:
00261:            private static final String SORTED_BY_DESCRIPTION = "description";
00262:
00263:            private static final String SORTED_BY_TYPE = "type";
00264:
00265:            private static final String SORTED_BY_STATUS = "status";
00266:
00267:            private static final String SORTED_BY_CREATION_DATE = "creationdate";
00268:
00269:            private static final String SORTED_BY_JOINABLE = "joinable";
00270:
00271:            private static final String SORTED_BY_PARTICIPANT_NAME = "participant_name";
00272:
00273:            private static final String SORTED_BY_PARTICIPANT_UNIQNAME = "participant_uniqname";
00274:
00275:            private static final String SORTED_BY_PARTICIPANT_ROLE = "participant_role";
00276:
00277:            private static final String SORTED_BY_PARTICIPANT_ID = "participant_id";
00278:
00279:            private static final String SORTED_BY_PARTICIPANT_COURSE = "participant_course";
00280:
00281:            private static final String SORTED_BY_PARTICIPANT_CREDITS = "participant_credits";
00282:
00283:            private static final String SORTED_BY_MEMBER_NAME = "member_name";
00284:
00285:            /** Name of the state attribute holding the site list column to sort by */
00286:            private static final String SORTED_ASC = "site.sort.asc";
00287:
00288:            /** State attribute for list of sites to be deleted. */
00289:            private static final String STATE_SITE_REMOVALS = "site.removals";
00290:
00291:            /** Name of the state attribute holding the site list View selected */
00292:            private static final String STATE_VIEW_SELECTED = "site.view.selected";
00293:
00294:            /** Names of lists related to tools */
00295:            private static final String STATE_TOOL_REGISTRATION_LIST = "toolRegistrationList";
00296:
00297:            private static final String STATE_TOOL_REGISTRATION_SELECTED_LIST = "toolRegistrationSelectedList";
00298:
00299:            private static final String STATE_TOOL_REGISTRATION_OLD_SELECTED_LIST = "toolRegistrationOldSelectedList";
00300:
00301:            private static final String STATE_TOOL_REGISTRATION_OLD_SELECTED_HOME = "toolRegistrationOldSelectedHome";
00302:
00303:            private static final String STATE_TOOL_EMAIL_ADDRESS = "toolEmailAddress";
00304:
00305:            private static final String STATE_TOOL_HOME_SELECTED = "toolHomeSelected";
00306:
00307:            private static final String STATE_PROJECT_TOOL_LIST = "projectToolList";
00308:
00309:            private final static String STATE_NEWS_TITLES = "newstitles";
00310:
00311:            private final static String STATE_NEWS_URLS = "newsurls";
00312:
00313:            private final static String NEWS_DEFAULT_TITLE = ServerConfigurationService
00314:                    .getString("news.title");
00315:
00316:            private final static String NEWS_DEFAULT_URL = ServerConfigurationService
00317:                    .getString("news.feedURL");
00318:
00319:            private final static String STATE_WEB_CONTENT_TITLES = "webcontenttitles";
00320:
00321:            private final static String STATE_WEB_CONTENT_URLS = "wcUrls";
00322:
00323:            private final static String WEB_CONTENT_DEFAULT_TITLE = "Web Content";
00324:
00325:            private final static String WEB_CONTENT_DEFAULT_URL = "http://";
00326:
00327:            private final static String STATE_SITE_QUEST_UNIQNAME = "site_quest_uniqname";
00328:
00329:            // %%% get rid of the IdAndText tool lists and just use ToolConfiguration or
00330:            // ToolRegistration lists
00331:            // %%% same for CourseItems
00332:
00333:            // Names for other state attributes that are lists
00334:            private final static String STATE_WORKSITE_SETUP_PAGE_LIST = "wSetupPageList"; // the
00335:
00336:            // list
00337:            // of
00338:            // site
00339:            // pages
00340:            // consistent
00341:            // with
00342:            // Worksite
00343:            // Setup
00344:            // page
00345:            // patterns
00346:
00347:            /**
00348:             * The name of the state form field containing additional information for a
00349:             * course request
00350:             */
00351:            private static final String FORM_ADDITIONAL = "form.additional";
00352:
00353:            /** %%% in transition from putting all form variables in state */
00354:            private final static String FORM_TITLE = "form_title";
00355:
00356:            private final static String FORM_DESCRIPTION = "form_description";
00357:
00358:            private final static String FORM_HONORIFIC = "form_honorific";
00359:
00360:            private final static String FORM_INSTITUTION = "form_institution";
00361:
00362:            private final static String FORM_SUBJECT = "form_subject";
00363:
00364:            private final static String FORM_PHONE = "form_phone";
00365:
00366:            private final static String FORM_EMAIL = "form_email";
00367:
00368:            private final static String FORM_REUSE = "form_reuse";
00369:
00370:            private final static String FORM_RELATED_CLASS = "form_related_class";
00371:
00372:            private final static String FORM_RELATED_PROJECT = "form_related_project";
00373:
00374:            private final static String FORM_NAME = "form_name";
00375:
00376:            private final static String FORM_SHORT_DESCRIPTION = "form_short_description";
00377:
00378:            private final static String FORM_ICON_URL = "iconUrl";
00379:
00380:            /** site info edit form variables */
00381:            private final static String FORM_SITEINFO_TITLE = "siteinfo_title";
00382:
00383:            private final static String FORM_SITEINFO_TERM = "siteinfo_term";
00384:
00385:            private final static String FORM_SITEINFO_DESCRIPTION = "siteinfo_description";
00386:
00387:            private final static String FORM_SITEINFO_SHORT_DESCRIPTION = "siteinfo_short_description";
00388:
00389:            private final static String FORM_SITEINFO_SKIN = "siteinfo_skin";
00390:
00391:            private final static String FORM_SITEINFO_INCLUDE = "siteinfo_include";
00392:
00393:            private final static String FORM_SITEINFO_ICON_URL = "siteinfo_icon_url";
00394:
00395:            private final static String FORM_SITEINFO_CONTACT_NAME = "siteinfo_contact_name";
00396:
00397:            private final static String FORM_SITEINFO_CONTACT_EMAIL = "siteinfo_contact_email";
00398:
00399:            private final static String FORM_WILL_NOTIFY = "form_will_notify";
00400:
00401:            /** Context action */
00402:            private static final String CONTEXT_ACTION = "SiteAction";
00403:
00404:            /** The name of the Attribute for display template index */
00405:            private static final String STATE_TEMPLATE_INDEX = "site.templateIndex";
00406:
00407:            /** State attribute for state initialization. */
00408:            private static final String STATE_INITIALIZED = "site.initialized";
00409:
00410:            /** The action for menu */
00411:            private static final String STATE_ACTION = "site.action";
00412:
00413:            /** The user copyright string */
00414:            private static final String STATE_MY_COPYRIGHT = "resources.mycopyright";
00415:
00416:            /** The copyright character */
00417:            private static final String COPYRIGHT_SYMBOL = "copyright (c)";
00418:
00419:            /** The null/empty string */
00420:            private static final String NULL_STRING = "";
00421:
00422:            /** The state attribute alerting user of a sent course request */
00423:            private static final String REQUEST_SENT = "site.request.sent";
00424:
00425:            /** The state attributes in the make public vm */
00426:            private static final String STATE_JOINABLE = "state_joinable";
00427:
00428:            private static final String STATE_JOINERROLE = "state_joinerRole";
00429:
00430:            /** the list of selected user */
00431:            private static final String STATE_SELECTED_USER_LIST = "state_selected_user_list";
00432:
00433:            private static final String STATE_SELECTED_PARTICIPANT_ROLES = "state_selected_participant_roles";
00434:
00435:            private static final String STATE_SELECTED_PARTICIPANTS = "state_selected_participants";
00436:
00437:            private static final String STATE_PARTICIPANT_LIST = "state_participant_list";
00438:
00439:            private static final String STATE_ADD_PARTICIPANTS = "state_add_participants";
00440:
00441:            /** for changing participant roles */
00442:            private static final String STATE_CHANGEROLE_SAMEROLE = "state_changerole_samerole";
00443:
00444:            private static final String STATE_CHANGEROLE_SAMEROLE_ROLE = "state_changerole_samerole_role";
00445:
00446:            /** for remove user */
00447:            private static final String STATE_REMOVEABLE_USER_LIST = "state_removeable_user_list";
00448:
00449:            private static final String STATE_IMPORT = "state_import";
00450:
00451:            private static final String STATE_IMPORT_SITES = "state_import_sites";
00452:
00453:            private static final String STATE_IMPORT_SITE_TOOL = "state_import_site_tool";
00454:
00455:            /** for navigating between sites in site list */
00456:            private static final String STATE_SITES = "state_sites";
00457:
00458:            private static final String STATE_PREV_SITE = "state_prev_site";
00459:
00460:            private static final String STATE_NEXT_SITE = "state_next_site";
00461:
00462:            /** for course information */
00463:            private final static String STATE_TERM_COURSE_LIST = "state_term_course_list";
00464:
00465:            private final static String STATE_TERM_COURSE_HASH = "state_term_course_hash";
00466:
00467:            private final static String STATE_TERM_SELECTED = "state_term_selected";
00468:
00469:            private final static String STATE_INSTRUCTOR_SELECTED = "state_instructor_selected";
00470:
00471:            private final static String STATE_FUTURE_TERM_SELECTED = "state_future_term_selected";
00472:
00473:            private final static String STATE_ADD_CLASS_PROVIDER = "state_add_class_provider";
00474:
00475:            private final static String STATE_ADD_CLASS_PROVIDER_CHOSEN = "state_add_class_provider_chosen";
00476:
00477:            private final static String STATE_ADD_CLASS_MANUAL = "state_add_class_manual";
00478:
00479:            private final static String STATE_AUTO_ADD = "state_auto_add";
00480:
00481:            private final static String STATE_MANUAL_ADD_COURSE_NUMBER = "state_manual_add_course_number";
00482:
00483:            private final static String STATE_MANUAL_ADD_COURSE_FIELDS = "state_manual_add_course_fields";
00484:
00485:            public final static String PROP_SITE_REQUEST_COURSE = "site-request-course-sections";
00486:
00487:            public final static String SITE_PROVIDER_COURSE_LIST = "site_provider_course_list";
00488:
00489:            public final static String SITE_MANUAL_COURSE_LIST = "site_manual_course_list";
00490:
00491:            private final static String STATE_SUBJECT_AFFILIATES = "site.subject.affiliates";
00492:
00493:            private final static String STATE_ICONS = "icons";
00494:
00495:            // site template used to create a UM Grad Tools student site
00496:            public static final String SITE_GTS_TEMPLATE = "!gtstudent";
00497:
00498:            // the type used to identify a UM Grad Tools student site
00499:            public static final String SITE_TYPE_GRADTOOLS_STUDENT = "GradToolsStudent";
00500:
00501:            // list of UM Grad Tools site types for editing
00502:            public static final String GRADTOOLS_SITE_TYPES = "gradtools_site_types";
00503:
00504:            public static final String SITE_DUPLICATED = "site_duplicated";
00505:
00506:            public static final String SITE_DUPLICATED_NAME = "site_duplicated_named";
00507:
00508:            // used for site creation wizard title
00509:            public static final String SITE_CREATE_TOTAL_STEPS = "site_create_total_steps";
00510:
00511:            public static final String SITE_CREATE_CURRENT_STEP = "site_create_current_step";
00512:
00513:            // types of site whose title can be editable
00514:            public static final String TITLE_EDITABLE_SITE_TYPE = "title_editable_site_type";
00515:
00516:            // types of site where site view roster permission is editable
00517:            public static final String EDIT_VIEW_ROSTER_SITE_TYPE = "edit_view_roster_site_type";
00518:
00519:            // htripath : for import material from file - classic import
00520:            private static final String ALL_ZIP_IMPORT_SITES = "allzipImports";
00521:
00522:            private static final String FINAL_ZIP_IMPORT_SITES = "finalzipImports";
00523:
00524:            private static final String DIRECT_ZIP_IMPORT_SITES = "directzipImports";
00525:
00526:            private static final String CLASSIC_ZIP_FILE_NAME = "classicZipFileName";
00527:
00528:            private static final String SESSION_CONTEXT_ID = "sessionContextId";
00529:
00530:            // page size for worksite setup tool
00531:            private static final String STATE_PAGESIZE_SITESETUP = "state_pagesize_sitesetup";
00532:
00533:            // page size for site info tool
00534:            private static final String STATE_PAGESIZE_SITEINFO = "state_pagesize_siteinfo";
00535:
00536:            // group info
00537:            private static final String STATE_GROUP_INSTANCE_ID = "state_group_instance_id";
00538:
00539:            private static final String STATE_GROUP_TITLE = "state_group_title";
00540:
00541:            private static final String STATE_GROUP_DESCRIPTION = "state_group_description";
00542:
00543:            private static final String STATE_GROUP_MEMBERS = "state_group_members";
00544:
00545:            private static final String STATE_GROUP_REMOVE = "state_group_remove";
00546:
00547:            private static final String GROUP_PROP_WSETUP_CREATED = "group_prop_wsetup_created";
00548:
00549:            private static final String IMPORT_DATA_SOURCE = "import_data_source";
00550:
00551:            private static final String EMAIL_CHAR = "@";
00552:
00553:            // Special tool id for Home page
00554:            private static final String HOME_TOOL_ID = "home";
00555:
00556:            private static final String STATE_CM_LEVELS = "site.cm.levels";
00557:
00558:            private static final String STATE_CM_LEVEL_SELECTIONS = "site.cm.level.selections";
00559:
00560:            private static final String STATE_CM_SELECTED_SECTION = "site.cm.selectedSection";
00561:
00562:            private static final String STATE_CM_REQUESTED_SECTIONS = "site.cm.requested";
00563:
00564:            private static final String STATE_PROVIDER_SECTION_LIST = "site_provider_section_list";
00565:
00566:            private static final String STATE_CM_CURRENT_USERID = "site_cm_current_userId";
00567:
00568:            private static final String STATE_CM_AUTHORIZER_LIST = "site_cm_authorizer_list";
00569:
00570:            private static final String STATE_CM_AUTHORIZER_SECTIONS = "site_cm_authorizer_sections";
00571:
00572:            private String cmSubjectCategory;
00573:
00574:            private boolean warnedNoSubjectCategory = false;
00575:
00576:            // the string marks the protocol part in url
00577:            private static final String PROTOCOL_STRING = "://";
00578:
00579:            /**
00580:             * Populate the state object, if needed.
00581:             */
00582:            protected void initState(SessionState state,
00583:                    VelocityPortlet portlet, JetspeedRunData rundata) {
00584:                super .initState(state, portlet, rundata);
00585:
00586:                // store current userId in state
00587:                User user = UserDirectoryService.getCurrentUser();
00588:                String userId = user.getEid();
00589:                state.setAttribute(STATE_CM_CURRENT_USERID, userId);
00590:
00591:                PortletConfig config = portlet.getPortletConfig();
00592:
00593:                // types of sites that can either be public or private
00594:                String changeableTypes = StringUtil.trimToNull(config
00595:                        .getInitParameter("publicChangeableSiteTypes"));
00596:                if (state.getAttribute(STATE_PUBLIC_CHANGEABLE_SITE_TYPES) == null) {
00597:                    if (changeableTypes != null) {
00598:                        state.setAttribute(STATE_PUBLIC_CHANGEABLE_SITE_TYPES,
00599:                                new ArrayList(Arrays.asList(changeableTypes
00600:                                        .split(","))));
00601:                    } else {
00602:                        state.setAttribute(STATE_PUBLIC_CHANGEABLE_SITE_TYPES,
00603:                                new Vector());
00604:                    }
00605:                }
00606:
00607:                // type of sites that are always public
00608:                String publicTypes = StringUtil.trimToNull(config
00609:                        .getInitParameter("publicSiteTypes"));
00610:                if (state.getAttribute(STATE_PUBLIC_SITE_TYPES) == null) {
00611:                    if (publicTypes != null) {
00612:                        state.setAttribute(STATE_PUBLIC_SITE_TYPES,
00613:                                new ArrayList(Arrays.asList(publicTypes
00614:                                        .split(","))));
00615:                    } else {
00616:                        state.setAttribute(STATE_PUBLIC_SITE_TYPES,
00617:                                new Vector());
00618:                    }
00619:                }
00620:
00621:                // types of sites that are always private
00622:                String privateTypes = StringUtil.trimToNull(config
00623:                        .getInitParameter("privateSiteTypes"));
00624:                if (state.getAttribute(STATE_PRIVATE_SITE_TYPES) == null) {
00625:                    if (privateTypes != null) {
00626:                        state.setAttribute(STATE_PRIVATE_SITE_TYPES,
00627:                                new ArrayList(Arrays.asList(privateTypes
00628:                                        .split(","))));
00629:                    } else {
00630:                        state.setAttribute(STATE_PRIVATE_SITE_TYPES,
00631:                                new Vector());
00632:                    }
00633:                }
00634:
00635:                // default site type
00636:                String defaultType = StringUtil.trimToNull(config
00637:                        .getInitParameter("defaultSiteType"));
00638:                if (state.getAttribute(STATE_DEFAULT_SITE_TYPE) == null) {
00639:                    if (defaultType != null) {
00640:                        state
00641:                                .setAttribute(STATE_DEFAULT_SITE_TYPE,
00642:                                        defaultType);
00643:                    } else {
00644:                        state.setAttribute(STATE_PRIVATE_SITE_TYPES,
00645:                                new Vector());
00646:                    }
00647:                }
00648:
00649:                // certain type(s) of site cannot get its "joinable" option set
00650:                if (state.getAttribute(STATE_DISABLE_JOINABLE_SITE_TYPE) == null) {
00651:                    if (ServerConfigurationService
00652:                            .getStrings("wsetup.disable.joinable") != null) {
00653:                        state
00654:                                .setAttribute(
00655:                                        STATE_DISABLE_JOINABLE_SITE_TYPE,
00656:                                        new ArrayList(
00657:                                                Arrays
00658:                                                        .asList(ServerConfigurationService
00659:                                                                .getStrings("wsetup.disable.joinable"))));
00660:                    } else {
00661:                        state.setAttribute(STATE_DISABLE_JOINABLE_SITE_TYPE,
00662:                                new Vector());
00663:                    }
00664:                }
00665:
00666:                if (state.getAttribute(STATE_TOP_PAGE_MESSAGE) == null) {
00667:                    state.setAttribute(STATE_TOP_PAGE_MESSAGE, new Integer(0));
00668:                }
00669:
00670:                // affiliates if any
00671:                if (state.getAttribute(STATE_SUBJECT_AFFILIATES) == null) {
00672:                    setupSubjectAffiliates(state);
00673:                }
00674:
00675:                // skins if any
00676:                if (state.getAttribute(STATE_ICONS) == null) {
00677:                    setupIcons(state);
00678:                }
00679:
00680:                if (state.getAttribute(GRADTOOLS_SITE_TYPES) == null) {
00681:                    List gradToolsSiteTypes = new Vector();
00682:                    if (ServerConfigurationService
00683:                            .getStrings("gradToolsSiteType") != null) {
00684:                        gradToolsSiteTypes = new ArrayList(Arrays
00685:                                .asList(ServerConfigurationService
00686:                                        .getStrings("gradToolsSiteType")));
00687:                    }
00688:                    state
00689:                            .setAttribute(GRADTOOLS_SITE_TYPES,
00690:                                    gradToolsSiteTypes);
00691:                }
00692:
00693:                if (ServerConfigurationService
00694:                        .getStrings("titleEditableSiteType") != null) {
00695:                    state.setAttribute(TITLE_EDITABLE_SITE_TYPE, new ArrayList(
00696:                            Arrays.asList(ServerConfigurationService
00697:                                    .getStrings("titleEditableSiteType"))));
00698:                } else {
00699:                    state.setAttribute(TITLE_EDITABLE_SITE_TYPE, new Vector());
00700:                }
00701:
00702:                if (state.getAttribute(EDIT_VIEW_ROSTER_SITE_TYPE) == null) {
00703:                    List siteTypes = new Vector();
00704:                    if (ServerConfigurationService
00705:                            .getStrings("editViewRosterSiteType") != null) {
00706:                        siteTypes = new ArrayList(Arrays
00707:                                .asList(ServerConfigurationService
00708:                                        .getStrings("editViewRosterSiteType")));
00709:                    }
00710:                    state.setAttribute(EDIT_VIEW_ROSTER_SITE_TYPE, siteTypes);
00711:                }
00712:
00713:                // get site tool mode from tool registry
00714:                String site_mode = portlet.getPortletConfig().getInitParameter(
00715:                        STATE_SITE_MODE);
00716:                state.setAttribute(STATE_SITE_MODE, site_mode);
00717:
00718:            } // initState
00719:
00720:            /**
00721:             * cleanState removes the current site instance and it's properties from
00722:             * state
00723:             */
00724:            private void cleanState(SessionState state) {
00725:                state.removeAttribute(STATE_SITE_INSTANCE_ID);
00726:                state.removeAttribute(STATE_SITE_INFO);
00727:                state.removeAttribute(STATE_SITE_TYPE);
00728:                state.removeAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST);
00729:                state
00730:                        .removeAttribute(STATE_TOOL_REGISTRATION_OLD_SELECTED_LIST);
00731:                state
00732:                        .removeAttribute(STATE_TOOL_REGISTRATION_OLD_SELECTED_HOME);
00733:                state.removeAttribute(STATE_TOOL_EMAIL_ADDRESS);
00734:                state.removeAttribute(STATE_TOOL_HOME_SELECTED);
00735:                state.removeAttribute(STATE_SELECTED_USER_LIST);
00736:                state.removeAttribute(STATE_JOINABLE);
00737:                state.removeAttribute(STATE_JOINERROLE);
00738:                state.removeAttribute(STATE_NEWS_TITLES);
00739:                state.removeAttribute(STATE_NEWS_URLS);
00740:                state.removeAttribute(STATE_WEB_CONTENT_TITLES);
00741:                state.removeAttribute(STATE_WEB_CONTENT_URLS);
00742:                state.removeAttribute(STATE_SITE_QUEST_UNIQNAME);
00743:                state.removeAttribute(STATE_IMPORT);
00744:                state.removeAttribute(STATE_IMPORT_SITES);
00745:                state.removeAttribute(STATE_IMPORT_SITE_TOOL);
00746:
00747:                // remove those state attributes related to course site creation
00748:                state.removeAttribute(STATE_TERM_COURSE_LIST);
00749:                state.removeAttribute(STATE_TERM_COURSE_HASH);
00750:                state.removeAttribute(STATE_TERM_SELECTED);
00751:                state.removeAttribute(STATE_INSTRUCTOR_SELECTED);
00752:                state.removeAttribute(STATE_FUTURE_TERM_SELECTED);
00753:                state.removeAttribute(STATE_ADD_CLASS_PROVIDER);
00754:                state.removeAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN);
00755:                state.removeAttribute(STATE_ADD_CLASS_MANUAL);
00756:                state.removeAttribute(STATE_AUTO_ADD);
00757:                state.removeAttribute(STATE_MANUAL_ADD_COURSE_NUMBER);
00758:                state.removeAttribute(STATE_MANUAL_ADD_COURSE_FIELDS);
00759:                state.removeAttribute(SITE_CREATE_TOTAL_STEPS);
00760:                state.removeAttribute(SITE_CREATE_CURRENT_STEP);
00761:                state.removeAttribute(STATE_PROVIDER_SECTION_LIST);
00762:                state.removeAttribute(STATE_CM_LEVELS);
00763:                state.removeAttribute(STATE_CM_LEVEL_SELECTIONS);
00764:                state.removeAttribute(STATE_CM_SELECTED_SECTION);
00765:                state.removeAttribute(STATE_CM_REQUESTED_SECTIONS);
00766:                state.removeAttribute(STATE_CM_CURRENT_USERID);
00767:                state.removeAttribute(STATE_CM_AUTHORIZER_LIST);
00768:                state.removeAttribute(STATE_CM_AUTHORIZER_SECTIONS);
00769:                state.removeAttribute(FORM_ADDITIONAL); // don't we need to clena this
00770:                // too? -daisyf
00771:
00772:            } // cleanState
00773:
00774:            /**
00775:             * Fire up the permissions editor
00776:             */
00777:            public void doPermissions(RunData data, Context context) {
00778:                // get into helper mode with this helper tool
00779:                startHelper(data.getRequest(), "sakai.permissions.helper");
00780:
00781:                SessionState state = ((JetspeedRunData) data)
00782:                        .getPortletSessionState(((JetspeedRunData) data)
00783:                                .getJs_peid());
00784:
00785:                String contextString = ToolManager.getCurrentPlacement()
00786:                        .getContext();
00787:                String siteRef = SiteService.siteReference(contextString);
00788:
00789:                // if it is in Worksite setup tool, pass the selected site's reference
00790:                if (state.getAttribute(STATE_SITE_MODE) != null
00791:                        && ((String) state.getAttribute(STATE_SITE_MODE))
00792:                                .equals(SITE_MODE_SITESETUP)) {
00793:                    if (state.getAttribute(STATE_SITE_INSTANCE_ID) != null) {
00794:                        Site s = getStateSite(state);
00795:                        if (s != null) {
00796:                            siteRef = s.getReference();
00797:                        }
00798:                    }
00799:                }
00800:
00801:                // setup for editing the permissions of the site for this tool, using
00802:                // the roles of this site, too
00803:                state.setAttribute(PermissionsHelper.TARGET_REF, siteRef);
00804:
00805:                // ... with this description
00806:                state.setAttribute(PermissionsHelper.DESCRIPTION, rb
00807:                        .getString("setperfor")
00808:                        + " " + SiteService.getSiteDisplay(contextString));
00809:
00810:                // ... showing only locks that are prpefixed with this
00811:                state.setAttribute(PermissionsHelper.PREFIX, "site.");
00812:
00813:            } // doPermissions
00814:
00815:            /**
00816:             * Build the context for normal display
00817:             */
00818:            public String buildMainPanelContext(VelocityPortlet portlet,
00819:                    Context context, RunData data, SessionState state) {
00820:                context.put("tlang", rb);
00821:                // TODO: what is all this doing? if we are in helper mode, we are
00822:                // already setup and don't get called here now -ggolden
00823:                /*
00824:                 * String helperMode = (String)
00825:                 * state.getAttribute(PermissionsAction.STATE_MODE); if (helperMode !=
00826:                 * null) { Site site = getStateSite(state); if (site != null) { if
00827:                 * (site.getType() != null && ((List)
00828:                 * state.getAttribute(EDIT_VIEW_ROSTER_SITE_TYPE)).contains(site.getType())) {
00829:                 * context.put("editViewRoster", Boolean.TRUE); } else {
00830:                 * context.put("editViewRoster", Boolean.FALSE); } } else {
00831:                 * context.put("editViewRoster", Boolean.FALSE); } // for new, don't
00832:                 * show site.del in Permission page context.put("hiddenLock",
00833:                 * "site.del");
00834:                 * 
00835:                 * String template = PermissionsAction.buildHelperContext(portlet,
00836:                 * context, data, state); if (template == null) { addAlert(state,
00837:                 * rb.getString("theisa")); } else { return template; } }
00838:                 */
00839:
00840:                String template = null;
00841:                context.put("action", CONTEXT_ACTION);
00842:
00843:                // updatePortlet(state, portlet, data);
00844:                if (state.getAttribute(STATE_INITIALIZED) == null) {
00845:                    init(portlet, data, state);
00846:                }
00847:                int index = Integer.valueOf(
00848:                        (String) state.getAttribute(STATE_TEMPLATE_INDEX))
00849:                        .intValue();
00850:                template = buildContextForTemplate(index, portlet, context,
00851:                        data, state);
00852:                return template;
00853:
00854:            } // buildMainPanelContext
00855:
00856:            /**
00857:             * Build the context for each template using template_index parameter passed
00858:             * in a form hidden field. Each case is associated with a template. (Not all
00859:             * templates implemented). See String[] TEMPLATES.
00860:             * 
00861:             * @param index
00862:             *            is the number contained in the template's template_index
00863:             */
00864:
00865:            private String buildContextForTemplate(int index,
00866:                    VelocityPortlet portlet, Context context, RunData data,
00867:                    SessionState state) {
00868:                String realmId = "";
00869:                String site_type = "";
00870:                String sortedBy = "";
00871:                String sortedAsc = "";
00872:                ParameterParser params = data.getParameters();
00873:                context.put("tlang", rb);
00874:                context.put("alertMessage", state.getAttribute(STATE_MESSAGE));
00875:
00876:                // If cleanState() has removed SiteInfo, get a new instance into state
00877:                SiteInfo siteInfo = new SiteInfo();
00878:                if (state.getAttribute(STATE_SITE_INFO) != null) {
00879:                    siteInfo = (SiteInfo) state.getAttribute(STATE_SITE_INFO);
00880:                } else {
00881:                    state.setAttribute(STATE_SITE_INFO, siteInfo);
00882:                }
00883:                // Lists used in more than one template
00884:
00885:                // Access
00886:                List roles = new Vector();
00887:
00888:                // the hashtables for News and Web Content tools
00889:                Hashtable newsTitles = new Hashtable();
00890:                Hashtable newsUrls = new Hashtable();
00891:                Hashtable wcTitles = new Hashtable();
00892:                Hashtable wcUrls = new Hashtable();
00893:
00894:                List toolRegistrationList = new Vector();
00895:                List toolRegistrationSelectedList = new Vector();
00896:
00897:                ResourceProperties siteProperties = null;
00898:
00899:                // for showing site creation steps
00900:                if (state.getAttribute(SITE_CREATE_TOTAL_STEPS) != null) {
00901:                    context.put("totalSteps", state
00902:                            .getAttribute(SITE_CREATE_TOTAL_STEPS));
00903:                }
00904:                if (state.getAttribute(SITE_CREATE_CURRENT_STEP) != null) {
00905:                    context.put("step", state
00906:                            .getAttribute(SITE_CREATE_CURRENT_STEP));
00907:                }
00908:
00909:                String hasGradSites = ServerConfigurationService.getString(
00910:                        "withDissertation", Boolean.FALSE.toString());
00911:
00912:                Site site = getStateSite(state);
00913:
00914:                switch (index) {
00915:                case 0:
00916:                    /*
00917:                     * buildContextForTemplate chef_site-list.vm
00918:                     * 
00919:                     */
00920:                    // site types
00921:                    List sTypes = (List) state.getAttribute(STATE_SITE_TYPES);
00922:
00923:                    // make sure auto-updates are enabled
00924:                    Hashtable views = new Hashtable();
00925:                    if (SecurityService.isSuperUser()) {
00926:                        views.put(rb.getString("java.allmy"), rb
00927:                                .getString("java.allmy"));
00928:                        views.put(rb.getString("java.my") + " "
00929:                                + rb.getString("java.sites"), rb
00930:                                .getString("java.my"));
00931:                        for (int sTypeIndex = 0; sTypeIndex < sTypes.size(); sTypeIndex++) {
00932:                            String type = (String) sTypes.get(sTypeIndex);
00933:                            views.put(type + " " + rb.getString("java.sites"),
00934:                                    type);
00935:                        }
00936:                        if (hasGradSites.equalsIgnoreCase("true")) {
00937:                            views.put(rb.getString("java.gradtools") + " "
00938:                                    + rb.getString("java.sites"), rb
00939:                                    .getString("java.gradtools"));
00940:                        }
00941:                        if (state.getAttribute(STATE_VIEW_SELECTED) == null) {
00942:                            state.setAttribute(STATE_VIEW_SELECTED, rb
00943:                                    .getString("java.allmy"));
00944:                        }
00945:                        context.put("superUser", Boolean.TRUE);
00946:                    } else {
00947:                        context.put("superUser", Boolean.FALSE);
00948:                        views.put(rb.getString("java.allmy"), rb
00949:                                .getString("java.allmy"));
00950:
00951:                        // if there is a GradToolsStudent choice inside
00952:                        boolean remove = false;
00953:                        if (hasGradSites.equalsIgnoreCase("true")) {
00954:                            try {
00955:                                // the Grad Tools site option is only presented to
00956:                                // GradTools Candidates
00957:                                String userId = StringUtil
00958:                                        .trimToZero(SessionManager
00959:                                                .getCurrentSessionUserId());
00960:
00961:                                // am I a grad student?
00962:                                if (!isGradToolsCandidate(userId)) {
00963:                                    // not a gradstudent
00964:                                    remove = true;
00965:                                }
00966:                            } catch (Exception e) {
00967:                                remove = true;
00968:                            }
00969:                        } else {
00970:                            // not support for dissertation sites
00971:                            remove = true;
00972:                        }
00973:                        // do not show this site type in views
00974:                        // sTypes.remove(new String(SITE_TYPE_GRADTOOLS_STUDENT));
00975:
00976:                        for (int sTypeIndex = 0; sTypeIndex < sTypes.size(); sTypeIndex++) {
00977:                            String type = (String) sTypes.get(sTypeIndex);
00978:                            if (!type.equals(SITE_TYPE_GRADTOOLS_STUDENT)) {
00979:                                views.put(type + " "
00980:                                        + rb.getString("java.sites"), type);
00981:                            }
00982:                        }
00983:                        if (!remove) {
00984:                            views.put(rb.getString("java.gradtools") + " "
00985:                                    + rb.getString("java.sites"), rb
00986:                                    .getString("java.gradtools"));
00987:                        }
00988:
00989:                        // default view
00990:                        if (state.getAttribute(STATE_VIEW_SELECTED) == null) {
00991:                            state.setAttribute(STATE_VIEW_SELECTED, rb
00992:                                    .getString("java.allmy"));
00993:                        }
00994:                    }
00995:                    context.put("views", views);
00996:
00997:                    if (state.getAttribute(STATE_VIEW_SELECTED) != null) {
00998:                        context.put("viewSelected", (String) state
00999:                                .getAttribute(STATE_VIEW_SELECTED));
01000:                    }
01001:
01002:                    String search = (String) state.getAttribute(STATE_SEARCH);
01003:                    context.put("search_term", search);
01004:
01005:                    sortedBy = (String) state.getAttribute(SORTED_BY);
01006:                    if (sortedBy == null) {
01007:                        state.setAttribute(SORTED_BY, SortType.TITLE_ASC
01008:                                .toString());
01009:                        sortedBy = SortType.TITLE_ASC.toString();
01010:                    }
01011:
01012:                    sortedAsc = (String) state.getAttribute(SORTED_ASC);
01013:                    if (sortedAsc == null) {
01014:                        sortedAsc = Boolean.TRUE.toString();
01015:                        state.setAttribute(SORTED_ASC, sortedAsc);
01016:                    }
01017:                    if (sortedBy != null)
01018:                        context.put("currentSortedBy", sortedBy);
01019:                    if (sortedAsc != null)
01020:                        context.put("currentSortAsc", sortedAsc);
01021:
01022:                    String portalUrl = ServerConfigurationService
01023:                            .getPortalUrl();
01024:                    context.put("portalUrl", portalUrl);
01025:
01026:                    List sites = prepPage(state);
01027:                    state.setAttribute(STATE_SITES, sites);
01028:                    context.put("sites", sites);
01029:
01030:                    context.put("totalPageNumber", new Integer(
01031:                            totalPageNumber(state)));
01032:                    context.put("searchString", state
01033:                            .getAttribute(STATE_SEARCH));
01034:                    context.put("form_search", FORM_SEARCH);
01035:                    context.put("formPageNumber", FORM_PAGE_NUMBER);
01036:                    context.put("prev_page_exists", state
01037:                            .getAttribute(STATE_PREV_PAGE_EXISTS));
01038:                    context.put("next_page_exists", state
01039:                            .getAttribute(STATE_NEXT_PAGE_EXISTS));
01040:                    context.put("current_page", state
01041:                            .getAttribute(STATE_CURRENT_PAGE));
01042:
01043:                    // put the service in the context (used for allow update calls on
01044:                    // each site)
01045:                    context.put("service", SiteService.getInstance());
01046:                    context.put("sortby_title", SortType.TITLE_ASC.toString());
01047:                    context.put("sortby_type", SortType.TYPE_ASC.toString());
01048:                    context.put("sortby_createdby", SortType.CREATED_BY_ASC
01049:                            .toString());
01050:                    context.put("sortby_publish", SortType.PUBLISHED_ASC
01051:                            .toString());
01052:                    context.put("sortby_createdon", SortType.CREATED_ON_ASC
01053:                            .toString());
01054:
01055:                    // top menu bar
01056:                    Menu bar = new MenuImpl(portlet, data, (String) state
01057:                            .getAttribute(STATE_ACTION));
01058:                    if (SiteService.allowAddSite(null)) {
01059:                        bar.add(new MenuEntry(rb.getString("java.new"),
01060:                                "doNew_site"));
01061:                    }
01062:                    bar.add(new MenuEntry(rb.getString("java.revise"), null,
01063:                            true, MenuItem.CHECKED_NA, "doGet_site",
01064:                            "sitesForm"));
01065:                    bar.add(new MenuEntry(rb.getString("java.delete"), null,
01066:                            true, MenuItem.CHECKED_NA, "doMenu_site_delete",
01067:                            "sitesForm"));
01068:                    context.put("menu", bar);
01069:                    // default to be no pageing
01070:                    context.put("paged", Boolean.FALSE);
01071:
01072:                    Menu bar2 = new MenuImpl(portlet, data, (String) state
01073:                            .getAttribute(STATE_ACTION));
01074:
01075:                    // add the search commands
01076:                    addSearchMenus(bar2, state);
01077:                    context.put("menu2", bar2);
01078:
01079:                    pagingInfoToContext(state, context);
01080:                    return (String) getContext(data).get("template")
01081:                            + TEMPLATE[0];
01082:                case 1:
01083:                    /*
01084:                     * buildContextForTemplate chef_site-type.vm
01085:                     * 
01086:                     */
01087:                    if (hasGradSites.equalsIgnoreCase("true")) {
01088:                        context.put("withDissertation", Boolean.TRUE);
01089:                        try {
01090:                            // the Grad Tools site option is only presented to UM grad
01091:                            // students
01092:                            String userId = StringUtil
01093:                                    .trimToZero(SessionManager
01094:                                            .getCurrentSessionUserId());
01095:
01096:                            // am I a UM grad student?
01097:                            Boolean isGradStudent = new Boolean(
01098:                                    isGradToolsCandidate(userId));
01099:                            context.put("isGradStudent", isGradStudent);
01100:
01101:                            // if I am a UM grad student, do I already have a Grad Tools
01102:                            // site?
01103:                            boolean noGradToolsSite = true;
01104:                            if (hasGradToolsStudentSite(userId))
01105:                                noGradToolsSite = false;
01106:                            context.put("noGradToolsSite", new Boolean(
01107:                                    noGradToolsSite));
01108:                        } catch (Exception e) {
01109:                            if (Log.isWarnEnabled()) {
01110:                                M_log
01111:                                        .warn("buildContextForTemplate chef_site-type.vm "
01112:                                                + e);
01113:                            }
01114:                        }
01115:                    } else {
01116:                        context.put("withDissertation", Boolean.FALSE);
01117:                    }
01118:
01119:                    List types = (List) state.getAttribute(STATE_SITE_TYPES);
01120:                    context.put("siteTypes", types);
01121:
01122:                    // put selected/default site type into context
01123:                    if (siteInfo.site_type != null
01124:                            && siteInfo.site_type.length() > 0) {
01125:                        context.put("typeSelected", siteInfo.site_type);
01126:                    } else if (types.size() > 0) {
01127:                        context.put("typeSelected", types.get(0));
01128:                    }
01129:                    setTermListForContext(context, state, true); // true => only
01130:                    // upcoming terms
01131:                    setSelectedTermForContext(context, state,
01132:                            STATE_TERM_SELECTED);
01133:                    return (String) getContext(data).get("template")
01134:                            + TEMPLATE[1];
01135:
01136:                case 2:
01137:                    /*
01138:                     * buildContextForTemplate chef_site-newSiteInformation.vm
01139:                     * 
01140:                     */
01141:                    context.put("siteTypes", state
01142:                            .getAttribute(STATE_SITE_TYPES));
01143:                    String siteType = (String) state
01144:                            .getAttribute(STATE_SITE_TYPE);
01145:
01146:                    context.put("titleEditableSiteType", state
01147:                            .getAttribute(TITLE_EDITABLE_SITE_TYPE));
01148:                    context.put("type", siteType);
01149:
01150:                    if (siteType.equalsIgnoreCase("course")) {
01151:                        context.put("isCourseSite", Boolean.TRUE);
01152:                        context.put("isProjectSite", Boolean.FALSE);
01153:
01154:                        if (state.getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN) != null) {
01155:                            context
01156:                                    .put(
01157:                                            "selectedProviderCourse",
01158:                                            state
01159:                                                    .getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN));
01160:                        }
01161:
01162:                        List<SectionObject> cmRequestedList = (List<SectionObject>) state
01163:                                .getAttribute(STATE_CM_REQUESTED_SECTIONS);
01164:
01165:                        if (cmRequestedList != null) {
01166:                            context.put("cmRequestedSections", cmRequestedList);
01167:                            context.put("back", "53");
01168:                        }
01169:
01170:                        List<SectionObject> cmAuthorizerSectionList = (List<SectionObject>) state
01171:                                .getAttribute(STATE_CM_AUTHORIZER_SECTIONS);
01172:                        if (cmAuthorizerSectionList != null) {
01173:                            context.put("cmAuthorizerSections",
01174:                                    cmAuthorizerSectionList);
01175:                            context.put("back", "36");
01176:                        }
01177:
01178:                        if (state.getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER) != null) {
01179:                            int number = ((Integer) state
01180:                                    .getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER))
01181:                                    .intValue();
01182:                            context.put("manualAddNumber", new Integer(
01183:                                    number - 1));
01184:                            context
01185:                                    .put(
01186:                                            "manualAddFields",
01187:                                            state
01188:                                                    .getAttribute(STATE_MANUAL_ADD_COURSE_FIELDS));
01189:                            context.put("back", "37");
01190:                        } else {
01191:                            if (courseManagementIsImplemented()) {
01192:                                context.put("back", "36");
01193:                            } else {
01194:                                context.put("back", "0");
01195:                                context.put("template-index", "37");
01196:                            }
01197:                        }
01198:
01199:                        context.put("skins", state.getAttribute(STATE_ICONS));
01200:                        if (StringUtil.trimToNull(siteInfo.getIconUrl()) != null) {
01201:                            context.put("selectedIcon", siteInfo.getIconUrl());
01202:                        }
01203:                    } else {
01204:                        context.put("isCourseSite", Boolean.FALSE);
01205:                        if (siteType.equalsIgnoreCase("project")) {
01206:                            context.put("isProjectSite", Boolean.TRUE);
01207:                        }
01208:
01209:                        if (StringUtil.trimToNull(siteInfo.iconUrl) != null) {
01210:                            context.put(FORM_ICON_URL, siteInfo.iconUrl);
01211:                        }
01212:
01213:                        context.put("back", "1");
01214:                    }
01215:
01216:                    context.put(FORM_TITLE, siteInfo.title);
01217:                    context.put(FORM_SHORT_DESCRIPTION,
01218:                            siteInfo.short_description);
01219:                    context.put(FORM_DESCRIPTION, siteInfo.description);
01220:
01221:                    // defalt the site contact person to the site creator
01222:                    if (siteInfo.site_contact_name.equals(NULL_STRING)
01223:                            && siteInfo.site_contact_email.equals(NULL_STRING)) {
01224:                        User user = UserDirectoryService.getCurrentUser();
01225:                        siteInfo.site_contact_name = user.getDisplayName();
01226:                        siteInfo.site_contact_email = user.getEmail();
01227:                    }
01228:                    context.put("form_site_contact_name",
01229:                            siteInfo.site_contact_name);
01230:                    context.put("form_site_contact_email",
01231:                            siteInfo.site_contact_email);
01232:
01233:                    // those manual inputs
01234:                    context.put("form_requiredFields", sectionFieldManager
01235:                            .getRequiredFields());
01236:                    context.put("fieldValues", state
01237:                            .getAttribute(STATE_MANUAL_ADD_COURSE_FIELDS));
01238:                    return (String) getContext(data).get("template")
01239:                            + TEMPLATE[2];
01240:                case 3:
01241:                    /*
01242:                     * buildContextForTemplate chef_site-newSiteFeatures.vm
01243:                     * 
01244:                     */
01245:                    siteType = (String) state.getAttribute(STATE_SITE_TYPE);
01246:                    if (siteType != null && siteType.equalsIgnoreCase("course")) {
01247:                        context.put("isCourseSite", Boolean.TRUE);
01248:                        context.put("isProjectSite", Boolean.FALSE);
01249:                    } else {
01250:                        context.put("isCourseSite", Boolean.FALSE);
01251:                        if (siteType.equalsIgnoreCase("project")) {
01252:                            context.put("isProjectSite", Boolean.TRUE);
01253:                        }
01254:                    }
01255:                    context.put("defaultTools", ServerConfigurationService
01256:                            .getToolsRequired(siteType));
01257:
01258:                    toolRegistrationSelectedList = (List) state
01259:                            .getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST);
01260:
01261:                    // If this is the first time through, check for tools
01262:                    // which should be selected by default.
01263:                    List defaultSelectedTools = ServerConfigurationService
01264:                            .getDefaultTools(siteType);
01265:                    if (toolRegistrationSelectedList == null) {
01266:                        toolRegistrationSelectedList = new Vector(
01267:                                defaultSelectedTools);
01268:                    }
01269:
01270:                    context.put(STATE_TOOL_REGISTRATION_SELECTED_LIST,
01271:                            toolRegistrationSelectedList); // String toolId's
01272:                    context.put(STATE_TOOL_REGISTRATION_LIST, state
01273:                            .getAttribute(STATE_TOOL_REGISTRATION_LIST)); // %%% use
01274:                    // ToolRegistrations
01275:                    // for
01276:                    // template
01277:                    // list
01278:                    context.put("emailId", state
01279:                            .getAttribute(STATE_TOOL_EMAIL_ADDRESS));
01280:                    context.put("serverName", ServerConfigurationService
01281:                            .getServerName());
01282:
01283:                    // The "Home" tool checkbox needs special treatment to be selected
01284:                    // by
01285:                    // default.
01286:                    Boolean checkHome = (Boolean) state
01287:                            .getAttribute(STATE_TOOL_HOME_SELECTED);
01288:                    if (checkHome == null) {
01289:                        if ((defaultSelectedTools != null)
01290:                                && defaultSelectedTools.contains(HOME_TOOL_ID)) {
01291:                            checkHome = Boolean.TRUE;
01292:                        }
01293:                    }
01294:                    context.put("check_home", checkHome);
01295:
01296:                    // titles for news tools
01297:                    context.put("newsTitles", state
01298:                            .getAttribute(STATE_NEWS_TITLES));
01299:                    // titles for web content tools
01300:                    context.put("wcTitles", state
01301:                            .getAttribute(STATE_WEB_CONTENT_TITLES));
01302:                    // urls for news tools
01303:                    context
01304:                            .put("newsUrls", state
01305:                                    .getAttribute(STATE_NEWS_URLS));
01306:                    // urls for web content tools
01307:                    context.put("wcUrls", state
01308:                            .getAttribute(STATE_WEB_CONTENT_URLS));
01309:                    context
01310:                            .put(
01311:                                    "sites",
01312:                                    SiteService
01313:                                            .getSites(
01314:                                                    org.sakaiproject.site.api.SiteService.SelectionType.UPDATE,
01315:                                                    null, null, null,
01316:                                                    SortType.TITLE_ASC, null));
01317:                    context.put("import", state.getAttribute(STATE_IMPORT));
01318:                    context.put("importSites", state
01319:                            .getAttribute(STATE_IMPORT_SITES));
01320:
01321:                    return (String) getContext(data).get("template")
01322:                            + TEMPLATE[3];
01323:                case 4:
01324:                    /*
01325:                     * buildContextForTemplate chef_site-addRemoveFeatures.vm
01326:                     * 
01327:                     */
01328:                    context.put("SiteTitle", site.getTitle());
01329:                    String type = (String) state.getAttribute(STATE_SITE_TYPE);
01330:                    context.put("defaultTools", ServerConfigurationService
01331:                            .getToolsRequired(type));
01332:
01333:                    boolean myworkspace_site = false;
01334:                    // Put up tool lists filtered by category
01335:                    List siteTypes = (List) state
01336:                            .getAttribute(STATE_SITE_TYPES);
01337:                    if (siteTypes.contains(type)) {
01338:                        myworkspace_site = false;
01339:                    }
01340:
01341:                    if (SiteService.isUserSite(site.getId())
01342:                            || (type != null && type
01343:                                    .equalsIgnoreCase("myworkspace"))) {
01344:                        myworkspace_site = true;
01345:                        type = "myworkspace";
01346:                    }
01347:
01348:                    context.put("myworkspace_site", new Boolean(
01349:                            myworkspace_site));
01350:
01351:                    context
01352:                            .put(
01353:                                    STATE_TOOL_REGISTRATION_SELECTED_LIST,
01354:                                    state
01355:                                            .getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST));
01356:
01357:                    // titles for news tools
01358:                    context.put("newsTitles", state
01359:                            .getAttribute(STATE_NEWS_TITLES));
01360:                    // titles for web content tools
01361:                    context.put("wcTitles", state
01362:                            .getAttribute(STATE_WEB_CONTENT_TITLES));
01363:                    // urls for news tools
01364:                    context
01365:                            .put("newsUrls", state
01366:                                    .getAttribute(STATE_NEWS_URLS));
01367:                    // urls for web content tools
01368:                    context.put("wcUrls", state
01369:                            .getAttribute(STATE_WEB_CONTENT_URLS));
01370:
01371:                    context.put(STATE_TOOL_REGISTRATION_LIST, state
01372:                            .getAttribute(STATE_TOOL_REGISTRATION_LIST));
01373:                    context.put("check_home", state
01374:                            .getAttribute(STATE_TOOL_HOME_SELECTED));
01375:
01376:                    // get the email alias when an Email Archive tool has been selected
01377:                    String channelReference = mailArchiveChannelReference(site
01378:                            .getId());
01379:                    List aliases = AliasService.getAliases(channelReference, 1,
01380:                            1);
01381:                    if (aliases.size() > 0) {
01382:                        state.setAttribute(STATE_TOOL_EMAIL_ADDRESS,
01383:                                ((Alias) aliases.get(0)).getId());
01384:                    } else {
01385:                        state.removeAttribute(STATE_TOOL_EMAIL_ADDRESS);
01386:                    }
01387:                    if (state.getAttribute(STATE_TOOL_EMAIL_ADDRESS) != null) {
01388:                        context.put("emailId", state
01389:                                .getAttribute(STATE_TOOL_EMAIL_ADDRESS));
01390:                    }
01391:                    context.put("serverName", ServerConfigurationService
01392:                            .getServerName());
01393:
01394:                    context.put("backIndex", "12");
01395:
01396:                    return (String) getContext(data).get("template")
01397:                            + TEMPLATE[4];
01398:                case 5:
01399:                    /*
01400:                     * buildContextForTemplate chef_site-addParticipant.vm
01401:                     * 
01402:                     */
01403:                    context.put("title", site.getTitle());
01404:                    roles = getRoles(state);
01405:                    context.put("roles", roles);
01406:
01407:                    // Note that (for now) these strings are in both sakai.properties
01408:                    // and sitesetupgeneric.properties
01409:                    context.put("noEmailInIdAccountName",
01410:                            ServerConfigurationService
01411:                                    .getString("noEmailInIdAccountName"));
01412:                    context.put("noEmailInIdAccountLabel",
01413:                            ServerConfigurationService
01414:                                    .getString("noEmailInIdAccountLabel"));
01415:                    context.put("emailInIdAccountName",
01416:                            ServerConfigurationService
01417:                                    .getString("emailInIdAccountName"));
01418:                    context.put("emailInIdAccountLabel",
01419:                            ServerConfigurationService
01420:                                    .getString("emailInIdAccountLabel"));
01421:
01422:                    if (state.getAttribute("noEmailInIdAccountValue") != null) {
01423:                        context.put("noEmailInIdAccountValue", (String) state
01424:                                .getAttribute("noEmailInIdAccountValue"));
01425:                    }
01426:                    if (state.getAttribute("emailInIdAccountValue") != null) {
01427:                        context.put("emailInIdAccountValue", (String) state
01428:                                .getAttribute("emailInIdAccountValue"));
01429:                    }
01430:
01431:                    if (state.getAttribute("form_same_role") != null) {
01432:                        context.put("form_same_role", ((Boolean) state
01433:                                .getAttribute("form_same_role")).toString());
01434:                    } else {
01435:                        context.put("form_same_role", Boolean.TRUE.toString());
01436:                    }
01437:                    context.put("backIndex", "12");
01438:                    return (String) getContext(data).get("template")
01439:                            + TEMPLATE[5];
01440:                case 6:
01441:                    /*
01442:                     * buildContextForTemplate chef_site-removeParticipants.vm
01443:                     * 
01444:                     */
01445:                    context.put("title", site.getTitle());
01446:                    realmId = SiteService.siteReference(site.getId());
01447:                    try {
01448:                        AuthzGroup realm = AuthzGroupService
01449:                                .getAuthzGroup(realmId);
01450:                        try {
01451:                            List removeableList = (List) state
01452:                                    .getAttribute(STATE_REMOVEABLE_USER_LIST);
01453:                            List removeableParticipants = new Vector();
01454:
01455:                            for (int k = 0; k < removeableList.size(); k++) {
01456:                                User user = UserDirectoryService
01457:                                        .getUser((String) removeableList.get(k));
01458:                                Participant participant = new Participant();
01459:                                participant.name = user.getSortName();
01460:                                participant.uniqname = user.getId();
01461:                                Role r = realm.getUserRole(user.getId());
01462:                                if (r != null) {
01463:                                    participant.role = r.getId();
01464:                                }
01465:                                removeableParticipants.add(participant);
01466:                            }
01467:                            context.put("removeableList",
01468:                                    removeableParticipants);
01469:                        } catch (UserNotDefinedException ee) {
01470:                        }
01471:                    } catch (GroupNotDefinedException e) {
01472:                    }
01473:
01474:                    context.put("backIndex", "18");
01475:                    return (String) getContext(data).get("template")
01476:                            + TEMPLATE[6];
01477:                case 7:
01478:                    /*
01479:                     * buildContextForTemplate chef_site-changeRoles.vm
01480:                     * 
01481:                     */
01482:                    context.put("same_role", state
01483:                            .getAttribute(STATE_CHANGEROLE_SAMEROLE));
01484:                    roles = getRoles(state);
01485:                    context.put("roles", roles);
01486:                    context.put("currentRole", state
01487:                            .getAttribute(STATE_CHANGEROLE_SAMEROLE_ROLE));
01488:                    context.put("participantSelectedList", state
01489:                            .getAttribute(STATE_SELECTED_PARTICIPANTS));
01490:                    context.put("selectedRoles", state
01491:                            .getAttribute(STATE_SELECTED_PARTICIPANT_ROLES));
01492:                    context.put("siteTitle", site.getTitle());
01493:                    return (String) getContext(data).get("template")
01494:                            + TEMPLATE[7];
01495:                case 8:
01496:                    /*
01497:                     * buildContextForTemplate chef_site-siteDeleteConfirm.vm
01498:                     * 
01499:                     */
01500:                    String site_title = NULL_STRING;
01501:                    String[] removals = (String[]) state
01502:                            .getAttribute(STATE_SITE_REMOVALS);
01503:                    List remove = new Vector();
01504:                    String user = SessionManager.getCurrentSessionUserId();
01505:                    String workspace = SiteService.getUserSiteId(user);
01506:                    if (removals != null && removals.length != 0) {
01507:                        for (int i = 0; i < removals.length; i++) {
01508:                            String id = (String) removals[i];
01509:                            if (!(id.equals(workspace))) {
01510:                                try {
01511:                                    site_title = SiteService.getSite(id)
01512:                                            .getTitle();
01513:                                } catch (IdUnusedException e) {
01514:                                    M_log
01515:                                            .warn("SiteAction.doSite_delete_confirmed - IdUnusedException "
01516:                                                    + id);
01517:                                    addAlert(state, rb
01518:                                            .getString("java.sitewith")
01519:                                            + " "
01520:                                            + id
01521:                                            + " "
01522:                                            + rb.getString("java.couldnt")
01523:                                            + " ");
01524:                                }
01525:                                if (SiteService.allowRemoveSite(id)) {
01526:                                    try {
01527:                                        Site removeSite = SiteService
01528:                                                .getSite(id);
01529:                                        remove.add(removeSite);
01530:                                    } catch (IdUnusedException e) {
01531:                                        M_log
01532:                                                .warn("SiteAction.buildContextForTemplate chef_site-siteDeleteConfirm.vm: IdUnusedException");
01533:                                    }
01534:                                } else {
01535:                                    addAlert(state, site_title + " "
01536:                                            + rb.getString("java.couldntdel")
01537:                                            + " ");
01538:                                }
01539:                            } else {
01540:                                addAlert(state, rb.getString("java.yourwork"));
01541:                            }
01542:                        }
01543:                        if (remove.size() == 0) {
01544:                            addAlert(state, rb.getString("java.click"));
01545:                        }
01546:                    }
01547:                    context.put("removals", remove);
01548:                    return (String) getContext(data).get("template")
01549:                            + TEMPLATE[8];
01550:                case 9:
01551:                    /*
01552:                     * buildContextForTemplate chef_site-publishUnpublish.vm
01553:                     * 
01554:                     */
01555:                    context.put("publish", Boolean.valueOf(((SiteInfo) state
01556:                            .getAttribute(STATE_SITE_INFO)).getPublished()));
01557:                    context.put("backIndex", "12");
01558:                    return (String) getContext(data).get("template")
01559:                            + TEMPLATE[9];
01560:                case 10:
01561:                    /*
01562:                     * buildContextForTemplate chef_site-newSiteConfirm.vm
01563:                     * 
01564:                     */
01565:                    siteInfo = (SiteInfo) state.getAttribute(STATE_SITE_INFO);
01566:                    siteType = (String) state.getAttribute(STATE_SITE_TYPE);
01567:                    if (siteType.equalsIgnoreCase("course")) {
01568:                        context.put("isCourseSite", Boolean.TRUE);
01569:                        context.put("isProjectSite", Boolean.FALSE);
01570:                        if (state.getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN) != null) {
01571:                            context
01572:                                    .put(
01573:                                            "selectedProviderCourse",
01574:                                            state
01575:                                                    .getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN));
01576:                        }
01577:                        if (state.getAttribute(STATE_CM_AUTHORIZER_SECTIONS) != null) {
01578:                            context
01579:                                    .put(
01580:                                            "selectedAuthorizerCourse",
01581:                                            state
01582:                                                    .getAttribute(STATE_CM_AUTHORIZER_SECTIONS));
01583:                        }
01584:                        if (state.getAttribute(STATE_CM_REQUESTED_SECTIONS) != null) {
01585:                            context.put("selectedRequestedCourse", state
01586:                                    .getAttribute(STATE_CM_REQUESTED_SECTIONS));
01587:                        }
01588:                        if (state.getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER) != null) {
01589:                            int number = ((Integer) state
01590:                                    .getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER))
01591:                                    .intValue();
01592:                            context.put("manualAddNumber", new Integer(
01593:                                    number - 1));
01594:                            context
01595:                                    .put(
01596:                                            "manualAddFields",
01597:                                            state
01598:                                                    .getAttribute(STATE_MANUAL_ADD_COURSE_FIELDS));
01599:                        }
01600:
01601:                        context.put("skins", state.getAttribute(STATE_ICONS));
01602:                        if (StringUtil.trimToNull(siteInfo.getIconUrl()) != null) {
01603:                            context.put("selectedIcon", siteInfo.getIconUrl());
01604:                        }
01605:                    } else {
01606:                        context.put("isCourseSite", Boolean.FALSE);
01607:                        if (siteType != null
01608:                                && siteType.equalsIgnoreCase("project")) {
01609:                            context.put("isProjectSite", Boolean.TRUE);
01610:                        }
01611:
01612:                        if (StringUtil.trimToNull(siteInfo.iconUrl) != null) {
01613:                            context.put("iconUrl", siteInfo.iconUrl);
01614:                        }
01615:                    }
01616:                    context.put("title", siteInfo.title);
01617:                    context.put("description", siteInfo.description);
01618:                    context
01619:                            .put("short_description",
01620:                                    siteInfo.short_description);
01621:                    context.put("siteContactName", siteInfo.site_contact_name);
01622:                    context
01623:                            .put("siteContactEmail",
01624:                                    siteInfo.site_contact_email);
01625:                    siteType = (String) state.getAttribute(STATE_SITE_TYPE);
01626:                    toolRegistrationSelectedList = (List) state
01627:                            .getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST);
01628:                    context.put(STATE_TOOL_REGISTRATION_SELECTED_LIST,
01629:                            toolRegistrationSelectedList); // String toolId's
01630:                    context.put(STATE_TOOL_REGISTRATION_LIST, state
01631:                            .getAttribute(STATE_TOOL_REGISTRATION_LIST)); // %%% use
01632:                    // Tool
01633:                    context.put("check_home", state
01634:                            .getAttribute(STATE_TOOL_HOME_SELECTED));
01635:                    context.put("emailId", state
01636:                            .getAttribute(STATE_TOOL_EMAIL_ADDRESS));
01637:                    context.put("serverName", ServerConfigurationService
01638:                            .getServerName());
01639:                    context.put("include", new Boolean(siteInfo.include));
01640:                    context.put("published", new Boolean(siteInfo.published));
01641:                    context.put("joinable", new Boolean(siteInfo.joinable));
01642:                    context.put("joinerRole", siteInfo.joinerRole);
01643:                    context.put("newsTitles", (Hashtable) state
01644:                            .getAttribute(STATE_NEWS_TITLES));
01645:                    context.put("wcTitles", (Hashtable) state
01646:                            .getAttribute(STATE_WEB_CONTENT_TITLES));
01647:
01648:                    // back to edit access page
01649:                    context.put("back", "18");
01650:
01651:                    context.put("importSiteTools", state
01652:                            .getAttribute(STATE_IMPORT_SITE_TOOL));
01653:                    context.put("siteService", SiteService.getInstance());
01654:
01655:                    // those manual inputs
01656:                    context.put("form_requiredFields", sectionFieldManager
01657:                            .getRequiredFields());
01658:                    context.put("fieldValues", state
01659:                            .getAttribute(STATE_MANUAL_ADD_COURSE_FIELDS));
01660:
01661:                    return (String) getContext(data).get("template")
01662:                            + TEMPLATE[10];
01663:                case 11:
01664:                    /*
01665:                     * buildContextForTemplate chef_site-newSitePublishUnpublish.vm
01666:                     * 
01667:                     */
01668:                    return (String) getContext(data).get("template")
01669:                            + TEMPLATE[11];
01670:                case 12:
01671:                    /*
01672:                     * buildContextForTemplate chef_site-siteInfo-list.vm
01673:                     * 
01674:                     */
01675:                    context.put("userDirectoryService", UserDirectoryService
01676:                            .getInstance());
01677:                    try {
01678:                        siteProperties = site.getProperties();
01679:                        siteType = site.getType();
01680:                        if (siteType != null) {
01681:                            state.setAttribute(STATE_SITE_TYPE, siteType);
01682:                        }
01683:
01684:                        boolean isMyWorkspace = false;
01685:                        if (SiteService.isUserSite(site.getId())) {
01686:                            if (SiteService.getSiteUserId(site.getId()).equals(
01687:                                    SessionManager.getCurrentSessionUserId())) {
01688:                                isMyWorkspace = true;
01689:                                context.put("siteUserId", SiteService
01690:                                        .getSiteUserId(site.getId()));
01691:                            }
01692:                        }
01693:                        context.put("isMyWorkspace", Boolean
01694:                                .valueOf(isMyWorkspace));
01695:
01696:                        String siteId = site.getId();
01697:                        if (state.getAttribute(STATE_ICONS) != null) {
01698:                            List skins = (List) state.getAttribute(STATE_ICONS);
01699:                            for (int i = 0; i < skins.size(); i++) {
01700:                                Icon s = (Icon) skins.get(i);
01701:                                if (!StringUtil.different(s.getUrl(), site
01702:                                        .getIconUrl())) {
01703:                                    context.put("siteUnit", s.getName());
01704:                                    break;
01705:                                }
01706:                            }
01707:                        }
01708:                        context.put("siteIcon", site.getIconUrl());
01709:                        context.put("siteTitle", site.getTitle());
01710:                        context.put("siteDescription", site.getDescription());
01711:                        context.put("siteJoinable", new Boolean(site
01712:                                .isJoinable()));
01713:
01714:                        if (site.isPublished()) {
01715:                            context.put("published", Boolean.TRUE);
01716:                        } else {
01717:                            context.put("published", Boolean.FALSE);
01718:                            context.put("owner", site.getCreatedBy()
01719:                                    .getSortName());
01720:                        }
01721:                        Time creationTime = site.getCreatedTime();
01722:                        if (creationTime != null) {
01723:                            context.put("siteCreationDate", creationTime
01724:                                    .toStringLocalFull());
01725:                        }
01726:                        boolean allowUpdateSite = SiteService
01727:                                .allowUpdateSite(siteId);
01728:                        context.put("allowUpdate", Boolean
01729:                                .valueOf(allowUpdateSite));
01730:
01731:                        boolean allowUpdateGroupMembership = SiteService
01732:                                .allowUpdateGroupMembership(siteId);
01733:                        context.put("allowUpdateGroupMembership", Boolean
01734:                                .valueOf(allowUpdateGroupMembership));
01735:
01736:                        boolean allowUpdateSiteMembership = SiteService
01737:                                .allowUpdateSiteMembership(siteId);
01738:                        context.put("allowUpdateSiteMembership", Boolean
01739:                                .valueOf(allowUpdateSiteMembership));
01740:
01741:                        if (allowUpdateSite) {
01742:                            // top menu bar
01743:                            Menu b = new MenuImpl(portlet, data, (String) state
01744:                                    .getAttribute(STATE_ACTION));
01745:
01746:                            if (!isMyWorkspace) {
01747:                                b.add(new MenuEntry(rb
01748:                                        .getString("java.editsite"),
01749:                                        "doMenu_edit_site_info"));
01750:                            }
01751:                            b.add(new MenuEntry(rb.getString("java.edittools"),
01752:                                    "doMenu_edit_site_tools"));
01753:
01754:                            if (!isMyWorkspace
01755:                                    && (ServerConfigurationService
01756:                                            .getString("wsetup.group.support") == "" || ServerConfigurationService
01757:                                            .getString("wsetup.group.support")
01758:                                            .equalsIgnoreCase(
01759:                                                    Boolean.TRUE.toString()))) {
01760:                                // show the group toolbar unless configured
01761:                                // to not support group
01762:                                b.add(new MenuEntry(rb.getString("java.group"),
01763:                                        "doMenu_group"));
01764:                            }
01765:                            if (!isMyWorkspace) {
01766:                                List gradToolsSiteTypes = (List) state
01767:                                        .getAttribute(GRADTOOLS_SITE_TYPES);
01768:                                boolean isGradToolSite = false;
01769:                                if (siteType != null
01770:                                        && gradToolsSiteTypes
01771:                                                .contains(siteType)) {
01772:                                    isGradToolSite = true;
01773:                                }
01774:                                if (siteType == null || siteType != null
01775:                                        && !isGradToolSite) {
01776:                                    // hide site access for GRADTOOLS
01777:                                    // type of sites
01778:                                    b.add(new MenuEntry(rb
01779:                                            .getString("java.siteaccess"),
01780:                                            "doMenu_edit_site_access"));
01781:                                }
01782:                                b.add(new MenuEntry(rb.getString("java.addp"),
01783:                                        "doMenu_siteInfo_addParticipant"));
01784:                                if (siteType != null
01785:                                        && siteType.equals("course")) {
01786:                                    b.add(new MenuEntry(rb
01787:                                            .getString("java.editc"),
01788:                                            "doMenu_siteInfo_editClass"));
01789:                                }
01790:                                if (siteType == null || siteType != null
01791:                                        && !isGradToolSite) {
01792:                                    // hide site duplicate and import
01793:                                    // for GRADTOOLS type of sites
01794:                                    b.add(new MenuEntry(rb
01795:                                            .getString("java.duplicate"),
01796:                                            "doMenu_siteInfo_duplicate"));
01797:
01798:                                    List updatableSites = SiteService
01799:                                            .getSites(
01800:                                                    org.sakaiproject.site.api.SiteService.SelectionType.UPDATE,
01801:                                                    null, null, null,
01802:                                                    SortType.TITLE_ASC, null);
01803:
01804:                                    // import link should be visible even if only one
01805:                                    // site
01806:                                    if (updatableSites.size() > 0) {
01807:                                        b.add(new MenuEntry(rb
01808:                                                .getString("java.import"),
01809:                                                "doMenu_siteInfo_import"));
01810:
01811:                                        // a configuration param for
01812:                                        // showing/hiding import
01813:                                        // from file choice
01814:                                        String importFromFile = ServerConfigurationService
01815:                                                .getString(
01816:                                                        "site.setup.import.file",
01817:                                                        Boolean.TRUE.toString());
01818:                                        if (importFromFile
01819:                                                .equalsIgnoreCase("true")) {
01820:                                            // htripath: June
01821:                                            // 4th added as per
01822:                                            // Kris and changed
01823:                                            // desc of above
01824:                                            b
01825:                                                    .add(new MenuEntry(
01826:                                                            rb
01827:                                                                    .getString("java.importFile"),
01828:                                                            "doAttachmentsMtrlFrmFile"));
01829:                                        }
01830:                                    }
01831:                                }
01832:                            }
01833:
01834:                            // if the page order helper is available, not
01835:                            // stealthed and not hidden, show the link
01836:                            if (ToolManager
01837:                                    .getTool("sakai-site-pageorder-helper") != null
01838:                                    && !ServerConfigurationService
01839:                                            .getString(
01840:                                                    "stealthTools@org.sakaiproject.tool.api.ActiveToolManager")
01841:                                            .contains(
01842:                                                    "sakai-site-pageorder-helper")
01843:                                    && !ServerConfigurationService
01844:                                            .getString(
01845:                                                    "hiddenTools@org.sakaiproject.tool.api.ActiveToolManager")
01846:                                            .contains(
01847:                                                    "sakai-site-pageorder-helper")) {
01848:                                b.add(new MenuEntry(rb
01849:                                        .getString("java.orderpages"),
01850:                                        "doPageOrderHelper"));
01851:                            }
01852:                            context.put("menu", b);
01853:                        }
01854:
01855:                        if (allowUpdateGroupMembership) {
01856:                            // show Manage Groups menu
01857:                            Menu b = new MenuImpl(portlet, data, (String) state
01858:                                    .getAttribute(STATE_ACTION));
01859:                            if (!isMyWorkspace
01860:                                    && (ServerConfigurationService
01861:                                            .getString("wsetup.group.support") == "" || ServerConfigurationService
01862:                                            .getString("wsetup.group.support")
01863:                                            .equalsIgnoreCase(
01864:                                                    Boolean.TRUE.toString()))) {
01865:                                // show the group toolbar unless configured
01866:                                // to not support group
01867:                                b.add(new MenuEntry(rb.getString("java.group"),
01868:                                        "doMenu_group"));
01869:                            }
01870:                            context.put("menu", b);
01871:                        }
01872:
01873:                        if (allowUpdateSiteMembership) {
01874:                            // show add participant menu
01875:                            Menu b = new MenuImpl(portlet, data, (String) state
01876:                                    .getAttribute(STATE_ACTION));
01877:                            if (!isMyWorkspace) {
01878:                                // show the Add Participant menu
01879:                                b.add(new MenuEntry(rb.getString("java.addp"),
01880:                                        "doMenu_siteInfo_addParticipant"));
01881:                            }
01882:                            context.put("menu", b);
01883:                        }
01884:
01885:                        if (((String) state.getAttribute(STATE_SITE_MODE))
01886:                                .equalsIgnoreCase(SITE_MODE_SITESETUP)) {
01887:                            // editing from worksite setup tool
01888:                            context.put("fromWSetup", Boolean.TRUE);
01889:                            if (state.getAttribute(STATE_PREV_SITE) != null) {
01890:                                context.put("prevSite", state
01891:                                        .getAttribute(STATE_PREV_SITE));
01892:                            }
01893:                            if (state.getAttribute(STATE_NEXT_SITE) != null) {
01894:                                context.put("nextSite", state
01895:                                        .getAttribute(STATE_NEXT_SITE));
01896:                            }
01897:                        } else {
01898:                            context.put("fromWSetup", Boolean.FALSE);
01899:                        }
01900:                        // allow view roster?
01901:                        boolean allowViewRoster = SiteService
01902:                                .allowViewRoster(siteId);
01903:                        if (allowViewRoster) {
01904:                            context.put("viewRoster", Boolean.TRUE);
01905:                        } else {
01906:                            context.put("viewRoster", Boolean.FALSE);
01907:                        }
01908:                        // set participant list
01909:                        if (allowUpdateSite || allowViewRoster
01910:                                || allowUpdateSiteMembership) {
01911:                            List participants = new Vector();
01912:                            participants = getParticipantList(state);
01913:                            sortedBy = (String) state.getAttribute(SORTED_BY);
01914:                            sortedAsc = (String) state.getAttribute(SORTED_ASC);
01915:                            if (sortedBy == null) {
01916:                                state.setAttribute(SORTED_BY,
01917:                                        SORTED_BY_PARTICIPANT_NAME);
01918:                                sortedBy = SORTED_BY_PARTICIPANT_NAME;
01919:                            }
01920:                            if (sortedAsc == null) {
01921:                                sortedAsc = Boolean.TRUE.toString();
01922:                                state.setAttribute(SORTED_ASC, sortedAsc);
01923:                            }
01924:                            if (sortedBy != null)
01925:                                context.put("currentSortedBy", sortedBy);
01926:                            if (sortedAsc != null)
01927:                                context.put("currentSortAsc", sortedAsc);
01928:                            Iterator sortedParticipants = null;
01929:                            if (sortedBy != null) {
01930:                                sortedParticipants = new SortedIterator(
01931:                                        participants.iterator(),
01932:                                        new SiteComparator(sortedBy, sortedAsc));
01933:                                participants.clear();
01934:                                while (sortedParticipants.hasNext()) {
01935:                                    participants.add(sortedParticipants.next());
01936:                                }
01937:                            }
01938:                            context.put("participantListSize", new Integer(
01939:                                    participants.size()));
01940:                            context.put("participantList", prepPage(state));
01941:                            pagingInfoToContext(state, context);
01942:                        }
01943:
01944:                        context.put("include", Boolean
01945:                                .valueOf(site.isPubView()));
01946:
01947:                        // site contact information
01948:                        String contactName = siteProperties
01949:                                .getProperty(PROP_SITE_CONTACT_NAME);
01950:                        String contactEmail = siteProperties
01951:                                .getProperty(PROP_SITE_CONTACT_EMAIL);
01952:                        if (contactName == null && contactEmail == null) {
01953:                            User u = site.getCreatedBy();
01954:                            String email = u.getEmail();
01955:                            if (email != null) {
01956:                                contactEmail = u.getEmail();
01957:                            }
01958:                            contactName = u.getDisplayName();
01959:                        }
01960:                        if (contactName != null) {
01961:                            context.put("contactName", contactName);
01962:                        }
01963:                        if (contactEmail != null) {
01964:                            context.put("contactEmail", contactEmail);
01965:                        }
01966:                        if (siteType != null
01967:                                && siteType.equalsIgnoreCase("course")) {
01968:                            context.put("isCourseSite", Boolean.TRUE);
01969:                            List providerCourseList = getProviderCourseList(StringUtil
01970:                                    .trimToNull(getExternalRealmId(state)));
01971:                            if (providerCourseList != null) {
01972:                                state.setAttribute(SITE_PROVIDER_COURSE_LIST,
01973:                                        providerCourseList);
01974:                                context.put("providerCourseList",
01975:                                        providerCourseList);
01976:                            }
01977:                            String manualCourseListString = site
01978:                                    .getProperties().getProperty(
01979:                                            PROP_SITE_REQUEST_COURSE);
01980:                            if (manualCourseListString != null) {
01981:                                List manualCourseList = new Vector();
01982:                                if (manualCourseListString.indexOf("+") != -1) {
01983:                                    manualCourseList = new ArrayList(Arrays
01984:                                            .asList(manualCourseListString
01985:                                                    .split("\\+")));
01986:                                } else {
01987:                                    manualCourseList
01988:                                            .add(manualCourseListString);
01989:                                }
01990:                                state.setAttribute(SITE_MANUAL_COURSE_LIST,
01991:                                        manualCourseList);
01992:                                context.put("manualCourseList",
01993:                                        manualCourseList);
01994:                            }
01995:                            context.put("term", siteProperties
01996:                                    .getProperty(PROP_SITE_TERM));
01997:                        } else {
01998:                            context.put("isCourseSite", Boolean.FALSE);
01999:                        }
02000:                    } catch (Exception e) {
02001:                        M_log.warn(this  + " site info list: " + e.toString());
02002:                    }
02003:
02004:                    roles = getRoles(state);
02005:                    context.put("roles", roles);
02006:
02007:                    // will have the choice to active/inactive user or not
02008:                    String activeInactiveUser = ServerConfigurationService
02009:                            .getString("activeInactiveUser", Boolean.FALSE
02010:                                    .toString());
02011:                    if (activeInactiveUser.equalsIgnoreCase("true")) {
02012:                        context.put("activeInactiveUser", Boolean.TRUE);
02013:                        // put realm object into context
02014:                        realmId = SiteService.siteReference(site.getId());
02015:                        try {
02016:                            context.put("realm", AuthzGroupService
02017:                                    .getAuthzGroup(realmId));
02018:                        } catch (GroupNotDefinedException e) {
02019:                            M_log.warn(this  + "  IdUnusedException " + realmId);
02020:                        }
02021:                    } else {
02022:                        context.put("activeInactiveUser", Boolean.FALSE);
02023:                    }
02024:
02025:                    context.put("groupsWithMember", site
02026:                            .getGroupsWithMember(UserDirectoryService
02027:                                    .getCurrentUser().getId()));
02028:                    return (String) getContext(data).get("template")
02029:                            + TEMPLATE[12];
02030:
02031:                case 13:
02032:                    /*
02033:                     * buildContextForTemplate chef_site-siteInfo-editInfo.vm
02034:                     * 
02035:                     */
02036:                    siteProperties = site.getProperties();
02037:
02038:                    context.put("title", state
02039:                            .getAttribute(FORM_SITEINFO_TITLE));
02040:
02041:                    context.put("titleEditableSiteType", state
02042:                            .getAttribute(TITLE_EDITABLE_SITE_TYPE));
02043:                    context.put("type", site.getType());
02044:
02045:                    siteType = (String) state.getAttribute(STATE_SITE_TYPE);
02046:                    if (siteType != null && siteType.equalsIgnoreCase("course")) {
02047:                        context.put("isCourseSite", Boolean.TRUE);
02048:                        context.put("skins", state.getAttribute(STATE_ICONS));
02049:                        if (state.getAttribute(FORM_SITEINFO_SKIN) != null) {
02050:                            context.put("selectedIcon", state
02051:                                    .getAttribute(FORM_SITEINFO_SKIN));
02052:                        } else if (site.getIconUrl() != null) {
02053:                            context.put("selectedIcon", site.getIconUrl());
02054:                        }
02055:
02056:                        setTermListForContext(context, state, false); // false => all
02057:                        // possible
02058:                        // terms
02059:
02060:                        if (state.getAttribute(FORM_SITEINFO_TERM) == null) {
02061:                            String currentTerm = site.getProperties()
02062:                                    .getProperty(PROP_SITE_TERM);
02063:                            if (currentTerm != null) {
02064:                                state.setAttribute(FORM_SITEINFO_TERM,
02065:                                        currentTerm);
02066:                            }
02067:                        }
02068:                        setSelectedTermForContext(context, state,
02069:                                FORM_SITEINFO_TERM);
02070:                    } else {
02071:                        context.put("isCourseSite", Boolean.FALSE);
02072:
02073:                        if (state.getAttribute(FORM_SITEINFO_ICON_URL) == null
02074:                                && StringUtil.trimToNull(site.getIconUrl()) != null) {
02075:                            state.setAttribute(FORM_SITEINFO_ICON_URL, site
02076:                                    .getIconUrl());
02077:                        }
02078:                        if (state.getAttribute(FORM_SITEINFO_ICON_URL) != null) {
02079:                            context.put("iconUrl", state
02080:                                    .getAttribute(FORM_SITEINFO_ICON_URL));
02081:                        }
02082:                    }
02083:                    context.put("description", state
02084:                            .getAttribute(FORM_SITEINFO_DESCRIPTION));
02085:                    context.put("short_description", state
02086:                            .getAttribute(FORM_SITEINFO_SHORT_DESCRIPTION));
02087:                    context.put("form_site_contact_name", state
02088:                            .getAttribute(FORM_SITEINFO_CONTACT_NAME));
02089:                    context.put("form_site_contact_email", state
02090:                            .getAttribute(FORM_SITEINFO_CONTACT_EMAIL));
02091:
02092:                    // Display of appearance icon/url list with course site based on
02093:                    // "disable.course.site.skin.selection" value set with
02094:                    // sakai.properties file.
02095:                    if ((ServerConfigurationService
02096:                            .getString("disable.course.site.skin.selection"))
02097:                            .equals("true")) {
02098:                        context.put("disableCourseSelection", Boolean.TRUE);
02099:                    }
02100:
02101:                    return (String) getContext(data).get("template")
02102:                            + TEMPLATE[13];
02103:                case 14:
02104:                    /*
02105:                     * buildContextForTemplate chef_site-siteInfo-editInfoConfirm.vm
02106:                     * 
02107:                     */
02108:                    siteProperties = site.getProperties();
02109:                    siteType = (String) state.getAttribute(STATE_SITE_TYPE);
02110:                    if (siteType != null && siteType.equalsIgnoreCase("course")) {
02111:                        context.put("isCourseSite", Boolean.TRUE);
02112:                        context.put("siteTerm", state
02113:                                .getAttribute(FORM_SITEINFO_TERM));
02114:                    } else {
02115:                        context.put("isCourseSite", Boolean.FALSE);
02116:                    }
02117:                    context.put("oTitle", site.getTitle());
02118:                    context.put("title", state
02119:                            .getAttribute(FORM_SITEINFO_TITLE));
02120:
02121:                    context.put("description", state
02122:                            .getAttribute(FORM_SITEINFO_DESCRIPTION));
02123:                    context.put("oDescription", site.getDescription());
02124:                    context.put("short_description", state
02125:                            .getAttribute(FORM_SITEINFO_SHORT_DESCRIPTION));
02126:                    context.put("oShort_description", site
02127:                            .getShortDescription());
02128:                    context.put("skin", state.getAttribute(FORM_SITEINFO_SKIN));
02129:                    context.put("oSkin", site.getIconUrl());
02130:                    context.put("skins", state.getAttribute(STATE_ICONS));
02131:                    context.put("oIcon", site.getIconUrl());
02132:                    context.put("icon", state
02133:                            .getAttribute(FORM_SITEINFO_ICON_URL));
02134:                    context.put("include", state
02135:                            .getAttribute(FORM_SITEINFO_INCLUDE));
02136:                    context.put("oInclude", Boolean.valueOf(site.isPubView()));
02137:                    context.put("name", state
02138:                            .getAttribute(FORM_SITEINFO_CONTACT_NAME));
02139:                    context.put("oName", siteProperties
02140:                            .getProperty(PROP_SITE_CONTACT_NAME));
02141:                    context.put("email", state
02142:                            .getAttribute(FORM_SITEINFO_CONTACT_EMAIL));
02143:                    context.put("oEmail", siteProperties
02144:                            .getProperty(PROP_SITE_CONTACT_EMAIL));
02145:
02146:                    return (String) getContext(data).get("template")
02147:                            + TEMPLATE[14];
02148:                case 15:
02149:                    /*
02150:                     * buildContextForTemplate chef_site-addRemoveFeatureConfirm.vm
02151:                     * 
02152:                     */
02153:                    context.put("title", site.getTitle());
02154:
02155:                    site_type = (String) state.getAttribute(STATE_SITE_TYPE);
02156:                    myworkspace_site = false;
02157:                    if (SiteService.isUserSite(site.getId())) {
02158:                        if (SiteService.getSiteUserId(site.getId()).equals(
02159:                                SessionManager.getCurrentSessionUserId())) {
02160:                            myworkspace_site = true;
02161:                            site_type = "myworkspace";
02162:                        }
02163:                    }
02164:
02165:                    context.put(STATE_TOOL_REGISTRATION_LIST, state
02166:                            .getAttribute(STATE_TOOL_REGISTRATION_LIST));
02167:
02168:                    context.put("check_home", state
02169:                            .getAttribute(STATE_TOOL_HOME_SELECTED));
02170:                    context
02171:                            .put(
02172:                                    "selectedTools",
02173:                                    orderToolIds(
02174:                                            state,
02175:                                            (String) state
02176:                                                    .getAttribute(STATE_SITE_TYPE),
02177:                                            (List) state
02178:                                                    .getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST)));
02179:                    context
02180:                            .put(
02181:                                    "oldSelectedTools",
02182:                                    state
02183:                                            .getAttribute(STATE_TOOL_REGISTRATION_OLD_SELECTED_LIST));
02184:                    context
02185:                            .put(
02186:                                    "oldSelectedHome",
02187:                                    state
02188:                                            .getAttribute(STATE_TOOL_REGISTRATION_OLD_SELECTED_HOME));
02189:                    context.put("continueIndex", "12");
02190:                    if (state.getAttribute(STATE_TOOL_EMAIL_ADDRESS) != null) {
02191:                        context.put("emailId", state
02192:                                .getAttribute(STATE_TOOL_EMAIL_ADDRESS));
02193:                    }
02194:                    context.put("serverName", ServerConfigurationService
02195:                            .getServerName());
02196:                    context.put("newsTitles", (Hashtable) state
02197:                            .getAttribute(STATE_NEWS_TITLES));
02198:                    context.put("wcTitles", (Hashtable) state
02199:                            .getAttribute(STATE_WEB_CONTENT_TITLES));
02200:
02201:                    if (fromENWModifyView(state)) {
02202:                        context.put("back", "26");
02203:                    } else {
02204:                        context.put("back", "4");
02205:                    }
02206:
02207:                    return (String) getContext(data).get("template")
02208:                            + TEMPLATE[15];
02209:                case 16:
02210:                    /*
02211:                     * buildContextForTemplate chef_site-publishUnpublish-sendEmail.vm
02212:                     * 
02213:                     */
02214:                    context.put("title", site.getTitle());
02215:                    context.put("willNotify", state
02216:                            .getAttribute(FORM_WILL_NOTIFY));
02217:                    return (String) getContext(data).get("template")
02218:                            + TEMPLATE[16];
02219:                case 17:
02220:                    /*
02221:                     * buildContextForTemplate chef_site-publishUnpublish-confirm.vm
02222:                     * 
02223:                     */
02224:                    context.put("title", site.getTitle());
02225:                    context.put("continueIndex", "12");
02226:                    SiteInfo sInfo = (SiteInfo) state
02227:                            .getAttribute(STATE_SITE_INFO);
02228:                    if (sInfo.getPublished()) {
02229:                        context.put("publish", Boolean.TRUE);
02230:                        context.put("backIndex", "16");
02231:                    } else {
02232:                        context.put("publish", Boolean.FALSE);
02233:                        context.put("backIndex", "9");
02234:                    }
02235:                    context.put("willNotify", state
02236:                            .getAttribute(FORM_WILL_NOTIFY));
02237:                    return (String) getContext(data).get("template")
02238:                            + TEMPLATE[17];
02239:                case 18:
02240:                    /*
02241:                     * buildContextForTemplate chef_siteInfo-editAccess.vm
02242:                     * 
02243:                     */
02244:                    List publicChangeableSiteTypes = (List) state
02245:                            .getAttribute(STATE_PUBLIC_CHANGEABLE_SITE_TYPES);
02246:                    List unJoinableSiteTypes = (List) state
02247:                            .getAttribute(STATE_DISABLE_JOINABLE_SITE_TYPE);
02248:
02249:                    if (site != null) {
02250:                        // editing existing site
02251:                        context.put("site", site);
02252:                        siteType = state.getAttribute(STATE_SITE_TYPE) != null ? (String) state
02253:                                .getAttribute(STATE_SITE_TYPE)
02254:                                : null;
02255:
02256:                        if (siteType != null
02257:                                && publicChangeableSiteTypes.contains(siteType)) {
02258:                            context.put("publicChangeable", Boolean.TRUE);
02259:                        } else {
02260:                            context.put("publicChangeable", Boolean.FALSE);
02261:                        }
02262:                        context.put("include", Boolean
02263:                                .valueOf(site.isPubView()));
02264:
02265:                        if (siteType != null
02266:                                && !unJoinableSiteTypes.contains(siteType)) {
02267:                            // site can be set as joinable
02268:                            context.put("disableJoinable", Boolean.FALSE);
02269:                            if (state.getAttribute(STATE_JOINABLE) == null) {
02270:                                state.setAttribute(STATE_JOINABLE, Boolean
02271:                                        .valueOf(site.isJoinable()));
02272:                            }
02273:                            if (state.getAttribute(STATE_JOINERROLE) == null
02274:                                    || state.getAttribute(STATE_JOINABLE) != null
02275:                                    && ((Boolean) state
02276:                                            .getAttribute(STATE_JOINABLE))
02277:                                            .booleanValue()) {
02278:                                state.setAttribute(STATE_JOINERROLE, site
02279:                                        .getJoinerRole());
02280:                            }
02281:
02282:                            if (state.getAttribute(STATE_JOINABLE) != null) {
02283:                                context.put("joinable", state
02284:                                        .getAttribute(STATE_JOINABLE));
02285:                            }
02286:                            if (state.getAttribute(STATE_JOINERROLE) != null) {
02287:                                context.put("joinerRole", state
02288:                                        .getAttribute(STATE_JOINERROLE));
02289:                            }
02290:                        } else {
02291:                            // site cannot be set as joinable
02292:                            context.put("disableJoinable", Boolean.TRUE);
02293:                        }
02294:
02295:                        context.put("roles", getRoles(state));
02296:                        context.put("back", "12");
02297:                    } else {
02298:                        siteInfo = (SiteInfo) state
02299:                                .getAttribute(STATE_SITE_INFO);
02300:
02301:                        if (siteInfo.site_type != null
02302:                                && publicChangeableSiteTypes
02303:                                        .contains(siteInfo.site_type)) {
02304:                            context.put("publicChangeable", Boolean.TRUE);
02305:                        } else {
02306:                            context.put("publicChangeable", Boolean.FALSE);
02307:                        }
02308:                        context.put("include", Boolean.valueOf(siteInfo
02309:                                .getInclude()));
02310:                        context.put("published", Boolean.valueOf(siteInfo
02311:                                .getPublished()));
02312:
02313:                        if (siteInfo.site_type != null
02314:                                && !unJoinableSiteTypes
02315:                                        .contains(siteInfo.site_type)) {
02316:                            // site can be set as joinable
02317:                            context.put("disableJoinable", Boolean.FALSE);
02318:                            context.put("joinable", Boolean
02319:                                    .valueOf(siteInfo.joinable));
02320:                            context.put("joinerRole", siteInfo.joinerRole);
02321:                        } else {
02322:                            // site cannot be set as joinable
02323:                            context.put("disableJoinable", Boolean.TRUE);
02324:                        }
02325:
02326:                        // use the type's template, if defined
02327:                        String realmTemplate = "!site.template";
02328:                        if (siteInfo.site_type != null) {
02329:                            realmTemplate = realmTemplate + "."
02330:                                    + siteInfo.site_type;
02331:                        }
02332:                        try {
02333:                            AuthzGroup r = AuthzGroupService
02334:                                    .getAuthzGroup(realmTemplate);
02335:                            context.put("roles", r.getRoles());
02336:                        } catch (GroupNotDefinedException e) {
02337:                            try {
02338:                                AuthzGroup rr = AuthzGroupService
02339:                                        .getAuthzGroup("!site.template");
02340:                                context.put("roles", rr.getRoles());
02341:                            } catch (GroupNotDefinedException ee) {
02342:                            }
02343:                        }
02344:
02345:                        // new site, go to confirmation page
02346:                        context.put("continue", "10");
02347:                        if (fromENWModifyView(state)) {
02348:                            context.put("back", "26");
02349:                        } else if (state.getAttribute(STATE_IMPORT) != null) {
02350:                            context.put("back", "27");
02351:                        } else {
02352:                            context.put("back", "3");
02353:                        }
02354:
02355:                        siteType = (String) state.getAttribute(STATE_SITE_TYPE);
02356:                        if (siteType != null
02357:                                && siteType.equalsIgnoreCase("course")) {
02358:                            context.put("isCourseSite", Boolean.TRUE);
02359:                            context.put("isProjectSite", Boolean.FALSE);
02360:                        } else {
02361:                            context.put("isCourseSite", Boolean.FALSE);
02362:                            if (siteType.equalsIgnoreCase("project")) {
02363:                                context.put("isProjectSite", Boolean.TRUE);
02364:                            }
02365:                        }
02366:                    }
02367:                    return (String) getContext(data).get("template")
02368:                            + TEMPLATE[18];
02369:                case 19:
02370:                    /*
02371:                     * buildContextForTemplate chef_site-addParticipant-sameRole.vm
02372:                     * 
02373:                     */
02374:                    context.put("title", site.getTitle());
02375:                    context.put("roles", getRoles(state));
02376:                    context.put("participantList", state
02377:                            .getAttribute(STATE_ADD_PARTICIPANTS));
02378:                    context.put("form_selectedRole", state
02379:                            .getAttribute("form_selectedRole"));
02380:                    return (String) getContext(data).get("template")
02381:                            + TEMPLATE[19];
02382:                case 20:
02383:                    /*
02384:                     * buildContextForTemplate chef_site-addParticipant-differentRole.vm
02385:                     * 
02386:                     */
02387:                    context.put("title", site.getTitle());
02388:                    context.put("roles", getRoles(state));
02389:                    context.put("selectedRoles", state
02390:                            .getAttribute(STATE_SELECTED_PARTICIPANT_ROLES));
02391:                    context.put("participantList", state
02392:                            .getAttribute(STATE_ADD_PARTICIPANTS));
02393:                    return (String) getContext(data).get("template")
02394:                            + TEMPLATE[20];
02395:                case 21:
02396:                    /*
02397:                     * buildContextForTemplate chef_site-addParticipant-notification.vm
02398:                     * 
02399:                     */
02400:                    context.put("title", site.getTitle());
02401:                    context.put("sitePublished", Boolean.valueOf(site
02402:                            .isPublished()));
02403:                    if (state.getAttribute("form_selectedNotify") == null) {
02404:                        state
02405:                                .setAttribute("form_selectedNotify",
02406:                                        Boolean.FALSE);
02407:                    }
02408:                    context.put("notify", state
02409:                            .getAttribute("form_selectedNotify"));
02410:                    boolean same_role = state.getAttribute("form_same_role") == null ? true
02411:                            : ((Boolean) state.getAttribute("form_same_role"))
02412:                                    .booleanValue();
02413:                    if (same_role) {
02414:                        context.put("backIndex", "19");
02415:                    } else {
02416:                        context.put("backIndex", "20");
02417:                    }
02418:                    return (String) getContext(data).get("template")
02419:                            + TEMPLATE[21];
02420:                case 22:
02421:                    /*
02422:                     * buildContextForTemplate chef_site-addParticipant-confirm.vm
02423:                     * 
02424:                     */
02425:                    context.put("title", site.getTitle());
02426:                    context.put("participants", state
02427:                            .getAttribute(STATE_ADD_PARTICIPANTS));
02428:                    context.put("notify", state
02429:                            .getAttribute("form_selectedNotify"));
02430:                    context.put("roles", getRoles(state));
02431:                    context.put("same_role", state
02432:                            .getAttribute("form_same_role"));
02433:                    context.put("selectedRoles", state
02434:                            .getAttribute(STATE_SELECTED_PARTICIPANT_ROLES));
02435:                    context.put("selectedRole", state
02436:                            .getAttribute("form_selectedRole"));
02437:                    return (String) getContext(data).get("template")
02438:                            + TEMPLATE[22];
02439:                case 23:
02440:                    /*
02441:                     * buildContextForTemplate chef_siteInfo-editAccess-globalAccess.vm
02442:                     * 
02443:                     */
02444:                    context.put("title", site.getTitle());
02445:                    context.put("roles", getRoles(state));
02446:                    if (state.getAttribute("form_joinable") == null) {
02447:                        state.setAttribute("form_joinable", new Boolean(site
02448:                                .isJoinable()));
02449:                    }
02450:                    context.put("form_joinable", state
02451:                            .getAttribute("form_joinable"));
02452:                    if (state.getAttribute("form_joinerRole") == null) {
02453:                        state.setAttribute("form_joinerRole", site
02454:                                .getJoinerRole());
02455:                    }
02456:                    context.put("form_joinerRole", state
02457:                            .getAttribute("form_joinerRole"));
02458:                    return (String) getContext(data).get("template")
02459:                            + TEMPLATE[23];
02460:                case 24:
02461:                    /*
02462:                     * buildContextForTemplate
02463:                     * chef_siteInfo-editAccess-globalAccess-confirm.vm
02464:                     * 
02465:                     */
02466:                    context.put("title", site.getTitle());
02467:                    context.put("form_joinable", state
02468:                            .getAttribute("form_joinable"));
02469:                    context.put("form_joinerRole", state
02470:                            .getAttribute("form_joinerRole"));
02471:                    return (String) getContext(data).get("template")
02472:                            + TEMPLATE[24];
02473:                case 25:
02474:                    /*
02475:                     * buildContextForTemplate chef_changeRoles-confirm.vm
02476:                     * 
02477:                     */
02478:                    Boolean sameRole = (Boolean) state
02479:                            .getAttribute(STATE_CHANGEROLE_SAMEROLE);
02480:                    context.put("sameRole", sameRole);
02481:                    if (sameRole.booleanValue()) {
02482:                        // same role
02483:                        context.put("currentRole", state
02484:                                .getAttribute(STATE_CHANGEROLE_SAMEROLE_ROLE));
02485:                    } else {
02486:                        context
02487:                                .put(
02488:                                        "selectedRoles",
02489:                                        state
02490:                                                .getAttribute(STATE_SELECTED_PARTICIPANT_ROLES));
02491:                    }
02492:
02493:                    roles = getRoles(state);
02494:                    context.put("roles", roles);
02495:
02496:                    context.put("participantSelectedList", state
02497:                            .getAttribute(STATE_SELECTED_PARTICIPANTS));
02498:                    if (state.getAttribute(STATE_SELECTED_PARTICIPANT_ROLES) != null) {
02499:                        context
02500:                                .put(
02501:                                        "selectedRoles",
02502:                                        state
02503:                                                .getAttribute(STATE_SELECTED_PARTICIPANT_ROLES));
02504:                    }
02505:                    context.put("siteTitle", site.getTitle());
02506:                    return (String) getContext(data).get("template")
02507:                            + TEMPLATE[25];
02508:                case 26:
02509:                    /*
02510:                     * buildContextForTemplate chef_site-modifyENW.vm
02511:                     * 
02512:                     */
02513:                    site_type = (String) state.getAttribute(STATE_SITE_TYPE);
02514:                    boolean existingSite = site != null ? true : false;
02515:                    if (existingSite) {
02516:                        // revising a existing site's tool
02517:                        context.put("existingSite", Boolean.TRUE);
02518:                        context.put("back", "4");
02519:                        context.put("continue", "15");
02520:                        context.put("function",
02521:                                "eventSubmit_doAdd_remove_features");
02522:                    } else {
02523:                        // new site
02524:                        context.put("existingSite", Boolean.FALSE);
02525:                        context.put("function", "eventSubmit_doAdd_features");
02526:                        if (state.getAttribute(STATE_IMPORT) != null) {
02527:                            context.put("back", "27");
02528:                        } else {
02529:                            // new site, go to edit access page
02530:                            context.put("back", "3");
02531:                        }
02532:                        context.put("continue", "18");
02533:                    }
02534:
02535:                    context.put(STATE_TOOL_REGISTRATION_LIST, state
02536:                            .getAttribute(STATE_TOOL_REGISTRATION_LIST));
02537:                    toolRegistrationSelectedList = (List) state
02538:                            .getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST);
02539:                    context.put(STATE_TOOL_REGISTRATION_SELECTED_LIST,
02540:                            toolRegistrationSelectedList); // String toolId's
02541:                    String emailId = (String) state
02542:                            .getAttribute(STATE_TOOL_EMAIL_ADDRESS);
02543:                    if (emailId != null) {
02544:                        context.put("emailId", emailId);
02545:                    }
02546:
02547:                    // titles for news tools
02548:                    newsTitles = (Hashtable) state
02549:                            .getAttribute(STATE_NEWS_TITLES);
02550:                    if (newsTitles == null) {
02551:                        newsTitles = new Hashtable();
02552:                        newsTitles.put("sakai.news", NEWS_DEFAULT_TITLE);
02553:                        state.setAttribute(STATE_NEWS_TITLES, newsTitles);
02554:                    }
02555:                    context.put("newsTitles", newsTitles);
02556:                    // urls for news tools
02557:                    newsUrls = (Hashtable) state.getAttribute(STATE_NEWS_URLS);
02558:                    if (newsUrls == null) {
02559:                        newsUrls = new Hashtable();
02560:                        newsUrls.put("sakai.news", NEWS_DEFAULT_URL);
02561:                        state.setAttribute(STATE_NEWS_URLS, newsUrls);
02562:                    }
02563:                    context.put("newsUrls", newsUrls);
02564:                    // titles for web content tools
02565:                    wcTitles = (Hashtable) state
02566:                            .getAttribute(STATE_WEB_CONTENT_TITLES);
02567:                    if (wcTitles == null) {
02568:                        wcTitles = new Hashtable();
02569:                        wcTitles.put("sakai.iframe", WEB_CONTENT_DEFAULT_TITLE);
02570:                        state.setAttribute(STATE_WEB_CONTENT_TITLES, wcTitles);
02571:                    }
02572:                    context.put("wcTitles", wcTitles);
02573:                    // URLs for web content tools
02574:                    wcUrls = (Hashtable) state
02575:                            .getAttribute(STATE_WEB_CONTENT_URLS);
02576:                    if (wcUrls == null) {
02577:                        wcUrls = new Hashtable();
02578:                        wcUrls.put("sakai.iframe", WEB_CONTENT_DEFAULT_URL);
02579:                        state.setAttribute(STATE_WEB_CONTENT_URLS, wcUrls);
02580:                    }
02581:                    context.put("wcUrls", wcUrls);
02582:
02583:                    context.put("serverName", ServerConfigurationService
02584:                            .getServerName());
02585:
02586:                    context
02587:                            .put(
02588:                                    "oldSelectedTools",
02589:                                    state
02590:                                            .getAttribute(STATE_TOOL_REGISTRATION_OLD_SELECTED_LIST));
02591:
02592:                    return (String) getContext(data).get("template")
02593:                            + TEMPLATE[26];
02594:                case 27:
02595:                    /*
02596:                     * buildContextForTemplate chef_site-importSites.vm
02597:                     * 
02598:                     */
02599:                    existingSite = site != null ? true : false;
02600:                    site_type = (String) state.getAttribute(STATE_SITE_TYPE);
02601:                    if (existingSite) {
02602:                        // revising a existing site's tool
02603:                        context.put("continue", "12");
02604:                        context.put("back", "28");
02605:                        context.put("totalSteps", "2");
02606:                        context.put("step", "2");
02607:                        context.put("currentSite", site);
02608:                    } else {
02609:                        // new site, go to edit access page
02610:                        context.put("back", "3");
02611:                        if (fromENWModifyView(state)) {
02612:                            context.put("continue", "26");
02613:                        } else {
02614:                            context.put("continue", "18");
02615:                        }
02616:                    }
02617:                    context.put(STATE_TOOL_REGISTRATION_LIST, state
02618:                            .getAttribute(STATE_TOOL_REGISTRATION_LIST));
02619:                    context.put("selectedTools", orderToolIds(state, site_type,
02620:                            getToolsAvailableForImport(state))); // String toolId's
02621:                    context.put("importSites", state
02622:                            .getAttribute(STATE_IMPORT_SITES));
02623:                    context.put("importSitesTools", state
02624:                            .getAttribute(STATE_IMPORT_SITE_TOOL));
02625:                    context.put("check_home", state
02626:                            .getAttribute(STATE_TOOL_HOME_SELECTED));
02627:                    context.put("importSupportedTools", importTools());
02628:
02629:                    return (String) getContext(data).get("template")
02630:                            + TEMPLATE[27];
02631:                case 28:
02632:                    /*
02633:                     * buildContextForTemplate chef_siteinfo-import.vm
02634:                     * 
02635:                     */
02636:                    context.put("currentSite", site);
02637:                    context.put("importSiteList", state
02638:                            .getAttribute(STATE_IMPORT_SITES));
02639:                    context
02640:                            .put(
02641:                                    "sites",
02642:                                    SiteService
02643:                                            .getSites(
02644:                                                    org.sakaiproject.site.api.SiteService.SelectionType.UPDATE,
02645:                                                    null, null, null,
02646:                                                    SortType.TITLE_ASC, null));
02647:                    return (String) getContext(data).get("template")
02648:                            + TEMPLATE[28];
02649:                case 29:
02650:                    /*
02651:                     * buildContextForTemplate chef_siteinfo-duplicate.vm
02652:                     * 
02653:                     */
02654:                    context.put("siteTitle", site.getTitle());
02655:                    String sType = site.getType();
02656:                    if (sType != null && sType.equals("course")) {
02657:                        context.put("isCourseSite", Boolean.TRUE);
02658:                        context.put("currentTermId", site.getProperties()
02659:                                .getProperty(PROP_SITE_TERM));
02660:                        setTermListForContext(context, state, true); // true =>
02661:                        // upcoming only
02662:                    } else {
02663:                        context.put("isCourseSite", Boolean.FALSE);
02664:                    }
02665:                    if (state.getAttribute(SITE_DUPLICATED) == null) {
02666:                        context.put("siteDuplicated", Boolean.FALSE);
02667:                    } else {
02668:                        context.put("siteDuplicated", Boolean.TRUE);
02669:                        context.put("duplicatedName", state
02670:                                .getAttribute(SITE_DUPLICATED_NAME));
02671:                    }
02672:
02673:                    setTermListForContext(context, state, true);
02674:
02675:                    return (String) getContext(data).get("template")
02676:                            + TEMPLATE[29];
02677:                case 36:
02678:                    /*
02679:                     * buildContextForTemplate chef_site-newSiteCourse.vm
02680:                     */
02681:
02682:                    // SAK-9824
02683:                    Boolean enableCourseCreationForUser = ServerConfigurationService
02684:                            .getBoolean("site.enableCreateAnyUser",
02685:                                    Boolean.FALSE);
02686:                    context.put("enableCourseCreationForUser",
02687:                            enableCourseCreationForUser);
02688:
02689:                    if (site != null) {
02690:                        context.put("site", site);
02691:                        context.put("siteTitle", site.getTitle());
02692:                        setTermListForContext(context, state, false); // false => all
02693:                        // possible
02694:                        // terms
02695:
02696:                        List providerCourseList = (List) state
02697:                                .getAttribute(SITE_PROVIDER_COURSE_LIST);
02698:                        context.put("providerCourseList", providerCourseList);
02699:                        context.put("manualCourseList", state
02700:                                .getAttribute(SITE_MANUAL_COURSE_LIST));
02701:
02702:                        AcademicSession t = (AcademicSession) state
02703:                                .getAttribute(STATE_TERM_SELECTED);
02704:                        context.put("term", t);
02705:                        if (t != null) {
02706:                            String userId = StringUtil
02707:                                    .trimToZero(SessionManager
02708:                                            .getCurrentSessionUserId());
02709:                            List courses = prepareCourseAndSectionListing(
02710:                                    userId, t.getEid(), state);
02711:                            if (courses != null && courses.size() > 0) {
02712:                                Vector notIncludedCourse = new Vector();
02713:
02714:                                // remove included sites
02715:                                for (Iterator i = courses.iterator(); i
02716:                                        .hasNext();) {
02717:                                    CourseObject c = (CourseObject) i.next();
02718:                                    if (!providerCourseList
02719:                                            .contains(c.getEid())) {
02720:                                        notIncludedCourse.add(c);
02721:                                    }
02722:                                }
02723:                                state.setAttribute(STATE_TERM_COURSE_LIST,
02724:                                        notIncludedCourse);
02725:                            } else {
02726:                                state.removeAttribute(STATE_TERM_COURSE_LIST);
02727:                            }
02728:                        }
02729:
02730:                        // step number used in UI
02731:                        state.setAttribute(SITE_CREATE_CURRENT_STEP,
02732:                                new Integer("1"));
02733:                    } else {
02734:                        // need to include both list 'cos STATE_CM_AUTHORIZER_SECTIONS
02735:                        // contains sections that doens't belongs to current user and
02736:                        // STATE_ADD_CLASS_PROVIDER_CHOSEN contains section that does -
02737:                        // v2.4 daisyf
02738:                        if (state.getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN) != null
02739:                                || state
02740:                                        .getAttribute(STATE_CM_AUTHORIZER_SECTIONS) != null) {
02741:                            List<String> providerSectionList = (List<String>) state
02742:                                    .getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN);
02743:                            if (providerSectionList != null) {
02744:                                /*
02745:                                List list1 = prepareSectionObject(providerSectionList,
02746:                                		(String) state
02747:                                				.getAttribute(STATE_CM_CURRENT_USERID));
02748:                                 */
02749:                                context.put("selectedProviderCourse",
02750:                                        providerSectionList);
02751:                            }
02752:
02753:                            List<SectionObject> authorizerSectionList = (List<SectionObject>) state
02754:                                    .getAttribute(STATE_CM_AUTHORIZER_SECTIONS);
02755:                            if (authorizerSectionList != null) {
02756:                                List authorizerList = (List) state
02757:                                        .getAttribute(STATE_CM_AUTHORIZER_LIST);
02758:                                //authorizerList is a list of SectionObject
02759:                                /*
02760:                                String userId = null;
02761:                                if (authorizerList != null) {
02762:                                	userId = (String) authorizerList.get(0);
02763:                                }
02764:                                List list2 = prepareSectionObject(
02765:                                		authorizerSectionList, userId);
02766:                                 */
02767:                                ArrayList list2 = new ArrayList();
02768:                                for (int i = 0; i < authorizerSectionList
02769:                                        .size(); i++) {
02770:                                    SectionObject so = (SectionObject) authorizerSectionList
02771:                                            .get(i);
02772:                                    list2.add(so.getEid());
02773:                                }
02774:                                context.put("selectedAuthorizerCourse", list2);
02775:                            }
02776:                        }
02777:
02778:                        if (state.getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER) != null) {
02779:                            context.put("selectedManualCourse", Boolean.TRUE);
02780:                        }
02781:                        context.put("term", (AcademicSession) state
02782:                                .getAttribute(STATE_TERM_SELECTED));
02783:                        context.put("currentUserId", (String) state
02784:                                .getAttribute(STATE_CM_CURRENT_USERID));
02785:                        context.put("form_additional", (String) state
02786:                                .getAttribute(FORM_ADDITIONAL));
02787:                        context.put("authorizers", getAuthorizers(state));
02788:                    }
02789:                    if (((String) state.getAttribute(STATE_SITE_MODE))
02790:                            .equalsIgnoreCase(SITE_MODE_SITESETUP)) {
02791:                        context.put("backIndex", "1");
02792:                    } else if (((String) state.getAttribute(STATE_SITE_MODE))
02793:                            .equalsIgnoreCase(SITE_MODE_SITEINFO)) {
02794:                        context.put("backIndex", "");
02795:                    }
02796:                    List ll = (List) state.getAttribute(STATE_TERM_COURSE_LIST);
02797:                    context.put("termCourseList", state
02798:                            .getAttribute(STATE_TERM_COURSE_LIST));
02799:
02800:                    // added for 2.4 -daisyf
02801:                    context.put("campusDirectory", getCampusDirectory());
02802:                    context.put("userId", (String) state
02803:                            .getAttribute(STATE_INSTRUCTOR_SELECTED));
02804:                    /*
02805:                     * for measuring how long it takes to load sections java.util.Date
02806:                     * date = new java.util.Date(); M_log.debug("***2. finish at:
02807:                     * "+date); M_log.debug("***3. userId:"+(String) state
02808:                     * .getAttribute(STATE_INSTRUCTOR_SELECTED));
02809:                     */
02810:                    return (String) getContext(data).get("template")
02811:                            + TEMPLATE[36];
02812:                case 37:
02813:                    /*
02814:                     * buildContextForTemplate chef_site-newSiteCourseManual.vm
02815:                     */
02816:                    if (site != null) {
02817:                        context.put("site", site);
02818:                        context.put("siteTitle", site.getTitle());
02819:                        coursesIntoContext(state, context, site);
02820:                    }
02821:                    buildInstructorSectionsList(state, params, context);
02822:                    context.put("form_requiredFields", sectionFieldManager
02823:                            .getRequiredFields());
02824:                    context.put("form_additional", siteInfo.additional);
02825:                    context.put("form_title", siteInfo.title);
02826:                    context.put("form_description", siteInfo.description);
02827:                    context.put("noEmailInIdAccountName",
02828:                            ServerConfigurationService.getString(
02829:                                    "noEmailInIdAccountName", ""));
02830:                    context.put("value_uniqname", state
02831:                            .getAttribute(STATE_SITE_QUEST_UNIQNAME));
02832:                    int number = 1;
02833:                    if (state.getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER) != null) {
02834:                        number = ((Integer) state
02835:                                .getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER))
02836:                                .intValue();
02837:                        context.put("currentNumber", new Integer(number));
02838:                    }
02839:                    context.put("currentNumber", new Integer(number));
02840:                    context.put("listSize", new Integer(number - 1));
02841:                    context.put("fieldValues", state
02842:                            .getAttribute(STATE_MANUAL_ADD_COURSE_FIELDS));
02843:
02844:                    if (state.getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN) != null) {
02845:                        List l = (List) state
02846:                                .getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN);
02847:                        context.put("selectedProviderCourse", l);
02848:                        context.put("size", new Integer(l.size() - 1));
02849:                    }
02850:
02851:                    // v2.4 - added & modified by daisyf
02852:                    if (courseManagementIsImplemented()) {
02853:                        context.put("back", "36");
02854:                    } else {
02855:                        context.put("back", "1");
02856:                    }
02857:
02858:                    if (site == null) {
02859:                        if (state.getAttribute(STATE_AUTO_ADD) != null) {
02860:                            context.put("autoAdd", Boolean.TRUE);
02861:                            // context.put("back", "36");
02862:                        } else {
02863:                            context.put("back", "1");
02864:                        }
02865:                    }
02866:                    context.put("isFutureTerm", state
02867:                            .getAttribute(STATE_FUTURE_TERM_SELECTED));
02868:                    context.put("weeksAhead", ServerConfigurationService
02869:                            .getString(
02870:                                    "roster.available.weeks.before.term.start",
02871:                                    "0"));
02872:                    return (String) getContext(data).get("template")
02873:                            + TEMPLATE[37];
02874:                case 42:
02875:                    /*
02876:                     * buildContextForTemplate chef_site-gradtoolsConfirm.vm
02877:                     * 
02878:                     */
02879:                    siteInfo = (SiteInfo) state.getAttribute(STATE_SITE_INFO);
02880:                    context.put("title", siteInfo.title);
02881:                    context.put("description", siteInfo.description);
02882:                    context
02883:                            .put("short_description",
02884:                                    siteInfo.short_description);
02885:                    toolRegistrationList = (Vector) state
02886:                            .getAttribute(STATE_PROJECT_TOOL_LIST);
02887:                    toolRegistrationSelectedList = (List) state
02888:                            .getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST);
02889:                    context.put(STATE_TOOL_REGISTRATION_SELECTED_LIST,
02890:                            toolRegistrationSelectedList); // String toolId's
02891:                    context.put(STATE_TOOL_REGISTRATION_LIST,
02892:                            toolRegistrationList); // %%%
02893:                    // use
02894:                    // Tool
02895:                    context.put("check_home", state
02896:                            .getAttribute(STATE_TOOL_HOME_SELECTED));
02897:                    context.put("emailId", state
02898:                            .getAttribute(STATE_TOOL_EMAIL_ADDRESS));
02899:                    context.put("serverName", ServerConfigurationService
02900:                            .getServerName());
02901:                    context.put("include", new Boolean(siteInfo.include));
02902:                    return (String) getContext(data).get("template")
02903:                            + TEMPLATE[42];
02904:                case 43:
02905:                    /*
02906:                     * buildContextForTemplate chef_siteInfo-editClass.vm
02907:                     * 
02908:                     */
02909:                    bar = new MenuImpl(portlet, data, (String) state
02910:                            .getAttribute(STATE_ACTION));
02911:                    if (SiteService.allowAddSite(null)) {
02912:                        bar.add(new MenuEntry(rb.getString("java.addclasses"),
02913:                                "doMenu_siteInfo_addClass"));
02914:                    }
02915:                    context.put("menu", bar);
02916:
02917:                    context.put("siteTitle", site.getTitle());
02918:                    coursesIntoContext(state, context, site);
02919:
02920:                    return (String) getContext(data).get("template")
02921:                            + TEMPLATE[43];
02922:                case 44:
02923:                    /*
02924:                     * buildContextForTemplate chef_siteInfo-addCourseConfirm.vm
02925:                     * 
02926:                     */
02927:
02928:                    context.put("siteTitle", site.getTitle());
02929:
02930:                    coursesIntoContext(state, context, site);
02931:
02932:                    context.put("providerAddCourses", state
02933:                            .getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN));
02934:                    if (state.getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER) != null) {
02935:                        int addNumber = ((Integer) state
02936:                                .getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER))
02937:                                .intValue() - 1;
02938:                        context.put("manualAddNumber", new Integer(addNumber));
02939:                        context.put("requestFields", state
02940:                                .getAttribute(STATE_MANUAL_ADD_COURSE_FIELDS));
02941:                        context.put("backIndex", "37");
02942:                    } else {
02943:                        context.put("backIndex", "36");
02944:                    }
02945:                    // those manual inputs
02946:                    context.put("form_requiredFields", sectionFieldManager
02947:                            .getRequiredFields());
02948:                    context.put("fieldValues", state
02949:                            .getAttribute(STATE_MANUAL_ADD_COURSE_FIELDS));
02950:
02951:                    return (String) getContext(data).get("template")
02952:                            + TEMPLATE[44];
02953:
02954:                    // htripath - import materials from classic
02955:                case 45:
02956:                    /*
02957:                     * buildContextForTemplate chef_siteInfo-importMtrlMaster.vm
02958:                     * 
02959:                     */
02960:                    return (String) getContext(data).get("template")
02961:                            + TEMPLATE[45];
02962:
02963:                case 46:
02964:                    /*
02965:                     * buildContextForTemplate chef_siteInfo-importMtrlCopy.vm
02966:                     * 
02967:                     */
02968:                    // this is for list display in listbox
02969:                    context.put("allZipSites", state
02970:                            .getAttribute(ALL_ZIP_IMPORT_SITES));
02971:
02972:                    context.put("finalZipSites", state
02973:                            .getAttribute(FINAL_ZIP_IMPORT_SITES));
02974:                    // zip file
02975:                    // context.put("zipreffile",state.getAttribute(CLASSIC_ZIP_FILE_NAME));
02976:
02977:                    return (String) getContext(data).get("template")
02978:                            + TEMPLATE[46];
02979:
02980:                case 47:
02981:                    /*
02982:                     * buildContextForTemplate chef_siteInfo-importMtrlCopyConfirm.vm
02983:                     * 
02984:                     */
02985:                    context.put("finalZipSites", state
02986:                            .getAttribute(FINAL_ZIP_IMPORT_SITES));
02987:
02988:                    return (String) getContext(data).get("template")
02989:                            + TEMPLATE[47];
02990:
02991:                case 48:
02992:                    /*
02993:                     * buildContextForTemplate chef_siteInfo-importMtrlCopyConfirm.vm
02994:                     * 
02995:                     */
02996:                    context.put("finalZipSites", state
02997:                            .getAttribute(FINAL_ZIP_IMPORT_SITES));
02998:                    return (String) getContext(data).get("template")
02999:                            + TEMPLATE[48];
03000:                case 49:
03001:                    /*
03002:                     * buildContextForTemplate chef_siteInfo-group.vm
03003:                     * 
03004:                     */
03005:                    context.put("site", site);
03006:                    bar = new MenuImpl(portlet, data, (String) state
03007:                            .getAttribute(STATE_ACTION));
03008:                    if (SiteService.allowUpdateSite(site.getId())
03009:                            || SiteService.allowUpdateGroupMembership(site
03010:                                    .getId())) {
03011:                        bar.add(new MenuEntry(rb.getString("java.new"),
03012:                                "doGroup_new"));
03013:                    }
03014:                    context.put("menu", bar);
03015:
03016:                    // the group list
03017:                    sortedBy = (String) state.getAttribute(SORTED_BY);
03018:                    sortedAsc = (String) state.getAttribute(SORTED_ASC);
03019:
03020:                    if (sortedBy != null)
03021:                        context.put("currentSortedBy", sortedBy);
03022:                    if (sortedAsc != null)
03023:                        context.put("currentSortAsc", sortedAsc);
03024:
03025:                    // only show groups created by WSetup tool itself
03026:                    Collection groups = (Collection) site.getGroups();
03027:                    List groupsByWSetup = new Vector();
03028:                    for (Iterator gIterator = groups.iterator(); gIterator
03029:                            .hasNext();) {
03030:                        Group gNext = (Group) gIterator.next();
03031:                        String gProp = gNext.getProperties().getProperty(
03032:                                GROUP_PROP_WSETUP_CREATED);
03033:                        if (gProp != null
03034:                                && gProp.equals(Boolean.TRUE.toString())) {
03035:                            groupsByWSetup.add(gNext);
03036:                        }
03037:                    }
03038:                    if (sortedBy != null && sortedAsc != null) {
03039:                        context.put("groups", new SortedIterator(groupsByWSetup
03040:                                .iterator(), new SiteComparator(sortedBy,
03041:                                sortedAsc)));
03042:                    }
03043:                    return (String) getContext(data).get("template")
03044:                            + TEMPLATE[49];
03045:                case 50:
03046:                    /*
03047:                     * buildContextForTemplate chef_siteInfo-groupedit.vm
03048:                     * 
03049:                     */
03050:                    Group g = getStateGroup(state);
03051:                    if (g != null) {
03052:                        context.put("group", g);
03053:                        context.put("newgroup", Boolean.FALSE);
03054:                    } else {
03055:                        context.put("newgroup", Boolean.TRUE);
03056:                    }
03057:                    if (state.getAttribute(STATE_GROUP_TITLE) != null) {
03058:                        context.put("title", state
03059:                                .getAttribute(STATE_GROUP_TITLE));
03060:                    }
03061:                    if (state.getAttribute(STATE_GROUP_DESCRIPTION) != null) {
03062:                        context.put("description", state
03063:                                .getAttribute(STATE_GROUP_DESCRIPTION));
03064:                    }
03065:                    Iterator siteMembers = new SortedIterator(
03066:                            getParticipantList(state).iterator(),
03067:                            new SiteComparator(SORTED_BY_PARTICIPANT_NAME,
03068:                                    Boolean.TRUE.toString()));
03069:                    if (siteMembers != null && siteMembers.hasNext()) {
03070:                        context.put("generalMembers", siteMembers);
03071:                    }
03072:                    Set groupMembersSet = (Set) state
03073:                            .getAttribute(STATE_GROUP_MEMBERS);
03074:                    if (state.getAttribute(STATE_GROUP_MEMBERS) != null) {
03075:                        context.put("groupMembers", new SortedIterator(
03076:                                groupMembersSet.iterator(), new SiteComparator(
03077:                                        SORTED_BY_MEMBER_NAME, Boolean.TRUE
03078:                                                .toString())));
03079:                    }
03080:                    context.put("groupMembersClone", groupMembersSet);
03081:                    context.put("userDirectoryService", UserDirectoryService
03082:                            .getInstance());
03083:                    return (String) getContext(data).get("template")
03084:                            + TEMPLATE[50];
03085:                case 51:
03086:                    /*
03087:                     * buildContextForTemplate chef_siteInfo-groupDeleteConfirm.vm
03088:                     * 
03089:                     */
03090:                    context.put("site", site);
03091:
03092:                    context.put("removeGroupIds", new ArrayList(Arrays
03093:                            .asList((String[]) state
03094:                                    .getAttribute(STATE_GROUP_REMOVE))));
03095:                    return (String) getContext(data).get("template")
03096:                            + TEMPLATE[51];
03097:                case 53: {
03098:                    /*
03099:                     * build context for chef_site-findCourse.vm
03100:                     */
03101:
03102:                    AcademicSession t = (AcademicSession) state
03103:                            .getAttribute(STATE_TERM_SELECTED);
03104:
03105:                    final List cmLevels = (List) state
03106:                            .getAttribute(STATE_CM_LEVELS), selections = (List) state
03107:                            .getAttribute(STATE_CM_LEVEL_SELECTIONS);
03108:
03109:                    SectionObject selectedSect = (SectionObject) state
03110:                            .getAttribute(STATE_CM_SELECTED_SECTION);
03111:                    List<SectionObject> requestedSections = (List<SectionObject>) state
03112:                            .getAttribute(STATE_CM_REQUESTED_SECTIONS);
03113:
03114:                    if (courseManagementIsImplemented() && cms != null) {
03115:                        context.put("cmsAvailable", new Boolean(true));
03116:                    }
03117:
03118:                    if (cms == null || !courseManagementIsImplemented()
03119:                            || cmLevels == null || cmLevels.size() < 1) {
03120:                        // TODO: redirect to manual entry: case #37
03121:                    } else {
03122:                        Object levelOpts[] = new Object[cmLevels.size()];
03123:                        int numSelections = 0;
03124:
03125:                        if (selections != null)
03126:                            numSelections = selections.size();
03127:
03128:                        // populate options for dropdown lists
03129:                        switch (numSelections) {
03130:                        /*
03131:                         * execution will fall through these statements based on number
03132:                         * of selections already made
03133:                         */
03134:                        case 3:
03135:                            // intentionally blank
03136:                        case 2:
03137:                            levelOpts[2] = getCMSections((String) selections
03138:                                    .get(1));
03139:                        case 1:
03140:                            levelOpts[1] = getCMCourseOfferings(
03141:                                    (String) selections.get(0), t.getEid());
03142:                        default:
03143:                            levelOpts[0] = getCMSubjects();
03144:                        }
03145:
03146:                        context.put("cmLevelOptions", Arrays.asList(levelOpts));
03147:                    }
03148:                    if (state.getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN) != null) {
03149:                        context.put("selectedProviderCourse", state
03150:                                .getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN));
03151:                    }
03152:                    if (state.getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER) != null) {
03153:                        int courseInd = ((Integer) state
03154:                                .getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER))
03155:                                .intValue();
03156:                        context.put("manualAddNumber", new Integer(
03157:                                courseInd - 1));
03158:                        context.put("manualAddFields", state
03159:                                .getAttribute(STATE_MANUAL_ADD_COURSE_FIELDS));
03160:                        context.put("back", "37");
03161:                    }
03162:
03163:                    context.put("term", (AcademicSession) state
03164:                            .getAttribute(STATE_TERM_SELECTED));
03165:
03166:                    context.put("cmLevels", cmLevels);
03167:                    context.put("cmLevelSelections", selections);
03168:                    context.put("selectedCourse", selectedSect);
03169:                    context.put("requestedSections", requestedSections);
03170:                    if (((String) state.getAttribute(STATE_SITE_MODE))
03171:                            .equalsIgnoreCase(SITE_MODE_SITESETUP)) {
03172:                        context.put("backIndex", "36");
03173:                    }
03174:                    // else if (((String) state.getAttribute(STATE_SITE_MODE))
03175:                    // .equalsIgnoreCase(SITE_MODE_SITEINFO)) {
03176:                    // context.put("backIndex", "");
03177:                    // }
03178:
03179:                    return (String) getContext(data).get("template")
03180:                            + TEMPLATE[53];
03181:                }
03182:
03183:                }
03184:                // should never be reached
03185:                return (String) getContext(data).get("template") + TEMPLATE[0];
03186:
03187:            } // buildContextForTemplate
03188:
03189:            /**
03190:             * Launch the Page Order Helper Tool -- for ordering, adding and customizing
03191:             * pages
03192:             * 
03193:             * @see case 12
03194:             * 
03195:             */
03196:            public void doPageOrderHelper(RunData data) {
03197:                SessionState state = ((JetspeedRunData) data)
03198:                        .getPortletSessionState(((JetspeedRunData) data)
03199:                                .getJs_peid());
03200:
03201:                // pass in the siteId of the site to be ordered (so it can configure
03202:                // sites other then the current site)
03203:                SessionManager.getCurrentToolSession().setAttribute(
03204:                        HELPER_ID + ".siteId",
03205:                        ((Site) getStateSite(state)).getId());
03206:
03207:                // launch the helper
03208:                startHelper(data.getRequest(), "sakai-site-pageorder-helper");
03209:            }
03210:
03211:            // htripath: import materials from classic
03212:            /**
03213:             * Master import -- for import materials from a file
03214:             * 
03215:             * @see case 45
03216:             * 
03217:             */
03218:            public void doAttachmentsMtrlFrmFile(RunData data) {
03219:                SessionState state = ((JetspeedRunData) data)
03220:                        .getPortletSessionState(((JetspeedRunData) data)
03221:                                .getJs_peid());
03222:
03223:                // state.setAttribute(FILE_UPLOAD_MAX_SIZE,
03224:                // ServerConfigurationService.getString("content.upload.max", "1"));
03225:                state.setAttribute(STATE_TEMPLATE_INDEX, "45");
03226:            } // doImportMtrlFrmFile
03227:
03228:            /**
03229:             * Handle File Upload request
03230:             * 
03231:             * @see case 46
03232:             * @throws Exception
03233:             */
03234:            public void doUpload_Mtrl_Frm_File(RunData data) {
03235:                SessionState state = ((JetspeedRunData) data)
03236:                        .getPortletSessionState(((JetspeedRunData) data)
03237:                                .getJs_peid());
03238:
03239:                List allzipList = new Vector();
03240:                List finalzipList = new Vector();
03241:                List directcopyList = new Vector();
03242:
03243:                // see if the user uploaded a file
03244:                FileItem fileFromUpload = null;
03245:                String fileName = null;
03246:                fileFromUpload = data.getParameters().getFileItem("file");
03247:
03248:                String max_file_size_mb = ServerConfigurationService.getString(
03249:                        "content.upload.max", "1");
03250:                int max_bytes = 1024 * 1024;
03251:                try {
03252:                    max_bytes = Integer.parseInt(max_file_size_mb) * 1024 * 1024;
03253:                } catch (Exception e) {
03254:                    // if unable to parse an integer from the value
03255:                    // in the properties file, use 1 MB as a default
03256:                    max_file_size_mb = "1";
03257:                    max_bytes = 1024 * 1024;
03258:                }
03259:                if (fileFromUpload == null) {
03260:                    // "The user submitted a file to upload but it was too big!"
03261:                    addAlert(state, rb.getString("importFile.size") + " "
03262:                            + max_file_size_mb + "MB "
03263:                            + rb.getString("importFile.exceeded"));
03264:                } else if (fileFromUpload.getFileName() == null
03265:                        || fileFromUpload.getFileName().length() == 0) {
03266:                    addAlert(state, rb.getString("importFile.choosefile"));
03267:                } else {
03268:                    byte[] fileData = fileFromUpload.get();
03269:
03270:                    if (fileData.length >= max_bytes) {
03271:                        addAlert(state, rb.getString("size") + " "
03272:                                + max_file_size_mb + "MB "
03273:                                + rb.getString("importFile.exceeded"));
03274:                    } else if (fileData.length > 0) {
03275:
03276:                        if (importService.isValidArchive(fileData)) {
03277:                            ImportDataSource importDataSource = importService
03278:                                    .parseFromFile(fileData);
03279:                            Log.info("chef",
03280:                                    "Getting import items from manifest.");
03281:                            List lst = importDataSource.getItemCategories();
03282:                            if (lst != null && lst.size() > 0) {
03283:                                Iterator iter = lst.iterator();
03284:                                while (iter.hasNext()) {
03285:                                    ImportMetadata importdata = (ImportMetadata) iter
03286:                                            .next();
03287:                                    // Log.info("chef","Preparing import
03288:                                    // item '" + importdata.getId() + "'");
03289:                                    if ((!importdata.isMandatory())
03290:                                            && (importdata.getFileName()
03291:                                                    .endsWith(".xml"))) {
03292:                                        allzipList.add(importdata);
03293:                                    } else {
03294:                                        directcopyList.add(importdata);
03295:                                    }
03296:                                }
03297:                            }
03298:                            // set Attributes
03299:                            state
03300:                                    .setAttribute(ALL_ZIP_IMPORT_SITES,
03301:                                            allzipList);
03302:                            state.setAttribute(FINAL_ZIP_IMPORT_SITES,
03303:                                    finalzipList);
03304:                            state.setAttribute(DIRECT_ZIP_IMPORT_SITES,
03305:                                    directcopyList);
03306:                            state.setAttribute(CLASSIC_ZIP_FILE_NAME, fileName);
03307:                            state.setAttribute(IMPORT_DATA_SOURCE,
03308:                                    importDataSource);
03309:
03310:                            state.setAttribute(STATE_TEMPLATE_INDEX, "46");
03311:                        } else { // uploaded file is not a valid archive
03312:
03313:                        }
03314:                    }
03315:                }
03316:            } // doImportMtrlFrmFile
03317:
03318:            /**
03319:             * Handle addition to list request
03320:             * 
03321:             * @param data
03322:             */
03323:            public void doAdd_MtrlSite(RunData data) {
03324:                SessionState state = ((JetspeedRunData) data)
03325:                        .getPortletSessionState(((JetspeedRunData) data)
03326:                                .getJs_peid());
03327:                ParameterParser params = data.getParameters();
03328:
03329:                List zipList = (List) state.getAttribute(ALL_ZIP_IMPORT_SITES);
03330:                List fnlList = (List) state
03331:                        .getAttribute(FINAL_ZIP_IMPORT_SITES);
03332:                List importSites = new ArrayList(Arrays.asList(params
03333:                        .getStrings("addImportSelected")));
03334:
03335:                for (int i = 0; i < importSites.size(); i++) {
03336:                    String value = (String) importSites.get(i);
03337:                    fnlList.add(removeItems(value, zipList));
03338:                }
03339:
03340:                state.setAttribute(ALL_ZIP_IMPORT_SITES, zipList);
03341:                state.setAttribute(FINAL_ZIP_IMPORT_SITES, fnlList);
03342:
03343:                state.setAttribute(STATE_TEMPLATE_INDEX, "46");
03344:            } // doAdd_MtrlSite
03345:
03346:            /**
03347:             * Helper class for Add and remove
03348:             * 
03349:             * @param value
03350:             * @param items
03351:             * @return
03352:             */
03353:            public ImportMetadata removeItems(String value, List items) {
03354:                ImportMetadata result = null;
03355:                for (int i = 0; i < items.size(); i++) {
03356:                    ImportMetadata item = (ImportMetadata) items.get(i);
03357:                    if (value.equals(item.getId())) {
03358:                        result = (ImportMetadata) items.remove(i);
03359:                        break;
03360:                    }
03361:                }
03362:                return result;
03363:            }
03364:
03365:            /**
03366:             * Handle the request for remove
03367:             * 
03368:             * @param data
03369:             */
03370:            public void doRemove_MtrlSite(RunData data) {
03371:                SessionState state = ((JetspeedRunData) data)
03372:                        .getPortletSessionState(((JetspeedRunData) data)
03373:                                .getJs_peid());
03374:                ParameterParser params = data.getParameters();
03375:
03376:                List zipList = (List) state.getAttribute(ALL_ZIP_IMPORT_SITES);
03377:                List fnlList = (List) state
03378:                        .getAttribute(FINAL_ZIP_IMPORT_SITES);
03379:
03380:                List importSites = new ArrayList(Arrays.asList(params
03381:                        .getStrings("removeImportSelected")));
03382:
03383:                for (int i = 0; i < importSites.size(); i++) {
03384:                    String value = (String) importSites.get(i);
03385:                    zipList.add(removeItems(value, fnlList));
03386:                }
03387:
03388:                state.setAttribute(ALL_ZIP_IMPORT_SITES, zipList);
03389:                state.setAttribute(FINAL_ZIP_IMPORT_SITES, fnlList);
03390:
03391:                state.setAttribute(STATE_TEMPLATE_INDEX, "46");
03392:            } // doAdd_MtrlSite
03393:
03394:            /**
03395:             * Handle the request for copy
03396:             * 
03397:             * @param data
03398:             */
03399:            public void doCopyMtrlSite(RunData data) {
03400:                SessionState state = ((JetspeedRunData) data)
03401:                        .getPortletSessionState(((JetspeedRunData) data)
03402:                                .getJs_peid());
03403:
03404:                List fnlList = (List) state
03405:                        .getAttribute(FINAL_ZIP_IMPORT_SITES);
03406:                state.setAttribute(FINAL_ZIP_IMPORT_SITES, fnlList);
03407:
03408:                state.setAttribute(STATE_TEMPLATE_INDEX, "47");
03409:            } // doCopy_MtrlSite
03410:
03411:            /**
03412:             * Handle the request for Save
03413:             * 
03414:             * @param data
03415:             * @throws ImportException
03416:             */
03417:            public void doSaveMtrlSite(RunData data) {
03418:                SessionState state = ((JetspeedRunData) data)
03419:                        .getPortletSessionState(((JetspeedRunData) data)
03420:                                .getJs_peid());
03421:
03422:                String siteId = (String) state
03423:                        .getAttribute(STATE_SITE_INSTANCE_ID);
03424:                List fnlList = (List) state
03425:                        .getAttribute(FINAL_ZIP_IMPORT_SITES);
03426:                List directList = (List) state
03427:                        .getAttribute(DIRECT_ZIP_IMPORT_SITES);
03428:                ImportDataSource importDataSource = (ImportDataSource) state
03429:                        .getAttribute(IMPORT_DATA_SOURCE);
03430:
03431:                // combine the selected import items with the mandatory import items
03432:                fnlList.addAll(directList);
03433:                Log.info("chef", "doSaveMtrlSite() about to import "
03434:                        + fnlList.size() + " top level items");
03435:                Log.info("chef", "doSaveMtrlSite() the importDataSource is "
03436:                        + importDataSource.getClass().getName());
03437:                if (importDataSource instanceof  SakaiArchive) {
03438:                    Log
03439:                            .info("chef",
03440:                                    "doSaveMtrlSite() our data source is a Sakai format");
03441:                    ((SakaiArchive) importDataSource)
03442:                            .buildSourceFolder(fnlList);
03443:                    Log.info("chef", "doSaveMtrlSite() source folder is "
03444:                            + ((SakaiArchive) importDataSource)
03445:                                    .getSourceFolder());
03446:                    ArchiveService.merge(((SakaiArchive) importDataSource)
03447:                            .getSourceFolder(), siteId, null);
03448:                } else {
03449:                    importService.doImportItems(importDataSource
03450:                            .getItemsForCategories(fnlList), siteId);
03451:                }
03452:                // remove attributes
03453:                state.removeAttribute(ALL_ZIP_IMPORT_SITES);
03454:                state.removeAttribute(FINAL_ZIP_IMPORT_SITES);
03455:                state.removeAttribute(DIRECT_ZIP_IMPORT_SITES);
03456:                state.removeAttribute(CLASSIC_ZIP_FILE_NAME);
03457:                state.removeAttribute(SESSION_CONTEXT_ID);
03458:                state.removeAttribute(IMPORT_DATA_SOURCE);
03459:
03460:                state.setAttribute(STATE_TEMPLATE_INDEX, "48");
03461:
03462:                // state.setAttribute(STATE_TEMPLATE_INDEX, "28");
03463:            } // doSave_MtrlSite
03464:
03465:            public void doSaveMtrlSiteMsg(RunData data) {
03466:                SessionState state = ((JetspeedRunData) data)
03467:                        .getPortletSessionState(((JetspeedRunData) data)
03468:                                .getJs_peid());
03469:
03470:                // remove attributes
03471:                state.removeAttribute(ALL_ZIP_IMPORT_SITES);
03472:                state.removeAttribute(FINAL_ZIP_IMPORT_SITES);
03473:                state.removeAttribute(DIRECT_ZIP_IMPORT_SITES);
03474:                state.removeAttribute(CLASSIC_ZIP_FILE_NAME);
03475:                state.removeAttribute(SESSION_CONTEXT_ID);
03476:
03477:                state.setAttribute(STATE_TEMPLATE_INDEX, "12");
03478:
03479:            }
03480:
03481:            // htripath-end
03482:
03483:            /**
03484:             * Handle the site search request.
03485:             */
03486:            public void doSite_search(RunData data, Context context) {
03487:                SessionState state = ((JetspeedRunData) data)
03488:                        .getPortletSessionState(((JetspeedRunData) data)
03489:                                .getJs_peid());
03490:
03491:                // read the search form field into the state object
03492:                String search = StringUtil.trimToNull(data.getParameters()
03493:                        .getString(FORM_SEARCH));
03494:
03495:                // set the flag to go to the prev page on the next list
03496:                if (search == null) {
03497:                    state.removeAttribute(STATE_SEARCH);
03498:                } else {
03499:                    state.setAttribute(STATE_SEARCH, search);
03500:                }
03501:
03502:            } // doSite_search
03503:
03504:            /**
03505:             * Handle a Search Clear request.
03506:             */
03507:            public void doSite_search_clear(RunData data, Context context) {
03508:                SessionState state = ((JetspeedRunData) data)
03509:                        .getPortletSessionState(((JetspeedRunData) data)
03510:                                .getJs_peid());
03511:
03512:                // clear the search
03513:                state.removeAttribute(STATE_SEARCH);
03514:
03515:            } // doSite_search_clear
03516:
03517:            private void coursesIntoContext(SessionState state,
03518:                    Context context, Site site) {
03519:                List providerCourseList = getProviderCourseList(StringUtil
03520:                        .trimToNull(getExternalRealmId(state)));
03521:                if (providerCourseList != null && providerCourseList.size() > 0) {
03522:                    state.setAttribute(SITE_PROVIDER_COURSE_LIST,
03523:                            providerCourseList);
03524:                    context.put("providerCourseList", providerCourseList);
03525:                }
03526:                String manualCourseListString = StringUtil.trimToNull(site
03527:                        .getProperties().getProperty(PROP_SITE_REQUEST_COURSE));
03528:                if (manualCourseListString != null) {
03529:                    List manualCourseList = new Vector();
03530:                    if (manualCourseListString.indexOf("+") != -1) {
03531:                        manualCourseList = new ArrayList(Arrays
03532:                                .asList(manualCourseListString.split("\\+")));
03533:                    } else {
03534:                        manualCourseList.add(manualCourseListString);
03535:                    }
03536:                    state.setAttribute(SITE_MANUAL_COURSE_LIST,
03537:                            manualCourseList);
03538:                    context.put("manualCourseList", manualCourseList);
03539:                }
03540:            }
03541:
03542:            /**
03543:             * buildInstructorSectionsList Build the CourseListItem list for this
03544:             * Instructor for the requested Term
03545:             * 
03546:             */
03547:            private void buildInstructorSectionsList(SessionState state,
03548:                    ParameterParser params, Context context) {
03549:                // Site information
03550:                // The sections of the specified term having this person as Instructor
03551:                context.put("providerCourseSectionList", state
03552:                        .getAttribute("providerCourseSectionList"));
03553:                context.put("manualCourseSectionList", state
03554:                        .getAttribute("manualCourseSectionList"));
03555:                context.put("term", (AcademicSession) state
03556:                        .getAttribute(STATE_TERM_SELECTED));
03557:                setTermListForContext(context, state, false);
03558:                context.put(STATE_TERM_COURSE_LIST, state
03559:                        .getAttribute(STATE_TERM_COURSE_LIST));
03560:                context.put("tlang", rb);
03561:            } // buildInstructorSectionsList
03562:
03563:            /**
03564:             * getProviderCourseList a course site/realm id in one of three formats, for
03565:             * a single section, for multiple sections of the same course, or for a
03566:             * cross-listing having multiple courses. getProviderCourseList parses a
03567:             * realm id into year, term, campus_code, catalog_nbr, section components.
03568:             * 
03569:             * @param id
03570:             *            is a String representation of the course realm id (external
03571:             *            id).
03572:             */
03573:            private List getProviderCourseList(String id) {
03574:                Vector rv = new Vector();
03575:                if (id == null || id == NULL_STRING) {
03576:                    return rv;
03577:                }
03578:                String course_part = NULL_STRING;
03579:                String section_part = NULL_STRING;
03580:                String key = NULL_STRING;
03581:                try {
03582:                    // Break Provider Id into course_nbr parts
03583:                    List course_nbrs = new ArrayList(Arrays.asList(id
03584:                            .split("\\+")));
03585:
03586:                    // Iterate through course_nbrs
03587:                    for (ListIterator i = course_nbrs.listIterator(); i
03588:                            .hasNext();) {
03589:                        String course_nbr = (String) i.next();
03590:
03591:                        // Course_nbr pattern will be for either one section or more
03592:                        // than one section
03593:                        if (course_nbr.indexOf("[") == -1) {
03594:                            // This course_nbr matches the pattern for one section
03595:                            try {
03596:                                rv.add(course_nbr);
03597:                            } catch (Exception e) {
03598:                                M_log.warn(this  + ": cannot find class "
03599:                                        + course_nbr);
03600:                            }
03601:                        } else {
03602:                            // This course_nbr matches the pattern for more than one
03603:                            // section
03604:                            course_part = course_nbr.substring(0, course_nbr
03605:                                    .indexOf("[")); // includes trailing ","
03606:                            section_part = course_nbr.substring(course_nbr
03607:                                    .indexOf("[") + 1, course_nbr.indexOf("]"));
03608:                            String[] sect = section_part.split(",");
03609:                            for (int j = 0; j < sect.length; j++) {
03610:                                key = course_part + sect[j];
03611:                                try {
03612:                                    rv.add(key);
03613:                                } catch (Exception e) {
03614:                                    M_log.warn(this  + ": cannot find class "
03615:                                            + key);
03616:                                }
03617:                            }
03618:                        }
03619:                    }
03620:                } catch (Exception ee) {
03621:                    M_log.warn(ee.getMessage());
03622:                }
03623:                return rv;
03624:
03625:            } // getProviderCourseList
03626:
03627:            /**
03628:             * {@inheritDoc}
03629:             */
03630:            protected int sizeResources(SessionState state) {
03631:                int size = 0;
03632:                String search = "";
03633:                String userId = SessionManager.getCurrentSessionUserId();
03634:
03635:                // if called from the site list page
03636:                if (((String) state.getAttribute(STATE_TEMPLATE_INDEX))
03637:                        .equals("0")) {
03638:                    search = StringUtil.trimToNull((String) state
03639:                            .getAttribute(STATE_SEARCH));
03640:                    if (SecurityService.isSuperUser()) {
03641:                        // admin-type of user
03642:                        String view = (String) state
03643:                                .getAttribute(STATE_VIEW_SELECTED);
03644:                        if (view != null) {
03645:                            if (view.equals(rb.getString("java.allmy"))) {
03646:                                // search for non-user sites, using
03647:                                // the criteria
03648:                                size = SiteService
03649:                                        .countSites(
03650:                                                org.sakaiproject.site.api.SiteService.SelectionType.NON_USER,
03651:                                                null, search, null);
03652:                            } else if (view.equals(rb.getString("java.my"))) {
03653:                                // search for a specific user site
03654:                                // for the particular user id in the
03655:                                // criteria - exact match only
03656:                                try {
03657:                                    SiteService.getSite(SiteService
03658:                                            .getUserSiteId(search));
03659:                                    size++;
03660:                                } catch (IdUnusedException e) {
03661:                                }
03662:                            } else if (view.equalsIgnoreCase(rb
03663:                                    .getString("java.gradtools"))) {
03664:                                // search for gradtools sites
03665:                                size = SiteService
03666:                                        .countSites(
03667:                                                org.sakaiproject.site.api.SiteService.SelectionType.NON_USER,
03668:                                                state
03669:                                                        .getAttribute(GRADTOOLS_SITE_TYPES),
03670:                                                search, null);
03671:                            } else {
03672:                                // search for specific type of sites
03673:                                size = SiteService
03674:                                        .countSites(
03675:                                                org.sakaiproject.site.api.SiteService.SelectionType.NON_USER,
03676:                                                view, search, null);
03677:                            }
03678:                        }
03679:                    } else {
03680:                        Site userWorkspaceSite = null;
03681:                        try {
03682:                            userWorkspaceSite = SiteService.getSite(SiteService
03683:                                    .getUserSiteId(userId));
03684:                        } catch (IdUnusedException e) {
03685:                            M_log.warn("Cannot find user "
03686:                                    + SessionManager.getCurrentSessionUserId()
03687:                                    + "'s My Workspace site.");
03688:                        }
03689:
03690:                        String view = (String) state
03691:                                .getAttribute(STATE_VIEW_SELECTED);
03692:                        if (view != null) {
03693:                            if (view.equals(rb.getString("java.allmy"))) {
03694:                                view = null;
03695:                                // add my workspace if any
03696:                                if (userWorkspaceSite != null) {
03697:                                    if (search != null) {
03698:                                        if (userId.indexOf(search) != -1) {
03699:                                            size++;
03700:                                        }
03701:                                    } else {
03702:                                        size++;
03703:                                    }
03704:                                }
03705:                                size += SiteService
03706:                                        .countSites(
03707:                                                org.sakaiproject.site.api.SiteService.SelectionType.ACCESS,
03708:                                                null, search, null);
03709:                            } else if (view.equalsIgnoreCase(rb
03710:                                    .getString("java.gradtools"))) {
03711:                                // search for gradtools sites
03712:                                size += SiteService
03713:                                        .countSites(
03714:                                                org.sakaiproject.site.api.SiteService.SelectionType.ACCESS,
03715:                                                state
03716:                                                        .getAttribute(GRADTOOLS_SITE_TYPES),
03717:                                                search, null);
03718:                            } else {
03719:                                // search for specific type of sites
03720:                                size += SiteService
03721:                                        .countSites(
03722:                                                org.sakaiproject.site.api.SiteService.SelectionType.ACCESS,
03723:                                                view, search, null);
03724:                            }
03725:                        }
03726:                    }
03727:                }
03728:                // for SiteInfo list page
03729:                else if (state.getAttribute(STATE_TEMPLATE_INDEX).toString()
03730:                        .equals("12")) {
03731:                    List l = (List) state.getAttribute(STATE_PARTICIPANT_LIST);
03732:                    size = (l != null) ? l.size() : 0;
03733:                }
03734:                return size;
03735:
03736:            } // sizeResources
03737:
03738:            /**
03739:             * {@inheritDoc}
03740:             */
03741:            protected List readResourcesPage(SessionState state, int first,
03742:                    int last) {
03743:                String search = StringUtil.trimToNull((String) state
03744:                        .getAttribute(STATE_SEARCH));
03745:
03746:                // if called from the site list page
03747:                if (((String) state.getAttribute(STATE_TEMPLATE_INDEX))
03748:                        .equals("0")) {
03749:                    // get sort type
03750:                    SortType sortType = null;
03751:                    String sortBy = (String) state.getAttribute(SORTED_BY);
03752:                    boolean sortAsc = (new Boolean((String) state
03753:                            .getAttribute(SORTED_ASC))).booleanValue();
03754:                    if (sortBy.equals(SortType.TITLE_ASC.toString())) {
03755:                        sortType = sortAsc ? SortType.TITLE_ASC
03756:                                : SortType.TITLE_DESC;
03757:                    } else if (sortBy.equals(SortType.TYPE_ASC.toString())) {
03758:                        sortType = sortAsc ? SortType.TYPE_ASC
03759:                                : SortType.TYPE_DESC;
03760:                    } else if (sortBy
03761:                            .equals(SortType.CREATED_BY_ASC.toString())) {
03762:                        sortType = sortAsc ? SortType.CREATED_BY_ASC
03763:                                : SortType.CREATED_BY_DESC;
03764:                    } else if (sortBy
03765:                            .equals(SortType.CREATED_ON_ASC.toString())) {
03766:                        sortType = sortAsc ? SortType.CREATED_ON_ASC
03767:                                : SortType.CREATED_ON_DESC;
03768:                    } else if (sortBy.equals(SortType.PUBLISHED_ASC.toString())) {
03769:                        sortType = sortAsc ? SortType.PUBLISHED_ASC
03770:                                : SortType.PUBLISHED_DESC;
03771:                    }
03772:
03773:                    if (SecurityService.isSuperUser()) {
03774:                        // admin-type of user
03775:                        String view = (String) state
03776:                                .getAttribute(STATE_VIEW_SELECTED);
03777:                        if (view != null) {
03778:                            if (view.equals(rb.getString("java.allmy"))) {
03779:                                // search for non-user sites, using the
03780:                                // criteria
03781:                                return SiteService
03782:                                        .getSites(
03783:                                                org.sakaiproject.site.api.SiteService.SelectionType.NON_USER,
03784:                                                null, search, null, sortType,
03785:                                                new PagingPosition(first, last));
03786:                            } else if (view.equalsIgnoreCase(rb
03787:                                    .getString("java.my"))) {
03788:                                // search for a specific user site for
03789:                                // the particular user id in the
03790:                                // criteria - exact match only
03791:                                List rv = new Vector();
03792:                                try {
03793:                                    Site userSite = SiteService
03794:                                            .getSite(SiteService
03795:                                                    .getUserSiteId(search));
03796:                                    rv.add(userSite);
03797:                                } catch (IdUnusedException e) {
03798:                                }
03799:
03800:                                return rv;
03801:                            } else if (view.equalsIgnoreCase(rb
03802:                                    .getString("java.gradtools"))) {
03803:                                // search for gradtools sites
03804:                                return SiteService
03805:                                        .getSites(
03806:                                                org.sakaiproject.site.api.SiteService.SelectionType.NON_USER,
03807:                                                state
03808:                                                        .getAttribute(GRADTOOLS_SITE_TYPES),
03809:                                                search, null, sortType,
03810:                                                new PagingPosition(first, last));
03811:                            } else {
03812:                                // search for a specific site
03813:                                return SiteService
03814:                                        .getSites(
03815:                                                org.sakaiproject.site.api.SiteService.SelectionType.ANY,
03816:                                                view, search, null, sortType,
03817:                                                new PagingPosition(first, last));
03818:                            }
03819:                        }
03820:                    } else {
03821:                        List rv = new Vector();
03822:                        Site userWorkspaceSite = null;
03823:                        String userId = SessionManager
03824:                                .getCurrentSessionUserId();
03825:
03826:                        try {
03827:                            userWorkspaceSite = SiteService.getSite(SiteService
03828:                                    .getUserSiteId(userId));
03829:                        } catch (IdUnusedException e) {
03830:                            M_log.warn("Cannot find user "
03831:                                    + SessionManager.getCurrentSessionUserId()
03832:                                    + "'s My Workspace site.");
03833:                        }
03834:                        String view = (String) state
03835:                                .getAttribute(STATE_VIEW_SELECTED);
03836:                        if (view != null) {
03837:                            if (view.equals(rb.getString("java.allmy"))) {
03838:                                view = null;
03839:                                // add my workspace if any
03840:                                if (userWorkspaceSite != null) {
03841:                                    if (search != null) {
03842:                                        if (userId.indexOf(search) != -1) {
03843:                                            rv.add(userWorkspaceSite);
03844:                                        }
03845:                                    } else {
03846:                                        rv.add(userWorkspaceSite);
03847:                                    }
03848:                                }
03849:                                rv
03850:                                        .addAll(SiteService
03851:                                                .getSites(
03852:                                                        org.sakaiproject.site.api.SiteService.SelectionType.ACCESS,
03853:                                                        null, search, null,
03854:                                                        sortType,
03855:                                                        new PagingPosition(
03856:                                                                first, last)));
03857:                            } else if (view.equalsIgnoreCase(rb
03858:                                    .getString("java.gradtools"))) {
03859:                                // search for a specific user site for
03860:                                // the particular user id in the
03861:                                // criteria - exact match only
03862:                                rv
03863:                                        .addAll(SiteService
03864:                                                .getSites(
03865:                                                        org.sakaiproject.site.api.SiteService.SelectionType.ACCESS,
03866:                                                        state
03867:                                                                .getAttribute(GRADTOOLS_SITE_TYPES),
03868:                                                        search, null, sortType,
03869:                                                        new PagingPosition(
03870:                                                                first, last)));
03871:
03872:                            } else {
03873:                                rv
03874:                                        .addAll(SiteService
03875:                                                .getSites(
03876:                                                        org.sakaiproject.site.api.SiteService.SelectionType.ACCESS,
03877:                                                        view, search, null,
03878:                                                        sortType,
03879:                                                        new PagingPosition(
03880:                                                                first, last)));
03881:                            }
03882:                        }
03883:
03884:                        return rv;
03885:
03886:                    }
03887:                }
03888:                // if in Site Info list view
03889:                else if (state.getAttribute(STATE_TEMPLATE_INDEX).toString()
03890:                        .equals("12")) {
03891:                    List participants = (state
03892:                            .getAttribute(STATE_PARTICIPANT_LIST) != null) ? (List) state
03893:                            .getAttribute(STATE_PARTICIPANT_LIST)
03894:                            : new Vector();
03895:                    PagingPosition page = new PagingPosition(first, last);
03896:                    page.validate(participants.size());
03897:                    participants = participants.subList(page.getFirst() - 1,
03898:                            page.getLast());
03899:
03900:                    return participants;
03901:                }
03902:
03903:                return null;
03904:
03905:            } // readResourcesPage
03906:
03907:            /**
03908:             * get the selected tool ids from import sites
03909:             */
03910:            private boolean select_import_tools(ParameterParser params,
03911:                    SessionState state) {
03912:                // has the user selected any tool for importing?
03913:                boolean anyToolSelected = false;
03914:
03915:                Hashtable importTools = new Hashtable();
03916:
03917:                // the tools for current site
03918:                List selectedTools = (List) state
03919:                        .getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST); // String
03920:                // toolId's
03921:                for (int i = 0; i < selectedTools.size(); i++) {
03922:                    // any tools chosen from import sites?
03923:                    String toolId = (String) selectedTools.get(i);
03924:                    if (params.getStrings(toolId) != null) {
03925:                        importTools.put(toolId, new ArrayList(Arrays
03926:                                .asList(params.getStrings(toolId))));
03927:                        if (!anyToolSelected) {
03928:                            anyToolSelected = true;
03929:                        }
03930:                    }
03931:                }
03932:
03933:                state.setAttribute(STATE_IMPORT_SITE_TOOL, importTools);
03934:
03935:                return anyToolSelected;
03936:
03937:            } // select_import_tools
03938:
03939:            /**
03940:             * Is it from the ENW edit page?
03941:             * 
03942:             * @return ture if the process went through the ENW page; false, otherwise
03943:             */
03944:            private boolean fromENWModifyView(SessionState state) {
03945:                boolean fromENW = false;
03946:                List oTools = (List) state
03947:                        .getAttribute(STATE_TOOL_REGISTRATION_OLD_SELECTED_LIST);
03948:
03949:                List toolList = (List) state
03950:                        .getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST);
03951:                for (int i = 0; i < toolList.size() && !fromENW; i++) {
03952:                    String toolId = (String) toolList.get(i);
03953:                    if (toolId.equals("sakai.mailbox")
03954:                            || toolId.indexOf("sakai.news") != -1
03955:                            || toolId.indexOf("sakai.iframe") != -1) {
03956:                        if (oTools == null) {
03957:                            // if during site creation proces
03958:                            fromENW = true;
03959:                        } else if (!oTools.contains(toolId)) {
03960:                            // if user is adding either EmailArchive tool, News tool or
03961:                            // Web Content tool, go to the Customize page for the tool
03962:                            fromENW = true;
03963:                        }
03964:                    }
03965:                }
03966:                return fromENW;
03967:            }
03968:
03969:            /**
03970:             * doNew_site is called when the Site list tool bar New... button is clicked
03971:             * 
03972:             */
03973:            public void doNew_site(RunData data) throws Exception {
03974:                SessionState state = ((JetspeedRunData) data)
03975:                        .getPortletSessionState(((JetspeedRunData) data)
03976:                                .getJs_peid());
03977:
03978:                // start clean
03979:                cleanState(state);
03980:
03981:                List siteTypes = (List) state.getAttribute(STATE_SITE_TYPES);
03982:                if (siteTypes != null) {
03983:                    if (siteTypes.size() == 1) {
03984:                        String siteType = (String) siteTypes.get(0);
03985:                        if (!siteType.equals(ServerConfigurationService
03986:                                .getString("courseSiteType", ""))) {
03987:                            // if only one site type is allowed and the type isn't
03988:                            // course type
03989:                            // skip the select site type step
03990:                            setNewSiteType(state, siteType);
03991:                            state.setAttribute(STATE_TEMPLATE_INDEX, "2");
03992:                        } else {
03993:                            state.setAttribute(STATE_TEMPLATE_INDEX, "1");
03994:                        }
03995:                    } else {
03996:                        state.setAttribute(STATE_TEMPLATE_INDEX, "1");
03997:                    }
03998:                }
03999:
04000:            } // doNew_site
04001:
04002:            /**
04003:             * doMenu_site_delete is called when the Site list tool bar Delete button is
04004:             * clicked
04005:             * 
04006:             */
04007:            public void doMenu_site_delete(RunData data) {
04008:                SessionState state = ((JetspeedRunData) data)
04009:                        .getPortletSessionState(((JetspeedRunData) data)
04010:                                .getJs_peid());
04011:                ParameterParser params = data.getParameters();
04012:                if (params.getStrings("selectedMembers") == null) {
04013:                    addAlert(state, rb.getString("java.nosites"));
04014:                    state.setAttribute(STATE_TEMPLATE_INDEX, "0");
04015:                    return;
04016:                }
04017:                String[] removals = (String[]) params
04018:                        .getStrings("selectedMembers");
04019:                state.setAttribute(STATE_SITE_REMOVALS, removals);
04020:
04021:                // present confirm delete template
04022:                state.setAttribute(STATE_TEMPLATE_INDEX, "8");
04023:
04024:            } // doMenu_site_delete
04025:
04026:            public void doSite_delete_confirmed(RunData data) {
04027:                SessionState state = ((JetspeedRunData) data)
04028:                        .getPortletSessionState(((JetspeedRunData) data)
04029:                                .getJs_peid());
04030:                ParameterParser params = data.getParameters();
04031:                if (params.getStrings("selectedMembers") == null) {
04032:                    M_log
04033:                            .warn("SiteAction.doSite_delete_confirmed selectedMembers null");
04034:                    state.setAttribute(STATE_TEMPLATE_INDEX, "0"); // return to the
04035:                    // site list
04036:                    return;
04037:                }
04038:                List chosenList = new ArrayList(Arrays.asList(params
04039:                        .getStrings("selectedMembers"))); // Site id's of checked
04040:                // sites
04041:                if (!chosenList.isEmpty()) {
04042:                    for (ListIterator i = chosenList.listIterator(); i
04043:                            .hasNext();) {
04044:                        String id = (String) i.next();
04045:                        String site_title = NULL_STRING;
04046:                        try {
04047:                            site_title = SiteService.getSite(id).getTitle();
04048:                        } catch (IdUnusedException e) {
04049:                            M_log
04050:                                    .warn("SiteAction.doSite_delete_confirmed - IdUnusedException "
04051:                                            + id);
04052:                            addAlert(state, rb.getString("java.sitewith") + " "
04053:                                    + id + " " + rb.getString("java.couldnt")
04054:                                    + " ");
04055:                        }
04056:                        if (SiteService.allowRemoveSite(id)) {
04057:
04058:                            try {
04059:                                Site site = SiteService.getSite(id);
04060:                                site_title = site.getTitle();
04061:                                SiteService.removeSite(site);
04062:                            } catch (IdUnusedException e) {
04063:                                M_log
04064:                                        .warn("SiteAction.doSite_delete_confirmed - IdUnusedException "
04065:                                                + id);
04066:                                addAlert(state, rb.getString("java.sitewith")
04067:                                        + " " + site_title + "(" + id + ") "
04068:                                        + rb.getString("java.couldnt") + " ");
04069:                            } catch (PermissionException e) {
04070:                                M_log
04071:                                        .warn("SiteAction.doSite_delete_confirmed -  PermissionException, site "
04072:                                                + site_title + "(" + id + ").");
04073:                                addAlert(state, site_title + " "
04074:                                        + rb.getString("java.dontperm") + " ");
04075:                            }
04076:                        } else {
04077:                            M_log
04078:                                    .warn("SiteAction.doSite_delete_confirmed -  allowRemoveSite failed for site "
04079:                                            + id);
04080:                            addAlert(state, site_title + " "
04081:                                    + rb.getString("java.dontperm") + " ");
04082:                        }
04083:                    }
04084:                }
04085:                state.setAttribute(STATE_TEMPLATE_INDEX, "0"); // return to the site
04086:                // list
04087:
04088:                // TODO: hard coding this frame id is fragile, portal dependent, and
04089:                // needs to be fixed -ggolden
04090:                // schedulePeerFrameRefresh("sitenav");
04091:                scheduleTopRefresh();
04092:
04093:            } // doSite_delete_confirmed
04094:
04095:            /**
04096:             * get the Site object based on SessionState attribute values
04097:             * 
04098:             * @return Site object related to current state; null if no such Site object
04099:             *         could be found
04100:             */
04101:            protected Site getStateSite(SessionState state) {
04102:                Site site = null;
04103:
04104:                if (state.getAttribute(STATE_SITE_INSTANCE_ID) != null) {
04105:                    try {
04106:                        site = SiteService.getSite((String) state
04107:                                .getAttribute(STATE_SITE_INSTANCE_ID));
04108:                    } catch (Exception ignore) {
04109:                    }
04110:                }
04111:                return site;
04112:
04113:            } // getStateSite
04114:
04115:            /**
04116:             * get the Group object based on SessionState attribute values
04117:             * 
04118:             * @return Group object related to current state; null if no such Group
04119:             *         object could be found
04120:             */
04121:            protected Group getStateGroup(SessionState state) {
04122:                Group group = null;
04123:                Site site = getStateSite(state);
04124:
04125:                if (site != null
04126:                        && state.getAttribute(STATE_GROUP_INSTANCE_ID) != null) {
04127:                    try {
04128:                        group = site.getGroup((String) state
04129:                                .getAttribute(STATE_GROUP_INSTANCE_ID));
04130:                    } catch (Exception ignore) {
04131:                    }
04132:                }
04133:                return group;
04134:
04135:            } // getStateGroup
04136:
04137:            /**
04138:             * do called when "eventSubmit_do" is in the request parameters to c is
04139:             * called from site list menu entry Revise... to get a locked site as
04140:             * editable and to go to the correct template to begin DB version of writes
04141:             * changes to disk at site commit whereas XML version writes at server
04142:             * shutdown
04143:             */
04144:            public void doGet_site(RunData data) {
04145:                SessionState state = ((JetspeedRunData) data)
04146:                        .getPortletSessionState(((JetspeedRunData) data)
04147:                                .getJs_peid());
04148:                ParameterParser params = data.getParameters();
04149:
04150:                // check form filled out correctly
04151:                if (params.getStrings("selectedMembers") == null) {
04152:                    addAlert(state, rb.getString("java.nosites"));
04153:                    state.setAttribute(STATE_TEMPLATE_INDEX, "0");
04154:                    return;
04155:                }
04156:                List chosenList = new ArrayList(Arrays.asList(params
04157:                        .getStrings("selectedMembers"))); // Site id's of checked
04158:                // sites
04159:                String siteId = "";
04160:                if (!chosenList.isEmpty()) {
04161:                    if (chosenList.size() != 1) {
04162:                        addAlert(state, rb.getString("java.please"));
04163:                        state.setAttribute(STATE_TEMPLATE_INDEX, "0");
04164:                        return;
04165:                    }
04166:
04167:                    siteId = (String) chosenList.get(0);
04168:                    getReviseSite(state, siteId);
04169:
04170:                    state.setAttribute(SORTED_BY, SORTED_BY_PARTICIPANT_NAME);
04171:                    state.setAttribute(SORTED_ASC, Boolean.TRUE.toString());
04172:                }
04173:
04174:                if (((String) state.getAttribute(STATE_SITE_MODE))
04175:                        .equalsIgnoreCase(SITE_MODE_SITESETUP)) {
04176:                    state.setAttribute(STATE_PAGESIZE_SITESETUP, state
04177:                            .getAttribute(STATE_PAGESIZE));
04178:                }
04179:
04180:                Hashtable h = (Hashtable) state
04181:                        .getAttribute(STATE_PAGESIZE_SITEINFO);
04182:                if (!h.containsKey(siteId)) {
04183:                    // when first entered Site Info, set the participant list size to
04184:                    // 200 as default
04185:                    state.setAttribute(STATE_PAGESIZE, new Integer(200));
04186:
04187:                    // update
04188:                    h.put(siteId, new Integer(200));
04189:                    state.setAttribute(STATE_PAGESIZE_SITEINFO, h);
04190:                } else {
04191:                    // restore the page size in site info tool
04192:                    state.setAttribute(STATE_PAGESIZE, h.get(siteId));
04193:                }
04194:
04195:            } // doGet_site
04196:
04197:            /**
04198:             * do called when "eventSubmit_do" is in the request parameters to c
04199:             */
04200:            public void doMenu_site_reuse(RunData data) throws Exception {
04201:                // called from chef_site-list.vm after a site has been selected from
04202:                // list
04203:                // create a new Site object based on selected Site object and put in
04204:                // state
04205:                //
04206:                SessionState state = ((JetspeedRunData) data)
04207:                        .getPortletSessionState(((JetspeedRunData) data)
04208:                                .getJs_peid());
04209:                state.setAttribute(STATE_TEMPLATE_INDEX, "1");
04210:
04211:            } // doMenu_site_reuse
04212:
04213:            /**
04214:             * do called when "eventSubmit_do" is in the request parameters to c
04215:             */
04216:            public void doMenu_site_revise(RunData data) throws Exception {
04217:                // called from chef_site-list.vm after a site has been selected from
04218:                // list
04219:                // get site as Site object, check SiteCreationStatus and SiteType of
04220:                // site, put in state, and set STATE_TEMPLATE_INDEX correctly
04221:                // set mode to state_mode_site_type
04222:                SessionState state = ((JetspeedRunData) data)
04223:                        .getPortletSessionState(((JetspeedRunData) data)
04224:                                .getJs_peid());
04225:                state.setAttribute(STATE_TEMPLATE_INDEX, "1");
04226:
04227:            } // doMenu_site_revise
04228:
04229:            /**
04230:             * doView_sites is called when "eventSubmit_doView_sites" is in the request
04231:             * parameters
04232:             */
04233:            public void doView_sites(RunData data) throws Exception {
04234:                SessionState state = ((JetspeedRunData) data)
04235:                        .getPortletSessionState(((JetspeedRunData) data)
04236:                                .getJs_peid());
04237:                ParameterParser params = data.getParameters();
04238:                state.setAttribute(STATE_VIEW_SELECTED, params
04239:                        .getString("view"));
04240:                state.setAttribute(STATE_TEMPLATE_INDEX, "0");
04241:
04242:                resetPaging(state);
04243:
04244:            } // doView_sites
04245:
04246:            /**
04247:             * do called when "eventSubmit_do" is in the request parameters to c
04248:             */
04249:            public void doView(RunData data) throws Exception {
04250:                // called from chef_site-list.vm with a select option to build query of
04251:                // sites
04252:                // 
04253:                // 
04254:                SessionState state = ((JetspeedRunData) data)
04255:                        .getPortletSessionState(((JetspeedRunData) data)
04256:                                .getJs_peid());
04257:                state.setAttribute(STATE_TEMPLATE_INDEX, "1");
04258:            } // doView
04259:
04260:            /**
04261:             * do called when "eventSubmit_do" is in the request parameters to c
04262:             */
04263:            public void doSite_type(RunData data) {
04264:                /*
04265:                 * for measuring how long it takes to load sections java.util.Date date =
04266:                 * new java.util.Date(); M_log.debug("***1. start preparing
04267:                 * section:"+date);
04268:                 */
04269:                SessionState state = ((JetspeedRunData) data)
04270:                        .getPortletSessionState(((JetspeedRunData) data)
04271:                                .getJs_peid());
04272:
04273:                ParameterParser params = data.getParameters();
04274:                int index = Integer.valueOf(params.getString("template-index"))
04275:                        .intValue();
04276:                actionForTemplate("continue", index, params, state);
04277:
04278:                String type = StringUtil.trimToNull(params
04279:                        .getString("itemType"));
04280:
04281:                int totalSteps = 0;
04282:
04283:                if (type == null) {
04284:                    addAlert(state, rb.getString("java.select") + " ");
04285:                } else {
04286:                    setNewSiteType(state, type);
04287:
04288:                    if (type.equalsIgnoreCase("course")) {
04289:                        User user = UserDirectoryService.getCurrentUser();
04290:                        String currentUserId = user.getEid();
04291:
04292:                        String userId = params.getString("userId");
04293:                        if (userId == null || "".equals(userId)) {
04294:                            userId = currentUserId;
04295:                        } else {
04296:                            // implies we are trying to pick sections owned by other
04297:                            // users. Currently "select section by user" page only
04298:                            // take one user per sitte request - daisy's note 1
04299:                            ArrayList<String> list = new ArrayList();
04300:                            list.add(userId);
04301:                            state.setAttribute(STATE_CM_AUTHORIZER_LIST, list);
04302:                        }
04303:                        state.setAttribute(STATE_INSTRUCTOR_SELECTED, userId);
04304:
04305:                        String academicSessionEid = params
04306:                                .getString("selectTerm");
04307:                        AcademicSession t = cms
04308:                                .getAcademicSession(academicSessionEid);
04309:                        state.setAttribute(STATE_TERM_SELECTED, t);
04310:                        if (t != null) {
04311:                            List sections = prepareCourseAndSectionListing(
04312:                                    userId, t.getEid(), state);
04313:
04314:                            int weeks = 0;
04315:                            Calendar c = (Calendar) Calendar.getInstance()
04316:                                    .clone();
04317:                            try {
04318:                                weeks = Integer
04319:                                        .parseInt(ServerConfigurationService
04320:                                                .getString(
04321:                                                        "roster.available.weeks.before.term.start",
04322:                                                        "0"));
04323:                                c.add(Calendar.DATE, weeks * 7);
04324:                            } catch (Exception ignore) {
04325:                            }
04326:
04327:                            if ((sections == null || sections != null
04328:                                    && sections.size() == 0)
04329:                                    && c.getTimeInMillis() < t.getStartDate()
04330:                                            .getTime()) {
04331:                                // if a future term is selected
04332:                                state.setAttribute(STATE_FUTURE_TERM_SELECTED,
04333:                                        Boolean.TRUE);
04334:                            } else {
04335:                                state.setAttribute(STATE_FUTURE_TERM_SELECTED,
04336:                                        Boolean.FALSE);
04337:                            }
04338:
04339:                            if (sections != null && sections.size() > 0) {
04340:                                state.setAttribute(STATE_TERM_COURSE_LIST,
04341:                                        sections);
04342:                                state.setAttribute(STATE_TEMPLATE_INDEX, "36");
04343:                                state
04344:                                        .setAttribute(STATE_AUTO_ADD,
04345:                                                Boolean.TRUE);
04346:                            } else {
04347:                                state.removeAttribute(STATE_TERM_COURSE_LIST);
04348:                            }
04349:                            // v2.4 added by daisyf
04350:                            if (courseManagementIsImplemented()) {
04351:                                state.setAttribute(STATE_TEMPLATE_INDEX, "36");
04352:                                totalSteps = 5;
04353:                            } else {
04354:                                state.setAttribute(STATE_TEMPLATE_INDEX, "37");
04355:                                totalSteps = 6;
04356:                            }
04357:
04358:                        } else { // type!="course"
04359:                            state.setAttribute(STATE_TEMPLATE_INDEX, "37");
04360:                            totalSteps = 5;
04361:                        }
04362:                    } else if (type.equals("project")) {
04363:                        totalSteps = 4;
04364:                        state.setAttribute(STATE_TEMPLATE_INDEX, "2");
04365:                    } else if (type.equals(SITE_TYPE_GRADTOOLS_STUDENT)) {
04366:                        // if a GradTools site use pre-defined site info and exclude
04367:                        // from public listing
04368:                        SiteInfo siteInfo = new SiteInfo();
04369:                        if (state.getAttribute(STATE_SITE_INFO) != null) {
04370:                            siteInfo = (SiteInfo) state
04371:                                    .getAttribute(STATE_SITE_INFO);
04372:                        }
04373:                        User currentUser = UserDirectoryService
04374:                                .getCurrentUser();
04375:                        siteInfo.title = rb.getString("java.grad") + " - "
04376:                                + currentUser.getId();
04377:                        siteInfo.description = rb.getString("java.gradsite")
04378:                                + " " + currentUser.getDisplayName();
04379:                        siteInfo.short_description = rb.getString("java.grad")
04380:                                + " - " + currentUser.getId();
04381:                        siteInfo.include = false;
04382:                        state.setAttribute(STATE_SITE_INFO, siteInfo);
04383:
04384:                        // skip directly to confirm creation of site
04385:                        state.setAttribute(STATE_TEMPLATE_INDEX, "42");
04386:                    } else {
04387:                        state.setAttribute(STATE_TEMPLATE_INDEX, "2");
04388:                    }
04389:                }
04390:
04391:                if (state.getAttribute(SITE_CREATE_TOTAL_STEPS) == null) {
04392:                    state.setAttribute(SITE_CREATE_TOTAL_STEPS, new Integer(
04393:                            totalSteps));
04394:                }
04395:
04396:                if (state.getAttribute(SITE_CREATE_CURRENT_STEP) == null) {
04397:                    state
04398:                            .setAttribute(SITE_CREATE_CURRENT_STEP,
04399:                                    new Integer(1));
04400:                }
04401:
04402:            } // doSite_type
04403:
04404:            public void doChange_user(RunData data) {
04405:                doSite_type(data);
04406:            } // doChange_user
04407:
04408:            /**
04409:             * cleanEditGroupParams clean the state parameters used by editing group
04410:             * process
04411:             * 
04412:             */
04413:            public void cleanEditGroupParams(SessionState state) {
04414:                state.removeAttribute(STATE_GROUP_INSTANCE_ID);
04415:                state.removeAttribute(STATE_GROUP_TITLE);
04416:                state.removeAttribute(STATE_GROUP_DESCRIPTION);
04417:                state.removeAttribute(STATE_GROUP_MEMBERS);
04418:                state.removeAttribute(STATE_GROUP_REMOVE);
04419:
04420:            } // cleanEditGroupParams
04421:
04422:            /**
04423:             * doGroup_edit
04424:             * 
04425:             */
04426:            public void doGroup_update(RunData data) {
04427:                SessionState state = ((JetspeedRunData) data)
04428:                        .getPortletSessionState(((JetspeedRunData) data)
04429:                                .getJs_peid());
04430:                ParameterParser params = data.getParameters();
04431:
04432:                Set gMemberSet = (Set) state.getAttribute(STATE_GROUP_MEMBERS);
04433:                Site site = getStateSite(state);
04434:
04435:                String title = StringUtil.trimToNull(params.getString(rb
04436:                        .getString("group.title")));
04437:                state.setAttribute(STATE_GROUP_TITLE, title);
04438:
04439:                String description = StringUtil.trimToZero(params.getString(rb
04440:                        .getString("group.description")));
04441:                state.setAttribute(STATE_GROUP_DESCRIPTION, description);
04442:
04443:                boolean found = false;
04444:                String option = params.getString("option");
04445:
04446:                if (option.equals("add")) {
04447:                    // add selected members into it
04448:                    if (params.getStrings("generallist") != null) {
04449:                        List addMemberIds = new ArrayList(Arrays.asList(params
04450:                                .getStrings("generallist")));
04451:                        for (int i = 0; i < addMemberIds.size(); i++) {
04452:                            String aId = (String) addMemberIds.get(i);
04453:                            found = false;
04454:                            for (Iterator iSet = gMemberSet.iterator(); !found
04455:                                    && iSet.hasNext();) {
04456:                                if (((Member) iSet.next()).getUserEid().equals(
04457:                                        aId)) {
04458:                                    found = true;
04459:                                }
04460:                            }
04461:                            if (!found) {
04462:                                try {
04463:                                    User u = UserDirectoryService.getUser(aId);
04464:                                    gMemberSet.add(site.getMember(u.getId()));
04465:                                } catch (UserNotDefinedException e) {
04466:                                    try {
04467:                                        User u2 = UserDirectoryService
04468:                                                .getUserByEid(aId);
04469:                                        gMemberSet.add(site.getMember(u2
04470:                                                .getId()));
04471:                                    } catch (UserNotDefinedException ee) {
04472:                                        M_log
04473:                                                .warn(this  + ee.getMessage()
04474:                                                        + aId);
04475:                                    }
04476:                                }
04477:                            }
04478:                        }
04479:                    }
04480:                    state.setAttribute(STATE_GROUP_MEMBERS, gMemberSet);
04481:                } else if (option.equals("remove")) {
04482:                    // update the group member list by remove selected members from it
04483:                    if (params.getStrings("grouplist") != null) {
04484:                        List removeMemberIds = new ArrayList(Arrays
04485:                                .asList(params.getStrings("grouplist")));
04486:                        for (int i = 0; i < removeMemberIds.size(); i++) {
04487:                            found = false;
04488:                            for (Iterator iSet = gMemberSet.iterator(); !found
04489:                                    && iSet.hasNext();) {
04490:                                Member mSet = (Member) iSet.next();
04491:                                if (mSet.getUserId().equals(
04492:                                        (String) removeMemberIds.get(i))) {
04493:                                    found = true;
04494:                                    gMemberSet.remove(mSet);
04495:                                }
04496:                            }
04497:                        }
04498:                    }
04499:                    state.setAttribute(STATE_GROUP_MEMBERS, gMemberSet);
04500:                } else if (option.equals("cancel")) {
04501:                    // cancel from the update the group member process
04502:                    doCancel_create(data);
04503:                    cleanEditGroupParams(state);
04504:
04505:                } else if (option.equals("save")) {
04506:                    Group group = null;
04507:                    if (site != null
04508:                            && state.getAttribute(STATE_GROUP_INSTANCE_ID) != null) {
04509:                        try {
04510:                            group = site.getGroup((String) state
04511:                                    .getAttribute(STATE_GROUP_INSTANCE_ID));
04512:                        } catch (Exception ignore) {
04513:                        }
04514:                    }
04515:
04516:                    if (title == null) {
04517:                        addAlert(state, rb.getString("editgroup.titlemissing"));
04518:                    } else {
04519:                        if (group == null) {
04520:                            // when adding a group, check whether the group title has
04521:                            // been used already
04522:                            boolean titleExist = false;
04523:                            for (Iterator iGroups = site.getGroups().iterator(); !titleExist
04524:                                    && iGroups.hasNext();) {
04525:                                Group iGroup = (Group) iGroups.next();
04526:                                if (iGroup.getTitle().equals(title)) {
04527:                                    // found same title
04528:                                    titleExist = true;
04529:                                }
04530:                            }
04531:                            if (titleExist) {
04532:                                addAlert(state, rb
04533:                                        .getString("group.title.same"));
04534:                            }
04535:                        }
04536:                    }
04537:
04538:                    if (state.getAttribute(STATE_MESSAGE) == null) {
04539:                        if (group == null) {
04540:                            // adding new group
04541:                            group = site.addGroup();
04542:                            group.getProperties().addProperty(
04543:                                    GROUP_PROP_WSETUP_CREATED,
04544:                                    Boolean.TRUE.toString());
04545:                        }
04546:
04547:                        if (group != null) {
04548:                            group.setTitle(title);
04549:                            group.setDescription(description);
04550:
04551:                            // save the modification to group members
04552:
04553:                            // remove those no longer included in the group
04554:                            Set members = group.getMembers();
04555:                            for (Iterator iMembers = members.iterator(); iMembers
04556:                                    .hasNext();) {
04557:                                found = false;
04558:                                String mId = ((Member) iMembers.next())
04559:                                        .getUserId();
04560:                                for (Iterator iMemberSet = gMemberSet
04561:                                        .iterator(); !found
04562:                                        && iMemberSet.hasNext();) {
04563:                                    if (mId.equals(((Member) iMemberSet.next())
04564:                                            .getUserId())) {
04565:                                        found = true;
04566:                                    }
04567:
04568:                                }
04569:                                if (!found) {
04570:                                    group.removeMember(mId);
04571:                                }
04572:                            }
04573:
04574:                            // add those seleted members
04575:                            for (Iterator iMemberSet = gMemberSet.iterator(); iMemberSet
04576:                                    .hasNext();) {
04577:                                String memberId = ((Member) iMemberSet.next())
04578:                                        .getUserId();
04579:                                if (group.getUserRole(memberId) == null) {
04580:                                    Role r = site.getUserRole(memberId);
04581:                                    Member m = site.getMember(memberId);
04582:                                    // for every member added through the "Manage
04583:                                    // Groups" interface, he should be defined as
04584:                                    // non-provided
04585:                                    group.addMember(memberId, r != null ? r
04586:                                            .getId() : "", m != null ? m
04587:                                            .isActive() : true, false);
04588:                                }
04589:                            }
04590:
04591:                            if (state.getAttribute(STATE_MESSAGE) == null) {
04592:                                try {
04593:                                    SiteService.save(site);
04594:                                } catch (IdUnusedException e) {
04595:                                } catch (PermissionException e) {
04596:                                }
04597:
04598:                                // return to group list view
04599:                                state.setAttribute(STATE_TEMPLATE_INDEX, "49");
04600:                                cleanEditGroupParams(state);
04601:                            }
04602:                        }
04603:                    }
04604:                }
04605:
04606:            } // doGroup_updatemembers
04607:
04608:            /**
04609:             * doGroup_new
04610:             * 
04611:             */
04612:            public void doGroup_new(RunData data) {
04613:                SessionState state = ((JetspeedRunData) data)
04614:                        .getPortletSessionState(((JetspeedRunData) data)
04615:                                .getJs_peid());
04616:                if (state.getAttribute(STATE_GROUP_TITLE) == null) {
04617:                    state.setAttribute(STATE_GROUP_TITLE, "");
04618:                }
04619:                if (state.getAttribute(STATE_GROUP_DESCRIPTION) == null) {
04620:                    state.setAttribute(STATE_GROUP_DESCRIPTION, "");
04621:                }
04622:                if (state.getAttribute(STATE_GROUP_MEMBERS) == null) {
04623:                    state.setAttribute(STATE_GROUP_MEMBERS, new HashSet());
04624:                }
04625:                state.setAttribute(STATE_TEMPLATE_INDEX, "50");
04626:
04627:            } // doGroup_new
04628:
04629:            /**
04630:             * doGroup_edit
04631:             * 
04632:             */
04633:            public void doGroup_edit(RunData data) {
04634:                SessionState state = ((JetspeedRunData) data)
04635:                        .getPortletSessionState(((JetspeedRunData) data)
04636:                                .getJs_peid());
04637:                String groupId = data.getParameters().getString("groupId");
04638:                state.setAttribute(STATE_GROUP_INSTANCE_ID, groupId);
04639:
04640:                Site site = getStateSite(state);
04641:                if (site != null) {
04642:                    Group g = site.getGroup(groupId);
04643:                    if (g != null) {
04644:                        if (state.getAttribute(STATE_GROUP_TITLE) == null) {
04645:                            state.setAttribute(STATE_GROUP_TITLE, g.getTitle());
04646:                        }
04647:                        if (state.getAttribute(STATE_GROUP_DESCRIPTION) == null) {
04648:                            state.setAttribute(STATE_GROUP_DESCRIPTION, g
04649:                                    .getDescription());
04650:                        }
04651:                        if (state.getAttribute(STATE_GROUP_MEMBERS) == null) {
04652:                            // double check the member existance
04653:                            Set gMemberSet = g.getMembers();
04654:                            Set rvGMemberSet = new HashSet();
04655:                            for (Iterator iSet = gMemberSet.iterator(); iSet
04656:                                    .hasNext();) {
04657:                                Member member = (Member) iSet.next();
04658:                                try {
04659:                                    UserDirectoryService.getUser(member
04660:                                            .getUserId());
04661:                                    ((Set) rvGMemberSet).add(member);
04662:                                } catch (UserNotDefinedException e) {
04663:                                    // cannot find user
04664:                                    M_log.warn(this 
04665:                                            + rb.getString("user.notdefined")
04666:                                            + member.getUserId());
04667:                                }
04668:                            }
04669:                            state.setAttribute(STATE_GROUP_MEMBERS,
04670:                                    rvGMemberSet);
04671:                        }
04672:                    }
04673:                }
04674:                state.setAttribute(STATE_TEMPLATE_INDEX, "50");
04675:
04676:            } // doGroup_edit
04677:
04678:            /**
04679:             * doGroup_remove_prep Go to confirmation page before deleting group(s)
04680:             * 
04681:             */
04682:            public void doGroup_remove_prep(RunData data) {
04683:                SessionState state = ((JetspeedRunData) data)
04684:                        .getPortletSessionState(((JetspeedRunData) data)
04685:                                .getJs_peid());
04686:                String[] removeGroupIds = data.getParameters().getStrings(
04687:                        "removeGroups");
04688:
04689:                if (removeGroupIds.length > 0) {
04690:                    state.setAttribute(STATE_GROUP_REMOVE, removeGroupIds);
04691:                    state.setAttribute(STATE_TEMPLATE_INDEX, "51");
04692:                }
04693:
04694:            } // doGroup_remove_prep
04695:
04696:            /**
04697:             * doGroup_remove_confirmed Delete selected groups after confirmation
04698:             * 
04699:             */
04700:            public void doGroup_remove_confirmed(RunData data) {
04701:                SessionState state = ((JetspeedRunData) data)
04702:                        .getPortletSessionState(((JetspeedRunData) data)
04703:                                .getJs_peid());
04704:                String[] removeGroupIds = (String[]) state
04705:                        .getAttribute(STATE_GROUP_REMOVE);
04706:
04707:                Site site = getStateSite(state);
04708:                for (int i = 0; i < removeGroupIds.length; i++) {
04709:                    if (site != null) {
04710:                        Group g = site.getGroup(removeGroupIds[i]);
04711:                        if (g != null) {
04712:                            site.removeGroup(g);
04713:                        }
04714:                    }
04715:                }
04716:                try {
04717:                    SiteService.save(site);
04718:                } catch (IdUnusedException e) {
04719:                    addAlert(state, rb
04720:                            .getString("editgroup.site.notfound.alert"));
04721:                } catch (PermissionException e) {
04722:                    addAlert(state, rb
04723:                            .getString("editgroup.site.permission.alert"));
04724:                }
04725:
04726:                if (state.getAttribute(STATE_MESSAGE) == null) {
04727:                    cleanEditGroupParams(state);
04728:                    state.setAttribute(STATE_TEMPLATE_INDEX, "49");
04729:                }
04730:
04731:            } // doGroup_remove_confirmed
04732:
04733:            /**
04734:             * doMenu_edit_site_info The menu choice to enter group view
04735:             * 
04736:             */
04737:            public void doMenu_group(RunData data) {
04738:                SessionState state = ((JetspeedRunData) data)
04739:                        .getPortletSessionState(((JetspeedRunData) data)
04740:                                .getJs_peid());
04741:
04742:                // reset sort criteria
04743:                state.setAttribute(SORTED_BY, rb.getString("group.title"));
04744:                state.setAttribute(SORTED_ASC, Boolean.TRUE.toString());
04745:
04746:                state.setAttribute(STATE_TEMPLATE_INDEX, "49");
04747:
04748:            } // doMenu_group
04749:
04750:            /**
04751:             * dispatch to different functions based on the option value in the
04752:             * parameter
04753:             */
04754:            public void doManual_add_course(RunData data) {
04755:                SessionState state = ((JetspeedRunData) data)
04756:                        .getPortletSessionState(((JetspeedRunData) data)
04757:                                .getJs_peid());
04758:                ParameterParser params = data.getParameters();
04759:
04760:                String option = params.getString("option");
04761:                if (option.equalsIgnoreCase("change")
04762:                        || option.equalsIgnoreCase("add")) {
04763:                    readCourseSectionInfo(state, params);
04764:
04765:                    String uniqname = StringUtil.trimToNull(params
04766:                            .getString("uniqname"));
04767:                    state.setAttribute(STATE_SITE_QUEST_UNIQNAME, uniqname);
04768:
04769:                    if (getStateSite(state) == null) {
04770:                        // creating new site
04771:                        updateSiteInfo(params, state);
04772:                    }
04773:
04774:                    if (option.equalsIgnoreCase("add")) {
04775:
04776:                        if (state.getAttribute(STATE_FUTURE_TERM_SELECTED) != null
04777:                                && !((Boolean) state
04778:                                        .getAttribute(STATE_FUTURE_TERM_SELECTED))
04779:                                        .booleanValue()) {
04780:                            // if a future term is selected, do not check authorization
04781:                            // uniqname
04782:                            if (uniqname == null) {
04783:                                addAlert(
04784:                                        state,
04785:                                        rb.getString("java.author")
04786:                                                + " "
04787:                                                + ServerConfigurationService
04788:                                                        .getString("noEmailInIdAccountName")
04789:                                                + ". ");
04790:                            } else {
04791:                                try {
04792:                                    UserDirectoryService.getUserByEid(uniqname);
04793:                                } catch (UserNotDefinedException e) {
04794:                                    addAlert(
04795:                                            state,
04796:                                            rb.getString("java.validAuthor1")
04797:                                                    + " "
04798:                                                    + ServerConfigurationService
04799:                                                            .getString("noEmailInIdAccountName")
04800:                                                    + " "
04801:                                                    + rb
04802:                                                            .getString("java.validAuthor2"));
04803:                                }
04804:                            }
04805:                        }
04806:                        if (state.getAttribute(STATE_MESSAGE) == null) {
04807:                            if (getStateSite(state) == null) {
04808:                                state.setAttribute(STATE_TEMPLATE_INDEX, "2");
04809:                            } else {
04810:                                state.setAttribute(STATE_TEMPLATE_INDEX, "44");
04811:                            }
04812:                        }
04813:                        updateCurrentStep(state, true);
04814:                    }
04815:                } else if (option.equalsIgnoreCase("back")) {
04816:                    doBack(data);
04817:                    if (state.getAttribute(STATE_MESSAGE) == null) {
04818:                        updateCurrentStep(state, false);
04819:                    }
04820:                } else if (option.equalsIgnoreCase("cancel")) {
04821:                    if (getStateSite(state) == null) {
04822:                        doCancel_create(data);
04823:                    } else {
04824:                        doCancel(data);
04825:                    }
04826:                }
04827:
04828:            } // doManual_add_course
04829:
04830:            /**
04831:             * read the input information of subject, course and section in the manual
04832:             * site creation page
04833:             */
04834:            private void readCourseSectionInfo(SessionState state,
04835:                    ParameterParser params) {
04836:                int oldNumber = 1;
04837:                if (state.getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER) != null) {
04838:                    oldNumber = ((Integer) state
04839:                            .getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER))
04840:                            .intValue();
04841:                }
04842:
04843:                // read the user input
04844:                int validInputSites = 0;
04845:                boolean validInput = true;
04846:                List requiredFields = sectionFieldManager.getRequiredFields();
04847:                List multiCourseInputs = new Vector();
04848:                for (int i = 0; i < oldNumber; i++) {
04849:                    List aCourseInputs = new Vector();
04850:                    int emptyInputNum = 0;
04851:
04852:                    // iterate through all required fields
04853:                    for (int k = 0; k < requiredFields.size(); k++) {
04854:                        SectionField sectionField = (SectionField) requiredFields
04855:                                .get(k);
04856:                        String fieldLabel = sectionField.getLabelKey();
04857:                        String fieldInput = StringUtil.trimToZero(params
04858:                                .getString(fieldLabel + i));
04859:                        sectionField.setValue(fieldInput);
04860:                        aCourseInputs.add(sectionField);
04861:                        if (fieldInput.length() == 0) {
04862:                            // is this an empty String input?
04863:                            emptyInputNum++;
04864:                        }
04865:                        // add to the multiCourseInput vector
04866:                    }
04867:                    multiCourseInputs.add(i, aCourseInputs);
04868:
04869:                    // is any input invalid?
04870:                    if (emptyInputNum == 0) {
04871:                        // valid if all the inputs are not empty
04872:                        validInputSites++;
04873:                    } else if (emptyInputNum == requiredFields.size()) {
04874:                        // ignore if all inputs are empty
04875:                    } else {
04876:                        if (state.getAttribute(STATE_FUTURE_TERM_SELECTED) != null
04877:                                && ((Boolean) state
04878:                                        .getAttribute(STATE_FUTURE_TERM_SELECTED))
04879:                                        .booleanValue()) {
04880:                            // if future term selected, then not all fields are required
04881:                            // %%%
04882:                            validInputSites++;
04883:                        } else {
04884:                            validInput = false;
04885:                        }
04886:                    }
04887:                }
04888:
04889:                // how many more course/section to include in the site?
04890:                String option = params.getString("option");
04891:                if (option.equalsIgnoreCase("change")) {
04892:                    if (params.getString("number") != null) {
04893:                        int newNumber = Integer.parseInt(params
04894:                                .getString("number"));
04895:                        state.setAttribute(STATE_MANUAL_ADD_COURSE_NUMBER,
04896:                                new Integer(oldNumber + newNumber));
04897:
04898:                        for (int j = 0; j < newNumber; j++) {
04899:                            // add a new course input
04900:                            List aCourseInputs = new Vector();
04901:                            // iterate through all required fields
04902:                            for (int m = 0; m < requiredFields.size(); m++) {
04903:                                aCourseInputs = sectionFieldManager
04904:                                        .getRequiredFields();
04905:                            }
04906:                            multiCourseInputs.add(aCourseInputs);
04907:                        }
04908:                    }
04909:                }
04910:
04911:                state.setAttribute(STATE_MANUAL_ADD_COURSE_FIELDS,
04912:                        multiCourseInputs);
04913:
04914:                if (!option.equalsIgnoreCase("change")) {
04915:                    if (!validInput || validInputSites == 0) {
04916:                        // not valid input
04917:                        addAlert(state, rb.getString("java.miss"));
04918:                    } else {
04919:                        // valid input, adjust the add course number
04920:                        state.setAttribute(STATE_MANUAL_ADD_COURSE_NUMBER,
04921:                                new Integer(validInputSites));
04922:                    }
04923:                }
04924:
04925:                // set state attributes
04926:                state.setAttribute(FORM_ADDITIONAL, StringUtil
04927:                        .trimToZero(params.getString("additional")));
04928:
04929:                SiteInfo siteInfo = new SiteInfo();
04930:                if (state.getAttribute(STATE_SITE_INFO) != null) {
04931:                    siteInfo = (SiteInfo) state.getAttribute(STATE_SITE_INFO);
04932:                }
04933:                List providerCourseList = (List) state
04934:                        .getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN);
04935:                // store the manually requested sections in one site property
04936:                if ((providerCourseList == null || providerCourseList.size() == 0)
04937:                        && multiCourseInputs.size() > 0) {
04938:                    AcademicSession t = (AcademicSession) state
04939:                            .getAttribute(STATE_TERM_SELECTED);
04940:                    String courseId = sectionFieldManager.getSectionEid(t
04941:                            .getEid(), (List) multiCourseInputs.get(0));
04942:                    String title = "";
04943:                    try {
04944:                        // instead of making up a name, Josh & I decided to use the
04945:                        // section.eid instead
04946:                        title = courseId;
04947:                    } catch (Exception e) {
04948:                        // ignore
04949:                    }
04950:                    siteInfo.title = title;
04951:                }
04952:                state.setAttribute(STATE_SITE_INFO, siteInfo);
04953:
04954:            } // readCourseSectionInfo
04955:
04956:            /**
04957:             * set the site type for new site
04958:             * 
04959:             * @param type
04960:             *            The type String
04961:             */
04962:            private void setNewSiteType(SessionState state, String type) {
04963:                state.removeAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST);
04964:                state
04965:                        .removeAttribute(STATE_TOOL_REGISTRATION_OLD_SELECTED_LIST);
04966:                state
04967:                        .removeAttribute(STATE_TOOL_REGISTRATION_OLD_SELECTED_HOME);
04968:
04969:                // start out with fresh site information
04970:                SiteInfo siteInfo = new SiteInfo();
04971:                siteInfo.site_type = type;
04972:                siteInfo.published = true;
04973:                state.setAttribute(STATE_SITE_INFO, siteInfo);
04974:
04975:                // get registered tools list
04976:                Set categories = new HashSet();
04977:                categories.add(type);
04978:                Set toolRegistrations = ToolManager.findTools(categories, null);
04979:
04980:                List tools = new Vector();
04981:                SortedIterator i = new SortedIterator(toolRegistrations
04982:                        .iterator(), new ToolComparator());
04983:                for (; i.hasNext();) {
04984:                    // form a new Tool
04985:                    Tool tr = (Tool) i.next();
04986:                    MyTool newTool = new MyTool();
04987:                    newTool.title = tr.getTitle();
04988:                    newTool.id = tr.getId();
04989:                    newTool.description = tr.getDescription();
04990:
04991:                    tools.add(newTool);
04992:                }
04993:                state.setAttribute(STATE_TOOL_REGISTRATION_LIST, tools);
04994:
04995:                state.setAttribute(STATE_SITE_TYPE, type);
04996:            }
04997:
04998:            /**
04999:             * Set the field on which to sort the list of students
05000:             * 
05001:             */
05002:            public void doSort_roster(RunData data) {
05003:                SessionState state = ((JetspeedRunData) data)
05004:                        .getPortletSessionState(((JetspeedRunData) data)
05005:                                .getJs_peid());
05006:
05007:                // get the field on which to sort the student list
05008:                ParameterParser params = data.getParameters();
05009:                String criterion = params.getString("criterion");
05010:
05011:                // current sorting sequence
05012:                String asc = "";
05013:                if (!criterion.equals(state.getAttribute(SORTED_BY))) {
05014:                    state.setAttribute(SORTED_BY, criterion);
05015:                    asc = Boolean.TRUE.toString();
05016:                    state.setAttribute(SORTED_ASC, asc);
05017:                } else {
05018:                    // current sorting sequence
05019:                    asc = (String) state.getAttribute(SORTED_ASC);
05020:
05021:                    // toggle between the ascending and descending sequence
05022:                    if (asc.equals(Boolean.TRUE.toString())) {
05023:                        asc = Boolean.FALSE.toString();
05024:                    } else {
05025:                        asc = Boolean.TRUE.toString();
05026:                    }
05027:                    state.setAttribute(SORTED_ASC, asc);
05028:                }
05029:
05030:            } // doSort_roster
05031:
05032:            /**
05033:             * Set the field on which to sort the list of sites
05034:             * 
05035:             */
05036:            public void doSort_sites(RunData data) {
05037:                SessionState state = ((JetspeedRunData) data)
05038:                        .getPortletSessionState(((JetspeedRunData) data)
05039:                                .getJs_peid());
05040:
05041:                // call this method at the start of a sort for proper paging
05042:                resetPaging(state);
05043:
05044:                // get the field on which to sort the site list
05045:                ParameterParser params = data.getParameters();
05046:                String criterion = params.getString("criterion");
05047:
05048:                // current sorting sequence
05049:                String asc = "";
05050:                if (!criterion.equals(state.getAttribute(SORTED_BY))) {
05051:                    state.setAttribute(SORTED_BY, criterion);
05052:                    asc = Boolean.TRUE.toString();
05053:                    state.setAttribute(SORTED_ASC, asc);
05054:                } else {
05055:                    // current sorting sequence
05056:                    asc = (String) state.getAttribute(SORTED_ASC);
05057:
05058:                    // toggle between the ascending and descending sequence
05059:                    if (asc.equals(Boolean.TRUE.toString())) {
05060:                        asc = Boolean.FALSE.toString();
05061:                    } else {
05062:                        asc = Boolean.TRUE.toString();
05063:                    }
05064:                    state.setAttribute(SORTED_ASC, asc);
05065:                }
05066:
05067:                state.setAttribute(SORTED_BY, criterion);
05068:
05069:            } // doSort_sites
05070:
05071:            /**
05072:             * doContinue is called when "eventSubmit_doContinue" is in the request
05073:             * parameters
05074:             */
05075:            public void doContinue(RunData data) {
05076:                // Put current form data in state and continue to the next template,
05077:                // make any permanent changes
05078:                SessionState state = ((JetspeedRunData) data)
05079:                        .getPortletSessionState(((JetspeedRunData) data)
05080:                                .getJs_peid());
05081:                ParameterParser params = data.getParameters();
05082:                int index = Integer.valueOf(params.getString("template-index"))
05083:                        .intValue();
05084:
05085:                // Let actionForTemplate know to make any permanent changes before
05086:                // continuing to the next template
05087:                String direction = "continue";
05088:                String option = params.getString("option");
05089:
05090:                actionForTemplate(direction, index, params, state);
05091:                if (state.getAttribute(STATE_MESSAGE) == null) {
05092:                    if (index == 9) {
05093:                        // go to the send site publish email page if "publish" option is
05094:                        // chosen
05095:                        SiteInfo sInfo = (SiteInfo) state
05096:                                .getAttribute(STATE_SITE_INFO);
05097:                        if (sInfo.getPublished()) {
05098:                            state.setAttribute(STATE_TEMPLATE_INDEX, "16");
05099:                        } else {
05100:                            state.setAttribute(STATE_TEMPLATE_INDEX, "17");
05101:                        }
05102:                    } else if (index == 36 && ("add").equals(option)) {
05103:                        // this is the Add extra Roster(s) case after a site is created
05104:                        state.setAttribute(STATE_TEMPLATE_INDEX, "44");
05105:                    } else if (params.getString("continue") != null) {
05106:                        state.setAttribute(STATE_TEMPLATE_INDEX, params
05107:                                .getString("continue"));
05108:                    }
05109:                }
05110:            }// doContinue
05111:
05112:            /**
05113:             * handle with continue add new course site options
05114:             * 
05115:             */
05116:            public void doContinue_new_course(RunData data) {
05117:                String option = data.getParameters().getString("option");
05118:                if (option.equals("continue")) {
05119:                    doContinue(data);
05120:                } else if (option.equals("cancel")) {
05121:                    doCancel_create(data);
05122:                } else if (option.equals("back")) {
05123:                    doBack(data);
05124:                } else if (option.equals("cancel")) {
05125:                    doCancel_create(data);
05126:                }
05127:            } // doContinue_new_course
05128:
05129:            /**
05130:             * doBack is called when "eventSubmit_doBack" is in the request parameters
05131:             * Pass parameter to actionForTemplate to request action for backward
05132:             * direction
05133:             */
05134:            public void doBack(RunData data) {
05135:                // Put current form data in state and return to the previous template
05136:                SessionState state = ((JetspeedRunData) data)
05137:                        .getPortletSessionState(((JetspeedRunData) data)
05138:                                .getJs_peid());
05139:                ParameterParser params = data.getParameters();
05140:                int currentIndex = Integer.parseInt((String) state
05141:                        .getAttribute(STATE_TEMPLATE_INDEX));
05142:                state.setAttribute(STATE_TEMPLATE_INDEX, params
05143:                        .getString("back"));
05144:
05145:                // Let actionForTemplate know not to make any permanent changes before
05146:                // continuing to the next template
05147:                String direction = "back";
05148:                actionForTemplate(direction, currentIndex, params, state);
05149:
05150:            }// doBack
05151:
05152:            /**
05153:             * doFinish is called when a site has enough information to be saved as an
05154:             * unpublished site
05155:             */
05156:            public void doFinish(RunData data) {
05157:                SessionState state = ((JetspeedRunData) data)
05158:                        .getPortletSessionState(((JetspeedRunData) data)
05159:                                .getJs_peid());
05160:                ParameterParser params = data.getParameters();
05161:
05162:                if (state.getAttribute(STATE_MESSAGE) == null) {
05163:                    state.setAttribute(STATE_TEMPLATE_INDEX, params
05164:                            .getString("continue"));
05165:                    int index = Integer.valueOf(
05166:                            params.getString("template-index")).intValue();
05167:                    actionForTemplate("continue", index, params, state);
05168:
05169:                    addNewSite(params, state);
05170:
05171:                    addFeatures(state);
05172:
05173:                    Site site = getStateSite(state);
05174:
05175:                    // for course sites
05176:                    String siteType = (String) state
05177:                            .getAttribute(STATE_SITE_TYPE);
05178:                    if (siteType != null && siteType.equalsIgnoreCase("course")) {
05179:                        String siteId = site.getId();
05180:
05181:                        ResourcePropertiesEdit rp = site.getPropertiesEdit();
05182:
05183:                        AcademicSession term = null;
05184:                        if (state.getAttribute(STATE_TERM_SELECTED) != null) {
05185:                            term = (AcademicSession) state
05186:                                    .getAttribute(STATE_TERM_SELECTED);
05187:                            rp.addProperty(PROP_SITE_TERM, term.getTitle());
05188:                            rp.addProperty(PROP_SITE_TERM_EID, term.getEid());
05189:                        }
05190:
05191:                        List providerCourseList = (List) state
05192:                                .getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN);
05193:                        int manualAddNumber = 0;
05194:                        if (state.getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER) != null) {
05195:                            manualAddNumber = ((Integer) state
05196:                                    .getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER))
05197:                                    .intValue();
05198:                        }
05199:
05200:                        List<SectionObject> cmRequestedSections = (List<SectionObject>) state
05201:                                .getAttribute(STATE_CM_REQUESTED_SECTIONS);
05202:
05203:                        List<SectionObject> cmAuthorizerSections = (List<SectionObject>) state
05204:                                .getAttribute(STATE_CM_AUTHORIZER_SECTIONS);
05205:
05206:                        String realm = SiteService.siteReference(siteId);
05207:
05208:                        if ((providerCourseList != null)
05209:                                && (providerCourseList.size() != 0)) {
05210:                            String providerRealm = buildExternalRealm(siteId,
05211:                                    state, providerCourseList);
05212:
05213:                            try {
05214:                                AuthzGroup realmEdit = AuthzGroupService
05215:                                        .getAuthzGroup(realm);
05216:                                realmEdit.setProviderGroupId(providerRealm);
05217:                                AuthzGroupService.save(realmEdit);
05218:                            } catch (GroupNotDefinedException e) {
05219:                                M_log
05220:                                        .warn(this 
05221:                                                + " IdUnusedException, not found, or not an AuthzGroup object");
05222:                                addAlert(state, rb.getString("java.realm"));
05223:                                return;
05224:                            }
05225:                            // catch (AuthzPermissionException e)
05226:                            // {
05227:                            // M_log.warn(this + " PermissionException, user does not
05228:                            // have permission to edit AuthzGroup object.");
05229:                            // addAlert(state, rb.getString("java.notaccess"));
05230:                            // return;
05231:                            // }
05232:                            catch (Exception e) {
05233:                                addAlert(state, this 
05234:                                        + rb.getString("java.problem"));
05235:                                return;
05236:                            }
05237:
05238:                            // talk to Zhen, agreed to mve this call out of SiteAction
05239:                            // addSubjectAffliates(state, providerCourseList);
05240:
05241:                            sendSiteNotification(state, providerCourseList);
05242:                        }
05243:
05244:                        if (manualAddNumber != 0) {
05245:                            // set the manual sections to the site property
05246:                            String manualSections = "";
05247:
05248:                            // manualCourseInputs is a list of a list of SectionField
05249:                            List manualCourseInputs = (List) state
05250:                                    .getAttribute(STATE_MANUAL_ADD_COURSE_FIELDS);
05251:
05252:                            // but we want to feed a list of a list of String (input of
05253:                            // the required fields)
05254:                            for (int j = 0; j < manualAddNumber; j++) {
05255:                                manualSections = manualSections.concat(
05256:                                        sectionFieldManager.getSectionEid(term
05257:                                                .getEid(),
05258:                                                (List) manualCourseInputs
05259:                                                        .get(j))).concat("+");
05260:                            }
05261:
05262:                            // trim the trailing plus sign
05263:                            if (manualSections.endsWith("+")) {
05264:                                manualSections = manualSections.substring(0,
05265:                                        manualSections.lastIndexOf("+"));
05266:                            }
05267:                            rp.addProperty(PROP_SITE_REQUEST_COURSE,
05268:                                    manualSections);
05269:                            // send request
05270:                            sendSiteRequest(state, "new", manualAddNumber,
05271:                                    manualCourseInputs);
05272:                        }
05273:
05274:                        if (cmRequestedSections != null
05275:                                && cmRequestedSections.size() > 0) {
05276:                            sendSiteRequest(state, "new", cmRequestedSections);
05277:                        }
05278:
05279:                        if (cmAuthorizerSections != null
05280:                                && cmAuthorizerSections.size() > 0) {
05281:                            sendSiteRequest(state, "new", cmAuthorizerSections);
05282:                        }
05283:
05284:                    }
05285:
05286:                    // commit site
05287:                    commitSite(site);
05288:
05289:                    String siteId = (String) state
05290:                            .getAttribute(STATE_SITE_INSTANCE_ID);
05291:
05292:                    // now that the site exists, we can set the email alias when an
05293:                    // Email Archive tool has been selected
05294:                    String alias = StringUtil.trimToNull((String) state
05295:                            .getAttribute(STATE_TOOL_EMAIL_ADDRESS));
05296:                    if (alias != null) {
05297:                        String channelReference = mailArchiveChannelReference(siteId);
05298:                        try {
05299:                            AliasService.setAlias(alias, channelReference);
05300:                        } catch (IdUsedException ee) {
05301:                            addAlert(state, rb.getString("java.alias") + " "
05302:                                    + alias + " " + rb.getString("java.exists"));
05303:                        } catch (IdInvalidException ee) {
05304:                            addAlert(state, rb.getString("java.alias") + " "
05305:                                    + alias + " "
05306:                                    + rb.getString("java.isinval"));
05307:                        } catch (PermissionException ee) {
05308:                            addAlert(state, rb.getString("java.addalias") + " ");
05309:                        }
05310:                    }
05311:                    // TODO: hard coding this frame id is fragile, portal dependent, and
05312:                    // needs to be fixed -ggolden
05313:                    // schedulePeerFrameRefresh("sitenav");
05314:                    scheduleTopRefresh();
05315:
05316:                    resetPaging(state);
05317:
05318:                    // clean state variables
05319:                    cleanState(state);
05320:
05321:                    state.setAttribute(STATE_TEMPLATE_INDEX, "0");
05322:
05323:                }
05324:
05325:            }// doFinish
05326:
05327:            /*
05328:             * talked to Zhen and we agreed that this shoudl be moved out of SiteAction -
05329:             * daisyf, 03/12/07 private void addSubjectAffliates(SessionState state,
05330:             * List providerCourseList) { Vector subjAffiliates = new Vector(); Vector
05331:             * affiliates = new Vector(); String subject = ""; String affiliate = ""; //
05332:             * get all subject and campus pairs for this site for (ListIterator i =
05333:             * providerCourseList.listIterator(); i.hasNext();) { String courseId =
05334:             * (String) i.next();
05335:             * 
05336:             * try { Section c = cms.getSection(courseId); if (c != null) // comment
05337:             * this out so at least this method won't break //subject =
05338:             * CourseIdGenerator.getSubject(c.getEid()); subject = c.getEid();
05339:             * subjAffiliates.add(subject); } catch (Exception e) { // M_log.warn(this + "
05340:             * cannot find course " + courseId + ". "); } } // remove duplicates
05341:             * Collection noDups = new HashSet(subjAffiliates); // get affliates for
05342:             * subjects for (Iterator i = noDups.iterator(); i.hasNext();) { subject =
05343:             * (String) i.next();
05344:             * 
05345:             * Collection uniqnames = getSubjectAffiliates(state, subject);
05346:             * 
05347:             * try { affiliates.addAll(uniqnames); } catch (Exception ignore) { } } //
05348:             * remove duplicates Collection addAffiliates = new HashSet(affiliates); //
05349:             * try to add uniqnames with appropriate role for (Iterator i =
05350:             * addAffiliates.iterator(); i.hasNext();) { affiliate = (String) i.next();
05351:             * 
05352:             * try { User user = UserDirectoryService.getUserByEid(affiliate); String
05353:             * realmId = "/site/" + (String) state.getAttribute(STATE_SITE_INSTANCE_ID);
05354:             * if (AuthzGroupService.allowUpdate(realmId)) { try { AuthzGroup realmEdit =
05355:             * AuthzGroupService .getAuthzGroup(realmId); Role role =
05356:             * realmEdit.getRole("Affiliate"); realmEdit.addMember(user.getId(),
05357:             * role.getId(), true, false); AuthzGroupService.save(realmEdit); } catch
05358:             * (Exception ignore) { } } } catch (Exception ignore) { M_log.warn(this + "
05359:             * cannot find affiliate " + affiliate); } } } // addSubjectAffliates
05360:             */
05361:
05362:            /**
05363:             * @params - SessionState state
05364:             * @params - String subject is the University's Subject code
05365:             * @return - Collection of uniqnames of affiliates for this subject
05366:             */
05367:            private Collection getSubjectAffiliates(SessionState state,
05368:                    String subject) {
05369:                Collection rv = null;
05370:                List allAffiliates = (Vector) state
05371:                        .getAttribute(STATE_SUBJECT_AFFILIATES);
05372:
05373:                // iterate through the subjects looking for this subject
05374:                for (Iterator i = allAffiliates.iterator(); i.hasNext();) {
05375:                    SubjectAffiliates sa = (SubjectAffiliates) i.next();
05376:                    if (subject.equals(sa.getCampus() + "_" + sa.getSubject()))
05377:                        return sa.getUniqnames();
05378:                }
05379:                return rv;
05380:
05381:            } // getSubjectAffiliates
05382:
05383:            /**
05384:             * buildExternalRealm creates a site/realm id in one of three formats, for a
05385:             * single section, for multiple sections of the same course, or for a
05386:             * cross-listing having multiple courses
05387:             * 
05388:             * @param sectionList
05389:             *            is a Vector of CourseListItem
05390:             * @param id
05391:             *            The site id
05392:             */
05393:            private String buildExternalRealm(String id, SessionState state,
05394:                    List<String> providerIdList) {
05395:                String realm = SiteService.siteReference(id);
05396:                if (!AuthzGroupService.allowUpdate(realm)) {
05397:                    addAlert(state, rb.getString("java.rosters"));
05398:                    return null;
05399:                }
05400:                String[] providers = new String[providerIdList.size()];
05401:                providers = (String[]) providerIdList.toArray(providers);
05402:                String providerId = groupProvider.packId(providers);
05403:                return providerId;
05404:
05405:            } // buildExternalRealm
05406:
05407:            /**
05408:             * Notification sent when a course site needs to be set up by Support
05409:             * 
05410:             */
05411:            private void sendSiteRequest(SessionState state, String request,
05412:                    int requestListSize, List requestFields) {
05413:                User cUser = UserDirectoryService.getCurrentUser();
05414:                boolean sendEmailToRequestee = false;
05415:                StringBuffer buf = new StringBuffer();
05416:
05417:                // get the request email from configuration
05418:                String requestEmail = ServerConfigurationService.getString(
05419:                        "setup.request", null);
05420:                if (requestEmail == null) {
05421:                    M_log.warn(this  + " - no 'setup.request' in configuration");
05422:                } else {
05423:                    String noEmailInIdAccountName = ServerConfigurationService
05424:                            .getString("noEmailInIdAccountName", "");
05425:
05426:                    SiteInfo siteInfo = (SiteInfo) state
05427:                            .getAttribute(STATE_SITE_INFO);
05428:
05429:                    Site site = getStateSite(state);
05430:                    String id = site.getId();
05431:                    String title = site.getTitle();
05432:
05433:                    Time time = TimeService.newTime();
05434:                    String local_time = time.toStringLocalTime();
05435:                    String local_date = time.toStringLocalDate();
05436:
05437:                    AcademicSession term = null;
05438:                    boolean termExist = false;
05439:                    if (state.getAttribute(STATE_TERM_SELECTED) != null) {
05440:                        termExist = true;
05441:                        term = (AcademicSession) state
05442:                                .getAttribute(STATE_TERM_SELECTED);
05443:                    }
05444:                    String productionSiteName = ServerConfigurationService
05445:                            .getServerName();
05446:
05447:                    String from = NULL_STRING;
05448:                    String to = NULL_STRING;
05449:                    String headerTo = NULL_STRING;
05450:                    String replyTo = NULL_STRING;
05451:                    String message_subject = NULL_STRING;
05452:                    String content = NULL_STRING;
05453:
05454:                    String sessionUserName = cUser.getDisplayName();
05455:                    String additional = NULL_STRING;
05456:                    if (request.equals("new")) {
05457:                        additional = siteInfo.getAdditional();
05458:                    } else {
05459:                        additional = (String) state
05460:                                .getAttribute(FORM_ADDITIONAL);
05461:                    }
05462:
05463:                    boolean isFutureTerm = false;
05464:                    if (state.getAttribute(STATE_FUTURE_TERM_SELECTED) != null
05465:                            && ((Boolean) state
05466:                                    .getAttribute(STATE_FUTURE_TERM_SELECTED))
05467:                                    .booleanValue()) {
05468:                        isFutureTerm = true;
05469:                    }
05470:
05471:                    // message subject
05472:                    if (termExist) {
05473:                        message_subject = rb.getString("java.sitereqfrom")
05474:                                + " " + sessionUserName + " "
05475:                                + rb.getString("java.for") + " "
05476:                                + term.getEid();
05477:                    } else {
05478:                        message_subject = rb.getString("java.official") + " "
05479:                                + sessionUserName;
05480:                    }
05481:
05482:                    // there is no offical instructor for future term sites
05483:                    String requestId = (String) state
05484:                            .getAttribute(STATE_SITE_QUEST_UNIQNAME);
05485:                    if (!isFutureTerm) {
05486:                        // To site quest account - the instructor of record's
05487:                        if (requestId != null) {
05488:                            try {
05489:                                User instructor = UserDirectoryService
05490:                                        .getUser(requestId);
05491:                                from = requestEmail;
05492:                                to = instructor.getEmail();
05493:                                headerTo = instructor.getEmail();
05494:                                replyTo = requestEmail;
05495:                                buf
05496:                                        .append(rb.getString("java.hello")
05497:                                                + " \n\n");
05498:                                buf.append(rb.getString("java.receiv") + " "
05499:                                        + sessionUserName + ", ");
05500:                                buf.append(rb.getString("java.who") + "\n");
05501:                                if (termExist) {
05502:                                    String dateString = term.getStartDate()
05503:                                            .toString();
05504:                                    String year = dateString
05505:                                            .substring(dateString.length() - 4);
05506:                                    buf.append(term.getTitle() + " " + year
05507:                                            + "\n");
05508:
05509:                                }
05510:
05511:                                // what are the required fields shown in the UI
05512:                                List requiredFields = sectionFieldManager
05513:                                        .getRequiredFields();
05514:                                for (int i = 0; i < requestListSize; i++) {
05515:                                    List requiredFieldList = (List) requestFields
05516:                                            .get(i);
05517:                                    for (int j = 0; j < requiredFieldList
05518:                                            .size(); j++) {
05519:                                        String requiredField = (String) requiredFields
05520:                                                .get(j);
05521:
05522:                                        buf.append(requiredField + "\t"
05523:                                                + requiredFieldList.get(j)
05524:                                                + "\n");
05525:                                    }
05526:                                }
05527:                                buf.append("\n"
05528:                                        + rb.getString("java.sitetitle") + "\t"
05529:                                        + title + "\n");
05530:                                buf.append(rb.getString("java.siteid") + "\t"
05531:                                        + id);
05532:                                buf.append("\n\n"
05533:                                        + rb.getString("java.according") + " "
05534:                                        + sessionUserName + " "
05535:                                        + rb.getString("java.record"));
05536:                                buf.append(" " + rb.getString("java.canyou")
05537:                                        + " " + sessionUserName + " "
05538:                                        + rb.getString("java.assoc") + "\n\n");
05539:                                buf
05540:                                        .append(rb.getString("java.respond")
05541:                                                + " " + sessionUserName
05542:                                                + rb.getString("java.appoint")
05543:                                                + "\n\n");
05544:                                buf.append(rb.getString("java.thanks") + "\n");
05545:                                buf.append(productionSiteName + " "
05546:                                        + rb.getString("java.support"));
05547:                                content = buf.toString();
05548:
05549:                                // send the email
05550:                                EmailService.send(from, to, message_subject,
05551:                                        content, headerTo, replyTo, null);
05552:
05553:                                // email has been sent successfully
05554:                                sendEmailToRequestee = true;
05555:                            } catch (UserNotDefinedException ee) {
05556:                            } // try
05557:                        }
05558:                    }
05559:
05560:                    // To Support
05561:                    from = cUser.getEmail();
05562:                    to = requestEmail;
05563:                    headerTo = requestEmail;
05564:                    replyTo = cUser.getEmail();
05565:                    buf.setLength(0);
05566:                    buf.append(rb.getString("java.to") + "\t\t"
05567:                            + productionSiteName + " "
05568:                            + rb.getString("java.supp") + "\n");
05569:                    buf.append("\n" + rb.getString("java.from") + "\t"
05570:                            + sessionUserName + "\n");
05571:                    if (request.equals("new")) {
05572:                        buf.append(rb.getString("java.subj") + "\t"
05573:                                + rb.getString("java.sitereq") + "\n");
05574:                    } else {
05575:                        buf.append(rb.getString("java.subj") + "\t"
05576:                                + rb.getString("java.sitechreq") + "\n");
05577:                    }
05578:                    buf.append(rb.getString("java.date") + "\t" + local_date
05579:                            + " " + local_time + "\n\n");
05580:                    if (request.equals("new")) {
05581:                        buf.append(rb.getString("java.approval") + " "
05582:                                + productionSiteName + " "
05583:                                + rb.getString("java.coursesite") + " ");
05584:                    } else {
05585:                        buf.append(rb.getString("java.approval2") + " "
05586:                                + productionSiteName + " "
05587:                                + rb.getString("java.coursesite") + " ");
05588:                    }
05589:                    if (termExist) {
05590:                        String dateString = term.getStartDate().toString();
05591:                        String year = dateString
05592:                                .substring(dateString.length() - 4);
05593:                        buf.append(term.getTitle() + " " + year);
05594:                    }
05595:                    if (requestListSize > 1) {
05596:                        buf.append(" " + rb.getString("java.forthese") + " "
05597:                                + requestListSize + " "
05598:                                + rb.getString("java.sections") + "\n\n");
05599:                    } else {
05600:                        buf.append(" " + rb.getString("java.forthis") + "\n\n");
05601:                    }
05602:
05603:                    // what are the required fields shown in the UI
05604:                    List requiredFields = sectionFieldManager
05605:                            .getRequiredFields();
05606:                    for (int i = 0; i < requestListSize; i++) {
05607:                        List requiredFieldList = (List) requestFields.get(i);
05608:                        for (int j = 0; j < requiredFieldList.size(); j++) {
05609:                            String requiredField = (String) requiredFields
05610:                                    .get(j);
05611:
05612:                            buf.append(requiredField + "\t"
05613:                                    + requiredFieldList.get(j) + "\n");
05614:                        }
05615:                    }
05616:                    buf.append(rb.getString("java.name") + "\t"
05617:                            + sessionUserName + " (" + noEmailInIdAccountName
05618:                            + " " + cUser.getEid() + ")\n");
05619:                    buf.append(rb.getString("java.email") + "\t" + replyTo
05620:                            + "\n\n");
05621:                    buf.append(rb.getString("java.sitetitle") + "\t" + title
05622:                            + "\n");
05623:                    buf.append(rb.getString("java.siteid") + "\t" + id + "\n");
05624:                    buf.append(rb.getString("java.siteinstr") + "\n"
05625:                            + additional + "\n\n");
05626:
05627:                    if (!isFutureTerm) {
05628:                        if (sendEmailToRequestee) {
05629:                            buf.append(rb.getString("java.authoriz") + " "
05630:                                    + requestId + " "
05631:                                    + rb.getString("java.asreq"));
05632:                        } else {
05633:                            buf.append(rb.getString("java.thesiteemail") + " "
05634:                                    + requestId + " "
05635:                                    + rb.getString("java.asreq"));
05636:                        }
05637:                    }
05638:                    content = buf.toString();
05639:                    EmailService.send(from, to, message_subject, content,
05640:                            headerTo, replyTo, null);
05641:
05642:                    // To the Instructor
05643:                    from = requestEmail;
05644:                    to = cUser.getEmail();
05645:                    headerTo = to;
05646:                    replyTo = to;
05647:                    buf.setLength(0);
05648:                    buf.append(rb.getString("java.isbeing") + " ");
05649:                    buf.append(rb.getString("java.meantime") + "\n\n");
05650:                    buf.append(rb.getString("java.copy") + "\n\n");
05651:                    buf.append(content);
05652:                    buf.append("\n" + rb.getString("java.wish") + " "
05653:                            + requestEmail);
05654:                    content = buf.toString();
05655:                    EmailService.send(from, to, message_subject, content,
05656:                            headerTo, replyTo, null);
05657:                    state.setAttribute(REQUEST_SENT, new Boolean(true));
05658:
05659:                } // if
05660:
05661:            } // sendSiteRequest
05662:
05663:            private void sendSiteRequest(SessionState state, String request,
05664:                    List<SectionObject> cmRequestedSections) {
05665:                User cUser = UserDirectoryService.getCurrentUser();
05666:                boolean sendEmailToRequestee = false;
05667:                StringBuffer buf = new StringBuffer();
05668:
05669:                // get the request email from configuration
05670:                String requestEmail = ServerConfigurationService.getString(
05671:                        "setup.request", null);
05672:                if (requestEmail == null) {
05673:                    M_log.warn(this  + " - no 'setup.request' in configuration");
05674:                } else {
05675:                    String noEmailInIdAccountName = ServerConfigurationService
05676:                            .getString("noEmailInIdAccountName", "");
05677:
05678:                    SiteInfo siteInfo = (SiteInfo) state
05679:                            .getAttribute(STATE_SITE_INFO);
05680:
05681:                    Site site = getStateSite(state);
05682:                    String id = site.getId();
05683:                    String title = site.getTitle();
05684:
05685:                    Time time = TimeService.newTime();
05686:                    String local_time = time.toStringLocalTime();
05687:                    String local_date = time.toStringLocalDate();
05688:
05689:                    AcademicSession term = null;
05690:                    boolean termExist = false;
05691:                    if (state.getAttribute(STATE_TERM_SELECTED) != null) {
05692:                        termExist = true;
05693:                        term = (AcademicSession) state
05694:                                .getAttribute(STATE_TERM_SELECTED);
05695:                    }
05696:                    String productionSiteName = ServerConfigurationService
05697:                            .getServerName();
05698:
05699:                    String from = NULL_STRING;
05700:                    String to = NULL_STRING;
05701:                    String headerTo = NULL_STRING;
05702:                    String replyTo = NULL_STRING;
05703:                    String message_subject = NULL_STRING;
05704:                    String content = NULL_STRING;
05705:
05706:                    String sessionUserName = cUser.getDisplayName();
05707:                    String additional = NULL_STRING;
05708:
05709:                    /*
05710:                     * I don't understand the following logic, why isn't aditional info
05711:                     * be included when it is a new request? -daisyf
05712:                     */
05713:                    /*
05714:                     * So I am commented this out if (request.equals("new")) {
05715:                     * additional = siteInfo.getAdditional(); } else { additional =
05716:                     * (String) state.getAttribute(FORM_ADDITIONAL); }
05717:                     */
05718:                    additional = (String) state.getAttribute(FORM_ADDITIONAL);
05719:
05720:                    boolean isFutureTerm = false;
05721:                    if (state.getAttribute(STATE_FUTURE_TERM_SELECTED) != null
05722:                            && ((Boolean) state
05723:                                    .getAttribute(STATE_FUTURE_TERM_SELECTED))
05724:                                    .booleanValue()) {
05725:                        isFutureTerm = true;
05726:                    }
05727:
05728:                    // message subject
05729:                    if (termExist) {
05730:                        message_subject = rb.getString("java.sitereqfrom")
05731:                                + " " + sessionUserName + " "
05732:                                + rb.getString("java.for") + " "
05733:                                + term.getEid();
05734:                    } else {
05735:                        message_subject = rb.getString("java.official") + " "
05736:                                + sessionUserName;
05737:                    }
05738:
05739:                    // there is no offical instructor for future term sites
05740:                    String requestUserId = (String) state
05741:                            .getAttribute(STATE_SITE_QUEST_UNIQNAME);
05742:                    // authorizerList is added by daisyf for v2.4
05743:                    List<String> authorizerList = (List) state
05744:                            .getAttribute(STATE_CM_AUTHORIZER_LIST);
05745:                    if (authorizerList == null) {
05746:                        authorizerList = new ArrayList();
05747:                    }
05748:                    if (requestUserId != null) {
05749:                        authorizerList.add(requestUserId);
05750:                    }
05751:                    for (int j = 0; j < authorizerList.size(); j++) {
05752:                        String requestId = (String) authorizerList.get(j);
05753:                        if (!isFutureTerm) {
05754:                            // To site quest account - the instructor of record's
05755:                            if (requestId != null) {
05756:                                try {
05757:                                    User instructor = UserDirectoryService
05758:                                            .getUserByEid(requestId); // v2.4 -daisyf
05759:                                    from = requestEmail;
05760:                                    to = instructor.getEmail();
05761:                                    headerTo = instructor.getEmail();
05762:                                    replyTo = requestEmail;
05763:                                    buf.append(rb.getString("java.hello")
05764:                                            + " \n\n");
05765:                                    buf.append(rb.getString("java.receiv")
05766:                                            + " " + sessionUserName + ", ");
05767:                                    buf.append(rb.getString("java.who") + "\n");
05768:                                    if (termExist) {
05769:                                        String dateString = term.getStartDate()
05770:                                                .toString();
05771:                                        String year = dateString
05772:                                                .substring(dateString.length() - 4);
05773:                                        buf.append(term.getTitle() + " " + year
05774:                                                + "\n");
05775:
05776:                                    }
05777:
05778:                                    for (int i = 0; i < cmRequestedSections
05779:                                            .size(); i++) {
05780:                                        SectionObject so = (SectionObject) cmRequestedSections
05781:                                                .get(i);
05782:
05783:                                        buf.append(so.getTitle() + "("
05784:                                                + so.getEid() + ")"
05785:                                                + so.getCategory() + "\n");
05786:                                    }
05787:
05788:                                    buf.append("\n"
05789:                                            + rb.getString("java.sitetitle")
05790:                                            + "\t" + title + "\n");
05791:                                    buf.append(rb.getString("java.siteid")
05792:                                            + "\t" + id);
05793:                                    buf.append("\n\n"
05794:                                            + rb.getString("java.according")
05795:                                            + " " + sessionUserName + " "
05796:                                            + rb.getString("java.record"));
05797:                                    buf.append(" "
05798:                                            + rb.getString("java.canyou") + " "
05799:                                            + sessionUserName + " "
05800:                                            + rb.getString("java.assoc")
05801:                                            + "\n\n");
05802:                                    buf.append(rb.getString("java.respond")
05803:                                            + " " + sessionUserName
05804:                                            + rb.getString("java.appoint")
05805:                                            + "\n\n");
05806:                                    buf.append(rb.getString("java.thanks")
05807:                                            + "\n");
05808:                                    buf.append(productionSiteName + " "
05809:                                            + rb.getString("java.support"));
05810:                                    content = buf.toString();
05811:
05812:                                    // send the email
05813:                                    EmailService.send(from, to,
05814:                                            message_subject, content, headerTo,
05815:                                            replyTo, null);
05816:
05817:                                    // email has been sent successfully
05818:                                    sendEmailToRequestee = true;
05819:                                } catch (UserNotDefinedException ee) {
05820:                                    M_log.warn(ee.getMessage());
05821:                                } // try
05822:                            }
05823:                        }
05824:                    }
05825:
05826:                    // To Support
05827:                    from = cUser.getEmail();
05828:                    to = requestEmail;
05829:                    headerTo = requestEmail;
05830:                    replyTo = cUser.getEmail();
05831:                    buf.setLength(0);
05832:                    buf.append(rb.getString("java.to") + "\t\t"
05833:                            + productionSiteName + " "
05834:                            + rb.getString("java.supp") + "\n");
05835:                    buf.append("\n" + rb.getString("java.from") + "\t"
05836:                            + sessionUserName + "\n");
05837:                    if (request.equals("new")) {
05838:                        buf.append(rb.getString("java.subj") + "\t"
05839:                                + rb.getString("java.sitereq") + "\n");
05840:                    } else {
05841:                        buf.append(rb.getString("java.subj") + "\t"
05842:                                + rb.getString("java.sitechreq") + "\n");
05843:                    }
05844:                    buf.append(rb.getString("java.date") + "\t" + local_date
05845:                            + " " + local_time + "\n\n");
05846:                    if (request.equals("new")) {
05847:                        buf.append(rb.getString("java.approval") + " "
05848:                                + productionSiteName + " "
05849:                                + rb.getString("java.coursesite") + " ");
05850:                    } else {
05851:                        buf.append(rb.getString("java.approval2") + " "
05852:                                + productionSiteName + " "
05853:                                + rb.getString("java.coursesite") + " ");
05854:                    }
05855:                    if (termExist) {
05856:                        String dateString = term.getStartDate().toString();
05857:                        String year = dateString
05858:                                .substring(dateString.length() - 4);
05859:                        buf.append(term.getTitle() + " " + year);
05860:                    }
05861:                    if (cmRequestedSections != null
05862:                            && cmRequestedSections.size() > 1) {
05863:                        buf.append(" " + rb.getString("java.forthese") + " "
05864:                                + cmRequestedSections.size() + " "
05865:                                + rb.getString("java.sections") + "\n\n");
05866:                    } else {
05867:                        buf.append(" " + rb.getString("java.forthis") + "\n\n");
05868:                    }
05869:
05870:                    for (int i = 0; i < cmRequestedSections.size(); i++) {
05871:                        SectionObject so = (SectionObject) cmRequestedSections
05872:                                .get(i);
05873:
05874:                        buf.append(so.getTitle() + "(" + so.getEid() + ")"
05875:                                + so.getCategory() + "\n");
05876:                    }
05877:
05878:                    buf.append(rb.getString("java.name") + "\t"
05879:                            + sessionUserName + " (" + noEmailInIdAccountName
05880:                            + " " + cUser.getEid() + ")\n");
05881:                    buf.append(rb.getString("java.email") + "\t" + replyTo
05882:                            + "\n\n");
05883:                    buf.append(rb.getString("java.sitetitle") + "\t" + title
05884:                            + "\n");
05885:                    buf.append(rb.getString("java.siteid") + "\t" + id + "\n");
05886:                    buf.append(rb.getString("java.siteinstr") + "\n"
05887:                            + additional + "\n\n");
05888:
05889:                    if (!isFutureTerm) {
05890:                        if (sendEmailToRequestee) {
05891:                            buf.append(rb.getString("java.authoriz") + " "
05892:                                    + requestUserId + " "
05893:                                    + rb.getString("java.asreq"));
05894:                        } else {
05895:                            buf.append(rb.getString("java.thesiteemail") + " "
05896:                                    + requestUserId + " "
05897:                                    + rb.getString("java.asreq"));
05898:                        }
05899:                    }
05900:                    content = buf.toString();
05901:                    EmailService.send(from, to, message_subject, content,
05902:                            headerTo, replyTo, null);
05903:
05904:                    // To the Instructor
05905:                    from = requestEmail;
05906:                    to = cUser.getEmail();
05907:                    headerTo = to;
05908:                    replyTo = to;
05909:                    buf.setLength(0);
05910:                    buf.append(rb.getString("java.isbeing") + " ");
05911:                    buf.append(rb.getString("java.meantime") + "\n\n");
05912:                    buf.append(rb.getString("java.copy") + "\n\n");
05913:                    buf.append(content);
05914:                    buf.append("\n" + rb.getString("java.wish") + " "
05915:                            + requestEmail);
05916:                    content = buf.toString();
05917:                    EmailService.send(from, to, message_subject, content,
05918:                            headerTo, replyTo, null);
05919:                    state.setAttribute(REQUEST_SENT, new Boolean(true));
05920:                } // if
05921:
05922:            } // sendSiteRequest
05923:
05924:            /**
05925:             * Notification sent when a course site is set up automatcally
05926:             * 
05927:             */
05928:            private void sendSiteNotification(SessionState state,
05929:                    List notifySites) {
05930:                // get the request email from configuration
05931:                String requestEmail = ServerConfigurationService.getString(
05932:                        "setup.request", null);
05933:                if (requestEmail == null) {
05934:                    M_log.warn(this  + " - no 'setup.request' in configuration");
05935:                } else {
05936:                    // send emails
05937:                    Site site = getStateSite(state);
05938:                    String id = site.getId();
05939:                    String title = site.getTitle();
05940:                    Time time = TimeService.newTime();
05941:                    String local_time = time.toStringLocalTime();
05942:                    String local_date = time.toStringLocalDate();
05943:                    String term_name = "";
05944:                    if (state.getAttribute(STATE_TERM_SELECTED) != null) {
05945:                        term_name = ((AcademicSession) state
05946:                                .getAttribute(STATE_TERM_SELECTED)).getEid();
05947:                    }
05948:                    String message_subject = rb.getString("java.official")
05949:                            + " "
05950:                            + UserDirectoryService.getCurrentUser()
05951:                                    .getDisplayName() + " "
05952:                            + rb.getString("java.for") + " " + term_name;
05953:
05954:                    String from = NULL_STRING;
05955:                    String to = NULL_STRING;
05956:                    String headerTo = NULL_STRING;
05957:                    String replyTo = NULL_STRING;
05958:                    String sender = UserDirectoryService.getCurrentUser()
05959:                            .getDisplayName();
05960:                    String userId = StringUtil.trimToZero(SessionManager
05961:                            .getCurrentSessionUserId());
05962:                    try {
05963:                        userId = UserDirectoryService.getUserEid(userId);
05964:                    } catch (UserNotDefinedException e) {
05965:                        M_log.warn(this  + rb.getString("user.notdefined") + " "
05966:                                + userId);
05967:                    }
05968:
05969:                    // To Support
05970:                    from = UserDirectoryService.getCurrentUser().getEmail();
05971:                    to = requestEmail;
05972:                    headerTo = requestEmail;
05973:                    replyTo = UserDirectoryService.getCurrentUser().getEmail();
05974:                    StringBuffer buf = new StringBuffer();
05975:                    buf.append("\n" + rb.getString("java.fromwork") + " "
05976:                            + ServerConfigurationService.getServerName() + " "
05977:                            + rb.getString("java.supp") + ":\n\n");
05978:                    buf.append(rb.getString("java.off") + " '" + title
05979:                            + "' (id " + id + "), "
05980:                            + rb.getString("java.wasset") + " ");
05981:                    buf.append(sender + " (" + userId + ", "
05982:                            + rb.getString("java.email2") + " " + replyTo
05983:                            + ") ");
05984:                    buf.append(rb.getString("java.on") + " " + local_date + " "
05985:                            + rb.getString("java.at") + " " + local_time + " ");
05986:                    buf.append(rb.getString("java.for") + " " + term_name
05987:                            + ", ");
05988:                    int nbr_sections = notifySites.size();
05989:                    if (nbr_sections > 1) {
05990:                        buf.append(rb.getString("java.withrost") + " "
05991:                                + Integer.toString(nbr_sections) + " "
05992:                                + rb.getString("java.sections") + "\n\n");
05993:                    } else {
05994:                        buf.append(" " + rb.getString("java.withrost2")
05995:                                + "\n\n");
05996:                    }
05997:
05998:                    for (int i = 0; i < nbr_sections; i++) {
05999:                        String course = (String) notifySites.get(i);
06000:                        buf.append(rb.getString("java.course2") + " " + course
06001:                                + "\n");
06002:                    }
06003:                    String content = buf.toString();
06004:                    EmailService.send(from, to, message_subject, content,
06005:                            headerTo, replyTo, null);
06006:                } // if
06007:
06008:            } // sendSiteNotification
06009:
06010:            /**
06011:             * doCancel called when "eventSubmit_doCancel_create" is in the request
06012:             * parameters to c
06013:             */
06014:            public void doCancel_create(RunData data) {
06015:                // Don't put current form data in state, just return to the previous
06016:                // template
06017:                SessionState state = ((JetspeedRunData) data)
06018:                        .getPortletSessionState(((JetspeedRunData) data)
06019:                                .getJs_peid());
06020:                removeAddClassContext(state);
06021:                state.setAttribute(STATE_TEMPLATE_INDEX, "0");
06022:
06023:            } // doCancel_create
06024:
06025:            /**
06026:             * doCancel called when "eventSubmit_doCancel" is in the request parameters
06027:             * to c int index = Integer.valueOf(params.getString
06028:             * ("template-index")).intValue();
06029:             */
06030:            public void doCancel(RunData data) {
06031:                // Don't put current form data in state, just return to the previous
06032:                // template
06033:                SessionState state = ((JetspeedRunData) data)
06034:                        .getPortletSessionState(((JetspeedRunData) data)
06035:                                .getJs_peid());
06036:
06037:                ParameterParser params = data.getParameters();
06038:
06039:                state.removeAttribute(STATE_MESSAGE);
06040:
06041:                String currentIndex = (String) state
06042:                        .getAttribute(STATE_TEMPLATE_INDEX);
06043:
06044:                String backIndex = params.getString("back");
06045:                state.setAttribute(STATE_TEMPLATE_INDEX, backIndex);
06046:
06047:                if (currentIndex.equals("4")) {
06048:                    state.removeAttribute(STATE_TOOL_EMAIL_ADDRESS);
06049:                    state.removeAttribute(STATE_MESSAGE);
06050:                    removeEditToolState(state);
06051:                } else if (currentIndex.equals("5")) {
06052:                    // remove related state variables
06053:                    removeAddParticipantContext(state);
06054:
06055:                    params = data.getParameters();
06056:                    state.setAttribute(STATE_TEMPLATE_INDEX, params
06057:                            .getString("back"));
06058:                } else if (currentIndex.equals("6")) {
06059:                    state.removeAttribute(STATE_REMOVEABLE_USER_LIST);
06060:                } else if (currentIndex.equals("9")) {
06061:                    state.removeAttribute(FORM_WILL_NOTIFY);
06062:                } else if (currentIndex.equals("17")
06063:                        || currentIndex.equals("16")) {
06064:                    state.removeAttribute(FORM_WILL_NOTIFY);
06065:                    state.setAttribute(STATE_TEMPLATE_INDEX, "12");
06066:                } else if (currentIndex.equals("13")
06067:                        || currentIndex.equals("14")) {
06068:                    // clean state attributes
06069:                    state.removeAttribute(FORM_SITEINFO_TITLE);
06070:                    state.removeAttribute(FORM_SITEINFO_DESCRIPTION);
06071:                    state.removeAttribute(FORM_SITEINFO_SHORT_DESCRIPTION);
06072:                    state.removeAttribute(FORM_SITEINFO_SKIN);
06073:                    state.removeAttribute(FORM_SITEINFO_INCLUDE);
06074:                    state.setAttribute(STATE_TEMPLATE_INDEX, "12");
06075:                } else if (currentIndex.equals("15")) {
06076:                    params = data.getParameters();
06077:                    state.setAttribute(STATE_TEMPLATE_INDEX, params
06078:                            .getString("cancelIndex"));
06079:                    removeEditToolState(state);
06080:                }
06081:                // htripath: added 'currentIndex.equals("45")' for import from file
06082:                // cancel
06083:                else if (currentIndex.equals("19") || currentIndex.equals("20")
06084:                        || currentIndex.equals("21")
06085:                        || currentIndex.equals("22")
06086:                        || currentIndex.equals("45")) {
06087:                    // from adding participant pages
06088:                    // remove related state variables
06089:                    removeAddParticipantContext(state);
06090:
06091:                    state.setAttribute(STATE_TEMPLATE_INDEX, "12");
06092:                } else if (currentIndex.equals("23")
06093:                        || currentIndex.equals("24")) {
06094:                    // from change global access
06095:                    state.removeAttribute("form_joinable");
06096:                    state.removeAttribute("form_joinerRole");
06097:
06098:                    state.setAttribute(STATE_TEMPLATE_INDEX, "18");
06099:                } else if (currentIndex.equals("7")
06100:                        || currentIndex.equals("25")) {
06101:                    // from change role
06102:                    removeChangeRoleContext(state);
06103:                    state.setAttribute(STATE_TEMPLATE_INDEX, "18");
06104:                } else if (currentIndex.equals("3")) {
06105:                    // from adding class
06106:                    if (((String) state.getAttribute(STATE_SITE_MODE))
06107:                            .equalsIgnoreCase(SITE_MODE_SITESETUP)) {
06108:                        state.setAttribute(STATE_TEMPLATE_INDEX, "0");
06109:                    } else if (((String) state.getAttribute(STATE_SITE_MODE))
06110:                            .equalsIgnoreCase(SITE_MODE_SITEINFO)) {
06111:                        state.setAttribute(STATE_TEMPLATE_INDEX, "18");
06112:                    }
06113:                } else if (currentIndex.equals("27")
06114:                        || currentIndex.equals("28")) {
06115:                    // from import
06116:                    if (((String) state.getAttribute(STATE_SITE_MODE))
06117:                            .equalsIgnoreCase(SITE_MODE_SITESETUP)) {
06118:                        // worksite setup
06119:                        if (getStateSite(state) == null) {
06120:                            // in creating new site process
06121:                            state.setAttribute(STATE_TEMPLATE_INDEX, "0");
06122:                        } else {
06123:                            // in editing site process
06124:                            state.setAttribute(STATE_TEMPLATE_INDEX, "12");
06125:                        }
06126:                    } else if (((String) state.getAttribute(STATE_SITE_MODE))
06127:                            .equalsIgnoreCase(SITE_MODE_SITEINFO)) {
06128:                        // site info
06129:                        state.setAttribute(STATE_TEMPLATE_INDEX, "12");
06130:                    }
06131:                    state.removeAttribute(STATE_IMPORT_SITE_TOOL);
06132:                    state.removeAttribute(STATE_IMPORT_SITES);
06133:                } else if (currentIndex.equals("26")) {
06134:                    if (((String) state.getAttribute(STATE_SITE_MODE))
06135:                            .equalsIgnoreCase(SITE_MODE_SITESETUP)
06136:                            && getStateSite(state) == null) {
06137:                        // from creating site
06138:                        state.setAttribute(STATE_TEMPLATE_INDEX, "0");
06139:                    } else {
06140:                        // from revising site
06141:                        state.setAttribute(STATE_TEMPLATE_INDEX, "12");
06142:                    }
06143:                    removeEditToolState(state);
06144:                } else if (currentIndex.equals("37")
06145:                        || currentIndex.equals("44")) {
06146:                    // cancel back to edit class view
06147:                    state.setAttribute(STATE_TEMPLATE_INDEX, "43");
06148:                    removeAddClassContext(state);
06149:                }
06150:
06151:            } // doCancel
06152:
06153:            /**
06154:             * doMenu_customize is called when "eventSubmit_doBack" is in the request
06155:             * parameters Pass parameter to actionForTemplate to request action for
06156:             * backward direction
06157:             */
06158:            public void doMenu_customize(RunData data) {
06159:                SessionState state = ((JetspeedRunData) data)
06160:                        .getPortletSessionState(((JetspeedRunData) data)
06161:                                .getJs_peid());
06162:                state.setAttribute(STATE_TEMPLATE_INDEX, "15");
06163:
06164:            }// doMenu_customize
06165:
06166:            /**
06167:             * doBack_to_list cancels an outstanding site edit, cleans state and returns
06168:             * to the site list
06169:             * 
06170:             */
06171:            public void doBack_to_list(RunData data) {
06172:                SessionState state = ((JetspeedRunData) data)
06173:                        .getPortletSessionState(((JetspeedRunData) data)
06174:                                .getJs_peid());
06175:                Site site = getStateSite(state);
06176:                if (site != null) {
06177:                    Hashtable h = (Hashtable) state
06178:                            .getAttribute(STATE_PAGESIZE_SITEINFO);
06179:                    h.put(site.getId(), state.getAttribute(STATE_PAGESIZE));
06180:                    state.setAttribute(STATE_PAGESIZE_SITEINFO, h);
06181:                }
06182:
06183:                // restore the page size for Worksite setup tool
06184:                if (state.getAttribute(STATE_PAGESIZE_SITESETUP) != null) {
06185:                    state.setAttribute(STATE_PAGESIZE, state
06186:                            .getAttribute(STATE_PAGESIZE_SITESETUP));
06187:                    state.removeAttribute(STATE_PAGESIZE_SITESETUP);
06188:                }
06189:
06190:                cleanState(state);
06191:                setupFormNamesAndConstants(state);
06192:
06193:                state.setAttribute(STATE_TEMPLATE_INDEX, "0");
06194:
06195:            } // doBack_to_list
06196:
06197:            /**
06198:             * do called when "eventSubmit_do" is in the request parameters to c
06199:             */
06200:            public void doAdd_custom_link(RunData data) {
06201:                SessionState state = ((JetspeedRunData) data)
06202:                        .getPortletSessionState(((JetspeedRunData) data)
06203:                                .getJs_peid());
06204:                ParameterParser params = data.getParameters();
06205:                if ((params.getString("name")) == null
06206:                        || (params.getString("url") == null)) {
06207:                    Tool tr = ToolManager.getTool("sakai.iframe");
06208:                    Site site = getStateSite(state);
06209:                    SitePage page = site.addPage();
06210:                    page.setTitle(params.getString("name")); // the visible label on
06211:                    // the tool menu
06212:                    ToolConfiguration tool = page.addTool();
06213:                    tool.setTool("sakai.iframe", tr);
06214:                    tool.setTitle(params.getString("name"));
06215:                    commitSite(site);
06216:                } else {
06217:                    addAlert(state, rb.getString("java.reqmiss"));
06218:                    state.setAttribute(STATE_TEMPLATE_INDEX, params
06219:                            .getString("template-index"));
06220:                }
06221:
06222:            } // doAdd_custom_link
06223:
06224:            /**
06225:             * doAdd_remove_features is called when Make These Changes is clicked in
06226:             * chef_site-addRemoveFeatures
06227:             */
06228:            public void doAdd_remove_features(RunData data) {
06229:                SessionState state = ((JetspeedRunData) data)
06230:                        .getPortletSessionState(((JetspeedRunData) data)
06231:                                .getJs_peid());
06232:                List existTools = (List) state
06233:                        .getAttribute(STATE_TOOL_REGISTRATION_OLD_SELECTED_LIST);
06234:
06235:                ParameterParser params = data.getParameters();
06236:                String option = params.getString("option");
06237:
06238:                // dispatch
06239:                if (option.equalsIgnoreCase("addNews")) {
06240:                    updateSelectedToolList(state, params, false);
06241:                    insertTool(state, "sakai.news", STATE_NEWS_TITLES,
06242:                            NEWS_DEFAULT_TITLE, STATE_NEWS_URLS,
06243:                            NEWS_DEFAULT_URL, Integer.parseInt(params
06244:                                    .getString("newsNum")));
06245:                    state.setAttribute(STATE_TEMPLATE_INDEX, "26");
06246:                } else if (option.equalsIgnoreCase("addWC")) {
06247:                    updateSelectedToolList(state, params, false);
06248:                    insertTool(state, "sakai.iframe", STATE_WEB_CONTENT_TITLES,
06249:                            WEB_CONTENT_DEFAULT_TITLE, STATE_WEB_CONTENT_URLS,
06250:                            WEB_CONTENT_DEFAULT_URL, Integer.parseInt(params
06251:                                    .getString("wcNum")));
06252:                    state.setAttribute(STATE_TEMPLATE_INDEX, "26");
06253:                } else if (option.equalsIgnoreCase("save")) {
06254:                    List idsSelected = new Vector();
06255:
06256:                    boolean goToENWPage = false;
06257:                    boolean homeSelected = false;
06258:
06259:                    // Add new pages and tools, if any
06260:                    if (params.getStrings("selectedTools") == null) {
06261:                        addAlert(state, rb.getString("atleastonetool"));
06262:                    } else {
06263:                        List l = new ArrayList(Arrays.asList(params
06264:                                .getStrings("selectedTools"))); // toolId's & titles of
06265:                        // chosen tools
06266:
06267:                        for (int i = 0; i < l.size(); i++) {
06268:                            String toolId = (String) l.get(i);
06269:
06270:                            if (toolId.equals(HOME_TOOL_ID)) {
06271:                                homeSelected = true;
06272:                            } else if (toolId.equals("sakai.mailbox")
06273:                                    || toolId.indexOf("sakai.news") != -1
06274:                                    || toolId.indexOf("sakai.iframe") != -1) {
06275:                                // if user is adding either EmailArchive tool, News tool
06276:                                // or Web Content tool, go to the Customize page for the
06277:                                // tool
06278:                                if (!existTools.contains(toolId)) {
06279:                                    goToENWPage = true;
06280:                                }
06281:
06282:                                if (toolId.equals("sakai.mailbox")) {
06283:                                    // get the email alias when an Email Archive tool
06284:                                    // has been selected
06285:                                    String channelReference = mailArchiveChannelReference((String) state
06286:                                            .getAttribute(STATE_SITE_INSTANCE_ID));
06287:                                    List aliases = AliasService.getAliases(
06288:                                            channelReference, 1, 1);
06289:                                    if (aliases.size() > 0) {
06290:                                        state.setAttribute(
06291:                                                STATE_TOOL_EMAIL_ADDRESS,
06292:                                                ((Alias) aliases.get(0))
06293:                                                        .getId());
06294:                                    }
06295:                                }
06296:                            }
06297:                            idsSelected.add(toolId);
06298:
06299:                        }
06300:
06301:                        state.setAttribute(STATE_TOOL_HOME_SELECTED,
06302:                                new Boolean(homeSelected));
06303:                    }
06304:
06305:                    state.setAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST,
06306:                            idsSelected); // List of ToolRegistration toolId's
06307:
06308:                    if (state.getAttribute(STATE_MESSAGE) == null) {
06309:                        if (goToENWPage) {
06310:                            // go to the configuration page for Email Archive, News and
06311:                            // Web Content tools
06312:                            state.setAttribute(STATE_TEMPLATE_INDEX, "26");
06313:                        } else {
06314:                            // go to confirmation page
06315:                            state.setAttribute(STATE_TEMPLATE_INDEX, "15");
06316:                        }
06317:                    }
06318:                } else if (option.equalsIgnoreCase("continue")) {
06319:                    // continue
06320:                    doContinue(data);
06321:                } else if (option.equalsIgnoreCase("Back")) {
06322:                    // back
06323:                    doBack(data);
06324:                } else if (option.equalsIgnoreCase("Cancel")) {
06325:                    // cancel
06326:                    doCancel(data);
06327:                }
06328:            } // doAdd_remove_features
06329:
06330:            /**
06331:             * doSave_revised_features
06332:             */
06333:            public void doSave_revised_features(RunData data) {
06334:                SessionState state = ((JetspeedRunData) data)
06335:                        .getPortletSessionState(((JetspeedRunData) data)
06336:                                .getJs_peid());
06337:                ParameterParser params = data.getParameters();
06338:                getRevisedFeatures(params, state);
06339:
06340:                Site site = getStateSite(state);
06341:                String id = site.getId();
06342:
06343:                // now that the site exists, we can set the email alias when an Email
06344:                // Archive tool has been selected
06345:                String alias = StringUtil.trimToNull((String) state
06346:                        .getAttribute(STATE_TOOL_EMAIL_ADDRESS));
06347:                if (alias != null) {
06348:                    String channelReference = mailArchiveChannelReference(id);
06349:                    try {
06350:                        AliasService.setAlias(alias, channelReference);
06351:                    } catch (IdUsedException ee) {
06352:                    } catch (IdInvalidException ee) {
06353:                        addAlert(state, rb.getString("java.alias") + " "
06354:                                + alias + " " + rb.getString("java.isinval"));
06355:                    } catch (PermissionException ee) {
06356:                        addAlert(state, rb.getString("java.addalias") + " ");
06357:                    }
06358:                }
06359:                if (state.getAttribute(STATE_MESSAGE) == null) {
06360:                    // clean state variables
06361:                    state
06362:                            .removeAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST);
06363:                    state
06364:                            .removeAttribute(STATE_TOOL_REGISTRATION_OLD_SELECTED_LIST);
06365:                    state
06366:                            .removeAttribute(STATE_TOOL_REGISTRATION_OLD_SELECTED_HOME);
06367:                    state.removeAttribute(STATE_NEWS_TITLES);
06368:                    state.removeAttribute(STATE_NEWS_URLS);
06369:                    state.removeAttribute(STATE_WEB_CONTENT_TITLES);
06370:                    state.removeAttribute(STATE_WEB_CONTENT_URLS);
06371:
06372:                    state.setAttribute(STATE_SITE_INSTANCE_ID, id);
06373:
06374:                    state.setAttribute(STATE_TEMPLATE_INDEX, params
06375:                            .getString("continue"));
06376:                }
06377:
06378:                // refresh the whole page
06379:                scheduleTopRefresh();
06380:
06381:            } // doSave_revised_features
06382:
06383:            /**
06384:             * doMenu_add_participant
06385:             */
06386:            public void doMenu_add_participant(RunData data) {
06387:                SessionState state = ((JetspeedRunData) data)
06388:                        .getPortletSessionState(((JetspeedRunData) data)
06389:                                .getJs_peid());
06390:                state.removeAttribute(STATE_SELECTED_USER_LIST);
06391:                state.setAttribute(STATE_TEMPLATE_INDEX, "5");
06392:
06393:            } // doMenu_add_participant
06394:
06395:            /**
06396:             * doMenu_siteInfo_addParticipant
06397:             */
06398:            public void doMenu_siteInfo_addParticipant(RunData data) {
06399:                SessionState state = ((JetspeedRunData) data)
06400:                        .getPortletSessionState(((JetspeedRunData) data)
06401:                                .getJs_peid());
06402:
06403:                state.removeAttribute(STATE_SELECTED_USER_LIST);
06404:
06405:                if (state.getAttribute(STATE_MESSAGE) == null) {
06406:                    state.setAttribute(STATE_TEMPLATE_INDEX, "5");
06407:                }
06408:
06409:            } // doMenu_siteInfo_addParticipant
06410:
06411:            /**
06412:             * doMenu_siteInfo_removeParticipant
06413:             */
06414:            public void doMenu_siteInfo_removeParticipant(RunData data) {
06415:                SessionState state = ((JetspeedRunData) data)
06416:                        .getPortletSessionState(((JetspeedRunData) data)
06417:                                .getJs_peid());
06418:
06419:                ParameterParser params = data.getParameters();
06420:
06421:                if (params.getStrings("selectedUser") == null) {
06422:                    addAlert(state, rb.getString("java.nousers"));
06423:                } else {
06424:                    List removeUser = Arrays.asList(params
06425:                            .getStrings("selectedUser"));
06426:
06427:                    // all or some selected user(s) can be removed, go to confirmation
06428:                    // page
06429:                    if (removeUser.size() > 0) {
06430:                        state.setAttribute(STATE_TEMPLATE_INDEX, "6");
06431:                    } else {
06432:                        addAlert(state, rb.getString("java.however"));
06433:                    }
06434:
06435:                    state.setAttribute(STATE_REMOVEABLE_USER_LIST, removeUser);
06436:                }
06437:
06438:            } // doMenu_siteInfo_removeParticipant
06439:
06440:            /**
06441:             * doMenu_siteInfo_changeRole
06442:             */
06443:            public void doMenu_siteInfo_changeRole(RunData data) {
06444:                SessionState state = ((JetspeedRunData) data)
06445:                        .getPortletSessionState(((JetspeedRunData) data)
06446:                                .getJs_peid());
06447:
06448:                ParameterParser params = data.getParameters();
06449:                if (params.getStrings("selectedUser") == null) {
06450:                    state.removeAttribute(STATE_SELECTED_USER_LIST);
06451:                    addAlert(state, rb.getString("java.nousers2"));
06452:                } else {
06453:                    state.setAttribute(STATE_CHANGEROLE_SAMEROLE, Boolean.TRUE);
06454:
06455:                    List selectedUserIds = Arrays.asList(params
06456:                            .getStrings("selectedUser"));
06457:                    state.setAttribute(STATE_SELECTED_USER_LIST,
06458:                            selectedUserIds);
06459:
06460:                    // get roles for selected participants
06461:                    setSelectedParticipantRoles(state);
06462:
06463:                    if (state.getAttribute(STATE_MESSAGE) == null) {
06464:                        state.setAttribute(STATE_TEMPLATE_INDEX, "7");
06465:                    }
06466:                }
06467:
06468:            } // doMenu_siteInfo_changeRole
06469:
06470:            /**
06471:             * doMenu_siteInfo_globalAccess
06472:             */
06473:            public void doMenu_siteInfo_globalAccess(RunData data) {
06474:                SessionState state = ((JetspeedRunData) data)
06475:                        .getPortletSessionState(((JetspeedRunData) data)
06476:                                .getJs_peid());
06477:
06478:                if (state.getAttribute(STATE_MESSAGE) == null) {
06479:                    state.setAttribute(STATE_TEMPLATE_INDEX, "23");
06480:                }
06481:
06482:            } // doMenu_siteInfo_globalAccess
06483:
06484:            /**
06485:             * doMenu_siteInfo_cancel_access
06486:             */
06487:            public void doMenu_siteInfo_cancel_access(RunData data) {
06488:                SessionState state = ((JetspeedRunData) data)
06489:                        .getPortletSessionState(((JetspeedRunData) data)
06490:                                .getJs_peid());
06491:
06492:                state.removeAttribute(STATE_SELECTED_USER_LIST);
06493:                state.setAttribute(STATE_TEMPLATE_INDEX, "12");
06494:
06495:            } // doMenu_siteInfo_cancel_access
06496:
06497:            /**
06498:             * doMenu_siteInfo_import
06499:             */
06500:            public void doMenu_siteInfo_import(RunData data) {
06501:                SessionState state = ((JetspeedRunData) data)
06502:                        .getPortletSessionState(((JetspeedRunData) data)
06503:                                .getJs_peid());
06504:
06505:                // get the tools
06506:                siteToolsIntoState(state);
06507:
06508:                if (state.getAttribute(STATE_MESSAGE) == null) {
06509:                    state.setAttribute(STATE_TEMPLATE_INDEX, "28");
06510:                }
06511:
06512:            } // doMenu_siteInfo_import
06513:
06514:            /**
06515:             * doMenu_siteInfo_editClass
06516:             */
06517:            public void doMenu_siteInfo_editClass(RunData data) {
06518:                SessionState state = ((JetspeedRunData) data)
06519:                        .getPortletSessionState(((JetspeedRunData) data)
06520:                                .getJs_peid());
06521:
06522:                state.setAttribute(STATE_TEMPLATE_INDEX, "43");
06523:
06524:            } // doMenu_siteInfo_editClass
06525:
06526:            /**
06527:             * doMenu_siteInfo_addClass
06528:             */
06529:            public void doMenu_siteInfo_addClass(RunData data) {
06530:                SessionState state = ((JetspeedRunData) data)
06531:                        .getPortletSessionState(((JetspeedRunData) data)
06532:                                .getJs_peid());
06533:
06534:                Site site = getStateSite(state);
06535:                String termEid = site.getProperties().getProperty(
06536:                        PROP_SITE_TERM_EID);
06537:                state.setAttribute(STATE_TERM_SELECTED, cms
06538:                        .getAcademicSession(termEid));
06539:                state.setAttribute(STATE_TEMPLATE_INDEX, "36");
06540:
06541:            } // doMenu_siteInfo_addClass
06542:
06543:            /**
06544:             * first step of adding class
06545:             */
06546:            public void doAdd_class_select(RunData data) {
06547:                SessionState state = ((JetspeedRunData) data)
06548:                        .getPortletSessionState(((JetspeedRunData) data)
06549:                                .getJs_peid());
06550:                ParameterParser params = data.getParameters();
06551:                String option = params.getString("option");
06552:                if (option.equalsIgnoreCase("change")) {
06553:                    // change term
06554:                    String termId = params.getString("selectTerm");
06555:                    AcademicSession t = cms.getAcademicSession(termId);
06556:                    state.setAttribute(STATE_TERM_SELECTED, t);
06557:                } else if (option.equalsIgnoreCase("cancel")) {
06558:                    // cancel
06559:                    state.removeAttribute(STATE_TERM_SELECTED);
06560:                    removeAddClassContext(state);
06561:                    state.setAttribute(STATE_TEMPLATE_INDEX, "43");
06562:                } else if (option.equalsIgnoreCase("add")) {
06563:                    String userId = StringUtil.trimToZero(SessionManager
06564:                            .getCurrentSessionUserId());
06565:                    AcademicSession t = (AcademicSession) state
06566:                            .getAttribute(STATE_TERM_SELECTED);
06567:                    if (t != null) {
06568:                        List courses = prepareCourseAndSectionListing(userId, t
06569:                                .getEid(), state);
06570:
06571:                        // future term? roster information is not available yet?
06572:                        int weeks = 0;
06573:                        try {
06574:                            weeks = Integer
06575:                                    .parseInt(ServerConfigurationService
06576:                                            .getString(
06577:                                                    "roster.available.weeks.before.term.start",
06578:                                                    "0"));
06579:                        } catch (Exception ignore) {
06580:                            M_log.warn(ignore.getMessage());
06581:                        }
06582:                        if ((courses == null || courses != null
06583:                                && courses.size() == 0)
06584:                                && System.currentTimeMillis() + weeks * 7 * 24
06585:                                        * 60 * 60 * 1000 < t.getStartDate()
06586:                                        .getTime()) {
06587:                            // if a future term is selected
06588:                            state.setAttribute(STATE_FUTURE_TERM_SELECTED,
06589:                                    Boolean.TRUE);
06590:                        } else {
06591:                            state.setAttribute(STATE_FUTURE_TERM_SELECTED,
06592:                                    Boolean.FALSE);
06593:                        }
06594:                    }
06595:
06596:                    // continue
06597:                    doContinue(data);
06598:                }
06599:
06600:            } // doAdd_class_select
06601:
06602:            /**
06603:             * doMenu_siteInfo_duplicate
06604:             */
06605:            public void doMenu_siteInfo_duplicate(RunData data) {
06606:                SessionState state = ((JetspeedRunData) data)
06607:                        .getPortletSessionState(((JetspeedRunData) data)
06608:                                .getJs_peid());
06609:
06610:                if (state.getAttribute(STATE_MESSAGE) == null) {
06611:                    state.setAttribute(STATE_TEMPLATE_INDEX, "29");
06612:                }
06613:
06614:            } // doMenu_siteInfo_import
06615:
06616:            /**
06617:             * doMenu_change_roles
06618:             */
06619:            public void doMenu_change_roles(RunData data) {
06620:                SessionState state = ((JetspeedRunData) data)
06621:                        .getPortletSessionState(((JetspeedRunData) data)
06622:                                .getJs_peid());
06623:                ParameterParser params = data.getParameters();
06624:                if (params.getStrings("removeUser") != null) {
06625:                    state.setAttribute(STATE_SELECTED_USER_LIST, new ArrayList(
06626:                            Arrays.asList(params.getStrings("removeUser"))));
06627:                    state.setAttribute(STATE_TEMPLATE_INDEX, "7");
06628:                } else {
06629:                    addAlert(state, rb.getString("java.nousers2"));
06630:                }
06631:
06632:            } // doMenu_change_roles
06633:
06634:            /**
06635:             * doMenu_edit_site_info
06636:             * 
06637:             */
06638:            public void doMenu_edit_site_info(RunData data) {
06639:                SessionState state = ((JetspeedRunData) data)
06640:                        .getPortletSessionState(((JetspeedRunData) data)
06641:                                .getJs_peid());
06642:
06643:                Site Site = getStateSite(state);
06644:                ResourceProperties siteProperties = Site.getProperties();
06645:                state.setAttribute(FORM_SITEINFO_TITLE, Site.getTitle());
06646:
06647:                String site_type = (String) state.getAttribute(STATE_SITE_TYPE);
06648:                if (site_type != null
06649:                        && !site_type.equalsIgnoreCase("myworkspace")) {
06650:                    state.setAttribute(FORM_SITEINFO_INCLUDE, Boolean.valueOf(
06651:                            Site.isPubView()).toString());
06652:                }
06653:                state.setAttribute(FORM_SITEINFO_DESCRIPTION, Site
06654:                        .getDescription());
06655:                state.setAttribute(FORM_SITEINFO_SHORT_DESCRIPTION, Site
06656:                        .getShortDescription());
06657:                state.setAttribute(FORM_SITEINFO_SKIN, Site.getIconUrl());
06658:                if (Site.getIconUrl() != null) {
06659:                    state.setAttribute(FORM_SITEINFO_SKIN, Site.getIconUrl());
06660:                }
06661:
06662:                // site contact information
06663:                String contactName = siteProperties
06664:                        .getProperty(PROP_SITE_CONTACT_NAME);
06665:                String contactEmail = siteProperties
06666:                        .getProperty(PROP_SITE_CONTACT_EMAIL);
06667:                if (contactName == null && contactEmail == null) {
06668:                    String creatorId = siteProperties
06669:                            .getProperty(ResourceProperties.PROP_CREATOR);
06670:                    try {
06671:                        User u = UserDirectoryService.getUser(creatorId);
06672:                        String email = u.getEmail();
06673:                        if (email != null) {
06674:                            contactEmail = u.getEmail();
06675:                        }
06676:                        contactName = u.getDisplayName();
06677:                    } catch (UserNotDefinedException e) {
06678:                    }
06679:                }
06680:                if (contactName != null) {
06681:                    state.setAttribute(FORM_SITEINFO_CONTACT_NAME, contactName);
06682:                }
06683:                if (contactEmail != null) {
06684:                    state.setAttribute(FORM_SITEINFO_CONTACT_EMAIL,
06685:                            contactEmail);
06686:                }
06687:
06688:                if (state.getAttribute(STATE_MESSAGE) == null) {
06689:                    state.setAttribute(STATE_TEMPLATE_INDEX, "13");
06690:                }
06691:
06692:            } // doMenu_edit_site_info
06693:
06694:            /**
06695:             * doMenu_edit_site_tools
06696:             * 
06697:             */
06698:            public void doMenu_edit_site_tools(RunData data) {
06699:                SessionState state = ((JetspeedRunData) data)
06700:                        .getPortletSessionState(((JetspeedRunData) data)
06701:                                .getJs_peid());
06702:
06703:                // get the tools
06704:                siteToolsIntoState(state);
06705:
06706:                if (state.getAttribute(STATE_MESSAGE) == null) {
06707:                    state.setAttribute(STATE_TEMPLATE_INDEX, "4");
06708:                }
06709:
06710:            } // doMenu_edit_site_tools
06711:
06712:            /**
06713:             * doMenu_edit_site_access
06714:             * 
06715:             */
06716:            public void doMenu_edit_site_access(RunData data) {
06717:                SessionState state = ((JetspeedRunData) data)
06718:                        .getPortletSessionState(((JetspeedRunData) data)
06719:                                .getJs_peid());
06720:
06721:                if (state.getAttribute(STATE_MESSAGE) == null) {
06722:                    state.setAttribute(STATE_TEMPLATE_INDEX, "18");
06723:                }
06724:
06725:            } // doMenu_edit_site_access
06726:
06727:            /**
06728:             * doMenu_publish_site
06729:             * 
06730:             */
06731:            public void doMenu_publish_site(RunData data) {
06732:                SessionState state = ((JetspeedRunData) data)
06733:                        .getPortletSessionState(((JetspeedRunData) data)
06734:                                .getJs_peid());
06735:
06736:                // get the site properties
06737:                sitePropertiesIntoState(state);
06738:
06739:                if (state.getAttribute(STATE_MESSAGE) == null) {
06740:                    state.setAttribute(STATE_TEMPLATE_INDEX, "9");
06741:                }
06742:
06743:            } // doMenu_publish_site
06744:
06745:            /**
06746:             * Back to worksite setup's list view
06747:             * 
06748:             */
06749:            public void doBack_to_site_list(RunData data) {
06750:                SessionState state = ((JetspeedRunData) data)
06751:                        .getPortletSessionState(((JetspeedRunData) data)
06752:                                .getJs_peid());
06753:                state.removeAttribute(STATE_SELECTED_USER_LIST);
06754:                state.removeAttribute(STATE_SITE_TYPE);
06755:                state.removeAttribute(STATE_SITE_INSTANCE_ID);
06756:
06757:                state.setAttribute(STATE_TEMPLATE_INDEX, "0");
06758:
06759:            } // doBack_to_site_list
06760:
06761:            /**
06762:             * doSave_site_info
06763:             * 
06764:             */
06765:            public void doSave_siteInfo(RunData data) {
06766:                SessionState state = ((JetspeedRunData) data)
06767:                        .getPortletSessionState(((JetspeedRunData) data)
06768:                                .getJs_peid());
06769:                Site Site = getStateSite(state);
06770:                ResourcePropertiesEdit siteProperties = Site
06771:                        .getPropertiesEdit();
06772:                String site_type = (String) state.getAttribute(STATE_SITE_TYPE);
06773:
06774:                List titleEditableSiteType = (List) state
06775:                        .getAttribute(TITLE_EDITABLE_SITE_TYPE);
06776:                if (titleEditableSiteType.contains(Site.getType())) {
06777:                    Site.setTitle((String) state
06778:                            .getAttribute(FORM_SITEINFO_TITLE));
06779:                }
06780:
06781:                Site.setDescription((String) state
06782:                        .getAttribute(FORM_SITEINFO_DESCRIPTION));
06783:                Site.setShortDescription((String) state
06784:                        .getAttribute(FORM_SITEINFO_SHORT_DESCRIPTION));
06785:
06786:                if (site_type != null) {
06787:                    if (site_type.equals("course")) {
06788:                        // set icon url for course
06789:                        String skin = (String) state
06790:                                .getAttribute(FORM_SITEINFO_SKIN);
06791:                        setAppearance(state, Site, skin);
06792:                    } else {
06793:                        // set icon url for others
06794:                        String iconUrl = (String) state
06795:                                .getAttribute(FORM_SITEINFO_ICON_URL);
06796:                        Site.setIconUrl(iconUrl);
06797:                    }
06798:
06799:                }
06800:
06801:                // site contact information
06802:                String contactName = (String) state
06803:                        .getAttribute(FORM_SITEINFO_CONTACT_NAME);
06804:                if (contactName != null) {
06805:                    siteProperties.addProperty(PROP_SITE_CONTACT_NAME,
06806:                            contactName);
06807:                }
06808:
06809:                String contactEmail = (String) state
06810:                        .getAttribute(FORM_SITEINFO_CONTACT_EMAIL);
06811:                if (contactEmail != null) {
06812:                    siteProperties.addProperty(PROP_SITE_CONTACT_EMAIL,
06813:                            contactEmail);
06814:                }
06815:
06816:                if (state.getAttribute(STATE_MESSAGE) == null) {
06817:                    try {
06818:                        SiteService.save(Site);
06819:                    } catch (IdUnusedException e) {
06820:                        // TODO:
06821:                    } catch (PermissionException e) {
06822:                        // TODO:
06823:                    }
06824:
06825:                    // clean state attributes
06826:                    state.removeAttribute(FORM_SITEINFO_TITLE);
06827:                    state.removeAttribute(FORM_SITEINFO_DESCRIPTION);
06828:                    state.removeAttribute(FORM_SITEINFO_SHORT_DESCRIPTION);
06829:                    state.removeAttribute(FORM_SITEINFO_SKIN);
06830:                    state.removeAttribute(FORM_SITEINFO_INCLUDE);
06831:                    state.removeAttribute(FORM_SITEINFO_CONTACT_NAME);
06832:                    state.removeAttribute(FORM_SITEINFO_CONTACT_EMAIL);
06833:
06834:                    // back to site info view
06835:                    state.setAttribute(STATE_TEMPLATE_INDEX, "12");
06836:
06837:                    // refresh the whole page
06838:                    scheduleTopRefresh();
06839:
06840:                }
06841:            } // doSave_siteInfo
06842:
06843:            /**
06844:             * init
06845:             * 
06846:             */
06847:            private void init(VelocityPortlet portlet, RunData data,
06848:                    SessionState state) {
06849:                state.setAttribute(STATE_ACTION, "SiteAction");
06850:                setupFormNamesAndConstants(state);
06851:
06852:                if (state.getAttribute(STATE_PAGESIZE_SITEINFO) == null) {
06853:                    state
06854:                            .setAttribute(STATE_PAGESIZE_SITEINFO,
06855:                                    new Hashtable());
06856:                }
06857:
06858:                if (((String) state.getAttribute(STATE_SITE_MODE))
06859:                        .equalsIgnoreCase(SITE_MODE_SITESETUP)) {
06860:                    state.setAttribute(STATE_TEMPLATE_INDEX, "0");
06861:                } else if (((String) state.getAttribute(STATE_SITE_MODE))
06862:                        .equalsIgnoreCase(SITE_MODE_SITEINFO)) {
06863:
06864:                    String siteId = ToolManager.getCurrentPlacement()
06865:                            .getContext();
06866:                    getReviseSite(state, siteId);
06867:                    Hashtable h = (Hashtable) state
06868:                            .getAttribute(STATE_PAGESIZE_SITEINFO);
06869:                    if (!h.containsKey(siteId)) {
06870:                        // update
06871:                        h.put(siteId, new Integer(200));
06872:                        state.setAttribute(STATE_PAGESIZE_SITEINFO, h);
06873:                        state.setAttribute(STATE_PAGESIZE, new Integer(200));
06874:                    }
06875:                }
06876:                if (state.getAttribute(STATE_SITE_TYPES) == null) {
06877:                    PortletConfig config = portlet.getPortletConfig();
06878:
06879:                    // all site types
06880:                    String t = StringUtil.trimToNull(config
06881:                            .getInitParameter("siteTypes"));
06882:                    if (t != null) {
06883:                        state.setAttribute(STATE_SITE_TYPES, new ArrayList(
06884:                                Arrays.asList(t.split(","))));
06885:                    } else {
06886:                        state.setAttribute(STATE_SITE_TYPES, new Vector());
06887:                    }
06888:                }
06889:            } // init
06890:
06891:            public void doNavigate_to_site(RunData data) {
06892:                SessionState state = ((JetspeedRunData) data)
06893:                        .getPortletSessionState(((JetspeedRunData) data)
06894:                                .getJs_peid());
06895:                String siteId = StringUtil.trimToNull(data.getParameters()
06896:                        .getString("option"));
06897:                if (siteId != null) {
06898:                    getReviseSite(state, siteId);
06899:                } else {
06900:                    doBack_to_list(data);
06901:                }
06902:
06903:            } // doNavigate_to_site
06904:
06905:            /**
06906:             * Get site information for revise screen
06907:             */
06908:            private void getReviseSite(SessionState state, String siteId) {
06909:                if (state.getAttribute(STATE_SELECTED_USER_LIST) == null) {
06910:                    state.setAttribute(STATE_SELECTED_USER_LIST, new Vector());
06911:                }
06912:
06913:                List sites = (List) state.getAttribute(STATE_SITES);
06914:
06915:                try {
06916:                    Site site = SiteService.getSite(siteId);
06917:                    state.setAttribute(STATE_SITE_INSTANCE_ID, site.getId());
06918:
06919:                    if (sites != null) {
06920:                        int pos = -1;
06921:                        for (int index = 0; index < sites.size() && pos == -1; index++) {
06922:                            if (((Site) sites.get(index)).getId()
06923:                                    .equals(siteId)) {
06924:                                pos = index;
06925:                            }
06926:                        }
06927:
06928:                        // has any previous site in the list?
06929:                        if (pos > 0) {
06930:                            state.setAttribute(STATE_PREV_SITE, sites
06931:                                    .get(pos - 1));
06932:                        } else {
06933:                            state.removeAttribute(STATE_PREV_SITE);
06934:                        }
06935:
06936:                        // has any next site in the list?
06937:                        if (pos < sites.size() - 1) {
06938:                            state.setAttribute(STATE_NEXT_SITE, sites
06939:                                    .get(pos + 1));
06940:                        } else {
06941:                            state.removeAttribute(STATE_NEXT_SITE);
06942:                        }
06943:                    }
06944:
06945:                    String type = site.getType();
06946:                    if (type == null) {
06947:                        if (state.getAttribute(STATE_DEFAULT_SITE_TYPE) != null) {
06948:                            type = (String) state
06949:                                    .getAttribute(STATE_DEFAULT_SITE_TYPE);
06950:                        }
06951:                    }
06952:                    state.setAttribute(STATE_SITE_TYPE, type);
06953:
06954:                } catch (IdUnusedException e) {
06955:                    M_log.warn(this  + e.toString());
06956:                }
06957:
06958:                // one site has been selected
06959:                state.setAttribute(STATE_TEMPLATE_INDEX, "12");
06960:
06961:            } // getReviseSite
06962:
06963:            /**
06964:             * doUpdate_participant
06965:             * 
06966:             */
06967:            public void doUpdate_participant(RunData data) {
06968:                SessionState state = ((JetspeedRunData) data)
06969:                        .getPortletSessionState(((JetspeedRunData) data)
06970:                                .getJs_peid());
06971:                ParameterParser params = data.getParameters();
06972:                Site s = getStateSite(state);
06973:                String realmId = SiteService.siteReference(s.getId());
06974:                if (AuthzGroupService.allowUpdate(realmId)
06975:                        || SiteService.allowUpdateSiteMembership(s.getId())) {
06976:                    try {
06977:                        AuthzGroup realmEdit = AuthzGroupService
06978:                                .getAuthzGroup(realmId);
06979:
06980:                        // does the site has maintain type user(s) before updating
06981:                        // participants?
06982:                        String maintainRoleString = realmEdit.getMaintainRole();
06983:                        boolean hadMaintainUser = !realmEdit.getUsersHasRole(
06984:                                maintainRoleString).isEmpty();
06985:
06986:                        // update participant roles
06987:                        List participants = (List) state
06988:                                .getAttribute(STATE_PARTICIPANT_LIST);
06989:                        ;
06990:                        // remove all roles and then add back those that were checked
06991:                        for (int i = 0; i < participants.size(); i++) {
06992:                            String id = null;
06993:
06994:                            // added participant
06995:                            Participant participant = (Participant) participants
06996:                                    .get(i);
06997:                            id = participant.getUniqname();
06998:
06999:                            if (id != null) {
07000:                                // get the newly assigned role
07001:                                String inputRoleField = "role" + id;
07002:                                String roleId = params
07003:                                        .getString(inputRoleField);
07004:
07005:                                // only change roles when they are different than before
07006:                                if (roleId != null) {
07007:                                    // get the grant active status
07008:                                    boolean activeGrant = true;
07009:                                    String activeGrantField = "activeGrant"
07010:                                            + id;
07011:                                    if (params.getString(activeGrantField) != null) {
07012:                                        activeGrant = params.getString(
07013:                                                activeGrantField)
07014:                                                .equalsIgnoreCase("true") ? true
07015:                                                : false;
07016:                                    }
07017:
07018:                                    boolean fromProvider = !participant
07019:                                            .isRemoveable();
07020:                                    if (fromProvider
07021:                                            && !roleId.equals(participant
07022:                                                    .getRole())) {
07023:                                        fromProvider = false;
07024:                                    }
07025:                                    realmEdit.addMember(id, roleId,
07026:                                            activeGrant, fromProvider);
07027:                                }
07028:                            }
07029:                        }
07030:
07031:                        // remove selected users
07032:                        if (params.getStrings("selectedUser") != null) {
07033:                            List removals = new ArrayList(Arrays.asList(params
07034:                                    .getStrings("selectedUser")));
07035:                            state.setAttribute(STATE_SELECTED_USER_LIST,
07036:                                    removals);
07037:                            for (int i = 0; i < removals.size(); i++) {
07038:                                String rId = (String) removals.get(i);
07039:                                try {
07040:                                    User user = UserDirectoryService
07041:                                            .getUser(rId);
07042:                                    Participant selected = new Participant();
07043:                                    selected.name = user.getDisplayName();
07044:                                    selected.uniqname = user.getId();
07045:                                    realmEdit.removeMember(user.getId());
07046:                                } catch (UserNotDefinedException e) {
07047:                                    M_log.warn(this  + " IdUnusedException "
07048:                                            + rId + ". ");
07049:                                }
07050:                            }
07051:                        }
07052:
07053:                        if (hadMaintainUser
07054:                                && realmEdit
07055:                                        .getUsersHasRole(maintainRoleString)
07056:                                        .isEmpty()) {
07057:                            // if after update, the "had maintain type user" status
07058:                            // changed, show alert message and don't save the update
07059:                            addAlert(
07060:                                    state,
07061:                                    rb
07062:                                            .getString("sitegen.siteinfolist.nomaintainuser")
07063:                                            + maintainRoleString + ".");
07064:                        } else {
07065:                            AuthzGroupService.save(realmEdit);
07066:                        }
07067:                    } catch (GroupNotDefinedException e) {
07068:                        addAlert(state, rb.getString("java.problem2"));
07069:                        M_log.warn(this  + "  IdUnusedException " + s.getTitle()
07070:                                + "(" + realmId + "). ");
07071:                    } catch (AuthzPermissionException e) {
07072:                        addAlert(state, rb.getString("java.changeroles"));
07073:                        M_log.warn(this  + "  PermissionException "
07074:                                + s.getTitle() + "(" + realmId + "). ");
07075:                    }
07076:                }
07077:
07078:            } // doUpdate_participant
07079:
07080:            /**
07081:             * doUpdate_site_access
07082:             * 
07083:             */
07084:            public void doUpdate_site_access(RunData data) {
07085:                SessionState state = ((JetspeedRunData) data)
07086:                        .getPortletSessionState(((JetspeedRunData) data)
07087:                                .getJs_peid());
07088:                Site sEdit = getStateSite(state);
07089:
07090:                ParameterParser params = data.getParameters();
07091:                String publishUnpublish = params.getString("publishunpublish");
07092:                String include = params.getString("include");
07093:                String joinable = params.getString("joinable");
07094:
07095:                if (sEdit != null) {
07096:                    // editing existing site
07097:                    // publish site or not
07098:                    if (publishUnpublish != null
07099:                            && publishUnpublish.equalsIgnoreCase("publish")) {
07100:                        sEdit.setPublished(true);
07101:                    } else {
07102:                        sEdit.setPublished(false);
07103:                    }
07104:
07105:                    // site public choice
07106:                    if (include != null) {
07107:                        // if there is pubview input, use it
07108:                        sEdit
07109:                                .setPubView(include.equalsIgnoreCase("true") ? true
07110:                                        : false);
07111:                    } else if (state.getAttribute(STATE_SITE_TYPE) != null) {
07112:                        String type = (String) state
07113:                                .getAttribute(STATE_SITE_TYPE);
07114:                        List publicSiteTypes = (List) state
07115:                                .getAttribute(STATE_PUBLIC_SITE_TYPES);
07116:                        List privateSiteTypes = (List) state
07117:                                .getAttribute(STATE_PRIVATE_SITE_TYPES);
07118:
07119:                        if (publicSiteTypes.contains(type)) {
07120:                            // sites are always public
07121:                            sEdit.setPubView(true);
07122:                        } else if (privateSiteTypes.contains(type)) {
07123:                            // site are always private
07124:                            sEdit.setPubView(false);
07125:                        }
07126:                    } else {
07127:                        sEdit.setPubView(false);
07128:                    }
07129:
07130:                    // publish site or not
07131:                    if (joinable != null && joinable.equalsIgnoreCase("true")) {
07132:                        state.setAttribute(STATE_JOINABLE, Boolean.TRUE);
07133:                        sEdit.setJoinable(true);
07134:                        String joinerRole = StringUtil.trimToNull(params
07135:                                .getString("joinerRole"));
07136:                        if (joinerRole != null) {
07137:                            state.setAttribute(STATE_JOINERROLE, joinerRole);
07138:                            sEdit.setJoinerRole(joinerRole);
07139:                        } else {
07140:                            state.setAttribute(STATE_JOINERROLE, "");
07141:                            addAlert(state, rb.getString("java.joinsite") + " ");
07142:                        }
07143:                    } else {
07144:                        state.setAttribute(STATE_JOINABLE, Boolean.FALSE);
07145:                        state.removeAttribute(STATE_JOINERROLE);
07146:                        sEdit.setJoinable(false);
07147:                        sEdit.setJoinerRole(null);
07148:                    }
07149:
07150:                    if (state.getAttribute(STATE_MESSAGE) == null) {
07151:                        commitSite(sEdit);
07152:                        state.setAttribute(STATE_TEMPLATE_INDEX, "12");
07153:
07154:                        // TODO: hard coding this frame id is fragile, portal dependent,
07155:                        // and needs to be fixed -ggolden
07156:                        // schedulePeerFrameRefresh("sitenav");
07157:                        scheduleTopRefresh();
07158:
07159:                        state.removeAttribute(STATE_JOINABLE);
07160:                        state.removeAttribute(STATE_JOINERROLE);
07161:                    }
07162:                } else {
07163:                    // adding new site
07164:                    if (state.getAttribute(STATE_SITE_INFO) != null) {
07165:                        SiteInfo siteInfo = (SiteInfo) state
07166:                                .getAttribute(STATE_SITE_INFO);
07167:
07168:                        if (publishUnpublish != null
07169:                                && publishUnpublish.equalsIgnoreCase("publish")) {
07170:                            siteInfo.published = true;
07171:                        } else {
07172:                            siteInfo.published = false;
07173:                        }
07174:
07175:                        // site public choice
07176:                        if (include != null) {
07177:                            siteInfo.include = include.equalsIgnoreCase("true") ? true
07178:                                    : false;
07179:                        } else if (StringUtil.trimToNull(siteInfo.site_type) != null) {
07180:                            String type = StringUtil
07181:                                    .trimToNull(siteInfo.site_type);
07182:                            List publicSiteTypes = (List) state
07183:                                    .getAttribute(STATE_PUBLIC_SITE_TYPES);
07184:                            List privateSiteTypes = (List) state
07185:                                    .getAttribute(STATE_PRIVATE_SITE_TYPES);
07186:
07187:                            if (publicSiteTypes.contains(type)) {
07188:                                // sites are always public
07189:                                siteInfo.include = true;
07190:                            } else if (privateSiteTypes.contains(type)) {
07191:                                // site are always private
07192:                                siteInfo.include = false;
07193:                            }
07194:                        } else {
07195:                            siteInfo.include = false;
07196:                        }
07197:
07198:                        // joinable site or not
07199:                        if (joinable != null
07200:                                && joinable.equalsIgnoreCase("true")) {
07201:                            siteInfo.joinable = true;
07202:                            String joinerRole = StringUtil.trimToNull(params
07203:                                    .getString("joinerRole"));
07204:                            if (joinerRole != null) {
07205:                                siteInfo.joinerRole = joinerRole;
07206:                            } else {
07207:                                addAlert(state, rb.getString("java.joinsite")
07208:                                        + " ");
07209:                            }
07210:                        } else {
07211:                            siteInfo.joinable = false;
07212:                            siteInfo.joinerRole = null;
07213:                        }
07214:
07215:                        state.setAttribute(STATE_SITE_INFO, siteInfo);
07216:                    }
07217:
07218:                    if (state.getAttribute(STATE_MESSAGE) == null) {
07219:                        state.setAttribute(STATE_TEMPLATE_INDEX, "10");
07220:                        updateCurrentStep(state, true);
07221:                    }
07222:                }
07223:
07224:                // if editing an existing site, refresh the whole page so that the
07225:                // publish/unpublish icon could be updated
07226:                if (sEdit != null) {
07227:                    scheduleTopRefresh();
07228:                }
07229:
07230:            } // doUpdate_site_access
07231:
07232:            /**
07233:             * remove related state variable for changing participants roles
07234:             * 
07235:             * @param state
07236:             *            SessionState object
07237:             */
07238:            private void removeChangeRoleContext(SessionState state) {
07239:                // remove related state variables
07240:                state.removeAttribute(STATE_CHANGEROLE_SAMEROLE);
07241:                state.removeAttribute(STATE_CHANGEROLE_SAMEROLE_ROLE);
07242:                state.removeAttribute(STATE_ADD_PARTICIPANTS);
07243:                state.removeAttribute(STATE_SELECTED_USER_LIST);
07244:                state.removeAttribute(STATE_SELECTED_PARTICIPANT_ROLES);
07245:
07246:            } // removeChangeRoleContext
07247:
07248:            /**
07249:             * /* Actions for vm templates under the "chef_site" root. This method is
07250:             * called by doContinue. Each template has a hidden field with the value of
07251:             * template-index that becomes the value of index for the switch statement
07252:             * here. Some cases not implemented.
07253:             */
07254:            private void actionForTemplate(String direction, int index,
07255:                    ParameterParser params, SessionState state) {
07256:                // Continue - make any permanent changes, Back - keep any data entered
07257:                // on the form
07258:                boolean forward = direction.equals("continue") ? true : false;
07259:
07260:                SiteInfo siteInfo = new SiteInfo();
07261:
07262:                switch (index) {
07263:                case 0:
07264:                    /*
07265:                     * actionForTemplate chef_site-list.vm
07266:                     * 
07267:                     */
07268:                    break;
07269:                case 1:
07270:                    /*
07271:                     * actionForTemplate chef_site-type.vm
07272:                     * 
07273:                     */
07274:                    break;
07275:                case 2:
07276:                    /*
07277:                     * actionForTemplate chef_site-newSiteInformation.vm
07278:                     * 
07279:                     */
07280:                    if (state.getAttribute(STATE_SITE_INFO) != null) {
07281:                        siteInfo = (SiteInfo) state
07282:                                .getAttribute(STATE_SITE_INFO);
07283:                    }
07284:
07285:                    // defaults to be true
07286:                    siteInfo.include = true;
07287:
07288:                    state.setAttribute(STATE_SITE_INFO, siteInfo);
07289:                    updateSiteInfo(params, state);
07290:
07291:                    // alerts after clicking Continue but not Back
07292:                    if (forward) {
07293:                        if (StringUtil.trimToNull(siteInfo.title) == null) {
07294:                            addAlert(state, rb.getString("java.reqfields"));
07295:                            state.setAttribute(STATE_TEMPLATE_INDEX, "2");
07296:                            return;
07297:                        }
07298:                    }
07299:                    updateSiteAttributes(state);
07300:
07301:                    if (state.getAttribute(STATE_MESSAGE) == null) {
07302:                        updateCurrentStep(state, forward);
07303:                    }
07304:
07305:                    break;
07306:                case 3:
07307:                    /*
07308:                     * actionForTemplate chef_site-newSiteFeatures.vm
07309:                     * 
07310:                     */
07311:                    if (forward) {
07312:                        getFeatures(params, state);
07313:                    }
07314:                    if (state.getAttribute(STATE_MESSAGE) == null) {
07315:                        updateCurrentStep(state, forward);
07316:                    }
07317:                    break;
07318:
07319:                case 4:
07320:                    /*
07321:                     * actionForTemplate chef_site-addRemoveFeature.vm
07322:                     * 
07323:                     */
07324:                    break;
07325:                case 5:
07326:                    /*
07327:                     * actionForTemplate chef_site-addParticipant.vm
07328:                     * 
07329:                     */
07330:                    if (forward) {
07331:                        checkAddParticipant(params, state);
07332:                    } else {
07333:                        // remove related state variables
07334:                        removeAddParticipantContext(state);
07335:                    }
07336:                    break;
07337:                case 6:
07338:                    /*
07339:                     * actionForTemplate chef_site-removeParticipants.vm
07340:                     * 
07341:                     */
07342:
07343:                    break;
07344:                case 7:
07345:                    /*
07346:                     * actionForTemplate chef_site-changeRoles.vm
07347:                     * 
07348:                     */
07349:                    if (forward) {
07350:                        if (!((Boolean) state
07351:                                .getAttribute(STATE_CHANGEROLE_SAMEROLE))
07352:                                .booleanValue()) {
07353:                            getSelectedRoles(state, params,
07354:                                    STATE_SELECTED_USER_LIST);
07355:                        } else {
07356:                            String role = params.getString("role_to_all");
07357:                            if (role == null) {
07358:                                addAlert(state, rb
07359:                                        .getString("java.pleasechoose")
07360:                                        + " ");
07361:                            } else {
07362:                                state.setAttribute(
07363:                                        STATE_CHANGEROLE_SAMEROLE_ROLE, role);
07364:                            }
07365:                        }
07366:                    } else {
07367:                        removeChangeRoleContext(state);
07368:                    }
07369:                    break;
07370:                case 8:
07371:                    /*
07372:                     * actionForTemplate chef_site-siteDeleteConfirm.vm
07373:                     * 
07374:                     */
07375:                    break;
07376:                case 9:
07377:                    /*
07378:                     * actionForTemplate chef_site-publishUnpublish.vm
07379:                     * 
07380:                     */
07381:                    updateSiteInfo(params, state);
07382:                    break;
07383:                case 10:
07384:                    /*
07385:                     * actionForTemplate chef_site-newSiteConfirm.vm
07386:                     * 
07387:                     */
07388:                    if (!forward) {
07389:                        if (state.getAttribute(STATE_MESSAGE) == null) {
07390:                            updateCurrentStep(state, false);
07391:                        }
07392:                    }
07393:                    break;
07394:                case 11:
07395:                    /*
07396:                     * actionForTemplate chef_site_newsitePublishUnpublish.vm
07397:                     * 
07398:                     */
07399:                    break;
07400:                case 12:
07401:                    /*
07402:                     * actionForTemplate chef_site_siteInfo-list.vm
07403:                     * 
07404:                     */
07405:                    break;
07406:                case 13:
07407:                    /*
07408:                     * actionForTemplate chef_site_siteInfo-editInfo.vm
07409:                     * 
07410:                     */
07411:                    if (forward) {
07412:                        Site Site = getStateSite(state);
07413:
07414:                        List titleEditableSiteType = (List) state
07415:                                .getAttribute(TITLE_EDITABLE_SITE_TYPE);
07416:                        if (titleEditableSiteType.contains(Site.getType())) {
07417:                            // site titel is editable and could not be null
07418:                            String title = StringUtil.trimToNull(params
07419:                                    .getString("title"));
07420:                            state.setAttribute(FORM_SITEINFO_TITLE, title);
07421:                            if (title == null) {
07422:                                addAlert(state, rb.getString("java.specify")
07423:                                        + " ");
07424:                            }
07425:                        }
07426:
07427:                        String description = StringUtil.trimToNull(params
07428:                                .getString("description"));
07429:                        state.setAttribute(FORM_SITEINFO_DESCRIPTION,
07430:                                description);
07431:
07432:                        String short_description = StringUtil.trimToNull(params
07433:                                .getString("short_description"));
07434:                        state.setAttribute(FORM_SITEINFO_SHORT_DESCRIPTION,
07435:                                short_description);
07436:
07437:                        String skin = params.getString("skin");
07438:                        if (skin != null) {
07439:                            // if there is a skin input for course site
07440:                            skin = StringUtil.trimToNull(skin);
07441:                            state.setAttribute(FORM_SITEINFO_SKIN, skin);
07442:                        } else {
07443:                            // if ther is a icon input for non-course site
07444:                            String icon = StringUtil.trimToNull(params
07445:                                    .getString("icon"));
07446:                            if (icon != null) {
07447:                                if (icon.endsWith(PROTOCOL_STRING)) {
07448:                                    addAlert(state, rb
07449:                                            .getString("alert.protocol"));
07450:                                }
07451:                                state
07452:                                        .setAttribute(FORM_SITEINFO_ICON_URL,
07453:                                                icon);
07454:                            } else {
07455:                                state.removeAttribute(FORM_SITEINFO_ICON_URL);
07456:                            }
07457:                        }
07458:
07459:                        // site contact information
07460:                        String contactName = StringUtil.trimToZero(params
07461:                                .getString("siteContactName"));
07462:                        state.setAttribute(FORM_SITEINFO_CONTACT_NAME,
07463:                                contactName);
07464:
07465:                        String email = StringUtil.trimToZero(params
07466:                                .getString("siteContactEmail"));
07467:                        String[] parts = email.split("@");
07468:                        if (email.length() > 0
07469:                                && (email.indexOf("@") == -1
07470:                                        || parts.length != 2
07471:                                        || parts[0].length() == 0 || !Validator
07472:                                        .checkEmailLocal(parts[0]))) {
07473:                            // invalid email
07474:                            addAlert(state, email + " "
07475:                                    + rb.getString("java.invalid")
07476:                                    + rb.getString("java.theemail"));
07477:                        }
07478:                        state.setAttribute(FORM_SITEINFO_CONTACT_EMAIL, email);
07479:
07480:                        if (state.getAttribute(STATE_MESSAGE) == null) {
07481:                            state.setAttribute(STATE_TEMPLATE_INDEX, "14");
07482:                        }
07483:                    }
07484:                    break;
07485:                case 14:
07486:                    /*
07487:                     * actionForTemplate chef_site_siteInfo-editInfoConfirm.vm
07488:                     * 
07489:                     */
07490:                    break;
07491:                case 15:
07492:                    /*
07493:                     * actionForTemplate chef_site_siteInfo-addRemoveFeatureConfirm.vm
07494:                     * 
07495:                     */
07496:                    break;
07497:                case 16:
07498:                    /*
07499:                     * actionForTemplate
07500:                     * chef_site_siteInfo-publishUnpublish-sendEmail.vm
07501:                     * 
07502:                     */
07503:                    if (forward) {
07504:                        String notify = params.getString("notify");
07505:                        if (notify != null) {
07506:                            state.setAttribute(FORM_WILL_NOTIFY, new Boolean(
07507:                                    notify));
07508:                        }
07509:                    }
07510:                    break;
07511:                case 17:
07512:                    /*
07513:                     * actionForTemplate chef_site_siteInfo--publishUnpublish-confirm.vm
07514:                     * 
07515:                     */
07516:                    if (forward) {
07517:                        boolean oldStatus = getStateSite(state).isPublished();
07518:                        boolean newStatus = ((SiteInfo) state
07519:                                .getAttribute(STATE_SITE_INFO)).getPublished();
07520:                        saveSiteStatus(state, newStatus);
07521:
07522:                        if (oldStatus == false || newStatus == true) {
07523:                            // if site's status been changed from unpublish to publish
07524:                            // and notification is selected, send out notification to
07525:                            // participants.
07526:                            if (((Boolean) state.getAttribute(FORM_WILL_NOTIFY))
07527:                                    .booleanValue()) {
07528:                                // %%% place holder for sending email
07529:                            }
07530:                        }
07531:
07532:                        // commit site edit
07533:                        Site site = getStateSite(state);
07534:
07535:                        try {
07536:                            SiteService.save(site);
07537:                        } catch (IdUnusedException e) {
07538:                            // TODO:
07539:                        } catch (PermissionException e) {
07540:                            // TODO:
07541:                        }
07542:
07543:                        // TODO: hard coding this frame id is fragile, portal dependent,
07544:                        // and needs to be fixed -ggolden
07545:                        // schedulePeerFrameRefresh("sitenav");
07546:                        scheduleTopRefresh();
07547:                    }
07548:                    break;
07549:                case 18:
07550:                    /*
07551:                     * actionForTemplate chef_siteInfo-editAccess.vm
07552:                     * 
07553:                     */
07554:                    if (!forward) {
07555:                        if (state.getAttribute(STATE_MESSAGE) == null) {
07556:                            updateCurrentStep(state, false);
07557:                        }
07558:                    }
07559:                case 19:
07560:                    /*
07561:                     * actionForTemplate chef_site-addParticipant-sameRole.vm
07562:                     * 
07563:                     */
07564:                    String roleId = StringUtil.trimToNull(params
07565:                            .getString("selectRole"));
07566:                    if (roleId == null && forward) {
07567:                        addAlert(state, rb.getString("java.pleasesel") + " ");
07568:                    } else {
07569:                        state.setAttribute("form_selectedRole", params
07570:                                .getString("selectRole"));
07571:                    }
07572:                    break;
07573:                case 20:
07574:                    /*
07575:                     * actionForTemplate chef_site-addParticipant-differentRole.vm
07576:                     * 
07577:                     */
07578:                    if (forward) {
07579:                        getSelectedRoles(state, params, STATE_ADD_PARTICIPANTS);
07580:                    }
07581:                    break;
07582:                case 21:
07583:                    /*
07584:                     * actionForTemplate chef_site-addParticipant-notification.vm '
07585:                     */
07586:                    if (params.getString("notify") == null) {
07587:                        if (forward)
07588:                            addAlert(state, rb.getString("java.pleasechoice")
07589:                                    + " ");
07590:                    } else {
07591:                        state.setAttribute("form_selectedNotify", new Boolean(
07592:                                params.getString("notify")));
07593:                    }
07594:                    break;
07595:                case 22:
07596:                    /*
07597:                     * actionForTemplate chef_site-addParticipant-confirm.vm
07598:                     * 
07599:                     */
07600:                    break;
07601:                case 23:
07602:                    /*
07603:                     * actionForTemplate chef_siteInfo-editAccess-globalAccess.vm
07604:                     * 
07605:                     */
07606:                    if (forward) {
07607:                        String joinable = params.getString("joinable");
07608:                        state.setAttribute("form_joinable", Boolean
07609:                                .valueOf(joinable));
07610:                        String joinerRole = params.getString("joinerRole");
07611:                        state.setAttribute("form_joinerRole", joinerRole);
07612:                        if (joinable.equals("true")) {
07613:                            if (joinerRole == null) {
07614:                                addAlert(state, rb.getString("java.pleasesel")
07615:                                        + " ");
07616:                            }
07617:                        }
07618:                    } else {
07619:                    }
07620:                    break;
07621:                case 24:
07622:                    /*
07623:                     * actionForTemplate
07624:                     * chef_site-siteInfo-editAccess-globalAccess-confirm.vm
07625:                     * 
07626:                     */
07627:                    break;
07628:                case 25:
07629:                    /*
07630:                     * actionForTemplate chef_site-changeRoles-confirm.vm
07631:                     * 
07632:                     */
07633:                    break;
07634:                case 26:
07635:                    /*
07636:                     * actionForTemplate chef_site-modifyENW.vm
07637:                     * 
07638:                     */
07639:                    updateSelectedToolList(state, params, forward);
07640:                    if (state.getAttribute(STATE_MESSAGE) == null) {
07641:                        updateCurrentStep(state, forward);
07642:                    }
07643:                    break;
07644:                case 27:
07645:                    /*
07646:                     * actionForTemplate chef_site-importSites.vm
07647:                     * 
07648:                     */
07649:                    if (forward) {
07650:                        Site existingSite = getStateSite(state);
07651:                        if (existingSite != null) {
07652:                            // revising a existing site's tool
07653:                            if (select_import_tools(params, state)) {
07654:                                Hashtable importTools = (Hashtable) state
07655:                                        .getAttribute(STATE_IMPORT_SITE_TOOL);
07656:                                List selectedTools = (List) state
07657:                                        .getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST);
07658:                                importToolIntoSite(selectedTools, importTools,
07659:                                        existingSite);
07660:
07661:                                existingSite = getStateSite(state); // refresh site for
07662:                                // WC and News
07663:
07664:                                if (state.getAttribute(STATE_MESSAGE) == null) {
07665:                                    commitSite(existingSite);
07666:                                    state
07667:                                            .removeAttribute(STATE_IMPORT_SITE_TOOL);
07668:                                    state.removeAttribute(STATE_IMPORT_SITES);
07669:                                }
07670:                            } else {
07671:                                // show alert and remain in current page
07672:                                addAlert(state, rb
07673:                                        .getString("java.toimporttool"));
07674:                            }
07675:                        } else {
07676:                            // new site
07677:                            select_import_tools(params, state);
07678:                        }
07679:                    } else {
07680:                        // read form input about import tools
07681:                        select_import_tools(params, state);
07682:                    }
07683:                    if (state.getAttribute(STATE_MESSAGE) == null) {
07684:                        updateCurrentStep(state, forward);
07685:                    }
07686:                    break;
07687:                case 28:
07688:                    /*
07689:                     * actionForTemplate chef_siteinfo-import.vm
07690:                     * 
07691:                     */
07692:                    if (forward) {
07693:                        if (params.getStrings("importSites") == null) {
07694:                            addAlert(state, rb.getString("java.toimport") + " ");
07695:                            state.removeAttribute(STATE_IMPORT_SITES);
07696:                        } else {
07697:                            List importSites = new ArrayList(Arrays
07698:                                    .asList(params.getStrings("importSites")));
07699:                            Hashtable sites = new Hashtable();
07700:                            for (index = 0; index < importSites.size(); index++) {
07701:                                try {
07702:                                    Site s = SiteService
07703:                                            .getSite((String) importSites
07704:                                                    .get(index));
07705:                                    sites.put(s, new Vector());
07706:                                } catch (IdUnusedException e) {
07707:                                }
07708:                            }
07709:                            state.setAttribute(STATE_IMPORT_SITES, sites);
07710:                        }
07711:                    }
07712:                    break;
07713:                case 29:
07714:                    /*
07715:                     * actionForTemplate chef_siteinfo-duplicate.vm
07716:                     * 
07717:                     */
07718:                    if (forward) {
07719:                        if (state.getAttribute(SITE_DUPLICATED) == null) {
07720:                            if (StringUtil
07721:                                    .trimToNull(params.getString("title")) == null) {
07722:                                addAlert(state, rb.getString("java.dupli")
07723:                                        + " ");
07724:                            } else {
07725:                                String title = params.getString("title");
07726:                                state.setAttribute(SITE_DUPLICATED_NAME, title);
07727:
07728:                                try {
07729:                                    String oSiteId = (String) state
07730:                                            .getAttribute(STATE_SITE_INSTANCE_ID);
07731:                                    String nSiteId = IdManager.createUuid();
07732:                                    Site site = SiteService.addSite(nSiteId,
07733:                                            getStateSite(state));
07734:
07735:                                    try {
07736:                                        SiteService.save(site);
07737:                                    } catch (IdUnusedException e) {
07738:                                        // TODO:
07739:                                    } catch (PermissionException e) {
07740:                                        // TODO:
07741:                                    }
07742:
07743:                                    try {
07744:                                        site = SiteService.getSite(nSiteId);
07745:
07746:                                        // set title
07747:                                        site.setTitle(title);
07748:                                        // import tool content
07749:                                        List pageList = site.getPages();
07750:                                        if (!((pageList == null) || (pageList
07751:                                                .size() == 0))) {
07752:                                            for (ListIterator i = pageList
07753:                                                    .listIterator(); i
07754:                                                    .hasNext();) {
07755:                                                SitePage page = (SitePage) i
07756:                                                        .next();
07757:
07758:                                                List pageToolList = page
07759:                                                        .getTools();
07760:                                                String toolId = ((ToolConfiguration) pageToolList
07761:                                                        .get(0)).getTool()
07762:                                                        .getId();
07763:                                                if (toolId
07764:                                                        .equalsIgnoreCase("sakai.resources")) {
07765:                                                    // handle
07766:                                                    // resource
07767:                                                    // tool
07768:                                                    // specially
07769:                                                    transferCopyEntities(
07770:                                                            toolId,
07771:                                                            ContentHostingService
07772:                                                                    .getSiteCollection(oSiteId),
07773:                                                            ContentHostingService
07774:                                                                    .getSiteCollection(nSiteId));
07775:                                                } else {
07776:                                                    // other
07777:                                                    // tools
07778:                                                    transferCopyEntities(
07779:                                                            toolId, oSiteId,
07780:                                                            nSiteId);
07781:                                                }
07782:                                            }
07783:                                        }
07784:                                    } catch (Exception e1) {
07785:                                        // if goes here, IdService
07786:                                        // or SiteService has done
07787:                                        // something wrong.
07788:                                        M_log.warn(this  + "Exception" + e1
07789:                                                + ":" + nSiteId
07790:                                                + "when duplicating site");
07791:                                    }
07792:
07793:                                    if (site.getType().equals("course")) {
07794:                                        // for course site, need to
07795:                                        // read in the input for
07796:                                        // term information
07797:                                        String termId = StringUtil
07798:                                                .trimToNull(params
07799:                                                        .getString("selectTerm"));
07800:                                        if (termId != null) {
07801:                                            site.getPropertiesEdit()
07802:                                                    .addProperty(
07803:                                                            PROP_SITE_TERM,
07804:                                                            termId);
07805:                                        }
07806:                                    }
07807:                                    try {
07808:                                        SiteService.save(site);
07809:                                    } catch (IdUnusedException e) {
07810:                                        // TODO:
07811:                                    } catch (PermissionException e) {
07812:                                        // TODO:
07813:                                    }
07814:
07815:                                    // TODO: hard coding this frame id
07816:                                    // is fragile, portal dependent, and
07817:                                    // needs to be fixed -ggolden
07818:                                    // schedulePeerFrameRefresh("sitenav");
07819:                                    scheduleTopRefresh();
07820:
07821:                                    state.setAttribute(SITE_DUPLICATED,
07822:                                            Boolean.TRUE);
07823:                                } catch (IdInvalidException e) {
07824:                                    addAlert(state, rb
07825:                                            .getString("java.siteinval"));
07826:                                } catch (IdUsedException e) {
07827:                                    addAlert(state, rb
07828:                                            .getString("java.sitebeenused")
07829:                                            + " ");
07830:                                } catch (PermissionException e) {
07831:                                    addAlert(state, rb
07832:                                            .getString("java.allowcreate")
07833:                                            + " ");
07834:                                }
07835:                            }
07836:                        }
07837:
07838:                        if (state.getAttribute(STATE_MESSAGE) == null) {
07839:                            // site duplication confirmed
07840:                            state.removeAttribute(SITE_DUPLICATED);
07841:                            state.removeAttribute(SITE_DUPLICATED_NAME);
07842:
07843:                            // return to the list view
07844:                            state.setAttribute(STATE_TEMPLATE_INDEX, "12");
07845:                        }
07846:                    }
07847:                    break;
07848:                case 33:
07849:                    break;
07850:                case 36:
07851:                    /*
07852:                     * actionForTemplate chef_site-newSiteCourse.vm
07853:                     */
07854:                    if (forward) {
07855:                        List providerChosenList = new Vector();
07856:                        if (params.getStrings("providerCourseAdd") == null) {
07857:                            state
07858:                                    .removeAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN);
07859:                            if (params.getString("manualAdds") == null) {
07860:                                addAlert(state, rb.getString("java.manual")
07861:                                        + " ");
07862:                            }
07863:                        }
07864:                        if (state.getAttribute(STATE_MESSAGE) == null) {
07865:                            // The list of courses selected from provider listing
07866:                            if (params.getStrings("providerCourseAdd") != null) {
07867:                                providerChosenList = new ArrayList(
07868:                                        Arrays
07869:                                                .asList(params
07870:                                                        .getStrings("providerCourseAdd"))); // list of
07871:                                // course
07872:                                // ids
07873:                                String userId = (String) state
07874:                                        .getAttribute(STATE_INSTRUCTOR_SELECTED);
07875:                                String currentUserId = (String) state
07876:                                        .getAttribute(STATE_CM_CURRENT_USERID);
07877:
07878:                                if (userId == null
07879:                                        || (userId != null && userId
07880:                                                .equals(currentUserId))) {
07881:                                    state.setAttribute(
07882:                                            STATE_ADD_CLASS_PROVIDER_CHOSEN,
07883:                                            providerChosenList);
07884:                                    state
07885:                                            .removeAttribute(STATE_CM_AUTHORIZER_SECTIONS);
07886:                                    state.removeAttribute(FORM_ADDITIONAL);
07887:                                    state
07888:                                            .removeAttribute(STATE_CM_AUTHORIZER_LIST);
07889:                                } else {
07890:                                    // STATE_CM_AUTHORIZER_SECTIONS are SectionObject,
07891:                                    // so need to prepare it
07892:                                    // also in this page, u can pick either section from
07893:                                    // current user OR
07894:                                    // sections from another users but not both. -
07895:                                    // daisy's note 1 for now
07896:                                    // till we are ready to add more complexity
07897:                                    List sectionObjectList = prepareSectionObject(
07898:                                            providerChosenList, userId);
07899:                                    state.setAttribute(
07900:                                            STATE_CM_AUTHORIZER_SECTIONS,
07901:                                            sectionObjectList);
07902:                                    state
07903:                                            .removeAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN);
07904:                                    // set special instruction & we will keep
07905:                                    // STATE_CM_AUTHORIZER_LIST
07906:                                    String additional = StringUtil
07907:                                            .trimToZero(params
07908:                                                    .getString("additional"));
07909:                                    state.setAttribute(FORM_ADDITIONAL,
07910:                                            additional);
07911:                                }
07912:                            }
07913:                            collectNewSiteInfo(siteInfo, state, params,
07914:                                    providerChosenList);
07915:                        }
07916:                        // next step
07917:                        state.setAttribute(SITE_CREATE_CURRENT_STEP,
07918:                                new Integer(2));
07919:                    }
07920:                    break;
07921:                case 52:
07922:                    // v2.4 - added by daisyf
07923:                    // RemoveSection - remove any selected course from a list of
07924:                    // provider courses
07925:                    // check if any section need to be removed
07926:                    removeAnyFlagedSection(state, params);
07927:
07928:                    List providerChosenList = (List) state
07929:                            .getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN);
07930:                    collectNewSiteInfo(siteInfo, state, params,
07931:                            providerChosenList);
07932:                    // next step
07933:                    state
07934:                            .setAttribute(SITE_CREATE_CURRENT_STEP,
07935:                                    new Integer(2));
07936:                    break;
07937:                case 38:
07938:                    break;
07939:                case 39:
07940:                    break;
07941:                case 42:
07942:                    /*
07943:                     * actionForTemplate chef_site-gradtoolsConfirm.vm
07944:                     * 
07945:                     */
07946:                    break;
07947:                case 43:
07948:                    /*
07949:                     * actionForTemplate chef_site-editClass.vm
07950:                     * 
07951:                     */
07952:                    if (forward) {
07953:                        if (params.getStrings("providerClassDeletes") == null
07954:                                && params.getStrings("manualClassDeletes") == null
07955:                                && !direction.equals("back")) {
07956:                            addAlert(state, rb.getString("java.classes"));
07957:                        }
07958:
07959:                        if (params.getStrings("providerClassDeletes") != null) {
07960:                            // build the deletions list
07961:                            List providerCourseList = (List) state
07962:                                    .getAttribute(SITE_PROVIDER_COURSE_LIST);
07963:                            List providerCourseDeleteList = new ArrayList(
07964:                                    Arrays
07965:                                            .asList(params
07966:                                                    .getStrings("providerClassDeletes")));
07967:                            for (ListIterator i = providerCourseDeleteList
07968:                                    .listIterator(); i.hasNext();) {
07969:                                providerCourseList.remove((String) i.next());
07970:                            }
07971:                            state.setAttribute(SITE_PROVIDER_COURSE_LIST,
07972:                                    providerCourseList);
07973:                        }
07974:                        if (params.getStrings("manualClassDeletes") != null) {
07975:                            // build the deletions list
07976:                            List manualCourseList = (List) state
07977:                                    .getAttribute(SITE_MANUAL_COURSE_LIST);
07978:                            List manualCourseDeleteList = new ArrayList(Arrays
07979:                                    .asList(params
07980:                                            .getStrings("manualClassDeletes")));
07981:                            for (ListIterator i = manualCourseDeleteList
07982:                                    .listIterator(); i.hasNext();) {
07983:                                manualCourseList.remove((String) i.next());
07984:                            }
07985:                            state.setAttribute(SITE_MANUAL_COURSE_LIST,
07986:                                    manualCourseList);
07987:                        }
07988:
07989:                        updateCourseClasses(state, new Vector(), new Vector());
07990:                    }
07991:                    break;
07992:                case 44:
07993:                    if (forward) {
07994:                        List providerList = (state
07995:                                .getAttribute(SITE_PROVIDER_COURSE_LIST) == null) ? new Vector()
07996:                                : (List) state
07997:                                        .getAttribute(SITE_PROVIDER_COURSE_LIST);
07998:                        List addProviderList = (state
07999:                                .getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN) == null) ? new Vector()
08000:                                : (List) state
08001:                                        .getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN);
08002:                        providerList.addAll(addProviderList);
08003:                        state.setAttribute(SITE_PROVIDER_COURSE_LIST,
08004:                                providerList);
08005:
08006:                        if (state.getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER) != null) {
08007:                            // if manually added course
08008:                            List manualList = (state
08009:                                    .getAttribute(SITE_MANUAL_COURSE_LIST) == null) ? new Vector()
08010:                                    : (List) state
08011:                                            .getAttribute(SITE_MANUAL_COURSE_LIST);
08012:                            int manualAddNumber = ((Integer) state
08013:                                    .getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER))
08014:                                    .intValue();
08015:
08016:                            List manualAddFields = (List) state
08017:                                    .getAttribute(STATE_MANUAL_ADD_COURSE_FIELDS);
08018:
08019:                            AcademicSession a = (AcademicSession) state
08020:                                    .getAttribute(STATE_TERM_SELECTED);
08021:                            for (int m = 0; m < manualAddNumber && a != null; m++) {
08022:                                String manualAddClassId = sectionFieldManager
08023:                                        .getSectionEid(a.getEid(),
08024:                                                (List) manualAddFields.get(m));
08025:                                manualList.add(manualAddClassId);
08026:                            }
08027:                            state.setAttribute(SITE_MANUAL_COURSE_LIST,
08028:                                    manualList);
08029:                        }
08030:
08031:                        updateCourseClasses(state, (List) state
08032:                                .getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN),
08033:                                (List) state
08034:                                        .getAttribute(SITE_MANUAL_COURSE_LIST));
08035:
08036:                        removeAddClassContext(state);
08037:                    }
08038:
08039:                    break;
08040:                case 49:
08041:                    if (!forward) {
08042:                        state.removeAttribute(SORTED_BY);
08043:                        state.removeAttribute(SORTED_ASC);
08044:                    }
08045:                    break;
08046:                }
08047:
08048:            }// actionFor Template
08049:
08050:            /**
08051:             * update current step index within the site creation wizard
08052:             * 
08053:             * @param state
08054:             *            The SessionState object
08055:             * @param forward
08056:             *            Moving forward or backward?
08057:             */
08058:            private void updateCurrentStep(SessionState state, boolean forward) {
08059:                if (state.getAttribute(SITE_CREATE_CURRENT_STEP) != null) {
08060:                    int currentStep = ((Integer) state
08061:                            .getAttribute(SITE_CREATE_CURRENT_STEP)).intValue();
08062:                    if (forward) {
08063:                        state.setAttribute(SITE_CREATE_CURRENT_STEP,
08064:                                new Integer(currentStep + 1));
08065:                    } else {
08066:                        state.setAttribute(SITE_CREATE_CURRENT_STEP,
08067:                                new Integer(currentStep - 1));
08068:                    }
08069:                }
08070:            }
08071:
08072:            /**
08073:             * remove related state variable for adding class
08074:             * 
08075:             * @param state
08076:             *            SessionState object
08077:             */
08078:            private void removeAddClassContext(SessionState state) {
08079:                // remove related state variables
08080:                state.removeAttribute(STATE_ADD_CLASS_MANUAL);
08081:                state.removeAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN);
08082:                state.removeAttribute(STATE_MANUAL_ADD_COURSE_NUMBER);
08083:                state.removeAttribute(STATE_MANUAL_ADD_COURSE_FIELDS);
08084:                state.removeAttribute(STATE_SITE_QUEST_UNIQNAME);
08085:                state.removeAttribute(STATE_AUTO_ADD);
08086:                state.removeAttribute(SITE_CREATE_TOTAL_STEPS);
08087:                state.removeAttribute(SITE_CREATE_CURRENT_STEP);
08088:                state.removeAttribute(STATE_IMPORT_SITE_TOOL);
08089:                state.removeAttribute(STATE_IMPORT_SITES);
08090:
08091:            } // removeAddClassContext
08092:
08093:            private void updateCourseClasses(SessionState state,
08094:                    List notifyClasses, List requestClasses) {
08095:                List providerCourseSectionList = (List) state
08096:                        .getAttribute(SITE_PROVIDER_COURSE_LIST);
08097:                List manualCourseSectionList = (List) state
08098:                        .getAttribute(SITE_MANUAL_COURSE_LIST);
08099:                Site site = getStateSite(state);
08100:                String id = site.getId();
08101:                String realmId = SiteService.siteReference(id);
08102:
08103:                if ((providerCourseSectionList == null)
08104:                        || (providerCourseSectionList.size() == 0)) {
08105:                    // no section access so remove Provider Id
08106:                    try {
08107:                        AuthzGroup realmEdit1 = AuthzGroupService
08108:                                .getAuthzGroup(realmId);
08109:                        realmEdit1.setProviderGroupId(NULL_STRING);
08110:                        AuthzGroupService.save(realmEdit1);
08111:                    } catch (GroupNotDefinedException e) {
08112:                        M_log.warn(this  + " IdUnusedException, "
08113:                                + site.getTitle() + "(" + realmId
08114:                                + ") not found, or not an AuthzGroup object");
08115:                        addAlert(state, rb.getString("java.cannotedit"));
08116:                        return;
08117:                    } catch (AuthzPermissionException e) {
08118:                        M_log
08119:                                .warn(this 
08120:                                        + " PermissionException, user does not have permission to edit AuthzGroup object "
08121:                                        + site.getTitle() + "(" + realmId
08122:                                        + "). ");
08123:                        addAlert(state, rb.getString("java.notaccess"));
08124:                        return;
08125:                    }
08126:                }
08127:                if ((providerCourseSectionList != null)
08128:                        && (providerCourseSectionList.size() != 0)) {
08129:                    // section access so rewrite Provider Id
08130:                    String externalRealm = buildExternalRealm(id, state,
08131:                            providerCourseSectionList);
08132:                    try {
08133:                        AuthzGroup realmEdit2 = AuthzGroupService
08134:                                .getAuthzGroup(realmId);
08135:                        realmEdit2.setProviderGroupId(externalRealm);
08136:                        AuthzGroupService.save(realmEdit2);
08137:                    } catch (GroupNotDefinedException e) {
08138:                        M_log.warn(this  + " IdUnusedException, "
08139:                                + site.getTitle() + "(" + realmId
08140:                                + ") not found, or not an AuthzGroup object");
08141:                        addAlert(state, rb.getString("java.cannotclasses"));
08142:                        return;
08143:                    } catch (AuthzPermissionException e) {
08144:                        M_log
08145:                                .warn(this 
08146:                                        + " PermissionException, user does not have permission to edit AuthzGroup object "
08147:                                        + site.getTitle() + "(" + realmId
08148:                                        + "). ");
08149:                        addAlert(state, rb.getString("java.notaccess"));
08150:                        return;
08151:                    }
08152:
08153:                }
08154:
08155:                if ((manualCourseSectionList != null)
08156:                        && (manualCourseSectionList.size() != 0)) {
08157:                    // store the manually requested sections in one site property
08158:                    String manualSections = "";
08159:                    for (int j = 0; j < manualCourseSectionList.size();) {
08160:                        manualSections = manualSections
08161:                                + (String) manualCourseSectionList.get(j);
08162:                        j++;
08163:                        if (j < manualCourseSectionList.size()) {
08164:                            manualSections = manualSections + "+";
08165:                        }
08166:                    }
08167:                    ResourcePropertiesEdit rp = site.getPropertiesEdit();
08168:                    rp.addProperty(PROP_SITE_REQUEST_COURSE, manualSections);
08169:                } else {
08170:                    ResourcePropertiesEdit rp = site.getPropertiesEdit();
08171:                    rp.removeProperty(PROP_SITE_REQUEST_COURSE);
08172:                }
08173:
08174:                if (state.getAttribute(STATE_MESSAGE) == null) {
08175:                    commitSite(site);
08176:                } else {
08177:                }
08178:                if (requestClasses != null
08179:                        && requestClasses.size() > 0
08180:                        && state.getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER) != null) {
08181:                    try {
08182:                        // send out class request notifications
08183:                        sendSiteRequest(state, "change", ((Integer) state
08184:                                .getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER))
08185:                                .intValue(), (List) state
08186:                                .getAttribute(STATE_MANUAL_ADD_COURSE_FIELDS));
08187:                    } catch (Exception e) {
08188:                        M_log.warn(this  + e.toString());
08189:                    }
08190:                }
08191:                if (notifyClasses != null && notifyClasses.size() > 0) {
08192:                    try {
08193:                        // send out class access confirmation notifications
08194:                        sendSiteNotification(state, notifyClasses);
08195:                    } catch (Exception e) {
08196:                        M_log.warn(this  + e.toString());
08197:                    }
08198:                }
08199:            } // updateCourseClasses
08200:
08201:            /**
08202:             * Sets selected roles for multiple users
08203:             * 
08204:             * @param params
08205:             *            The ParameterParser object
08206:             * @param listName
08207:             *            The state variable
08208:             */
08209:            private void getSelectedRoles(SessionState state,
08210:                    ParameterParser params, String listName) {
08211:                Hashtable pSelectedRoles = (Hashtable) state
08212:                        .getAttribute(STATE_SELECTED_PARTICIPANT_ROLES);
08213:                if (pSelectedRoles == null) {
08214:                    pSelectedRoles = new Hashtable();
08215:                }
08216:                List userList = (List) state.getAttribute(listName);
08217:                for (int i = 0; i < userList.size(); i++) {
08218:                    String userId = null;
08219:
08220:                    if (listName.equalsIgnoreCase(STATE_ADD_PARTICIPANTS)) {
08221:                        userId = ((Participant) userList.get(i)).getUniqname();
08222:                    } else if (listName
08223:                            .equalsIgnoreCase(STATE_SELECTED_USER_LIST)) {
08224:                        userId = (String) userList.get(i);
08225:                    }
08226:
08227:                    if (userId != null) {
08228:                        String rId = StringUtil.trimToNull(params
08229:                                .getString("role" + userId));
08230:                        if (rId == null) {
08231:                            addAlert(state, rb.getString("java.rolefor") + " "
08232:                                    + userId + ". ");
08233:                            pSelectedRoles.remove(userId);
08234:                        } else {
08235:                            pSelectedRoles.put(userId, rId);
08236:                        }
08237:                    }
08238:                }
08239:                state.setAttribute(STATE_SELECTED_PARTICIPANT_ROLES,
08240:                        pSelectedRoles);
08241:
08242:            } // getSelectedRoles
08243:
08244:            /**
08245:             * dispatch function for changing participants roles
08246:             */
08247:            public void doSiteinfo_edit_role(RunData data) {
08248:                SessionState state = ((JetspeedRunData) data)
08249:                        .getPortletSessionState(((JetspeedRunData) data)
08250:                                .getJs_peid());
08251:                ParameterParser params = data.getParameters();
08252:
08253:                String option = params.getString("option");
08254:                // dispatch
08255:                if (option.equalsIgnoreCase("same_role_true")) {
08256:                    state.setAttribute(STATE_CHANGEROLE_SAMEROLE, Boolean.TRUE);
08257:                    state.setAttribute(STATE_CHANGEROLE_SAMEROLE_ROLE, params
08258:                            .getString("role_to_all"));
08259:                } else if (option.equalsIgnoreCase("same_role_false")) {
08260:                    state
08261:                            .setAttribute(STATE_CHANGEROLE_SAMEROLE,
08262:                                    Boolean.FALSE);
08263:                    state.removeAttribute(STATE_CHANGEROLE_SAMEROLE_ROLE);
08264:                    if (state.getAttribute(STATE_SELECTED_PARTICIPANT_ROLES) == null) {
08265:                        state.setAttribute(STATE_SELECTED_PARTICIPANT_ROLES,
08266:                                new Hashtable());
08267:                    }
08268:                } else if (option.equalsIgnoreCase("continue")) {
08269:                    doContinue(data);
08270:                } else if (option.equalsIgnoreCase("back")) {
08271:                    doBack(data);
08272:                } else if (option.equalsIgnoreCase("cancel")) {
08273:                    doCancel(data);
08274:                }
08275:            } // doSiteinfo_edit_globalAccess
08276:
08277:            /**
08278:             * dispatch function for changing site global access
08279:             */
08280:            public void doSiteinfo_edit_globalAccess(RunData data) {
08281:                SessionState state = ((JetspeedRunData) data)
08282:                        .getPortletSessionState(((JetspeedRunData) data)
08283:                                .getJs_peid());
08284:                ParameterParser params = data.getParameters();
08285:
08286:                String option = params.getString("option");
08287:
08288:                // dispatch
08289:                if (option.equalsIgnoreCase("joinable")) {
08290:                    state.setAttribute("form_joinable", Boolean.TRUE);
08291:                    state.setAttribute("form_joinerRole", getStateSite(state)
08292:                            .getJoinerRole());
08293:                } else if (option.equalsIgnoreCase("unjoinable")) {
08294:                    state.setAttribute("form_joinable", Boolean.FALSE);
08295:                    state.removeAttribute("form_joinerRole");
08296:                } else if (option.equalsIgnoreCase("continue")) {
08297:                    doContinue(data);
08298:                } else if (option.equalsIgnoreCase("cancel")) {
08299:                    doCancel(data);
08300:                }
08301:            } // doSiteinfo_edit_globalAccess
08302:
08303:            /**
08304:             * save changes to site global access
08305:             */
08306:            public void doSiteinfo_save_globalAccess(RunData data) {
08307:                SessionState state = ((JetspeedRunData) data)
08308:                        .getPortletSessionState(((JetspeedRunData) data)
08309:                                .getJs_peid());
08310:
08311:                Site s = getStateSite(state);
08312:                boolean joinable = ((Boolean) state
08313:                        .getAttribute("form_joinable")).booleanValue();
08314:                s.setJoinable(joinable);
08315:                if (joinable) {
08316:                    // set the joiner role
08317:                    String joinerRole = (String) state
08318:                            .getAttribute("form_joinerRole");
08319:                    s.setJoinerRole(joinerRole);
08320:                }
08321:
08322:                if (state.getAttribute(STATE_MESSAGE) == null) {
08323:                    // release site edit
08324:                    commitSite(s);
08325:
08326:                    state.setAttribute(STATE_TEMPLATE_INDEX, "18");
08327:                }
08328:
08329:            } // doSiteinfo_save_globalAccess
08330:
08331:            /**
08332:             * updateSiteAttributes
08333:             * 
08334:             */
08335:            private void updateSiteAttributes(SessionState state) {
08336:                SiteInfo siteInfo = new SiteInfo();
08337:                if (state.getAttribute(STATE_SITE_INFO) != null) {
08338:                    siteInfo = (SiteInfo) state.getAttribute(STATE_SITE_INFO);
08339:                } else {
08340:                    M_log
08341:                            .warn("SiteAction.updateSiteAttributes STATE_SITE_INFO == null");
08342:                    return;
08343:                }
08344:
08345:                Site site = getStateSite(state);
08346:
08347:                if (site != null) {
08348:                    if (StringUtil.trimToNull(siteInfo.title) != null) {
08349:                        site.setTitle(siteInfo.title);
08350:                    }
08351:                    if (siteInfo.description != null) {
08352:                        site.setDescription(siteInfo.description);
08353:                    }
08354:                    site.setPublished(siteInfo.published);
08355:
08356:                    setAppearance(state, site, siteInfo.iconUrl);
08357:
08358:                    site.setJoinable(siteInfo.joinable);
08359:                    if (StringUtil.trimToNull(siteInfo.joinerRole) != null) {
08360:                        site.setJoinerRole(siteInfo.joinerRole);
08361:                    }
08362:                    // Make changes and then put changed site back in state
08363:                    String id = site.getId();
08364:
08365:                    try {
08366:                        SiteService.save(site);
08367:                    } catch (IdUnusedException e) {
08368:                        // TODO:
08369:                    } catch (PermissionException e) {
08370:                        // TODO:
08371:                    }
08372:
08373:                    if (SiteService.allowUpdateSite(id)) {
08374:                        try {
08375:                            SiteService.getSite(id);
08376:                            state.setAttribute(STATE_SITE_INSTANCE_ID, id);
08377:                        } catch (IdUnusedException e) {
08378:                            M_log
08379:                                    .warn("SiteAction.commitSite IdUnusedException "
08380:                                            + siteInfo.getTitle()
08381:                                            + "("
08382:                                            + id
08383:                                            + ") not found");
08384:                        }
08385:                    }
08386:
08387:                    // no permission
08388:                    else {
08389:                        addAlert(state, rb.getString("java.makechanges"));
08390:                        M_log.warn("SiteAction.commitSite PermissionException "
08391:                                + siteInfo.getTitle() + "(" + id + ")");
08392:                    }
08393:                }
08394:
08395:            } // updateSiteAttributes
08396:
08397:            /**
08398:             * %%% legacy properties, to be removed
08399:             */
08400:            private void updateSiteInfo(ParameterParser params,
08401:                    SessionState state) {
08402:                SiteInfo siteInfo = new SiteInfo();
08403:                if (state.getAttribute(STATE_SITE_INFO) != null) {
08404:                    siteInfo = (SiteInfo) state.getAttribute(STATE_SITE_INFO);
08405:                }
08406:                siteInfo.site_type = (String) state
08407:                        .getAttribute(STATE_SITE_TYPE);
08408:
08409:                if (params.getString("title") != null) {
08410:                    siteInfo.title = params.getString("title");
08411:                }
08412:                if (params.getString("description") != null) {
08413:                    siteInfo.description = params.getString("description");
08414:                }
08415:                if (params.getString("short_description") != null) {
08416:                    siteInfo.short_description = params
08417:                            .getString("short_description");
08418:                }
08419:                if (params.getString("additional") != null) {
08420:                    siteInfo.additional = params.getString("additional");
08421:                }
08422:                if (params.getString("iconUrl") != null) {
08423:                    siteInfo.iconUrl = params.getString("iconUrl");
08424:                } else {
08425:                    siteInfo.iconUrl = params.getString("skin");
08426:                }
08427:                if (params.getString("joinerRole") != null) {
08428:                    siteInfo.joinerRole = params.getString("joinerRole");
08429:                }
08430:                if (params.getString("joinable") != null) {
08431:                    boolean joinable = params.getBoolean("joinable");
08432:                    siteInfo.joinable = joinable;
08433:                    if (!joinable)
08434:                        siteInfo.joinerRole = NULL_STRING;
08435:                }
08436:                if (params.getString("itemStatus") != null) {
08437:                    siteInfo.published = Boolean.valueOf(
08438:                            params.getString("itemStatus")).booleanValue();
08439:                }
08440:
08441:                // site contact information
08442:                String name = StringUtil.trimToZero(params
08443:                        .getString("siteContactName"));
08444:                siteInfo.site_contact_name = name;
08445:                String email = StringUtil.trimToZero(params
08446:                        .getString("siteContactEmail"));
08447:                if (email != null) {
08448:                    String[] parts = email.split("@");
08449:
08450:                    if (email.length() > 0
08451:                            && (email.indexOf("@") == -1 || parts.length != 2
08452:                                    || parts[0].length() == 0 || !Validator
08453:                                    .checkEmailLocal(parts[0]))) {
08454:                        // invalid email
08455:                        addAlert(state, email + " "
08456:                                + rb.getString("java.invalid")
08457:                                + rb.getString("java.theemail"));
08458:                    }
08459:                    siteInfo.site_contact_email = email;
08460:                }
08461:                state.setAttribute(STATE_SITE_INFO, siteInfo);
08462:
08463:            } // updateSiteInfo
08464:
08465:            /**
08466:             * getExternalRealmId
08467:             * 
08468:             */
08469:            private String getExternalRealmId(SessionState state) {
08470:                String realmId = SiteService.siteReference((String) state
08471:                        .getAttribute(STATE_SITE_INSTANCE_ID));
08472:                String rv = null;
08473:                try {
08474:                    AuthzGroup realm = AuthzGroupService.getAuthzGroup(realmId);
08475:                    rv = realm.getProviderGroupId();
08476:                } catch (GroupNotDefinedException e) {
08477:                    M_log
08478:                            .warn("SiteAction.getExternalRealmId, site realm not found");
08479:                }
08480:                return rv;
08481:
08482:            } // getExternalRealmId
08483:
08484:            /**
08485:             * getParticipantList
08486:             * 
08487:             */
08488:            private List getParticipantList(SessionState state) {
08489:                List members = new Vector();
08490:                List participants = new Vector();
08491:                String realmId = SiteService.siteReference((String) state
08492:                        .getAttribute(STATE_SITE_INSTANCE_ID));
08493:
08494:                List providerCourseList = null;
08495:                providerCourseList = getProviderCourseList(StringUtil
08496:                        .trimToNull(getExternalRealmId(state)));
08497:                if (providerCourseList != null && providerCourseList.size() > 0) {
08498:                    state.setAttribute(SITE_PROVIDER_COURSE_LIST,
08499:                            providerCourseList);
08500:                }
08501:
08502:                participants = prepareParticipants(realmId, providerCourseList);
08503:                state.setAttribute(STATE_PARTICIPANT_LIST, participants);
08504:
08505:                return participants;
08506:
08507:            } // getParticipantList
08508:
08509:            private Vector prepareParticipants(String realmId,
08510:                    List providerCourseList) {
08511:                Vector participants = new Vector();
08512:                try {
08513:                    AuthzGroup realm = AuthzGroupService.getAuthzGroup(realmId);
08514:                    Set grants = realm.getMembers();
08515:                    // Collections.sort(users);
08516:                    for (Iterator i = grants.iterator(); i.hasNext();) {
08517:                        Member g = (Member) i.next();
08518:                        String userString = g.getUserEid();
08519:                        Role r = g.getRole();
08520:                        try {
08521:                            User user = UserDirectoryService
08522:                                    .getUserByEid(userString);
08523:                            Participant participant = new Participant();
08524:                            participant.name = user.getSortName();
08525:                            participant.uniqname = user.getId();
08526:                            if (r != null) {
08527:                                participant.role = r.getId();
08528:                            }
08529:                            if (g.isProvided()) {
08530:                                // official member, can't delete
08531:                                participant.removeable = false;
08532:                            } else {
08533:                                participant.removeable = true;
08534:                            }
08535:                            participants.add(participant);
08536:                        } catch (UserNotDefinedException e) {
08537:                            // deal with missing user quietly without throwing a
08538:                            // warning message
08539:                        }
08540:                    }
08541:
08542:                } catch (GroupNotDefinedException e) {
08543:                    M_log.warn(this  + "  IdUnusedException " + realmId);
08544:                }
08545:                return participants;
08546:            }
08547:
08548:            /**
08549:             * getRoles
08550:             * 
08551:             */
08552:            private List getRoles(SessionState state) {
08553:                List roles = new Vector();
08554:                String realmId = SiteService.siteReference((String) state
08555:                        .getAttribute(STATE_SITE_INSTANCE_ID));
08556:                try {
08557:                    AuthzGroup realm = AuthzGroupService.getAuthzGroup(realmId);
08558:                    roles.addAll(realm.getRoles());
08559:                    Collections.sort(roles);
08560:                } catch (GroupNotDefinedException e) {
08561:                    M_log.warn("SiteAction.getRoles IdUnusedException "
08562:                            + realmId);
08563:                }
08564:                return roles;
08565:
08566:            } // getRoles
08567:
08568:            private void addSynopticTool(SitePage page, String toolId,
08569:                    String toolTitle, String layoutHint) {
08570:                // Add synoptic announcements tool
08571:                ToolConfiguration tool = page.addTool();
08572:                Tool reg = ToolManager.getTool(toolId);
08573:                tool.setTool(toolId, reg);
08574:                tool.setTitle(toolTitle);
08575:                tool.setLayoutHints(layoutHint);
08576:            }
08577:
08578:            private void getRevisedFeatures(ParameterParser params,
08579:                    SessionState state) {
08580:                Site site = getStateSite(state);
08581:                // get the list of Worksite Setup configured pages
08582:                List wSetupPageList = (List) state
08583:                        .getAttribute(STATE_WORKSITE_SETUP_PAGE_LIST);
08584:
08585:                WorksiteSetupPage wSetupPage = new WorksiteSetupPage();
08586:                WorksiteSetupPage wSetupHome = new WorksiteSetupPage();
08587:                List pageList = new Vector();
08588:
08589:                // declare some flags used in making decisions about Home, whether to
08590:                // add, remove, or do nothing
08591:                boolean homeInChosenList = false;
08592:                boolean homeInWSetupPageList = false;
08593:
08594:                List chosenList = (List) state
08595:                        .getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST);
08596:                // if features were selected, diff wSetupPageList and chosenList to get
08597:                // page adds and removes
08598:                // boolean values for adding synoptic views
08599:                boolean hasAnnouncement = false;
08600:                boolean hasSchedule = false;
08601:                boolean hasChat = false;
08602:                boolean hasDiscussion = false;
08603:                boolean hasEmail = false;
08604:                boolean hasNewSiteInfo = false;
08605:
08606:                // Special case - Worksite Setup Home comes from a hardcoded checkbox on
08607:                // the vm template rather than toolRegistrationList
08608:                // see if Home was chosen
08609:                for (ListIterator j = chosenList.listIterator(); j.hasNext();) {
08610:                    String choice = (String) j.next();
08611:                    if (choice.equalsIgnoreCase(HOME_TOOL_ID)) {
08612:                        homeInChosenList = true;
08613:                    } else if (choice.equals("sakai.mailbox")) {
08614:                        hasEmail = true;
08615:                        String alias = StringUtil.trimToNull((String) state
08616:                                .getAttribute(STATE_TOOL_EMAIL_ADDRESS));
08617:                        if (alias != null) {
08618:                            if (!Validator.checkEmailLocal(alias)) {
08619:                                addAlert(state, rb.getString("java.theemail"));
08620:                            } else {
08621:                                try {
08622:                                    String channelReference = mailArchiveChannelReference(site
08623:                                            .getId());
08624:                                    // first, clear any alias set to this channel
08625:                                    AliasService
08626:                                            .removeTargetAliases(channelReference); // check
08627:                                    // to
08628:                                    // see
08629:                                    // whether
08630:                                    // the
08631:                                    // alias
08632:                                    // has
08633:                                    // been
08634:                                    // used
08635:                                    try {
08636:                                        String target = AliasService
08637:                                                .getTarget(alias);
08638:                                        if (target != null) {
08639:                                            addAlert(
08640:                                                    state,
08641:                                                    rb
08642:                                                            .getString("java.emailinuse")
08643:                                                            + " ");
08644:                                        }
08645:                                    } catch (IdUnusedException ee) {
08646:                                        try {
08647:                                            AliasService.setAlias(alias,
08648:                                                    channelReference);
08649:                                        } catch (IdUsedException exception) {
08650:                                        } catch (IdInvalidException exception) {
08651:                                        } catch (PermissionException exception) {
08652:                                        }
08653:                                    }
08654:                                } catch (PermissionException exception) {
08655:                                }
08656:                            }
08657:                        }
08658:                    } else if (choice.equals("sakai.announcements")) {
08659:                        hasAnnouncement = true;
08660:                    } else if (choice.equals("sakai.schedule")) {
08661:                        hasSchedule = true;
08662:                    } else if (choice.equals("sakai.chat")) {
08663:                        hasChat = true;
08664:                    } else if (choice.equals("sakai.discussion")) {
08665:                        hasDiscussion = true;
08666:                    }
08667:                }
08668:
08669:                // see if Home and/or Help in the wSetupPageList (can just check title
08670:                // here, because we checked patterns before adding to the list)
08671:                for (ListIterator i = wSetupPageList.listIterator(); i
08672:                        .hasNext();) {
08673:                    wSetupPage = (WorksiteSetupPage) i.next();
08674:                    if (wSetupPage.getToolId().equals(HOME_TOOL_ID)) {
08675:                        homeInWSetupPageList = true;
08676:                    }
08677:                }
08678:
08679:                if (homeInChosenList) {
08680:                    SitePage page = null;
08681:                    // Were the synoptic views of Announcement, Discussioin, Chat
08682:                    // existing before the editing
08683:                    boolean hadAnnouncement = false, hadDiscussion = false, hadChat = false, hadSchedule = false;
08684:
08685:                    if (homeInWSetupPageList) {
08686:                        if (!SiteService.isUserSite(site.getId())) {
08687:                            // for non-myworkspace site, if Home is chosen and Home is
08688:                            // in the wSetupPageList, remove synoptic tools
08689:                            WorksiteSetupPage homePage = new WorksiteSetupPage();
08690:                            for (ListIterator i = wSetupPageList.listIterator(); i
08691:                                    .hasNext();) {
08692:                                WorksiteSetupPage comparePage = (WorksiteSetupPage) i
08693:                                        .next();
08694:                                if ((comparePage.getToolId())
08695:                                        .equals(HOME_TOOL_ID)) {
08696:                                    homePage = comparePage;
08697:                                }
08698:                            }
08699:                            page = site.getPage(homePage.getPageId());
08700:                            List toolList = page.getTools();
08701:                            List removeToolList = new Vector();
08702:                            // get those synoptic tools
08703:                            for (ListIterator iToolList = toolList
08704:                                    .listIterator(); iToolList.hasNext();) {
08705:                                ToolConfiguration tool = (ToolConfiguration) iToolList
08706:                                        .next();
08707:                                if (tool.getTool().getId().equals(
08708:                                        "sakai.synoptic.announcement")) {
08709:                                    hadAnnouncement = true;
08710:                                    if (!hasAnnouncement) {
08711:                                        removeToolList.add(tool);// if Announcement
08712:                                        // tool isn't
08713:                                        // selected, remove
08714:                                        // the synotic
08715:                                        // Announcement
08716:                                    }
08717:                                }
08718:                                if (tool.getTool().getId().equals(
08719:                                        "sakai.summary.calendar")) {
08720:                                    hadSchedule = true;
08721:                                    if (!hasSchedule) {
08722:                                        removeToolList.add(tool);// if Schedule
08723:                                        // tool isn't
08724:                                        // selected, remove
08725:                                        // the synotic
08726:                                        // Schedule
08727:                                    }
08728:                                }
08729:                                if (tool.getTool().getId().equals(
08730:                                        "sakai.synoptic.discussion")) {
08731:                                    hadDiscussion = true;
08732:                                    if (!hasDiscussion) {
08733:                                        removeToolList.add(tool);// if Discussion
08734:                                        // tool isn't
08735:                                        // selected, remove
08736:                                        // the synoptic
08737:                                        // Discussion
08738:                                    }
08739:                                }
08740:                                if (tool.getTool().getId().equals(
08741:                                        "sakai.synoptic.chat")) {
08742:                                    hadChat = true;
08743:                                    if (!hasChat) {
08744:                                        removeToolList.add(tool);// if Chat tool
08745:                                        // isn't selected,
08746:                                        // remove the
08747:                                        // synoptic Chat
08748:                                    }
08749:                                }
08750:                            }
08751:                            // remove those synoptic tools
08752:                            for (ListIterator rToolList = removeToolList
08753:                                    .listIterator(); rToolList.hasNext();) {
08754:                                page.removeTool((ToolConfiguration) rToolList
08755:                                        .next());
08756:                            }
08757:                        }
08758:                    } else {
08759:                        // if Home is chosen and Home is not in wSetupPageList, add Home
08760:                        // to site and wSetupPageList
08761:                        page = site.addPage();
08762:
08763:                        page.setTitle(rb.getString("java.home"));
08764:
08765:                        wSetupHome.pageId = page.getId();
08766:                        wSetupHome.pageTitle = page.getTitle();
08767:                        wSetupHome.toolId = HOME_TOOL_ID;
08768:                        wSetupPageList.add(wSetupHome);
08769:
08770:                        // Add worksite information tool
08771:                        ToolConfiguration tool = page.addTool();
08772:                        Tool reg = ToolManager.getTool("sakai.iframe.site");
08773:                        tool.setTool("sakai.iframe.site", reg);
08774:                        tool.setTitle(rb.getString("java.workinfo"));
08775:                        tool.setLayoutHints("0,0");
08776:                    }
08777:
08778:                    if (!SiteService.isUserSite(site.getId())) {
08779:                        // add synoptical tools to home tool in non-myworkspace site
08780:                        try {
08781:                            if (hasAnnouncement && !hadAnnouncement) {
08782:                                // Add synoptic announcements tool
08783:                                addSynopticTool(page,
08784:                                        "sakai.synoptic.announcement", rb
08785:                                                .getString("java.recann"),
08786:                                        "0,1");
08787:                            }
08788:                            if (hasDiscussion && !hadDiscussion) {
08789:                                // Add synoptic discussion tool
08790:                                addSynopticTool(page,
08791:                                        "sakai.synoptic.discussion", rb
08792:                                                .getString("java.recdisc"),
08793:                                        "1,1");
08794:                            }
08795:                            if (hasChat && !hadChat) {
08796:                                // Add synoptic chat tool
08797:                                addSynopticTool(page, "sakai.synoptic.chat", rb
08798:                                        .getString("java.recent"), "2,1");
08799:                            }
08800:                            if (hasSchedule && !hadSchedule) {
08801:                                // Add synoptic schedule tool
08802:                                addSynopticTool(page, "sakai.summary.calendar",
08803:                                        rb.getString("java.reccal"), "3,1");
08804:                            }
08805:                            if (hasAnnouncement || hasDiscussion || hasChat
08806:                                    || hasSchedule) {
08807:                                page.setLayout(SitePage.LAYOUT_DOUBLE_COL);
08808:                            } else {
08809:                                page.setLayout(SitePage.LAYOUT_SINGLE_COL);
08810:                            }
08811:
08812:                        } catch (Exception e) {
08813:                            M_log.warn("SiteAction.getFeatures Exception "
08814:                                    + e.getMessage());
08815:                        }
08816:                    }
08817:                } // add Home
08818:
08819:                // if Home is in wSetupPageList and not chosen, remove Home feature from
08820:                // wSetupPageList and site
08821:                if (!homeInChosenList && homeInWSetupPageList) {
08822:                    // remove Home from wSetupPageList
08823:                    WorksiteSetupPage removePage = new WorksiteSetupPage();
08824:                    for (ListIterator i = wSetupPageList.listIterator(); i
08825:                            .hasNext();) {
08826:                        WorksiteSetupPage comparePage = (WorksiteSetupPage) i
08827:                                .next();
08828:                        if (comparePage.getToolId().equals(HOME_TOOL_ID)) {
08829:                            removePage = comparePage;
08830:                        }
08831:                    }
08832:                    SitePage siteHome = site.getPage(removePage.getPageId());
08833:                    site.removePage(siteHome);
08834:                    wSetupPageList.remove(removePage);
08835:
08836:                }
08837:
08838:                // declare flags used in making decisions about whether to add, remove,
08839:                // or do nothing
08840:                boolean inChosenList;
08841:                boolean inWSetupPageList;
08842:
08843:                Hashtable newsTitles = (Hashtable) state
08844:                        .getAttribute(STATE_NEWS_TITLES);
08845:                Hashtable wcTitles = (Hashtable) state
08846:                        .getAttribute(STATE_WEB_CONTENT_TITLES);
08847:                Hashtable newsUrls = (Hashtable) state
08848:                        .getAttribute(STATE_NEWS_URLS);
08849:                Hashtable wcUrls = (Hashtable) state
08850:                        .getAttribute(STATE_WEB_CONTENT_URLS);
08851:
08852:                Set categories = new HashSet();
08853:                categories.add((String) state.getAttribute(STATE_SITE_TYPE));
08854:                Set toolRegistrationList = ToolManager.findTools(categories,
08855:                        null);
08856:
08857:                // first looking for any tool for removal
08858:                Vector removePageIds = new Vector();
08859:                for (ListIterator k = wSetupPageList.listIterator(); k
08860:                        .hasNext();) {
08861:                    wSetupPage = (WorksiteSetupPage) k.next();
08862:                    String pageToolId = wSetupPage.getToolId();
08863:
08864:                    // use page id + tool id for multiple News and Web Content tool
08865:                    if (pageToolId.indexOf("sakai.news") != -1
08866:                            || pageToolId.indexOf("sakai.iframe") != -1) {
08867:                        pageToolId = wSetupPage.getPageId() + pageToolId;
08868:                    }
08869:
08870:                    inChosenList = false;
08871:
08872:                    for (ListIterator j = chosenList.listIterator(); j
08873:                            .hasNext();) {
08874:                        String toolId = (String) j.next();
08875:                        if (pageToolId.equals(toolId)) {
08876:                            inChosenList = true;
08877:                        }
08878:                    }
08879:
08880:                    if (!inChosenList) {
08881:                        removePageIds.add(wSetupPage.getPageId());
08882:                    }
08883:                }
08884:                for (int i = 0; i < removePageIds.size(); i++) {
08885:                    // if the tool exists in the wSetupPageList, remove it from the site
08886:                    String removeId = (String) removePageIds.get(i);
08887:                    SitePage sitePage = site.getPage(removeId);
08888:                    site.removePage(sitePage);
08889:
08890:                    // and remove it from wSetupPageList
08891:                    for (ListIterator k = wSetupPageList.listIterator(); k
08892:                            .hasNext();) {
08893:                        wSetupPage = (WorksiteSetupPage) k.next();
08894:                        if (!wSetupPage.getPageId().equals(removeId)) {
08895:                            wSetupPage = null;
08896:                        }
08897:                    }
08898:                    if (wSetupPage != null) {
08899:                        wSetupPageList.remove(wSetupPage);
08900:                    }
08901:                }
08902:
08903:                // then looking for any tool to add
08904:                for (ListIterator j = orderToolIds(state,
08905:                        (String) state.getAttribute(STATE_SITE_TYPE),
08906:                        chosenList).listIterator(); j.hasNext();) {
08907:                    String toolId = (String) j.next();
08908:                    // Is the tool in the wSetupPageList?
08909:                    inWSetupPageList = false;
08910:                    for (ListIterator k = wSetupPageList.listIterator(); k
08911:                            .hasNext();) {
08912:                        wSetupPage = (WorksiteSetupPage) k.next();
08913:                        String pageToolId = wSetupPage.getToolId();
08914:
08915:                        // use page Id + toolId for multiple News and Web Content tool
08916:                        if (pageToolId.indexOf("sakai.news") != -1
08917:                                || pageToolId.indexOf("sakai.iframe") != -1) {
08918:                            pageToolId = wSetupPage.getPageId() + pageToolId;
08919:                        }
08920:
08921:                        if (pageToolId.equals(toolId)) {
08922:                            inWSetupPageList = true;
08923:                            // but for News and Web Content tool, need to change the
08924:                            // title
08925:                            if (toolId.indexOf("sakai.news") != -1) {
08926:                                SitePage pEdit = (SitePage) site
08927:                                        .getPage(wSetupPage.pageId);
08928:                                pEdit.setTitle((String) newsTitles.get(toolId));
08929:                                List toolList = pEdit.getTools();
08930:                                for (ListIterator jTool = toolList
08931:                                        .listIterator(); jTool.hasNext();) {
08932:                                    ToolConfiguration tool = (ToolConfiguration) jTool
08933:                                            .next();
08934:                                    if (tool.getTool().getId().equals(
08935:                                            "sakai.news")) {
08936:                                        // set News tool title
08937:                                        tool.setTitle((String) newsTitles
08938:                                                .get(toolId));
08939:
08940:                                        // set News tool url
08941:                                        String urlString = (String) newsUrls
08942:                                                .get(toolId);
08943:                                        try {
08944:                                            URL url = new URL(urlString);
08945:                                            // update the tool config
08946:                                            tool
08947:                                                    .getPlacementConfig()
08948:                                                    .setProperty(
08949:                                                            "channel-url",
08950:                                                            (String) url
08951:                                                                    .toExternalForm());
08952:                                        } catch (MalformedURLException e) {
08953:                                            addAlert(state, rb
08954:                                                    .getString("java.invurl")
08955:                                                    + " " + urlString + ". ");
08956:                                        }
08957:                                    }
08958:                                }
08959:                            } else if (toolId.indexOf("sakai.iframe") != -1) {
08960:                                SitePage pEdit = (SitePage) site
08961:                                        .getPage(wSetupPage.pageId);
08962:                                pEdit.setTitle((String) wcTitles.get(toolId));
08963:
08964:                                List toolList = pEdit.getTools();
08965:                                for (ListIterator jTool = toolList
08966:                                        .listIterator(); jTool.hasNext();) {
08967:                                    ToolConfiguration tool = (ToolConfiguration) jTool
08968:                                            .next();
08969:                                    if (tool.getTool().getId().equals(
08970:                                            "sakai.iframe")) {
08971:                                        // set Web Content tool title
08972:                                        tool.setTitle((String) wcTitles
08973:                                                .get(toolId));
08974:                                        // set Web Content tool url
08975:                                        String wcUrl = StringUtil
08976:                                                .trimToNull((String) wcUrls
08977:                                                        .get(toolId));
08978:                                        if (wcUrl != null
08979:                                                && !wcUrl
08980:                                                        .equals(WEB_CONTENT_DEFAULT_URL)) {
08981:                                            // if url is not empty and not consists only
08982:                                            // of "http://"
08983:                                            tool.getPlacementConfig()
08984:                                                    .setProperty("source",
08985:                                                            wcUrl);
08986:                                        }
08987:                                    }
08988:                                }
08989:                            }
08990:                        }
08991:                    }
08992:                    if (inWSetupPageList) {
08993:                        // if the tool already in the list, do nothing so to save the
08994:                        // option settings
08995:                    } else {
08996:                        // if in chosen list but not in wSetupPageList, add it to the
08997:                        // site (one tool on a page)
08998:
08999:                        // if Site Info tool is being newly added
09000:                        if (toolId.equals("sakai.siteinfo")) {
09001:                            hasNewSiteInfo = true;
09002:                        }
09003:
09004:                        Tool toolRegFound = null;
09005:                        for (Iterator i = toolRegistrationList.iterator(); i
09006:                                .hasNext();) {
09007:                            Tool toolReg = (Tool) i.next();
09008:                            if ((toolId.indexOf("assignment") != -1 && toolId
09009:                                    .equals(toolReg.getId()))
09010:                                    || (toolId.indexOf("assignment") == -1 && toolId
09011:                                            .indexOf(toolReg.getId()) != -1)) {
09012:                                toolRegFound = toolReg;
09013:                            }
09014:                        }
09015:
09016:                        if (toolRegFound != null) {
09017:                            // we know such a tool, so add it
09018:                            WorksiteSetupPage addPage = new WorksiteSetupPage();
09019:                            SitePage page = site.addPage();
09020:                            addPage.pageId = page.getId();
09021:                            if (toolId.indexOf("sakai.news") != -1) {
09022:                                // set News tool title
09023:                                page.setTitle((String) newsTitles.get(toolId));
09024:                            } else if (toolId.indexOf("sakai.iframe") != -1) {
09025:                                // set Web Content tool title
09026:                                page.setTitle((String) wcTitles.get(toolId));
09027:                            } else {
09028:                                // other tools with default title
09029:                                page.setTitle(toolRegFound.getTitle());
09030:                            }
09031:                            page.setLayout(SitePage.LAYOUT_SINGLE_COL);
09032:                            ToolConfiguration tool = page.addTool();
09033:                            tool.setTool(toolRegFound.getId(), toolRegFound);
09034:                            addPage.toolId = toolId;
09035:                            wSetupPageList.add(addPage);
09036:
09037:                            // set tool title
09038:                            if (toolId.indexOf("sakai.news") != -1) {
09039:                                // set News tool title
09040:                                tool.setTitle((String) newsTitles.get(toolId));
09041:
09042:                                // set News tool url
09043:                                String urlString = (String) newsUrls
09044:                                        .get(toolId);
09045:                                try {
09046:                                    URL url = new URL(urlString);
09047:                                    // update the tool config
09048:                                    tool.getPlacementConfig().setProperty(
09049:                                            "channel-url",
09050:                                            (String) url.toExternalForm());
09051:                                } catch (MalformedURLException e) {
09052:                                    // display message
09053:                                    addAlert(state, "Invalid URL " + urlString
09054:                                            + ". ");
09055:
09056:                                    // remove the page because of invalid url
09057:                                    site.removePage(page);
09058:                                }
09059:                            } else if (toolId.indexOf("sakai.iframe") != -1) {
09060:                                // set Web Content tool title
09061:                                tool.setTitle((String) wcTitles.get(toolId));
09062:                                // set Web Content tool url
09063:                                String wcUrl = StringUtil
09064:                                        .trimToNull((String) wcUrls.get(toolId));
09065:                                if (wcUrl != null
09066:                                        && !wcUrl
09067:                                                .equals(WEB_CONTENT_DEFAULT_URL)) {
09068:                                    // if url is not empty and not consists only of
09069:                                    // "http://"
09070:                                    tool.getPlacementConfig().setProperty(
09071:                                            "source", wcUrl);
09072:                                }
09073:                            } else {
09074:                                tool.setTitle(toolRegFound.getTitle());
09075:                            }
09076:                        }
09077:                    }
09078:                } // for
09079:
09080:                if (homeInChosenList) {
09081:                    // Order tools - move Home to the top - first find it
09082:                    SitePage homePage = null;
09083:                    pageList = site.getPages();
09084:                    if (pageList != null && pageList.size() != 0) {
09085:                        for (ListIterator i = pageList.listIterator(); i
09086:                                .hasNext();) {
09087:                            SitePage page = (SitePage) i.next();
09088:                            if (rb.getString("java.home").equals(
09089:                                    page.getTitle()))// if
09090:                            // ("Home".equals(page.getTitle()))
09091:                            {
09092:                                homePage = page;
09093:                                break;
09094:                            }
09095:                        }
09096:                    }
09097:
09098:                    // if found, move it
09099:                    if (homePage != null) {
09100:                        // move home from it's index to the first position
09101:                        int homePosition = pageList.indexOf(homePage);
09102:                        for (int n = 0; n < homePosition; n++) {
09103:                            homePage.moveUp();
09104:                        }
09105:                    }
09106:                }
09107:
09108:                // if Site Info is newly added, more it to the last
09109:                if (hasNewSiteInfo) {
09110:                    SitePage siteInfoPage = null;
09111:                    pageList = site.getPages();
09112:                    String[] toolIds = { "sakai.siteinfo" };
09113:                    if (pageList != null && pageList.size() != 0) {
09114:                        for (ListIterator i = pageList.listIterator(); siteInfoPage == null
09115:                                && i.hasNext();) {
09116:                            SitePage page = (SitePage) i.next();
09117:                            int s = page.getTools(toolIds).size();
09118:                            if (s > 0) {
09119:                                siteInfoPage = page;
09120:                            }
09121:                        }
09122:                    }
09123:
09124:                    // if found, move it
09125:                    if (siteInfoPage != null) {
09126:                        // move home from it's index to the first position
09127:                        int siteInfoPosition = pageList.indexOf(siteInfoPage);
09128:                        for (int n = siteInfoPosition; n < pageList.size(); n++) {
09129:                            siteInfoPage.moveDown();
09130:                        }
09131:                    }
09132:                }
09133:
09134:                // if there is no email tool chosen
09135:                if (!hasEmail) {
09136:                    state.removeAttribute(STATE_TOOL_EMAIL_ADDRESS);
09137:                }
09138:
09139:                // commit
09140:                commitSite(site);
09141:
09142:            } // getRevisedFeatures
09143:
09144:            /**
09145:             * getFeatures gets features for a new site
09146:             * 
09147:             */
09148:            private void getFeatures(ParameterParser params, SessionState state) {
09149:                List idsSelected = new Vector();
09150:
09151:                boolean goToENWPage = false;
09152:                boolean homeSelected = false;
09153:
09154:                // Add new pages and tools, if any
09155:                if (params.getStrings("selectedTools") == null) {
09156:                    addAlert(state, rb.getString("atleastonetool"));
09157:                } else {
09158:                    List l = new ArrayList(Arrays.asList(params
09159:                            .getStrings("selectedTools"))); // toolId's & titles of
09160:                    // chosen tools
09161:                    for (int i = 0; i < l.size(); i++) {
09162:                        String toolId = (String) l.get(i);
09163:
09164:                        if (toolId.equals("sakai.mailbox")
09165:                                || toolId.indexOf("sakai.news") != -1
09166:                                || toolId.indexOf("sakai.iframe") != -1) {
09167:                            goToENWPage = true;
09168:                        } else if (toolId.equals(HOME_TOOL_ID)) {
09169:                            homeSelected = true;
09170:                        }
09171:                        idsSelected.add(toolId);
09172:                    }
09173:                    state.setAttribute(STATE_TOOL_HOME_SELECTED, new Boolean(
09174:                            homeSelected));
09175:                }
09176:
09177:                String importString = params.getString("import");
09178:                if (importString != null
09179:                        && importString.equalsIgnoreCase(Boolean.TRUE
09180:                                .toString())) {
09181:                    state.setAttribute(STATE_IMPORT, Boolean.TRUE);
09182:
09183:                    List importSites = new Vector();
09184:                    if (params.getStrings("importSites") != null) {
09185:                        importSites = new ArrayList(Arrays.asList(params
09186:                                .getStrings("importSites")));
09187:                    }
09188:                    if (importSites.size() == 0) {
09189:                        addAlert(state, rb.getString("java.toimport") + " ");
09190:                    } else {
09191:                        Hashtable sites = new Hashtable();
09192:                        for (int index = 0; index < importSites.size(); index++) {
09193:                            try {
09194:                                Site s = SiteService
09195:                                        .getSite((String) importSites
09196:                                                .get(index));
09197:                                if (!sites.containsKey(s)) {
09198:                                    sites.put(s, new Vector());
09199:                                }
09200:                            } catch (IdUnusedException e) {
09201:                            }
09202:                        }
09203:                        state.setAttribute(STATE_IMPORT_SITES, sites);
09204:                    }
09205:                } else {
09206:                    state.removeAttribute(STATE_IMPORT);
09207:                }
09208:
09209:                state.setAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST,
09210:                        idsSelected); // List
09211:                // of
09212:                // ToolRegistration
09213:                // toolId's
09214:                if (state.getAttribute(STATE_MESSAGE) == null) {
09215:                    if (state.getAttribute(STATE_IMPORT) != null) {
09216:                        // go to import tool page
09217:                        state.setAttribute(STATE_TEMPLATE_INDEX, "27");
09218:                    } else if (goToENWPage) {
09219:                        // go to the configuration page for Email Archive, News and Web
09220:                        // Content tools
09221:                        state.setAttribute(STATE_TEMPLATE_INDEX, "26");
09222:                    } else {
09223:                        // go to edit access page
09224:                        state.setAttribute(STATE_TEMPLATE_INDEX, "18");
09225:                    }
09226:
09227:                    int totalSteps = 4;
09228:                    if (state.getAttribute(STATE_SITE_TYPE) != null
09229:                            && ((String) state.getAttribute(STATE_SITE_TYPE))
09230:                                    .equalsIgnoreCase("course")) {
09231:                        totalSteps = 5;
09232:                        if (state.getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN) != null
09233:                                && state
09234:                                        .getAttribute(STATE_MANUAL_ADD_COURSE_NUMBER) != null) {
09235:                            totalSteps++;
09236:                        }
09237:                    }
09238:                    if (state.getAttribute(STATE_IMPORT) != null) {
09239:                        totalSteps++;
09240:                    }
09241:                    if (goToENWPage) {
09242:                        totalSteps++;
09243:                    }
09244:                    state.setAttribute(SITE_CREATE_TOTAL_STEPS, new Integer(
09245:                            totalSteps));
09246:                }
09247:            } // getFeatures
09248:
09249:            /**
09250:             * addFeatures adds features to a new site
09251:             * 
09252:             */
09253:            private void addFeatures(SessionState state) {
09254:                List toolRegistrationList = (Vector) state
09255:                        .getAttribute(STATE_TOOL_REGISTRATION_LIST);
09256:                Site site = getStateSite(state);
09257:
09258:                List pageList = new Vector();
09259:                int moves = 0;
09260:                boolean hasHome = false;
09261:                boolean hasAnnouncement = false;
09262:                boolean hasSchedule = false;
09263:                boolean hasChat = false;
09264:                boolean hasDiscussion = false;
09265:                boolean hasSiteInfo = false;
09266:
09267:                List chosenList = (List) state
09268:                        .getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST);
09269:
09270:                // tools to be imported from other sites?
09271:                Hashtable importTools = null;
09272:                if (state.getAttribute(STATE_IMPORT_SITE_TOOL) != null) {
09273:                    importTools = (Hashtable) state
09274:                            .getAttribute(STATE_IMPORT_SITE_TOOL);
09275:                }
09276:
09277:                // for tools other than home
09278:                if (chosenList.contains(HOME_TOOL_ID)) {
09279:                    // add home tool later
09280:                    hasHome = true;
09281:                }
09282:
09283:                // order the id list
09284:                chosenList = orderToolIds(state, site.getType(), chosenList);
09285:
09286:                // titles for news tools
09287:                Hashtable newsTitles = (Hashtable) state
09288:                        .getAttribute(STATE_NEWS_TITLES);
09289:                // urls for news tools
09290:                Hashtable newsUrls = (Hashtable) state
09291:                        .getAttribute(STATE_NEWS_URLS);
09292:                // titles for web content tools
09293:                Hashtable wcTitles = (Hashtable) state
09294:                        .getAttribute(STATE_WEB_CONTENT_TITLES);
09295:                // urls for web content tools
09296:                Hashtable wcUrls = (Hashtable) state
09297:                        .getAttribute(STATE_WEB_CONTENT_URLS);
09298:
09299:                if (chosenList.size() > 0) {
09300:                    Tool toolRegFound = null;
09301:                    for (ListIterator i = chosenList.listIterator(); i
09302:                            .hasNext();) {
09303:                        String toolId = (String) i.next();
09304:
09305:                        // find the tool in the tool registration list
09306:                        toolRegFound = null;
09307:                        for (int j = 0; j < toolRegistrationList.size()
09308:                                && toolRegFound == null; j++) {
09309:                            MyTool tool = (MyTool) toolRegistrationList.get(j);
09310:                            if ((toolId.indexOf("assignment") != -1 && toolId
09311:                                    .equals(tool.getId()))
09312:                                    || (toolId.indexOf("assignment") == -1 && toolId
09313:                                            .indexOf(tool.getId()) != -1)) {
09314:                                toolRegFound = ToolManager
09315:                                        .getTool(tool.getId());
09316:                            }
09317:                        }
09318:
09319:                        if (toolRegFound != null) {
09320:                            if (toolId.indexOf("sakai.news") != -1) {
09321:                                // adding multiple news tool
09322:                                String newsTitle = (String) newsTitles
09323:                                        .get(toolId);
09324:                                SitePage page = site.addPage();
09325:                                page.setTitle(newsTitle); // the visible label on the
09326:                                // tool menu
09327:                                page.setLayout(SitePage.LAYOUT_SINGLE_COL);
09328:                                ToolConfiguration tool = page.addTool();
09329:                                tool.setTool("sakai.news", ToolManager
09330:                                        .getTool("sakai.news"));
09331:                                tool.setTitle(newsTitle);
09332:                                tool.setLayoutHints("0,0");
09333:                                String urlString = (String) newsUrls
09334:                                        .get(toolId);
09335:                                // update the tool config
09336:                                tool.getPlacementConfig().setProperty(
09337:                                        "channel-url", urlString);
09338:                            } else if (toolId.indexOf("sakai.iframe") != -1) {
09339:                                // adding multiple web content tool
09340:                                String wcTitle = (String) wcTitles.get(toolId);
09341:                                SitePage page = site.addPage();
09342:                                page.setTitle(wcTitle); // the visible label on the tool
09343:                                // menu
09344:                                page.setLayout(SitePage.LAYOUT_SINGLE_COL);
09345:                                ToolConfiguration tool = page.addTool();
09346:                                tool.setTool("sakai.iframe", ToolManager
09347:                                        .getTool("sakai.iframe"));
09348:                                tool.setTitle(wcTitle);
09349:                                tool.setLayoutHints("0,0");
09350:                                String wcUrl = StringUtil
09351:                                        .trimToNull((String) wcUrls.get(toolId));
09352:                                if (wcUrl != null
09353:                                        && !wcUrl
09354:                                                .equals(WEB_CONTENT_DEFAULT_URL)) {
09355:                                    // if url is not empty and not consists only of
09356:                                    // "http://"
09357:                                    tool.getPlacementConfig().setProperty(
09358:                                            "source", wcUrl);
09359:                                }
09360:                            } else {
09361:                                SitePage page = site.addPage();
09362:                                page.setTitle(toolRegFound.getTitle()); // the visible
09363:                                // label on the
09364:                                // tool menu
09365:                                page.setLayout(SitePage.LAYOUT_SINGLE_COL);
09366:                                ToolConfiguration tool = page.addTool();
09367:                                tool
09368:                                        .setTool(toolRegFound.getId(),
09369:                                                toolRegFound);
09370:                                tool.setLayoutHints("0,0");
09371:
09372:                            } // Other features
09373:                        }
09374:
09375:                        // booleans for synoptic views
09376:                        if (toolId.equals("sakai.announcements")) {
09377:                            hasAnnouncement = true;
09378:                        } else if (toolId.equals("sakai.schedule")) {
09379:                            hasSchedule = true;
09380:                        } else if (toolId.equals("sakai.chat")) {
09381:                            hasChat = true;
09382:                        } else if (toolId.equals("sakai.discussion")) {
09383:                            hasDiscussion = true;
09384:                        } else if (toolId.equals("sakai.siteinfo")) {
09385:                            hasSiteInfo = true;
09386:                        }
09387:
09388:                    } // for
09389:
09390:                    // add home tool
09391:                    if (hasHome) {
09392:                        // Home is a special case, with several tools on the page.
09393:                        // "home" is hard coded in chef_site-addRemoveFeatures.vm.
09394:                        try {
09395:                            SitePage page = site.addPage();
09396:                            page.setTitle(rb.getString("java.home")); // the visible
09397:                            // label on the
09398:                            // tool menu
09399:                            if (hasAnnouncement || hasDiscussion || hasChat
09400:                                    || hasSchedule) {
09401:                                page.setLayout(SitePage.LAYOUT_DOUBLE_COL);
09402:                            } else {
09403:                                page.setLayout(SitePage.LAYOUT_SINGLE_COL);
09404:                            }
09405:
09406:                            // Add worksite information tool
09407:                            ToolConfiguration tool = page.addTool();
09408:                            tool.setTool("sakai.iframe.site", ToolManager
09409:                                    .getTool("sakai.iframe.site"));
09410:                            tool.setTitle(rb.getString("java.workinfo"));
09411:                            tool.setLayoutHints("0,0");
09412:
09413:                            if (hasAnnouncement) {
09414:                                // Add synoptic announcements tool
09415:                                tool = page.addTool();
09416:                                tool
09417:                                        .setTool(
09418:                                                "sakai.synoptic.announcement",
09419:                                                ToolManager
09420:                                                        .getTool("sakai.synoptic.announcement"));
09421:                                tool.setTitle(rb.getString("java.recann"));
09422:                                tool.setLayoutHints("0,1");
09423:                            }
09424:
09425:                            if (hasDiscussion) {
09426:                                // Add synoptic announcements tool
09427:                                tool = page.addTool();
09428:                                tool
09429:                                        .setTool(
09430:                                                "sakai.synoptic.discussion",
09431:                                                ToolManager
09432:                                                        .getTool("sakai.synoptic.discussion"));
09433:                                tool.setTitle("Recent Discussion Items");
09434:                                tool.setLayoutHints("1,1");
09435:                            }
09436:
09437:                            if (hasChat) {
09438:                                // Add synoptic chat tool
09439:                                tool = page.addTool();
09440:                                tool.setTool("sakai.synoptic.chat", ToolManager
09441:                                        .getTool("sakai.synoptic.chat"));
09442:                                tool.setTitle("Recent Chat Messages");
09443:                                tool.setLayoutHints("2,1");
09444:                            }
09445:
09446:                            if (hasSchedule) {
09447:                                // Add synoptic schedule tool
09448:                                tool = page.addTool();
09449:                                tool
09450:                                        .setTool(
09451:                                                "sakai.summary.calendar",
09452:                                                ToolManager
09453:                                                        .getTool("sakai.summary.calendar"));
09454:                                tool.setTitle(rb.getString("java.reccal"));
09455:                                tool.setLayoutHints("3,1");
09456:                            }
09457:
09458:                        } catch (Exception e) {
09459:                            M_log.warn("SiteAction.getFeatures Exception "
09460:                                    + e.getMessage());
09461:                        }
09462:
09463:                        state.setAttribute(STATE_TOOL_HOME_SELECTED,
09464:                                Boolean.TRUE);
09465:
09466:                        // Order tools - move Home to the top
09467:                        pageList = site.getPages();
09468:                        if (pageList != null && pageList.size() != 0) {
09469:                            for (ListIterator i = pageList.listIterator(); i
09470:                                    .hasNext();) {
09471:                                SitePage page = (SitePage) i.next();
09472:                                if ((page.getTitle()).equals(rb
09473:                                        .getString("java.home"))) {
09474:                                    moves = pageList.indexOf(page);
09475:                                    for (int n = 0; n < moves; n++) {
09476:                                        page.moveUp();
09477:                                    }
09478:                                }
09479:                            }
09480:                        }
09481:                    } // Home feature
09482:
09483:                    // move Site Info tool, if selected, to the end of tool list
09484:                    if (hasSiteInfo) {
09485:                        SitePage siteInfoPage = null;
09486:                        pageList = site.getPages();
09487:                        String[] toolIds = { "sakai.siteinfo" };
09488:                        if (pageList != null && pageList.size() != 0) {
09489:                            for (ListIterator i = pageList.listIterator(); siteInfoPage == null
09490:                                    && i.hasNext();) {
09491:                                SitePage page = (SitePage) i.next();
09492:                                int s = page.getTools(toolIds).size();
09493:                                if (s > 0) {
09494:                                    siteInfoPage = page;
09495:                                }
09496:                            }
09497:                        }
09498:
09499:                        // if found, move it
09500:                        if (siteInfoPage != null) {
09501:                            // move home from it's index to the first position
09502:                            int siteInfoPosition = pageList
09503:                                    .indexOf(siteInfoPage);
09504:                            for (int n = siteInfoPosition; n < pageList.size(); n++) {
09505:                                siteInfoPage.moveDown();
09506:                            }
09507:                        }
09508:                    } // Site Info
09509:                }
09510:
09511:                // commit
09512:                commitSite(site);
09513:
09514:                // import
09515:                importToolIntoSite(chosenList, importTools, site);
09516:
09517:            } // addFeatures
09518:
09519:            // import tool content into site
09520:            private void importToolIntoSite(List toolIds,
09521:                    Hashtable importTools, Site site) {
09522:                if (importTools != null) {
09523:                    // import resources first
09524:                    boolean resourcesImported = false;
09525:                    for (int i = 0; i < toolIds.size() && !resourcesImported; i++) {
09526:                        String toolId = (String) toolIds.get(i);
09527:
09528:                        if (toolId.equalsIgnoreCase("sakai.resources")
09529:                                && importTools.containsKey(toolId)) {
09530:                            List importSiteIds = (List) importTools.get(toolId);
09531:
09532:                            for (int k = 0; k < importSiteIds.size(); k++) {
09533:                                String fromSiteId = (String) importSiteIds
09534:                                        .get(k);
09535:                                String toSiteId = site.getId();
09536:
09537:                                String fromSiteCollectionId = ContentHostingService
09538:                                        .getSiteCollection(fromSiteId);
09539:                                String toSiteCollectionId = ContentHostingService
09540:                                        .getSiteCollection(toSiteId);
09541:                                transferCopyEntities(toolId,
09542:                                        fromSiteCollectionId,
09543:                                        toSiteCollectionId);
09544:                                resourcesImported = true;
09545:                            }
09546:                        }
09547:                    }
09548:
09549:                    // ijmport other tools then
09550:                    for (int i = 0; i < toolIds.size(); i++) {
09551:                        String toolId = (String) toolIds.get(i);
09552:                        if (!toolId.equalsIgnoreCase("sakai.resources")
09553:                                && importTools.containsKey(toolId)) {
09554:                            List importSiteIds = (List) importTools.get(toolId);
09555:                            for (int k = 0; k < importSiteIds.size(); k++) {
09556:                                String fromSiteId = (String) importSiteIds
09557:                                        .get(k);
09558:                                String toSiteId = site.getId();
09559:                                transferCopyEntities(toolId, fromSiteId,
09560:                                        toSiteId);
09561:                            }
09562:                        }
09563:                    }
09564:                }
09565:            } // importToolIntoSite
09566:
09567:            public void saveSiteStatus(SessionState state, boolean published) {
09568:                Site site = getStateSite(state);
09569:                site.setPublished(published);
09570:
09571:            } // saveSiteStatus
09572:
09573:            public void commitSite(Site site, boolean published) {
09574:                site.setPublished(published);
09575:
09576:                try {
09577:                    SiteService.save(site);
09578:                } catch (IdUnusedException e) {
09579:                    // TODO:
09580:                } catch (PermissionException e) {
09581:                    // TODO:
09582:                }
09583:
09584:            } // commitSite
09585:
09586:            public void commitSite(Site site) {
09587:                try {
09588:                    SiteService.save(site);
09589:                } catch (IdUnusedException e) {
09590:                    // TODO:
09591:                } catch (PermissionException e) {
09592:                    // TODO:
09593:                }
09594:
09595:            }// commitSite
09596:
09597:            private boolean isValidDomain(String email) {
09598:                String invalidEmailInIdAccountString = ServerConfigurationService
09599:                        .getString("invalidEmailInIdAccountString", null);
09600:
09601:                if (invalidEmailInIdAccountString != null) {
09602:                    String[] invalidDomains = invalidEmailInIdAccountString
09603:                            .split(",");
09604:
09605:                    for (int i = 0; i < invalidDomains.length; i++) {
09606:                        String domain = invalidDomains[i].trim();
09607:
09608:                        if (email.toLowerCase().indexOf(domain.toLowerCase()) != -1) {
09609:                            return false;
09610:                        }
09611:                    }
09612:                }
09613:                return true;
09614:            }
09615:
09616:            private void checkAddParticipant(ParameterParser params,
09617:                    SessionState state) {
09618:                // get the participants to be added
09619:                int i;
09620:                Vector pList = new Vector();
09621:                HashSet existingUsers = new HashSet();
09622:
09623:                Site site = null;
09624:                String siteId = (String) state
09625:                        .getAttribute(STATE_SITE_INSTANCE_ID);
09626:                try {
09627:                    site = SiteService.getSite(siteId);
09628:                } catch (IdUnusedException e) {
09629:                    addAlert(state, rb.getString("java.specif") + " " + siteId);
09630:                }
09631:
09632:                // accept noEmailInIdAccounts and/or emailInIdAccount account names
09633:                String noEmailInIdAccounts = "";
09634:                String emailInIdAccounts = "";
09635:
09636:                // check that there is something with which to work
09637:                noEmailInIdAccounts = StringUtil.trimToNull((params
09638:                        .getString("noEmailInIdAccount")));
09639:                emailInIdAccounts = StringUtil.trimToNull(params
09640:                        .getString("emailInIdAccount"));
09641:                state.setAttribute("noEmailInIdAccountValue",
09642:                        noEmailInIdAccounts);
09643:                state.setAttribute("emailInIdAccountValue", emailInIdAccounts);
09644:
09645:                // if there is no uniquname or emailInIdAccount entered
09646:                if (noEmailInIdAccounts == null && emailInIdAccounts == null) {
09647:                    addAlert(state, rb.getString("java.guest"));
09648:                    state.setAttribute(STATE_TEMPLATE_INDEX, "5");
09649:                    return;
09650:                }
09651:
09652:                String at = "@";
09653:
09654:                if (noEmailInIdAccounts != null) {
09655:                    // adding noEmailInIdAccounts
09656:                    String[] noEmailInIdAccountArray = noEmailInIdAccounts
09657:                            .split("\r\n");
09658:
09659:                    for (i = 0; i < noEmailInIdAccountArray.length; i++) {
09660:                        String noEmailInIdAccount = StringUtil
09661:                                .trimToNull(noEmailInIdAccountArray[i]
09662:                                        .replaceAll("[\t\r\n]", ""));
09663:                        // if there is some text, try to use it
09664:                        if (noEmailInIdAccount != null) {
09665:                            // automaticially add emailInIdAccount account
09666:                            Participant participant = new Participant();
09667:                            try {
09668:                                User u = UserDirectoryService
09669:                                        .getUserByEid(noEmailInIdAccount);
09670:                                if (site != null
09671:                                        && site.getUserRole(u.getId()) != null) {
09672:                                    // user already exists in the site, cannot be added
09673:                                    // again
09674:                                    existingUsers.add(noEmailInIdAccount);
09675:                                } else {
09676:                                    participant.name = u.getDisplayName();
09677:                                    participant.uniqname = noEmailInIdAccount;
09678:                                    pList.add(participant);
09679:                                }
09680:                            } catch (UserNotDefinedException e) {
09681:                                addAlert(state, noEmailInIdAccount + " "
09682:                                        + rb.getString("java.username") + " ");
09683:                            }
09684:                        }
09685:                    }
09686:                } // noEmailInIdAccounts
09687:
09688:                if (emailInIdAccounts != null) {
09689:                    String[] emailInIdAccountArray = emailInIdAccounts
09690:                            .split("\r\n");
09691:                    for (i = 0; i < emailInIdAccountArray.length; i++) {
09692:                        String emailInIdAccount = emailInIdAccountArray[i];
09693:
09694:                        // if there is some text, try to use it
09695:                        emailInIdAccount.replaceAll("[ \t\r\n]", "");
09696:
09697:                        // remove the trailing dots and empty space
09698:                        while (emailInIdAccount.endsWith(".")
09699:                                || emailInIdAccount.endsWith(" ")) {
09700:                            emailInIdAccount = emailInIdAccount.substring(0,
09701:                                    emailInIdAccount.length() - 1);
09702:                        }
09703:
09704:                        if (emailInIdAccount != null
09705:                                && emailInIdAccount.length() > 0) {
09706:                            String[] parts = emailInIdAccount.split(at);
09707:
09708:                            if (emailInIdAccount.indexOf(at) == -1) {
09709:                                // must be a valid email address
09710:                                addAlert(state, emailInIdAccount + " "
09711:                                        + rb.getString("java.emailaddress"));
09712:                            } else if ((parts.length != 2)
09713:                                    || (parts[0].length() == 0)) {
09714:                                // must have both id and address part
09715:                                addAlert(state, emailInIdAccount + " "
09716:                                        + rb.getString("java.notemailid"));
09717:                            } else if (!Validator.checkEmailLocal(parts[0])) {
09718:                                addAlert(state, emailInIdAccount + " "
09719:                                        + rb.getString("java.emailaddress")
09720:                                        + rb.getString("java.theemail"));
09721:                            } else if (emailInIdAccount != null
09722:                                    && !isValidDomain(emailInIdAccount)) {
09723:                                // wrong string inside emailInIdAccount id
09724:                                addAlert(state, emailInIdAccount + " "
09725:                                        + rb.getString("java.emailaddress")
09726:                                        + " ");
09727:                            } else {
09728:                                Participant participant = new Participant();
09729:                                try {
09730:                                    // if the emailInIdAccount user already exists
09731:                                    User u = UserDirectoryService
09732:                                            .getUserByEid(emailInIdAccount);
09733:                                    if (site != null
09734:                                            && site.getUserRole(u.getId()) != null) {
09735:                                        // user already exists in the site, cannot be
09736:                                        // added again
09737:                                        existingUsers.add(emailInIdAccount);
09738:                                    } else {
09739:                                        participant.name = u.getDisplayName();
09740:                                        participant.uniqname = emailInIdAccount;
09741:                                        pList.add(participant);
09742:                                    }
09743:                                } catch (UserNotDefinedException e) {
09744:                                    // if the emailInIdAccount user is not in the system
09745:                                    // yet
09746:                                    participant.name = emailInIdAccount;
09747:                                    participant.uniqname = emailInIdAccount; // TODO:
09748:                                    // what
09749:                                    // would
09750:                                    // the
09751:                                    // UDS
09752:                                    // case
09753:                                    // this
09754:                                    // name
09755:                                    // to?
09756:                                    // -ggolden
09757:                                    pList.add(participant);
09758:                                }
09759:                            }
09760:                        } // if
09761:                    } // 	
09762:                } // emailInIdAccounts
09763:
09764:                boolean same_role = true;
09765:                if (params.getString("same_role") == null) {
09766:                    addAlert(state, rb.getString("java.roletype") + " ");
09767:                } else {
09768:                    same_role = params.getString("same_role").equals("true") ? true
09769:                            : false;
09770:                    state
09771:                            .setAttribute("form_same_role", new Boolean(
09772:                                    same_role));
09773:                }
09774:
09775:                if (state.getAttribute(STATE_MESSAGE) != null) {
09776:                    state.setAttribute(STATE_TEMPLATE_INDEX, "5");
09777:                } else {
09778:                    if (same_role) {
09779:                        state.setAttribute(STATE_TEMPLATE_INDEX, "19");
09780:                    } else {
09781:                        state.setAttribute(STATE_TEMPLATE_INDEX, "20");
09782:                    }
09783:                }
09784:
09785:                // remove duplicate or existing user from participant list
09786:                pList = removeDuplicateParticipants(pList, state);
09787:                state.setAttribute(STATE_ADD_PARTICIPANTS, pList);
09788:
09789:                // if the add participant list is empty after above removal, stay in the
09790:                // current page
09791:                if (pList.size() == 0) {
09792:                    state.setAttribute(STATE_TEMPLATE_INDEX, "5");
09793:                }
09794:
09795:                // add alert for attempting to add existing site user(s)
09796:                if (!existingUsers.isEmpty()) {
09797:                    int count = 0;
09798:                    String accounts = "";
09799:                    for (Iterator eIterator = existingUsers.iterator(); eIterator
09800:                            .hasNext();) {
09801:                        if (count == 0) {
09802:                            accounts = (String) eIterator.next();
09803:                        } else {
09804:                            accounts = accounts + ", "
09805:                                    + (String) eIterator.next();
09806:                        }
09807:                        count++;
09808:                    }
09809:                    addAlert(state, rb.getString("add.existingpart.1")
09810:                            + accounts + rb.getString("add.existingpart.2"));
09811:                }
09812:
09813:                return;
09814:
09815:            } // checkAddParticipant
09816:
09817:            private Vector removeDuplicateParticipants(List pList,
09818:                    SessionState state) {
09819:                // check the uniqness of list member
09820:                Set s = new HashSet();
09821:                Set uniqnameSet = new HashSet();
09822:                Vector rv = new Vector();
09823:                for (int i = 0; i < pList.size(); i++) {
09824:                    Participant p = (Participant) pList.get(i);
09825:                    if (!uniqnameSet.contains(p.getUniqname())) {
09826:                        // no entry for the account yet
09827:                        rv.add(p);
09828:                        uniqnameSet.add(p.getUniqname());
09829:                    } else {
09830:                        // found duplicates
09831:                        s.add(p.getUniqname());
09832:                    }
09833:                }
09834:
09835:                if (!s.isEmpty()) {
09836:                    int count = 0;
09837:                    String accounts = "";
09838:                    for (Iterator i = s.iterator(); i.hasNext();) {
09839:                        if (count == 0) {
09840:                            accounts = (String) i.next();
09841:                        } else {
09842:                            accounts = accounts + ", " + (String) i.next();
09843:                        }
09844:                        count++;
09845:                    }
09846:                    if (count == 1) {
09847:                        addAlert(state, rb
09848:                                .getString("add.duplicatedpart.single")
09849:                                + accounts + ".");
09850:                    } else {
09851:                        addAlert(state, rb.getString("add.duplicatedpart")
09852:                                + accounts + ".");
09853:                    }
09854:                }
09855:
09856:                return rv;
09857:            }
09858:
09859:            public void doAdd_participant(RunData data) {
09860:                SessionState state = ((JetspeedRunData) data)
09861:                        .getPortletSessionState(((JetspeedRunData) data)
09862:                                .getJs_peid());
09863:                String siteTitle = getStateSite(state).getTitle();
09864:                String emailInIdAccountName = ServerConfigurationService
09865:                        .getString("emailInIdAccountName", "");
09866:
09867:                Hashtable selectedRoles = (Hashtable) state
09868:                        .getAttribute(STATE_SELECTED_PARTICIPANT_ROLES);
09869:
09870:                boolean notify = false;
09871:                if (state.getAttribute("form_selectedNotify") != null) {
09872:                    notify = ((Boolean) state
09873:                            .getAttribute("form_selectedNotify"))
09874:                            .booleanValue();
09875:                }
09876:                boolean same_role = ((Boolean) state
09877:                        .getAttribute("form_same_role")).booleanValue();
09878:                Hashtable eIdRoles = new Hashtable();
09879:
09880:                List addParticipantList = (List) state
09881:                        .getAttribute(STATE_ADD_PARTICIPANTS);
09882:                for (int i = 0; i < addParticipantList.size(); i++) {
09883:                    Participant p = (Participant) addParticipantList.get(i);
09884:                    String eId = p.getEid();
09885:
09886:                    // role defaults to same role
09887:                    String role = (String) state
09888:                            .getAttribute("form_selectedRole");
09889:                    if (!same_role) {
09890:                        // if all added participants have different role
09891:                        role = (String) selectedRoles.get(eId);
09892:                    }
09893:
09894:                    boolean noEmailInIdAccount = eId.indexOf(EMAIL_CHAR) == -1;
09895:                    if (noEmailInIdAccount) {
09896:                        // if this is a noEmailInIdAccount
09897:                        // update the hashtable
09898:                        eIdRoles.put(eId, role);
09899:                    } else {
09900:                        // if this is an emailInIdAccount
09901:                        try {
09902:                            UserDirectoryService.getUserByEid(eId);
09903:                        } catch (UserNotDefinedException e) {
09904:                            // if there is no such user yet, add the user
09905:                            try {
09906:                                UserEdit uEdit = UserDirectoryService.addUser(
09907:                                        null, eId);
09908:
09909:                                // set email address
09910:                                uEdit.setEmail(eId);
09911:
09912:                                // set the guest user type
09913:                                uEdit.setType("guest");
09914:
09915:                                // set password to a positive random number
09916:                                Random generator = new Random(System
09917:                                        .currentTimeMillis());
09918:                                Integer num = new Integer(generator
09919:                                        .nextInt(Integer.MAX_VALUE));
09920:                                if (num.intValue() < 0)
09921:                                    num = new Integer(num.intValue() * -1);
09922:                                String pw = num.toString();
09923:                                uEdit.setPassword(pw);
09924:
09925:                                // and save
09926:                                UserDirectoryService.commitEdit(uEdit);
09927:
09928:                                boolean notifyNewUserEmail = (ServerConfigurationService
09929:                                        .getString("notifyNewUserEmail",
09930:                                                Boolean.TRUE.toString()))
09931:                                        .equalsIgnoreCase(Boolean.TRUE
09932:                                                .toString());
09933:                                if (notifyNewUserEmail) {
09934:                                    notifyNewUserEmail(uEdit.getEid(), uEdit
09935:                                            .getEmail(), pw, siteTitle);
09936:                                }
09937:                            } catch (UserIdInvalidException ee) {
09938:                                addAlert(state, emailInIdAccountName + " id "
09939:                                        + eId + " "
09940:                                        + rb.getString("java.isinval"));
09941:                                M_log
09942:                                        .warn(this 
09943:                                                + " UserDirectoryService addUser exception "
09944:                                                + e.getMessage());
09945:                            } catch (UserAlreadyDefinedException ee) {
09946:                                addAlert(state, "The " + emailInIdAccountName
09947:                                        + " " + eId + " "
09948:                                        + rb.getString("java.beenused"));
09949:                                M_log
09950:                                        .warn(this 
09951:                                                + " UserDirectoryService addUser exception "
09952:                                                + e.getMessage());
09953:                            } catch (UserPermissionException ee) {
09954:                                addAlert(state, rb.getString("java.haveadd")
09955:                                        + " " + eId);
09956:                                M_log
09957:                                        .warn(this 
09958:                                                + " UserDirectoryService addUser exception "
09959:                                                + e.getMessage());
09960:                            }
09961:                        }
09962:
09963:                        if (state.getAttribute(STATE_MESSAGE) == null) {
09964:                            eIdRoles.put(eId, role);
09965:                        }
09966:                    }
09967:                }
09968:
09969:                // batch add and updates the successful added list
09970:                List addedParticipantEIds = addUsersRealm(state, eIdRoles,
09971:                        notify, false);
09972:
09973:                // update the not added user list
09974:                String notAddedNoEmailInIdAccounts = null;
09975:                String notAddedEmailInIdAccounts = null;
09976:                for (Iterator iEIds = eIdRoles.keySet().iterator(); iEIds
09977:                        .hasNext();) {
09978:                    String iEId = (String) iEIds.next();
09979:                    if (!addedParticipantEIds.contains(iEId)) {
09980:                        if (iEId.indexOf(EMAIL_CHAR) == -1) {
09981:                            // no email in eid
09982:                            notAddedNoEmailInIdAccounts = notAddedNoEmailInIdAccounts
09983:                                    .concat(iEId + "\n");
09984:                        } else {
09985:                            // email in eid
09986:                            notAddedEmailInIdAccounts = notAddedEmailInIdAccounts
09987:                                    .concat(iEId + "\n");
09988:                        }
09989:                    }
09990:                }
09991:
09992:                if (addedParticipantEIds.size() != 0
09993:                        && (notAddedNoEmailInIdAccounts != null || notAddedEmailInIdAccounts != null)) {
09994:                    // at lease one noEmailInIdAccount account or an emailInIdAccount
09995:                    // account added, and there are also failures
09996:                    addAlert(state, rb.getString("java.allusers"));
09997:                }
09998:
09999:                if (notAddedNoEmailInIdAccounts == null
10000:                        && notAddedEmailInIdAccounts == null) {
10001:                    // all account has been added successfully
10002:                    removeAddParticipantContext(state);
10003:                } else {
10004:                    state.setAttribute("noEmailInIdAccountValue",
10005:                            notAddedNoEmailInIdAccounts);
10006:                    state.setAttribute("emailInIdAccountValue",
10007:                            notAddedEmailInIdAccounts);
10008:                }
10009:                if (state.getAttribute(STATE_MESSAGE) != null) {
10010:                    state.setAttribute(STATE_TEMPLATE_INDEX, "22");
10011:                } else {
10012:                    state.setAttribute(STATE_TEMPLATE_INDEX, "12");
10013:                }
10014:                return;
10015:
10016:            } // doAdd_participant
10017:
10018:            /**
10019:             * remove related state variable for adding participants
10020:             * 
10021:             * @param state
10022:             *            SessionState object
10023:             */
10024:            private void removeAddParticipantContext(SessionState state) {
10025:                // remove related state variables
10026:                state.removeAttribute("form_selectedRole");
10027:                state.removeAttribute("noEmailInIdAccountValue");
10028:                state.removeAttribute("emailInIdAccountValue");
10029:                state.removeAttribute("form_same_role");
10030:                state.removeAttribute("form_selectedNotify");
10031:                state.removeAttribute(STATE_ADD_PARTICIPANTS);
10032:                state.removeAttribute(STATE_SELECTED_USER_LIST);
10033:                state.removeAttribute(STATE_SELECTED_PARTICIPANT_ROLES);
10034:
10035:            } // removeAddParticipantContext
10036:
10037:            /**
10038:             * Send an email to newly added user informing password
10039:             * 
10040:             * @param newEmailInIdAccount
10041:             * @param emailId
10042:             * @param userName
10043:             * @param siteTitle
10044:             */
10045:            private void notifyNewUserEmail(String userName,
10046:                    String newUserEmail, String newUserPassword,
10047:                    String siteTitle) {
10048:                String from = ServerConfigurationService.getString(
10049:                        "setup.request", null);
10050:                if (from == null) {
10051:                    M_log.warn(this  + " - no 'setup.request' in configuration");
10052:                    from = "postmaster@".concat(ServerConfigurationService
10053:                            .getServerName());
10054:                }
10055:                String productionSiteName = ServerConfigurationService
10056:                        .getString("ui.service", "");
10057:                String productionSiteUrl = ServerConfigurationService
10058:                        .getPortalUrl();
10059:
10060:                String to = newUserEmail;
10061:                String headerTo = newUserEmail;
10062:                String replyTo = newUserEmail;
10063:                String message_subject = productionSiteName + " "
10064:                        + rb.getString("java.newusernoti");
10065:                String content = "";
10066:
10067:                if (from != null && newUserEmail != null) {
10068:                    StringBuffer buf = new StringBuffer();
10069:                    buf.setLength(0);
10070:
10071:                    // email body
10072:                    buf.append(userName + ":\n\n");
10073:
10074:                    buf.append(rb.getString("java.addedto") + " "
10075:                            + productionSiteName + " (" + productionSiteUrl
10076:                            + ") ");
10077:                    buf.append(rb.getString("java.simpleby") + " ");
10078:                    buf.append(UserDirectoryService.getCurrentUser()
10079:                            .getDisplayName()
10080:                            + ". \n\n");
10081:                    buf.append(rb.getString("java.passwordis1") + "\n"
10082:                            + newUserPassword + "\n\n");
10083:                    buf.append(rb.getString("java.passwordis2") + "\n\n");
10084:
10085:                    content = buf.toString();
10086:                    EmailService.send(from, to, message_subject, content,
10087:                            headerTo, replyTo, null);
10088:                }
10089:            } // notifyNewUserEmail
10090:
10091:            /**
10092:             * send email notification to added participant
10093:             */
10094:            private void notifyAddedParticipant(boolean newEmailInIdAccount,
10095:                    String emailId, String userName, String siteTitle) {
10096:                String from = ServerConfigurationService.getString(
10097:                        "setup.request", null);
10098:                if (from == null) {
10099:                    M_log.warn(this  + " - no 'setup.request' in configuration");
10100:                } else {
10101:                    String productionSiteName = ServerConfigurationService
10102:                            .getString("ui.service", "");
10103:                    String productionSiteUrl = ServerConfigurationService
10104:                            .getPortalUrl();
10105:                    String emailInIdAccountUrl = ServerConfigurationService
10106:                            .getString("emailInIdAccount.url", null);
10107:                    String to = emailId;
10108:                    String headerTo = emailId;
10109:                    String replyTo = emailId;
10110:                    String message_subject = productionSiteName + " "
10111:                            + rb.getString("java.sitenoti");
10112:                    String content = "";
10113:                    StringBuffer buf = new StringBuffer();
10114:                    buf.setLength(0);
10115:
10116:                    // email body differs between newly added emailInIdAccount account
10117:                    // and other users
10118:                    buf.append(userName + ":\n\n");
10119:                    buf.append(rb.getString("java.following") + " "
10120:                            + productionSiteName + " "
10121:                            + rb.getString("java.simplesite") + "\n");
10122:                    buf.append(siteTitle + "\n");
10123:                    buf.append(rb.getString("java.simpleby") + " ");
10124:                    buf.append(UserDirectoryService.getCurrentUser()
10125:                            .getDisplayName()
10126:                            + ". \n\n");
10127:                    if (newEmailInIdAccount) {
10128:                        buf.append(ServerConfigurationService.getString(
10129:                                "emailInIdAccountInstru", "")
10130:                                + "\n");
10131:
10132:                        if (emailInIdAccountUrl != null) {
10133:                            buf.append(rb.getString("java.togeta1") + "\n"
10134:                                    + emailInIdAccountUrl + "\n");
10135:                            buf.append(rb.getString("java.togeta2") + "\n\n");
10136:                        }
10137:                        buf.append(rb.getString("java.once") + " "
10138:                                + productionSiteName + ": \n");
10139:                        buf.append(rb.getString("java.loginhow1") + " "
10140:                                + productionSiteName + ": " + productionSiteUrl
10141:                                + "\n");
10142:                        buf.append(rb.getString("java.loginhow2") + "\n");
10143:                        buf.append(rb.getString("java.loginhow3") + "\n");
10144:                    } else {
10145:                        buf.append(rb.getString("java.tolog") + "\n");
10146:                        buf.append(rb.getString("java.loginhow1") + " "
10147:                                + productionSiteName + ": " + productionSiteUrl
10148:                                + "\n");
10149:                        buf.append(rb.getString("java.loginhow2") + "\n");
10150:                        buf.append(rb.getString("java.loginhow3u") + "\n");
10151:                    }
10152:                    buf.append(rb.getString("java.tabscreen"));
10153:                    content = buf.toString();
10154:                    EmailService.send(from, to, message_subject, content,
10155:                            headerTo, replyTo, null);
10156:
10157:                } // if
10158:
10159:            } // notifyAddedParticipant
10160:
10161:            /*
10162:             * Given a list of user eids, add users to realm If the user account does
10163:             * not exist yet inside the user directory, assign role to it @return A list
10164:             * of eids for successfully added users
10165:             */
10166:            private List addUsersRealm(SessionState state, Hashtable eIdRoles,
10167:                    boolean notify, boolean emailInIdAccount) {
10168:                // return the list of user eids for successfully added user
10169:                List addedUserEIds = new Vector();
10170:
10171:                StringBuffer message = new StringBuffer();
10172:
10173:                if (eIdRoles != null && !eIdRoles.isEmpty()) {
10174:                    // get the current site
10175:                    Site sEdit = getStateSite(state);
10176:                    if (sEdit != null) {
10177:                        // get realm object
10178:                        String realmId = sEdit.getReference();
10179:                        try {
10180:                            AuthzGroup realmEdit = AuthzGroupService
10181:                                    .getAuthzGroup(realmId);
10182:                            for (Iterator eIds = eIdRoles.keySet().iterator(); eIds
10183:                                    .hasNext();) {
10184:                                String eId = (String) eIds.next();
10185:                                String role = (String) eIdRoles.get(eId);
10186:
10187:                                try {
10188:                                    User user = UserDirectoryService
10189:                                            .getUserByEid(eId);
10190:                                    if (AuthzGroupService.allowUpdate(realmId)
10191:                                            || SiteService
10192:                                                    .allowUpdateSiteMembership(sEdit
10193:                                                            .getId())) {
10194:                                        realmEdit.addMember(user.getId(), role,
10195:                                                true, false);
10196:                                        addedUserEIds.add(eId);
10197:
10198:                                        // send notification
10199:                                        if (notify) {
10200:                                            String emailId = user.getEmail();
10201:                                            String userName = user
10202:                                                    .getDisplayName();
10203:                                            // send notification email
10204:                                            notifyAddedParticipant(
10205:                                                    emailInIdAccount, emailId,
10206:                                                    userName, sEdit.getTitle());
10207:                                        }
10208:                                    }
10209:                                } catch (UserNotDefinedException e) {
10210:                                    message.append(eId + " "
10211:                                            + rb.getString("java.account")
10212:                                            + " \n");
10213:                                } // try
10214:                            } // for
10215:
10216:                            try {
10217:                                AuthzGroupService.save(realmEdit);
10218:                            } catch (GroupNotDefinedException ee) {
10219:                                message.append(rb.getString("java.realm")
10220:                                        + realmId);
10221:                            } catch (AuthzPermissionException ee) {
10222:                                message.append(rb
10223:                                        .getString("java.permeditsite")
10224:                                        + realmId);
10225:                            }
10226:                        } catch (GroupNotDefinedException eee) {
10227:                            message
10228:                                    .append(rb.getString("java.realm")
10229:                                            + realmId);
10230:                        }
10231:                    }
10232:                }
10233:
10234:                if (message.length() != 0) {
10235:                    addAlert(state, message.toString());
10236:                } // if
10237:
10238:                return addedUserEIds;
10239:
10240:            } // addUsersRealm
10241:
10242:            /**
10243:             * addNewSite is called when the site has enough information to create a new
10244:             * site
10245:             * 
10246:             */
10247:            private void addNewSite(ParameterParser params, SessionState state) {
10248:                if (getStateSite(state) != null) {
10249:                    // There is a Site in state already, so use it rather than creating
10250:                    // a new Site
10251:                    return;
10252:                }
10253:
10254:                // If cleanState() has removed SiteInfo, get a new instance into state
10255:                SiteInfo siteInfo = new SiteInfo();
10256:                if (state.getAttribute(STATE_SITE_INFO) != null) {
10257:                    siteInfo = (SiteInfo) state.getAttribute(STATE_SITE_INFO);
10258:                }
10259:                String id = StringUtil.trimToNull(siteInfo.getSiteId());
10260:                if (id == null) {
10261:                    // get id
10262:                    id = IdManager.createUuid();
10263:                    siteInfo.site_id = id;
10264:                }
10265:                state.setAttribute(STATE_SITE_INFO, siteInfo);
10266:                if (state.getAttribute(STATE_MESSAGE) == null) {
10267:                    try {
10268:                        siteInfo = (SiteInfo) state
10269:                                .getAttribute(STATE_SITE_INFO);
10270:
10271:                        Site site = SiteService.addSite(id, siteInfo.site_type);
10272:
10273:                        String title = StringUtil.trimToNull(siteInfo.title);
10274:                        String description = siteInfo.description;
10275:                        setAppearance(state, site, siteInfo.iconUrl);
10276:                        site.setDescription(description);
10277:                        if (title != null) {
10278:                            site.setTitle(title);
10279:                        }
10280:
10281:                        site.setType(siteInfo.site_type);
10282:
10283:                        ResourcePropertiesEdit rp = site.getPropertiesEdit();
10284:                        site.setShortDescription(siteInfo.short_description);
10285:                        site.setPubView(siteInfo.include);
10286:                        site.setJoinable(siteInfo.joinable);
10287:                        site.setJoinerRole(siteInfo.joinerRole);
10288:                        site.setPublished(siteInfo.published);
10289:                        // site contact information
10290:                        rp.addProperty(PROP_SITE_CONTACT_NAME,
10291:                                siteInfo.site_contact_name);
10292:                        rp.addProperty(PROP_SITE_CONTACT_EMAIL,
10293:                                siteInfo.site_contact_email);
10294:
10295:                        state
10296:                                .setAttribute(STATE_SITE_INSTANCE_ID, site
10297:                                        .getId());
10298:
10299:                        // commit newly added site in order to enable related realm
10300:                        commitSite(site);
10301:
10302:                    } catch (IdUsedException e) {
10303:                        addAlert(state, rb.getString("java.sitewithid") + " "
10304:                                + id + " " + rb.getString("java.exists"));
10305:                        state.setAttribute(STATE_TEMPLATE_INDEX, params
10306:                                .getString("template-index"));
10307:                        return;
10308:                    } catch (IdInvalidException e) {
10309:                        addAlert(state, rb.getString("java.thesiteid") + " "
10310:                                + id + " " + rb.getString("java.notvalid"));
10311:                        state.setAttribute(STATE_TEMPLATE_INDEX, params
10312:                                .getString("template-index"));
10313:                        return;
10314:                    } catch (PermissionException e) {
10315:                        addAlert(state, rb.getString("java.permission") + " "
10316:                                + id + ".");
10317:                        state.setAttribute(STATE_TEMPLATE_INDEX, params
10318:                                .getString("template-index"));
10319:                        return;
10320:                    }
10321:                }
10322:            } // addNewSite
10323:
10324:            /**
10325:             * %%% legacy properties, to be cleaned up
10326:             * 
10327:             */
10328:            private void sitePropertiesIntoState(SessionState state) {
10329:                try {
10330:                    Site site = getStateSite(state);
10331:                    SiteInfo siteInfo = new SiteInfo();
10332:
10333:                    // set from site attributes
10334:                    siteInfo.title = site.getTitle();
10335:                    siteInfo.description = site.getDescription();
10336:                    siteInfo.iconUrl = site.getIconUrl();
10337:                    siteInfo.infoUrl = site.getInfoUrl();
10338:                    siteInfo.joinable = site.isJoinable();
10339:                    siteInfo.joinerRole = site.getJoinerRole();
10340:                    siteInfo.published = site.isPublished();
10341:                    siteInfo.include = site.isPubView();
10342:                    siteInfo.short_description = site.getShortDescription();
10343:                    state.setAttribute(STATE_SITE_TYPE, siteInfo.site_type);
10344:
10345:                    state.setAttribute(STATE_SITE_INFO, siteInfo);
10346:                } catch (Exception e) {
10347:                    M_log.warn("SiteAction.sitePropertiesIntoState "
10348:                            + e.getMessage());
10349:                }
10350:
10351:            } // sitePropertiesIntoState
10352:
10353:            /**
10354:             * pageMatchesPattern returns true if a SitePage matches a WorkSite Setup
10355:             * pattern
10356:             * 
10357:             */
10358:            private boolean pageMatchesPattern(SessionState state, SitePage page) {
10359:                List pageToolList = page.getTools();
10360:
10361:                // if no tools on the page, return false
10362:                if (pageToolList == null || pageToolList.size() == 0) {
10363:                    return false;
10364:                }
10365:
10366:                // for the case where the page has one tool
10367:                ToolConfiguration toolConfiguration = (ToolConfiguration) pageToolList
10368:                        .get(0);
10369:
10370:                // don't compare tool properties, which may be changed using Options
10371:                List toolList = new Vector();
10372:                int count = pageToolList.size();
10373:                boolean match = false;
10374:
10375:                // check Worksite Setup Home pattern
10376:                if (page.getTitle() != null
10377:                        && page.getTitle().equals(rb.getString("java.home"))) {
10378:                    return true;
10379:
10380:                } // Home
10381:                else if (page.getTitle() != null
10382:                        && page.getTitle().equals(rb.getString("java.help"))) {
10383:                    // if the count of tools on the page doesn't match, return false
10384:                    if (count != 1) {
10385:                        return false;
10386:                    }
10387:
10388:                    // if the page layout doesn't match, return false
10389:                    if (page.getLayout() != SitePage.LAYOUT_SINGLE_COL) {
10390:                        return false;
10391:                    }
10392:
10393:                    // if tooId isn't sakai.contactSupport, return false
10394:                    if (!(toolConfiguration.getTool().getId())
10395:                            .equals("sakai.contactSupport")) {
10396:                        return false;
10397:                    }
10398:
10399:                    return true;
10400:                } // Help
10401:                else if (page.getTitle() != null
10402:                        && page.getTitle().equals("Chat")) {
10403:                    // if the count of tools on the page doesn't match, return false
10404:                    if (count != 1) {
10405:                        return false;
10406:                    }
10407:
10408:                    // if the page layout doesn't match, return false
10409:                    if (page.getLayout() != SitePage.LAYOUT_SINGLE_COL) {
10410:                        return false;
10411:                    }
10412:
10413:                    // if the tool doesn't match, return false
10414:                    if (!(toolConfiguration.getTool().getId())
10415:                            .equals("sakai.chat")) {
10416:                        return false;
10417:                    }
10418:
10419:                    // if the channel doesn't match value for main channel, return false
10420:                    String channel = toolConfiguration.getPlacementConfig()
10421:                            .getProperty("channel");
10422:                    if (channel == null) {
10423:                        return false;
10424:                    }
10425:                    if (!(channel.equals(NULL_STRING))) {
10426:                        return false;
10427:                    }
10428:
10429:                    return true;
10430:                } // Chat
10431:                else {
10432:                    // if the count of tools on the page doesn't match, return false
10433:                    if (count != 1) {
10434:                        return false;
10435:                    }
10436:
10437:                    // if the page layout doesn't match, return false
10438:                    if (page.getLayout() != SitePage.LAYOUT_SINGLE_COL) {
10439:                        return false;
10440:                    }
10441:
10442:                    toolList = (List) state
10443:                            .getAttribute(STATE_TOOL_REGISTRATION_LIST);
10444:
10445:                    if (pageToolList != null || pageToolList.size() != 0) {
10446:                        // if tool attributes don't match, return false
10447:                        match = false;
10448:                        for (ListIterator i = toolList.listIterator(); i
10449:                                .hasNext();) {
10450:                            MyTool tool = (MyTool) i.next();
10451:                            if (toolConfiguration.getTitle() != null) {
10452:                                if (toolConfiguration.getTool() != null
10453:                                        && toolConfiguration.getTool().getId()
10454:                                                .indexOf(tool.getId()) != -1) {
10455:                                    match = true;
10456:                                }
10457:                            }
10458:                        }
10459:                        if (!match) {
10460:                            return false;
10461:                        }
10462:                    }
10463:                } // Others
10464:                return true;
10465:
10466:            } // pageMatchesPattern
10467:
10468:            /**
10469:             * siteToolsIntoState is the replacement for siteToolsIntoState_ Make a list
10470:             * of pages and tools that match WorkSite Setup configurations into state
10471:             */
10472:            private void siteToolsIntoState(SessionState state) {
10473:                String wSetupTool = NULL_STRING;
10474:                List wSetupPageList = new Vector();
10475:                Site site = getStateSite(state);
10476:                List pageList = site.getPages();
10477:
10478:                // Put up tool lists filtered by category
10479:                String type = site.getType();
10480:                if (type == null) {
10481:                    if (SiteService.isUserSite(site.getId())) {
10482:                        type = "myworkspace";
10483:                    } else if (state.getAttribute(STATE_DEFAULT_SITE_TYPE) != null) {
10484:                        // for those sites without type, use the tool set for default
10485:                        // site type
10486:                        type = (String) state
10487:                                .getAttribute(STATE_DEFAULT_SITE_TYPE);
10488:                    }
10489:                }
10490:
10491:                List toolRegList = new Vector();
10492:                if (type != null) {
10493:                    Set categories = new HashSet();
10494:                    categories.add(type);
10495:                    Set toolRegistrations = ToolManager.findTools(categories,
10496:                            null);
10497:                    SortedIterator i = new SortedIterator(toolRegistrations
10498:                            .iterator(), new ToolComparator());
10499:                    for (; i.hasNext();) {
10500:                        // form a new Tool
10501:                        Tool tr = (Tool) i.next();
10502:                        MyTool newTool = new MyTool();
10503:                        newTool.title = tr.getTitle();
10504:                        newTool.id = tr.getId();
10505:                        newTool.description = tr.getDescription();
10506:
10507:                        toolRegList.add(newTool);
10508:                    }
10509:                }
10510:
10511:                if (toolRegList.size() == 0
10512:                        && state.getAttribute(STATE_DEFAULT_SITE_TYPE) != null) {
10513:                    // use default site type and try getting tools again
10514:                    type = (String) state.getAttribute(STATE_DEFAULT_SITE_TYPE);
10515:
10516:                    Set nCategories = new HashSet();
10517:                    nCategories.add(type);
10518:                    Set toolRegistrations = ToolManager.findTools(nCategories,
10519:                            null);
10520:                    SortedIterator i = new SortedIterator(toolRegistrations
10521:                            .iterator(), new ToolComparator());
10522:                    for (; i.hasNext();) {
10523:                        // form a new Tool
10524:                        Tool tr = (Tool) i.next();
10525:                        MyTool newTool = new MyTool();
10526:                        newTool.title = tr.getTitle();
10527:                        newTool.id = tr.getId();
10528:                        newTool.description = tr.getDescription();
10529:
10530:                        toolRegList.add(newTool);
10531:                    }
10532:                }
10533:                state.setAttribute(STATE_TOOL_REGISTRATION_LIST, toolRegList);
10534:                state.setAttribute(STATE_SITE_TYPE, type);
10535:
10536:                if (type == null) {
10537:                    M_log.warn(this  + ": - unknown STATE_SITE_TYPE");
10538:                } else {
10539:                    state.setAttribute(STATE_SITE_TYPE, type);
10540:                }
10541:
10542:                boolean check_home = false;
10543:                boolean hasNews = false;
10544:                boolean hasWebContent = false;
10545:                int newsToolNum = 0;
10546:                int wcToolNum = 0;
10547:                Hashtable newsTitles = new Hashtable();
10548:                Hashtable wcTitles = new Hashtable();
10549:                Hashtable newsUrls = new Hashtable();
10550:                Hashtable wcUrls = new Hashtable();
10551:
10552:                Vector idSelected = new Vector();
10553:
10554:                if (!((pageList == null) || (pageList.size() == 0))) {
10555:                    for (ListIterator i = pageList.listIterator(); i.hasNext();) {
10556:                        SitePage page = (SitePage) i.next();
10557:                        // collect the pages consistent with Worksite Setup patterns
10558:                        if (pageMatchesPattern(state, page)) {
10559:                            if (page.getTitle().equals(
10560:                                    rb.getString("java.home"))) {
10561:                                wSetupTool = HOME_TOOL_ID;
10562:                                check_home = true;
10563:                            } else {
10564:                                List pageToolList = page.getTools();
10565:                                wSetupTool = ((ToolConfiguration) pageToolList
10566:                                        .get(0)).getTool().getId();
10567:                                if (wSetupTool.indexOf("sakai.news") != -1) {
10568:                                    String newsToolId = page.getId()
10569:                                            + wSetupTool;
10570:                                    idSelected.add(newsToolId);
10571:                                    newsTitles.put(newsToolId, page.getTitle());
10572:                                    String channelUrl = ((ToolConfiguration) pageToolList
10573:                                            .get(0)).getPlacementConfig()
10574:                                            .getProperty("channel-url");
10575:                                    newsUrls.put(newsToolId,
10576:                                            channelUrl != null ? channelUrl
10577:                                                    : "");
10578:                                    newsToolNum++;
10579:
10580:                                    // insert the News tool into the list
10581:                                    hasNews = false;
10582:                                    int j = 0;
10583:                                    MyTool newTool = new MyTool();
10584:                                    newTool.title = NEWS_DEFAULT_TITLE;
10585:                                    newTool.id = newsToolId;
10586:                                    newTool.selected = false;
10587:
10588:                                    for (; j < toolRegList.size() && !hasNews; j++) {
10589:                                        MyTool t = (MyTool) toolRegList.get(j);
10590:                                        if (t.getId().equals("sakai.news")) {
10591:                                            hasNews = true;
10592:                                            newTool.description = t
10593:                                                    .getDescription();
10594:                                        }
10595:                                    }
10596:
10597:                                    if (hasNews) {
10598:                                        toolRegList.add(j - 1, newTool);
10599:                                    } else {
10600:                                        toolRegList.add(newTool);
10601:                                    }
10602:
10603:                                } else if ((wSetupTool).indexOf("sakai.iframe") != -1) {
10604:                                    String wcToolId = page.getId() + wSetupTool;
10605:                                    idSelected.add(wcToolId);
10606:                                    wcTitles.put(wcToolId, page.getTitle());
10607:                                    String wcUrl = StringUtil
10608:                                            .trimToNull(((ToolConfiguration) pageToolList
10609:                                                    .get(0))
10610:                                                    .getPlacementConfig()
10611:                                                    .getProperty("source"));
10612:                                    if (wcUrl == null) {
10613:                                        // if there is no source URL, seed it with the
10614:                                        // Web Content default URL
10615:                                        wcUrl = WEB_CONTENT_DEFAULT_URL;
10616:                                    }
10617:                                    wcUrls.put(wcToolId, wcUrl);
10618:                                    wcToolNum++;
10619:
10620:                                    MyTool newTool = new MyTool();
10621:                                    newTool.title = WEB_CONTENT_DEFAULT_TITLE;
10622:                                    newTool.id = wcToolId;
10623:                                    newTool.selected = false;
10624:
10625:                                    hasWebContent = false;
10626:                                    int j = 0;
10627:                                    for (; j < toolRegList.size()
10628:                                            && !hasWebContent; j++) {
10629:                                        MyTool t = (MyTool) toolRegList.get(j);
10630:                                        if (t.getId().equals("sakai.iframe")) {
10631:                                            hasWebContent = true;
10632:                                            newTool.description = t
10633:                                                    .getDescription();
10634:                                        }
10635:                                    }
10636:                                    if (hasWebContent) {
10637:                                        toolRegList.add(j - 1, newTool);
10638:                                    } else {
10639:                                        toolRegList.add(newTool);
10640:                                    }
10641:                                }
10642:                                /*
10643:                                 * else if(wSetupTool.indexOf("sakai.syllabus") != -1) {
10644:                                 * //add only one instance of tool per site if
10645:                                 * (!(idSelected.contains(wSetupTool))) {
10646:                                 * idSelected.add(wSetupTool); } }
10647:                                 */
10648:                                else {
10649:                                    idSelected.add(wSetupTool);
10650:                                }
10651:                            }
10652:
10653:                            WorksiteSetupPage wSetupPage = new WorksiteSetupPage();
10654:                            wSetupPage.pageId = page.getId();
10655:                            wSetupPage.pageTitle = page.getTitle();
10656:                            wSetupPage.toolId = wSetupTool;
10657:                            wSetupPageList.add(wSetupPage);
10658:                        }
10659:                    }
10660:                }
10661:
10662:                newsTitles.put("sakai.news", NEWS_DEFAULT_TITLE);
10663:                newsUrls.put("sakai.news", NEWS_DEFAULT_URL);
10664:                wcTitles.put("sakai.iframe", WEB_CONTENT_DEFAULT_TITLE);
10665:                wcUrls.put("sakai.iframe", WEB_CONTENT_DEFAULT_URL);
10666:
10667:                state.setAttribute(STATE_TOOL_REGISTRATION_LIST, toolRegList);
10668:                state.setAttribute(STATE_TOOL_HOME_SELECTED, new Boolean(
10669:                        check_home));
10670:                state.setAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST,
10671:                        idSelected); // List
10672:                // of
10673:                // ToolRegistration
10674:                // toolId's
10675:                state.setAttribute(STATE_TOOL_REGISTRATION_OLD_SELECTED_LIST,
10676:                        idSelected); // List of ToolRegistration toolId's
10677:                state.setAttribute(STATE_TOOL_REGISTRATION_OLD_SELECTED_HOME,
10678:                        Boolean.valueOf(check_home));
10679:                state.setAttribute(STATE_NEWS_TITLES, newsTitles);
10680:                state.setAttribute(STATE_WEB_CONTENT_TITLES, wcTitles);
10681:                state.setAttribute(STATE_NEWS_URLS, newsUrls);
10682:                state.setAttribute(STATE_WEB_CONTENT_URLS, wcUrls);
10683:                state.setAttribute(STATE_WORKSITE_SETUP_PAGE_LIST,
10684:                        wSetupPageList);
10685:
10686:            } // siteToolsIntoState
10687:
10688:            /**
10689:             * reset the state variables used in edit tools mode
10690:             * 
10691:             * @state The SessionState object
10692:             */
10693:            private void removeEditToolState(SessionState state) {
10694:                state.removeAttribute(STATE_TOOL_HOME_SELECTED);
10695:                state.removeAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST); // List
10696:                // of
10697:                // ToolRegistration
10698:                // toolId's
10699:                state
10700:                        .removeAttribute(STATE_TOOL_REGISTRATION_OLD_SELECTED_LIST); // List
10701:                // of
10702:                // ToolRegistration
10703:                // toolId's
10704:                state
10705:                        .removeAttribute(STATE_TOOL_REGISTRATION_OLD_SELECTED_HOME);
10706:                state.removeAttribute(STATE_NEWS_TITLES);
10707:                state.removeAttribute(STATE_NEWS_URLS);
10708:                state.removeAttribute(STATE_WEB_CONTENT_TITLES);
10709:                state.removeAttribute(STATE_WEB_CONTENT_URLS);
10710:                state.removeAttribute(STATE_WORKSITE_SETUP_PAGE_LIST);
10711:            }
10712:
10713:            private List orderToolIds(SessionState state, String type,
10714:                    List toolIdList) {
10715:                List rv = new Vector();
10716:                if (state.getAttribute(STATE_TOOL_HOME_SELECTED) != null
10717:                        && ((Boolean) state
10718:                                .getAttribute(STATE_TOOL_HOME_SELECTED))
10719:                                .booleanValue()) {
10720:                    rv.add(HOME_TOOL_ID);
10721:                }
10722:
10723:                // look for null site type
10724:                if (type != null && toolIdList != null) {
10725:                    Set categories = new HashSet();
10726:                    categories.add(type);
10727:                    Set tools = ToolManager.findTools(categories, null);
10728:                    SortedIterator i = new SortedIterator(tools.iterator(),
10729:                            new ToolComparator());
10730:                    for (; i.hasNext();) {
10731:                        String tool_id = ((Tool) i.next()).getId();
10732:                        for (ListIterator j = toolIdList.listIterator(); j
10733:                                .hasNext();) {
10734:                            String toolId = (String) j.next();
10735:                            if (toolId.indexOf("assignment") != -1
10736:                                    && toolId.equals(tool_id)
10737:                                    || toolId.indexOf("assignment") == -1
10738:                                    && toolId.indexOf(tool_id) != -1) {
10739:                                rv.add(toolId);
10740:                            }
10741:                        }
10742:                    }
10743:                }
10744:                return rv;
10745:
10746:            } // orderToolIds
10747:
10748:            private void setupFormNamesAndConstants(SessionState state) {
10749:                TimeBreakdown timeBreakdown = (TimeService.newTime())
10750:                        .breakdownLocal();
10751:                String mycopyright = COPYRIGHT_SYMBOL
10752:                        + " "
10753:                        + timeBreakdown.getYear()
10754:                        + ", "
10755:                        + UserDirectoryService.getCurrentUser()
10756:                                .getDisplayName() + ". All Rights Reserved. ";
10757:                state.setAttribute(STATE_MY_COPYRIGHT, mycopyright);
10758:                state.setAttribute(STATE_SITE_INSTANCE_ID, null);
10759:                state.setAttribute(STATE_INITIALIZED, Boolean.TRUE.toString());
10760:                SiteInfo siteInfo = new SiteInfo();
10761:                Participant participant = new Participant();
10762:                participant.name = NULL_STRING;
10763:                participant.uniqname = NULL_STRING;
10764:                state.setAttribute(STATE_SITE_INFO, siteInfo);
10765:                state.setAttribute("form_participantToAdd", participant);
10766:                state.setAttribute(FORM_ADDITIONAL, NULL_STRING);
10767:                // legacy
10768:                state.setAttribute(FORM_HONORIFIC, "0");
10769:                state.setAttribute(FORM_REUSE, "0");
10770:                state.setAttribute(FORM_RELATED_CLASS, "0");
10771:                state.setAttribute(FORM_RELATED_PROJECT, "0");
10772:                state.setAttribute(FORM_INSTITUTION, "0");
10773:                // sundry form variables
10774:                state.setAttribute(FORM_PHONE, "");
10775:                state.setAttribute(FORM_EMAIL, "");
10776:                state.setAttribute(FORM_SUBJECT, "");
10777:                state.setAttribute(FORM_DESCRIPTION, "");
10778:                state.setAttribute(FORM_TITLE, "");
10779:                state.setAttribute(FORM_NAME, "");
10780:                state.setAttribute(FORM_SHORT_DESCRIPTION, "");
10781:
10782:            } // setupFormNamesAndConstants
10783:
10784:            /**
10785:             * Add these Unit affliates to sites in these Subject areas with Instructor
10786:             * role
10787:             * 
10788:             */
10789:            private void setupSubjectAffiliates(SessionState state) {
10790:                Vector affiliates = new Vector();
10791:
10792:                List subjectList = new Vector();
10793:                List campusList = new Vector();
10794:                List uniqnameList = new Vector();
10795:
10796:                // get term information
10797:                if (ServerConfigurationService.getStrings("affiliatesubjects") != null) {
10798:                    subjectList = new ArrayList(Arrays
10799:                            .asList(ServerConfigurationService
10800:                                    .getStrings("affiliatesubjects")));
10801:                }
10802:                if (ServerConfigurationService.getStrings("affiliatecampus") != null) {
10803:                    campusList = new ArrayList(Arrays
10804:                            .asList(ServerConfigurationService
10805:                                    .getStrings("affiliatecampus")));
10806:                }
10807:                if (ServerConfigurationService.getStrings("affiliateuniqnames") != null) {
10808:                    uniqnameList = new ArrayList(Arrays
10809:                            .asList(ServerConfigurationService
10810:                                    .getStrings("affiliateuniqnames")));
10811:                }
10812:
10813:                if (subjectList.size() > 0
10814:                        && subjectList.size() == campusList.size()
10815:                        && subjectList.size() == uniqnameList.size()) {
10816:                    for (int i = 0; i < subjectList.size(); i++) {
10817:                        String[] subjectFields = ((String) subjectList.get(i))
10818:                                .split(",");
10819:                        String[] uniqnameFields = ((String) uniqnameList.get(i))
10820:                                .split(",");
10821:                        String campus = (String) campusList.get(i);
10822:
10823:                        for (int j = 0; j < subjectFields.length; j++) {
10824:                            String subject = StringUtil
10825:                                    .trimToZero(subjectFields[j]);
10826:
10827:                            SubjectAffiliates affiliate = new SubjectAffiliates();
10828:                            affiliate.setSubject(subject);
10829:                            affiliate.setCampus(campus);
10830:
10831:                            for (int k = 0; k < uniqnameFields.length; k++) {
10832:                                affiliate.getUniqnames().add(
10833:                                        StringUtil
10834:                                                .trimToZero(uniqnameFields[k]));
10835:                            }
10836:                            affiliates.add(affiliate);
10837:                        }
10838:                    }
10839:                }
10840:
10841:                state.setAttribute(STATE_SUBJECT_AFFILIATES, affiliates);
10842:
10843:            } // setupSubjectAffiliates
10844:
10845:            /**
10846:             * setupSkins
10847:             * 
10848:             */
10849:            private void setupIcons(SessionState state) {
10850:                List icons = new Vector();
10851:
10852:                String[] iconNames = null;
10853:                String[] iconUrls = null;
10854:                String[] iconSkins = null;
10855:
10856:                // get icon information
10857:                if (ServerConfigurationService.getStrings("iconNames") != null) {
10858:                    iconNames = ServerConfigurationService
10859:                            .getStrings("iconNames");
10860:                }
10861:                if (ServerConfigurationService.getStrings("iconUrls") != null) {
10862:                    iconUrls = ServerConfigurationService
10863:                            .getStrings("iconUrls");
10864:                }
10865:                if (ServerConfigurationService.getStrings("iconSkins") != null) {
10866:                    iconSkins = ServerConfigurationService
10867:                            .getStrings("iconSkins");
10868:                }
10869:
10870:                if ((iconNames != null) && (iconUrls != null)
10871:                        && (iconSkins != null)
10872:                        && (iconNames.length == iconUrls.length)
10873:                        && (iconNames.length == iconSkins.length)) {
10874:                    for (int i = 0; i < iconNames.length; i++) {
10875:                        Icon s = new Icon(StringUtil
10876:                                .trimToNull((String) iconNames[i]), StringUtil
10877:                                .trimToNull((String) iconUrls[i]), StringUtil
10878:                                .trimToNull((String) iconSkins[i]));
10879:                        icons.add(s);
10880:                    }
10881:                }
10882:
10883:                state.setAttribute(STATE_ICONS, icons);
10884:            }
10885:
10886:            private void setAppearance(SessionState state, Site edit,
10887:                    String iconUrl) {
10888:                // set the icon
10889:                edit.setIconUrl(iconUrl);
10890:                if (iconUrl == null) {
10891:                    // this is the default case - no icon, no (default) skin
10892:                    edit.setSkin(null);
10893:                    return;
10894:                }
10895:
10896:                // if this icon is in the config appearance list, find a skin to set
10897:                List icons = (List) state.getAttribute(STATE_ICONS);
10898:                for (Iterator i = icons.iterator(); i.hasNext();) {
10899:                    Icon icon = (Icon) i.next();
10900:                    if (!StringUtil.different(icon.getUrl(), iconUrl)) {
10901:                        edit.setSkin(icon.getSkin());
10902:                        return;
10903:                    }
10904:                }
10905:            }
10906:
10907:            /**
10908:             * A dispatch funtion when selecting course features
10909:             */
10910:            public void doAdd_features(RunData data) {
10911:                SessionState state = ((JetspeedRunData) data)
10912:                        .getPortletSessionState(((JetspeedRunData) data)
10913:                                .getJs_peid());
10914:                ParameterParser params = data.getParameters();
10915:
10916:                String option = params.getString("option");
10917:
10918:                if (option.equalsIgnoreCase("addNews")) {
10919:                    updateSelectedToolList(state, params, false);
10920:                    insertTool(state, "sakai.news", STATE_NEWS_TITLES,
10921:                            NEWS_DEFAULT_TITLE, STATE_NEWS_URLS,
10922:                            NEWS_DEFAULT_URL, Integer.parseInt(params
10923:                                    .getString("newsNum")));
10924:                    state.setAttribute(STATE_TEMPLATE_INDEX, "26");
10925:                } else if (option.equalsIgnoreCase("addWC")) {
10926:                    updateSelectedToolList(state, params, false);
10927:                    insertTool(state, "sakai.iframe", STATE_WEB_CONTENT_TITLES,
10928:                            WEB_CONTENT_DEFAULT_TITLE, STATE_WEB_CONTENT_URLS,
10929:                            WEB_CONTENT_DEFAULT_URL, Integer.parseInt(params
10930:                                    .getString("wcNum")));
10931:                    state.setAttribute(STATE_TEMPLATE_INDEX, "26");
10932:                } else if (option.equalsIgnoreCase("import")) {
10933:                    // import or not
10934:                    updateSelectedToolList(state, params, false);
10935:                    String importSites = params.getString("import");
10936:                    if (importSites != null
10937:                            && importSites.equalsIgnoreCase(Boolean.TRUE
10938:                                    .toString())) {
10939:                        state.setAttribute(STATE_IMPORT, Boolean.TRUE);
10940:                        if (importSites.equalsIgnoreCase(Boolean.TRUE
10941:                                .toString())) {
10942:                            state.removeAttribute(STATE_IMPORT);
10943:                            state.removeAttribute(STATE_IMPORT_SITES);
10944:                            state.removeAttribute(STATE_IMPORT_SITE_TOOL);
10945:                        }
10946:                    } else {
10947:                        state.removeAttribute(STATE_IMPORT);
10948:                    }
10949:                } else if (option.equalsIgnoreCase("continue")) {
10950:                    // continue
10951:                    doContinue(data);
10952:                } else if (option.equalsIgnoreCase("back")) {
10953:                    // back
10954:                    doBack(data);
10955:                } else if (option.equalsIgnoreCase("cancel")) {
10956:                    // cancel
10957:                    doCancel_create(data);
10958:                }
10959:
10960:            } // doAdd_features
10961:
10962:            /**
10963:             * update the selected tool list
10964:             * 
10965:             * @param params
10966:             *            The ParameterParser object
10967:             * @param verifyData
10968:             *            Need to verify input data or not
10969:             */
10970:            private void updateSelectedToolList(SessionState state,
10971:                    ParameterParser params, boolean verifyData) {
10972:                List selectedTools = new ArrayList(Arrays.asList(params
10973:                        .getStrings("selectedTools")));
10974:
10975:                Hashtable titles = (Hashtable) state
10976:                        .getAttribute(STATE_NEWS_TITLES);
10977:                Hashtable urls = (Hashtable) state
10978:                        .getAttribute(STATE_NEWS_URLS);
10979:                Hashtable wcTitles = (Hashtable) state
10980:                        .getAttribute(STATE_WEB_CONTENT_TITLES);
10981:                Hashtable wcUrls = (Hashtable) state
10982:                        .getAttribute(STATE_WEB_CONTENT_URLS);
10983:                boolean has_home = false;
10984:                String emailId = null;
10985:
10986:                for (int i = 0; i < selectedTools.size(); i++) {
10987:                    String id = (String) selectedTools.get(i);
10988:                    if (id.indexOf("sakai.news") != -1) {
10989:                        String title = StringUtil.trimToNull(params
10990:                                .getString("titlefor" + id));
10991:                        if (title == null) {
10992:                            // if there is no input, make the title for news tool
10993:                            // default to NEWS_DEFAULT_TITLE
10994:                            title = NEWS_DEFAULT_TITLE;
10995:                        }
10996:                        titles.put(id, title);
10997:
10998:                        String url = StringUtil.trimToNull(params
10999:                                .getString("urlfor" + id));
11000:                        if (url == null) {
11001:                            // if there is no input, make the title for news tool
11002:                            // default to NEWS_DEFAULT_URL
11003:                            url = NEWS_DEFAULT_URL;
11004:                        }
11005:                        urls.put(id, url);
11006:
11007:                        try {
11008:                            new URL(url);
11009:                        } catch (MalformedURLException e) {
11010:                            addAlert(state, rb.getString("java.invurl") + " "
11011:                                    + url + ". ");
11012:                        }
11013:                    } else if (id.indexOf("sakai.iframe") != -1) {
11014:                        String wcTitle = StringUtil.trimToNull(params
11015:                                .getString("titlefor" + id));
11016:                        if (wcTitle == null) {
11017:                            // if there is no input, make the title for Web Content tool
11018:                            // default to WEB_CONTENT_DEFAULT_TITLE
11019:                            wcTitle = WEB_CONTENT_DEFAULT_TITLE;
11020:                        }
11021:                        wcTitles.put(id, wcTitle);
11022:
11023:                        String wcUrl = StringUtil.trimToNull(params
11024:                                .getString("urlfor" + id));
11025:                        if (wcUrl == null) {
11026:                            // if there is no input, make the title for Web Content tool
11027:                            // default to WEB_CONTENT_DEFAULT_URL
11028:                            wcUrl = WEB_CONTENT_DEFAULT_URL;
11029:                        } else {
11030:                            if ((wcUrl.length() > 0)
11031:                                    && (!wcUrl.startsWith("/"))
11032:                                    && (wcUrl.indexOf("://") == -1)) {
11033:                                wcUrl = "http://" + wcUrl;
11034:                            }
11035:                        }
11036:                        wcUrls.put(id, wcUrl);
11037:                    } else if (id.equalsIgnoreCase(HOME_TOOL_ID)) {
11038:                        has_home = true;
11039:                    } else if (id.equalsIgnoreCase("sakai.mailbox")) {
11040:                        // if Email archive tool is selected, check the email alias
11041:                        emailId = StringUtil.trimToNull(params
11042:                                .getString("emailId"));
11043:                        if (verifyData) {
11044:                            if (emailId == null) {
11045:                                addAlert(state, rb
11046:                                        .getString("java.emailarchive")
11047:                                        + " ");
11048:                            } else {
11049:                                if (!Validator.checkEmailLocal(emailId)) {
11050:                                    addAlert(state, rb
11051:                                            .getString("java.theemail"));
11052:                                } else {
11053:                                    // check to see whether the alias has been used by
11054:                                    // other sites
11055:                                    try {
11056:                                        String target = AliasService
11057:                                                .getTarget(emailId);
11058:                                        if (target != null) {
11059:                                            if (state
11060:                                                    .getAttribute(STATE_SITE_INSTANCE_ID) != null) {
11061:                                                String siteId = (String) state
11062:                                                        .getAttribute(STATE_SITE_INSTANCE_ID);
11063:                                                String channelReference = mailArchiveChannelReference(siteId);
11064:                                                if (!target
11065:                                                        .equals(channelReference)) {
11066:                                                    // the email alias is not used by
11067:                                                    // current site
11068:                                                    addAlert(
11069:                                                            state,
11070:                                                            rb
11071:                                                                    .getString("java.emailinuse")
11072:                                                                    + " ");
11073:                                                }
11074:                                            } else {
11075:                                                addAlert(
11076:                                                        state,
11077:                                                        rb
11078:                                                                .getString("java.emailinuse")
11079:                                                                + " ");
11080:                                            }
11081:                                        }
11082:                                    } catch (IdUnusedException ee) {
11083:                                    }
11084:                                }
11085:                            }
11086:                        }
11087:                    }
11088:                }
11089:                state.setAttribute(STATE_TOOL_HOME_SELECTED, new Boolean(
11090:                        has_home));
11091:                state.setAttribute(STATE_TOOL_EMAIL_ADDRESS, emailId);
11092:                state.setAttribute(STATE_NEWS_TITLES, titles);
11093:                state.setAttribute(STATE_NEWS_URLS, urls);
11094:                state.setAttribute(STATE_WEB_CONTENT_TITLES, wcTitles);
11095:                state.setAttribute(STATE_WEB_CONTENT_URLS, wcUrls);
11096:            } // updateSelectedToolList
11097:
11098:            /**
11099:             * find the tool in the tool list and insert another tool instance to the
11100:             * list
11101:             * 
11102:             * @param state
11103:             *            SessionState object
11104:             * @param toolId
11105:             *            The id for the inserted tool
11106:             * @param stateTitlesVariable
11107:             *            The titles
11108:             * @param defaultTitle
11109:             *            The default title for the inserted tool
11110:             * @param stateUrlsVariable
11111:             *            The urls
11112:             * @param defaultUrl
11113:             *            The default url for the inserted tool
11114:             * @param insertTimes
11115:             *            How many tools need to be inserted
11116:             */
11117:            private void insertTool(SessionState state, String toolId,
11118:                    String stateTitlesVariable, String defaultTitle,
11119:                    String stateUrlsVariable, String defaultUrl, int insertTimes) {
11120:                // the list of available tools
11121:                List toolList = (List) state
11122:                        .getAttribute(STATE_TOOL_REGISTRATION_LIST);
11123:                int toolListedTimes = 0;
11124:                int index = 0;
11125:                int insertIndex = 0;
11126:                while (index < toolList.size()) {
11127:                    MyTool tListed = (MyTool) toolList.get(index);
11128:                    if (tListed.getId().indexOf(toolId) != -1) {
11129:                        toolListedTimes++;
11130:                    }
11131:
11132:                    if (toolListedTimes > 0 && insertIndex == 0) {
11133:                        // update the insert index
11134:                        insertIndex = index;
11135:                    }
11136:
11137:                    index++;
11138:                }
11139:
11140:                List toolSelected = (List) state
11141:                        .getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST);
11142:
11143:                // the titles
11144:                Hashtable titles = (Hashtable) state
11145:                        .getAttribute(stateTitlesVariable);
11146:                if (titles == null) {
11147:                    titles = new Hashtable();
11148:                }
11149:
11150:                // the urls
11151:                Hashtable urls = (Hashtable) state
11152:                        .getAttribute(stateUrlsVariable);
11153:                if (urls == null) {
11154:                    urls = new Hashtable();
11155:                }
11156:
11157:                // insert multiple tools
11158:                for (int i = 0; i < insertTimes; i++) {
11159:                    toolListedTimes = toolListedTimes + i;
11160:
11161:                    toolSelected.add(toolId + toolListedTimes);
11162:
11163:                    // We need to insert a specific tool entry only if all the specific
11164:                    // tool entries have been selected
11165:                    MyTool newTool = new MyTool();
11166:                    newTool.title = defaultTitle;
11167:                    newTool.id = toolId + toolListedTimes;
11168:                    toolList.add(insertIndex, newTool);
11169:                    titles.put(newTool.id, defaultTitle);
11170:                    urls.put(newTool.id, defaultUrl);
11171:                }
11172:
11173:                state.setAttribute(STATE_TOOL_REGISTRATION_LIST, toolList);
11174:                state.setAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST,
11175:                        toolSelected);
11176:                state.setAttribute(stateTitlesVariable, titles);
11177:                state.setAttribute(stateUrlsVariable, urls);
11178:
11179:            } // insertTool
11180:
11181:            /**
11182:             * 
11183:             * set selected participant role Hashtable
11184:             */
11185:            private void setSelectedParticipantRoles(SessionState state) {
11186:                List selectedUserIds = (List) state
11187:                        .getAttribute(STATE_SELECTED_USER_LIST);
11188:                List participantList = (List) state
11189:                        .getAttribute(STATE_PARTICIPANT_LIST);
11190:                List selectedParticipantList = new Vector();
11191:
11192:                Hashtable selectedParticipantRoles = new Hashtable();
11193:
11194:                if (!selectedUserIds.isEmpty() && participantList != null) {
11195:                    for (int i = 0; i < participantList.size(); i++) {
11196:                        String id = "";
11197:                        Object o = (Object) participantList.get(i);
11198:                        if (o.getClass().equals(Participant.class)) {
11199:                            // get participant roles
11200:                            id = ((Participant) o).getUniqname();
11201:                            selectedParticipantRoles.put(id, ((Participant) o)
11202:                                    .getRole());
11203:                        } else if (o.getClass().equals(Student.class)) {
11204:                            // get participant from roster role
11205:                            id = ((Student) o).getUniqname();
11206:                            selectedParticipantRoles.put(id, ((Student) o)
11207:                                    .getRole());
11208:                        }
11209:                        if (selectedUserIds.contains(id)) {
11210:                            selectedParticipantList.add(participantList.get(i));
11211:                        }
11212:                    }
11213:                }
11214:                state.setAttribute(STATE_SELECTED_PARTICIPANT_ROLES,
11215:                        selectedParticipantRoles);
11216:                state.setAttribute(STATE_SELECTED_PARTICIPANTS,
11217:                        selectedParticipantList);
11218:
11219:            } // setSelectedParticipantRol3es
11220:
11221:            /**
11222:             * the SiteComparator class
11223:             */
11224:            private class SiteComparator implements  Comparator {
11225:
11226:                Collator collator = Collator.getInstance();
11227:
11228:                /**
11229:                 * the criteria
11230:                 */
11231:                String m_criterion = null;
11232:
11233:                String m_asc = null;
11234:
11235:                /**
11236:                 * constructor
11237:                 * 
11238:                 * @param criteria
11239:                 *            The sort criteria string
11240:                 * @param asc
11241:                 *            The sort order string. TRUE_STRING if ascending; "false"
11242:                 *            otherwise.
11243:                 */
11244:                public SiteComparator(String criterion, String asc) {
11245:                    m_criterion = criterion;
11246:                    m_asc = asc;
11247:
11248:                } // constructor
11249:
11250:                /**
11251:                 * implementing the Comparator compare function
11252:                 * 
11253:                 * @param o1
11254:                 *            The first object
11255:                 * @param o2
11256:                 *            The second object
11257:                 * @return The compare result. 1 is o1 < o2; -1 otherwise
11258:                 */
11259:                public int compare(Object o1, Object o2) {
11260:                    int result = -1;
11261:
11262:                    if (m_criterion == null)
11263:                        m_criterion = SORTED_BY_TITLE;
11264:
11265:                    /** *********** for sorting site list ****************** */
11266:                    if (m_criterion.equals(SORTED_BY_TITLE)) {
11267:                        // sorted by the worksite title
11268:                        String s1 = ((Site) o1).getTitle();
11269:                        String s2 = ((Site) o2).getTitle();
11270:                        result = compareString(s1, s2);
11271:                    } else if (m_criterion.equals(SORTED_BY_DESCRIPTION)) {
11272:
11273:                        // sorted by the site short description
11274:                        String s1 = ((Site) o1).getShortDescription();
11275:                        String s2 = ((Site) o2).getShortDescription();
11276:                        result = compareString(s1, s2);
11277:                    } else if (m_criterion.equals(SORTED_BY_TYPE)) {
11278:                        // sorted by the site type
11279:                        String s1 = ((Site) o1).getType();
11280:                        String s2 = ((Site) o2).getType();
11281:                        result = compareString(s1, s2);
11282:                    } else if (m_criterion.equals(SortType.CREATED_BY_ASC
11283:                            .toString())) {
11284:                        // sorted by the site creator
11285:                        String s1 = ((Site) o1).getProperties().getProperty(
11286:                                "CHEF:creator");
11287:                        String s2 = ((Site) o2).getProperties().getProperty(
11288:                                "CHEF:creator");
11289:                        result = compareString(s1, s2);
11290:                    } else if (m_criterion.equals(SORTED_BY_STATUS)) {
11291:                        // sort by the status, published or unpublished
11292:                        int i1 = ((Site) o1).isPublished() ? 1 : 0;
11293:                        int i2 = ((Site) o2).isPublished() ? 1 : 0;
11294:                        if (i1 > i2) {
11295:                            result = 1;
11296:                        } else {
11297:                            result = -1;
11298:                        }
11299:                    } else if (m_criterion.equals(SORTED_BY_JOINABLE)) {
11300:                        // sort by whether the site is joinable or not
11301:                        boolean b1 = ((Site) o1).isJoinable();
11302:                        boolean b2 = ((Site) o2).isJoinable();
11303:                        if (b1 == b2) {
11304:                            result = 0;
11305:                        } else if (b1 == true) {
11306:                            result = 1;
11307:                        } else {
11308:                            result = -1;
11309:                        }
11310:                    } else if (m_criterion.equals(SORTED_BY_PARTICIPANT_NAME)) {
11311:                        // sort by whether the site is joinable or not
11312:                        String s1 = null;
11313:                        if (o1.getClass().equals(Participant.class)) {
11314:                            s1 = ((Participant) o1).getName();
11315:                        }
11316:
11317:                        String s2 = null;
11318:                        if (o2.getClass().equals(Participant.class)) {
11319:                            s2 = ((Participant) o2).getName();
11320:                        }
11321:
11322:                        result = compareString(s1, s2);
11323:
11324:                    } else if (m_criterion
11325:                            .equals(SORTED_BY_PARTICIPANT_UNIQNAME)) {
11326:                        // sort by whether the site is joinable or not
11327:                        String s1 = null;
11328:                        if (o1.getClass().equals(Participant.class)) {
11329:                            s1 = ((Participant) o1).getUniqname();
11330:                        }
11331:
11332:                        String s2 = null;
11333:                        if (o2.getClass().equals(Participant.class)) {
11334:                            s2 = ((Participant) o2).getUniqname();
11335:                        }
11336:
11337:                        result = compareString(s1, s2);
11338:                    } else if (m_criterion.equals(SORTED_BY_PARTICIPANT_ROLE)) {
11339:                        String s1 = "";
11340:                        if (o1.getClass().equals(Participant.class)) {
11341:                            s1 = ((Participant) o1).getRole();
11342:                        }
11343:
11344:                        String s2 = "";
11345:                        if (o2.getClass().equals(Participant.class)) {
11346:                            s2 = ((Participant) o2).getRole();
11347:                        }
11348:
11349:                        result = compareString(s1, s2);
11350:                    } else if (m_criterion.equals(SORTED_BY_PARTICIPANT_COURSE)) {
11351:                        // sort by whether the site is joinable or not
11352:                        String s1 = null;
11353:                        if (o1.getClass().equals(Participant.class)) {
11354:                            s1 = ((Participant) o1).getCourse();
11355:                        }
11356:
11357:                        String s2 = null;
11358:                        if (o2.getClass().equals(Participant.class)) {
11359:                            s2 = ((Participant) o2).getCourse();
11360:                        }
11361:
11362:                        result = compareString(s1, s2);
11363:                    } else if (m_criterion.equals(SORTED_BY_PARTICIPANT_ID)) {
11364:                        String s1 = null;
11365:                        if (o1.getClass().equals(Participant.class)) {
11366:                            s1 = ((Participant) o1).getRegId();
11367:                        }
11368:
11369:                        String s2 = null;
11370:                        if (o2.getClass().equals(Participant.class)) {
11371:                            s2 = ((Participant) o2).getRegId();
11372:                        }
11373:
11374:                        result = compareString(s1, s2);
11375:                    } else if (m_criterion
11376:                            .equals(SORTED_BY_PARTICIPANT_CREDITS)) {
11377:                        String s1 = null;
11378:                        if (o1.getClass().equals(Participant.class)) {
11379:                            s1 = ((Participant) o1).getCredits();
11380:                        }
11381:
11382:                        String s2 = null;
11383:                        if (o2.getClass().equals(Participant.class)) {
11384:                            s2 = ((Participant) o2).getCredits();
11385:                        }
11386:
11387:                        result = compareString(s1, s2);
11388:                    } else if (m_criterion.equals(SORTED_BY_CREATION_DATE)) {
11389:                        // sort by the site's creation date
11390:                        Time t1 = null;
11391:                        Time t2 = null;
11392:
11393:                        // get the times
11394:                        try {
11395:                            t1 = ((Site) o1).getProperties().getTimeProperty(
11396:                                    ResourceProperties.PROP_CREATION_DATE);
11397:                        } catch (EntityPropertyNotDefinedException e) {
11398:                        } catch (EntityPropertyTypeException e) {
11399:                        }
11400:
11401:                        try {
11402:                            t2 = ((Site) o2).getProperties().getTimeProperty(
11403:                                    ResourceProperties.PROP_CREATION_DATE);
11404:                        } catch (EntityPropertyNotDefinedException e) {
11405:                        } catch (EntityPropertyTypeException e) {
11406:                        }
11407:                        if (t1 == null) {
11408:                            result = -1;
11409:                        } else if (t2 == null) {
11410:                            result = 1;
11411:                        } else if (t1.before(t2)) {
11412:                            result = -1;
11413:                        } else {
11414:                            result = 1;
11415:                        }
11416:                    } else if (m_criterion.equals(rb.getString("group.title"))) {
11417:                        // sorted by the group title
11418:                        String s1 = ((Group) o1).getTitle();
11419:                        String s2 = ((Group) o2).getTitle();
11420:                        result = compareString(s1, s2);
11421:                    } else if (m_criterion.equals(rb.getString("group.number"))) {
11422:                        // sorted by the group title
11423:                        int n1 = ((Group) o1).getMembers().size();
11424:                        int n2 = ((Group) o2).getMembers().size();
11425:                        result = (n1 > n2) ? 1 : -1;
11426:                    } else if (m_criterion.equals(SORTED_BY_MEMBER_NAME)) {
11427:                        // sorted by the member name
11428:                        String s1 = null;
11429:                        String s2 = null;
11430:
11431:                        try {
11432:                            s1 = UserDirectoryService.getUser(
11433:                                    ((Member) o1).getUserId()).getSortName();
11434:                        } catch (Exception ignore) {
11435:
11436:                        }
11437:
11438:                        try {
11439:                            s2 = UserDirectoryService.getUser(
11440:                                    ((Member) o2).getUserId()).getSortName();
11441:                        } catch (Exception ignore) {
11442:
11443:                        }
11444:                        result = compareString(s1, s2);
11445:                    }
11446:
11447:                    if (m_asc == null)
11448:                        m_asc = Boolean.TRUE.toString();
11449:
11450:                    // sort ascending or descending
11451:                    if (m_asc.equals(Boolean.FALSE.toString())) {
11452:                        result = -result;
11453:                    }
11454:
11455:                    return result;
11456:
11457:                } // compare
11458:
11459:                private int compareString(String s1, String s2) {
11460:                    int result;
11461:                    if (s1 == null && s2 == null) {
11462:                        result = 0;
11463:                    } else if (s2 == null) {
11464:                        result = 1;
11465:                    } else if (s1 == null) {
11466:                        result = -1;
11467:                    } else {
11468:                        result = collator.compare(s1, s2);
11469:                    }
11470:                    return result;
11471:                }
11472:
11473:            } // SiteComparator
11474:
11475:            private class ToolComparator implements  Comparator {
11476:                /**
11477:                 * implementing the Comparator compare function
11478:                 * 
11479:                 * @param o1
11480:                 *            The first object
11481:                 * @param o2
11482:                 *            The second object
11483:                 * @return The compare result. 1 is o1 < o2; 0 is o1.equals(o2); -1
11484:                 *         otherwise
11485:                 */
11486:                public int compare(Object o1, Object o2) {
11487:                    try {
11488:                        return ((Tool) o1).getTitle().compareTo(
11489:                                ((Tool) o2).getTitle());
11490:                    } catch (Exception e) {
11491:                    }
11492:                    return -1;
11493:
11494:                } // compare
11495:
11496:            } // ToolComparator
11497:
11498:            public class Icon {
11499:                protected String m_name = null;
11500:
11501:                protected String m_url = null;
11502:
11503:                protected String m_skin = null;
11504:
11505:                public Icon(String name, String url, String skin) {
11506:                    m_name = name;
11507:                    m_url = url;
11508:                    m_skin = skin;
11509:                }
11510:
11511:                public String getName() {
11512:                    return m_name;
11513:                }
11514:
11515:                public String getUrl() {
11516:                    return m_url;
11517:                }
11518:
11519:                public String getSkin() {
11520:                    return m_skin;
11521:                }
11522:            }
11523:
11524:            // a utility class for form select options
11525:            public class IdAndText {
11526:                public int id;
11527:
11528:                public String text;
11529:
11530:                public int getId() {
11531:                    return id;
11532:                }
11533:
11534:                public String getText() {
11535:                    return text;
11536:                }
11537:
11538:            } // IdAndText
11539:
11540:            // a utility class for working with ToolConfigurations and ToolRegistrations
11541:            // %%% convert featureList from IdAndText to Tool so getFeatures item.id =
11542:            // chosen-feature.id is a direct mapping of data
11543:            public class MyTool {
11544:                public String id = NULL_STRING;
11545:
11546:                public String title = NULL_STRING;
11547:
11548:                public String description = NULL_STRING;
11549:
11550:                public boolean selected = false;
11551:
11552:                public String getId() {
11553:                    return id;
11554:                }
11555:
11556:                public String getTitle() {
11557:                    return title;
11558:                }
11559:
11560:                public String getDescription() {
11561:                    return description;
11562:                }
11563:
11564:                public boolean getSelected() {
11565:                    return selected;
11566:                }
11567:
11568:            }
11569:
11570:            /*
11571:             * WorksiteSetupPage is a utility class for working with site pages
11572:             * configured by Worksite Setup
11573:             * 
11574:             */
11575:            public class WorksiteSetupPage {
11576:                public String pageId = NULL_STRING;
11577:
11578:                public String pageTitle = NULL_STRING;
11579:
11580:                public String toolId = NULL_STRING;
11581:
11582:                public String getPageId() {
11583:                    return pageId;
11584:                }
11585:
11586:                public String getPageTitle() {
11587:                    return pageTitle;
11588:                }
11589:
11590:                public String getToolId() {
11591:                    return toolId;
11592:                }
11593:
11594:            } // WorksiteSetupPage
11595:
11596:            /**
11597:             * Participant in site access roles
11598:             * 
11599:             */
11600:            public class Participant {
11601:                public String name = NULL_STRING;
11602:
11603:                // Note: uniqname is really a user ID
11604:                public String uniqname = NULL_STRING;
11605:
11606:                public String role = NULL_STRING;
11607:
11608:                /** role from provider */
11609:                public String providerRole = NULL_STRING;
11610:
11611:                /** The member credits */
11612:                protected String credits = NULL_STRING;
11613:
11614:                /** The course */
11615:                public String course = NULL_STRING;
11616:
11617:                /** The section */
11618:                public String section = NULL_STRING;
11619:
11620:                /** The regestration id */
11621:                public String regId = NULL_STRING;
11622:
11623:                /** removeable if not from provider */
11624:                public boolean removeable = true;
11625:
11626:                public String getName() {
11627:                    return name;
11628:                }
11629:
11630:                public String getUniqname() {
11631:                    return uniqname;
11632:                }
11633:
11634:                public String getRole() {
11635:                    return role;
11636:                } // cast to Role
11637:
11638:                public String getProviderRole() {
11639:                    return providerRole;
11640:                }
11641:
11642:                public boolean isRemoveable() {
11643:                    return removeable;
11644:                }
11645:
11646:                // extra info from provider
11647:                public String getCredits() {
11648:                    return credits;
11649:                } // getCredits
11650:
11651:                public String getCourse() {
11652:                    return course;
11653:                } // getCourse
11654:
11655:                public String getSection() {
11656:                    return section;
11657:                } // getSection
11658:
11659:                public String getRegId() {
11660:                    return regId;
11661:                } // getRegId
11662:
11663:                /**
11664:                 * Access the user eid, if we can find it - fall back to the id if not.
11665:                 * 
11666:                 * @return The user eid.
11667:                 */
11668:                public String getEid() {
11669:                    try {
11670:                        return UserDirectoryService.getUserEid(uniqname);
11671:                    } catch (UserNotDefinedException e) {
11672:                        return uniqname;
11673:                    }
11674:                }
11675:
11676:                /**
11677:                 * Access the user display id, if we can find it - fall back to the id
11678:                 * if not.
11679:                 * 
11680:                 * @return The user display id.
11681:                 */
11682:                public String getDisplayId() {
11683:                    try {
11684:                        User user = UserDirectoryService.getUser(uniqname);
11685:                        return user.getDisplayId();
11686:                    } catch (UserNotDefinedException e) {
11687:                        return uniqname;
11688:                    }
11689:                }
11690:
11691:            } // Participant
11692:
11693:            /**
11694:             * Student in roster
11695:             * 
11696:             */
11697:            public class Student {
11698:                public String name = NULL_STRING;
11699:
11700:                public String uniqname = NULL_STRING;
11701:
11702:                public String id = NULL_STRING;
11703:
11704:                public String level = NULL_STRING;
11705:
11706:                public String credits = NULL_STRING;
11707:
11708:                public String role = NULL_STRING;
11709:
11710:                public String course = NULL_STRING;
11711:
11712:                public String section = NULL_STRING;
11713:
11714:                public String getName() {
11715:                    return name;
11716:                }
11717:
11718:                public String getUniqname() {
11719:                    return uniqname;
11720:                }
11721:
11722:                public String getId() {
11723:                    return id;
11724:                }
11725:
11726:                public String getLevel() {
11727:                    return level;
11728:                }
11729:
11730:                public String getCredits() {
11731:                    return credits;
11732:                }
11733:
11734:                public String getRole() {
11735:                    return role;
11736:                }
11737:
11738:                public String getCourse() {
11739:                    return course;
11740:                }
11741:
11742:                public String getSection() {
11743:                    return section;
11744:                }
11745:
11746:            } // Student
11747:
11748:            public class SiteInfo {
11749:                public String site_id = NULL_STRING; // getId of Resource
11750:
11751:                public String external_id = NULL_STRING; // if matches site_id
11752:
11753:                // connects site with U-M
11754:                // course information
11755:
11756:                public String site_type = "";
11757:
11758:                public String iconUrl = NULL_STRING;
11759:
11760:                public String infoUrl = NULL_STRING;
11761:
11762:                public boolean joinable = false;
11763:
11764:                public String joinerRole = NULL_STRING;
11765:
11766:                public String title = NULL_STRING; // the short name of the site
11767:
11768:                public String short_description = NULL_STRING; // the short (20 char)
11769:
11770:                // description of the
11771:                // site
11772:
11773:                public String description = NULL_STRING; // the longer description of
11774:
11775:                // the site
11776:
11777:                public String additional = NULL_STRING; // additional information on
11778:
11779:                // crosslists, etc.
11780:
11781:                public boolean published = false;
11782:
11783:                public boolean include = true; // include the site in the Sites index;
11784:
11785:                // default is true.
11786:
11787:                public String site_contact_name = NULL_STRING; // site contact name
11788:
11789:                public String site_contact_email = NULL_STRING; // site contact email
11790:
11791:                public String getSiteId() {
11792:                    return site_id;
11793:                }
11794:
11795:                public String getSiteType() {
11796:                    return site_type;
11797:                }
11798:
11799:                public String getTitle() {
11800:                    return title;
11801:                }
11802:
11803:                public String getDescription() {
11804:                    return description;
11805:                }
11806:
11807:                public String getIconUrl() {
11808:                    return iconUrl;
11809:                }
11810:
11811:                public String getInfoUrll() {
11812:                    return infoUrl;
11813:                }
11814:
11815:                public boolean getJoinable() {
11816:                    return joinable;
11817:                }
11818:
11819:                public String getJoinerRole() {
11820:                    return joinerRole;
11821:                }
11822:
11823:                public String getAdditional() {
11824:                    return additional;
11825:                }
11826:
11827:                public boolean getPublished() {
11828:                    return published;
11829:                }
11830:
11831:                public boolean getInclude() {
11832:                    return include;
11833:                }
11834:
11835:                public String getSiteContactName() {
11836:                    return site_contact_name;
11837:                }
11838:
11839:                public String getSiteContactEmail() {
11840:                    return site_contact_email;
11841:                }
11842:
11843:            } // SiteInfo
11844:
11845:            // dissertation tool related
11846:            /**
11847:             * doFinish_grad_tools is called when creation of a Grad Tools site is
11848:             * confirmed
11849:             */
11850:            public void doFinish_grad_tools(RunData data) {
11851:                SessionState state = ((JetspeedRunData) data)
11852:                        .getPortletSessionState(((JetspeedRunData) data)
11853:                                .getJs_peid());
11854:                ParameterParser params = data.getParameters();
11855:
11856:                // set up for the coming template
11857:                state.setAttribute(STATE_TEMPLATE_INDEX, params
11858:                        .getString("continue"));
11859:                int index = Integer.valueOf(params.getString("template-index"))
11860:                        .intValue();
11861:                actionForTemplate("continue", index, params, state);
11862:
11863:                // add the pre-configured Grad Tools tools to a new site
11864:                addGradToolsFeatures(state);
11865:
11866:                // TODO: hard coding this frame id is fragile, portal dependent, and
11867:                // needs to be fixed -ggolden
11868:                // schedulePeerFrameRefresh("sitenav");
11869:                scheduleTopRefresh();
11870:
11871:                resetPaging(state);
11872:
11873:            }// doFinish_grad_tools
11874:
11875:            /**
11876:             * addGradToolsFeatures adds features to a new Grad Tools student site
11877:             * 
11878:             */
11879:            private void addGradToolsFeatures(SessionState state) {
11880:                Site edit = null;
11881:                Site template = null;
11882:
11883:                // get a unique id
11884:                String id = IdManager.createUuid();
11885:
11886:                // get the Grad Tools student site template
11887:                try {
11888:                    template = SiteService.getSite(SITE_GTS_TEMPLATE);
11889:                } catch (Exception e) {
11890:                    if (Log.isWarnEnabled())
11891:                        M_log.warn("addGradToolsFeatures template " + e);
11892:                }
11893:                if (template != null) {
11894:                    // create a new site based on the template
11895:                    try {
11896:                        edit = SiteService.addSite(id, template);
11897:                    } catch (Exception e) {
11898:                        if (Log.isWarnEnabled())
11899:                            M_log.warn("addGradToolsFeatures add/edit site "
11900:                                    + e);
11901:                    }
11902:
11903:                    // set the tab, etc.
11904:                    if (edit != null) {
11905:                        SiteInfo siteInfo = (SiteInfo) state
11906:                                .getAttribute(STATE_SITE_INFO);
11907:                        edit.setShortDescription(siteInfo.short_description);
11908:                        edit.setTitle(siteInfo.title);
11909:                        edit.setPublished(true);
11910:                        edit.setPubView(false);
11911:                        edit.setType(SITE_TYPE_GRADTOOLS_STUDENT);
11912:                        // ResourcePropertiesEdit rpe = edit.getPropertiesEdit();
11913:                        try {
11914:                            SiteService.save(edit);
11915:                        } catch (Exception e) {
11916:                            if (Log.isWarnEnabled())
11917:                                M_log.warn("addGradToolsFeartures commitEdit "
11918:                                        + e);
11919:                        }
11920:
11921:                        // now that the site and realm exist, we can set the email alias
11922:                        // set the GradToolsStudent site alias as:
11923:                        // gradtools-uniqname@servername
11924:                        String alias = "gradtools-"
11925:                                + SessionManager.getCurrentSessionUserId();
11926:                        String channelReference = mailArchiveChannelReference(id);
11927:                        try {
11928:                            AliasService.setAlias(alias, channelReference);
11929:                        } catch (IdUsedException ee) {
11930:                            addAlert(state, rb.getString("java.alias") + " "
11931:                                    + alias + " " + rb.getString("java.exists"));
11932:                        } catch (IdInvalidException ee) {
11933:                            addAlert(state, rb.getString("java.alias") + " "
11934:                                    + alias + " "
11935:                                    + rb.getString("java.isinval"));
11936:                        } catch (PermissionException ee) {
11937:                            M_log
11938:                                    .warn(SessionManager
11939:                                            .getCurrentSessionUserId()
11940:                                            + " does not have permission to add alias. ");
11941:                        }
11942:                    }
11943:                }
11944:
11945:            } // addGradToolsFeatures
11946:
11947:            /**
11948:             * handle with add site options
11949:             * 
11950:             */
11951:            public void doAdd_site_option(RunData data) {
11952:                String option = data.getParameters().getString("option");
11953:                if (option.equals("finish")) {
11954:                    doFinish(data);
11955:                } else if (option.equals("cancel")) {
11956:                    doCancel_create(data);
11957:                } else if (option.equals("back")) {
11958:                    doBack(data);
11959:                }
11960:            } // doAdd_site_option
11961:
11962:            /**
11963:             * handle with duplicate site options
11964:             * 
11965:             */
11966:            public void doDuplicate_site_option(RunData data) {
11967:                String option = data.getParameters().getString("option");
11968:                if (option.equals("duplicate")) {
11969:                    doContinue(data);
11970:                } else if (option.equals("cancel")) {
11971:                    doCancel(data);
11972:                } else if (option.equals("finish")) {
11973:                    doContinue(data);
11974:                }
11975:            } // doDuplicate_site_option
11976:
11977:            /**
11978:             * Special check against the Dissertation service, which might not be
11979:             * here...
11980:             * 
11981:             * @return
11982:             */
11983:            protected boolean isGradToolsCandidate(String userId) {
11984:                // DissertationService.isCandidate(userId) - but the hard way
11985:
11986:                Object service = ComponentManager
11987:                        .get("org.sakaiproject.api.app.dissertation.DissertationService");
11988:                if (service == null)
11989:                    return false;
11990:
11991:                // the method signature
11992:                Class[] signature = new Class[1];
11993:                signature[0] = String.class;
11994:
11995:                // the method name
11996:                String methodName = "isCandidate";
11997:
11998:                // find a method of this class with this name and signature
11999:                try {
12000:                    Method method = service.getClass().getMethod(methodName,
12001:                            signature);
12002:
12003:                    // the parameters
12004:                    Object[] args = new Object[1];
12005:                    args[0] = userId;
12006:
12007:                    // make the call
12008:                    Boolean rv = (Boolean) method.invoke(service, args);
12009:                    return rv.booleanValue();
12010:                } catch (Throwable t) {
12011:                }
12012:
12013:                return false;
12014:            }
12015:
12016:            /**
12017:             * User has a Grad Tools student site
12018:             * 
12019:             * @return
12020:             */
12021:            protected boolean hasGradToolsStudentSite(String userId) {
12022:                boolean has = false;
12023:                int n = 0;
12024:                try {
12025:                    n = SiteService
12026:                            .countSites(
12027:                                    org.sakaiproject.site.api.SiteService.SelectionType.UPDATE,
12028:                                    SITE_TYPE_GRADTOOLS_STUDENT, null, null);
12029:                    if (n > 0)
12030:                        has = true;
12031:                } catch (Exception e) {
12032:                    if (Log.isWarnEnabled())
12033:                        M_log.warn("hasGradToolsStudentSite " + e);
12034:                }
12035:
12036:                return has;
12037:
12038:            }// hasGradToolsStudentSite
12039:
12040:            /**
12041:             * Get the mail archive channel reference for the main container placement
12042:             * for this site.
12043:             * 
12044:             * @param siteId
12045:             *            The site id.
12046:             * @return The mail archive channel reference for this site.
12047:             */
12048:            protected String mailArchiveChannelReference(String siteId) {
12049:                MailArchiveService m = (org.sakaiproject.mailarchive.api.MailArchiveService) ComponentManager
12050:                        .get("org.sakaiproject.mailarchive.api.MailArchiveService");
12051:
12052:                if (m != null) {
12053:                    return m.channelReference(siteId,
12054:                            SiteService.MAIN_CONTAINER);
12055:                } else {
12056:                    return "";
12057:                }
12058:            }
12059:
12060:            /**
12061:             * Transfer a copy of all entites from another context for any entity
12062:             * producer that claims this tool id.
12063:             * 
12064:             * @param toolId
12065:             *            The tool id.
12066:             * @param fromContext
12067:             *            The context to import from.
12068:             * @param toContext
12069:             *            The context to import into.
12070:             */
12071:            protected void transferCopyEntities(String toolId,
12072:                    String fromContext, String toContext) {
12073:                // TODO: used to offer to resources first - why? still needed? -ggolden
12074:
12075:                // offer to all EntityProducers
12076:                for (Iterator i = EntityManager.getEntityProducers().iterator(); i
12077:                        .hasNext();) {
12078:                    EntityProducer ep = (EntityProducer) i.next();
12079:                    if (ep instanceof  EntityTransferrer) {
12080:                        try {
12081:                            EntityTransferrer et = (EntityTransferrer) ep;
12082:
12083:                            // if this producer claims this tool id
12084:                            if (ArrayUtil.contains(et.myToolIds(), toolId)) {
12085:                                et.transferCopyEntities(fromContext, toContext,
12086:                                        new Vector());
12087:                            }
12088:                        } catch (Throwable t) {
12089:                            M_log
12090:                                    .warn(
12091:                                            "Error encountered while asking EntityTransfer to transferCopyEntities from: "
12092:                                                    + fromContext + " to: "
12093:                                                    + toContext, t);
12094:                        }
12095:                    }
12096:                }
12097:            }
12098:
12099:            /**
12100:             * @return Get a list of all tools that support the import (transfer copy)
12101:             *         option
12102:             */
12103:            protected Set importTools() {
12104:                HashSet rv = new HashSet();
12105:
12106:                // offer to all EntityProducers
12107:                for (Iterator i = EntityManager.getEntityProducers().iterator(); i
12108:                        .hasNext();) {
12109:                    EntityProducer ep = (EntityProducer) i.next();
12110:                    if (ep instanceof  EntityTransferrer) {
12111:                        EntityTransferrer et = (EntityTransferrer) ep;
12112:
12113:                        String[] tools = et.myToolIds();
12114:                        if (tools != null) {
12115:                            for (int t = 0; t < tools.length; t++) {
12116:                                rv.add(tools[t]);
12117:                            }
12118:                        }
12119:                    }
12120:                }
12121:
12122:                return rv;
12123:            }
12124:
12125:            /**
12126:             * @param state
12127:             * @return Get a list of all tools that should be included as options for
12128:             *         import
12129:             */
12130:            protected List getToolsAvailableForImport(SessionState state) {
12131:                // The Web Content and News tools do not follow the standard rules for
12132:                // import
12133:                // Even if the current site does not contain the tool, News and WC will
12134:                // be
12135:                // an option if the imported site contains it
12136:                boolean displayWebContent = false;
12137:                boolean displayNews = false;
12138:
12139:                Set importSites = ((Hashtable) state
12140:                        .getAttribute(STATE_IMPORT_SITES)).keySet();
12141:                Iterator sitesIter = importSites.iterator();
12142:                while (sitesIter.hasNext()) {
12143:                    Site site = (Site) sitesIter.next();
12144:                    if (site.getToolForCommonId("sakai.iframe") != null)
12145:                        displayWebContent = true;
12146:                    if (site.getToolForCommonId("sakai.news") != null)
12147:                        displayNews = true;
12148:                }
12149:
12150:                List toolsOnImportList = (List) state
12151:                        .getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST);
12152:                if (displayWebContent
12153:                        && !toolsOnImportList.contains("sakai.iframe"))
12154:                    toolsOnImportList.add("sakai.iframe");
12155:                if (displayNews && !toolsOnImportList.contains("sakai.news"))
12156:                    toolsOnImportList.add("sakai.news");
12157:
12158:                return toolsOnImportList;
12159:            } // getToolsAvailableForImport
12160:
12161:            private void setTermListForContext(Context context,
12162:                    SessionState state, boolean upcomingOnly) {
12163:                List terms;
12164:                if (upcomingOnly) {
12165:                    terms = cms.getCurrentAcademicSessions();
12166:                } else { // get all
12167:                    terms = cms.getAcademicSessions();
12168:                }
12169:                if (terms != null && terms.size() > 0) {
12170:                    context.put("termList", terms);
12171:                }
12172:            } // setTermListForContext
12173:
12174:            private void setSelectedTermForContext(Context context,
12175:                    SessionState state, String stateAttribute) {
12176:                if (state.getAttribute(stateAttribute) != null) {
12177:                    context.put("selectedTerm", state
12178:                            .getAttribute(stateAttribute));
12179:                }
12180:            } // setSelectedTermForContext
12181:
12182:            /**
12183:             * rewrote for 2.4
12184:             * 
12185:             * @param userId
12186:             * @param academicSessionEid
12187:             * @param courseOfferingHash
12188:             * @param sectionHash
12189:             */
12190:            private void prepareCourseAndSectionMap(String userId,
12191:                    String academicSessionEid, HashMap courseOfferingHash,
12192:                    HashMap sectionHash) {
12193:
12194:                // looking for list of courseOffering and sections that should be
12195:                // included in
12196:                // the selection list. The course offering must be offered
12197:                // 1. in the specific academic Session
12198:                // 2. that the specified user has right to attach its section to a
12199:                // course site
12200:                // map = (section.eid, sakai rolename)
12201:                Map map = groupProvider.getGroupRolesForUser(userId);
12202:                if (map == null)
12203:                    return;
12204:
12205:                Set keys = map.keySet();
12206:                Set roleSet = getRolesAllowedToAttachSection();
12207:                for (Iterator i = keys.iterator(); i.hasNext();) {
12208:                    String sectionEid = (String) i.next();
12209:                    String role = (String) map.get(sectionEid);
12210:                    if (includeRole(role, roleSet)) {
12211:                        Section section = null;
12212:                        try {
12213:                            section = cms.getSection(sectionEid);
12214:                        } catch (IdNotFoundException e) {
12215:                            M_log.warn(e.getMessage());
12216:                        }
12217:                        if (section != null) {
12218:                            String courseOfferingEid = section
12219:                                    .getCourseOfferingEid();
12220:                            CourseOffering courseOffering = cms
12221:                                    .getCourseOffering(courseOfferingEid);
12222:                            String sessionEid = courseOffering
12223:                                    .getAcademicSession().getEid();
12224:                            if (academicSessionEid.equals(sessionEid)) {
12225:                                // a long way to the conclusion that yes, this course
12226:                                // offering
12227:                                // should be included in the selected list. Sigh...
12228:                                // -daisyf
12229:                                ArrayList sectionList = (ArrayList) sectionHash
12230:                                        .get(courseOffering.getEid());
12231:                                if (sectionList == null) {
12232:                                    sectionList = new ArrayList();
12233:                                }
12234:                                sectionList.add(new SectionObject(section));
12235:                                sectionHash.put(courseOffering.getEid(),
12236:                                        sectionList);
12237:                                courseOfferingHash.put(courseOffering.getEid(),
12238:                                        courseOffering);
12239:                            }
12240:                        }
12241:                    }
12242:                }
12243:            } // prepareCourseAndSectionMap
12244:
12245:            /**
12246:             * for 2.4
12247:             * 
12248:             * @param role
12249:             * @return
12250:             */
12251:            private boolean includeRole(String role, Set roleSet) {
12252:                boolean includeRole = false;
12253:                for (Iterator i = roleSet.iterator(); i.hasNext();) {
12254:                    String r = (String) i.next();
12255:                    if (r.equals(role)) {
12256:                        includeRole = true;
12257:                        break;
12258:                    }
12259:                }
12260:                return includeRole;
12261:            } // includeRole
12262:
12263:            protected Set getRolesAllowedToAttachSection() {
12264:                // Use !site.template.[site_type]
12265:                String azgId = "!site.template.course";
12266:                AuthzGroup azgTemplate;
12267:                try {
12268:                    azgTemplate = AuthzGroupService.getAuthzGroup(azgId);
12269:                } catch (GroupNotDefinedException e) {
12270:                    M_log.warn("Could not find authz group " + azgId);
12271:                    return new HashSet();
12272:                }
12273:                Set roles = azgTemplate.getRolesIsAllowed("site.upd");
12274:                roles.addAll(azgTemplate.getRolesIsAllowed("realm.upd"));
12275:                return roles;
12276:            } // getRolesAllowedToAttachSection
12277:
12278:            /**
12279:             * Here, we will preapre two HashMap: 1. courseOfferingHash stores
12280:             * courseOfferingId and CourseOffering 2. sectionHash stores
12281:             * courseOfferingId and a list of its Section We sorted the CourseOffering
12282:             * by its eid & title and went through them one at a time to construct the
12283:             * CourseObject that is used for the displayed in velocity. Each
12284:             * CourseObject will contains a list of CourseOfferingObject(again used for
12285:             * vm display). Usually, a CourseObject would only contain one
12286:             * CourseOfferingObject. A CourseObject containing multiple
12287:             * CourseOfferingObject implies that this is a cross-listing situation.
12288:             * 
12289:             * @param userId
12290:             * @param academicSessionEid
12291:             * @return
12292:             */
12293:            private List prepareCourseAndSectionListing(String userId,
12294:                    String academicSessionEid, SessionState state) {
12295:                // courseOfferingHash = (courseOfferingEid, vourseOffering)
12296:                // sectionHash = (courseOfferingEid, list of sections)
12297:                HashMap courseOfferingHash = new HashMap();
12298:                HashMap sectionHash = new HashMap();
12299:                prepareCourseAndSectionMap(userId, academicSessionEid,
12300:                        courseOfferingHash, sectionHash);
12301:                // courseOfferingHash & sectionHash should now be filled with stuffs
12302:                // put section list in state for later use
12303:
12304:                state.setAttribute(STATE_PROVIDER_SECTION_LIST,
12305:                        getSectionList(sectionHash));
12306:
12307:                ArrayList offeringList = new ArrayList();
12308:                Set keys = courseOfferingHash.keySet();
12309:                for (Iterator i = keys.iterator(); i.hasNext();) {
12310:                    CourseOffering o = (CourseOffering) courseOfferingHash
12311:                            .get((String) i.next());
12312:                    offeringList.add(o);
12313:                }
12314:
12315:                Collection offeringListSorted = sortOffering(offeringList);
12316:                ArrayList resultedList = new ArrayList();
12317:
12318:                // use this to keep track of courseOffering that we have dealt with
12319:                // already
12320:                // this is important 'cos cross-listed offering is dealt with together
12321:                // with its
12322:                // equivalents
12323:                ArrayList dealtWith = new ArrayList();
12324:
12325:                for (Iterator j = offeringListSorted.iterator(); j.hasNext();) {
12326:                    CourseOffering o = (CourseOffering) j.next();
12327:                    if (!dealtWith.contains(o.getEid())) {
12328:                        // 1. construct list of CourseOfferingObject for CourseObject
12329:                        ArrayList l = new ArrayList();
12330:                        CourseOfferingObject coo = new CourseOfferingObject(o,
12331:                                (ArrayList) sectionHash.get(o.getEid()));
12332:                        l.add(coo);
12333:
12334:                        // 2. check if course offering is cross-listed
12335:                        Set set = cms.getEquivalentCourseOfferings(o.getEid());
12336:                        for (Iterator k = set.iterator(); k.hasNext();) {
12337:                            CourseOffering eo = (CourseOffering) k.next();
12338:                            if (courseOfferingHash.containsKey(eo.getEid())) {
12339:                                // => cross-listed, then list them together
12340:                                CourseOfferingObject coo_equivalent = new CourseOfferingObject(
12341:                                        eo, (ArrayList) sectionHash.get(eo
12342:                                                .getEid()));
12343:                                l.add(coo_equivalent);
12344:                                dealtWith.add(eo.getEid());
12345:                            }
12346:                        }
12347:                        CourseObject co = new CourseObject(o, l);
12348:                        dealtWith.add(o.getEid());
12349:                        resultedList.add(co);
12350:                    }
12351:                }
12352:                return resultedList;
12353:            } // prepareCourseAndSectionListing
12354:
12355:            /**
12356:             * Sort CourseOffering by order of eid, title uisng velocity SortTool
12357:             * 
12358:             * @param offeringList
12359:             * @return
12360:             */
12361:            private Collection sortOffering(ArrayList offeringList) {
12362:                return sortCmObject(offeringList);
12363:                /*
12364:                 * List propsList = new ArrayList(); propsList.add("eid");
12365:                 * propsList.add("title"); SortTool sort = new SortTool(); return
12366:                 * sort.sort(offeringList, propsList);
12367:                 */
12368:            } // sortOffering
12369:
12370:            /**
12371:             * sort any Cm object such as CourseOffering, CourseOfferingObject,
12372:             * SectionObject provided object has getter & setter for eid & title
12373:             * 
12374:             * @param list
12375:             * @return
12376:             */
12377:            private Collection sortCmObject(List list) {
12378:                if (list != null) {
12379:                    List propsList = new ArrayList();
12380:                    propsList.add("eid");
12381:                    propsList.add("title");
12382:                    SortTool sort = new SortTool();
12383:                    return sort.sort(list, propsList);
12384:                } else {
12385:                    return list;
12386:                }
12387:            } // sortCmObject
12388:
12389:            /**
12390:             * this object is used for displaying purposes in chef_site-newSiteCourse.vm
12391:             */
12392:            public class SectionObject {
12393:                public Section section;
12394:
12395:                public String eid;
12396:
12397:                public String title;
12398:
12399:                public String category;
12400:
12401:                public String categoryDescription;
12402:
12403:                public boolean isLecture;
12404:
12405:                public boolean attached;
12406:
12407:                public String authorizer;
12408:
12409:                public SectionObject(Section section) {
12410:                    this .section = section;
12411:                    this .eid = section.getEid();
12412:                    this .title = section.getTitle();
12413:                    this .category = section.getCategory();
12414:                    this .categoryDescription = cms
12415:                            .getSectionCategoryDescription(section
12416:                                    .getCategory());
12417:                    if ("01.lct".equals(section.getCategory())) {
12418:                        this .isLecture = true;
12419:                    } else {
12420:                        this .isLecture = false;
12421:                    }
12422:                    Set set = authzGroupService.getAuthzGroupIds(section
12423:                            .getEid());
12424:                    if (set != null && !set.isEmpty()) {
12425:                        this .attached = true;
12426:                    } else {
12427:                        this .attached = false;
12428:                    }
12429:                }
12430:
12431:                public Section getSection() {
12432:                    return section;
12433:                }
12434:
12435:                public String getEid() {
12436:                    return eid;
12437:                }
12438:
12439:                public String getTitle() {
12440:                    return title;
12441:                }
12442:
12443:                public String getCategory() {
12444:                    return category;
12445:                }
12446:
12447:                public String getCategoryDescription() {
12448:                    return categoryDescription;
12449:                }
12450:
12451:                public boolean getIsLecture() {
12452:                    return isLecture;
12453:                }
12454:
12455:                public boolean getAttached() {
12456:                    return attached;
12457:                }
12458:
12459:                public String getAuthorizer() {
12460:                    return authorizer;
12461:                }
12462:
12463:                public void setAuthorizer(String authorizer) {
12464:                    this .authorizer = authorizer;
12465:                }
12466:
12467:            } // SectionObject constructor
12468:
12469:            /**
12470:             * this object is used for displaying purposes in chef_site-newSiteCourse.vm
12471:             */
12472:            public class CourseObject {
12473:                public String eid;
12474:
12475:                public String title;
12476:
12477:                public List courseOfferingObjects;
12478:
12479:                public CourseObject(CourseOffering offering,
12480:                        List courseOfferingObjects) {
12481:                    this .eid = offering.getEid();
12482:                    this .title = offering.getTitle();
12483:                    this .courseOfferingObjects = courseOfferingObjects;
12484:                }
12485:
12486:                public String getEid() {
12487:                    return eid;
12488:                }
12489:
12490:                public String getTitle() {
12491:                    return title;
12492:                }
12493:
12494:                public List getCourseOfferingObjects() {
12495:                    return courseOfferingObjects;
12496:                }
12497:
12498:            } // CourseObject constructor
12499:
12500:            /**
12501:             * this object is used for displaying purposes in chef_site-newSiteCourse.vm
12502:             */
12503:            public class CourseOfferingObject {
12504:                public String eid;
12505:
12506:                public String title;
12507:
12508:                public List sections;
12509:
12510:                public CourseOfferingObject(CourseOffering offering,
12511:                        List unsortedSections) {
12512:                    List propsList = new ArrayList();
12513:                    propsList.add("category");
12514:                    propsList.add("eid");
12515:                    SortTool sort = new SortTool();
12516:                    this .sections = new ArrayList();
12517:                    if (unsortedSections != null) {
12518:                        this .sections = (List) sort.sort(unsortedSections,
12519:                                propsList);
12520:                    }
12521:                    this .eid = offering.getEid();
12522:                    this .title = offering.getTitle();
12523:                }
12524:
12525:                public String getEid() {
12526:                    return eid;
12527:                }
12528:
12529:                public String getTitle() {
12530:                    return title;
12531:                }
12532:
12533:                public List getSections() {
12534:                    return sections;
12535:                }
12536:            } // CourseOfferingObject constructor
12537:
12538:            /**
12539:             * get campus user directory for dispaly in chef_newSiteCourse.vm
12540:             * 
12541:             * @return
12542:             */
12543:            private String getCampusDirectory() {
12544:                return ServerConfigurationService.getString(
12545:                        "site-manage.campusUserDirectory", null);
12546:            } // getCampusDirectory
12547:
12548:            private void removeAnyFlagedSection(SessionState state,
12549:                    ParameterParser params) {
12550:                List all = new ArrayList();
12551:                List providerCourseList = (List) state
12552:                        .getAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN);
12553:                if (providerCourseList != null) {
12554:                    all.addAll(providerCourseList);
12555:                }
12556:                List manualCourseList = (List) state
12557:                        .getAttribute(SITE_MANUAL_COURSE_LIST);
12558:                if (manualCourseList != null) {
12559:                    all.addAll(manualCourseList);
12560:                }
12561:
12562:                for (int i = 0; i < all.size(); i++) {
12563:                    String eid = (String) all.get(i);
12564:                    String field = "removeSection" + eid;
12565:                    String toRemove = params.getString(field);
12566:                    if ("true".equals(toRemove)) {
12567:                        // eid is in either providerCourseList or manualCourseList
12568:                        // either way, just remove it
12569:                        if (providerCourseList != null)
12570:                            providerCourseList.remove(eid);
12571:                        if (manualCourseList != null)
12572:                            manualCourseList.remove(eid);
12573:                    }
12574:                }
12575:
12576:                List<SectionObject> requestedCMSections = (List<SectionObject>) state
12577:                        .getAttribute(STATE_CM_REQUESTED_SECTIONS);
12578:
12579:                if (requestedCMSections != null) {
12580:                    for (int i = 0; i < requestedCMSections.size(); i++) {
12581:                        SectionObject so = (SectionObject) requestedCMSections
12582:                                .get(i);
12583:
12584:                        String field = "removeSection" + so.getEid();
12585:                        String toRemove = params.getString(field);
12586:
12587:                        if ("true".equals(toRemove)) {
12588:                            requestedCMSections.remove(so);
12589:                        }
12590:
12591:                    }
12592:
12593:                    if (requestedCMSections.size() == 0)
12594:                        state.removeAttribute(STATE_CM_REQUESTED_SECTIONS);
12595:                }
12596:
12597:                List<SectionObject> authorizerSections = (List<SectionObject>) state
12598:                        .getAttribute(STATE_CM_AUTHORIZER_SECTIONS);
12599:                if (authorizerSections != null) {
12600:                    for (int i = 0; i < authorizerSections.size(); i++) {
12601:                        SectionObject so = (SectionObject) authorizerSections
12602:                                .get(i);
12603:
12604:                        String field = "removeSection" + so.getEid();
12605:                        String toRemove = params.getString(field);
12606:
12607:                        if ("true".equals(toRemove)) {
12608:                            authorizerSections.remove(so);
12609:                        }
12610:
12611:                    }
12612:
12613:                    if (authorizerSections.size() == 0)
12614:                        state.removeAttribute(STATE_CM_AUTHORIZER_SECTIONS);
12615:                }
12616:
12617:                // if list is empty, set to null. This is important 'cos null is
12618:                // the indication that the list is empty in the code. See case 2 on line
12619:                // 1081
12620:                if (manualCourseList != null && manualCourseList.size() == 0)
12621:                    manualCourseList = null;
12622:                if (providerCourseList != null
12623:                        && providerCourseList.size() == 0)
12624:                    providerCourseList = null;
12625:            }
12626:
12627:            private void collectNewSiteInfo(SiteInfo siteInfo,
12628:                    SessionState state, ParameterParser params,
12629:                    List providerChosenList) {
12630:                if (state.getAttribute(STATE_MESSAGE) == null) {
12631:                    siteInfo = new SiteInfo();
12632:                    if (state.getAttribute(STATE_SITE_INFO) != null) {
12633:                        siteInfo = (SiteInfo) state
12634:                                .getAttribute(STATE_SITE_INFO);
12635:                    }
12636:
12637:                    // site title is the title of the 1st section selected -
12638:                    // daisyf's note
12639:                    if (providerChosenList != null
12640:                            && providerChosenList.size() >= 1) {
12641:                        String title = prepareTitle((List) state
12642:                                .getAttribute(STATE_PROVIDER_SECTION_LIST),
12643:                                providerChosenList);
12644:                        siteInfo.title = title;
12645:                    }
12646:                    state.setAttribute(STATE_SITE_INFO, siteInfo);
12647:
12648:                    if (params.getString("manualAdds") != null
12649:                            && ("true").equals(params.getString("manualAdds"))) {
12650:                        // if creating a new site
12651:                        state.setAttribute(STATE_TEMPLATE_INDEX, "37");
12652:
12653:                        state.setAttribute(STATE_MANUAL_ADD_COURSE_NUMBER,
12654:                                new Integer(1));
12655:
12656:                    } else if (params.getString("findCourse") != null
12657:                            && ("true").equals(params.getString("findCourse"))) {
12658:                        state.setAttribute(STATE_ADD_CLASS_PROVIDER_CHOSEN,
12659:                                providerChosenList);
12660:                        prepFindPage(state);
12661:                    } else {
12662:                        // no manual add
12663:                        state.removeAttribute(STATE_MANUAL_ADD_COURSE_NUMBER);
12664:                        state.removeAttribute(STATE_MANUAL_ADD_COURSE_FIELDS);
12665:                        state.removeAttribute(STATE_SITE_QUEST_UNIQNAME);
12666:
12667:                        if (getStateSite(state) != null) {
12668:                            // if revising a site, go to the confirmation
12669:                            // page of adding classes
12670:                            state.setAttribute(STATE_TEMPLATE_INDEX, "44");
12671:                        } else {
12672:                            // if creating a site, go the the site
12673:                            // information entry page
12674:                            state.setAttribute(STATE_TEMPLATE_INDEX, "2");
12675:                        }
12676:                    }
12677:                }
12678:            }
12679:
12680:            /**
12681:             * By default, courseManagement is implemented
12682:             * 
12683:             * @return
12684:             */
12685:            private boolean courseManagementIsImplemented() {
12686:                boolean returnValue = true;
12687:                String isImplemented = ServerConfigurationService
12688:                        .getString(
12689:                                "site-manage.courseManagementSystemImplemented",
12690:                                "true");
12691:                if (("false").equals(isImplemented))
12692:                    returnValue = false;
12693:                return returnValue;
12694:            }
12695:
12696:            private List getCMSubjects() {
12697:                String subjectCategory = getCMSubjectCategory();
12698:
12699:                if (cms == null || subjectCategory == null) {
12700:                    return new ArrayList(0);
12701:                }
12702:                Collection c = sortCmObject(cms.findCourseSets(subjectCategory));
12703:                return (List) c;
12704:
12705:            }
12706:
12707:            private List getCMSections(String offeringEid) {
12708:                if (offeringEid == null || offeringEid.trim().length() == 0)
12709:                    return null;
12710:
12711:                if (cms != null) {
12712:                    Set sections = cms.getSections(offeringEid);
12713:                    Collection c = sortCmObject(new ArrayList(sections));
12714:                    return (List) c;
12715:                }
12716:
12717:                return new ArrayList(0);
12718:            }
12719:
12720:            private List getCMCourseOfferings(String subjectEid, String termID) {
12721:                if (subjectEid == null || subjectEid.trim().length() == 0
12722:                        || termID == null || termID.trim().length() == 0)
12723:                    return null;
12724:
12725:                if (cms != null) {
12726:                    Set offerings = cms
12727:                            .getCourseOfferingsInCourseSet(subjectEid);// ,
12728:                    // termID);
12729:                    ArrayList returnList = new ArrayList();
12730:                    Iterator coIt = offerings.iterator();
12731:
12732:                    while (coIt.hasNext()) {
12733:                        CourseOffering co = (CourseOffering) coIt.next();
12734:                        AcademicSession as = co.getAcademicSession();
12735:                        if (as != null && as.getEid().equals(termID))
12736:                            returnList.add(co);
12737:                    }
12738:                    Collection c = sortCmObject(returnList);
12739:
12740:                    return (List) c;
12741:                }
12742:
12743:                return new ArrayList(0);
12744:            }
12745:
12746:            private String getCMSubjectCategory() {
12747:                if (cmSubjectCategory == null) {
12748:                    cmSubjectCategory = ServerConfigurationService
12749:                            .getString("site-manage.cms.subject.category");
12750:
12751:                    if (cmSubjectCategory == null) {
12752:                        if (warnedNoSubjectCategory)
12753:                            M_log
12754:                                    .debug(rb
12755:                                            .getString("nscourse.cm.configure.log.nosubjectcat"));
12756:                        else {
12757:                            M_log
12758:                                    .info(rb
12759:                                            .getString("nscourse.cm.configure.log.nosubjectcat"));
12760:                            warnedNoSubjectCategory = true;
12761:                        }
12762:                    }
12763:                }
12764:                return cmSubjectCategory;
12765:            }
12766:
12767:            private List<String> getCMLevelLabels() {
12768:                List<String> cmLevels = new ArrayList(3);
12769:
12770:                String level = null;
12771:
12772:                cmLevels = new ArrayList<String>(3);
12773:
12774:                level = ServerConfigurationService
12775:                        .getString("site-manage.cms.subject.label");
12776:                if (level == null) {
12777:                    M_log
12778:                            .warn("site-manage.cms.subject.label is not set in sakai.properties.");
12779:                    // return cmLevels;
12780:                }
12781:
12782:                cmLevels.add(level);
12783:
12784:                level = rb.getString("nscourse.cms.courseoffering.label");
12785:                if (level == null) {
12786:                    M_log
12787:                            .warn("nscourse.cms.courseoffering.label is not set in sitesetupgeneric.properties.");
12788:                    // return cmLevels;
12789:                }
12790:                cmLevels.add(level);
12791:
12792:                level = rb.getString("nscourse.cms.section.label");
12793:                if (level == null) {
12794:                    M_log
12795:                            .warn("nscourse.cms.section.label is not set in sitesetupgeneric.properties.");
12796:                    // return cmLevels;
12797:                }
12798:                cmLevels.add(level);
12799:
12800:                return cmLevels;
12801:            }
12802:
12803:            private void prepFindPage(SessionState state) {
12804:                final List cmLevels = getCMLevelLabels(), selections = (List) state
12805:                        .getAttribute(STATE_CM_LEVEL_SELECTIONS);
12806:                int lvlSz = 0;
12807:
12808:                if (cmLevels == null || (lvlSz = cmLevels.size()) < 1) {
12809:                    // TODO: no cm levels configured, redirect to manual add
12810:                    return;
12811:                }
12812:
12813:                if (selections != null && selections.size() == lvlSz) {
12814:                    Section sect = cms.getSection((String) selections
12815:                            .get(selections.size() - 1));
12816:                    SectionObject so = new SectionObject(sect);
12817:
12818:                    state.setAttribute(STATE_CM_SELECTED_SECTION, so);
12819:                } else
12820:                    state.removeAttribute(STATE_CM_SELECTED_SECTION);
12821:
12822:                state.setAttribute(STATE_CM_LEVELS, cmLevels);
12823:                state.setAttribute(STATE_CM_LEVEL_SELECTIONS, selections);
12824:
12825:                state.setAttribute(STATE_TEMPLATE_INDEX, "53");
12826:            }
12827:
12828:            private void addRequestedSection(SessionState state) {
12829:                SectionObject so = (SectionObject) state
12830:                        .getAttribute(STATE_CM_SELECTED_SECTION);
12831:
12832:                if (so == null)
12833:                    return;
12834:
12835:                List<SectionObject> requestedSections = (List<SectionObject>) state
12836:                        .getAttribute(STATE_CM_REQUESTED_SECTIONS);
12837:
12838:                if (requestedSections == null) {
12839:                    requestedSections = new ArrayList<SectionObject>();
12840:                }
12841:
12842:                // don't add duplicates
12843:                if (!requestedSections.contains(so))
12844:                    requestedSections.add(so);
12845:
12846:                // if the title has not yet been set and there is just
12847:                // one section, set the title to that section's EID
12848:                if (requestedSections.size() == 1) {
12849:                    SiteInfo siteInfo = (SiteInfo) state
12850:                            .getAttribute(STATE_SITE_INFO);
12851:
12852:                    if (siteInfo == null) {
12853:                        siteInfo = new SiteInfo();
12854:                    }
12855:
12856:                    if (siteInfo.title == null
12857:                            || siteInfo.title.trim().length() == 0) {
12858:                        siteInfo.title = so.getEid();
12859:                    }
12860:
12861:                    state.setAttribute(STATE_SITE_INFO, siteInfo);
12862:                }
12863:
12864:                state.setAttribute(STATE_CM_REQUESTED_SECTIONS,
12865:                        requestedSections);
12866:
12867:                state.removeAttribute(STATE_CM_LEVEL_SELECTIONS);
12868:                state.removeAttribute(STATE_CM_SELECTED_SECTION);
12869:            }
12870:
12871:            public void doFind_course(RunData data) {
12872:                final SessionState state = ((JetspeedRunData) data)
12873:                        .getPortletSessionState(((JetspeedRunData) data)
12874:                                .getJs_peid());
12875:                final ParameterParser params = data.getParameters();
12876:                final String option = params.get("option");
12877:
12878:                if (option != null) {
12879:                    if ("continue".equals(option)) {
12880:                        addRequestedSection(state);
12881:
12882:                        String uniqname = StringUtil.trimToNull(params
12883:                                .getString("uniqname"));
12884:                        state.setAttribute(STATE_SITE_QUEST_UNIQNAME, uniqname);
12885:
12886:                        if (state.getAttribute(STATE_FUTURE_TERM_SELECTED) != null
12887:                                && !((Boolean) state
12888:                                        .getAttribute(STATE_FUTURE_TERM_SELECTED))
12889:                                        .booleanValue()) {
12890:                            // if a future term is selected, do not check authorization
12891:                            // uniqname
12892:                            if (uniqname == null) {
12893:                                addAlert(
12894:                                        state,
12895:                                        rb.getString("java.author")
12896:                                                + " "
12897:                                                + ServerConfigurationService
12898:                                                        .getString("noEmailInIdAccountName")
12899:                                                + ". ");
12900:                            } else {
12901:                                try {
12902:                                    UserDirectoryService.getUserByEid(uniqname);
12903:                                } catch (UserNotDefinedException e) {
12904:                                    addAlert(
12905:                                            state,
12906:                                            rb.getString("java.validAuthor1")
12907:                                                    + " "
12908:                                                    + ServerConfigurationService
12909:                                                            .getString("noEmailInIdAccountName")
12910:                                                    + " "
12911:                                                    + rb
12912:                                                            .getString("java.validAuthor2"));
12913:                                }
12914:                            }
12915:                        }
12916:                        if (state.getAttribute(STATE_MESSAGE) == null) {
12917:                            if (getStateSite(state) == null) {
12918:                                state.setAttribute(STATE_TEMPLATE_INDEX, "2");
12919:                            } else {
12920:                                state.setAttribute(STATE_TEMPLATE_INDEX, "44");
12921:                            }
12922:                        }
12923:
12924:                        doContinue(data);
12925:                        return;
12926:                    } else if ("back".equals(option)) {
12927:                        doBack(data);
12928:                        return;
12929:                    } else if ("cancel".equals(option)) {
12930:                        doCancel_create(data);
12931:                        return;
12932:                    } else if (option.equals("add")) {
12933:                        addRequestedSection(state);
12934:                        return;
12935:                    } else if (option.equals("manual")) {
12936:                        // TODO: send to case 37
12937:                        state.setAttribute(STATE_TEMPLATE_INDEX, "37");
12938:
12939:                        state.setAttribute(STATE_MANUAL_ADD_COURSE_NUMBER,
12940:                                new Integer(1));
12941:
12942:                        return;
12943:                    } else if (option.equals("remove"))
12944:                        removeAnyFlagedSection(state, params);
12945:                }
12946:
12947:                final List selections = new ArrayList(3);
12948:
12949:                int cmLevel = 3;
12950:                String deptChanged = params.get("deptChanged");
12951:                if ("true".equals(deptChanged)) {
12952:                    // when dept changes, remove selection on courseOffering and
12953:                    // courseSection
12954:                    cmLevel = 1;
12955:                }
12956:                for (int i = 0; i < cmLevel; i++) {
12957:                    String val = params.get("idField_" + i);
12958:
12959:                    if (val == null || val.trim().length() < 1) {
12960:                        break;
12961:                    }
12962:                    selections.add(val);
12963:                }
12964:
12965:                state.setAttribute(STATE_CM_LEVEL_SELECTIONS, selections);
12966:
12967:                prepFindPage(state);
12968:            }
12969:
12970:            /**
12971:             * return the title of the 1st section in the chosen list that has an
12972:             * enrollment set. No discrimination on section category
12973:             * 
12974:             * @param sectionList
12975:             * @param chosenList
12976:             * @return
12977:             */
12978:            private String prepareTitle(List sectionList, List chosenList) {
12979:                String title = null;
12980:                HashMap map = new HashMap();
12981:                for (Iterator i = sectionList.iterator(); i.hasNext();) {
12982:                    SectionObject o = (SectionObject) i.next();
12983:                    map.put(o.getEid(), o.getSection());
12984:                }
12985:                for (int j = 0; j < chosenList.size(); j++) {
12986:                    String eid = (String) chosenList.get(j);
12987:                    Section s = (Section) map.get(eid);
12988:                    // we will always has a title regardless but we prefer it to be the
12989:                    // 1st section on the chosen list that has an enrollment set
12990:                    if (j == 0) {
12991:                        title = s.getTitle();
12992:                    }
12993:                    if (s.getEnrollmentSet() != null) {
12994:                        title = s.getTitle();
12995:                        break;
12996:                    }
12997:                }
12998:                return title;
12999:            } // prepareTitle
13000:
13001:            /**
13002:             * return an ArrayList of SectionObject
13003:             * 
13004:             * @param sectionHash
13005:             *            contains an ArrayList collection of SectionObject
13006:             * @return
13007:             */
13008:            private ArrayList getSectionList(HashMap sectionHash) {
13009:                ArrayList list = new ArrayList();
13010:                // values is an ArrayList of section
13011:                Collection c = sectionHash.values();
13012:                for (Iterator i = c.iterator(); i.hasNext();) {
13013:                    ArrayList l = (ArrayList) i.next();
13014:                    list.addAll(l);
13015:                }
13016:                return list;
13017:            }
13018:
13019:            private String getAuthorizers(SessionState state) {
13020:                String authorizers = "";
13021:                ArrayList list = (ArrayList) state
13022:                        .getAttribute(STATE_CM_AUTHORIZER_LIST);
13023:                if (list != null) {
13024:                    for (int i = 0; i < list.size(); i++) {
13025:                        if (i == 0) {
13026:                            authorizers = (String) list.get(i);
13027:                        } else {
13028:                            authorizers = authorizers + ", " + list.get(i);
13029:                        }
13030:                    }
13031:                }
13032:                return authorizers;
13033:            }
13034:
13035:            private List prepareSectionObject(List sectionList, String userId) {
13036:                ArrayList list = new ArrayList();
13037:                if (sectionList != null) {
13038:                    for (int i = 0; i < sectionList.size(); i++) {
13039:                        String sectionEid = (String) sectionList.get(i);
13040:                        Section s = cms.getSection(sectionEid);
13041:                        SectionObject so = new SectionObject(s);
13042:                        so.setAuthorizer(userId);
13043:                        list.add(so);
13044:                    }
13045:                }
13046:                return list;
13047:            }
13048:
13049:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.