1 31 32 package org.opencms.workplace.commons; 33 34 import org.opencms.file.CmsResource; 35 import org.opencms.file.CmsResourceFilter; 36 import org.opencms.jsp.CmsJspActionElement; 37 import org.opencms.main.CmsException; 38 import org.opencms.main.CmsLog; 39 import org.opencms.security.CmsPermissionSet; 40 import org.opencms.util.CmsUUID; 41 import org.opencms.workplace.CmsMultiDialog; 42 import org.opencms.workplace.CmsWorkplaceSettings; 43 44 import java.util.Iterator ; 45 46 import javax.servlet.http.HttpServletRequest ; 47 import javax.servlet.http.HttpServletResponse ; 48 import javax.servlet.jsp.JspException ; 49 import javax.servlet.jsp.PageContext ; 50 51 import org.apache.commons.logging.Log; 52 53 68 public class CmsUndoChanges extends CmsMultiDialog { 69 70 71 public static final int ACTION_UNDOCHANGES = 100; 72 73 74 public static final String DIALOG_TYPE = "undochanges"; 75 76 77 public static final String PARAM_RECURSIVE = "recursive"; 78 79 80 private static final Log LOG = CmsLog.getLog(CmsUndoChanges.class); 81 82 private CmsResource m_currentResource; 83 private String m_paramRecursive; 84 85 90 public CmsUndoChanges(CmsJspActionElement jsp) { 91 92 super(jsp); 93 } 94 95 102 public CmsUndoChanges(PageContext context, HttpServletRequest req, HttpServletResponse res) { 103 104 this(new CmsJspActionElement(context, req, res)); 105 } 106 107 112 public void actionUndoChanges() throws JspException { 113 114 getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this); 116 try { 117 if (performDialogOperation()) { 118 actionCloseDialog(); 120 } else { 121 getJsp().include(FILE_DIALOG_SCREEN_WAIT); 123 } 124 } catch (Throwable e) { 125 includeErrorpage(this, e); 127 } 128 } 129 130 135 public String buildDialogOptions() { 136 137 StringBuffer result = new StringBuffer (256); 138 139 if (!isMultiOperation()) { 140 result.append(dialogSpacer()); 141 result.append(key(Messages.GUI_UNDO_LASTMODIFIED_INFO_3, new Object [] { 142 getFileName(), 143 getLastModifiedDate(), 144 getLastModifiedUser()})); 145 } 146 result.append(dialogSpacer()); 147 result.append(key(Messages.GUI_UNDO_CONFIRMATION_0)); 148 if (isOperationOnFolder()) { 149 result.append(dialogSpacer()); 151 result.append("<input type=\"checkbox\" name=\""); 152 result.append(PARAM_RECURSIVE); 153 result.append("\" value=\"true\"> "); 154 if (isMultiOperation()) { 155 result.append(key(Messages.GUI_UNDO_CHANGES_MULTI_SUBRESOURCES_0)); 156 } else { 157 result.append(key(Messages.GUI_UNDO_CHANGES_SUBRESOURCES_0)); 158 } 159 } 160 161 return result.toString(); 162 } 163 164 173 public String getParamRecursive() { 174 175 return m_paramRecursive; 176 } 177 178 183 public void setParamRecursive(String value) { 184 185 m_paramRecursive = value; 186 } 187 188 193 protected CmsResource getCurrentResource() { 194 195 return m_currentResource; 196 } 197 198 203 protected String getFileName() { 204 205 return CmsResource.getName(getParamResource()); 206 } 207 208 213 protected String getLastModifiedDate() { 214 215 long dateLong = getCurrentResource().getDateLastModified(); 216 return getMessages().getDateTime(dateLong); 217 } 218 219 224 protected String getLastModifiedUser() { 225 226 CmsUUID userId = getCurrentResource().getUserLastModified(); 227 try { 228 return getCms().readUser(userId).getName(); 229 } catch (CmsException e) { 230 return ""; 231 } 232 } 233 234 237 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 238 239 fillParamValues(request); 241 242 if (!checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE, false)) { 244 setParamAction(DIALOG_CANCEL); 246 } 247 248 setParamDialogtype(DIALOG_TYPE); 250 if (DIALOG_TYPE.equals(getParamAction())) { 252 setAction(ACTION_UNDOCHANGES); 253 } else if (DIALOG_WAIT.equals(getParamAction())) { 254 setAction(ACTION_WAIT); 255 } else if (DIALOG_CANCEL.equals(getParamAction())) { 256 setAction(ACTION_CANCEL); 257 } else { 258 setAction(ACTION_DEFAULT); 259 setDialogTitle(Messages.GUI_UNDO_CHANGES_1, Messages.GUI_UNDO_CHANGES_MULTI_2); 261 } 262 263 if (! isMultiOperation()) { 264 try { 266 setCurrentResource(getCms().readResource(getParamResource(), CmsResourceFilter.ALL)); 267 } catch (CmsException e) { 268 if (LOG.isInfoEnabled()) { 270 LOG.info(e.getLocalizedMessage()); 271 } 272 } 273 } 274 275 } 276 277 283 protected boolean performDialogOperation() throws CmsException { 284 285 boolean isFolder = isOperationOnFolder(); 287 if ((isMultiOperation() || isFolder) && !DIALOG_WAIT.equals(getParamAction())) { 289 return false; 291 } 292 293 boolean undoRecursive = Boolean.valueOf(getParamRecursive()).booleanValue(); 295 296 Iterator i = getResourceList().iterator(); 297 while (i.hasNext()) { 299 String resName = (String )i.next(); 300 try { 301 checkLock(resName); 303 getCms().undoChanges(resName, undoRecursive); 305 } catch (CmsException e) { 306 if (isMultiOperation()) { 307 addMultiOperationException(e); 309 } else { 310 throw e; 312 } 313 } 314 } 315 checkMultiOperationException(Messages.get(), Messages.ERR_UNDO_CHANGES_MULTI_0); 317 318 return true; 319 } 320 321 326 protected void setCurrentResource(CmsResource res) { 327 328 m_currentResource = res; 329 } 330 331 } 332 | Popular Tags |