Source Code Cross Referenced for Bundle.java in  » IDE-Netbeans » jellytools » org » netbeans » jellytools » 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 » IDE Netbeans » jellytools » org.netbeans.jellytools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.jellytools;
043:
044:        import java.util.MissingResourceException;
045:        import java.util.ResourceBundle;
046:        import org.netbeans.jemmy.JemmyException;
047:        import org.openide.util.NbBundle;
048:
049:        /** Helper class to get strings from NetBeans Bundle.properties files.
050:         * <br>
051:         * Everytime someone wants to identify a component by its title, label, caption or whatever,
052:         * he should not use hard coded string in his test case but he should use
053:         * <code>Bundle.getString(bundleName, key)</code> to obtain string from bundle.
054:         * Then test cases can be executed on different than English locale because
055:         * <code>getString()</code> methods returns string according to current locale.
056:         * <br><br>
057:         * Usage:
058:         * <br><pre>
059:         *        // "OK"
060:         *        Bundle.getString("org.netbeans.core.windows.services.Bundle", "OK_OPTION_CAPTION");
061:         *        // "Properties of AnObject"
062:         *        Bundle.getString("org.netbeans.core.Bundle", "CTL_FMT_LocalProperties", new Object[] {new Integer(1), "AnObject"});
063:         *        // "View"
064:         *        Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Menu/View");
065:         * </pre>
066:         */
067:        public class Bundle {
068:
069:            /** Placeholder to disallow creating of instances. */
070:            private Bundle() {
071:                throw new Error("Bundle is just a container for static methods");
072:            }
073:
074:            /** Returns ResourceBundle from specified path.
075:             * @param bundle path to bundle (e.g. "org.netbeans.core.Bundle")
076:             * @return ResourceBundle instance
077:             */
078:            public static ResourceBundle getBundle(String bundle) {
079:                try {
080:                    return NbBundle.getBundle(bundle);
081:                } catch (NullPointerException e) {
082:                    throw new JemmyException("\"" + bundle
083:                            + "\" bundle was not found", e);
084:                } catch (MissingResourceException e) {
085:                    throw new JemmyException("\"" + bundle
086:                            + "\" bundle was not found", e);
087:                }
088:            }
089:
090:            /** Gets string from specified ResourceBundle.
091:             * @param bundle instance of ResourceBundle
092:             * @param key key of requested string
093:             * @return string from bundle in current locale
094:             */
095:            public static String getString(ResourceBundle bundle, String key) {
096:                try {
097:                    return bundle.getString(key);
098:                } catch (MissingResourceException e) {
099:                    throw new JemmyException("\"" + key
100:                            + "\" key was not found", e);
101:                } catch (NullPointerException npe) {
102:                    throw new JemmyException("Cannot accept null parameter.",
103:                            npe);
104:                }
105:            }
106:
107:            /** Gets string from bundle specified by path to bundle and format it.
108:             * @param bundle path to bundle (e.g. "org.netbeans.core.Bundle")
109:             * @param key key of requested string
110:             * @param params parameters to be formatted
111:             * @return string from bundle in current locale with formatted parameters
112:             */
113:            public static String getString(ResourceBundle bundle, String key,
114:                    Object[] params) {
115:                return java.text.MessageFormat.format(getString(bundle, key),
116:                        params);
117:            }
118:
119:            /** Gets string from bundle specified by path to bundle.
120:             * @param bundle path to bundle (e.g. "org.netbeans.core.Bundle")
121:             * @param key key of requested string
122:             * @return string from bundle in current locale
123:             */
124:            public static String getString(String bundle, String key) {
125:                return getString(getBundle(bundle), key);
126:            }
127:
128:            /** Gets string from bundle, removes mnemonic (i.e. '&' or '(&X)') from it
129:             * and cuts parameters like {0} from the end.
130:             * @param bundle path to bundle (e.g. "org.netbeans.core.Bundle")
131:             * @param key key of requested string
132:             * @return string from bundle in current locale. Mnemonic (i.e. '&' or '(&X)')
133:             * is removed and parameter patterns are also removed starting by first '{'.
134:             */
135:            public static String getStringTrimmed(String bundle, String key) {
136:                return trim(getString(getBundle(bundle), key));
137:            }
138:
139:            /** Gets string from bundle specified by path to bundle and format it.
140:             * @param bundle path to bundle (e.g. "org.netbeans.core.Bundle")
141:             * @param key key of requested string
142:             * @param params parameter to be formatted
143:             * @return string from bundle in current locale with formatted parameters
144:             */
145:            public static String getString(String bundle, String key,
146:                    Object[] params) {
147:                return java.text.MessageFormat.format(getString(bundle, key),
148:                        params);
149:            }
150:
151:            /** Gets string from bundle and formats it. It removes mnemonic (i.e. '&' or '(&X)') 
152:             * from it and cuts parameters like {0} from the end if any.
153:             * @param bundle path to bundle (e.g. "org.netbeans.core.Bundle")
154:             * @param key key of requested string
155:             * @param params parameter to be formatted
156:             * @return string from bundle in current locale. Mnemonic and parameters 
157:             * like {0} removed from the end.
158:             */
159:            public static String getStringTrimmed(String bundle, String key,
160:                    Object[] params) {
161:                return trim(getString(getBundle(bundle), key, params));
162:            }
163:
164:            /** Removes mnemonic (i.e. '&' or '(&X)') and cut parameters like {0} from the end.
165:             * @param value string to modify
166:             * @return string with removed mnemonic and parameters like {0} from the end.
167:             */
168:            private static String trim(String value) {
169:                // remove mnemonic, i.e. '&' or '(&X)'
170:                value = cutAmpersand(value);
171:                // cut parameters like {0} from string
172:                if (value.indexOf('{') != -1) {
173:                    value = value.substring(0, value.indexOf('{'));
174:                }
175:                return value;
176:            }
177:
178:            /**
179:             * Removes an ampersand from a text string; commonly used to strip out unneeded mnemonics.
180:             * Replaces the first occurence of <samp>&amp;?</samp> by <samp>?</samp> or <samp>(&amp;??</samp> by the empty string 
181:             * where <samp>?</samp> is a wildcard for any character.
182:             * <samp>&amp;?</samp> is a shortcut in English locale.
183:             * <samp>(&amp;?)</samp> is a shortcut in Japanese locale.
184:             * Used to remove shortcuts from workspace names (or similar) when shortcuts are not supported.
185:             * <p>The current implementation behaves in the same way regardless of locale.
186:             * In case of a conflict it would be necessary to change the
187:             * behavior based on the current locale.
188:             * @param text a localized label that may have mnemonic information in it
189:             * @return string without first <samp>&amp;</samp> if there was any
190:             */
191:            private static String cutAmpersand(String text) {
192:                // modified code of org.openide.awt.Actions.cutAmpersand
193:                // see also org.openide.awt.Mnemonics
194:                int i;
195:                String result = text;
196:                /* First check of occurence of '(&'. If not found check 
197:                 * for '&' itself.
198:                 * If '(&' is found then remove '(&??' and rest of line.
199:                 */
200:                i = text.indexOf("(&"); // NOI18N
201:                if (i >= 0 && i + 3 < text.length()
202:                        && /* #31093 */text.charAt(i + 3) == ')') { // NOI18N
203:                    result = text.substring(0, i);
204:                } else {
205:                    //Sequence '(&?)' not found look for '&' itself
206:                    i = text.indexOf('&');
207:                    if (i < 0) {
208:                        //No ampersand
209:                        result = text;
210:                    } else if (i == (text.length() - 1)) {
211:                        //Ampersand is last character, wrong shortcut but we remove it anyway
212:                        result = text.substring(0, i);
213:                    } else {
214:                        //Remove ampersand from middle of string
215:                        result = text.substring(0, i) + text.substring(i + 1);
216:                    }
217:                }
218:                return result;
219:            }
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.