
net.sf.ahtutils.web.mbean.util.AbstractIconBean Maven / Gradle / Ivy
package net.sf.ahtutils.web.mbean.util;
import java.io.Serializable;
import java.util.Hashtable;
import java.util.Map;
import net.sf.ahtutils.jsf.filter.UtilsStatusFilter;
import net.sf.ahtutils.model.interfaces.status.UtilsDescription;
import net.sf.ahtutils.model.interfaces.status.UtilsLang;
import net.sf.ahtutils.model.interfaces.status.UtilsStatus;
import net.sf.ahtutils.model.interfaces.with.EjbWithImage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AbstractIconBean > implements Serializable
{
final static Logger logger = LoggerFactory.getLogger(AbstractIconBean.class);
private static final long serialVersionUID = 1L;
private String imagePath;
private Map> mapImages;
private Map> mapImagesAlt;
protected Map mapStatic;
//******* Methods *******************************
public void initPath(String imagePath)
{
this.imagePath=imagePath;
mapImages = new Hashtable>();
mapImagesAlt = new Hashtable>();
mapStatic = new Hashtable();
}
public String urlFilter(Integer size, UtilsStatusFilter filter)
{
// logger.info("URL for "+filter.getValue().getCode()+" active="+filter.isActive());
if(filter.isActive()){return url(size,filter.getValue());}
else
{
String key = filter.getValue().getClass().getSimpleName();
if(!mapImagesAlt.containsKey(key)){generate(mapImagesAlt,size, filter.getValue().getId(), filter.getValue().getImageAlt(), key);}
else
{
if(!mapImagesAlt.get(key).containsKey(filter.getValue().getId())){generate(mapImagesAlt,size, filter.getValue().getId(), filter.getValue().getImageAlt(), key);}
}
return mapImagesAlt.get(key).get(filter.getValue().getId());
}
}
public String url(Integer size, EjbWithImage image)
{
String key = image.getClass().getSimpleName();
if(!mapImages.containsKey(key)){generate(mapImages, size, image.getId(), image.getImage(), key);}
else
{
if(!mapImages.get(key).containsKey(image.getId())){generate(mapImages, size, image.getId(), image.getImage(), key);}
}
return mapImages.get(key).get(image.getId());
}
private void generate(Map> map, int size, long id, String image, String key)
{
if(!map.containsKey(key))
{
map.put(key, new Hashtable());
}
StringBuffer sb = new StringBuffer();
sb.append("/").append(imagePath);
sb.append("/").append(size);
sb.append("/");
if(image!=null){sb.append(image);}
else{sb.append("noImage.png");}
map.get(key).put(id, sb.toString());
}
public String icon(int size, String key)
{
StringBuffer sb = new StringBuffer();
sb.append("/").append(imagePath);
sb.append("/").append(size);
sb.append("/").append(mapStatic.get(key));
return sb.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy