Package: AcceleoExamplesMessages

AcceleoExamplesMessages

nameinstructionbranchcomplexitylinemethod
getString(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getString(String, Object[])
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
internalGetString(String)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2006, 2007, 2008, 2009 Obeo.
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: * Obeo - initial API and implementation
10: *******************************************************************************/
11: package org.eclipse.acceleo.examples.internal;
12:
13: import java.text.MessageFormat;
14: import java.util.MissingResourceException;
15: import java.util.ResourceBundle;
16:
17: /**
18: * Utility class to access externalized Strings used by the examples.
19: *
20: * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
21: */
22: public final class AcceleoExamplesMessages {
23:         /** Qualified path to the properties file in which to seek the keys. */
24:         private static final String BUNDLE_NAME = "org.eclipse.acceleo.examples.internal.acceleoexamplesmessages"; //$NON-NLS-1$
25:
26:         /** Contains the locale specific {@link String}s needed by this plug-in. */
27:         private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
28:
29:         /**
30:          * Utility classes don't need to (and shouldn't) be instantiated.
31:          */
32:         private AcceleoExamplesMessages() {
33:                 // prevents instantiation
34:         }
35:
36:         /**
37:          * This will return an unformatted String from the resource bundle.
38:          *
39:          * @param key
40:          * Key of the String we seek.
41:          * @return An unformatted String from the bundle.
42:          */
43:         private static String internalGetString(String key) {
44:                 try {
45:                         return RESOURCE_BUNDLE.getString(key);
46:                 } catch (MissingResourceException e) {
47:                         return '!' + key + '!';
48:                 }
49:         }
50:
51:         /**
52:          * Returns the specified {@link String} from the resource bundle.
53:          *
54:          * @param key
55:          * Key of the String we seek.
56:          * @return The String from the resource bundle associated with <code>key</code>.
57:          * <code>'!' + key + '!'</code> will be returned in case we didn't find it in the bundle.
58:          */
59:         public static String getString(String key) {
60:                 // Pass through MessageFormat so that we're consistent in the handling of special chars such as the
61:                 // apostrophe
62:                 return MessageFormat.format(internalGetString(key), new Object[] {});
63:         }
64:
65:         /**
66:          * Returns a String from the resource bundle bound with the given arguments.
67:          *
68:          * @param key
69:          * Key of the String we seek.
70:          * @param arguments
71:          * Arguments for the String formatting.
72:          * @return formatted {@link String}.
73:          * @see MessageFormat#format(String, Object[])
74:          */
75:         public static String getString(String key, Object... arguments) {
76:•                if (arguments == null) {
77:                         return getString(key);
78:                 }
79:                 return MessageFormat.format(internalGetString(key), arguments);
80:         }
81: }