Source Code Cross Referenced for LocaleInfo.java in  » Portal » jboss-portal-2.6.4 » org » jboss » portal » migration » model22 » other » 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 » jboss portal 2.6.4 » org.jboss.portal.migration.model22.other 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************************
002:         * JBoss, a division of Red Hat                                               *
003:         * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
004:         * contributors as indicated by the @authors tag. See the                     *
005:         * copyright.txt in the distribution for a full listing of                    *
006:         * individual contributors.                                                   *
007:         *                                                                            *
008:         * This is free software; you can redistribute it and/or modify it            *
009:         * under the terms of the GNU Lesser General Public License as                *
010:         * published by the Free Software Foundation; either version 2.1 of           *
011:         * the License, or (at your option) any later version.                        *
012:         *                                                                            *
013:         * This software is distributed in the hope that it will be useful,           *
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
016:         * Lesser General Public License for more details.                            *
017:         *                                                                            *
018:         * You should have received a copy of the GNU Lesser General Public           *
019:         * License along with this software; if not, write to the Free                *
020:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
021:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
022:         ******************************************************************************/package org.jboss.portal.migration.model22.other;
023:
024:        import org.apache.log4j.Logger;
025:
026:        import java.util.ArrayList;
027:        import java.util.Collection;
028:        import java.util.Collections;
029:        import java.util.Comparator;
030:        import java.util.HashMap;
031:        import java.util.Iterator;
032:        import java.util.List;
033:        import java.util.Locale;
034:        import java.util.Map;
035:
036:        /**
037:         * Additional infos about a locale.
038:         *
039:         * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
040:         * @version $Revision: 8784 $
041:         */
042:        public final class LocaleInfo {
043:
044:            // Static fields ****************************************************************************************************
045:
046:            private static Logger log = Logger.getLogger(LocaleInfo.class);
047:
048:            /** The locale info map. */
049:            private static final Map infos = initializeInfos();
050:
051:            /** The locale info objects. */
052:            private static final Collection all = initializeAll();
053:
054:            // Fields ***********************************************************************************************************
055:
056:            /** The parent locale info or null if no parent. */
057:            private LocaleInfo parent;
058:
059:            /** The relaled locale. */
060:            private Locale locale;
061:
062:            /** The trailing name used to compute resource bundle name. */
063:            private String trailingName;
064:
065:            // Constructor ******************************************************************************************************
066:
067:            private LocaleInfo(Locale locale) {
068:                this .locale = locale;
069:                this .trailingName = computeTrailingName(locale);
070:            }
071:
072:            // Public ***********************************************************************************************************
073:
074:            public LocaleInfo getParent() {
075:                return parent;
076:            }
077:
078:            public Locale getLocale() {
079:                return locale;
080:            }
081:
082:            public String getTrailingName() {
083:                return trailingName;
084:            }
085:
086:            // Object override **************************************************************************************************
087:
088:            public String toString() {
089:                return locale.toString();
090:            }
091:
092:            // Static ***********************************************************************************************************
093:
094:            /**
095:             * Compute the trainling name for a given locale.
096:             *
097:             * @param locale the locale
098:             * @return the trailing name
099:             * @throws IllegalArgumentException if locale is null
100:             */
101:            public static String computeTrailingName(Locale locale)
102:                    throws IllegalArgumentException {
103:                if (locale == null) {
104:                    throw new IllegalArgumentException(
105:                            "locale parameter is null");
106:                }
107:                StringBuffer tmp = new StringBuffer();
108:                if (locale.getLanguage() != null
109:                        && locale.getLanguage().length() > 0) {
110:                    tmp.append('_').append(locale.getLanguage());
111:                    if (locale.getCountry() != null
112:                            && locale.getCountry().length() > 0) {
113:                        tmp.append('_').append(locale.getCountry());
114:                        {
115:                            if (locale.getVariant() != null
116:                                    && locale.getVariant().length() > 0) {
117:                                tmp.append('_').append(locale.getVariant());
118:                            }
119:                        }
120:                    }
121:                }
122:                return tmp.toString();
123:            }
124:
125:            private static final Map initializeInfos() {
126:                Map locales = new HashMap();
127:
128:                // Initialize all objects
129:                Locale[] temp = Locale.getAvailableLocales();
130:                for (int i = 0; i < temp.length; i++) {
131:                    Locale locale = temp[i];
132:                    LocaleInfo info = new LocaleInfo(locale);
133:                    locales.put(locale.toString(), info);
134:                    log.debug("LocaleInfo " + locale.toString()
135:                            + " initialized");
136:                }
137:
138:                // Resolve parent links
139:                for (Iterator i = locales.values().iterator(); i.hasNext();) {
140:                    LocaleInfo info = (LocaleInfo) i.next();
141:                    LocaleInfo parent = null;
142:                    Locale locale = info.locale;
143:
144:                    // If this is a language/country/variant, try to get language/country
145:                    if (locale.getVariant() != null
146:                            && locale.getVariant().length() > 0) {
147:                        Locale key = new Locale(locale.getLanguage(), locale
148:                                .getCountry());
149:                        parent = (LocaleInfo) locales.get(key.toString());
150:                    }
151:
152:                    // If this is a language/country, try to get language
153:                    if (parent == null && locale.getCountry() != null
154:                            && locale.getCountry().length() > 0) {
155:                        Locale key = new Locale(locale.getLanguage());
156:                        parent = (LocaleInfo) locales.get(key.toString());
157:                    }
158:
159:                    // Set the parent
160:                    info.parent = parent;
161:                }
162:
163:                return Collections.unmodifiableMap(locales);
164:            }
165:
166:            private static Collection initializeAll() {
167:                Comparator c = new Comparator() {
168:                    public int compare(Object o1, Object o2) {
169:                        String s1 = ((LocaleInfo) o1).getTrailingName();
170:                        String s2 = ((LocaleInfo) o2).getTrailingName();
171:                        return s1.compareTo(s2);
172:                    }
173:                };
174:                List all = new ArrayList(infos.values());
175:                Collections.sort(all, c);
176:                return Collections.unmodifiableList(all);
177:            }
178:
179:            public static Collection getAll() {
180:                return all;
181:            }
182:
183:            public static LocaleInfo decodeLocaleInfo(String code) {
184:                return (LocaleInfo) infos.get(code);
185:            }
186:
187:            public static LocaleInfo decodeLocaleInfo(Locale locale) {
188:                return (LocaleInfo) infos.get(locale.toString());
189:            }
190:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.