1 8 package org.apache.avalon.excalibur.i18n; 9 10 import java.util.HashMap ; 11 12 17 public class ResourceManager 18 { 19 private final static HashMap c_resources = new HashMap (); 20 21 27 public final static Resources getBaseResources( final String baseName ) 28 { 29 return getBaseResources( baseName, null ); 30 } 31 32 39 public final static Resources getBaseResources( final String baseName, 40 final ClassLoader classLoader ) 41 { 42 Resources packet = (Resources)c_resources.get( baseName ); 44 45 if( null == packet ) 46 { 47 packet = new Resources( baseName, classLoader ); 48 c_resources.put( baseName, packet ); 49 } 50 51 return packet; 52 } 53 54 61 public final static Resources getResources( final String resource ) 62 { 63 return getBaseResources( resource + ".Resources" ); 64 } 65 66 74 public final static Resources getPackageResources( final Class clazz ) 75 { 76 return getBaseResources( getPackageResourcesBaseName( clazz ), clazz.getClassLoader() ); 77 } 78 79 87 public final static Resources getClassResources( final Class clazz ) 88 { 89 return getBaseResources( getClassResourcesBaseName( clazz ), clazz.getClassLoader() ); 90 } 91 92 100 public final static String getPackageResourcesBaseName( final Class clazz ) 101 { 102 final Package pkg = clazz.getPackage(); 103 104 String baseName; 105 if ( null == pkg ) 106 { 107 final String name = clazz.getName(); 108 if ( -1 == name.lastIndexOf( "." ) ) 109 { 110 baseName = "Resources"; 111 } 112 else 113 { 114 baseName = name.substring( 0, name.lastIndexOf( "." ) ) + ".Resources"; 115 } 116 } 117 else 118 { 119 baseName = pkg.getName() + ".Resources"; 120 } 121 122 return baseName; 123 } 124 125 133 public final static String getClassResourcesBaseName( final Class clazz ) 134 { 135 return clazz.getName() + "Resources"; 136 } 137 138 141 private ResourceManager() 142 { 143 } 144 } 145 | Popular Tags |