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


0001:        /**********************************************************************************
0002:         * $URL: https://source.sakaiproject.org/svn/user/tags/sakai_2-4-1/user-tool-prefs/tool/src/java/org/sakaiproject/user/tool/UserPrefsTool.java $
0003:         * $Id: UserPrefsTool.java 28758 2007-04-12 02:09:50Z ajpoland@iupui.edu $
0004:         ***********************************************************************************
0005:         *
0006:         * Copyright (c) 2005, 2006 The Sakai Foundation.
0007:         * 
0008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
0009:         * you may not use this file except in compliance with the License. 
0010:         * You may obtain a copy of the License at
0011:         * 
0012:         *      http://www.opensource.org/licenses/ecl1.php
0013:         * 
0014:         * Unless required by applicable law or agreed to in writing, software 
0015:         * distributed under the License is distributed on an "AS IS" BASIS, 
0016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
0017:         * See the License for the specific language governing permissions and 
0018:         * limitations under the License.
0019:         *
0020:         **********************************************************************************/package org.sakaiproject.user.tool;
0021:
0022:        import java.util.ArrayList;
0023:        import java.util.Arrays;
0024:        import java.util.Collection;
0025:        import java.util.Iterator;
0026:        import java.util.List;
0027:        import java.util.Locale;
0028:        import java.util.TimeZone;
0029:        import java.util.Vector;
0030:
0031:        import javax.faces.application.FacesMessage;
0032:        import javax.faces.context.FacesContext;
0033:        import javax.faces.model.SelectItem;
0034:
0035:        import org.apache.commons.logging.Log;
0036:        import org.apache.commons.logging.LogFactory;
0037:        import org.sakaiproject.announcement.api.AnnouncementService;
0038:        import org.sakaiproject.api.app.syllabus.SyllabusService;
0039:        import org.sakaiproject.component.cover.ServerConfigurationService;
0040:        import org.sakaiproject.content.api.ContentHostingService;
0041:        import org.sakaiproject.entity.api.ResourceProperties;
0042:        import org.sakaiproject.entity.api.ResourcePropertiesEdit;
0043:        import org.sakaiproject.event.cover.NotificationService;
0044:        import org.sakaiproject.exception.IdUnusedException;
0045:        import org.sakaiproject.mailarchive.api.MailArchiveService;
0046:        import org.sakaiproject.site.api.Site;
0047:        import org.sakaiproject.site.cover.SiteService;
0048:        import org.sakaiproject.time.cover.TimeService;
0049:        import org.sakaiproject.tool.api.SessionManager;
0050:        import org.sakaiproject.user.api.Preferences;
0051:        import org.sakaiproject.user.api.PreferencesEdit;
0052:        import org.sakaiproject.user.api.PreferencesService;
0053:        import org.sakaiproject.util.ResourceLoader;
0054:
0055:        /**
0056:         * UserPrefsTool is the Sakai end-user tool to view and edit one's preferences.
0057:         */
0058:        public class UserPrefsTool {
0059:            /** Our log (commons). */
0060:            private static final Log LOG = LogFactory
0061:                    .getLog(UserPrefsTool.class);
0062:
0063:            /** * Resource bundle messages */
0064:            ResourceLoader msgs = new ResourceLoader("user-tool-prefs");
0065:
0066:            /** The string that Charon uses for preferences. */
0067:            private static final String CHARON_PREFS = "sakai:portal:sitenav";
0068:
0069:            /** The string to get whether privacy status should be visible */
0070:            private static final String ENABLE_PRIVACY_STATUS = "enable.privacy.status";
0071:
0072:            /**
0073:             * Represents a name value pair in a keyed preferences set.
0074:             */
0075:            public class KeyNameValue {
0076:                /** Is this value a list?. */
0077:                protected boolean m_isList = false;
0078:
0079:                /** The key. */
0080:                protected String m_key = null;
0081:
0082:                /** The name. */
0083:                protected String m_name = null;
0084:
0085:                /** The original is this value a list?. */
0086:                protected boolean m_origIsList = false;
0087:
0088:                /** The original key. */
0089:                protected String m_origKey = null;
0090:
0091:                /** The original name. */
0092:                protected String m_origName = null;
0093:
0094:                /** The original value. */
0095:                protected String m_origValue = null;
0096:
0097:                /** The value. */
0098:                protected String m_value = null;
0099:
0100:                public KeyNameValue(String key, String name, String value,
0101:                        boolean isList) {
0102:                    m_key = key;
0103:                    m_origKey = key;
0104:                    m_name = name;
0105:                    m_origName = name;
0106:                    m_value = value;
0107:                    m_origValue = value;
0108:                    m_isList = isList;
0109:                    m_origIsList = isList;
0110:                }
0111:
0112:                public String getKey() {
0113:                    return m_key;
0114:                }
0115:
0116:                public String getName() {
0117:                    return m_name;
0118:                }
0119:
0120:                public String getOrigKey() {
0121:                    return m_origKey;
0122:                }
0123:
0124:                public String getOrigName() {
0125:                    return m_origName;
0126:                }
0127:
0128:                public String getOrigValue() {
0129:                    return m_origValue;
0130:                }
0131:
0132:                public String getValue() {
0133:                    return m_value;
0134:                }
0135:
0136:                public boolean isChanged() {
0137:                    return ((!m_name.equals(m_origName))
0138:                            || (!m_value.equals(m_origValue))
0139:                            || (!m_key.equals(m_origKey)) || (m_isList != m_origIsList));
0140:                }
0141:
0142:                public boolean isList() {
0143:                    return m_isList;
0144:                }
0145:
0146:                public boolean origIsList() {
0147:                    return m_origIsList;
0148:                }
0149:
0150:                public void setKey(String value) {
0151:                    if (!m_key.equals(value)) {
0152:                        m_key = value;
0153:                    }
0154:                }
0155:
0156:                public void setList(boolean b) {
0157:                    m_isList = b;
0158:                }
0159:
0160:                public void setName(String value) {
0161:                    if (!m_name.equals(value)) {
0162:                        m_name = value;
0163:                    }
0164:                }
0165:
0166:                public void setValue(String value) {
0167:                    if (!m_value.equals(value)) {
0168:                        m_value = value;
0169:                    }
0170:                }
0171:            }
0172:
0173:            /** The PreferencesEdit being worked on. */
0174:            protected PreferencesEdit m_edit = null;
0175:
0176:            /** Preferences service (injected dependency) */
0177:            protected PreferencesService m_preferencesService = null;
0178:
0179:            /** Session manager (injected dependency) */
0180:            protected SessionManager m_sessionManager = null;
0181:
0182:            /** The PreferencesEdit in KeyNameValue collection form. */
0183:            protected Collection m_stuff = null;
0184:
0185:            // /** The user id (from the end user) to edit. */
0186:            // protected String m_userId = null;
0187:            /** For display and selection of Items in JSF-- edit.jsp */
0188:            private List prefExcludeItems = new ArrayList();
0189:
0190:            private List prefOrderItems = new ArrayList();
0191:
0192:            private List prefTimeZones = new ArrayList();
0193:
0194:            private List prefLocales = new ArrayList();
0195:
0196:            private String[] selectedExcludeItems;
0197:
0198:            private String[] selectedOrderItems;
0199:
0200:            protected final static String EXCLUDE_SITE_LISTS = "exclude";
0201:
0202:            protected final static String ORDER_SITE_LISTS = "order";
0203:
0204:            protected boolean isNewUser = false;
0205:
0206:            protected boolean tabUpdated = false;
0207:
0208:            // user's currently selected time zone
0209:            private TimeZone m_timeZone = null;
0210:
0211:            // user's currently selected regional language locale
0212:            private Locale m_locale = null;
0213:
0214:            private LocaleComparator localeComparator = new LocaleComparator();
0215:
0216:            /** The user id retrieved from UsageSessionService */
0217:            private String userId = "";
0218:
0219:            private String SAKAI_LOCALES = "locales";
0220:
0221:            // //////////////////////////////// PROPERTY GETTER AND SETTER ////////////////////////////////////////////
0222:            /**
0223:             * @return Returns the ResourceLoader value. Note: workaround for <f:selectItem> element, which doesn't like using the <f:loadBundle> map variable
0224:             */
0225:            public String getMsgNotiAnn1() {
0226:                return msgs.getString("noti_ann_1");
0227:            }
0228:
0229:            public String getMsgNotiAnn2() {
0230:                return msgs.getString("noti_ann_2");
0231:            }
0232:
0233:            public String getMsgNotiAnn3() {
0234:                return msgs.getString("noti_ann_3");
0235:            }
0236:
0237:            public String getMsgNotiMail1() {
0238:                return msgs.getString("noti_mail_1");
0239:            }
0240:
0241:            public String getMsgNotiMail2() {
0242:                return msgs.getString("noti_mail_2");
0243:            }
0244:
0245:            public String getMsgNotiMail3() {
0246:                return msgs.getString("noti_mail_3");
0247:            }
0248:
0249:            public String getMsgNotiRsrc1() {
0250:                return msgs.getString("noti_rsrc_1");
0251:            }
0252:
0253:            public String getMsgNotiRsrc2() {
0254:                return msgs.getString("noti_rsrc_2");
0255:            }
0256:
0257:            public String getMsgNotiRsrc3() {
0258:                return msgs.getString("noti_rsrc_3");
0259:            }
0260:
0261:            public String getMsgNotiSyll1() {
0262:                return msgs.getString("noti_syll_1");
0263:            }
0264:
0265:            public String getMsgNotiSyll2() {
0266:                return msgs.getString("noti_syll_2");
0267:            }
0268:
0269:            public String getMsgNotiSyll3() {
0270:                return msgs.getString("noti_syll_3");
0271:            }
0272:
0273:            /**
0274:             * @return Returns the prefExcludeItems.
0275:             */
0276:            public List getPrefExcludeItems() {
0277:                return prefExcludeItems;
0278:            }
0279:
0280:            /**
0281:             * @param prefExcludeItems
0282:             *        The prefExcludeItems to set.
0283:             */
0284:            public void setPrefExcludeItems(List prefExcludeItems) {
0285:                if (LOG.isDebugEnabled()) {
0286:                    LOG.debug("setPrefExcludeItems(List " + prefExcludeItems
0287:                            + ")");
0288:                }
0289:
0290:                this .prefExcludeItems = prefExcludeItems;
0291:            }
0292:
0293:            /**
0294:             * @return Returns the prefOrderItems.
0295:             */
0296:            public List getPrefOrderItems() {
0297:                return prefOrderItems;
0298:            }
0299:
0300:            /**
0301:             * @param prefOrderItems
0302:             *        The prefOrderItems to set.
0303:             */
0304:            public void setPrefOrderItems(List prefOrderItems) {
0305:                if (LOG.isDebugEnabled()) {
0306:                    LOG.debug("setPrefOrderItems(List " + prefOrderItems + ")");
0307:                }
0308:
0309:                this .prefOrderItems = prefOrderItems;
0310:            }
0311:
0312:            /**
0313:             * @return Returns the prefTimeZones.
0314:             */
0315:            public List getPrefTimeZones() {
0316:                if (prefTimeZones.size() == 0) {
0317:                    String[] timeZoneArray = TimeZone.getAvailableIDs();
0318:                    Arrays.sort(timeZoneArray);
0319:                    for (int i = 0; i < timeZoneArray.length; i++)
0320:                        prefTimeZones.add(new SelectItem(timeZoneArray[i],
0321:                                timeZoneArray[i]));
0322:                }
0323:
0324:                return prefTimeZones;
0325:            }
0326:
0327:            /**
0328:             * @param prefTimeZones
0329:             *        The prefTimeZones to set.
0330:             */
0331:            public void setPrefTimeZones(List prefTimeZones) {
0332:                if (LOG.isDebugEnabled()) {
0333:                    LOG.debug("setPrefTimeZones(List " + prefTimeZones + ")");
0334:                }
0335:
0336:                this .prefTimeZones = prefTimeZones;
0337:            }
0338:
0339:            /**
0340:             * *
0341:             * 
0342:             * @return Locale based on its string representation (language_region)
0343:             */
0344:            private Locale getLocaleFromString(String localeString) {
0345:                String[] locValues = localeString.trim().split("_");
0346:                if (locValues.length > 1)
0347:                    return new Locale(locValues[0], locValues[1]); // language, country
0348:                else if (locValues.length == 1)
0349:                    return new Locale(locValues[0]); // just language
0350:                else
0351:                    return Locale.getDefault();
0352:            }
0353:
0354:            /**
0355:             * @return Returns the prefLocales
0356:             */
0357:            public List getPrefLocales() {
0358:                // Initialize list of supported locales, if necessary
0359:                if (prefLocales.size() == 0) {
0360:                    Locale[] localeArray = null;
0361:                    String localeString = ServerConfigurationService
0362:                            .getString(SAKAI_LOCALES);
0363:
0364:                    if (localeString != null && !localeString.equals("")) {
0365:                        String[] sakai_locales = localeString.split(",");
0366:                        localeArray = new Locale[sakai_locales.length + 1];
0367:                        for (int i = 0; i < sakai_locales.length; i++)
0368:                            localeArray[i] = getLocaleFromString(sakai_locales[i]);
0369:                        localeArray[localeArray.length - 1] = Locale
0370:                                .getDefault();
0371:                    } else
0372:                    // if no locales specified, get default list
0373:                    {
0374:                        localeArray = new Locale[] { Locale.getDefault() };
0375:                    }
0376:
0377:                    // Sort locales and add to prefLocales (removing duplicates)
0378:                    Arrays.sort(localeArray, localeComparator);
0379:                    for (int i = 0; i < localeArray.length; i++) {
0380:                        if (i == 0
0381:                                || !localeArray[i].equals(localeArray[i - 1]))
0382:                            prefLocales.add(new SelectItem(localeArray[i]
0383:                                    .toString(), localeArray[i]
0384:                                    .getDisplayName()));
0385:                    }
0386:                }
0387:
0388:                return prefLocales;
0389:            }
0390:
0391:            /**
0392:             * @param prefLocales
0393:             *        The prefLocales to set.
0394:             */
0395:            public void setPrefLocales(List prefLocales) {
0396:                if (LOG.isDebugEnabled()) {
0397:                    LOG.debug("setPrefLocales(List " + prefLocales + ")");
0398:                }
0399:
0400:                this .prefLocales = prefLocales;
0401:            }
0402:
0403:            /**
0404:             * @return Returns the selectedExcludeItems.
0405:             */
0406:            public String[] getSelectedExcludeItems() {
0407:                return selectedExcludeItems;
0408:            }
0409:
0410:            /**
0411:             * @param selectedExcludeItems
0412:             *        The selectedExcludeItems to set.
0413:             */
0414:            public void setSelectedExcludeItems(String[] selectedExcludeItems) {
0415:                if (LOG.isDebugEnabled()) {
0416:                    LOG.debug("setSelectedExcludeItems(String[] "
0417:                            + selectedExcludeItems + ")");
0418:                }
0419:
0420:                this .selectedExcludeItems = selectedExcludeItems;
0421:            }
0422:
0423:            /**
0424:             * @return Returns the selectedOrderItems.
0425:             */
0426:            public String[] getSelectedOrderItems() {
0427:                return selectedOrderItems;
0428:            }
0429:
0430:            /**
0431:             * @param selectedOrderItems
0432:             *        The selectedOrderItems to set.
0433:             */
0434:            public void setSelectedOrderItems(String[] selectedOrderItems) {
0435:                if (LOG.isDebugEnabled()) {
0436:                    LOG.debug("setSelectedOrderItems(String[] "
0437:                            + selectedOrderItems + ")");
0438:                }
0439:
0440:                this .selectedOrderItems = selectedOrderItems;
0441:            }
0442:
0443:            /**
0444:             * @return Returns the user's selected TimeZone ID
0445:             */
0446:            public String getSelectedTimeZone() {
0447:                if (m_timeZone != null)
0448:                    return m_timeZone.getID();
0449:
0450:                Preferences prefs = (PreferencesEdit) m_preferencesService
0451:                        .getPreferences(getUserId());
0452:                ResourceProperties props = prefs
0453:                        .getProperties(TimeService.APPLICATION_ID);
0454:                String timeZone = props.getProperty(TimeService.TIMEZONE_KEY);
0455:
0456:                if (hasValue(timeZone))
0457:                    m_timeZone = TimeZone.getTimeZone(timeZone);
0458:                else
0459:                    m_timeZone = TimeZone.getDefault();
0460:
0461:                return m_timeZone.getID();
0462:            }
0463:
0464:            /**
0465:             * @param selectedTimeZone
0466:             *        The selectedTimeZone to set.
0467:             */
0468:            public void setSelectedTimeZone(String selectedTimeZone) {
0469:                if (selectedTimeZone != null)
0470:                    m_timeZone = TimeZone.getTimeZone(selectedTimeZone);
0471:                else
0472:                    LOG.warn(this  + "setSelctedTimeZone() has null TimeZone");
0473:            }
0474:
0475:            /**
0476:             * @return Returns the user's selected Locale ID
0477:             */
0478:            private Locale getSelectedLocale() {
0479:                if (m_locale != null)
0480:                    return m_locale;
0481:
0482:                Preferences prefs = (PreferencesEdit) m_preferencesService
0483:                        .getPreferences(getUserId());
0484:                ResourceProperties props = prefs
0485:                        .getProperties(ResourceLoader.APPLICATION_ID);
0486:                String prefLocale = props
0487:                        .getProperty(ResourceLoader.LOCALE_KEY);
0488:
0489:                if (hasValue(prefLocale))
0490:                    m_locale = getLocaleFromString(prefLocale);
0491:                else
0492:                    m_locale = Locale.getDefault();
0493:
0494:                return m_locale;
0495:            }
0496:
0497:            /**
0498:             * @return Returns the user's selected Locale ID
0499:             */
0500:            public String getSelectedLocaleName() {
0501:                return getSelectedLocale().getDisplayName();
0502:            }
0503:
0504:            /**
0505:             * @return Returns the user's selected Locale ID
0506:             */
0507:            public String getSelectedLocaleString() {
0508:                return getSelectedLocale().toString();
0509:            }
0510:
0511:            /**
0512:             * @param selectedLocale
0513:             *        The selectedLocale to set.
0514:             */
0515:            public void setSelectedLocaleString(String selectedLocale) {
0516:                if (selectedLocale != null)
0517:                    m_locale = getLocaleFromString(selectedLocale);
0518:            }
0519:
0520:            /**
0521:             * @return Returns the userId.
0522:             */
0523:            public String getUserId() {
0524:                return m_sessionManager.getCurrentSessionUserId();
0525:            }
0526:
0527:            /**
0528:             * @param userId
0529:             *        The userId to set.
0530:             */
0531:            public void setUserId(String userId) {
0532:                if (LOG.isDebugEnabled()) {
0533:                    LOG.debug("setUserId(String " + userId + ")");
0534:                }
0535:                this .userId = userId;
0536:            }
0537:
0538:            /**
0539:             * @param mgr
0540:             *        The preferences service.
0541:             */
0542:            public void setPreferencesService(PreferencesService mgr) {
0543:                if (LOG.isDebugEnabled()) {
0544:                    LOG.debug("setPreferencesService(PreferencesService " + mgr
0545:                            + ")");
0546:                }
0547:
0548:                m_preferencesService = mgr;
0549:            }
0550:
0551:            /**
0552:             * @param mgr
0553:             *        The session manager.
0554:             */
0555:            public void setSessionManager(SessionManager mgr) {
0556:                if (LOG.isDebugEnabled()) {
0557:                    LOG.debug("setSessionManager(SessionManager " + mgr + ")");
0558:                }
0559:
0560:                m_sessionManager = mgr;
0561:            }
0562:
0563:            /**
0564:             * @return Returns the tabUpdated.
0565:             */
0566:            public boolean isTabUpdated() {
0567:                return tabUpdated;
0568:            }
0569:
0570:            /**
0571:             * @param tabUpdated
0572:             *        The tabUpdated to set.
0573:             */
0574:            public void setTabUpdated(boolean tabUpdated) {
0575:                this .tabUpdated = tabUpdated;
0576:            }
0577:
0578:            // /////////////////////////////////////// CONSTRUCTOR ////////////////////////////////////////////
0579:            /**
0580:             * no-arg constructor.
0581:             */
0582:            public UserPrefsTool() {
0583:                LOG.debug("new UserPrefsTool()");
0584:            }
0585:
0586:            // Naming in faces-config.xml Refresh jsp- "refresh" , Notification jsp- "noti" , tab cutomization jsp- "tab"
0587:            // ///////////////////////////////////// PROCESS ACTION ///////////////////////////////////////////
0588:            /**
0589:             * Process the add command from the edit view.
0590:             * 
0591:             * @return navigation outcome to tab customization page (edit)
0592:             */
0593:            public String processActionAdd() {
0594:                LOG.debug("processActionAdd()");
0595:                tabUpdated = false; // reset successful text message if existing with same jsp
0596:                String[] values = getSelectedExcludeItems();
0597:                if (values.length < 1) {
0598:                    FacesContext
0599:                            .getCurrentInstance()
0600:                            .addMessage(
0601:                                    null,
0602:                                    new FacesMessage(
0603:                                            "Please select a site to add to Sites Visible in Tabs."));
0604:                    return "tab";
0605:                }
0606:
0607:                for (int i = 0; i < values.length; i++) {
0608:                    String value = values[i];
0609:                    getPrefOrderItems().add(
0610:                            removeItems(value, getPrefExcludeItems(),
0611:                                    ORDER_SITE_LISTS, EXCLUDE_SITE_LISTS));
0612:                }
0613:                return "tab";
0614:            }
0615:
0616:            /**
0617:             * Process remove from order list command
0618:             * 
0619:             * @return navigation output to tab customization page (edit)
0620:             */
0621:            public String processActionRemove() {
0622:                LOG.debug("processActionRemove()");
0623:                tabUpdated = false; // reset successful text message if existing in jsp
0624:                String[] values = getSelectedOrderItems();
0625:                if (values.length < 1) {
0626:                    FacesContext
0627:                            .getCurrentInstance()
0628:                            .addMessage(
0629:                                    null,
0630:                                    new FacesMessage(
0631:                                            "Please select a site to remove from Sites Visible in Tabs."));
0632:                    return "tab";
0633:                }
0634:
0635:                for (int i = 0; i < values.length; i++) {
0636:                    String value = values[i];
0637:                    getPrefExcludeItems().add(
0638:                            removeItems(value, getPrefOrderItems(),
0639:                                    EXCLUDE_SITE_LISTS, ORDER_SITE_LISTS));
0640:                }
0641:                return "tab";
0642:            }
0643:
0644:            /**
0645:             * Process Add All action
0646:             * 
0647:             * @return navigation output to tab customization page (edit)
0648:             */
0649:            public String processActionAddAll() {
0650:                LOG.debug("processActionAddAll()");
0651:
0652:                getPrefOrderItems().addAll(getPrefExcludeItems());
0653:                getPrefExcludeItems().clear();
0654:                tabUpdated = false; // reset successful text message if existing in jsp
0655:                return "tab";
0656:            }
0657:
0658:            /**
0659:             * Process Remove All command
0660:             * 
0661:             * @return navigation output to tab customization page (edit)
0662:             */
0663:            public String processActionRemoveAll() {
0664:                LOG.debug("processActionRemoveAll()");
0665:
0666:                getPrefExcludeItems().addAll(getPrefOrderItems());
0667:                getPrefOrderItems().clear();
0668:                tabUpdated = false; // reset successful text message if existing in jsp
0669:                return "tab";
0670:            }
0671:
0672:            /**
0673:             * Move Up the selected item in Ordered List
0674:             * 
0675:             * @return navigation output to tab customization page (edit)
0676:             */
0677:            public String processActionMoveUp() {
0678:                LOG.debug("processActionMoveUp()");
0679:                tabUpdated = false; // reset successful text message if existing in jsp
0680:                String[] selvalues = getSelectedOrderItems();
0681:                if (!(selvalues.length == 1)) {
0682:                    FacesContext.getCurrentInstance().addMessage(
0683:                            null,
0684:                            new FacesMessage(
0685:                                    "Please select one site to move up."));
0686:                    return "tab";
0687:                }
0688:                int itmPos = 0;
0689:                SelectItem swapData = null;
0690:                Iterator iterUp = getPrefOrderItems().iterator();
0691:                while (iterUp.hasNext()) {
0692:                    SelectItem dataUpSite = (SelectItem) iterUp.next();
0693:                    if (selectedOrderItems[0].equals(dataUpSite.getValue())) {
0694:                        break;
0695:                    } else {
0696:                        swapData = dataUpSite;
0697:                    }
0698:                    itmPos++;
0699:                }
0700:                // Swap the position
0701:                if (swapData != null) {
0702:                    if (itmPos >= 1 && (itmPos + 1 <= prefOrderItems.size())) {
0703:                        SelectItem temp = (SelectItem) prefOrderItems
0704:                                .get(itmPos - 1);
0705:                        prefOrderItems.set(itmPos - 1, prefOrderItems
0706:                                .get(itmPos));
0707:                        prefOrderItems.set(itmPos, temp);
0708:                    }
0709:                }
0710:                return "tab";
0711:            }
0712:
0713:            /**
0714:             * Move down the selected item in Ordered List
0715:             * 
0716:             * @return navigation output to tab customization page (edit)
0717:             */
0718:            public String processActionMoveDown() {
0719:                LOG.debug("processActionMoveDown()");
0720:                tabUpdated = false; // reset successful text message if existing in jsp
0721:                String[] values = getSelectedOrderItems();
0722:                if (!(values.length == 1)) {
0723:                    FacesContext.getCurrentInstance().addMessage(
0724:                            null,
0725:                            new FacesMessage(
0726:                                    "Please select one site to move down."));
0727:                    return "tab";
0728:                }
0729:                SelectItem swapDataSite = null;
0730:                int elemPos = 0;
0731:                Iterator iter = getPrefOrderItems().iterator();
0732:                while (iter.hasNext()) {
0733:                    elemPos++;
0734:                    SelectItem dataSite = (SelectItem) iter.next();
0735:                    if (selectedOrderItems[0].equals(dataSite.getValue())) {
0736:                        if (iter.hasNext())
0737:                            swapDataSite = (SelectItem) iter.next();
0738:                        break;
0739:                    }
0740:                }
0741:                // swap the position - elemPos is the final moving position
0742:                if (swapDataSite != null) {
0743:                    if (elemPos >= 1 && (elemPos < prefOrderItems.size())) {
0744:                        SelectItem temp = (SelectItem) prefOrderItems
0745:                                .get(elemPos);
0746:                        prefOrderItems.set(elemPos, prefOrderItems
0747:                                .get(elemPos - 1));
0748:                        prefOrderItems.set(elemPos - 1, temp);
0749:                    }
0750:                }
0751:                return "tab";
0752:            }
0753:
0754:            /**
0755:             * Process the edit command.
0756:             * 
0757:             * @return navigation outcome to tab customization page (edit)
0758:             */
0759:            public String processActionEdit() {
0760:                LOG.debug("processActionEdit()");
0761:
0762:                if (!hasValue(getUserId())) {
0763:                    FacesContext.getCurrentInstance().addMessage(null,
0764:                            new FacesMessage("UserId is missing."));
0765:                    return null;
0766:                }
0767:                tabUpdated = false; // Reset display of text message on JSP
0768:                prefExcludeItems = new ArrayList();
0769:                prefOrderItems = new ArrayList();
0770:                setUserEditingOn();
0771:                List prefExclude = new Vector();
0772:                List prefOrder = new Vector();
0773:
0774:                Preferences prefs = m_preferencesService
0775:                        .getPreferences(getUserId());
0776:                ResourceProperties props = prefs.getProperties(CHARON_PREFS);
0777:                List l = props.getPropertyList("exclude");
0778:                if (l != null) {
0779:                    prefExclude = l;
0780:                }
0781:
0782:                l = props.getPropertyList("order");
0783:                if (l != null) {
0784:                    prefOrder = l;
0785:                }
0786:
0787:                List mySites = SiteService
0788:                        .getSites(
0789:                                org.sakaiproject.site.api.SiteService.SelectionType.ACCESS,
0790:                                null,
0791:                                null,
0792:                                null,
0793:                                org.sakaiproject.site.api.SiteService.SortType.TITLE_ASC,
0794:                                null);
0795:                // create excluded and order list of Sites and add balance mySites to excluded Site list for display in Form
0796:                List ordered = new Vector();
0797:                List excluded = new Vector();
0798:                for (Iterator i = prefOrder.iterator(); i.hasNext();) {
0799:                    String id = (String) i.next();
0800:                    // find this site in the mySites list
0801:                    int pos = indexOf(id, mySites);
0802:                    if (pos != -1) {
0803:                        // move it from mySites to order
0804:                        Site s = (Site) mySites.get(pos);
0805:                        ordered.add(s);
0806:                        mySites.remove(pos);
0807:                    }
0808:                }
0809:                for (Iterator iter = prefExclude.iterator(); iter.hasNext();) {
0810:                    String element = (String) iter.next();
0811:                    int pos = indexOf(element, mySites);
0812:                    if (pos != -1) {
0813:                        Site s = (Site) mySites.get(pos);
0814:                        excluded.add(s);
0815:                        mySites.remove(pos);
0816:                    }
0817:                }
0818:                // pick up the rest of the sites if not available with exclude and order list
0819:                // and add to the ordered list as when a new site is created it is displayed in header
0820:                ordered.addAll(mySites);
0821:
0822:                // Now convert to SelectItem for display in JSF
0823:                for (Iterator iter = excluded.iterator(); iter.hasNext();) {
0824:                    Site element = (Site) iter.next();
0825:                    SelectItem excludeItem = new SelectItem(element.getId(),
0826:                            element.getTitle());
0827:                    prefExcludeItems.add(excludeItem);
0828:                }
0829:
0830:                for (Iterator iter = ordered.iterator(); iter.hasNext();) {
0831:                    Site element = (Site) iter.next();
0832:                    SelectItem orderItem = new SelectItem(element.getId(),
0833:                            element.getTitle());
0834:                    prefOrderItems.add(orderItem);
0835:                }
0836:                // release lock
0837:                m_preferencesService.cancel(m_edit);
0838:                return "tab";
0839:            }
0840:
0841:            /**
0842:             * Process the save command from the edit view.
0843:             * 
0844:             * @return navigation outcome to tab customization page (edit)
0845:             */
0846:            public String processActionSave() {
0847:                LOG.debug("processActionSave()");
0848:
0849:                setUserEditingOn();
0850:                // Remove existing property
0851:                ResourcePropertiesEdit props = m_edit
0852:                        .getPropertiesEdit(CHARON_PREFS);
0853:                props.removeProperty("exclude");
0854:                props.removeProperty("order");
0855:                // Commit to remove from database, for next set of value storing
0856:                m_preferencesService.commit(m_edit);
0857:
0858:                m_stuff = new Vector();
0859:                String oparts = "";
0860:                String eparts = "";
0861:                for (int i = 0; i < prefExcludeItems.size(); i++) {
0862:                    SelectItem item = (SelectItem) prefExcludeItems.get(i);
0863:                    String evalue = (String) item.getValue();
0864:                    eparts += evalue + ", ";
0865:                }
0866:                for (int i = 0; i < prefOrderItems.size(); i++) {
0867:                    SelectItem item = (SelectItem) prefOrderItems.get(i);
0868:                    String value = (String) item.getValue();
0869:                    oparts += value + ", ";
0870:                }
0871:                // add property name and value for saving
0872:                m_stuff.add(new KeyNameValue(CHARON_PREFS, "exclude", eparts,
0873:                        true));
0874:                m_stuff.add(new KeyNameValue(CHARON_PREFS, "order", oparts,
0875:                        true));
0876:                // TODO tab size is set to 4 by default. i can't set null , not "" as in portal code "" will be number to display on tab
0877:                // m_stuff.add(new KeyNameValue(CHARON_PREFS, "tabs", "4", false));
0878:
0879:                // save
0880:                saveEdit();
0881:                // release lock and clear session variables
0882:                cancelEdit();
0883:                // To stay on the same page - load the page data
0884:                processActionEdit();
0885:                tabUpdated = true; // set for display of text message on JSP
0886:
0887:                // schedule a "peer" html element refresh, to update the site nav tabs
0888:                // TODO: hard coding this frame id is fragile, portal dependent, and needs to be fixed -ggolden
0889:                setRefreshElement("sitenav");
0890:
0891:                return "tab";
0892:            }
0893:
0894:            /**
0895:             * Process the cancel command from the edit view.
0896:             * 
0897:             * @return navigation outcome to tab customization page (edit)
0898:             */
0899:            public String processActionCancel() {
0900:                LOG.debug("processActionCancel()");
0901:
0902:                // remove session variables
0903:                cancelEdit();
0904:                // To stay on the same page - load the page data
0905:                processActionEdit();
0906:                return "tab";
0907:            }
0908:
0909:            /**
0910:             * Process the cancel command from the edit view.
0911:             * 
0912:             * @return navigation outcome to Notification page (list)
0913:             */
0914:            public String processActionNotiFrmEdit() {
0915:                LOG.debug("processActionNotiFrmEdit()");
0916:
0917:                cancelEdit();
0918:                // navigation page data are loaded through getter method as navigation is the default page for 'sakai.preferences' tool.
0919:                return "noti";
0920:            }
0921:
0922:            /**
0923:             * Process the cancel command from the edit view.
0924:             * 
0925:             * @return navigation outcome to timezone page (list)
0926:             */
0927:            public String processActionTZFrmEdit() {
0928:                LOG.debug("processActionTZFrmEdit()");
0929:
0930:                cancelEdit();
0931:                // navigation page data are loaded through getter method as navigation is the default page for 'sakai.preferences' tool.
0932:                return "timezone";
0933:            }
0934:
0935:            /**
0936:             * Process the cancel command from the edit view.
0937:             * 
0938:             * @return navigation outcome to locale page (list)
0939:             */
0940:            public String processActionLocFrmEdit() {
0941:                LOG.debug("processActionLocFrmEdit()");
0942:
0943:                cancelEdit();
0944:                // navigation page data are loaded through getter method as navigation is the default page for 'sakai.preferences' tool.
0945:                return "locale";
0946:            }
0947:
0948:            /**
0949:             * Process the cancel command from the edit view.
0950:             * 
0951:             * @return navigation outcome to locale page (list)
0952:             */
0953:            public String processActionPrivFrmEdit() {
0954:                LOG.debug("processActionPrivFrmEdit()");
0955:
0956:                cancelEdit();
0957:                // navigation page data are loaded through getter method as navigation is the default page for 'sakai.preferences' tool.
0958:                return "privacy";
0959:            }
0960:
0961:            /**
0962:             * This is called from edit page for navigation to refresh page
0963:             * 
0964:             * @return navigation outcome to refresh page (refresh)
0965:             */
0966:            public String processActionRefreshFrmEdit() {
0967:                LOG.debug("processActionRefreshFrmEdit()");
0968:
0969:                // is required as user editing is set on while entering to tab customization page
0970:                cancelEdit();
0971:                loadRefreshData();
0972:                return "refresh";
0973:            }
0974:
0975:            // //////////////////////////////////// HELPER METHODS TO ACTIONS ////////////////////////////////////////////
0976:            /**
0977:             * Cancel the edit and cleanup.
0978:             */
0979:            protected void cancelEdit() {
0980:                LOG.debug("cancelEdit()");
0981:
0982:                // cleanup
0983:                m_stuff = null;
0984:                m_edit = null;
0985:                prefExcludeItems = new ArrayList();
0986:                prefOrderItems = new ArrayList();
0987:                isNewUser = false;
0988:
0989:                tabUpdated = false;
0990:                notiUpdated = false;
0991:                tzUpdated = false;
0992:                locUpdated = false;
0993:                refreshUpdated = false;
0994:            }
0995:
0996:            /**
0997:             * used with processActionAdd() and processActionRemove()
0998:             * 
0999:             * @return SelectItem
1000:             */
1001:            private SelectItem removeItems(String value, List items,
1002:                    String addtype, String removetype) {
1003:                if (LOG.isDebugEnabled()) {
1004:                    LOG.debug("removeItems(String " + value + ", List " + items
1005:                            + ", String " + addtype + ", String " + removetype
1006:                            + ")");
1007:                }
1008:
1009:                SelectItem result = null;
1010:                for (int i = 0; i < items.size(); i++) {
1011:                    SelectItem item = (SelectItem) items.get(i);
1012:                    if (value.equals(item.getValue())) {
1013:                        result = (SelectItem) items.remove(i);
1014:                        break;
1015:                    }
1016:                }
1017:                return result;
1018:            }
1019:
1020:            /**
1021:             * Set editing mode on for user and add user if not existing
1022:             */
1023:            protected void setUserEditingOn() {
1024:                LOG.debug("setUserEditingOn()");
1025:
1026:                try {
1027:                    m_edit = m_preferencesService.edit(getUserId());
1028:                } catch (IdUnusedException e) {
1029:                    try {
1030:                        m_edit = m_preferencesService.add(getUserId());
1031:                        isNewUser = true;
1032:                    } catch (Exception ee) {
1033:                        FacesContext.getCurrentInstance().addMessage(null,
1034:                                new FacesMessage(ee.toString()));
1035:                    }
1036:                } catch (Exception e) {
1037:                    FacesContext.getCurrentInstance().addMessage(null,
1038:                            new FacesMessage(e.toString()));
1039:                }
1040:            }
1041:
1042:            /**
1043:             * Save any changed values from the edit and cleanup.
1044:             */
1045:            protected void saveEdit() {
1046:                LOG.debug("saveEdit()");
1047:
1048:                // user editing is required as commit() disable isActive() flag
1049:                setUserEditingOn();
1050:                // move the stuff from m_stuff into the edit
1051:                for (Iterator i = m_stuff.iterator(); i.hasNext();) {
1052:                    KeyNameValue knv = (KeyNameValue) i.next();
1053:                    // find the original to remove (unless this one was new)
1054:                    if (!knv.getOrigKey().equals("")) {
1055:                        ResourcePropertiesEdit props = m_edit
1056:                                .getPropertiesEdit(knv.getOrigKey());
1057:                        props.removeProperty(knv.getOrigName());
1058:                    }
1059:                    // add the new if we have a key and name and value
1060:                    if ((!knv.getKey().equals(""))
1061:                            && (!knv.getName().equals(""))
1062:                            && (!knv.getValue().equals(""))) {
1063:                        ResourcePropertiesEdit props = m_edit
1064:                                .getPropertiesEdit(knv.getKey());
1065:                        if (knv.isList()) {
1066:                            // split by ", "
1067:                            String[] parts = knv.getValue().split(", ");
1068:                            for (int p = 0; p < parts.length; p++) {
1069:                                props
1070:                                        .addPropertyToList(knv.getName(),
1071:                                                parts[p]);
1072:                            }
1073:                        } else {
1074:                            props.addProperty(knv.getName(), knv.getValue());
1075:                        }
1076:                    }
1077:                }
1078:                // save the preferences, release the edit
1079:                m_preferencesService.commit(m_edit);
1080:            }
1081:
1082:            /**
1083:             * Check String has value, not null
1084:             * 
1085:             * @return boolean
1086:             */
1087:            protected boolean hasValue(String eval) {
1088:                if (LOG.isDebugEnabled()) {
1089:                    LOG.debug("hasValue(String " + eval + ")");
1090:                }
1091:
1092:                if (eval != null && !eval.trim().equals("")) {
1093:                    return true;
1094:                } else {
1095:                    return false;
1096:                }
1097:            }
1098:
1099:            // Copied from CheronPortal.java
1100:            /**
1101:             * Find the site in the list that has this id - return the position. *
1102:             * 
1103:             * @param value
1104:             *        The site id to find.
1105:             * @param siteList
1106:             *        The list of Site objects.
1107:             * @return The index position in siteList of the site with site id = value, or -1 if not found.
1108:             */
1109:            protected int indexOf(String value, List siteList) {
1110:                if (LOG.isDebugEnabled()) {
1111:                    LOG.debug("indexOf(String " + value + ", List " + siteList
1112:                            + ")");
1113:                }
1114:
1115:                for (int i = 0; i < siteList.size(); i++) {
1116:                    Site site = (Site) siteList.get(i);
1117:                    if (site.equals(value)) {
1118:                        return i;
1119:                    }
1120:                }
1121:                return -1;
1122:            }
1123:
1124:            // ////////////////////////////////// NOTIFICATION ACTIONS ////////////////////////////////
1125:            private String selectedAnnItem = "";
1126:
1127:            private String selectedMailItem = "";
1128:
1129:            private String selectedRsrcItem = "";
1130:
1131:            private String selectedSyllItem = "";
1132:
1133:            protected boolean notiUpdated = false;
1134:
1135:            protected boolean tzUpdated = false;
1136:
1137:            protected boolean locUpdated = false;
1138:
1139:            // ///////////////////////////////// GETTER AND SETTER ///////////////////////////////////
1140:            // TODO chec for any preprocessor for handling request for first time. This can simplify getter() methods as below
1141:            /**
1142:             * @return Returns the selectedAnnItem.
1143:             */
1144:            public String getSelectedAnnItem() {
1145:                LOG.debug("getSelectedAnnItem()");
1146:
1147:                if (!hasValue(selectedAnnItem)) {
1148:                    Preferences prefs = (PreferencesEdit) m_preferencesService
1149:                            .getPreferences(getUserId());
1150:                    String a = buildTypePrefsContext(
1151:                            AnnouncementService.APPLICATION_ID, "annc",
1152:                            selectedAnnItem, prefs);
1153:                    if (hasValue(a)) {
1154:                        selectedAnnItem = a; // load from saved data
1155:                    } else {
1156:                        selectedAnnItem = "3"; // default setting
1157:                    }
1158:                }
1159:                return selectedAnnItem;
1160:            }
1161:
1162:            /**
1163:             * @param selectedAnnItem
1164:             *        The selectedAnnItem to set.
1165:             */
1166:            public void setSelectedAnnItem(String selectedAnnItem) {
1167:                if (LOG.isDebugEnabled()) {
1168:                    LOG.debug("setSelectedAnnItem(String " + selectedAnnItem
1169:                            + ")");
1170:                }
1171:
1172:                this .selectedAnnItem = selectedAnnItem;
1173:            }
1174:
1175:            /**
1176:             * @return Returns the selectedMailItem.
1177:             */
1178:            public String getSelectedMailItem() {
1179:                LOG.debug("getSelectedMailItem()");
1180:
1181:                if (!hasValue(this .selectedMailItem)) {
1182:                    Preferences prefs = (PreferencesEdit) m_preferencesService
1183:                            .getPreferences(getUserId());
1184:                    String a = buildTypePrefsContext(
1185:                            MailArchiveService.APPLICATION_ID, "mail",
1186:                            selectedMailItem, prefs);
1187:                    if (hasValue(a)) {
1188:                        selectedMailItem = a; // load from saved data
1189:                    } else {
1190:                        selectedMailItem = "3"; // default setting
1191:                    }
1192:                }
1193:                return selectedMailItem;
1194:            }
1195:
1196:            /**
1197:             * @param selectedMailItem
1198:             *        The selectedMailItem to set.
1199:             */
1200:            public void setSelectedMailItem(String selectedMailItem) {
1201:                if (LOG.isDebugEnabled()) {
1202:                    LOG.debug("setSelectedMailItem(String " + selectedMailItem
1203:                            + ")");
1204:                }
1205:
1206:                this .selectedMailItem = selectedMailItem;
1207:            }
1208:
1209:            /**
1210:             * @return Returns the selectedRsrcItem.
1211:             */
1212:            public String getSelectedRsrcItem() {
1213:                LOG.debug("getSelectedRsrcItem()");
1214:
1215:                if (!hasValue(this .selectedRsrcItem)) {
1216:                    Preferences prefs = (PreferencesEdit) m_preferencesService
1217:                            .getPreferences(getUserId());
1218:                    String a = buildTypePrefsContext(
1219:                            ContentHostingService.APPLICATION_ID, "rsrc",
1220:                            selectedRsrcItem, prefs);
1221:                    if (hasValue(a)) {
1222:                        selectedRsrcItem = a; // load from saved data
1223:                    } else {
1224:                        selectedRsrcItem = "3"; // default setting
1225:                    }
1226:                }
1227:                return selectedRsrcItem;
1228:            }
1229:
1230:            /**
1231:             * @param selectedRsrcItem
1232:             *        The selectedRsrcItem to set.
1233:             */
1234:            public void setSelectedRsrcItem(String selectedRsrcItem) {
1235:                if (LOG.isDebugEnabled()) {
1236:                    LOG.debug("setSelectedRsrcItem(String " + selectedRsrcItem
1237:                            + ")");
1238:                }
1239:
1240:                this .selectedRsrcItem = selectedRsrcItem;
1241:            }
1242:
1243:            // syllabus
1244:            public String getSelectedSyllItem() {
1245:                LOG.debug("getSelectedSyllItem()");
1246:
1247:                if (!hasValue(this .selectedSyllItem)) {
1248:                    Preferences prefs = (PreferencesEdit) m_preferencesService
1249:                            .getPreferences(getUserId());
1250:                    String a = buildTypePrefsContext(
1251:                            SyllabusService.APPLICATION_ID, "syll",
1252:                            selectedSyllItem, prefs);
1253:                    if (hasValue(a)) {
1254:                        selectedSyllItem = a; // load from saved data
1255:                    } else {
1256:                        selectedSyllItem = "3"; // default setting
1257:                    }
1258:                }
1259:                return selectedSyllItem;
1260:            }
1261:
1262:            public void setSelectedSyllItem(String selectedSyllItem) {
1263:                if (LOG.isDebugEnabled()) {
1264:                    LOG.debug("setSelectedRsrcItem(String " + selectedRsrcItem
1265:                            + ")");
1266:                }
1267:
1268:                this .selectedSyllItem = selectedSyllItem;
1269:            }
1270:
1271:            /**
1272:             * @return Returns the notiUpdated.
1273:             */
1274:            public boolean getNotiUpdated() {
1275:                return notiUpdated;
1276:            }
1277:
1278:            /**
1279:             * @param notiUpdated
1280:             *        The notiUpdated to set.
1281:             */
1282:            public void setNotiUpdated(boolean notiUpdated) {
1283:                this .notiUpdated = notiUpdated;
1284:            }
1285:
1286:            /**
1287:             * @return Returns the tzUpdated.
1288:             */
1289:            public boolean getTzUpdated() {
1290:                return tzUpdated;
1291:            }
1292:
1293:            /**
1294:             * @param notiUpdated
1295:             *        The tzUpdated to set.
1296:             */
1297:            public void setTzUpdated(boolean tzUpdated) {
1298:                this .tzUpdated = tzUpdated;
1299:            }
1300:
1301:            /**
1302:             * @return Returns the tzUpdated.
1303:             */
1304:            public boolean getLocUpdated() {
1305:                return locUpdated;
1306:            }
1307:
1308:            /**
1309:             * @param notiUpdated
1310:             *        The locUpdated to set.
1311:             */
1312:            public void setLocUpdated(boolean locUpdated) {
1313:                this .locUpdated = locUpdated;
1314:            }
1315:
1316:            // ///////////////////////////////////////NOTIFICATION ACTION - copied from NotificationprefsAction.java////////
1317:            // TODO - clean up method call. These are basically copied from legacy legacy implementations.
1318:            /**
1319:             * Process the save command from the edit view.
1320:             * 
1321:             * @return navigation outcome to notification page
1322:             */
1323:            public String processActionNotiSave() {
1324:                LOG.debug("processActionNotiSave()");
1325:
1326:                // get an edit
1327:                setUserEditingOn();
1328:                if (m_edit != null) {
1329:                    readTypePrefs(AnnouncementService.APPLICATION_ID, "annc",
1330:                            m_edit, getSelectedAnnItem());
1331:                    readTypePrefs(MailArchiveService.APPLICATION_ID, "mail",
1332:                            m_edit, getSelectedMailItem());
1333:                    readTypePrefs(ContentHostingService.APPLICATION_ID, "rsrc",
1334:                            m_edit, getSelectedRsrcItem());
1335:                    readTypePrefs(SyllabusService.APPLICATION_ID, "syll",
1336:                            m_edit, getSelectedSyllItem());
1337:
1338:                    // update the edit and release it
1339:                    m_preferencesService.commit(m_edit);
1340:                }
1341:                notiUpdated = true;
1342:                return "noti";
1343:            }
1344:
1345:            /**
1346:             * process notification cancel
1347:             * 
1348:             * @return navigation outcome to notification page
1349:             */
1350:            public String processActionNotiCancel() {
1351:                LOG.debug("processActionNotiCancel()");
1352:
1353:                loadNotiData();
1354:                return "noti";
1355:            }
1356:
1357:            /**
1358:             * Process the save command from the edit view.
1359:             * 
1360:             * @return navigation outcome to timezone page
1361:             */
1362:            public String processActionTzSave() {
1363:                setUserEditingOn();
1364:                ResourcePropertiesEdit props = m_edit
1365:                        .getPropertiesEdit(TimeService.APPLICATION_ID);
1366:                props.addProperty(TimeService.TIMEZONE_KEY, m_timeZone.getID());
1367:                m_preferencesService.commit(m_edit);
1368:
1369:                TimeService.clearLocalTimeZone(getUserId()); // clear user's cached timezone
1370:
1371:                tzUpdated = true; // set for display of text massage
1372:                return "timezone";
1373:            }
1374:
1375:            /**
1376:             * process timezone cancel
1377:             * 
1378:             * @return navigation outcome to timezone page
1379:             */
1380:            public String processActionTzCancel() {
1381:                LOG.debug("processActionTzCancel()");
1382:
1383:                // restore original time zone
1384:                m_timeZone = null;
1385:                getSelectedTimeZone();
1386:
1387:                return "timezone";
1388:            }
1389:
1390:            /**
1391:             * Process the save command from the edit view.
1392:             * 
1393:             * @return navigation outcome to locale page
1394:             */
1395:            public String processActionLocSave() {
1396:                setUserEditingOn();
1397:                ResourcePropertiesEdit props = m_edit
1398:                        .getPropertiesEdit(ResourceLoader.APPLICATION_ID);
1399:                props.addProperty(ResourceLoader.LOCALE_KEY, m_locale
1400:                        .toString());
1401:                m_preferencesService.commit(m_edit);
1402:
1403:                TimeService.clearLocalTimeZone(getUserId()); // clear user's cached timezone
1404:
1405:                locUpdated = true; // set for display of text massage
1406:                return "locale";
1407:            }
1408:
1409:            /**
1410:             * process locale cancel
1411:             * 
1412:             * @return navigation outcome to locale page
1413:             */
1414:            public String processActionLocCancel() {
1415:                LOG.debug("processActionLocCancel()");
1416:
1417:                // restore original locale
1418:                m_locale = null;
1419:                getSelectedLocale();
1420:
1421:                return "locale";
1422:            }
1423:
1424:            /**
1425:             * This is called from notification page for navigation to Refresh page
1426:             * 
1427:             * @return navigation outcome to refresh page
1428:             */
1429:            public String processActionRefreshFrmNoti() {
1430:                LOG.debug("processActionRefreshFrmNoti()");
1431:
1432:                loadRefreshData();
1433:                return "refresh";
1434:            }
1435:
1436:            // ////////////////////////////////////// HELPER METHODS FOR NOTIFICATIONS /////////////////////////////////////
1437:            /**
1438:             * Load saved notification data - this is called from cancel button of notification page as navigation stays in the page
1439:             */
1440:            protected void loadNotiData() {
1441:                LOG.debug("loadNotiData()");
1442:
1443:                selectedAnnItem = "";
1444:                selectedMailItem = "";
1445:                selectedRsrcItem = "";
1446:                selectedSyllItem = "";
1447:                notiUpdated = false;
1448:                Preferences prefs = (PreferencesEdit) m_preferencesService
1449:                        .getPreferences(getUserId());
1450:                String a = buildTypePrefsContext(
1451:                        AnnouncementService.APPLICATION_ID, "annc",
1452:                        selectedAnnItem, prefs);
1453:                if (hasValue(a)) {
1454:                    selectedAnnItem = a; // load from saved data
1455:                } else {
1456:                    selectedAnnItem = "3"; // default setting
1457:                }
1458:                String m = buildTypePrefsContext(
1459:                        MailArchiveService.APPLICATION_ID, "mail",
1460:                        selectedMailItem, prefs);
1461:                if (hasValue(m)) {
1462:                    selectedMailItem = m; // load from saved data
1463:                } else {
1464:                    selectedMailItem = "3"; // default setting
1465:                }
1466:                String r = buildTypePrefsContext(
1467:                        ContentHostingService.APPLICATION_ID, "rsrc",
1468:                        selectedRsrcItem, prefs);
1469:                if (hasValue(r)) {
1470:                    selectedRsrcItem = r; // load from saved data
1471:                } else {
1472:                    selectedRsrcItem = "3"; // default setting
1473:                }
1474:                // syllabus
1475:                String s = buildTypePrefsContext(
1476:                        SyllabusService.APPLICATION_ID, "syll",
1477:                        selectedSyllItem, prefs);
1478:                if (hasValue(s)) {
1479:                    selectedSyllItem = s; // load from saved data
1480:                } else {
1481:                    selectedSyllItem = "2"; // default setting
1482:                }
1483:            }
1484:
1485:            /**
1486:             * Read the two context references for defaults for this type from the form.
1487:             * 
1488:             * @param type
1489:             *        The resource type (i.e. a service name).
1490:             * @param prefix
1491:             *        The prefix for context references.
1492:             * @param edit
1493:             *        The preferences being edited.
1494:             * @param data
1495:             *        The rundata with the form fields.
1496:             */
1497:            protected void readTypePrefs(String type, String prefix,
1498:                    PreferencesEdit edit, String data) {
1499:                if (LOG.isDebugEnabled()) {
1500:                    LOG.debug("readTypePrefs(String " + type + ", String "
1501:                            + prefix + ", PreferencesEdit " + edit
1502:                            + ", String " + data + ")");
1503:                }
1504:
1505:                // update the default settings from the form
1506:                ResourcePropertiesEdit props = edit
1507:                        .getPropertiesEdit(NotificationService.PREFS_TYPE
1508:                                + type);
1509:
1510:                // read the defaults
1511:                props.addProperty(Integer
1512:                        .toString(NotificationService.NOTI_OPTIONAL), data);
1513:
1514:            } // readTypePrefs
1515:
1516:            /**
1517:             * Add the two context references for defaults for this type.
1518:             * 
1519:             * @param type
1520:             *        The resource type (i.e. a service name).
1521:             * @param prefix
1522:             *        The prefix for context references.
1523:             * @param context
1524:             *        The context.
1525:             * @param prefs
1526:             *        The full set of preferences.
1527:             */
1528:            protected String buildTypePrefsContext(String type, String prefix,
1529:                    String context, Preferences prefs) {
1530:                if (LOG.isDebugEnabled()) {
1531:                    LOG.debug("buildTypePrefsContext(String " + type
1532:                            + ", String " + prefix + ", String " + context
1533:                            + ", Preferences " + prefs + ")");
1534:                }
1535:
1536:                ResourceProperties props = prefs
1537:                        .getProperties(NotificationService.PREFS_TYPE + type);
1538:                String value = props.getProperty(new Integer(
1539:                        NotificationService.NOTI_OPTIONAL).toString());
1540:
1541:                return value;
1542:            }
1543:
1544:            // ////////////////////////////////////// REFRESH //////////////////////////////////////////
1545:            private String selectedRefreshItem = "";
1546:
1547:            protected boolean refreshUpdated = false;
1548:
1549:            /**
1550:             * @return Returns the selectedRefreshItem.
1551:             */
1552:            public String getSelectedRefreshItem() {
1553:                return selectedRefreshItem;
1554:            }
1555:
1556:            /**
1557:             * @param selectedRefreshItem
1558:             *        The selectedRefreshItem to set.
1559:             */
1560:            public void setSelectedRefreshItem(String selectedRefreshItem) {
1561:                if (LOG.isDebugEnabled()) {
1562:                    LOG.debug("setSelectedRefreshItem(String "
1563:                            + selectedRefreshItem + ")");
1564:                }
1565:
1566:                this .selectedRefreshItem = selectedRefreshItem;
1567:            }
1568:
1569:            // /**
1570:            // * process saving of refresh
1571:            // *
1572:            // * @return navigation outcome to refresh page
1573:            // */
1574:            // public String processActionRefreshSave()
1575:            // {
1576:            // LOG.debug("processActionRefreshSave()");
1577:            //
1578:            // // get an edit
1579:            // setUserEditingOn();
1580:            // if (m_edit != null)
1581:            // {
1582:            // setStringPref(PortalService.SERVICE_NAME, "refresh", m_edit, getSelectedRefreshItem());
1583:            // // update the edit and release it
1584:            // m_preferencesService.commit(m_edit);
1585:            // }
1586:            // refreshUpdated = true;
1587:            // return "refresh";
1588:            // }
1589:
1590:            /**
1591:             * Process cancel and navigate to list page.
1592:             * 
1593:             * @return navigation outcome to refresh page
1594:             */
1595:            public String processActionRefreshCancel() {
1596:                LOG.debug("processActionRefreshCancel()");
1597:
1598:                loadRefreshData();
1599:                return "refresh";
1600:            }
1601:
1602:            /**
1603:             * Process cancel and navigate to list page.
1604:             * 
1605:             * @return navigation outcome to notification page
1606:             */
1607:            public String processActionNotiFrmRefresh() {
1608:                LOG.debug("processActionNotiFrmRefresh()");
1609:
1610:                loadNotiData();
1611:                return "noti";
1612:            }
1613:
1614:            // ///////////////////////////////////// HELPER METHODS FOR REFRESH /////////////////////////
1615:            /**
1616:             * Load refresh data from stored information. This is called when navigated into this page for first time.
1617:             */
1618:            protected void loadRefreshData() {
1619:                LOG.debug("loadRefreshData()");
1620:
1621:                selectedRefreshItem = "";
1622:                refreshUpdated = false;
1623:                if (!hasValue(selectedRefreshItem)) {
1624:                    Preferences prefs = (PreferencesEdit) m_preferencesService
1625:                            .getPreferences(getUserId());
1626:                    // String a = getStringPref(PortalService.SERVICE_NAME, "refresh", prefs);
1627:                    // if (hasValue(a))
1628:                    // {
1629:                    // setSelectedRefreshItem(a); // load from saved data
1630:                    // }
1631:                    // else
1632:                    // {
1633:                    // setSelectedRefreshItem("2"); // default setting
1634:                    // }
1635:                }
1636:            }
1637:
1638:            /**
1639:             * Set an integer preference.
1640:             * 
1641:             * @param pres_base
1642:             *        The name of the group of properties (i.e. a service name)
1643:             * @param type
1644:             *        The particular property
1645:             * @param edit
1646:             *        An edit version of the full set of preferences for the current logged in user.
1647:             * @param newval
1648:             *        The string to be the new preference.
1649:             */
1650:            protected void setStringPref(String pref_base, String type,
1651:                    PreferencesEdit edit, String newval) {
1652:                if (LOG.isDebugEnabled()) {
1653:                    LOG.debug("setStringPref(String " + pref_base + ", String "
1654:                            + type + ", PreferencesEdit " + edit + ", String "
1655:                            + newval + ")");
1656:                }
1657:
1658:                ResourcePropertiesEdit props = edit
1659:                        .getPropertiesEdit(pref_base);
1660:
1661:                props.addProperty(type, newval);
1662:            } // setStringPref
1663:
1664:            /**
1665:             * Retrieve a preference
1666:             * 
1667:             * @param pres_base
1668:             *        The name of the group of properties (i.e. a service name)
1669:             * @param type
1670:             *        The particular property
1671:             * @param prefs
1672:             *        The full set of preferences for the current logged in user.
1673:             */
1674:            protected String getStringPref(String pref_base, String type,
1675:                    Preferences prefs) {
1676:                if (LOG.isDebugEnabled()) {
1677:                    LOG.debug("getStringPref(String " + pref_base + ", String "
1678:                            + type + ", PreferencesEdit " + prefs + ")");
1679:                }
1680:
1681:                ResourceProperties props = prefs.getProperties(pref_base);
1682:                String a = props.getProperty(type);
1683:                return a;
1684:            } // getIntegerPref
1685:
1686:            /** The html "peer" element to refresh on the next rendering. */
1687:            protected String m_refreshElement = null;
1688:
1689:            /**
1690:             * Get, and clear, the refresh element
1691:             * 
1692:             * @return The html "peer" element to refresh on the next rendering, or null if none defined.
1693:             */
1694:            public String getRefreshElement() {
1695:                String rv = m_refreshElement;
1696:                m_refreshElement = null;
1697:                return rv;
1698:            }
1699:
1700:            /**
1701:             * Set the "peer" html element to refresh on the next rendering.
1702:             * 
1703:             * @param element
1704:             */
1705:            public void setRefreshElement(String element) {
1706:                m_refreshElement = element;
1707:            }
1708:
1709:            /**
1710:             * Pull whether privacy status should be enabled from sakai.properties
1711:             * 
1712:             */
1713:            public boolean isPrivacyEnabled() {
1714:                return new Boolean(ServerConfigurationService
1715:                        .getString(ENABLE_PRIVACY_STATUS)).booleanValue();
1716:            }
1717:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.