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, element));
}
if (value instanceof DrawableWrapper)
{
return value;
}
if (DrawableWrapper.isDrawable(value))
{
return new DrawableWrapper(value);
}
final ContentTypeContext context = element.getElementContext(ContentTypeContext.class);
if (context.failureCache != null)
{
final Object o = context.failureCache.get(value);
if (Boolean.TRUE.equals(o))
{
return null;
}
}
try
{
final ResourceKey contentBase = runtime.getProcessingContext().getContentBase();
final ResourceManager resManager = runtime.getProcessingContext().getResourceManager();
final Object contentBaseValue = element.getAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.CONTENT_BASE);
final ResourceKey key = resManager.createOrDeriveKey(contentBase, value, contentBaseValue);
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;
}