1 11 package org.eclipse.ui.internal; 12 13 import java.net.MalformedURLException ; 14 import java.net.URL ; 15 import java.util.ArrayList ; 16 import java.util.StringTokenizer ; 17 18 import org.eclipse.core.runtime.Path; 19 import org.eclipse.core.runtime.Platform; 20 import org.eclipse.jface.resource.ImageDescriptor; 21 import org.osgi.framework.Bundle; 22 23 29 public abstract class BrandingProperties { 30 31 42 public static URL getUrl(String value, Bundle definingBundle) { 43 try { 44 if (value != null) { 45 return new URL (value); 46 } 47 } catch (MalformedURLException e) { 48 if (definingBundle != null) { 49 return Platform.find(definingBundle, new Path(value)); 50 } 51 } 52 53 return null; 54 } 55 56 67 public static ImageDescriptor getImage(String value, Bundle definingBundle) { 68 URL url = getUrl(value, definingBundle); 69 return url == null ? null : ImageDescriptor.createFromURL(url); 70 } 71 72 86 public static URL [] getURLs(String value, Bundle definingBundle) { 87 if (value == null) { 88 return null; 89 } 90 91 StringTokenizer tokens = new StringTokenizer (value, ","); ArrayList array = new ArrayList (10); 93 while (tokens.hasMoreTokens()) { 94 array.add(getUrl(tokens.nextToken().trim(), definingBundle)); 95 } 96 97 return (URL []) array.toArray(new URL [array.size()]); 98 } 99 100 114 public static ImageDescriptor[] getImages(String value, 115 Bundle definingBundle) { 116 URL [] urls = getURLs(value, definingBundle); 117 if (urls == null || urls.length <= 0) { 118 return null; 119 } 120 121 ImageDescriptor[] images = new ImageDescriptor[urls.length]; 122 for (int i = 0; i < images.length; ++i) { 123 images[i] = ImageDescriptor.createFromURL(urls[i]); 124 } 125 126 return images; 127 } 128 } 129 | Popular Tags |