KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > util > BundleUtilities


1 /*****************************************************************************
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is the CVS Client Library.
16  * The Initial Developer of the Original Software is Thomas Singer.
17  * Portions created by Thomas Singer are Copyright (C) 2001.
18  * All Rights Reserved.
19  *
20  * Contributor(s): Thomas Singer.
21  *****************************************************************************/

22 package org.netbeans.lib.cvsclient.util;
23
24 import java.util.*;
25
26 /**
27  * @author Thomas Singer
28  * @version Sep 26, 2001
29  */

30 public class BundleUtilities {
31
32     /**
33      * Returns the package name of the specified class.
34      * An empty String is returned, if the class is in the default package.
35      */

36     public static String JavaDoc getPackageName(Class JavaDoc clazz) {
37         String JavaDoc fullClassName = clazz.getName();
38         int lastDotIndex = fullClassName.lastIndexOf('.');
39         if (lastDotIndex < 0) {
40             return ""; // NOI18N
41
}
42         return fullClassName.substring(0, lastDotIndex);
43     }
44
45     /**
46      * Returns the resourcename for the resource' shortName relative to the classInSamePackage.
47      */

48     public static String JavaDoc getResourceName(Class JavaDoc classInSamePackage, String JavaDoc shortName) {
49         String JavaDoc packageName = getPackageName(classInSamePackage);
50         String JavaDoc resourceName = packageName.replace('.', '/') + '/' + shortName;
51         return resourceName;
52     }
53
54     /**
55      * Returns the resource bundle for the specified resource' shortName relative to classInSamePackage.
56      */

57     public static ResourceBundle getResourceBundle(Class JavaDoc classInSamePackage, String JavaDoc shortName) {
58         String JavaDoc resourceName = getResourceName(classInSamePackage, shortName);
59         return ResourceBundle.getBundle(resourceName);
60     }
61 }
62
Popular Tags