Source Code Cross Referenced for Preferences.java in  » Wiki-Engine » JSPWiki » com » ecyrd » jspwiki » preferences » 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 » Wiki Engine » JSPWiki » com.ecyrd.jspwiki.preferences 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.ecyrd.jspwiki.preferences;
002:
003:        import java.text.ParseException;
004:        import java.util.HashMap;
005:        import java.util.Iterator;
006:        import java.util.Properties;
007:
008:        import javax.servlet.http.HttpServletRequest;
009:        import javax.servlet.http.HttpSession;
010:        import javax.servlet.jsp.PageContext;
011:
012:        import org.json.JSONObject;
013:
014:        import com.ecyrd.jspwiki.PropertyReader;
015:        import com.ecyrd.jspwiki.TextUtil;
016:        import com.ecyrd.jspwiki.WikiContext;
017:        import com.ecyrd.jspwiki.util.HttpUtil;
018:
019:        /**
020:         *  Represents an object which is used to store user preferences.
021:         *  
022:         *  @author jalkanen
023:         */
024:        public class Preferences extends HashMap {
025:            private static final long serialVersionUID = 1L;
026:
027:            /**
028:             *  The name under which a Preferences object is stored in the HttpSession.
029:             *  Its value is {@value}.
030:             */
031:            public static final String SESSIONPREFS = "prefs";
032:
033:            /**
034:             *  This is an utility method which is called to make sure that the
035:             *  JSP pages do have proper access to any user preferences.  It should be
036:             *  called from the commonheader.jsp.
037:             *  <p>
038:             *  This method reads user cookie preferences and mixes them up with any
039:             *  default preferences (and in the future, any user-specific preferences)
040:             *  and puts them all in the session, so that they do not have to be rewritten
041:             *  again.
042:             *  <p>
043:             *  This method will remember if the user has already changed his prefs.
044:             *  
045:             *  @param pageContext The JSP PageContext.
046:             */
047:            public static void setupPreferences(PageContext pageContext) {
048:                HttpSession session = pageContext.getSession();
049:
050:                if (session.getAttribute(SESSIONPREFS) == null) {
051:                    reloadPreferences(pageContext);
052:                }
053:            }
054:
055:            public static void reloadPreferences(PageContext pageContext) {
056:                Preferences prefs = new Preferences();
057:                Properties props = PropertyReader.loadWebAppProps(pageContext
058:                        .getServletContext());
059:
060:                prefs.put("SkinName", TextUtil.getStringProperty(props,
061:                        "jspwiki.defaultprefs.template.skinname",
062:                        "PlainVanilla"));
063:                prefs.put("DateFormat", TextUtil.getStringProperty(props,
064:                        "jspwiki.defaultprefs.template.dateformat",
065:                        "dd-MMM-yyyy HH:mm"));
066:                prefs.put("TimeZone", TextUtil.getStringProperty(props,
067:                        "jspwiki.defaultprefs.template.timezone",
068:                        java.util.TimeZone.getDefault().getID()));
069:                prefs.put("orientation", TextUtil
070:                        .getStringProperty(props,
071:                                "jspwiki.defaultprefs.template.orientation",
072:                                "fav-left"));
073:
074:                // FIXME: "editor" property does not get registered, may be related with http://bugs.jspwiki.org/show_bug.cgi?id=117
075:                // disabling it until knowing why it's happening
076:                // FIXME: editomanager reads jspwiki.editor -- which of both properties should continue
077:                prefs.put("editor", TextUtil.getStringProperty(props,
078:                        "jspwiki.defaultprefs.template.editor", "plain"));
079:
080:                parseJSONPreferences((HttpServletRequest) pageContext
081:                        .getRequest(), prefs);
082:
083:                pageContext.getSession().setAttribute(SESSIONPREFS, prefs);
084:            }
085:
086:            /**
087:             *  Parses new-style preferences stored as JSON objects and stores them
088:             *  in the session.  Everything in the cookie is stored.
089:             *  
090:             *  @param request
091:             *  @param prefs The default hashmap of preferences
092:             *  
093:             */
094:            private static void parseJSONPreferences(
095:                    HttpServletRequest request, Preferences prefs) {
096:                //FIXME: urlDecodeUTF8 should better go in HttpUtil ??
097:                String prefVal = TextUtil.urlDecodeUTF8(HttpUtil
098:                        .retrieveCookieValue(request, "JSPWikiUserPrefs"));
099:
100:                if (prefVal != null) {
101:                    try {
102:                        JSONObject jo = new JSONObject(prefVal);
103:
104:                        for (Iterator i = jo.keys(); i.hasNext();) {
105:                            String key = TextUtil.replaceEntities((String) i
106:                                    .next());
107:                            prefs.put(key, jo.getString(key));
108:                        }
109:                    } catch (ParseException e) {
110:                    }
111:                }
112:            }
113:
114:            /**
115:             *  Returns a preference value programmatically.
116:             *  FIXME
117:             *  
118:             *  @param wikiContext
119:             *  @param name
120:             *  @return
121:             */
122:            public static String getPreference(WikiContext wikiContext,
123:                    String name) {
124:                Preferences prefs = (Preferences) wikiContext.getHttpRequest()
125:                        .getSession().getAttribute(SESSIONPREFS);
126:
127:                if (prefs != null)
128:                    return (String) prefs.get(name);
129:
130:                return null;
131:            }
132:
133:            /**
134:             *  Returns a preference value programmatically.
135:             *  FIXME
136:             *  
137:             *  @param pageContext
138:             *  @param name
139:             *  @return
140:             */
141:            public static String getPreference(PageContext pageContext,
142:                    String name) {
143:                Preferences prefs = (Preferences) pageContext.getSession()
144:                        .getAttribute(SESSIONPREFS);
145:
146:                if (prefs != null)
147:                    return (String) prefs.get(name);
148:
149:                return null;
150:            }
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.