Source Code Cross Referenced for SettingsHandler.java in  » Portal » Open-Portal » com » sun » portal » rssportlet » 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 » Portal » Open Portal » com.sun.portal.rssportlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: SettingsHandler.java,v 1.2 2006/04/17 20:08:42 jtb Exp $
003:         * Copyright 2003 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.rssportlet;
014:
015:        import java.io.IOException;
016:        import java.util.Arrays;
017:        import java.util.LinkedList;
018:        import javax.portlet.PortletConfig;
019:        import javax.portlet.PortletPreferences;
020:        import javax.portlet.PortletRequest;
021:        import javax.portlet.PortletSession;
022:        import javax.portlet.ReadOnlyException;
023:        import javax.portlet.ValidatorException;
024:
025:        /**
026:         * This class builds a <code>SettingsBean</code> object.
027:         */
028:        public class SettingsHandler {
029:            //
030:            // portlet preference keys
031:            //
032:            private interface PrefKeys {
033:                public static final String FEEDS = "feeds";
034:                public static final String MAX_DESCRIPTION_LENGTH = "maxDescriptionLength";
035:                public static final String CACHE_TIMEOUT = "cacheTimeout";
036:                public static final String NEWWIN = "newWindow";
037:                public static final String MAX_AGE = "maxAge";
038:                public static final String MAX_ENTRIES = "maxEntries";
039:                public static final String DISABLE_MAX_AGE = "disableMaxAge";
040:            }
041:
042:            //
043:            // session attribute keys
044:            //
045:            private interface SessionKeys {
046:                public static final String SELECTED_FEED = "selectedFeed";
047:            }
048:
049:            private SettingsBean settingsBean;
050:
051:            private PortletRequest portletRequest = null;
052:            private PortletConfig portletConfig = null;
053:
054:            /**
055:             * Initialize the <code>RssPortletBean</code>.
056:             *
057:             * This is called after the bean has been set into this handler.
058:             */
059:            private void initSettingsBean() {
060:                LinkedList feeds = new LinkedList(Arrays
061:                        .asList(getPortletPreferences().getValues(
062:                                PrefKeys.FEEDS, new String[] {})));
063:                getSettingsBean().setFeeds(feeds);
064:                int maxAge = getIntPreference(PrefKeys.MAX_AGE, 72);
065:                getSettingsBean().setMaxAge(maxAge);
066:                int cacheTimeout = getIntPreference(PrefKeys.CACHE_TIMEOUT,
067:                        3600);
068:                getSettingsBean().setCacheTimeout(cacheTimeout);
069:                int maxDescriptionLength = getIntPreference(
070:                        PrefKeys.MAX_DESCRIPTION_LENGTH, 512);
071:                getSettingsBean().setMaxDescriptionLength(maxDescriptionLength);
072:                boolean newWindow = getBooleanPreference(PrefKeys.NEWWIN, false);
073:                getSettingsBean().setNewWindow(newWindow);
074:                boolean disableMaxAge = getBooleanPreference(
075:                        PrefKeys.DISABLE_MAX_AGE, false);
076:                getSettingsBean().setDisableMaxAge(disableMaxAge);
077:                int maxEntries = getIntPreference(PrefKeys.MAX_ENTRIES, 5);
078:                getSettingsBean().setMaxEntries(maxEntries);
079:
080:                initSelectedFeed();
081:
082:                getSettingsBean().setLocale(getPortletRequest().getLocale());
083:            }
084:
085:            /**
086:             * Initialize the <code>selectedFeed</code>
087:             * field of the <code>RssPortletBean</code>.
088:             */
089:            private void initSelectedFeed() {
090:                // first, try to get from session
091:                String selectedFeed = (String) getPortletRequest()
092:                        .getPortletSession().getAttribute(
093:                                SessionKeys.SELECTED_FEED);
094:
095:                if (selectedFeed == null || selectedFeed.trim().length() == 0) {
096:                    // next, try to get from start feed
097:                    selectedFeed = getSettingsBean().getStartFeed();
098:                }
099:
100:                // might be null
101:                getSettingsBean().setSelectedFeed(selectedFeed);
102:            }
103:
104:            /**
105:             * Persist this handler's <code>RssPortletBean</code>, if necessary.
106:             */
107:            public void persistSettingsBean(SettingsBean delta)
108:                    throws ReadOnlyException, IOException, ValidatorException {
109:                boolean store = false;
110:
111:                // selected feed        
112:                if (delta.getFeeds() != null && delta.getFeedsSize() == 0) {
113:                    // if there are no feeds, set the selected feed to null
114:                    getPortletSession().setAttribute(SessionKeys.SELECTED_FEED,
115:                            null);
116:                } else if (delta.getSelectedFeed() != null) {
117:                    getPortletSession().setAttribute(SessionKeys.SELECTED_FEED,
118:                            delta.getSelectedFeed());
119:                }
120:
121:                // feeds
122:                if (delta.getFeeds() != null) {
123:                    getPortletPreferences().setValues(PrefKeys.FEEDS,
124:                            (String[]) delta.getFeeds().toArray(new String[0]));
125:                    store = true;
126:                }
127:
128:                // max age
129:                if (delta.isMaxAgeSet()) {
130:                    getPortletPreferences().setValue(PrefKeys.MAX_AGE,
131:                            Integer.toString(delta.getMaxAge()));
132:                    store = true;
133:                }
134:
135:                // disable max age
136:                if (delta.isDisableMaxAgeSet()) {
137:                    getPortletPreferences().setValue(PrefKeys.DISABLE_MAX_AGE,
138:                            Boolean.toString(delta.isDisableMaxAge()));
139:                    store = true;
140:                }
141:
142:                // max entries
143:                if (delta.isMaxEntriesSet()) {
144:                    getPortletPreferences().setValue(PrefKeys.MAX_ENTRIES,
145:                            Integer.toString(delta.getMaxEntries()));
146:                    store = true;
147:                }
148:
149:                // new window
150:                if (delta.isNewWindowSet()) {
151:                    getPortletPreferences().setValue(PrefKeys.NEWWIN,
152:                            Boolean.toString(delta.isNewWindow()));
153:                    store = true;
154:                }
155:
156:                if (store) {
157:                    getPortletPreferences().store();
158:                }
159:            }
160:
161:            /** Get a portlet preference as an int. */
162:            private int getIntPreference(String key, int def) {
163:                String s = getPortletPreferences().getValue(key, null);
164:                int i = def;
165:                try {
166:                    i = Integer.parseInt(s);
167:                } catch (NumberFormatException nfe) {
168:                    i = def;
169:                }
170:
171:                return i;
172:            }
173:
174:            /** Get a portlet preference as a boolean. */
175:            private boolean getBooleanPreference(String key, boolean def) {
176:                Boolean b = Boolean.valueOf(getPortletPreferences().getValue(
177:                        key, "false"));
178:                return b.booleanValue();
179:            }
180:
181:            /** Get the Rss portlet bean. */
182:            public SettingsBean getSettingsBean() {
183:                return settingsBean;
184:            }
185:
186:            /** Set the Rss portlet bean. */
187:            public void setSettingsBean(SettingsBean settingsBean) {
188:                this .settingsBean = settingsBean;
189:                initSettingsBean();
190:            }
191:
192:            /** Get the portlet request. */
193:            private PortletRequest getPortletRequest() {
194:                return portletRequest;
195:            }
196:
197:            /** Set the portlet request. */
198:            public void setPortletRequest(PortletRequest portletRequest) {
199:                this .portletRequest = portletRequest;
200:            }
201:
202:            /** Get the portlet config. */
203:            private PortletConfig getPortletConfig() {
204:                return portletConfig;
205:            }
206:
207:            /** Set the portlet config. */
208:            public void setPortletConfig(PortletConfig portletConfig) {
209:                this .portletConfig = portletConfig;
210:            }
211:
212:            /** Get the portlet preferences. */
213:            private PortletPreferences getPortletPreferences() {
214:                return getPortletRequest().getPreferences();
215:            }
216:
217:            /** Get the portlet session. */
218:            private PortletSession getPortletSession() {
219:                return getPortletRequest().getPortletSession();
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.