KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ssh2 > Policy


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.team.internal.ccvs.ssh2;
12
13
14 import java.text.MessageFormat JavaDoc;
15 import java.util.MissingResourceException JavaDoc;
16 import java.util.ResourceBundle JavaDoc;
17
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.OperationCanceledException;
20
21 public class Policy {
22     protected static ResourceBundle JavaDoc bundle = null;
23
24     /**
25      * Creates a NLS catalog for the given locale.
26      */

27     public static void localize(String JavaDoc bundleName) {
28         bundle = ResourceBundle.getBundle(bundleName);
29     }
30     
31     /**
32      * Gets a string from the resource bundle. We don't want to crash because of a missing String.
33      * Returns the key if not found.
34      */

35     public static String JavaDoc bind(String JavaDoc key) {
36         try {
37             return bundle.getString(key);
38         } catch (MissingResourceException JavaDoc e) {
39             return key;
40         } catch (NullPointerException JavaDoc e) {
41             return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$
42
}
43     }
44
45     /**
46      * Lookup the message with the given ID in this catalog and bind its
47      * substitution locations with the given string.
48      */

49     public static String JavaDoc bind(String JavaDoc id, String JavaDoc binding) {
50         return bind(id, new String JavaDoc[] { binding });
51     }
52         
53     /**
54      * Gets a string from the resource bundle and binds it with the given arguments. If the key is
55      * not found, return the key.
56      */

57     public static String JavaDoc bind(String JavaDoc key, Object JavaDoc[] args) {
58         try {
59             return MessageFormat.format(bind(key), args);
60         } catch (MissingResourceException JavaDoc e) {
61             return key;
62         } catch (NullPointerException JavaDoc e) {
63             return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$
64
}
65     }
66
67     public static void checkCanceled(IProgressMonitor monitor) {
68         if (monitor != null && monitor.isCanceled()) {
69             throw new OperationCanceledException();
70         }
71     }
72
73 }
74
Popular Tags