Source Code Cross Referenced for CmsWorkplaceMessages.java in  » Content-Management-System » opencms » org » opencms » workplace » 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 » opencms » org.opencms.workplace 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/CmsWorkplaceMessages.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:45 $
004:         * Version: $Revision: 1.44 $
005:         *
006:         * This library is part of OpenCms -
007:         * the Open Source Content Management System
008:         *
009:         * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010:         *
011:         * This library is free software; you can redistribute it and/or
012:         * modify it under the terms of the GNU Lesser General Public
013:         * License as published by the Free Software Foundation; either
014:         * version 2.1 of the License, or (at your option) any later version.
015:         *
016:         * This library is distributed in the hope that it will be useful,
017:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019:         * Lesser General Public License for more details.
020:         *
021:         * For further information about Alkacon Software GmbH, please see the
022:         * company website: http://www.alkacon.com
023:         *
024:         * For further information about OpenCms, please see the
025:         * project website: http://www.opencms.org
026:         * 
027:         * You should have received a copy of the GNU Lesser General Public
028:         * License along with this library; if not, write to the Free Software
029:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
030:         */
031:
032:        package org.opencms.workplace;
033:
034:        import org.opencms.i18n.A_CmsMessageBundle;
035:        import org.opencms.i18n.CmsMessages;
036:        import org.opencms.i18n.CmsMultiMessages;
037:        import org.opencms.i18n.I_CmsMessageBundle;
038:        import org.opencms.main.OpenCms;
039:
040:        import java.util.ArrayList;
041:        import java.util.Iterator;
042:        import java.util.List;
043:        import java.util.Locale;
044:        import java.util.Set;
045:
046:        /**
047:         * Provides access to the localized messages for the OpenCms workplace.<p>
048:         * 
049:         * The workplace messages are collected from the workplace resource bundles of all installed modules,
050:         * plus all the OpenCms core packages.<p>
051:         * 
052:         * To be recognized as a workplace module resource bundle,
053:         * the workplace property file must follow the naming convention <code>${module_package_name}.workplace${locale}.properties</code>,
054:         * or <code>${module_package_name}.messages${locale}.properties</code>
055:         * for example like <code>com.mycompany.module.workplace_en.properties</code> or 
056:         * <code>com.mycompany.module.messages_en.properties</code>.<p>
057:         * 
058:         * Workplace messages are cached for faster lookup. If a localized key is contained in more then one module,
059:         * it will be used only from the module where it was first found in. The module order is undefined. It is therefore 
060:         * recommended to ensure the uniqueness of all module keys by placing a special prefix in front of all keys of a module.<p>
061:         * 
062:         * @author  Alexander Kandzior 
063:         * 
064:         * @version $Revision: 1.44 $ 
065:         * 
066:         * @since 6.0.0 
067:         */
068:        public class CmsWorkplaceMessages extends CmsMultiMessages {
069:
070:            /** The title key prefix used for the "new resource" dialog. */
071:            public static final String GUI_NEW_RESOURCE_TITLE_PREFIX = "title.new";
072:
073:            /** The prefix to generate the resource type names with. */
074:            public static final String GUI_RESOURCE_TYPE_PREFIX = "fileicon.";
075:
076:            /** Constant for the <code>".messages"</code> prefix. */
077:            public static final String PREFIX_BUNDLE_MESSAGES = ".messages";
078:
079:            /** Constant for the <code>".workplace"</code> prefix. */
080:            public static final String PREFIX_BUNDLE_WORKPLACE = ".workplace";
081:
082:            /** Constant for the multi bundle name. */
083:            public static final String WORKPLACE_BUNDLE_NAME = CmsWorkplaceMessages.class
084:                    .getName();
085:
086:            /**
087:             * Constructor for creating a new messages object
088:             * initialized with the provided locale.<p>
089:             * 
090:             * @param locale the locale to initialize 
091:             */
092:            public CmsWorkplaceMessages(Locale locale) {
093:
094:                super (locale);
095:                setBundleName(WORKPLACE_BUNDLE_NAME);
096:                addMessages(collectModuleMessages(locale));
097:            }
098:
099:            /**
100:             * Returns the title for the "new resource" dialog.<p>
101:             * 
102:             * It will look up a key with the prefix {@link #GUI_NEW_RESOURCE_TITLE_PREFIX} 
103:             * and the given name appended (converted to lower case).<p>
104:             * 
105:             * If this key is not found, the value of 
106:             * {@link org.opencms.workplace.explorer.Messages#GUI_TITLE_NEWFILEOTHER_0} will be returned.<p>
107:             * 
108:             * @param wp an instance of a {@link CmsWorkplace} to resolve the key name with
109:             * @param name the type to generate the title for
110:             * 
111:             * @return the title for the "new resource" dialog
112:             */
113:            public static String getNewResourceTitle(CmsWorkplace wp,
114:                    String name) {
115:
116:                // try to find the localized key
117:                String title = wp.key(GUI_NEW_RESOURCE_TITLE_PREFIX
118:                        + name.toLowerCase());
119:                if (CmsMessages.isUnknownKey(title)) {
120:                    // still unknown - use default title
121:                    title = wp
122:                            .key(org.opencms.workplace.explorer.Messages.GUI_TITLE_NEWFILEOTHER_0);
123:                }
124:                return title;
125:            }
126:
127:            /**
128:             * Returns the nice name of the given resource type name.<p>
129:             * 
130:             * It will look up a key with the prefix {@link #GUI_RESOURCE_TYPE_PREFIX} 
131:             * and the given name appended.<p>
132:             * 
133:             * If this key is not found, the value of 
134:             * the name input will be returned.<p>
135:             * 
136:             * @param wp an instance of a {@link CmsWorkplace} to resolve the key name with
137:             * @param name the resource type name to generate the nice name for
138:             * 
139:             * @return the nice name of the given resource type name
140:             */
141:            public static String getResourceName(CmsWorkplace wp, String name) {
142:
143:                // try to find the localized key
144:                return wp.keyDefault(GUI_RESOURCE_TYPE_PREFIX + name, name);
145:            }
146:
147:            /**
148:             * Gathers all localization files for the workplace from the different modules.<p>
149:             * 
150:             * For a module named "my.module.name" the locale file must be named 
151:             * "my.module.name.workplace" or "my.module.name.messages" and 
152:             * be located in the classpath so that the resource loader can find it.<p>
153:             * 
154:             * @param locale the selected locale
155:             * 
156:             * @return an initialized set of module messages
157:             */
158:            private static List collectModuleMessages(Locale locale) {
159:
160:                // create a new list and add the base bundle
161:                ArrayList result = new ArrayList();
162:
163:                //////////// iterate over all registered modules ////////////////        
164:                Set names = OpenCms.getModuleManager().getModuleNames();
165:                if (names != null) {
166:                    // iterate all module names
167:                    Iterator i = names.iterator();
168:                    while (i.hasNext()) {
169:                        String modName = (String) i.next();
170:                        //////////// collect the workplace.properties ////////////////
171:                        // this should result in a name like "my.module.name.workplace"
172:                        String bundleName = modName + PREFIX_BUNDLE_WORKPLACE;
173:                        // try to load a bundle with the module names
174:                        CmsMessages msg = new CmsMessages(bundleName, locale);
175:                        // bundle was loaded, add to list of bundles
176:                        if (msg.isInitialized()) {
177:                            result.add(msg);
178:                        }
179:                        //////////// collect the messages.properties ////////////////
180:                        // this should result in a name like "my.module.name.messages"
181:                        bundleName = modName + PREFIX_BUNDLE_MESSAGES;
182:                        // try to load a bundle with the module names
183:                        msg = new CmsMessages(bundleName, locale);
184:                        // bundle was loaded, add to list of bundles
185:                        if (msg.isInitialized()) {
186:                            result.add(msg);
187:                        }
188:                    }
189:                }
190:
191:                //////////// collect additional core packages ////////////////
192:                I_CmsMessageBundle[] coreMsgs = A_CmsMessageBundle
193:                        .getOpenCmsMessageBundles();
194:                for (int i = 0; i < coreMsgs.length; i++) {
195:                    I_CmsMessageBundle bundle = coreMsgs[i];
196:                    result.add(bundle.getBundle(locale));
197:                }
198:
199:                return result;
200:            }
201:
202:            /**
203:             * @see java.lang.Object#equals(java.lang.Object)
204:             */
205:            public boolean equals(Object obj) {
206:
207:                if (obj == this ) {
208:                    return true;
209:                }
210:                if (obj instanceof  CmsWorkplaceMessages) {
211:                    // workplace messages are equal if the locale is equal (since all bundles are the same)
212:                    CmsMessages other = (CmsMessages) obj;
213:                    return other.getLocale().equals(getLocale());
214:                }
215:                return false;
216:            }
217:
218:            /**
219:             * @see org.opencms.i18n.CmsMessages#hashCode()
220:             */
221:            public int hashCode() {
222:
223:                return getLocale().hashCode();
224:            }
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.