www.pudn.com > 20061029005.rar > ResourceBundle.java


// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov. 
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html 
// Decompiler options: packimports(3) fieldsfirst ansi  
 
package org.cesar.inmotion.util; 
 
import java.io.PrintStream; 
import java.util.Hashtable; 
 
public class ResourceBundle 
{ 
    public static class Locale 
    { 
 
        private String language; 
        private String country; 
        private static Locale defaultLocale = new Locale("en-US"); 
 
        public String getLanguage() 
        { 
            return language; 
        } 
 
        public String getCountry() 
        { 
            return country; 
        } 
 
        public static Locale getDefaultLocale() 
        { 
            return defaultLocale; 
        } 
 
        public static void setDefaultLocale(Locale locale) 
        { 
            defaultLocale = locale; 
        } 
 
 
        public Locale(String s, String s1) 
        { 
            language = "en"; 
            country = "US"; 
            language = s; 
            country = s1; 
        } 
 
        public Locale(String s) 
        { 
            language = "en"; 
            country = "US"; 
            if(s != null) 
            { 
                int i = s.indexOf(45); 
                if(i != -1) 
                { 
                    language = s.substring(0, i); 
                    s = s.substring(i + 1); 
                    i = s.indexOf(45); 
                    if(i == -1) 
                        country = s; 
                    else 
                        country = s.substring(0, i); 
                } 
                System.out.println("language = " + language); 
                System.out.println("country = " + country); 
            } 
        } 
    } 
 
 
    private static Hashtable groups = new Hashtable(); 
    protected Hashtable resources; 
    private ResourceBundle parent; 
 
    protected ResourceBundle() 
    { 
        resources = new Hashtable(); 
    } 
 
    public static Object getObject(String s, String s1) 
    { 
        ResourceBundle resourcebundle; 
        synchronized(groups) 
        { 
            resourcebundle = (ResourceBundle)groups.get(s); 
            if(resourcebundle == null) 
                resourcebundle = loadBundle(s); 
        } 
        return resourcebundle.getResource(s1); 
    } 
 
    public static String getString(String s, String s1) 
    { 
        return (String)getObject(s, s1); 
    } 
 
    public static ResourceBundle loadBundle(String s) 
    { 
        ResourceBundle resourcebundle = null; 
        Locale locale = Locale.getDefaultLocale(); 
        String s1 = locale.getLanguage(); 
        String s2 = locale.getCountry(); 
        try 
        { 
            resourcebundle = (ResourceBundle)Class.forName(s).newInstance(); 
        } 
        catch(Exception exception) { } 
        if(s1 != null) 
        { 
            try 
            { 
                ResourceBundle resourcebundle1 = (ResourceBundle)Class.forName(s + '_' + s1).newInstance(); 
                resourcebundle1.setParent(resourcebundle); 
                resourcebundle = resourcebundle1; 
            } 
            catch(Exception exception1) { } 
            if(s2 != null) 
                try 
                { 
                    ResourceBundle resourcebundle2 = (ResourceBundle)Class.forName(s + '_' + s1 + '_' + s2).newInstance(); 
                    resourcebundle2.setParent(resourcebundle); 
                    resourcebundle = resourcebundle2; 
                } 
                catch(Exception exception2) { } 
        } 
        if(resourcebundle != null) 
            groups.put(s, resourcebundle); 
        return resourcebundle; 
    } 
 
    protected void setParent(ResourceBundle resourcebundle) 
    { 
        parent = resourcebundle; 
    } 
 
    public Object getResource(String s) 
    { 
        Object obj = null; 
        if(resources != null) 
            obj = resources.get(s); 
        if(obj == null && parent != null) 
            obj = parent.getResource(s); 
        return obj; 
    } 
 
    public String getResourceAsString(String s) 
    { 
        Object obj = null; 
        if(resources != null) 
            obj = resources.get(s); 
        if(obj == null && parent != null) 
            obj = parent.getResource(s); 
        return (String)obj; 
    } 
 
}