2011/08/05 - Jakarta Cactus has been retired.

For more information, please explore the Attic.

View Javadoc

1   /* 
2    * ========================================================================
3    * 
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   * 
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * 
19   * ========================================================================
20   */
21  package org.apache.cactus.eclipse.runner.ui;
22  
23  import java.text.MessageFormat;
24  import java.util.MissingResourceException;
25  import java.util.ResourceBundle;
26  
27  /**
28   * Helper class to format text messages from the Cactus property resource 
29   * bundle.
30   * 
31   * @version $Id: CactusMessages.java 238816 2004-02-29 16:36:46Z vmassol $
32   */
33  public final class CactusMessages
34  {
35      /**
36       * Name and location of property resource bundle on disk.
37       */
38      private static final String BUNDLE_NAME = 
39          "org.apache.cactus.eclipse.runner.ui.CactusMessages";
40  
41      /**
42       * The resource bundle object were Cactus messages are stored.
43       */
44      private static final ResourceBundle RESOURCE_BUNDLE = 
45          ResourceBundle.getBundle(BUNDLE_NAME);
46  
47      /**
48       * Prevent this class from being instantiated. It containes only static
49       * methods.
50       */
51      private CactusMessages()
52      {
53      }
54  
55      /**
56       * Gets a string from the resource bundle and formats it with one argument.
57       * 
58       * @param theKey the string used to get the bundle value, must not be null
59       * @param theArg the object to use when constructing the message
60       * @return the formatted string
61       */
62      public static String getFormattedString(String theKey, Object theArg)
63      {
64          return MessageFormat.format(getString(theKey), 
65              new Object[] {theArg});
66      }
67  
68      /**
69       * Gets a string from the resource bundle and formats it with arguments.
70       * 
71       * @param theKey the string used to get the bundle value, must not be null
72       * @param theArgs the objects to use when constructing the message
73       * @return the formatted string
74       */
75      public static String getFormattedString(String theKey, Object[] theArgs)
76      {
77          return MessageFormat.format(getString(theKey), theArgs);
78      }
79  
80      /**
81       * Gets an unformatted string from the resource bundle.
82       * 
83       * @param theKey the string used to get the bundle value, must not be null
84       * @return the string from the resource bundle or "![key name]!" if the key
85       *         does not exist in the resource bundle
86       */
87      public static String getString(String theKey)
88      {
89          try
90          {
91              return RESOURCE_BUNDLE.getString(theKey);
92          } 
93          catch (MissingResourceException e)
94          {
95              return '!' + theKey + '!';
96          }
97      }
98  }