1 31 32 package org.opencms.workplace.commons; 33 34 import com.alkacon.simapi.Simapi; 35 36 import org.opencms.file.CmsProperty; 37 import org.opencms.file.CmsPropertyDefinition; 38 import org.opencms.file.CmsResource; 39 import org.opencms.file.CmsResourceFilter; 40 import org.opencms.file.types.CmsResourceTypeImage; 41 import org.opencms.i18n.CmsEncoder; 42 import org.opencms.jsp.CmsJspActionElement; 43 import org.opencms.loader.CmsImageScaler; 44 import org.opencms.main.CmsException; 45 import org.opencms.main.CmsLog; 46 import org.opencms.main.OpenCms; 47 import org.opencms.security.CmsPermissionSet; 48 import org.opencms.util.CmsStringUtil; 49 import org.opencms.workplace.CmsDialog; 50 import org.opencms.workplace.CmsWorkplaceSettings; 51 52 import java.awt.Color ; 53 import java.util.ArrayList ; 54 import java.util.Iterator ; 55 import java.util.List ; 56 57 import javax.servlet.http.HttpServletRequest ; 58 import javax.servlet.http.HttpServletResponse ; 59 import javax.servlet.jsp.JspException ; 60 import javax.servlet.jsp.PageContext ; 61 62 import org.apache.commons.logging.Log; 63 64 79 public class CmsCommentImages extends CmsDialog { 80 81 82 public static final int ACTION_COMMENTIMAGES = 100; 83 84 85 public static final String DIALOG_TYPE = "commentimages"; 86 87 88 public static final String PREFIX_DESCRIPTION = "desc_"; 89 90 91 public static final String PREFIX_TITLE = "title_"; 92 93 94 public static final int THUMB_HEIGHT = 150; 95 96 97 public static final int THUMB_WIDTH = 200; 98 99 100 private static final Log LOG = CmsLog.getLog(CmsCommentImages.class); 101 102 103 private CmsImageScaler m_imageScaler; 104 105 110 public CmsCommentImages(CmsJspActionElement jsp) { 111 112 super(jsp); 113 } 114 115 122 public CmsCommentImages(PageContext context, HttpServletRequest req, HttpServletResponse res) { 123 124 this(new CmsJspActionElement(context, req, res)); 125 } 126 127 132 public void actionCommentImages() throws JspException { 133 134 getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this); 136 try { 137 performDialogOperation(); 138 actionCloseDialog(); 140 } catch (Throwable e) { 141 includeErrorpage(this, e); 143 } 144 } 145 146 151 public String buildDialogForm() { 152 153 StringBuffer result = new StringBuffer (16384); 154 Iterator i = getImages().iterator(); 155 156 result.append("<div style=\"height: 450px; padding: 4px; overflow: auto;\">"); 157 158 while (i.hasNext()) { 159 CmsResource res = (CmsResource)i.next(); 160 String imageName = res.getName(); 161 String propertySuffix = "" + imageName.hashCode(); 162 result.append(dialogBlockStart(imageName)); 163 result.append("<table border=\"0\">\n"); 164 result.append("<tr>\n\t<td style=\"vertical-align: top;\">"); 165 result.append("<img SRC=\""); 167 StringBuffer link = new StringBuffer (256); 168 link.append(getCms().getSitePath(res)); 169 link.append(getImageScaler().toRequestParam()); 170 result.append(getJsp().link(link.toString())); 171 result.append("\" border=\"0\" alt=\"\" width=\""); 172 result.append(getImageScaler().getWidth()); 173 result.append("\" height=\""); 174 result.append(getImageScaler().getHeight()); 175 result.append("\">"); 176 177 result.append("</td>\n"); 178 result.append("\t<td class=\"maxwidth\" style=\"vertical-align: top;\">\n"); 179 180 result.append("\t\t<table border=\"0\">\n"); 181 182 String title = ""; 184 try { 185 title = getCms().readPropertyObject(res, CmsPropertyDefinition.PROPERTY_TITLE, false).getValue(); 186 } catch (CmsException e) { 187 if (LOG.isErrorEnabled()) { 189 LOG.error(e.getLocalizedMessage(getLocale())); 190 } 191 } 192 result.append("\t\t<tr>\n\t\t\t<td style=\"white-space: nowrap;\" unselectable=\"on\">"); 193 result.append(key(Messages.GUI_LABEL_TITLE_0)); 194 result.append(":</td>\n\t\t\t<td class=\"maxwidth\">"); 195 result.append("<input type=\"text\" class=\"maxwidth\" name=\""); 196 result.append(PREFIX_TITLE); 197 result.append(propertySuffix); 198 result.append("\" value=\""); 199 if (CmsStringUtil.isNotEmpty(title)) { 200 result.append(CmsEncoder.escapeXml(title)); 201 } 202 result.append("\">"); 203 result.append("</td>\n\t\t</tr>\n"); 204 205 String description = ""; 207 try { 208 description = getCms().readPropertyObject(res, CmsPropertyDefinition.PROPERTY_DESCRIPTION, false).getValue(); 209 } catch (CmsException e) { 210 if (LOG.isErrorEnabled()) { 212 LOG.error(e.getLocalizedMessage(getLocale())); 213 } 214 } 215 result.append("\t\t<tr>\n\t\t\t<td style=\"white-space: nowrap; vertical-align: top;\" unselectable=\"on\">"); 216 result.append(key(Messages.GUI_LABEL_DESCRIPTION_0)); 217 result.append(":</td>\n\t\t\t<td style=\"vertical-align: top; height: 110px;\">"); 218 result.append("<textarea rows=\"8\" class=\"maxwidth\" style=\"overflow: auto;\" name=\""); 219 result.append(PREFIX_DESCRIPTION); 220 result.append(propertySuffix); 221 result.append("\">"); 222 if (CmsStringUtil.isNotEmpty(description)) { 223 result.append(CmsEncoder.escapeXml(description)); 224 } 225 result.append("</textarea>"); 226 result.append("</td>\n\t\t</tr>\n"); 227 228 result.append("\t\t</table>\n"); 229 230 result.append("</td>\n</tr>\n"); 231 result.append("</table>\n"); 232 result.append(dialogBlockEnd()); 233 234 if (i.hasNext()) { 235 result.append(dialogSpacer()); 237 } 238 } 239 240 result.append("</div>"); 241 242 return result.toString(); 243 } 244 245 250 protected List getImages() { 251 252 CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION.addRequireType(CmsResourceTypeImage.getStaticTypeId()); 254 try { 255 return getCms().readResources(getParamResource(), filter, false); 256 } catch (CmsException e) { 257 if (LOG.isErrorEnabled()) { 259 LOG.error(e.getLocalizedMessage(getLocale())); 260 } 261 return new ArrayList (0); 262 } 263 } 264 265 270 protected CmsImageScaler getImageScaler() { 271 272 if (m_imageScaler == null) { 273 m_imageScaler = new CmsImageScaler(); 275 m_imageScaler.setWidth(THUMB_WIDTH); 276 m_imageScaler.setHeight(THUMB_HEIGHT); 277 m_imageScaler.setRenderMode(Simapi.RENDER_SPEED); 278 m_imageScaler.setColor(new Color (0, 0, 0)); 279 m_imageScaler.setType(1); 280 } 281 return m_imageScaler; 282 } 283 284 287 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 288 289 fillParamValues(request); 291 292 if (!checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE, false)) { 294 setParamAction(DIALOG_CANCEL); 296 } 297 298 setParamDialogtype(DIALOG_TYPE); 300 if (DIALOG_TYPE.equals(getParamAction())) { 302 setAction(ACTION_COMMENTIMAGES); 303 } else if (DIALOG_CANCEL.equals(getParamAction())) { 304 setAction(ACTION_CANCEL); 305 } else { 306 setAction(ACTION_DEFAULT); 307 Object [] args = new Object [] {getParamResource()}; 309 setParamTitle(key(Messages.GUI_COMMENTIMAGES_TITLE_1, args)); 310 } 311 } 312 313 319 protected boolean performDialogOperation() throws CmsException { 320 321 checkLock(getParamResource()); 323 324 Iterator i = getImages().iterator(); 325 while (i.hasNext()) { 327 CmsResource res = (CmsResource)i.next(); 328 String imageName = res.getName(); 329 String propertySuffix = "" + imageName.hashCode(); 330 331 CmsProperty titleProperty = getCms().readPropertyObject(res, CmsPropertyDefinition.PROPERTY_TITLE, false); 333 String newValue = getJsp().getRequest().getParameter(PREFIX_TITLE + propertySuffix); 334 writeProperty(res, CmsPropertyDefinition.PROPERTY_TITLE, newValue, titleProperty); 335 336 CmsProperty descProperty = getCms().readPropertyObject( 338 res, 339 CmsPropertyDefinition.PROPERTY_DESCRIPTION, 340 false); 341 newValue = getJsp().getRequest().getParameter(PREFIX_DESCRIPTION + propertySuffix); 342 writeProperty(res, CmsPropertyDefinition.PROPERTY_DESCRIPTION, newValue, descProperty); 343 } 344 345 return true; 346 } 347 348 357 protected void writeProperty(CmsResource res, String propName, String propValue, CmsProperty currentProperty) 358 throws CmsException { 359 360 if (currentProperty.isNullProperty()) { 362 currentProperty = new CmsProperty(); 364 currentProperty.setName(propName); 365 } 366 367 if (CmsStringUtil.isEmptyOrWhitespaceOnly(propValue)) { 368 boolean writeProperty = false; 370 if (currentProperty.getStructureValue() != null) { 371 currentProperty.setStructureValue(CmsProperty.DELETE_VALUE); 372 currentProperty.setResourceValue(null); 373 writeProperty = true; 374 } else if (currentProperty.getResourceValue() != null) { 375 currentProperty.setResourceValue(CmsProperty.DELETE_VALUE); 376 currentProperty.setStructureValue(null); 377 writeProperty = true; 378 } 379 if (writeProperty) { 380 getCms().writePropertyObject(getCms().getSitePath(res), currentProperty); 382 } 383 } else { 384 if (!propValue.equals(currentProperty.getValue())) { 386 if (currentProperty.getStructureValue() == null && currentProperty.getResourceValue() == null) { 387 if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) { 389 currentProperty.setStructureValue(propValue); 390 currentProperty.setResourceValue(null); 391 } else { 392 currentProperty.setResourceValue(propValue); 393 currentProperty.setStructureValue(null); 394 } 395 } else if (currentProperty.getStructureValue() != null) { 396 currentProperty.setStructureValue(propValue); 398 currentProperty.setResourceValue(null); 399 } else { 400 currentProperty.setResourceValue(propValue); 402 currentProperty.setStructureValue(null); 403 } 404 getCms().writePropertyObject(getCms().getSitePath(res), currentProperty); 406 } 407 } 408 } 409 410 } 411 | Popular Tags |