Source Code Cross Referenced for LocalePropertiesFilter.java in  » Portal » Open-Portal » com » sun » portal » providers » context » 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.providers.context 
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.providers.context;
015:
016:        import java.util.List;
017:        import java.util.ArrayList;
018:        import java.util.Locale;
019:        import java.util.Iterator;
020:        import java.util.StringTokenizer;
021:
022:        import com.sun.portal.providers.context.PropertiesFilter;
023:
024:        /**
025:         * This class implements the "locale" filter.
026:         */
027:
028:        public class LocalePropertiesFilter extends PropertiesFilter {
029:
030:            /**
031:             * Constructor.  Do not call this directly.  Instead use
032:             * <code>PropertiesFilterFactory.get(LOCALE_PROPERTIESFILTER_CLASSNAME, ...)</code>.
033:             *
034:             * @see PropertiesFilterFactory#get(String, String, boolean)
035:             */
036:            public LocalePropertiesFilter() {
037:                super ();
038:            }
039:
040:            /**
041:             * CACHING IS DISABLED FOR NOW.
042:             *
043:             * Return true.
044:             *
045:             * @return true
046:             *
047:            public boolean isCachable() {
048:                return true;
049:            }
050:             */
051:
052:            /**
053:             * Return "<code>locale</code>"
054:             *
055:             * @return "<code>locale</code>"
056:             */
057:            public String getCondition() {
058:                return "locale";
059:            }
060:
061:            /**
062:             * Does the given condition and value match this locale filter?
063:             * This match method is based on a case-sensitive string comparison.
064:             *
065:             * In other words, the condition should be "locale" and value should
066:             * exactly match the value that was used to instantiate this filter.
067:             *
068:             * @param condition filter condition.  i.e. "locale"
069:             * @param value locale suffix (i.e. en, US, etc.)
070:             * @return boolean value indicating whether match has succeeded or not.
071:             */
072:            public boolean match(String condition, String value) {
073:                return condition.toLowerCase().equals("locale")
074:                        && getValue().equals(value);
075:            }
076:
077:            /**
078:             * A convenient method for converting Locale into a list of
079:             * <code>LocalePropertiesFilters</code>.
080:             *
081:             * @param locale Locale object 
082:             * @param required boolean value that determines whether the filters are
083:             * required or optional
084:             * @return List of non-required (optional) <code>LocalePropertiesFilter</code>
085:             */
086:            public static List getLocalePropertiesFilters(Locale locale,
087:                    boolean required) throws PropertiesFilterException {
088:                if (locale == null) {
089:                    return null;
090:                }
091:
092:                String localeString = locale.toString();
093:                if (localeString == null) {
094:                    return null;
095:                }
096:
097:                List pflist = new ArrayList();
098:                StringTokenizer tokenizer = new StringTokenizer(localeString,
099:                        "_");
100:                while (tokenizer.hasMoreTokens()) {
101:                    PropertiesFilter pf = PropertiesFilterFactory
102:                            .get(
103:                                    PropertiesFilterFactory.LOCALE_PROPERTIESFILTER_CLASSNAME,
104:                                    tokenizer.nextToken(), required);
105:
106:                    pflist.add(pf);
107:                }
108:
109:                return pflist;
110:            }
111:
112:            /**
113:             * A convenient method for converting LocalePropertiesFilters into
114:             * a locale object.  
115:             *
116:             * @param pflist List of LocalePropertiesFilter objects or other 
117:             * PropertiesFilter that are non-required.
118:             * @return Locale object.  Returns null if no locale can be instantiated
119:             * from the given PropertiesFilters.
120:             */
121:            public static Locale getLocale(List pflist)
122:                    throws PropertiesFilterException {
123:
124:                String lang = "";
125:                String country = "";
126:                String variant = "";
127:
128:                Iterator i = pflist.iterator();
129:                PropertiesFilter pf = (PropertiesFilter) i.next();
130:
131:                //
132:                // skip PropertiesFilter that are not LocalePropertiesFilters
133:                // if it's a required filter, then return null
134:                // 
135:                while (!(pf instanceof  LocalePropertiesFilter)) {
136:                    if (pf.isRequired()) {
137:                        return null;
138:                    }
139:                    if (i.hasNext()) {
140:                        pf = (PropertiesFilter) i.next();
141:                    } else {
142:                        return null;
143:                    }
144:                }
145:                lang = pf.getValue();
146:
147:                if (i.hasNext()) {
148:                    pf = (PropertiesFilter) i.next();
149:                    if (pf instanceof  LocalePropertiesFilter) {
150:                        country = pf.getValue();
151:                    } else {
152:                        if (pf.isRequired()) {
153:                            return null;
154:                        }
155:                    }
156:                }
157:
158:                if (i.hasNext()) {
159:                    pf = (PropertiesFilter) i.next();
160:                    if (pf instanceof  LocalePropertiesFilter) {
161:                        variant = pf.getValue();
162:                    } else {
163:                        if (pf.isRequired()) {
164:                            return null;
165:                        }
166:                    }
167:                }
168:
169:                return new Locale(lang, country, variant);
170:            }
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.