ResourceManager.java :  » Database-ORM » tro-community-7.2-1 » jtaDiscRack » Java Open Source

Java Open Source » Database ORM » tro community 7.2 1 
tro community 7.2 1 » jtaDiscRack » ResourceManager.java
package jtaDiscRack;

import java.util.*;
import java.net.URL;

/**
 * Implements the static methods that are used to implement
 * multilanguage support.
 *
 * @author Sasa Bojanic
 * @version 1.0
 */
public class ResourceManager {
   private static final String resourcePath=
         "jtaDiscRack.resources.jtaDiscRack";

   public static ResourceBundle defaultResource;


   static {
      try {
         defaultResource = ResourceBundle.
            getBundle(resourcePath);
      }
      catch (MissingResourceException mre) {
         System.err.println(resourcePath+".properties not found");
         System.exit(1);
      }
   }

   /**
    * Gets a resource string from the resource bundle.<p> Resource bundle
    * represents the <i>property file</i>. For example, if property file
    * contains something like this:<BR><CENTER>menubar=file edit help</CENTER>
    * method call getResourceString("menubar") will give the string
    * <i>file edit help</i> as a result. <BR> This method reads information
    * from property file. If can't find desired resource, returns <b>null</b>.
    * @param nm name of the resource to fetch.
    * @return String value of named resource.
    */
   public static String getResourceString (String nm) {
      String str;
      try {
         str=defaultResource.getString(nm);
      } catch (MissingResourceException mre1) {
         str = null;
      }
      return str;
   }

   /**
    * Gets the url from a resource string.
    * @param key the string key to the url in the resource bundle.
    * @return the resource location.
    * @see java.lang.Class#getResource
    */
   public static URL getResource (String key) {
      String name = getResourceString(key);
      if (name != null) {
         URL url = ResourceManager.class.getClassLoader().getResource(name);
         return url;
      }
      return null;
   }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.