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.security.CmsPermissionSet; 39 import org.opencms.util.CmsStringUtil; 40 import org.opencms.widgets.CmsCalendarWidget; 41 import org.opencms.workplace.CmsMultiDialog; 42 import org.opencms.workplace.CmsWorkplaceSettings; 43 44 import java.text.ParseException ; 45 import java.util.Iterator ; 46 47 import javax.servlet.http.HttpServletRequest ; 48 import javax.servlet.http.HttpServletResponse ; 49 import javax.servlet.jsp.JspException ; 50 import javax.servlet.jsp.PageContext ; 51 52 67 public class CmsTouch extends CmsMultiDialog { 68 69 70 public static final int ACTION_TOUCH = 100; 71 72 73 public static final String DIALOG_TYPE = "touch"; 74 75 76 public static final String PARAM_NEWTIMESTAMP = "newtimestamp"; 77 78 79 public static final String PARAM_RECURSIVE = "recursive"; 80 81 private String m_paramNewtimestamp; 82 private String m_paramRecursive; 83 84 85 public static final String DEFAULT_DATE_STRING = "-"; 86 87 92 public CmsTouch(CmsJspActionElement jsp) { 93 94 super(jsp); 95 } 96 97 104 public CmsTouch(PageContext context, HttpServletRequest req, HttpServletResponse res) { 105 106 this(new CmsJspActionElement(context, req, res)); 107 } 108 109 114 public void actionTouch() throws JspException { 115 116 getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this); 118 try { 119 if (performDialogOperation()) { 120 actionCloseDialog(); 122 } else { 123 getJsp().include(FILE_DIALOG_SCREEN_WAIT); 125 } 126 } catch (Throwable e) { 127 includeErrorpage(this, e); 128 } 129 } 130 131 136 public String buildCheckRecursive() { 137 138 StringBuffer retValue = new StringBuffer (256); 139 140 if (isOperationOnFolder()) { 142 retValue.append("<tr>\n\t<td colspan=\"3\" style=\"white-space: nowrap;\" unselectable=\"on\">"); 143 retValue.append("<input type=\"checkbox\" name=\""); 144 retValue.append(PARAM_RECURSIVE); 145 retValue.append("\" value=\"true\"> "); 146 retValue.append(key(Messages.GUI_TOUCH_MODIFY_SUBRESOURCES_0)); 147 retValue.append("</td>\n</tr>\n"); 148 } 149 return retValue.toString(); 150 } 151 152 159 public String calendarIncludes() { 160 161 return CmsCalendarWidget.calendarIncludes(getLocale()); 162 } 163 164 179 public String calendarInit( 180 String inputFieldId, 181 String triggerButtonId, 182 String align, 183 boolean singleClick, 184 boolean weekNumbers, 185 boolean mondayFirst, 186 String dateStatusFunc, 187 boolean showTime) { 188 189 return CmsCalendarWidget.calendarInit( 190 getMessages(), 191 inputFieldId, 192 triggerButtonId, 193 align, 194 singleClick, 195 weekNumbers, 196 mondayFirst, 197 dateStatusFunc, 198 showTime); 199 } 200 201 206 public String getCurrentDateTime() { 207 208 return CmsCalendarWidget.getCalendarLocalizedTime(getLocale(), getMessages(), System.currentTimeMillis()); 210 } 211 212 220 public String getParamNewtimestamp() { 221 222 return m_paramNewtimestamp; 223 } 224 225 234 public String getParamRecursive() { 235 236 return m_paramRecursive; 237 } 238 239 244 public void setParamNewtimestamp(String value) { 245 246 m_paramNewtimestamp = value; 247 } 248 249 254 public void setParamRecursive(String value) { 255 256 m_paramRecursive = value; 257 } 258 259 262 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 263 264 fillParamValues(request); 266 267 if (! checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE, false)) { 269 setParamAction(DIALOG_CANCEL); 271 } 272 273 setParamDialogtype(DIALOG_TYPE); 275 276 if (DIALOG_TYPE.equals(getParamAction())) { 278 setAction(ACTION_TOUCH); 279 } else if (DIALOG_WAIT.equals(getParamAction())) { 280 setAction(ACTION_WAIT); 281 } else if (DIALOG_CANCEL.equals(getParamAction())) { 282 setAction(ACTION_CANCEL); 283 } else { 284 setAction(ACTION_DEFAULT); 285 setDialogTitle(Messages.GUI_TOUCH_RESOURCE_1, Messages.GUI_TOUCH_MULTI_2); 287 } 288 } 289 290 296 protected boolean performDialogOperation() throws CmsException { 297 298 if (!DIALOG_WAIT.equals(getParamAction())) { 300 if (isMultiOperation()) { 302 return false; 304 } else { 305 CmsResource sourceRes = getCms().readResource(getParamResource(), CmsResourceFilter.ALL); 307 if (sourceRes.isFolder()) { 308 return false; 309 } 310 } 311 } 312 313 long timeStamp = 0; 315 boolean correctDate = false; 316 try { 317 if (CmsStringUtil.isNotEmpty(getParamNewtimestamp())) { 318 timeStamp = CmsCalendarWidget.getCalendarDate(getMessages(), getParamNewtimestamp(), true); 319 correctDate = true; 320 } 321 } catch (ParseException e) { 322 throw new CmsException(Messages.get().container(Messages.ERR_PARSE_TIMESTAMP_1, getParamNewtimestamp()), e); 323 } 324 325 boolean touchRecursive = Boolean.valueOf(getParamRecursive()).booleanValue(); 327 328 Iterator i = getResourceList().iterator(); 330 while (i.hasNext()) { 331 String resName = (String )i.next(); 332 try { 333 touchSingleResource(resName, timeStamp, touchRecursive, correctDate); 334 } catch (CmsException e) { 335 addMultiOperationException(e); 337 } 338 } 339 checkMultiOperationException(Messages.get(), Messages.ERR_TOUCH_MULTI_0); 340 341 return true; 342 } 343 344 353 protected void touchSingleResource(String resourceName, long timeStamp, boolean recursive, boolean correctDate) throws CmsException { 354 355 checkLock(resourceName); 357 CmsResource sourceRes = getCms().readResource(resourceName, CmsResourceFilter.ALL); 358 if (! correctDate) { 359 timeStamp = sourceRes.getDateLastModified(); 361 } 362 getCms().setDateLastModified(resourceName, timeStamp, recursive); 363 } 364 } 365 | Popular Tags |