1 11 package org.eclipse.ui.internal; 12 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 import java.net.URL ; 16 import com.ibm.icu.text.MessageFormat; 17 import java.util.ArrayList ; 18 import java.util.MissingResourceException ; 19 import java.util.PropertyResourceBundle ; 20 21 import org.eclipse.core.runtime.IProduct; 22 import org.eclipse.core.runtime.Path; 23 import org.eclipse.core.runtime.Platform; 24 import org.eclipse.jface.resource.ImageDescriptor; 25 import org.eclipse.ui.branding.IProductConstants; 26 27 37 public class ProductProperties extends BrandingProperties implements 38 IProductConstants { 39 40 private final IProduct product; 41 42 private String appName; 43 44 private String aboutText; 45 46 private ImageDescriptor aboutImageDescriptor; 47 48 private ImageDescriptor[] windowImageDescriptors; 49 50 private URL welcomePageUrl; 51 52 private String productName; 53 54 private String productId; 55 56 private static final String ABOUT_MAPPINGS = "$nl$/about.mappings"; 58 private static String [] systemPropertiesKeys = new String [0]; 59 private static String [] mappings = loadMappings(); 60 61 private static String [] loadMappings() { 62 IProduct product = Platform.getProduct(); 63 if (product == null) { 64 return new String [0]; 65 } 66 URL location = Platform.find(product.getDefiningBundle(), new Path( 67 ABOUT_MAPPINGS)); 68 PropertyResourceBundle bundle = null; 69 InputStream is; 70 if (location != null) { 71 is = null; 72 try { 73 is = location.openStream(); 74 bundle = new PropertyResourceBundle (is); 75 } catch (IOException e) { 76 bundle = null; 77 } finally { 78 try { 79 if (is != null) { 80 is.close(); 81 } 82 } catch (IOException e) { 83 } 85 } 86 } 87 88 ArrayList mappingsList = new ArrayList (); 89 if (bundle != null) { 90 boolean found = true; 91 int i = 0; 92 ArrayList systemPropertiesKeysList = new ArrayList (); 93 while (found) { 94 try { 95 String nextString = bundle.getString(Integer.toString(i)); 96 int length = nextString.length(); 97 104 if (length > 2 && nextString.indexOf('$') == 0 && nextString.lastIndexOf('$') == length - 1) { 105 int newIndex = systemPropertiesKeysList.size(); 106 systemPropertiesKeysList.add(nextString.substring(1, length-1)); 107 nextString = "{" + newIndex + "}"; } 109 mappingsList.add(nextString); 110 } catch (MissingResourceException e) { 111 found = false; 112 } 113 i++; 114 } 115 systemPropertiesKeys = (String []) systemPropertiesKeysList.toArray(new String [systemPropertiesKeysList.size()]) ; 116 } 117 return (String []) mappingsList.toArray(new String [mappingsList.size()]); 118 } 119 120 125 public ProductProperties(IProduct product) { 126 if (product == null) { 127 throw new IllegalArgumentException (); 128 } 129 this.product = product; 130 } 131 132 142 public String getAppName() { 143 if (appName == null) { 144 appName = getAppName(product); 145 } 146 return appName; 147 } 148 149 154 public String getAboutText() { 155 if (aboutText == null) { 156 aboutText = getAboutText(product); 157 } 158 return aboutText; 159 } 160 161 171 public ImageDescriptor getAboutImage() { 172 if (aboutImageDescriptor == null) { 173 aboutImageDescriptor = getAboutImage(product); 174 } 175 return aboutImageDescriptor; 176 } 177 178 187 public ImageDescriptor[] getWindowImages() { 188 if (windowImageDescriptors == null) { 189 windowImageDescriptors = getWindowImages(product); 190 } 191 return windowImageDescriptors; 192 } 193 194 201 public URL getWelcomePageUrl() { 202 if (welcomePageUrl == null) { 203 welcomePageUrl = getWelcomePageUrl(product); 204 } 205 return welcomePageUrl; 206 } 207 208 212 public String getProductName() { 213 if (productName == null) { 214 productName = getProductName(product); 215 } 216 return productName; 217 } 218 219 222 public String getProductId() { 223 if (productId == null) { 224 productId = getProductId(product); 225 } 226 return productId; 227 } 228 229 243 public static String getAppName(IProduct product) { 244 String property = product.getProperty(APP_NAME); 245 if (property == null) { 246 return ""; } 248 if (property.indexOf('{') == -1) { 249 return property; 250 } 251 return MessageFormat.format(property, mappings); 252 } 253 254 263 public static String getAboutText(IProduct product) { 264 String property = product.getProperty(ABOUT_TEXT); 265 if (property == null) { 266 return ""; } 268 if (property.indexOf('{') == -1) { 269 return property; 270 } 271 property = MessageFormat.format(property, mappings); 272 273 278 if (property.indexOf('{') == -1) { 279 return property; 280 } 281 282 if (systemPropertiesKeys.length == 0) 283 return property; 284 285 289 String [] systemPropertiesMappings = new String [systemPropertiesKeys.length]; 290 for (int i=0; i < systemPropertiesKeys.length; i++){ 291 String systemProperty = systemPropertiesKeys[i]; 292 systemPropertiesMappings[i] = System.getProperty(systemProperty, ""); } 295 298 return MessageFormat.format(property, systemPropertiesMappings); 299 } 300 301 311 public static ImageDescriptor getAboutImage(IProduct product) { 312 return getImage(product.getProperty(ABOUT_IMAGE), product 313 .getDefiningBundle()); 314 } 315 316 325 public static ImageDescriptor[] getWindowImages(IProduct product) { 326 String property = product.getProperty(WINDOW_IMAGES); 327 328 if (property == null) { 330 property = product.getProperty(WINDOW_IMAGE); 331 } 332 333 return getImages(property, product.getDefiningBundle()); 334 } 335 336 343 public static URL getWelcomePageUrl(IProduct product) { 344 return getUrl(product.getProperty(WELCOME_PAGE), product 345 .getDefiningBundle()); 346 } 347 348 352 public static String getProductName(IProduct product) { 353 return product.getName(); 354 } 355 356 359 public static String getProductId(IProduct product) { 360 return product.getId(); 361 } 362 } 363 | Popular Tags |