1 31 32 package org.opencms.workplace.tools.scheduler; 33 34 import org.opencms.configuration.CmsSystemConfiguration; 35 import org.opencms.jsp.CmsJspActionElement; 36 import org.opencms.main.CmsContextInfo; 37 import org.opencms.main.OpenCms; 38 import org.opencms.monitor.CmsMemoryMonitor; 39 import org.opencms.notification.CmsContentNotificationJob; 40 import org.opencms.scheduler.CmsScheduledJobInfo; 41 import org.opencms.scheduler.jobs.CmsCreateImageSizeJob; 42 import org.opencms.scheduler.jobs.CmsImageCacheCleanupJob; 43 import org.opencms.scheduler.jobs.CmsPublishJob; 44 import org.opencms.scheduler.jobs.CmsStaticExportJob; 45 import org.opencms.search.CmsSearchManager; 46 import org.opencms.util.CmsStringUtil; 47 import org.opencms.validation.CmsPointerLinkValidator; 48 import org.opencms.widgets.CmsCheckboxWidget; 49 import org.opencms.widgets.CmsComboWidget; 50 import org.opencms.widgets.CmsInputWidget; 51 import org.opencms.widgets.CmsSelectWidgetOption; 52 import org.opencms.widgets.CmsUserWidget; 53 import org.opencms.widgets.CmsVfsFileWidget; 54 import org.opencms.workplace.CmsDialog; 55 import org.opencms.workplace.CmsWidgetDialog; 56 import org.opencms.workplace.CmsWidgetDialogParameter; 57 import org.opencms.workplace.CmsWorkplaceSettings; 58 59 import java.util.ArrayList ; 60 import java.util.Iterator ; 61 import java.util.List ; 62 import java.util.Map ; 63 64 import javax.servlet.http.HttpServletRequest ; 65 import javax.servlet.http.HttpServletResponse ; 66 import javax.servlet.jsp.PageContext ; 67 68 77 public class CmsEditScheduledJobInfoDialog extends CmsWidgetDialog { 78 79 80 public static final String DIALOG_COPYJOB = "copyjob"; 81 82 83 public static final String [] PAGES = {"page1", "page2"}; 84 85 86 public static final String PARAM_JOBID = "jobid"; 87 88 89 private CmsScheduledJobInfo m_jobInfo; 90 91 92 private String m_paramJobid; 93 94 99 public CmsEditScheduledJobInfoDialog(CmsJspActionElement jsp) { 100 101 super(jsp); 102 } 103 104 111 public CmsEditScheduledJobInfoDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { 112 113 this(new CmsJspActionElement(context, req, res)); 114 } 115 116 119 public void actionCommit() { 120 121 List errors = new ArrayList (); 122 123 try { 124 OpenCms.getScheduleManager().scheduleJob(getCms(), m_jobInfo); 126 OpenCms.writeConfiguration(CmsSystemConfiguration.class); 128 Map objects = (Map )getSettings().getListObject(); 130 if (objects != null) { 131 objects.remove(CmsSchedulerList.class.getName()); 132 } 133 } catch (Throwable t) { 134 errors.add(t); 135 } 136 setCommitErrors(errors); 138 } 139 140 145 public String getParamJobid() { 146 147 return m_paramJobid; 148 } 149 150 155 public void setParamJobid(String jobid) { 156 157 m_paramJobid = jobid; 158 } 159 160 168 protected String createDialogHtml(String dialog) { 169 170 StringBuffer result = new StringBuffer (1024); 171 172 result.append(createWidgetTableStart()); 174 175 result.append(createWidgetErrorHeader()); 177 178 if (dialog.equals(PAGES[0])) { 179 result.append(createWidgetBlockStart(key(Messages.GUI_EDITOR_LABEL_JOBSETTINGS_BLOCK_0))); 181 result.append(createDialogRowsHtml(0, 4)); 182 result.append(createWidgetBlockEnd()); 183 result.append(createWidgetBlockStart(key(Messages.GUI_EDITOR_LABEL_CONTEXTINFO_BLOCK_0))); 184 result.append(createDialogRowsHtml(5, 11)); 185 result.append(createWidgetBlockEnd()); 186 } else if (dialog.equals(PAGES[1])) { 187 result.append(createWidgetBlockStart(key(Messages.GUI_EDITOR_LABEL_PARAMETERS_BLOCK_0))); 189 result.append(createDialogRowsHtml(12, 12)); 190 result.append(createWidgetBlockEnd()); 191 } 192 193 result.append(createWidgetTableEnd()); 195 196 return result.toString(); 197 } 198 199 202 protected void defineWidgets() { 203 204 initScheduledJobObject(); 206 207 CmsContextInfo dC = new CmsContextInfo(); 209 210 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "jobName", PAGES[0], new CmsInputWidget())); 212 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "className", PAGES[0], new CmsComboWidget(getComboClasses()))); 213 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "cronExpression", PAGES[0], new CmsComboWidget( 214 getComboCronExpressions()))); 215 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "reuseInstance", PAGES[0], new CmsCheckboxWidget())); 216 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "active", PAGES[0], new CmsCheckboxWidget())); 217 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "contextInfo.userName", PAGES[0], new CmsUserWidget( 218 null, 219 null, 220 null))); 221 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "contextInfo.projectName", PAGES[0], new CmsInputWidget())); 222 addWidget(new CmsWidgetDialogParameter( 223 m_jobInfo, 224 "contextInfo.siteRoot", 225 dC.getSiteRoot(), 226 PAGES[0], 227 new CmsVfsFileWidget(), 228 0, 229 1)); 230 addWidget(new CmsWidgetDialogParameter( 231 m_jobInfo, 232 "contextInfo.requestedUri", 233 dC.getRequestedUri(), 234 PAGES[0], 235 new CmsVfsFileWidget(), 236 0, 237 1)); 238 addWidget(new CmsWidgetDialogParameter( 239 m_jobInfo, 240 "contextInfo.localeName", 241 dC.getLocaleName(), 242 PAGES[0], 243 new CmsInputWidget(), 244 0, 245 1)); 246 addWidget(new CmsWidgetDialogParameter( 247 m_jobInfo, 248 "contextInfo.encoding", 249 dC.getEncoding(), 250 PAGES[0], 251 new CmsInputWidget(), 252 0, 253 1)); 254 addWidget(new CmsWidgetDialogParameter( 255 m_jobInfo, 256 "contextInfo.remoteAddr", 257 dC.getRemoteAddr(), 258 PAGES[0], 259 new CmsInputWidget(), 260 0, 261 1)); 262 263 addWidget(new CmsWidgetDialogParameter(m_jobInfo, "parameters", PAGES[1], new CmsInputWidget())); 265 } 266 267 274 protected List getComboClasses() { 275 276 List result = new ArrayList (); 277 result.add(new CmsSelectWidgetOption( 278 CmsPublishJob.class.getName(), 279 false, 280 null, 281 key(Messages.GUI_EDITOR_CRONCLASS_PUBLISH_0))); 282 result.add(new CmsSelectWidgetOption( 283 CmsStaticExportJob.class.getName(), 284 false, 285 null, 286 key(Messages.GUI_EDITOR_CRONCLASS_STATICEXPORT_0))); 287 result.add(new CmsSelectWidgetOption( 288 CmsPointerLinkValidator.class.getName(), 289 false, 290 null, 291 key(Messages.GUI_EDITOR_CRONCLASS_POINTERVALIDATION_0))); 292 result.add(new CmsSelectWidgetOption( 293 CmsMemoryMonitor.class.getName(), 294 false, 295 null, 296 key(Messages.GUI_EDITOR_CRONCLASS_MEMORYMONITOR_0))); 297 result.add(new CmsSelectWidgetOption( 298 CmsSearchManager.class.getName(), 299 false, 300 null, 301 key(Messages.GUI_EDITOR_CRONCLASS_SEARCHINDEX_0))); 302 result.add(new CmsSelectWidgetOption( 303 CmsContentNotificationJob.class.getName(), 304 false, 305 null, 306 key(Messages.GUI_EDITOR_CRONCLASS_CONTENTNOTIFICATION_0))); 307 result.add(new CmsSelectWidgetOption( 308 CmsCreateImageSizeJob.class.getName(), 309 false, 310 null, 311 key(Messages.GUI_EDITOR_CRONCLASS_IMAGESIZE_0))); 312 result.add(new CmsSelectWidgetOption( 313 CmsImageCacheCleanupJob.class.getName(), 314 false, 315 null, 316 key(Messages.GUI_EDITOR_CRONCLASS_IMAGE_CACHECLEAN_0))); 317 return result; 318 } 319 320 327 protected List getComboCronExpressions() { 328 329 List result = new ArrayList (); 330 331 result.add(new CmsSelectWidgetOption("0 0 3 * * ?", false, null, key(Messages.GUI_EDITOR_CRONJOB_EXAMPLE1_0))); 333 result.add(new CmsSelectWidgetOption("0 0/30 * * * ?", false, null, key(Messages.GUI_EDITOR_CRONJOB_EXAMPLE2_0))); 335 result.add(new CmsSelectWidgetOption("0 30 8 ? * 4", false, null, key(Messages.GUI_EDITOR_CRONJOB_EXAMPLE3_0))); 337 result.add(new CmsSelectWidgetOption("0 15 18 20 * ?", false, null, key(Messages.GUI_EDITOR_CRONJOB_EXAMPLE4_0))); 339 result.add(new CmsSelectWidgetOption( 341 "0 45 15 ? * 1 2005-2006", 342 false, 343 null, 344 key(Messages.GUI_EDITOR_CRONJOB_EXAMPLE5_0))); 345 return result; 346 } 347 348 351 protected String [] getPageArray() { 352 353 return PAGES; 354 } 355 356 359 protected void initMessages() { 360 361 addMessages(Messages.get().getBundleName()); 363 super.initMessages(); 365 } 366 367 377 protected void initScheduledJobObject() { 378 379 Object o; 380 381 boolean setActive = false; 382 383 if (CmsStringUtil.isEmpty(getParamAction()) 384 || CmsDialog.DIALOG_INITIAL.equals(getParamAction()) 385 || DIALOG_COPYJOB.equals(getParamAction())) { 386 if (CmsStringUtil.isNotEmpty(getParamJobid())) { 388 setActive = OpenCms.getScheduleManager().getJob(getParamJobid()).isActive(); 390 o = OpenCms.getScheduleManager().getJob(getParamJobid()).clone(); 391 } else { 392 o = null; 394 } 395 } else { 396 o = getDialogObject(); 398 } 399 400 if (!(o instanceof CmsScheduledJobInfo)) { 401 m_jobInfo = new CmsScheduledJobInfo(); 403 m_jobInfo.setContextInfo(new CmsContextInfo()); 404 } else { 405 m_jobInfo = (CmsScheduledJobInfo)o; 407 } 408 409 if (setActive) { 410 m_jobInfo.setActive(true); 412 } 413 414 if (DIALOG_COPYJOB.equals(getParamAction())) { 415 m_jobInfo.clearId(); 417 } 418 } 419 420 423 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 424 425 super.initWorkplaceRequestValues(settings, request); 427 428 setDialogObject(m_jobInfo); 430 } 431 432 435 protected void validateParamaters() throws Exception { 436 437 if (!isNewJob()) { 438 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParamJobid())) { 440 Iterator it = OpenCms.getScheduleManager().getJobs().iterator(); 442 while (it.hasNext()) { 443 CmsScheduledJobInfo job = (CmsScheduledJobInfo)it.next(); 444 if (job.getId().equals(getParamJobid())) { 445 return; 447 } 448 } 449 } 450 throw new Exception (); 452 } 453 } 454 455 460 private boolean isNewJob() { 461 462 return getCurrentToolPath().equals("/scheduler/new"); 463 } 464 } | Popular Tags |