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


001:        package de.webman.config;
002:
003:        import de.webman.util.registry.Manager;
004:        import de.webman.util.registry.RegistryException;
005:        import de.webman.util.log4j.WebmanCategory;
006:        import org.apache.log4j.Category;
007:        import com.teamkonzept.webman.db.TKWebmanDBManager;
008:        import com.teamkonzept.lib.TKException;
009:        import java.sql.SQLException;
010:        import com.teamkonzept.db.TKPrepQuery;
011:        import java.util.Locale;
012:        import com.teamkonzept.lib.PropertyManager;
013:        import com.teamkonzept.lib.ConfigurationListener;
014:        import com.teamkonzept.lib.ConfigurationManager;
015:
016:        /**
017:         * A manager which initializes and setups the configuration and database
018:         * connection.  It should be registered and loaded recently early, at least
019:         * before any database access.<p>
020:         *
021:         * @author <a href="mailto:gregor@webman.de">Gregor Klinke</a>
022:         * @version $Revision: 1.3 $
023:         **/
024:        public class ConfigMgr implements  Manager, ConfigurationListener {
025:            /* $Id $ */
026:
027:            /**
028:             * logging facility
029:             **/
030:            private static Category cat = Category.getInstance(ConfigMgr.class);
031:
032:            /**
033:             * the property group, the locale is configured in
034:             **/
035:            public static final String LOCALE_PROPERTY_GROUP = "WEBMAN";
036:
037:            /**
038:             * the constructor, only to be used by the related factory
039:             * @param basedir directory from where to read the configuration
040:             * @throws RegistryException if anything fails
041:             **/
042:            ConfigMgr(String basedir) throws RegistryException {
043:                cat.info("setup database connection");
044:
045:                try {
046:                    TKWebmanDBManager.initConnection("/webmandb.ini", true);
047:
048:                    // call this once, otherwise prepared queries seems not to run
049:                    // (found in WebManThread)
050:                    TKPrepQuery.enableCleanup();
051:                } catch (TKException e) {
052:                    cat.error("Exception during pre init : ", e);
053:                    throw new RegistryException(e);
054:                }
055:
056:                setDefaultLocale();
057:
058:                /* deregister the current thread!  This is not done automatically
059:                   by the webman backend code ..., really, we do need a better
060:                   solution herefore! */
061:                try {
062:                    TKWebmanDBManager.deregister(true);
063:                } catch (SQLException e) {
064:                    throw new RegistryException(e);
065:                }
066:
067:                ConfigurationManager.getInstance()
068:                        .registerConfigurationListener(this ,
069:                                LOCALE_PROPERTY_GROUP);
070:
071:                cat.info("database connection successful");
072:            }
073:
074:            /**
075:             * looks up an object from the manager.
076:             *
077:             * @param key the key under which the object is stored in the manager
078:             * @return the found object or <code>null</code> if not found
079:             * @throws RegistryException if anything fails
080:             **/
081:            public Object get(String key) throws RegistryException {
082:                /* to wrap this and use the property manager, we need a scope, something like LEGACY */
083:                // PropertyManager.getPropertyManager(scope).getValue(key);
084:                return null;
085:            }
086:
087:            /**
088:             * looks up an object from the manager.  If no such object found return a default value
089:             *
090:             * @param key the key under which the object is stored in the manager
091:             * @param def the default object
092:             * @return the found object or <code>null</code> if not found
093:             * @throws RegistryException if anything fails
094:             **/
095:            public Object get(String key, Object def) throws RegistryException {
096:                Object o = get(key);
097:                return o != null ? o : def;
098:            }
099:
100:            /**
101:             * sets a object in the manager.
102:             *
103:             * @param key the key under which the object is stored in the manager,
104:             * must not be <code>null</code>
105:             * @param obj the object to store
106:             * @throws RegistryException if anything fails
107:             **/
108:            public void put(String key, Object obj) throws RegistryException {
109:                // TODO
110:            }
111:
112:            /**
113:             * removes any object stored under a given key from the registry.  If
114:             * no object was stored under such a key nothing happens.
115:             *
116:             * @param key the key for which the object should be removed.
117:             * @throws RegistryException if anything fails
118:             **/
119:            public void remove(String key) throws RegistryException {
120:                // TODO
121:            }
122:
123:            /* --------------------------------------------------------------------
124:               functions to set the default local
125:               -------------------------------------------------------------------- */
126:
127:            /**
128:             * if the WEBMAN property group changes, this event is fired
129:             * @throws TKException if anything fails
130:             **/
131:            public void configurationChanged() throws TKException {
132:                setDefaultLocale();
133:            }
134:
135:            /**
136:             * set the default locale according to the WEBMAN.LOCALE property
137:             * setting
138:             **/
139:            private void setDefaultLocale() {
140:                boolean lclset = false;
141:
142:                try {
143:                    PropertyManager man = PropertyManager
144:                            .getPropertyManager(LOCALE_PROPERTY_GROUP);
145:                    String lnm = man.getValue("LOCALE", "de_DE");
146:
147:                    if (lnm != null) {
148:                        Locale defl = new Locale(getLocaleLanguagePart(lnm),
149:                                getLocaleCountryPart(lnm));
150:
151:                        Locale[] all = Locale.getAvailableLocales();
152:                        for (int i = 0; i < all.length; i++) {
153:                            if (all[i].equals(defl)) {
154:                                Locale.setDefault(defl);
155:
156:                                cat.info("Requested default locale: '" + lnm
157:                                        + "', use: '" + defl + "'");
158:
159:                                lclset = true;
160:                            }
161:                        }
162:
163:                        if (!lclset) {
164:                            cat.error("Locale setting '" + defl
165:                                    + "' not known on system");
166:                        }
167:                    }
168:                } catch (Exception e) {
169:                    ;
170:                }
171:
172:                if (!lclset) {
173:                    cat.warn("No locale setting, use system default: '"
174:                            + Locale.getDefault() + "'");
175:                }
176:            }
177:
178:            /**
179:             * extracts the iso639 language part of a locale name
180:             * @param localeName the locale name
181:             * @return the language part or "" if none found
182:             **/
183:            private String getLocaleLanguagePart(String localeName) {
184:                if (localeName != null) {
185:                    int idx = localeName.indexOf("_");
186:
187:                    if (idx > 0)
188:                        return localeName.substring(0, idx);
189:                    return localeName;
190:                }
191:                return "";
192:            }
193:
194:            /**
195:             * extracts the iso 3166 2 country part of a locale name
196:             * @param localeName the locale name
197:             * @return the country part or "" if none found
198:             **/
199:            private String getLocaleCountryPart(String localeName) {
200:                if (localeName != null) {
201:                    int idx = localeName.indexOf("_");
202:
203:                    if (idx > 0)
204:                        return localeName.substring(idx + 1);
205:                    return localeName;
206:                }
207:                return "";
208:            }
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.