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


001:        /*
002:         * Copyright ? 2006 Sun Microsystems, Inc. All rights reserved. 
003:         *
004:         * Sun Microsystems, Inc. has intellectual property rights relating to
005:         * technology embodied in the product that is described in this document. 
006:         * In particular, and without limitation, these intellectual property 
007:         * rights may include one or more of the U.S. patents listed at 
008:         * http://www.sun.com/patents and one or more additional patents or
009:         * pending patent applications in the U.S. and in other countries.
010:         * 
011:         * U.S. Government Rights - Commercial software. Government users are subject
012:         * to the Sun Microsystems, Inc. standard license agreement and applicable 
013:         * provisions of the FAR and its supplements. Use is subject to license terms. 
014:         * This distribution may include materials developed by third parties.
015:         * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered 
016:         * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. 
017:         */
018:        package com.sun.portal.app.blog.env;
019:
020:        import com.sun.portal.app.blog.BlogPortletException;
021:        import com.sun.portal.app.blog.password.Password;
022:        import java.io.IOException;
023:        import java.io.InputStream;
024:        import java.net.MalformedURLException;
025:        import java.net.URL;
026:        import javax.crypto.SecretKey;
027:        import javax.servlet.ServletContextEvent;
028:        import javax.servlet.ServletContextListener;
029:
030:        /**
031:         * Abstract base class for preferences.
032:         *
033:         * Implementations of this class define the concept of 
034:         * preferences for different runtime application runtime environments.
035:         */
036:        public abstract class AbstractPrefs implements  Prefs,
037:                ServletContextListener {
038:            private static AbstractPrefs prefs;
039:            private static Password password = new Password();
040:
041:            private SecretKey secret;
042:
043:            public AbstractPrefs() {
044:                InputStream is = this .getClass().getClassLoader()
045:                        .getResourceAsStream("passwords.key");
046:                try {
047:                    secret = password.readKey(is);
048:                } catch (BlogPortletException bpe) {
049:                    throw new RuntimeException(bpe);
050:                }
051:            }
052:
053:            public static AbstractPrefs getInstance() {
054:                if (prefs == null) {
055:                    throw new IllegalStateException("prefs instance is null");
056:                }
057:
058:                return prefs;
059:            }
060:
061:            public static void setInstance(AbstractPrefs prefs) {
062:                AbstractPrefs.prefs = prefs;
063:            }
064:
065:            public void contextInitialized(ServletContextEvent event) {
066:                setInstance(this );
067:            }
068:
069:            public void contextDestroyed(ServletContextEvent event) {
070:                //nothing
071:            }
072:
073:            public String getAppUserPassword() throws BlogPortletException {
074:                if (isEncryptedPasswords()) {
075:                    return decrypt(getRawAppUserPassword());
076:                } else {
077:                    return getRawAppUserPassword();
078:                }
079:            }
080:
081:            public String getAappUserPassword() throws BlogPortletException {
082:                if (isEncryptedPasswords()) {
083:                    return decrypt(getRawAappUserPassword());
084:                } else {
085:                    return getRawAappUserPassword();
086:                }
087:            }
088:
089:            public void setAppUserPassword(String val)
090:                    throws BlogPortletException {
091:                if (isEncryptedPasswords()) {
092:                    setRawAppUserPassword(encrypt(val));
093:                } else {
094:                    setRawAppUserPassword(val);
095:                }
096:            }
097:
098:            /**
099:             * Decrypt a password string. 
100:             *
101:             * This method is provided as a service for subclasses.
102:             */
103:            protected String decrypt(String epw) throws BlogPortletException {
104:                return password.decrypt(epw, secret);
105:            }
106:
107:            /**
108:             * Encrypt a password string. 
109:             *
110:             * This method is provided as a service for subclasses.
111:             */
112:            protected String encrypt(String dpw) throws BlogPortletException {
113:                return password.encrypt(dpw, secret);
114:            }
115:
116:            protected abstract String getPreference(String key)
117:                    throws BlogPortletException;
118:
119:            protected abstract void setPreference(String key, String val)
120:                    throws BlogPortletException;
121:
122:            public abstract void store() throws BlogPortletException;
123:
124:            public String getAppEntriesUrl() throws BlogPortletException {
125:                return getPreference(PortletPreferenceKeys.APP_ENTRIES_URL);
126:            }
127:
128:            public String getAppUrl() throws BlogPortletException {
129:                return getPreference(PortletPreferenceKeys.APP_URL);
130:            }
131:
132:            public String getAppUserName() throws BlogPortletException {
133:                return getPreference(PortletPreferenceKeys.APP_USER_NAME);
134:            }
135:
136:            public String getRawAppUserPassword() throws BlogPortletException {
137:                return getPreference(PortletPreferenceKeys.APP_USER_PASSWORD);
138:            }
139:
140:            public String getAappUrl() throws BlogPortletException {
141:                return getPreference(PortletPreferenceKeys.AAPP_URL);
142:            }
143:
144:            public String getAappUserName() throws BlogPortletException {
145:                return getPreference(PortletPreferenceKeys.AAPP_USER_NAME);
146:            }
147:
148:            public String getRawAappUserPassword() throws BlogPortletException {
149:                return getPreference(PortletPreferenceKeys.AAPP_USER_PASSWORD);
150:            }
151:
152:            public String getHandle() throws BlogPortletException {
153:                return getPreference(PortletPreferenceKeys.HANDLE);
154:            }
155:
156:            public String getConfigMode() throws BlogPortletException {
157:                return getPreference(PortletPreferenceKeys.CONFIG_MODE);
158:            }
159:
160:            public String getMemberPermission() throws BlogPortletException {
161:                return getPreference(PortletPreferenceKeys.MEMBER_PERMISSION);
162:            }
163:
164:            public String getUserUrl() throws BlogPortletException {
165:                return getPreference(PortletPreferenceKeys.USER_URL);
166:            }
167:
168:            public boolean isEncryptedPasswords() throws BlogPortletException {
169:                return new Boolean(
170:                        getPreference(PortletPreferenceKeys.ENCRYPTED_PASSWORDS))
171:                        .booleanValue();
172:            }
173:
174:            public int getPageSize() throws BlogPortletException {
175:                return Integer.valueOf(
176:                        getPreference(PortletPreferenceKeys.PAGE_SIZE))
177:                        .intValue();
178:            }
179:
180:            public URL getSearchUrl() throws BlogPortletException {
181:                String u = getPreference(PortletPreferenceKeys.SEARCH_URL);
182:                if (u == null || u.length() == 0) {
183:                    return null;
184:                }
185:
186:                try {
187:                    URL url = new URL(u);
188:                    return url;
189:                } catch (MalformedURLException mue) {
190:                    throw new BlogPortletException(mue);
191:                }
192:            }
193:
194:            public String getSearchDatabase() throws BlogPortletException {
195:                String db = getPreference(PortletPreferenceKeys.SEARCH_DATABASE);
196:                if (db == null || db.length() == 0) {
197:                    return null;
198:                }
199:
200:                return db;
201:            }
202:
203:            public int getRefreshInterval() throws BlogPortletException {
204:                return Integer.valueOf(
205:                        getPreference(PortletPreferenceKeys.REFRESH_INTERVAL))
206:                        .intValue();
207:            }
208:
209:            public void setAppUrl(String appUrl) throws BlogPortletException {
210:                setPreference(PortletPreferenceKeys.APP_URL, appUrl);
211:            }
212:
213:            public void setAppEntriesUrl(String appEntriesUrl)
214:                    throws BlogPortletException {
215:                setPreference(PortletPreferenceKeys.APP_ENTRIES_URL,
216:                        appEntriesUrl);
217:            }
218:
219:            public void setAppUserName(String appUserName)
220:                    throws BlogPortletException {
221:                setPreference(PortletPreferenceKeys.APP_USER_NAME, appUserName);
222:            }
223:
224:            public void setRawAppUserPassword(String appUserPassword)
225:                    throws BlogPortletException {
226:                setPreference(PortletPreferenceKeys.APP_USER_PASSWORD,
227:                        appUserPassword);
228:            }
229:
230:            public void setAappUrl(String aappUrl) throws BlogPortletException {
231:                setPreference(PortletPreferenceKeys.AAPP_URL, aappUrl);
232:            }
233:
234:            public void setAappUserName(String aappUserName)
235:                    throws BlogPortletException {
236:                setPreference(PortletPreferenceKeys.AAPP_USER_NAME,
237:                        aappUserName);
238:            }
239:
240:            public void setHandle(String handle) throws BlogPortletException {
241:                setPreference(PortletPreferenceKeys.HANDLE, handle);
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.