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


001:        /*
002:         * Copyright 2002 Sun Microsystems, Inc. All 
003:         * rights reserved. Use of this product is subject 
004:         * to license terms. Federal Acquisitions: 
005:         * Commercial Software -- Government Users 
006:         * Subject to Standard License Terms and 
007:         * Conditions. 
008:         * 
009:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE 
010:         * are trademarks or registered trademarks of Sun Microsystems, 
011:         * Inc. in the United States and other countries. 
012:         */
013:
014:        package com.sun.portal.portletcontainercommon;
015:
016:        import java.util.List;
017:        import java.util.ArrayList;
018:
019:        public class PortletPreferencesUtility {
020:
021:            private static String ARRAY_DELIMITER = "|";
022:            private static String SPACE = " ";
023:            private static char ARRAY_DELIMITER_CHAR = ARRAY_DELIMITER
024:                    .charAt(0);
025:            private static String ESCAPED_ARRAY_DELIMITER = ARRAY_DELIMITER
026:                    + ARRAY_DELIMITER;
027:            private static int ARRAY_DELIMITER_LENGTH = ARRAY_DELIMITER
028:                    .length();
029:            private static int ESCAPED_ARRAY_DELIMITER_LENGTH = ESCAPED_ARRAY_DELIMITER
030:                    .length();
031:            public static final String NULL_STRING = "@@$$NULL_STRING$$@@";
032:            private static final String EMPTY_STRING = "@@$$EMPTY_STRING$$@@";
033:
034:            /**
035:             * Converts the List of preference values by using | character as the
036:             * delimiter.
037:             * @param prefs list of preference values
038:             * @return String that has preference values delimited by |
039:             */
040:            public static String getPreferenceString(List prefs) {
041:                if (prefs != null) {
042:                    StringBuffer sb = new StringBuffer("");
043:                    for (int i = 0; i < prefs.size(); i++) {
044:                        sb.append(ARRAY_DELIMITER);
045:                        sb.append(getPreferenceString((String) prefs.get(i)));
046:                    }
047:                    return sb.toString();
048:                } else {
049:                    return null;
050:                }
051:            }
052:
053:            /**
054:             * Converts the List of preference values by using | character as the
055:             * delimiter.
056:             * @param prefs array of preference values
057:             * @return String that has preference values delimited by |
058:             */
059:            public static String getPreferenceString(String[] prefs) {
060:                if (prefs != null) {
061:                    StringBuffer sb = new StringBuffer("");
062:                    for (int i = 0; i < prefs.length; i++) {
063:                        sb.append(ARRAY_DELIMITER);
064:                        sb.append(getPreferenceString(prefs[i]));
065:                    }
066:                    return sb.toString();
067:                } else {
068:                    return null;
069:                }
070:            }
071:
072:            // If the value includes |, then its escaped by adding one more | character.
073:            // Eg: if pref="v1|v2", then the returned value will be "v1||v2"
074:            private static String getPreferenceString(String pref) {
075:                if (pref == null) {
076:                    pref = NULL_STRING;
077:                } else if (pref.length() == 0) {
078:                    pref = EMPTY_STRING;
079:                }
080:                StringBuffer prefBuffer = new StringBuffer(pref);
081:                // pref should never start with '|' and never end with '|'. In case
082:                // such a thing happens, its abnormal, so in order for the
083:                // parsing algorithm to work properly, if pref starts with '|', insert a space
084:                // and if pref endswith '|' append a space.
085:                if (pref.startsWith(ARRAY_DELIMITER))
086:                    prefBuffer.insert(0, SPACE);
087:                if (pref.endsWith(ARRAY_DELIMITER))
088:                    prefBuffer.insert(prefBuffer.length(), SPACE);
089:                // If the preference value contains |, then add one more |
090:                int arrayDelimiterIndex = prefBuffer.indexOf(ARRAY_DELIMITER);
091:                if (arrayDelimiterIndex != -1) {
092:                    while (arrayDelimiterIndex != -1) {
093:                        prefBuffer.replace(arrayDelimiterIndex,
094:                                arrayDelimiterIndex + ARRAY_DELIMITER_LENGTH,
095:                                ESCAPED_ARRAY_DELIMITER);
096:                        arrayDelimiterIndex = prefBuffer.indexOf(
097:                                ARRAY_DELIMITER, arrayDelimiterIndex
098:                                        + ESCAPED_ARRAY_DELIMITER_LENGTH);
099:                    }
100:                }
101:                return prefBuffer.toString();
102:            }
103:
104:            /**
105:             * Converts the preference value string into a list. Multiple preference
106:             * values are delimited by '|'.
107:             * @param pref multiple preference value delimited by '|'.
108:             * @return List of preference values.
109:             */
110:            public static List getPreferenceValues(String pref) {
111:
112:                ArrayList prefArray = new ArrayList();
113:                if (pref == null || pref.length() == 0) {
114:                    return prefArray;
115:                }
116:
117:                StringBuffer valueBuffer = new StringBuffer();
118:                StringBuffer prefBuffer = new StringBuffer(pref);
119:                boolean start = false;
120:
121:                // pref from DP should always start with '|' and never end with '|'. In case
122:                // such a thing happens, its abnormal, however just to be nice and not
123:                // blow things,
124:                // (a)if pref does not start with '|', insert '|'
125:                // (b)if pref starts with '||' , insert '| '
126:                // (c)if pref ends with '|', insert ' |'.
127:
128:                if (pref.startsWith(ARRAY_DELIMITER)) {
129:                    if (pref.startsWith(ESCAPED_ARRAY_DELIMITER)) {
130:                        prefBuffer.insert(0, SPACE);
131:                        prefBuffer.insert(0, ARRAY_DELIMITER);
132:                    }
133:                } else {
134:                    prefBuffer.insert(0, ARRAY_DELIMITER);
135:                }
136:                if (pref.endsWith(ARRAY_DELIMITER)) {
137:                    prefBuffer.insert(prefBuffer.length(), SPACE);
138:                    prefBuffer.insert(prefBuffer.length(), ARRAY_DELIMITER);
139:                } else {
140:                    prefBuffer.insert(prefBuffer.length(), ARRAY_DELIMITER);
141:                }
142:
143:                /*
144:                In order to convert the preferences value back into array
145:                check for the array delimiter '|'. If if the value contains '||'
146:                include it. Before adding into the array, replace '||' by '|'
147:                 */
148:                String modifiedPref = prefBuffer.toString();
149:                char[] prefCharArray = modifiedPref.toCharArray();
150:                int modifiedPrefLength = prefCharArray.length;
151:                for (int i = 0; i < prefCharArray.length; i++) {
152:                    if (!start && (prefCharArray[i] == '|')) {
153:                        start = true;
154:                        valueBuffer = new StringBuffer();
155:                    } else if (start
156:                            && (prefCharArray[i] == ARRAY_DELIMITER_CHAR
157:                                    && i + 1 != modifiedPrefLength && prefCharArray[i + 1] == ARRAY_DELIMITER_CHAR)) {
158:                        valueBuffer.append(prefCharArray[i]);
159:                        valueBuffer.append(prefCharArray[i + 1]);
160:                        i = i + 1;
161:                    } else if (start
162:                            && (prefCharArray[i] == ARRAY_DELIMITER_CHAR && (i + 1 == modifiedPrefLength || prefCharArray[i + 1] != ARRAY_DELIMITER_CHAR))) {
163:                        if (valueBuffer.equals(NULL_STRING)) {
164:                            valueBuffer = null;
165:                        } else if (valueBuffer.indexOf(EMPTY_STRING) != -1) {
166:                            valueBuffer = new StringBuffer("");
167:                        } else {
168:                            replaceEscapedArrayDelimiter(valueBuffer);
169:                        }
170:                        prefArray.add(valueBuffer.toString());
171:                        valueBuffer = new StringBuffer();
172:                    } else if (start) {
173:                        valueBuffer.append(prefCharArray[i]);
174:                    }
175:                }
176:                return prefArray;
177:            }
178:
179:            private static void replaceEscapedArrayDelimiter(
180:                    StringBuffer valueBuffer) {
181:                int index = valueBuffer.indexOf(ESCAPED_ARRAY_DELIMITER);
182:                while (index != -1) {
183:                    valueBuffer.replace(index, index
184:                            + ESCAPED_ARRAY_DELIMITER_LENGTH, ARRAY_DELIMITER);
185:                    index = valueBuffer.indexOf(ESCAPED_ARRAY_DELIMITER, index
186:                            + ARRAY_DELIMITER_LENGTH);
187:                }
188:            }
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.