1 31 32 package org.opencms.scheduler.jobs; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.file.CmsProject; 36 import org.opencms.file.CmsUser; 37 import org.opencms.main.CmsException; 38 import org.opencms.main.CmsLog; 39 import org.opencms.notification.CmsPublishNotification; 40 import org.opencms.report.CmsLogReport; 41 import org.opencms.scheduler.I_CmsScheduledJob; 42 43 import java.text.DateFormat ; 44 import java.util.Date ; 45 import java.util.Map ; 46 47 import org.apache.commons.logging.Log; 48 49 68 public class CmsPublishJob implements I_CmsScheduledJob { 69 70 71 public static final String PARAM_LINKCHECK = "linkcheck"; 72 73 74 public static final String PARAM_UNLOCK = "unlock"; 75 76 77 public static final String PARAM_USER = "mail-to-user"; 78 79 80 private static final Log LOG = CmsLog.getLog(CmsPublishJob.class); 81 82 85 public String launch(CmsObject cms, Map parameters) throws Exception { 86 87 Date jobStart = new Date (); 88 String finishMessage; 89 String unlock = (String )parameters.get(PARAM_UNLOCK); 90 String linkcheck = (String )parameters.get(PARAM_LINKCHECK); 91 CmsProject project = cms.getRequestContext().currentProject(); 92 93 CmsLogReport report = new CmsLogReport(cms.getRequestContext().getLocale(), CmsPublishJob.class); 94 95 try { 96 97 if (Boolean.valueOf(unlock).booleanValue()) { 99 cms.unlockProject(project.getId()); 100 } 101 102 if (Boolean.valueOf(linkcheck).booleanValue()) { 104 cms.validateHtmlLinks(cms.getPublishList(), report); 105 } 106 107 cms.publishProject(report); 109 finishMessage = Messages.get().getBundle().key(Messages.LOG_PUBLISH_FINISHED_1, project.getName()); 110 } catch (CmsException e) { 111 finishMessage = Messages.get().getBundle().key( 113 Messages.LOG_PUBLISH_FAILED_2, 114 project.getName(), 115 e.getMessageContainer().key()); 116 117 report.addError(finishMessage); 119 } finally { 120 121 if (report.hasWarning() || report.hasError()) { 123 try { 124 String userName = (String )parameters.get(PARAM_USER); 125 CmsUser user = cms.readUser(userName); 126 127 CmsPublishNotification notification = new CmsPublishNotification(cms, user, report); 128 129 DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); 130 notification.addMacro("jobStart", df.format(jobStart)); 131 132 notification.send(); 133 } catch (Exception e) { 134 LOG.error(Messages.get().getBundle().key(Messages.LOG_PUBLISH_SEND_NOTIFICATION_FAILED_0), e); 135 } 136 } 137 } 138 139 return finishMessage; 140 } 141 142 } | Popular Tags |