KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > ide > HelpIdeResources


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.ui.internal.ide;
12 import java.net.*;
13 import java.text.*;
14 import java.util.*;
15
16 import org.eclipse.core.runtime.*;
17 /**
18  * Uses a resource bundle to load images and strings from a property file. This
19  * class needs to properly use the desired locale.
20  */

21 public class HelpIdeResources {
22     private static ResourceBundle resBundle;
23     static {
24         resBundle = ResourceBundle.getBundle(HelpIdeResources.class.getName());
25     }
26     /**
27      * WorkbenchResources constructor comment.
28      */

29     public HelpIdeResources() {
30         super();
31     }
32     /**
33      * Returns a string from a property file
34      */

35     public static URL getImagePath(String JavaDoc name) {
36         IPath path = new Path("icons/").append(name); //$NON-NLS-1$
37
return Platform.find(HelpIdePlugin.getDefault().getBundle(), path);
38     }
39     /**
40      * Returns a string from a property file
41      */

42     public static String JavaDoc getString(String JavaDoc name) {
43         try {
44             return resBundle.getString(name);
45         } catch (Exception JavaDoc e) {
46             return name;
47         }
48
49     }
50     /**
51      * Returns a string from a property file
52      */

53     public static String JavaDoc getString(String JavaDoc name, String JavaDoc replace0) {
54         try {
55             String JavaDoc stringFromPropertiesFile = resBundle.getString(name);
56             stringFromPropertiesFile = MessageFormat.format(
57                     stringFromPropertiesFile, new Object JavaDoc[]{replace0});
58             return stringFromPropertiesFile;
59         } catch (Exception JavaDoc e) {
60             return name;
61         }
62
63     }
64     /**
65      * Returns a string from a property file
66      */

67     public static String JavaDoc getString(String JavaDoc name, String JavaDoc replace0, String JavaDoc replace1) {
68         try {
69             String JavaDoc stringFromPropertiesFile = resBundle.getString(name);
70             stringFromPropertiesFile = MessageFormat.format(
71                     stringFromPropertiesFile, new Object JavaDoc[]{replace0, replace1});
72             return stringFromPropertiesFile;
73         } catch (Exception JavaDoc e) {
74             return name;
75         }
76
77     }
78     /**
79      * Returns a string from a property file
80      */

81     public static String JavaDoc getString(String JavaDoc name, String JavaDoc replace0,
82             String JavaDoc replace1, String JavaDoc replace2) {
83         try {
84             String JavaDoc stringFromPropertiesFile = resBundle.getString(name);
85             stringFromPropertiesFile = MessageFormat.format(
86                     stringFromPropertiesFile, new Object JavaDoc[]{replace0, replace1,
87                             replace2});
88             return stringFromPropertiesFile;
89         } catch (Exception JavaDoc e) {
90             return name;
91         }
92
93     }
94     /**
95      * Returns a string from a property file
96      */

97     public static String JavaDoc getString(String JavaDoc name, String JavaDoc replace0,
98             String JavaDoc replace1, String JavaDoc replace2, String JavaDoc replace3) {
99         try {
100             String JavaDoc stringFromPropertiesFile = resBundle.getString(name);
101             stringFromPropertiesFile = MessageFormat.format(
102                     stringFromPropertiesFile, new Object JavaDoc[]{replace0, replace1,
103                             replace2, replace3});
104             return stringFromPropertiesFile;
105         } catch (Exception JavaDoc e) {
106             return name;
107         }
108
109     }
110     /**
111      * Returns a string from a property file
112      */

113     public static String JavaDoc getString(String JavaDoc name, String JavaDoc replace0,
114             String JavaDoc replace1, String JavaDoc replace2, String JavaDoc replace3, String JavaDoc replace4) {
115         try {
116             String JavaDoc stringFromPropertiesFile = resBundle.getString(name);
117             stringFromPropertiesFile = MessageFormat.format(
118                     stringFromPropertiesFile, new Object JavaDoc[]{replace0, replace1,
119                             replace2, replace3, replace4});
120             return stringFromPropertiesFile;
121         } catch (Exception JavaDoc e) {
122             return name;
123         }
124
125     }
126     /**
127      * Returns a string from a property file
128      */

129     public static String JavaDoc getString(String JavaDoc name, String JavaDoc replace0,
130             String JavaDoc replace1, String JavaDoc replace2, String JavaDoc replace3, String JavaDoc replace4,
131             String JavaDoc replace5) {
132         try {
133             String JavaDoc stringFromPropertiesFile = resBundle.getString(name);
134             stringFromPropertiesFile = MessageFormat.format(
135                     stringFromPropertiesFile, new Object JavaDoc[]{replace0, replace1,
136                             replace2, replace3, replace4, replace5});
137             return stringFromPropertiesFile;
138         } catch (Exception JavaDoc e) {
139             return name;
140         }
141
142     }
143 }
144
Popular Tags