001
002package org.opencms.jsp.util;
003
004import java.util.HashMap;
005import java.util.Map;
006
007/**
008 * Bean extending the CmsJspImageBean with an additional Map containing hi-DPI variants of the same image.
009 */
010public class CmsJspScaledImageBean extends CmsJspImageBean {
011
012    /**
013     * Internal Map used to store the hi-DPI variants of the image.
014     * <ul>
015     *   <li>key: the variant multiplier, e.g. "2x" (the common retina multiplier)</li>
016     *   <li>value: a CmsJspImageBean representing the hi-DPI variant</li>
017     * </ul>
018     */
019    private Map<String, CmsJspImageBean> m_hiDpiImages;
020
021    /**
022     * adds a CmsJspImageBean as hi-DPI variant to this image
023     * @param factor the variant multiplier, e.g. "2x" (the common retina multiplier)
024     * @param image the image to be used for this variant
025     */
026    public void addHiDpiImage(String factor, CmsJspImageBean image) {
027
028        if (m_hiDpiImages == null) {
029            m_hiDpiImages = new HashMap<>();
030        }
031        m_hiDpiImages.put(factor, image);
032    }
033
034    /**
035     * Returns the map containing all hi-DPI variants of this image.
036     * @return Map containing the hi-DPI variants of the image.
037     * <ul>
038     *   <li>key: the variant multiplier, e.g. "2x" (the common retina multiplier)</li>
039     *   <li>value: a CmsJspImageBean representing the hi-DPI variant</li>
040     * </ul>
041     */
042    public Map<String, CmsJspImageBean> getHiDpiImages() {
043
044        return m_hiDpiImages;
045    }
046
047}