if (value instanceof Image)
{
try
{
return new DefaultImageReference((Image) value);
}
catch (IOException e)
{
ContentType.logger.warn("Failed to load content using value " + value, e);
}
return null;
}
if (value instanceof Shape)
{
return value;
}
if (value instanceof ImageContainer)
{
return value;
}
if (value instanceof Component)
{
final Component c = (Component) value;
return new DrawableWrapper(createComponentDrawable(runtime, c));
}
if (value instanceof DrawableWrapper)
{
return value;
}
if (DrawableWrapper.isDrawable(value))
{
return new DrawableWrapper(value);
}
if (failureCache != null)
{
final Object o = failureCache.get(value);
if (Boolean.TRUE.equals(o))
{
return null;
}
}
try
{
final ResourceKey contentBase = runtime.getProcessingContext().getContentBase();
final ResourceManager resManager = runtime.getProcessingContext().getResourceManager();
final ResourceKey key;
if (value instanceof ResourceKey)
{
key = (ResourceKey) value;
}
else if (value instanceof Blob)
{
final Blob b = (Blob) value;
final byte[] data = IOUtils.getInstance().readBlob(b);
key = resManager.createKey(data);
}
else if (value instanceof String)
{
final Object baseURL = element.getAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.CONTENT_BASE);
if (baseURL instanceof String)
{
final ResourceKey baseKey = createKeyFromString(resManager, null, (String) baseURL);
key = createKeyFromString(resManager, baseKey, (String) value);
}
else if (baseURL instanceof ResourceKey)
{
final ResourceKey baseKey = (ResourceKey) baseURL;
key = createKeyFromString(resManager, baseKey, (String) value);
}
else if (baseURL != null)
{
// if a base-url object is given, we assume that it is indeed valid.
final ResourceKey baseKey = resManager.createKey(baseURL);
key = createKeyFromString(resManager, baseKey, (String) value);
}
else
{
key = createKeyFromString(resManager, contentBase, (String) value);
}
}
else
{
key = resManager.createKey(value);
}
if (key == null)
{
return null;
}
final Resource resource = resManager.create(key, contentBase, ContentType.TARGETS);
final Object resourceContent = resource.getResource();
if (resourceContent instanceof DrawableWrapper)
{
return resourceContent;
}
else if (DrawableWrapper.isDrawable(resourceContent))
{
return new DrawableWrapper(resourceContent);
}
else if (resourceContent instanceof Image)
{
return new DefaultImageReference(resource);
}
else
{
return resourceContent;
}