FileDocCategorySizeDatePackage
ResourceBundleAccessor.javaAPI DocExample3010Tue Dec 08 01:21:00 GMT 1998oisoft.togetherx.scripts.doc

ResourceBundleAccessor

public class ResourceBundleAccessor extends Object

Fields Summary
Constructors Summary
Methods Summary
private static java.io.InputStreamgetResourceAsStream(java.lang.String fileName, java.lang.Class cls)

        fileName = resolveName(fileName, cls);
        ClassLoader loader = cls.getClassLoader ();
        if (loader == null) {
            return ClassLoader.getSystemResourceAsStream(fileName);
        }
        InputStream in = loader.getResourceAsStream(fileName);
        if (in == null) {
            in = ClassLoader.getSystemResourceAsStream(fileName);
        }
        return in;
    
public static java.util.ResourceBundlegetResourceBundle(java.lang.String className, java.lang.String propertyName)
Returns resource bundle associated with class or with property file

param
className a class which extends ListResourceBundle
param
propertyName a name for property file (without .properties prefix)

        ResourceBundle myBundle = null;
        // Try to open property file first
        InputStream in = getResourceAsStream(propertyName + ".properties", ResourceBundleAccessor.class);
        if (in != null) {
            try {
                myBundle = new PropertyResourceBundle (in);
            }
            catch(IOException ioException) {
                myBundle = null;
            }
            finally{
                try {
                    in.close ();
                    in = null;
                    System.gc ();
                }
                catch(IOException closeException) {
                    System.out.println ("Could not close resource input stream: " + closeException);
                }
            }
        }

        // If property file did not open, use standard way
        if (myBundle == null) {
            System.err.println ("Property file ["+ propertyName + ".properties] not found , opening class");
            // Try to open resources as class/property
            myBundle = ResourceBundle.getBundle (className);
        }
        return myBundle;
    
private static java.lang.StringresolveName(java.lang.String name, java.lang.Class clazz)

        System.err.println("resolveName " + name);

        if (name == null) {
            return name;
        }
        if (!name.startsWith("/")) {
            Class c = clazz;
            while (c.isArray()) {
                c = c.getComponentType();
            }
            String baseName = c.getName();
            int index = baseName.lastIndexOf('.");
            if (index != -1) {
                name = baseName.substring(0, index).replace('.", '/")+"/"+name;
            }
        }
        else {
            name = name.substring(1);
        }

        System.err.println("resolvedName = " + name);
        return name;