Skip to main content
summaryrefslogtreecommitdiffstats
blob: d2dc6dc6994e9f406e1e1df048dfd2c858069bd1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*******************************************************************************
 * Copyright (c) 2001, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 * IBM Corporation - initial API and implementation
 ******************************************************************************/

package org.eclipse.wst.ws.internal.parser.plugin;

import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.eclipse.core.runtime.Plugin;
import org.eclipse.wst.command.internal.env.core.common.MessageUtils;

/**
 * The main plugin class to be used in the desktop.
 */
public class ParserPlugin extends Plugin {
	//The shared instance.
	private static ParserPlugin plugin;
	//Resource bundle.
	private ResourceBundle resourceBundle;
	
	/**
	 * The constructor.
	 */
	public ParserPlugin() {
		super();
		plugin = this;
		try {
			resourceBundle   = ResourceBundle.getBundle("org.eclipse.wst.ws.parser.ParserPluginResources");
		} catch (MissingResourceException x) {
			resourceBundle = null;
		}
	}

	/**
	 * Returns the shared instance.
	 */
	public static ParserPlugin getDefault() {
		return plugin;
	}

	/**
	 * Returns the string from the plugin's resource bundle,
	 * or 'key' if not found.
	 */
	public static String getResourceString(String key) {
		ResourceBundle bundle = ParserPlugin.getDefault().getResourceBundle();
		try {
			return (bundle != null) ? bundle.getString(key) : key;
		} catch (MissingResourceException e) {
			return key;
		}
	}

	/**
	 * Returns the plugin's resource bundle,
	 */
	public ResourceBundle getResourceBundle() {
		return resourceBundle;
	}

	 /**
	  * Returns the message string identified by the given key from
	  * the plugin.properties file for the appropriate locale.
	  * @param key The message key string prefixed by a "%" symbol.
	  * That is, the string passed in must be of the form "%KEY"
	  * where the plugin.properties file contains a line of the
	  * form: "KEY = value".
	  * @return The locale-specific message.
	  */
	  public static String getMessage ( String key )
	  {
	    MessageUtils msgUtils = new MessageUtils( "org.eclipse.wst.ws.parser.plugin", plugin );
	    
	    if( key.startsWith("%"))
	    {
	      key = key.substring( 1, key.length() );
	    }
	    
	    return msgUtils.getMessage(key);
	  }

	  /**
	  * Returns the message string identified by the given key from
	  * the plugin.properties file for the appropriate locale.
	  * Substitution sequences in the message string
	  * are replaced by the given array of substitution objects (which
	  * are most frequently strings). See java.text.MessageFormat for
	  * further details on substitution.
	  * @param key The message key string prefixed by a "%" symbol.
	  * That is, the string passed in must be of the form "%KEY"
	  * where the plugin.properties file contains a line of the
	  * form: "KEY = value".
	  * @param args The substitution values for the message
	  * as required by the message in plugin.properties and
	  * by the rules of class java.text.MessageFormat.
	  * @return The locale-specific message.
	  */
	  public static String getMessage ( String key, Object[] args )
	  {
	    return MessageFormat.format(getMessage(key),args);
	  }
}

Back to the top