001 002package org.opencms.jsp; 003 004import org.opencms.loader.CmsImageScaler; 005import org.opencms.util.CmsStringUtil; 006 007import javax.servlet.jsp.tagext.BodyTagSupport; 008 009/** 010 * Abstract parent for all JSP tags dealing with image scaling, defines some common image scaler 011 * properties and corresponding getters/setters that may be used by extending classes. 012 */ 013public abstract class CmsJspImageScalerTagSupport extends BodyTagSupport { 014 015 /** Serial version UID required for safe serialization. */ 016 private static final long serialVersionUID = 1303030767942208144L; 017 018 /** Required image scaler attributes constant. */ 019 protected static final String SCALE_ATTR_HEIGHT = "height"; 020 021 /** Required image scaler attributes constant. */ 022 protected static final String SCALE_ATTR_MAXHEIGHT = "maxHeight"; 023 024 /** Required image scaler attributes constant. */ 025 protected static final String SCALE_ATTR_MAXWIDTH = "maxWidth"; 026 027 /** Required image scaler attributes constant. */ 028 protected static final String SCALE_ATTR_POSITION = "scaleposition"; 029 030 /** Required image scaler attributes constant. */ 031 protected static final String SCALE_ATTR_QUALITY = "scalequality"; 032 033 /** Required image scaler attributes constant. */ 034 protected static final String SCALE_ATTR_RENDERMODE = "scalerendermode"; 035 036 /** Required image scaler attributes constant. */ 037 protected static final String SCALE_ATTR_TYPE = "scaletype"; 038 039 /** Required image scaler attributes constant. */ 040 protected static final String SCALE_ATTR_WIDTH = "width"; 041 042 /** The given image scaler parameters. */ 043 protected transient CmsImageScaler m_scaler; 044 045 /** The image source. */ 046 protected String m_src; 047 048 /** 049 * Initializes a CmsImageScaler to be used by derived classes. The CmsImageScaler is recreated 050 * every time {@link #release()} is called. 051 */ 052 public CmsJspImageScalerTagSupport() { 053 // initialize the image scaler parameter container 054 m_scaler = new CmsImageScaler(); 055 } 056 057 /** 058 * Returns the scaling height for the image.<p> 059 * 060 * @return the scaling height for the image 061 */ 062 public String getHeight() { 063 064 return String.valueOf(m_scaler.getHeight()); 065 } 066 067 /** 068 * Returns the maximum scaling height for the image, only needed if scale type is 5.<p> 069 * 070 * @return the maximum scaling height for the image 071 */ 072 public String getMaxHeight() { 073 074 return String.valueOf(m_scaler.getMaxHeight()); 075 } 076 077 /** 078 * Returns the maximum scaling width for the image, only needed if scale type is 5.<p> 079 * 080 * @return the maximum scaling width for the image 081 */ 082 public String getMaxWidth() { 083 084 return String.valueOf(m_scaler.getMaxWidth()); 085 } 086 087 /** 088 * Returns the background color used by the image scaler.<p> 089 * 090 * @return the background color used by the image scaler 091 */ 092 public String getScaleColor() { 093 094 return m_scaler.getColorString(); 095 } 096 097 /** 098 * Returns the filter list used by the image scaler.<p> 099 * 100 * @return the filter list used by the image scaler 101 */ 102 public String getScaleFilter() { 103 104 return m_scaler.getFiltersString(); 105 } 106 107 /** 108 * Returns the position used by the image scaler.<p> 109 * 110 * @return the position used by the image scaler 111 */ 112 public String getScalePosition() { 113 114 return String.valueOf(m_scaler.getPosition()); 115 } 116 117 /** 118 * Returns the quality used by the image scaler.<p> 119 * 120 * @return the quality used by the image scaler 121 */ 122 public String getScaleQuality() { 123 124 return String.valueOf(m_scaler.getQuality()); 125 } 126 127 /** 128 * Returns the render mode used by the image scaler.<p> 129 * 130 * @return the render mode used by the image scaler 131 */ 132 public String getScaleRendermode() { 133 134 return String.valueOf(m_scaler.getRenderMode()); 135 } 136 137 /** 138 * Returns the scaling type for the image.<p> 139 * 140 * @return the scaling type for the image 141 */ 142 public String getScaleType() { 143 144 return String.valueOf(m_scaler.getType()); 145 } 146 147 /** 148 * Returns the source of the image to scale, 149 * which will have the OpenCms webapp / servlet prefix added.<p> 150 * 151 * @return the source of the image to scale 152 */ 153 public String getSrc() { 154 155 return m_src; 156 } 157 158 /** 159 * Returns the scaling width for the image.<p> 160 * 161 * @return the scaling width for the image 162 */ 163 public String getWidth() { 164 165 return String.valueOf(m_scaler.getWidth()); 166 } 167 168 /** 169 * Does some cleanup and creates a new ImageScaler before the tag is released to the tag pool. 170 * 171 * @see javax.servlet.jsp.tagext.Tag#release() 172 */ 173 @Override 174 public void release() { 175 176 m_scaler = new CmsImageScaler(); 177 m_src = null; 178 super.release(); 179 } 180 181 /** 182 * Sets the scaling height for the image.<p> 183 * 184 * If no valid integer is given, then "0" is used as value.<p> 185 * 186 * @param value the scaling height for the image to set 187 */ 188 public void setHeight(String value) { 189 190 m_scaler.setHeight(CmsStringUtil.getIntValueRounded(value, 0, SCALE_ATTR_HEIGHT)); 191 } 192 193 /** 194 * Sets the maximum scaling height for the image, only needed if scale type is 5.<p> 195 * 196 * If no valid integer is given, then the value of {@link #getHeight()} is used as value.<p> 197 * 198 * @param value the maximum scaling height for the image to set 199 */ 200 public void setMaxHeight(String value) { 201 202 m_scaler.setMaxHeight(CmsStringUtil.getIntValueRounded(value, -1, SCALE_ATTR_MAXHEIGHT)); 203 } 204 205 /** 206 * Sets the maximum scaling width for the image, only needed if scale type is 5.<p> 207 * 208 * If no valid integer is given, then the value of {@link #getWidth()} is used as value.<p> 209 * 210 * @param value the maximum scaling width for the image to set 211 */ 212 public void setMaxWidth(String value) { 213 214 m_scaler.setMaxWidth(CmsStringUtil.getIntValueRounded(value, -1, SCALE_ATTR_MAXWIDTH)); 215 } 216 217 /** 218 * Sets the background color used by the image scaler.<p> 219 * 220 * @param value the background color to set 221 */ 222 public void setScaleColor(String value) { 223 224 m_scaler.setColor(value); 225 } 226 227 /** 228 * Sets the filter(s) used by the image scaler.<p> 229 * 230 * @param value the filter(s) to set 231 */ 232 public void setScaleFilter(String value) { 233 234 m_scaler.setFilters(value); 235 } 236 237 /** 238 * Sets the position used by the image scaler.<p> 239 * 240 * @param value the position to set 241 */ 242 public void setScalePosition(String value) { 243 244 m_scaler.setPosition(CmsStringUtil.getIntValue(value, 0, SCALE_ATTR_POSITION)); 245 } 246 247 /** 248 * Sets the quality used by the image scaler.<p> 249 * 250 * @param value the quality to set 251 */ 252 public void setScaleQuality(String value) { 253 254 m_scaler.setQuality(CmsStringUtil.getIntValue(value, 0, SCALE_ATTR_QUALITY)); 255 } 256 257 /** 258 * Sets the render mode used by the image scaler.<p> 259 * 260 * @param value the render mode to set 261 */ 262 public void setScaleRendermode(String value) { 263 264 m_scaler.setRenderMode(CmsStringUtil.getIntValue(value, 0, SCALE_ATTR_RENDERMODE)); 265 } 266 267 /** 268 * Sets the scaling type for the image.<p> 269 * 270 * If no valid integer is given, then "0" is used as value.<p> 271 * 272 * @param value the scaling type for the image to set 273 */ 274 public void setScaleType(String value) { 275 276 m_scaler.setType(CmsStringUtil.getIntValue(value, 0, SCALE_ATTR_TYPE)); 277 } 278 279 /** 280 * Sets the source of the image.<p> 281 * 282 * The source must be an absolute path in the current users OpenCms site, without any 283 * webapp or servlet prefix.<p> 284 * 285 * @param value the image source to set 286 */ 287 public void setSrc(String value) { 288 289 m_src = value; 290 } 291 292 /** 293 * Sets the scaling width for the image.<p> 294 * 295 * If no valid integer is given, then "0" is used as value.<p> 296 * 297 * @param value the scaling width for the image to set 298 */ 299 public void setWidth(String value) { 300 301 m_scaler.setWidth(CmsStringUtil.getIntValueRounded(value, 0, SCALE_ATTR_WIDTH)); 302 } 303}