1 19 20 package org.netbeans; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.util.ArrayList ; 26 import java.util.Collections ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.Locale ; 30 import java.util.MissingResourceException ; 31 import java.util.Properties ; 32 import java.util.ResourceBundle ; 33 import java.util.Set ; 34 import java.util.jar.Attributes ; 35 import java.util.jar.Manifest ; 36 import java.util.logging.Level ; 37 import org.openide.util.NbBundle; 38 39 47 final class FixedModule extends Module { 48 49 50 private Properties localizedProps; 51 52 53 public FixedModule(ModuleManager mgr, Events ev, Manifest manifest, Object history, ClassLoader classloader) throws InvalidException { 54 super(mgr, ev, manifest, history, classloader); 55 loadLocalizedPropsClasspath(); 56 parseManifest(); 57 } 58 59 74 public Object getLocalizedAttribute(String attr) { 75 String locb = getManifest().getMainAttributes().getValue("OpenIDE-Module-Localizing-Bundle"); boolean usingLoader = false; 77 if (locb != null) { 78 if (classloader != null) { 79 if (locb.endsWith(".properties")) { usingLoader = true; 81 String basename = locb.substring(0, locb.length() - 11).replace('/', '.'); 82 try { 83 ResourceBundle bundle = NbBundle.getBundle(basename, Locale.getDefault(), classloader); 84 try { 85 return bundle.getString(attr); 86 } catch (MissingResourceException mre) { 87 } 89 } catch (MissingResourceException mre) { 90 Util.err.log(Level.WARNING, null, mre); 91 } 92 } else { 93 Util.err.warning("cannot efficiently load non-*.properties OpenIDE-Module-Localizing-Bundle: " + locb); 94 } 95 } 96 if (!usingLoader) { 97 if (localizedProps != null) { 98 String val = localizedProps.getProperty(attr); 99 if (val != null) { 100 return val; 101 } 102 } 103 } 104 } 105 int idx = attr.lastIndexOf('/'); if (idx == -1) { 108 return NbBundle.getLocalizedValue(getManifest().getMainAttributes(), new Attributes.Name (attr)); 110 } else { 111 String section = attr.substring(0, idx); 113 String realAttr = attr.substring(idx + 1); 114 Attributes attrs = getManifest().getAttributes(section); 115 if (attrs != null) { 116 return NbBundle.getLocalizedValue(attrs, new Attributes.Name (realAttr)); 117 } else { 118 return null; 119 } 120 } 121 } 122 123 public boolean isFixed() { 124 return true; 125 } 126 127 131 private void loadLocalizedPropsClasspath() throws InvalidException { 132 Attributes attr = manifest.getMainAttributes(); 133 String locbundle = attr.getValue("OpenIDE-Module-Localizing-Bundle"); if (locbundle != null) { 135 Util.err.fine("Localized props in " + locbundle + " for " + attr.getValue("OpenIDE-Module")); 136 try { 137 int idx = locbundle.lastIndexOf('.'); String name, ext; 139 if (idx == -1) { 140 name = locbundle; 141 ext = ""; } else { 143 name = locbundle.substring(0, idx); 144 ext = locbundle.substring(idx); 145 } 146 List <String > suffixes = new ArrayList <String >(10); 147 Iterator <String > it = NbBundle.getLocalizingSuffixes(); 148 while (it.hasNext()) { 149 suffixes.add(it.next()); 150 } 151 Collections.reverse(suffixes); 152 it = suffixes.iterator(); 153 for (String suffix: suffixes) { 154 String resource = name + suffix + ext; 155 InputStream is = classloader.getResourceAsStream(resource); 156 if (is != null) { 157 Util.err.fine("Found " + resource); 158 if (localizedProps == null) { 159 localizedProps = new Properties (); 160 } 161 localizedProps.load(is); 162 } 163 } 164 if (localizedProps == null) { 165 throw new IOException ("Could not find localizing bundle: " + locbundle); } 167 } catch (IOException ioe) { 168 throw (InvalidException) new InvalidException(ioe.toString()).initCause(ioe); 169 } 170 } 171 } 172 173 184 public List <File > getAllJars() { 185 return Collections.emptyList(); 186 } 187 188 195 public void setReloadable(boolean r) { 196 throw new IllegalStateException (); 197 } 198 199 205 public void reload() throws IOException { 206 throw new IOException ("Fixed module cannot be reloaded!"); } 208 209 213 protected void classLoaderUp(Set parents) throws IOException { 214 return; } 216 217 218 protected void classLoaderDown() { 219 return; } 221 222 protected void cleanup() { 223 return; } 225 226 227 protected void destroy() { 228 } 229 230 231 public String toString() { 232 String s = "FixedModule:" + getCodeNameBase(); if (!isValid()) s += "[invalid]"; return s; 235 } 236 } 237 | Popular Tags |