* by the registry.
*/
private Image getImage(String imagePath, Element element) {
Image image = null;
if (imagePath != null && imagePath.length() > 0) {
ImageRegistry registry = PDPlugin.getDefault().getImageRegistry();
image = registry.get(imagePath);
if (image == null) {
try {
URL imageURL = new URL(imagePath);
ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(imageURL);
image = imageDescriptor.createImage();
if (image != null) {
registry.put(imagePath, image);
}
} catch(MalformedURLException mue) {
//attempt to resolve as relative to document
if (element instanceof IDOMNode) {
IDOMModel model = ((IDOMNode)element).getModel();
if (model != null) {
String baseLocation = model.getBaseLocation();
if (baseLocation != null && baseLocation.length() > 0) {
IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
if (wsRoot != null) {
IResource jspRes = wsRoot.findMember(baseLocation);
if (jspRes != null) {
IContainer jspFolder = jspRes.getParent();
if (jspFolder != null) {
IResource imageRes = jspFolder.findMember(imagePath);
if (imageRes != null) {
URI imageURI = imageRes.getLocationURI();
if (imageURI != null) {
try {
URL imageURL = imageURI.toURL();
ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(imageURL);
image = imageDescriptor.createImage();
if (image != null) {
registry.put(imagePath, image);
}
} catch(MalformedURLException mue2) {
//ignore - what else can be done?
}
}
}
}
}
}
}
}
}
}
} else if (image.isDisposed()) {
//shouldn't be able to get here from there, but...just in case
registry.remove(imagePath);
image = getImage(imagePath, element);
}
}
return image;
}