1. /*
  2. * @(#)I18NImpl.java 1.3 03/12/19 16:54:01
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.imageio.plugins.common;
  8. import java.io.InputStream;
  9. import java.util.PropertyResourceBundle;
  10. import java.net.URL;
  11. /**
  12. * Class to simplify use of internationalization message strings.
  13. * Property files are constructed in terms of content as for JAI with
  14. * one "key=value" pair per line. All such files however have the same
  15. * name "properties". The resource extractor resolves the extraction of
  16. * the file from the jar as the package name is included automatically.
  17. *
  18. * <p>Extenders need only provide a static method
  19. * <code>getString(String)</code> which calls the static method in this
  20. * class with the name of the invoking class and returns a
  21. * <code>String</code>.
  22. */
  23. public class I18NImpl {
  24. /**
  25. * Returns the message string with the specified key from the
  26. * "properties" file in the package containing the class with
  27. * the specified name.
  28. */
  29. protected static final String getString(String className, String resource_name, String key) {
  30. PropertyResourceBundle bundle = null;
  31. try {
  32. InputStream stream =
  33. Class.forName(className).getResourceAsStream(resource_name);
  34. bundle = new PropertyResourceBundle(stream);
  35. } catch(Throwable e) {
  36. throw new RuntimeException(e); // Chain the exception.
  37. }
  38. return (String)bundle.handleGetObject(key);
  39. }
  40. }