KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > resources > ant > Policy


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

11 package org.eclipse.core.resources.ant;
12
13 import java.text.MessageFormat JavaDoc;// can't use ICU, used by ant
14
import java.util.*;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.NullProgressMonitor;
17
18 public class Policy {
19     private static final String JavaDoc bundleName = "org.eclipse.core.resources.ant.messages";//$NON-NLS-1$
20
private static ResourceBundle bundle = ResourceBundle.getBundle(bundleName, Locale.getDefault());
21
22     /**
23      * Lookup the message with the given ID in this catalog
24      */

25     public static String JavaDoc bind(String JavaDoc id) {
26         return bind(id, (String JavaDoc[]) null);
27     }
28
29     public static IProgressMonitor monitorFor(IProgressMonitor monitor) {
30         if (monitor == null)
31             return new NullProgressMonitor();
32         return monitor;
33     }
34
35     /**
36      * Lookup the message with the given ID in this catalog and bind its
37      * substitution locations with the given string.
38      */

39     public static String JavaDoc bind(String JavaDoc id, String JavaDoc binding) {
40         return bind(id, new String JavaDoc[] {binding});
41     }
42
43     /**
44      * Lookup the message with the given ID in this catalog and bind its
45      * substitution locations with the given strings.
46      */

47     public static String JavaDoc bind(String JavaDoc id, String JavaDoc binding1, String JavaDoc binding2) {
48         return bind(id, new String JavaDoc[] {binding1, binding2});
49     }
50
51     /**
52      * Lookup the message with the given ID in this catalog and bind its
53      * substitution locations with the given string values.
54      */

55     public static String JavaDoc bind(String JavaDoc id, String JavaDoc[] bindings) {
56         if (id == null)
57             return "No message available";//$NON-NLS-1$
58
String JavaDoc message = null;
59         try {
60             message = bundle.getString(id);
61         } catch (MissingResourceException e) {
62             // If we got an exception looking for the message, fail gracefully by just returning
63
// the id we were looking for. In most cases this is semi-informative so is not too bad.
64
return "Missing message: " + id + " in: " + bundleName;//$NON-NLS-1$ //$NON-NLS-2$
65
}
66         if (bindings == null)
67             return message;
68         return MessageFormat.format(message, bindings);
69     }
70 }
71
Popular Tags