1 31 32 package org.opencms.workplace.tools.content; 33 34 import org.opencms.file.CmsProperty; 35 import org.opencms.file.CmsPropertyDefinition; 36 import org.opencms.file.CmsResource; 37 import org.opencms.file.CmsVfsException; 38 import org.opencms.i18n.CmsMessages; 39 import org.opencms.jsp.CmsJspActionElement; 40 import org.opencms.lock.CmsLock; 41 import org.opencms.main.CmsException; 42 import org.opencms.main.OpenCms; 43 import org.opencms.workplace.CmsDialog; 44 import org.opencms.workplace.CmsWorkplaceSettings; 45 46 import java.util.ArrayList ; 47 import java.util.Collections ; 48 import java.util.Iterator ; 49 import java.util.List ; 50 51 import javax.servlet.http.HttpServletRequest ; 52 import javax.servlet.http.HttpServletResponse ; 53 import javax.servlet.jsp.JspException ; 54 import javax.servlet.jsp.PageContext ; 55 56 66 public class CmsPropertyDelete extends CmsDialog { 67 68 69 public static final int ACTION_DELETE_CASCADE = 100; 70 71 72 public static final String DIALOG_DELETE_CASCADE = "deletecascade"; 73 74 75 public static final String DIALOG_TYPE = "propertydelete"; 76 77 78 public static final String PARAM_PROPERTYNAME = "propertyname"; 79 80 private String m_paramPropertyName; 81 82 87 public CmsPropertyDelete(CmsJspActionElement jsp) { 88 89 super(jsp); 90 } 91 92 99 public CmsPropertyDelete(PageContext context, HttpServletRequest req, HttpServletResponse res) { 100 101 this(new CmsJspActionElement(context, req, res)); 102 } 103 104 109 public void actionDelete() throws JspException { 110 111 getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this); 113 try { 114 getCms().deletePropertyDefinition(getParamPropertyName()); 115 actionCloseDialog(); 117 } catch (Throwable e) { 118 includeErrorpage(this, e); 120 } 121 } 122 123 128 public void actionDeleteCascade() throws JspException { 129 130 131 getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this); 133 try { 134 List resourcesWithProperty = getCms().readResourcesWithProperty(getParamPropertyName()); 136 List resourcesLockedByOtherUser = getResourcesLockedByOtherUser(resourcesWithProperty); 138 if (resourcesLockedByOtherUser.isEmpty()) { 140 getCms().getRequestContext().saveSiteRoot(); 142 getCms().getRequestContext().setSiteRoot("/"); 144 try { 145 Iterator i = resourcesWithProperty.iterator(); 146 while (i.hasNext()) { 147 CmsResource resource = (CmsResource)i.next(); 148 CmsProperty property = getCms().readPropertyObject( 150 resource.getRootPath(), 151 getParamPropertyName(), 152 false); 153 if (!property.isNullProperty()) { 157 CmsLock lock = getCms().getLock(resource); 158 if (lock.getType() == CmsLock.TYPE_UNLOCKED) { 159 getCms().lockResource(resource.getRootPath()); 161 } 162 property.setStructureValue(CmsProperty.DELETE_VALUE); 163 property.setResourceValue(CmsProperty.DELETE_VALUE); 164 getCms().writePropertyObject(resource.getRootPath(), property); 166 getCms().unlockResource(resource.getRootPath()); 168 } 169 } 170 getCms().deletePropertyDefinition(getParamPropertyName()); 172 } finally { 173 getCms().getRequestContext().restoreSiteRoot(); 175 actionCloseDialog(); 177 } 178 } else { 179 180 StringBuffer reason = new StringBuffer (); 181 reason.append(dialogWhiteBoxStart()); 182 reason.append(buildResourceList(resourcesLockedByOtherUser, true)); 183 reason.append(dialogWhiteBoxEnd()); 184 throw new CmsVfsException(Messages.get().container( 185 Messages.ERR_DEL_PROP_RESOURCES_LOCKED_1, 186 reason.toString())); 187 } 188 } catch (Throwable e) { 189 includeErrorpage(this, e); 191 } 192 } 193 194 201 public String buildResourceList() throws CmsException { 202 203 List resourcesWithProperty = getCms().readResourcesWithProperty(getParamPropertyName()); 204 205 return buildResourceList(resourcesWithProperty, false); 206 } 207 208 219 public String buildResourceList(List resourceList, boolean lockInfo) throws CmsException { 220 221 Collections.reverse(resourceList); 223 CmsMessages messages = Messages.get().getBundle(getLocale()); 224 StringBuffer result = new StringBuffer (); 225 result.append("<table border=\"0\" width=\"100%\" cellpadding=\"1\" cellspacing=\"1\">\n"); 226 result.append("<tr>\n"); 227 result.append("\t<td style=\"width:5%;\" class=\"textbold\">"); 229 result.append(messages.key(Messages.GUI_INPUT_TYPE_0)); 230 result.append("</td>\n"); 231 result.append("\t<td style=\"width:40%;\" class=\"textbold\">"); 233 result.append(messages.key(Messages.GUI_INPUT_ADRESS_0)); 234 result.append("</td>\n"); 235 result.append("\t<td style=\"width:25%;\" class=\"textbold\">"); 237 result.append(messages.key(Messages.GUI_INPUT_TITLE_0)); 238 result.append("</td>\n"); 239 if (!lockInfo) { 240 result.append("\t<td style=\"width:30%;\" class=\"textbold\">"); 242 result.append(messages.key(Messages.GUI_INPUT_PROPERTYVALUE_0)); 243 result.append("</td>\n"); 244 } 245 if (lockInfo) { 246 result.append("\t<td style=\"width:30%;\" class=\"textbold\">"); 248 result.append(messages.key(Messages.GUI_EXPLORER_LOCKEDBY_0)); 249 result.append("</td>\n"); 250 result.append("</tr>\n"); 251 } 252 result.append("</tr>\n"); 253 result.append("<tr><td colspan=\"4\"><span style=\"height: 6px;\"> </span></td></tr>\n"); 254 255 getCms().getRequestContext().saveSiteRoot(); 256 getCms().getRequestContext().setSiteRoot("/"); 257 try { 258 Iterator i = resourceList.iterator(); 259 while (i.hasNext()) { 260 CmsResource resource = (CmsResource)i.next(); 261 String filetype = OpenCms.getResourceManager().getResourceType(resource.getTypeId()).getTypeName(); 262 result.append("<tr>\n"); 263 result.append("\t<td>"); 265 result.append("<img SRC=\""); 266 result.append(getSkinUri()); 267 result.append("filetypes/"); 268 result.append(filetype); 269 result.append(".gif\">"); 270 result.append("</td>\n"); 271 result.append("\t<td>"); 273 result.append(resource.getRootPath()); 274 result.append("</td>\n"); 275 result.append("\t<td>"); 277 result.append(getJsp().property(CmsPropertyDefinition.PROPERTY_TITLE, resource.getRootPath(), "")); 278 result.append("</td>\n"); 279 if (!lockInfo) { 281 result.append("\t<td>"); 282 result.append(getJsp().property(getParamPropertyName(), resource.getRootPath())); 283 result.append("</td>\n"); 284 } 285 if (lockInfo) { 287 CmsLock lock = getCms().getLock(resource); 288 result.append("\t<td>"); 289 result.append(getCms().readUser(lock.getUserId()).getName()); 290 result.append("</td>\n"); 291 } 292 result.append("</tr>\n"); 293 } 294 result.append("</table>\n"); 295 } finally { 296 getCms().getRequestContext().restoreSiteRoot(); 297 } 298 299 return result.toString(); 300 } 301 302 308 public String buildSelectProperty(String attributes) { 309 310 return CmsPropertyChange.buildSelectProperty(getCms(), Messages.get().getBundle(getLocale()).key( 311 Messages.GUI_PLEASE_SELECT_0), attributes, ""); 312 } 313 314 319 public String getParamPropertyName() { 320 321 return m_paramPropertyName; 322 } 323 324 329 public void setParamPropertyName(String paramPropertyName) { 330 331 m_paramPropertyName = paramPropertyName; 332 } 333 334 337 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 338 339 fillParamValues(request); 341 setParamDialogtype(DIALOG_TYPE); 343 if (DIALOG_OK.equals(getParamAction())) { 345 setAction(ACTION_OK); 346 setParamTitle(Messages.get().getBundle(getLocale()).key(Messages.GUI_TITLE_PROPERTYDELETE_0) + ": " + getParamPropertyName()); 347 } else if (DIALOG_CANCEL.equals(getParamAction())) { 348 setAction(ACTION_CANCEL); 349 } else if (DIALOG_DELETE_CASCADE.equals(getParamAction())) { 350 setAction(ACTION_DELETE_CASCADE); 351 } else { 352 setAction(ACTION_DEFAULT); 353 setParamTitle(Messages.get().getBundle(getLocale()).key(Messages.GUI_TITLE_PROPERTYDELETE_0)); 355 } 356 } 357 358 366 private List getResourcesLockedByOtherUser(List resourceList) throws CmsException { 367 368 List lockedResourcesByOtherUser = new ArrayList (); 369 Iterator i = resourceList.iterator(); 370 while (i.hasNext()) { 371 CmsResource resource = (CmsResource)i.next(); 372 CmsLock lock = getCms().getLock(resource); 374 if (lock.getType() != CmsLock.TYPE_UNLOCKED 376 && !lock.getUserId().equals(getCms().getRequestContext().currentUser().getId())) { 377 lockedResourcesByOtherUser.add(resource); 378 } 379 } 380 381 return lockedResourcesByOtherUser; 382 } 383 } 384 | Popular Tags |