Source Code Cross Referenced for LanguageManager.java in  » Content-Management-System » webman » com » teamkonzept » international » 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 » Content Management System » webman » com.teamkonzept.international 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.teamkonzept.international;
002:
003:        import java.util.*;
004:        import java.text.MessageFormat;
005:        import org.apache.log4j.Category;
006:        import com.teamkonzept.web.TKEvent;
007:
008:        /**
009:         * The language manager.
010:         *
011:         * @author $Author: uli $
012:         * @version $Revision: 1.25 $
013:         */
014:        public class LanguageManager implements  LanguageSelection {
015:            private static Hashtable contexts;
016:
017:            private static Category cat = Category
018:                    .getInstance(LanguageManager.class);
019:
020:            private static Hashtable CACHED_LOCALES = new Hashtable();
021:
022:            public final static String GENERAL = "general";
023:
024:            static {
025:                contexts = new Hashtable();
026:                registerContext("/content", LanguageManager.class);
027:                registerContext("/general", LanguageManager.class);
028:                registerContext("/workflow", LanguageManager.class);
029:                registerContext("/form", LanguageManager.class);
030:                registerContext("/field", LanguageManager.class);
031:                registerContext("/contenttags", LanguageManager.class);
032:                registerContext("/documenttype", LanguageManager.class);
033:                registerContext("/copytool", LanguageManager.class);
034:                registerContext("/properties", LanguageManager.class);
035:                registerContext("/start", LanguageManager.class);
036:                registerContext("/accessrights", LanguageManager.class);
037:                registerContext("/templates", LanguageManager.class);
038:                registerContext("/sitestructure", LanguageManager.class);
039:                registerContext("/gui", LanguageManager.class);
040:            }
041:
042:            /** aktuell gesetztes Server Locale */
043:            private static Locale serverLocale = Locale.GERMAN;
044:
045:            /** aktuell gesetzte LanguageSelektion */
046:            private static int languageCode = USER_CHOSEN_LOCALE;
047:
048:            /**
049:                   registriert Kontext und den Ort -> Properties mussen also in dem Package der uebergebenen
050:                   Klasse liegen
051:                   @param context name des Kontexts
052:                   @param source die aufrufende Klasse, um den Ort des PropertyFiles zu bestimmen
053:             */
054:            public static void registerContext(String context, Object source) {
055:                Class cl = source.getClass();
056:                String name = cl.getName();
057:                int index = name.lastIndexOf(".");
058:                if (index == -1 || context.startsWith("/")) {
059:                    // kein Package
060:                    if (context.startsWith("/")) {
061:                        contexts.put(context.substring(1, context.length()),
062:                                context.substring(1, context.length()));
063:                    } else
064:                        contexts.put(context, context);
065:                } else {
066:                    contexts.put(context, name.substring(0, index + 1)
067:                            + context);
068:                }
069:            }
070:
071:            /**
072:             * Returns the specified internationalized text token.
073:             *
074:             * @param context the name of the context.
075:             * @param identifier the identifier of the text token.
076:             * @return the specified internationalized text token.
077:             */
078:            public static String getText(String context, String identifier) {
079:                return getText(context, identifier, null);
080:            }
081:
082:            /**
083:             * Returns the specified internationalized text token.
084:             *
085:             * @param context the name of the context.
086:             * @param identifier the identifier of the text token.
087:             * @param arguments the arguments of the text token.
088:             * @return the specified internationalized text token.
089:             */
090:            public static String getText(String context, String identifier,
091:                    Object[] arguments) {
092:                try {
093:                    String location = (String) contexts.get(context);
094:                    if (location == null) {
095:                        cat.error("Unknown location '" + context + "'");
096:                        return "";
097:                    }
098:                    ResourceBundle bundle = null;
099:                    if (languageCode == SERVER_CURRENT_LOCALE) {
100:                        bundle = ResourceBundle.getBundle(location,
101:                                serverLocale);
102:                    } else if (languageCode == USER_CHOSEN_LOCALE) {
103:                        TKEvent evt = TKEvent.getEventForThread();
104:                        if (evt != null) {
105:                            String language = evt.getSelectedLanguage();
106:                            Locale locale;
107:                            if (language == null) {
108:                                locale = serverLocale;
109:                            } else {
110:                                locale = getLocale(language);
111:                            }
112:                            bundle = ResourceBundle.getBundle(location, locale);
113:                        } else {
114:                            // Generator !!!
115:                            bundle = ResourceBundle.getBundle(location,
116:                                    serverLocale);
117:                        }
118:                    }
119:                    String text = bundle.getString(identifier);
120:                    if (arguments != null && arguments.length > 0) {
121:                        text = MessageFormat.format(text, arguments);
122:                    }
123:
124:                    return text;
125:                } catch (MissingResourceException e) {
126:                    cat.error("No values for '" + identifier + "' in context '"
127:                            + context + "'");
128:                } catch (Exception e) {
129:                    cat.error("Unknown error", e);
130:                }
131:                return "";
132:            }
133:
134:            /**
135:             * holt eine gecachte Locale instanz oder erzeugt eine neue
136:             */
137:            public static Locale getLocale(String language) {
138:                Locale locale = (Locale) CACHED_LOCALES.get(language);
139:                if (locale == null) {
140:                    locale = new Locale(language, "");
141:                    CACHED_LOCALES.put(language, locale);
142:                }
143:                return locale;
144:            }
145:
146:            public static Locale getStandardLocale() {
147:                return serverLocale;
148:            }
149:
150:            public static void setLanguageSelection(int code) {
151:                languageCode = code;
152:                // noch was machen ???
153:            }
154:
155:            public static void setLocale(Locale locale) {
156:                serverLocale = locale;
157:            }
158:
159:            /**
160:             * returns the language as a ISO 639 language code, as it would be used
161:             * for a getText() method call.  */
162:            public static String getAppliableLanguage() {
163:                Locale locale = null;
164:                if (languageCode == SERVER_CURRENT_LOCALE) {
165:                    locale = serverLocale;
166:                } else if (languageCode == USER_CHOSEN_LOCALE) {
167:                    TKEvent evt = TKEvent.getEventForThread();
168:                    if (evt != null) {
169:                        String language = evt.getSelectedLanguage();
170:                        if (language == null) {
171:                            locale = serverLocale;
172:                        } else {
173:                            locale = getLocale(language);
174:                        }
175:                    } else {
176:                        locale = serverLocale;
177:                    }
178:                }
179:
180:                return (locale != null ? locale.getLanguage() : null);
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.