* @return the encoded path to the image source
*/
public static String getImageSource(FacesContext context, UIComponent component, String attrName) {
String resName = (String) component.getAttributes().get("name");
ResourceHandler handler = context.getApplication().getResourceHandler();
if (resName != null) {
String libName = (String) component.getAttributes().get("library");
Resource res = handler.createResource(resName, libName);
if (res == null) {
if (context.isProjectStage(ProjectStage.Development)) {
String msg = "Unable to find resource " + resName;
context.addMessage(component.getClientId(context),
new FacesMessage(FacesMessage.SEVERITY_ERROR,
msg,
msg));
}
return "RES_NOT_FOUND";
} else {
String requestPath = res.getRequestPath();
return context.getExternalContext().encodeResourceURL(requestPath);
}
} else {
String value = (String) component.getAttributes().get(attrName);
if (value == null || value.length() == 0) {
return "";
}
if (handler.isResourceURL(value)) {
return value;
} else {
value = context.getApplication().getViewHandler().
getResourceURL(context, value);
return (context.getExternalContext().encodeResourceURL(value));