Source Code Cross Referenced for LanguageSetImpl.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » om » impl » 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 » jetspeed 2.1.3 » org.apache.jetspeed.om.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.jetspeed.om.impl;
018:
019:        import java.io.Serializable;
020:        import java.util.ArrayList;
021:        import java.util.Collection;
022:        import java.util.Collections;
023:        import java.util.HashSet;
024:        import java.util.Iterator;
025:        import java.util.Locale;
026:        import java.util.MissingResourceException;
027:        import java.util.ResourceBundle;
028:
029:        import org.apache.jetspeed.om.common.MutableLanguage;
030:        import org.apache.jetspeed.om.common.Support;
031:        import org.apache.jetspeed.util.JetspeedLocale;
032:        import org.apache.pluto.om.common.Language;
033:        import org.apache.pluto.om.common.LanguageSet;
034:
035:        /**
036:         * 
037:         * LanguageSetImpl
038:         * 
039:         * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
040:         * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
041:         * @version $Id: LanguageSetImpl.java 553014 2007-07-03 23:10:53Z ate $
042:         *  
043:         */
044:        public class LanguageSetImpl implements  LanguageSet, Serializable,
045:                Support {
046:            private transient ClassLoader classLoader = null;
047:
048:            private String resources;
049:            protected Collection innerCollection;
050:
051:            /**
052:             * 
053:             * @param wrappedSet
054:             */
055:            public LanguageSetImpl(Collection collection) {
056:                super ();
057:                this .innerCollection = collection;
058:            }
059:
060:            public LanguageSetImpl() {
061:                this (Collections.synchronizedList(new ArrayList()));
062:            }
063:
064:            /**
065:             * @see org.apache.pluto.om.common.LanguageSet#iterator()
066:             */
067:            public Iterator iterator() {
068:                return innerCollection.iterator();
069:            }
070:
071:            /**
072:             * @see org.apache.pluto.om.common.LanguageSet#getLocales()
073:             */
074:            public Iterator getLocales() {
075:                HashSet localSet = new HashSet();
076:                synchronized (innerCollection) {
077:                    Iterator itr = innerCollection.iterator();
078:                    while (itr.hasNext()) {
079:                        Language lang = (Language) itr.next();
080:                        localSet.add(lang.getLocale());
081:                    }
082:                }
083:                return localSet.iterator();
084:            }
085:
086:            /**
087:             * @see org.apache.pluto.om.common.LanguageSet#get(java.util.Locale)
088:             */
089:            public Language get(Locale locale) {
090:                LanguageImpl fallback = null;
091:                synchronized (innerCollection) {
092:                    Iterator searchItr = innerCollection.iterator();
093:                    while (searchItr.hasNext()) {
094:                        LanguageImpl lang = (LanguageImpl) searchItr.next();
095:
096:                        if (lang.getLocale().equals(locale)) {
097:                            if (resources != null
098:                                    && lang.getParentResourceBundle() == null) {
099:                                lang.setResourceBundle(loadResourceBundle(lang
100:                                        .getLocale()));
101:                            }
102:                            return lang;
103:                        } else if (lang.getLocale().getLanguage().equals(
104:                                locale.getLanguage())) {
105:                            fallback = lang;
106:                        }
107:
108:                    }
109:                }
110:                if (fallback == null) {
111:                    if (getDefaultLocale().equals(locale)) {
112:                        // no default language stored yet
113:                        LanguageImpl defaultLanguage = new LanguageImpl();
114:                        defaultLanguage.setLocale(locale);
115:
116:                        if (resources != null) {
117:                            defaultLanguage
118:                                    .setResourceBundle(loadResourceBundle(locale));
119:                            defaultLanguage.loadDefaults();
120:                            innerCollection.add(defaultLanguage);
121:                            return defaultLanguage;
122:                        }
123:                    } else {
124:                        fallback = (LanguageImpl) get(getDefaultLocale());
125:                    }
126:                }
127:
128:                LanguageImpl language = new LanguageImpl();
129:                language.setLocale(locale);
130:                language.setTitle(fallback.getTitle());
131:                language.setShortTitle(fallback.getShortTitle());
132:                language.setKeywords(fallback.getKeywordStr());
133:                if (resources != null) {
134:                    language.setResourceBundle(loadResourceBundle(locale));
135:                }
136:                language.loadDefaults();
137:                innerCollection.add(language);
138:                return language;
139:            }
140:
141:            /**
142:             * @see org.apache.pluto.om.common.LanguageSet#getDefaultLocale()
143:             */
144:            public Locale getDefaultLocale() {
145:                return JetspeedLocale.getDefaultLocale();
146:            }
147:
148:            public boolean add(Object o) {
149:                if (o instanceof  Language) {
150:                    Language language = (Language) o;
151:                    if (language.getLocale() == null) {
152:                        ((MutableLanguage) o).setLocale(getDefaultLocale());
153:                    }
154:
155:                    synchronized (innerCollection) {
156:                        Iterator ite = innerCollection.iterator();
157:                        while (ite.hasNext()) {
158:                            Language lang = (Language) ite.next();
159:                            if (lang.equals(language)) {
160:                                innerCollection.remove(lang);
161:                                return innerCollection.add(o);
162:                            }
163:                        }
164:                    }
165:                    return innerCollection.add(o);
166:                }
167:                return false;
168:            }
169:
170:            /**
171:             * @return
172:             */
173:            public Collection getInnerCollection() {
174:                return innerCollection;
175:            }
176:
177:            /**
178:             * @param collection
179:             */
180:            public void setInnerCollection(Collection collection) {
181:                innerCollection = collection;
182:            }
183:
184:            public int size() {
185:                return innerCollection.size();
186:            }
187:
188:            /**
189:             * @param string
190:             */
191:            public void setResources(String string) {
192:                resources = string;
193:            }
194:
195:            /*
196:             * (non-Javadoc)
197:             * 
198:             * @see org.apache.jetspeed.om.common.Support#postLoad(java.lang.Object)
199:             */
200:            public void postLoad(Object parameter) throws Exception {
201:                Iterator iter = ((Collection) parameter).iterator();
202:                LanguageImpl language;
203:                while (iter.hasNext()) {
204:                    language = (LanguageImpl) get((Locale) iter.next());
205:                    // load available resource bundle values
206:                    language.loadDefaults();
207:                }
208:                // ensure default locale language is created and available resource bundle values are loaded
209:                language = (LanguageImpl) get(getDefaultLocale());
210:                language.loadDefaults();
211:            }
212:
213:            protected ResourceBundle loadResourceBundle(Locale locale) {
214:                ResourceBundle resourceBundle = null;
215:                try {
216:                    if (resources != null) {
217:                        if (classLoader != null) {
218:                            resourceBundle = ResourceBundle.getBundle(
219:                                    resources, locale, classLoader);
220:                        } else {
221:                            resourceBundle = ResourceBundle.getBundle(
222:                                    resources, locale, Thread.currentThread()
223:                                            .getContextClassLoader());
224:                        }
225:                    }
226:                } catch (MissingResourceException x) {
227:                    return null;
228:                }
229:                return resourceBundle;
230:            }
231:
232:            /**
233:             * 
234:             * Sets Portlet Class Loader
235:             * 
236:             * @param loader
237:             */
238:            public void setClassLoader(ClassLoader loader) {
239:                classLoader = loader;
240:            }
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.