1 17 18 19 20 package org.apache.lenya.cms.scheduler; 21 22 import javax.servlet.http.HttpServletRequest ; 23 24 import org.apache.lenya.util.NamespaceMap; 25 import org.apache.lenya.xml.NamespaceHelper; 26 import org.apache.log4j.Category; 27 import org.quartz.Job; 28 import org.quartz.JobDataMap; 29 import org.quartz.JobDetail; 30 import org.quartz.SchedulerException; 31 import org.w3c.dom.Element ; 32 33 36 public abstract class ServletJob implements Job { 37 38 private static Category log = Category.getInstance(ServletJob.class); 39 40 46 public JobDataMap createJobData(HttpServletRequest request) 47 throws SchedulerException { 48 JobDataMap map = new JobDataMap(); 49 String key = NamespaceMap.getFullName(LoadQuartzServlet.PREFIX, PARAMETER_DOCUMENT_URL); 50 String documentUrl = request.getParameter(key); 51 if (documentUrl == null) { 52 throw new SchedulerException("Document URL must not be null!"); 53 } 54 map.put(key, documentUrl); 55 return map; 56 } 57 58 66 public JobDetail load(Element element, String jobGroup, String servletContextPath) 67 throws SchedulerException { 68 String jobId = element.getAttribute(ATTRIBUTE_ID); 69 JobDetail jobDetail = new JobDetail(jobId, jobGroup, getClass()); 70 return jobDetail; 71 72 } 73 74 public static final String ELEMENT_JOB = "job"; 75 public static final String ATTRIBUTE_ID = "id"; 76 public static final String ATTRIBUTE_CLASS = "class"; 77 public static final String ATTRIBUTE_DOCUMENT_URL = "url"; 78 public static final String ATTRIBUTE_SERVLET_CONTEXT = "servletcontext"; 79 public static final String PARAMETER_DOCUMENT_URL = "document-url"; 80 81 88 public Element save(NamespaceHelper helper, JobDetail jobDetail) throws SchedulerException { 89 log.debug("Saving job"); 90 91 Element jobElement = helper.createElement(ELEMENT_JOB); 92 jobElement.setAttribute(ATTRIBUTE_ID, jobDetail.getName()); 93 jobElement.setAttribute(ATTRIBUTE_CLASS, getClass().getName()); 94 95 String documentUrl = getDocumentUrl(jobDetail); 96 jobElement.setAttribute(ATTRIBUTE_DOCUMENT_URL, documentUrl); 97 98 return jobElement; 99 } 100 101 106 public String getDocumentUrl(JobDetail jobDetail) { 107 JobDataMap map = jobDetail.getJobDataMap(); 108 NamespaceMap wrapper = new NamespaceMap(map, LoadQuartzServlet.PREFIX); 109 String documentUrl = (String ) wrapper.get(PARAMETER_DOCUMENT_URL); 110 return documentUrl; 111 } 112 113 118 public void setDocumentUrl(JobDetail jobDetail, String url) { 119 JobDataMap map = jobDetail.getJobDataMap(); 120 NamespaceMap wrapper = new NamespaceMap(map, LoadQuartzServlet.PREFIX); 121 wrapper.put(PARAMETER_DOCUMENT_URL, url); 122 jobDetail.setJobDataMap(map); 123 } 124 125 } 126 | Popular Tags |