You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by so...@apache.org on 2008/01/31 08:44:36 UTC

svn commit: r617035 [12/22] - in /lenya/branches/revolution/1.3.x: ./ src/java/org/apache/lenya/ac/ src/java/org/apache/lenya/ac/cache/ src/java/org/apache/lenya/ac/cifs/ src/java/org/apache/lenya/ac/file/ src/java/org/apache/lenya/ac/impl/ src/java/or...

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/scheduler/LoadQuartzServlet.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/scheduler/LoadQuartzServlet.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/scheduler/LoadQuartzServlet.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/scheduler/LoadQuartzServlet.java Wed Jan 30 23:44:03 2008
@@ -14,11 +14,8 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.cms.scheduler;
-
 import java.io.File;
 import java.io.FileFilter;
 import java.io.IOException;
@@ -31,14 +28,12 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-
 import org.apache.lenya.cms.publication.DocumentBuildException;
 import org.apache.lenya.cms.publication.Publication;
 import org.apache.lenya.cms.publication.PublicationException;
@@ -47,368 +42,334 @@
 import org.apache.lenya.cms.scheduler.xml.TriggerHelper;
 import org.apache.lenya.util.NamespaceMap;
 import org.apache.lenya.xml.DocumentHelper;
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
 import org.quartz.SchedulerException;
 import org.w3c.dom.Document;
-
 /**
  * A simple servlet that starts an instance of a Quartz scheduler.
  */
 public class LoadQuartzServlet extends HttpServlet {
-    private static Category log = Category.getInstance(LoadQuartzServlet.class);
-    private static SchedulerWrapper scheduler = null;
-    private ServletContext servletContext;
-    private String schedulerConfigurations;
-
-    public static final String PREFIX = "scheduler";
-    public static final String PARAMETER_ACTION = "action";
-    public static final String PARAMETER_PUBLICATION_ID = "publication-id";
-    public static final String PARAMETER_DOCUMENT_URL = "document-url";
-    public static final String CONFIGURATION_ELEMENT = "scheduler-configurations";
-
-    /**
-     * Returns the scheduler wrapper.
-     * @return A scheduler wrapper.
-     */
-    public static SchedulerWrapper getScheduler() {
-        return scheduler;
-    }
-
-    /**
-     * Maps servlet context names to servlets.
-     */
-    private static Map servlets = new HashMap();
-
-    /**
-     * Initializes the servlet.
-     * @param config The servlet configuration.
-     * @throws ServletException when something went wrong.
-     */
-    public void init(ServletConfig config) throws ServletException {
-        super.init(config);
-
-        this.schedulerConfigurations = config.getInitParameter(CONFIGURATION_ELEMENT);
-        this.servletContext = config.getServletContext();
-        
-        log.debug(
-            ".init(): Servlet Context Path: " + getServletContextDirectory().getAbsolutePath());
-            
-        try {
-            log.debug("Storing servlet");
-            String contextPath = getServletContextDirectory().getCanonicalPath();
-            log.debug("  Context path: [" + contextPath + "]");
-            servlets.put(contextPath, this);
-        } catch (IOException e) {
-            throw new ServletException(e);
-        }
-            
-        log.debug(".init(): Scheduler Configurations: " + this.schedulerConfigurations);
-
-        try {
-            log.info("Working?...");
-            process();
-            log.info("OK");
-        } catch (Exception e) {
-            log.error("Init of LoadQuartzServlet failed", e);
-            throw new ServletException(e);
-        }
-    }
-
-    /**
-     * Process.
-     *
-     * @throws ServletException when an error occurs.
-     * @throws SchedulerException when an error occurs.
-     */
-    public void process() throws ServletException, SchedulerException {
-        scheduler =
-            new SchedulerWrapper(
-                getServletContextDirectory().getAbsolutePath(),
-                schedulerConfigurations);
-
-        try {
-            ShutdownHook();
-        } catch (Exception e) {
-            log.error(e.toString(), e);
-        }
-
-        restoreJobs();
-    }
-
-    /**
-     * Shuts down the scheduler.
-     */
-    public void destroy() {
-        destroyScheduler();
-    }
-
-    /**
-     * Shuts down the scheduler.
-     */
-    public static void destroyScheduler() {
-        log.debug("destroy: ");
-        getScheduler().shutdown();
-    }
-
-    /**
-     * This method sets a ShutdownHook to the system This traps the CTRL+C or kill signal and
-     * shutdows  Correctly the system.
-     *
-     * @throws Exception when something went wrong.
-     */
-    public static void ShutdownHook() throws Exception {
-        log.debug("-------------------- ShutdownHook --------------------");
-        Runtime.getRuntime().addShutdownHook(new Thread() {
-            public void run() {
-                LoadQuartzServlet.destroyScheduler();
-            }
-        });
-        log.debug("-------------------- End ShutdownHook --------------------");
-    }
-
-    /**
-     * Handles a GET request.
-     * @param request The request.
-     * @param response The response.
-     * @throws IOException when an error occured.
-     * @throws ServletException when an error occured.
-     */
-    public void doGet(HttpServletRequest request, HttpServletResponse response)
-        throws IOException, ServletException {
-        handleRequest(request, response);
-    }
-
-    /**
-     * Handles a POST request.
-     *
-     * @param req The requust.
-     * @param resp The response.
-     *
-     * @throws ServletException when an error occured.
-     * @throws IOException when an error occured.
-     */
-    public void doPost(HttpServletRequest req, HttpServletResponse resp)
-        throws ServletException, IOException {
-        doGet(req, resp);
-    }
-
-    protected static final String ADD = "add";
-    protected static final String MODIFY = "modify";
-    protected static final String DELETE = "delete";
-    protected static final String DOCUMENT_DELETED = "document-deleted";
-
-    /**
-     * Handles a servlet request.
-     * @param request The request.
-     * @param response The response.
-     * @throws IOException when something went wrong.
-     */
-    protected void handleRequest(HttpServletRequest request, HttpServletResponse response)
-        throws IOException {
-        log.debug("----------------------------------------------------------------");
-        log.debug("- Incoming request at URI: ");
-        log.debug(
-            request.getServerName() + ":" + request.getServerPort() + request.getRequestURI());
-        log.debug("----------------------------------------------------------------");
-        log.debug("Request parameters:");
-
-        NamespaceMap schedulerParameters = getSchedulerParameters(request);
-
-        try {
-            String publicationId = (String) schedulerParameters.get(PARAMETER_PUBLICATION_ID);
-            log.debug("Scheduler invoked.");
-
-            log.debug("Scheduler Parameters:");
-            log.debug("    scheduler.publication-id: [" + publicationId + "]");
-
-            logSessionAttributes(request);
-
-            // check if the request wants to submit, modify or delete a job.
-            String action = (String) schedulerParameters.get(PARAMETER_ACTION);
-            log.debug("    scheduler.action:         [" + action + "]");
-            if (action == null) {
-            } else if (action.equals(ADD)) {
-                Date startTime = TriggerHelper.getDate(schedulerParameters);
-                getScheduler().addJob(publicationId, startTime, request);
-            } else if (action.equals(MODIFY)) {
-                Date startTime = TriggerHelper.getDate(schedulerParameters);
-                String jobId = getJobId(schedulerParameters);
-                getScheduler().modifyJob(jobId, publicationId, startTime);
-            } else if (action.equals(DELETE)) {
-                String jobId = getJobId(schedulerParameters);
-                getScheduler().deleteJob(jobId, publicationId);
-            } else if (action.equals(DOCUMENT_DELETED)) {
-
-                Publication publication =
-                    PublicationFactory.getPublication(
-                        publicationId,
-                        getServletContextDirectory().getAbsolutePath());
-
-                String documentUrl = (String) schedulerParameters.get(PARAMETER_DOCUMENT_URL);
-                org.apache.lenya.cms.publication.Document document =
-                    publication.getDocumentBuilder().buildDocument(publication, documentUrl);
-                deleteDocumentJobs(document);
-            }
-
-            // handle the remainder of the request by simply returning all
-            // scheduled jobs (for the given publication ID).
-            PrintWriter writer = response.getWriter();
-            response.setContentType("text/xml");
-
-            Document snapshot = getScheduler().getSnapshot();
-
-            DocumentHelper.writeDocument(snapshot, writer);
-        } catch (Exception e) {
-            log.error("Can't create job snapshot: ", e);
-            throw new IOException(e.getMessage() + " (view log for details)");
-        }
-    }
-
-    /**
-     * Extracts the scheduler parameters from a request.
-     * @param request The request.
-     * @return A namespace map.
-     */
-    public static NamespaceMap getSchedulerParameters(HttpServletRequest request) {
-        Map parameterMap = new HashMap();
-        List keys = new ArrayList();
-        for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
-            String key = (String) e.nextElement();
-            keys.add(key);
-        }
-        Collections.sort(keys);
-        for (Iterator i = keys.iterator(); i.hasNext();) {
-            String key = (String) i.next();
-            String[] values = request.getParameterValues(key);
-            log.debug("    [" + key + "] = [" + values[0] + "]");
-            if (values.length == 1) {
-                parameterMap.put(key, values[0]);
-            } else {
-                parameterMap.put(key, values);
-            }
-        }
-        
-        NamespaceMap schedulerParameters = new NamespaceMap(parameterMap, PREFIX);
-        return schedulerParameters;
-    }
-
-    /**
-     * Deletes
-     * @param document
-     * @throws DocumentBuildException
-     * @throws SchedulerException
-     * @throws PublicationException
-     */
-    public void deleteDocumentJobs(org.apache.lenya.cms.publication.Document document)
-        throws DocumentBuildException, SchedulerException, PublicationException {
-        log.debug("Requested to delete jobs for document URL [" + document.getCompleteURL() + "]");
-        getScheduler().deleteJobs(document);
-    }
-
-    /**
-     * Extracts the job ID from the scheduler parameters.
-     * @param schedulerParameters A namespace map.
-     * @return A string.
-     */
-    protected String getJobId(NamespaceMap schedulerParameters) {
-        String parameterName =
-            NamespaceMap.getFullName(SchedulerWrapper.JOB_PREFIX, SchedulerWrapper.JOB_ID);
-        String jobId = (String) schedulerParameters.get(parameterName);
-        log.debug("    scheduler.job.id:         [" + jobId + "]");
-        return jobId;
-    }
-
-    /**
-     * Logs the session attributes of a request.
-     * @param request The request.
-     */
-    protected void logSessionAttributes(HttpServletRequest request) {
-        log.debug("-------------------- Session Attributes --------------------");
-        for (Enumeration e = request.getSession().getAttributeNames(); e.hasMoreElements();) {
-            String name = (String) e.nextElement();
-            log.debug(name + " = " + request.getSession().getAttribute(name));
-        }
-        log.debug("-------------------- End Session Attributes --------------------");
-    }
-
-    /**
-     * Returns the servlet context path.
-     *
-     * @return A string.
-     */
-    public File getServletContextDirectory() {
-        return new File(this.servletContext.getRealPath("/"));
-    }
-
-    /**
-     * Restores the jobs.
-     * @throws SchedulerException when something went wrong.
-     */
-    public void restoreJobs() throws SchedulerException {
-
-        File publicationsDirectory =
-            new File(getServletContextDirectory(), PublishingEnvironment.PUBLICATION_PREFIX);
-
-        File[] publicationDirectories = publicationsDirectory.listFiles(new FileFilter() {
-            public boolean accept(File file) {
-                return file.isDirectory();
-            }
-        });
-
-        log.debug("=========================================");
-        log.debug("  Restoring jobs.");
-        log.debug("    servlet context: [" + getServletContextDirectory() + "]");
-        log.debug("    publications directory: [" + publicationsDirectory + "]");
-        log.debug("=========================================");
-
-        for (int i = 0; i < publicationDirectories.length; i++) {
-            File directory = publicationDirectories[i];
-            String publicationId = directory.getName();
-            if (PublicationFactory
-                .existsPublication(publicationId, getServletContextDirectory().getAbsolutePath())) {
-                getScheduler().restoreJobs(publicationId);
-            }
-        }
-    }
-
-    public static final String SERVLET_URL = "/servlet/QuartzSchedulerServlet";
-
-    /**
-     * Returns the servlet for a certain canonical servlet context path.
-     * @param contextPath The canonical servlet context path.
-     * @return A LoadQuartzServlet.
-     */
-    public static LoadQuartzServlet getServlet(String contextPath) {
-        return (LoadQuartzServlet) servlets.get(contextPath);
-    }
-
-    /**
-     * Generates the request URI needed to delete the jobs for a certain document.
-     * @param document The document.
-     * @return A string.
-     */
-    public static String getDeleteDocumentRequestURI(
-        String port,
-        String servletContextPath,
-        org.apache.lenya.cms.publication.Document document) {
-
-        NamespaceMap requestParameters = new NamespaceMap(PREFIX);
-        requestParameters.put(PARAMETER_ACTION, DOCUMENT_DELETED);
-        requestParameters.put(PARAMETER_PUBLICATION_ID, document.getPublication().getId());
-        requestParameters.put(PARAMETER_DOCUMENT_URL, document.getCompleteURL());
-
-        String requestUri = "http://127.0.0.1:" + port + servletContextPath + "?";
-        Map map = requestParameters.getMap();
-
-        String[] keys = (String[]) map.keySet().toArray(new String[map.keySet().size()]);
-        for (int i = 0; i < keys.length; i++) {
-            if (i > 0) {
-                requestUri += "&";
-            }
-            String value = (String) map.get(keys[i]);
-            requestUri += keys[i] + "=" + value;
-        }
-
-        return requestUri;
-    }
+   private static final long serialVersionUID = 1L;
+   private static Logger log = Logger.getLogger(LoadQuartzServlet.class);
+   private static SchedulerWrapper scheduler = null;
+   private ServletContext servletContext;
+   private String schedulerConfigurations;
+   public static final String PREFIX = "scheduler";
+   public static final String PARAMETER_ACTION = "action";
+   public static final String PARAMETER_PUBLICATION_ID = "publication-id";
+   public static final String PARAMETER_DOCUMENT_URL = "document-url";
+   public static final String CONFIGURATION_ELEMENT = "scheduler-configurations";
+   /**
+    * Returns the scheduler wrapper.
+    * 
+    * @return A scheduler wrapper.
+    */
+   public static SchedulerWrapper getScheduler() {
+      return scheduler;
+   }
+   /**
+    * Maps servlet context names to servlets.
+    */
+   private static Map servlets = new HashMap();
+   /**
+    * Initializes the servlet.
+    * 
+    * @param config
+    *           The servlet configuration.
+    * @throws ServletException
+    *            when something went wrong.
+    */
+   public void init(ServletConfig config) throws ServletException {
+      super.init(config);
+      this.schedulerConfigurations = config.getInitParameter(CONFIGURATION_ELEMENT);
+      this.servletContext = config.getServletContext();
+      log.debug(".init(): Servlet Context Path: " + getServletContextDirectory().getAbsolutePath());
+      try{
+         log.debug("Storing servlet");
+         String contextPath = getServletContextDirectory().getCanonicalPath();
+         log.debug("  Context path: [" + contextPath + "]");
+         servlets.put(contextPath, this);
+      }catch(IOException e){
+         throw new ServletException(e);
+      }
+      log.debug(".init(): Scheduler Configurations: " + this.schedulerConfigurations);
+      try{
+         log.info("Working?...");
+         process();
+         log.info("OK");
+      }catch(Exception e){
+         log.error("Init of LoadQuartzServlet failed", e);
+         throw new ServletException(e);
+      }
+   }
+   /**
+    * Process.
+    * 
+    * @throws ServletException
+    *            when an error occurs.
+    * @throws SchedulerException
+    *            when an error occurs.
+    */
+   public void process() throws ServletException, SchedulerException {
+      scheduler = new SchedulerWrapper(getServletContextDirectory().getAbsolutePath(), schedulerConfigurations);
+      try{
+         ShutdownHook();
+      }catch(Exception e){
+         log.error(e.toString(), e);
+      }
+      restoreJobs();
+   }
+   /**
+    * Shuts down the scheduler.
+    */
+   public void destroy() {
+      destroyScheduler();
+   }
+   /**
+    * Shuts down the scheduler.
+    */
+   public static void destroyScheduler() {
+      log.debug("destroy: ");
+      getScheduler().shutdown();
+   }
+   /**
+    * This method sets a ShutdownHook to the system This traps the CTRL+C or kill signal and shutdows Correctly the system.
+    * 
+    * @throws Exception
+    *            when something went wrong.
+    */
+   public static void ShutdownHook() throws Exception {
+      log.debug("-------------------- ShutdownHook --------------------");
+      Runtime.getRuntime().addShutdownHook(new Thread() {
+         public void run() {
+            LoadQuartzServlet.destroyScheduler();
+         }
+      });
+      log.debug("-------------------- End ShutdownHook --------------------");
+   }
+   /**
+    * Handles a GET request.
+    * 
+    * @param request
+    *           The request.
+    * @param response
+    *           The response.
+    * @throws IOException
+    *            when an error occured.
+    * @throws ServletException
+    *            when an error occured.
+    */
+   public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
+      handleRequest(request, response);
+   }
+   /**
+    * Handles a POST request.
+    * 
+    * @param req
+    *           The requust.
+    * @param resp
+    *           The response.
+    * 
+    * @throws ServletException
+    *            when an error occured.
+    * @throws IOException
+    *            when an error occured.
+    */
+   public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+      doGet(req, resp);
+   }
+   protected static final String ADD = "add";
+   protected static final String MODIFY = "modify";
+   protected static final String DELETE = "delete";
+   protected static final String DOCUMENT_DELETED = "document-deleted";
+   /**
+    * Handles a servlet request.
+    * 
+    * @param request
+    *           The request.
+    * @param response
+    *           The response.
+    * @throws IOException
+    *            when something went wrong.
+    */
+   protected void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
+      log.debug("----------------------------------------------------------------");
+      log.debug("- Incoming request at URI: ");
+      log.debug(request.getServerName() + ":" + request.getServerPort() + request.getRequestURI());
+      log.debug("----------------------------------------------------------------");
+      log.debug("Request parameters:");
+      NamespaceMap schedulerParameters = getSchedulerParameters(request);
+      try{
+         String publicationId = (String) schedulerParameters.get(PARAMETER_PUBLICATION_ID);
+         log.debug("Scheduler invoked.");
+         log.debug("Scheduler Parameters:");
+         log.debug("    scheduler.publication-id: [" + publicationId + "]");
+         logSessionAttributes(request);
+         // check if the request wants to submit, modify or delete a job.
+         String action = (String) schedulerParameters.get(PARAMETER_ACTION);
+         log.debug("    scheduler.action:         [" + action + "]");
+         if(action == null){
+         }else if(action.equals(ADD)){
+            Date startTime = TriggerHelper.getDate(schedulerParameters);
+            getScheduler().addJob(publicationId, startTime, request);
+         }else if(action.equals(MODIFY)){
+            Date startTime = TriggerHelper.getDate(schedulerParameters);
+            String jobId = getJobId(schedulerParameters);
+            getScheduler().modifyJob(jobId, publicationId, startTime);
+         }else if(action.equals(DELETE)){
+            String jobId = getJobId(schedulerParameters);
+            getScheduler().deleteJob(jobId, publicationId);
+         }else if(action.equals(DOCUMENT_DELETED)){
+            Publication publication = PublicationFactory.getPublication(publicationId, getServletContextDirectory().getAbsolutePath());
+            String documentUrl = (String) schedulerParameters.get(PARAMETER_DOCUMENT_URL);
+            org.apache.lenya.cms.publication.Document document = publication.getDocumentBuilder().buildDocument(publication, documentUrl);
+            deleteDocumentJobs(document);
+         }
+         // handle the remainder of the request by simply returning all
+         // scheduled jobs (for the given publication ID).
+         PrintWriter writer = response.getWriter();
+         response.setContentType("text/xml");
+         Document snapshot = getScheduler().getSnapshot();
+         DocumentHelper.writeDocument(snapshot, writer);
+      }catch(Exception e){
+         log.error("Can't create job snapshot: ", e);
+         throw new IOException(e.getMessage() + " (view log for details)");
+      }
+   }
+   /**
+    * Extracts the scheduler parameters from a request.
+    * 
+    * @param request
+    *           The request.
+    * @return A namespace map.
+    */
+   public static NamespaceMap getSchedulerParameters(HttpServletRequest request) {
+      Map parameterMap = new HashMap();
+      List keys = new ArrayList();
+      for(Enumeration e = request.getParameterNames(); e.hasMoreElements();){
+         String key = (String) e.nextElement();
+         keys.add(key);
+      }
+      Collections.sort(keys);
+      for(Iterator i = keys.iterator(); i.hasNext();){
+         String key = (String) i.next();
+         String[] values = request.getParameterValues(key);
+         log.debug("    [" + key + "] = [" + values[0] + "]");
+         if(values.length == 1){
+            parameterMap.put(key, values[0]);
+         }else{
+            parameterMap.put(key, values);
+         }
+      }
+      NamespaceMap schedulerParameters = new NamespaceMap(parameterMap, PREFIX);
+      return schedulerParameters;
+   }
+   /**
+    * Deletes
+    * 
+    * @param document
+    * @throws DocumentBuildException
+    * @throws SchedulerException
+    * @throws PublicationException
+    */
+   public void deleteDocumentJobs(org.apache.lenya.cms.publication.Document document) throws DocumentBuildException, SchedulerException, PublicationException {
+      log.debug("Requested to delete jobs for document URL [" + document.getCompleteURL() + "]");
+      getScheduler().deleteJobs(document);
+   }
+   /**
+    * Extracts the job ID from the scheduler parameters.
+    * 
+    * @param schedulerParameters
+    *           A namespace map.
+    * @return A string.
+    */
+   protected String getJobId(NamespaceMap schedulerParameters) {
+      String parameterName = NamespaceMap.getFullName(SchedulerWrapper.JOB_PREFIX, SchedulerWrapper.JOB_ID);
+      String jobId = (String) schedulerParameters.get(parameterName);
+      log.debug("    scheduler.job.id:         [" + jobId + "]");
+      return jobId;
+   }
+   /**
+    * Logs the session attributes of a request.
+    * 
+    * @param request
+    *           The request.
+    */
+   protected void logSessionAttributes(HttpServletRequest request) {
+      log.debug("-------------------- Session Attributes --------------------");
+      for(Enumeration e = request.getSession().getAttributeNames(); e.hasMoreElements();){
+         String name = (String) e.nextElement();
+         log.debug(name + " = " + request.getSession().getAttribute(name));
+      }
+      log.debug("-------------------- End Session Attributes --------------------");
+   }
+   /**
+    * Returns the servlet context path.
+    * 
+    * @return A string.
+    */
+   public File getServletContextDirectory() {
+      return new File(this.servletContext.getRealPath("/"));
+   }
+   /**
+    * Restores the jobs.
+    * 
+    * @throws SchedulerException
+    *            when something went wrong.
+    */
+   public void restoreJobs() throws SchedulerException {
+      File publicationsDirectory = new File(getServletContextDirectory(), PublishingEnvironment.PUBLICATION_PREFIX);
+      File[] publicationDirectories = publicationsDirectory.listFiles(new FileFilter() {
+         public boolean accept(File file) {
+            return file.isDirectory();
+         }
+      });
+      log.debug("=========================================");
+      log.debug("  Restoring jobs.");
+      log.debug("    servlet context: [" + getServletContextDirectory() + "]");
+      log.debug("    publications directory: [" + publicationsDirectory + "]");
+      log.debug("=========================================");
+      for(int i = 0; i < publicationDirectories.length; i++){
+         File directory = publicationDirectories[i];
+         String publicationId = directory.getName();
+         if(PublicationFactory.existsPublication(publicationId, getServletContextDirectory().getAbsolutePath())){
+            getScheduler().restoreJobs(publicationId);
+         }
+      }
+   }
+   public static final String SERVLET_URL = "/servlet/QuartzSchedulerServlet";
+   /**
+    * Returns the servlet for a certain canonical servlet context path.
+    * 
+    * @param contextPath
+    *           The canonical servlet context path.
+    * @return A LoadQuartzServlet.
+    */
+   public static LoadQuartzServlet getServlet(String contextPath) {
+      return (LoadQuartzServlet) servlets.get(contextPath);
+   }
+   /**
+    * Generates the request URI needed to delete the jobs for a certain document.
+    * 
+    * @param document
+    *           The document.
+    * @return A string.
+    */
+   public static String getDeleteDocumentRequestURI(String port, String servletContextPath, org.apache.lenya.cms.publication.Document document) {
+      NamespaceMap requestParameters = new NamespaceMap(PREFIX);
+      requestParameters.put(PARAMETER_ACTION, DOCUMENT_DELETED);
+      requestParameters.put(PARAMETER_PUBLICATION_ID, document.getPublication().getId());
+      requestParameters.put(PARAMETER_DOCUMENT_URL, document.getCompleteURL());
+      String requestUri = "http://127.0.0.1:" + port + servletContextPath + "?";
+      Map map = requestParameters.getMap();
+      String[] keys = (String[]) map.keySet().toArray(new String[map.keySet().size()]);
+      for(int i = 0; i < keys.length; i++){
+         if(i > 0){
+            requestUri += "&";
+         }
+         String value = (String) map.get(keys[i]);
+         requestUri += keys[i] + "=" + value;
+      }
+      return requestUri;
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/scheduler/SchedulerStore.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/scheduler/SchedulerStore.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/scheduler/SchedulerStore.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/scheduler/SchedulerStore.java Wed Jan 30 23:44:03 2008
@@ -14,11 +14,8 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.cms.scheduler;
-
 import java.io.File;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
@@ -26,281 +23,237 @@
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.List;
-
 import org.apache.lenya.cms.publication.Publication;
 import org.apache.lenya.cms.scheduler.xml.TriggerHelper;
 import org.apache.lenya.xml.DocumentHelper;
 import org.apache.lenya.xml.NamespaceHelper;
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
 import org.quartz.JobDetail;
 import org.quartz.SchedulerException;
 import org.quartz.Trigger;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
-
 /**
  * Store for scheduler jobs.
  */
 public class SchedulerStore {
-
-    public static final String ELEMENT_JOB_GROUP = "job-group";
-    public static final String ELEMENT_JOB = "job";
-    public static final String TITLE_ELEMENT = "title";
-
-    private static final Category log = Category.getInstance(SchedulerStore.class);
-
-    public static final String SNAPSHOT_FILE =
-        "config/scheduler/jobs.xml".replace('/', File.separatorChar);
-
-    /**
-     * Ctor.
-     * @param publication The publication.
-     */
-    public SchedulerStore() {
-    }
-
-    /**
-     * Returns the job snapshot file for a publication..
-     * @param Publication The publication.
-     * @return A file.
-     * @throws SchedulerException when the publication could not be built.
-     */
-    protected File getJobsFile(Publication publication) throws SchedulerException {
-        File jobsFile;
-        jobsFile = new File(publication.getDirectory(), SNAPSHOT_FILE);
-        log.debug("Resolved job snapshot file: [" + jobsFile.getAbsolutePath() + "]");
-        return jobsFile;
-    }
-
-    /**
-     * Writes a job snapshot.
-     * @param publication The publication.
-     * @throws SchedulerException when something went wrong.
-     */
-    protected void writeSnapshot(Publication publication, JobWrapper[] jobs)
-        throws SchedulerException {
-
-        log.debug("Writing job snapshot for publication [" + publication.getId() + "]");
-        File jobsFile = getJobsFile(publication);
-
-        try {
-            File directory = jobsFile.getParentFile();
-
-            if (!directory.exists()) {
-                directory.mkdirs();
-                log.debug("Creating job snapshot directory: " + directory.getPath());
-            }
-
-            jobsFile.createNewFile();
-            DocumentHelper.writeDocument(getSnapshot(publication, jobs), jobsFile);
-        } catch (Exception e) {
-            log.error("Writing job snapshot failed: ", e);
-        }
-    }
-
-    /**
-     * Return an xml description of all scheduled jobs for the given publication.
-     *
-     * @param publication The publication.
-     * @return An XML document.
-     * @exception SchedulerException if an error occurs
-     */
-    public Document getSnapshot(Publication publication, JobWrapper[] jobs)
-        throws SchedulerException {
-        NamespaceHelper helper = SchedulerStore.getNamespaceHelper();
-        Document document = helper.getDocument();
-        Element root = document.getDocumentElement();
-
-        log.debug("Creating job snapshot for publication [" + publication.getId() + "]");
-        root.appendChild(createSnapshot(helper, publication, jobs));
-
-        return document;
-    }
-
-    /** The namespace for the <code>jobs.xml</code> file. */
-    public static final String NAMESPACE = "http://apache.org/cocoon/lenya/scheduler/1.0";
-
-    /**
-     * Returns a scheduler namespace helper for a document.
-     * @param document The XML document.
-     * @return a namespace helper.
-     */
-    public static NamespaceHelper getNamespaceHelper(Document document) {
-        return new NamespaceHelper(NAMESPACE, "sch", document);
-    }
-
-    /**
-     * Returns a new scheduler namespace helper with an document containing
-     * a &lt;sch:scheduler&gt; element.
-     * @return a namespace helper.
-     */
-    public static NamespaceHelper getNamespaceHelper() {
-        try {
-            return new NamespaceHelper(NAMESPACE, "sch", "scheduler");
-        } catch (Exception e) {
-            log.error("Could not create namespace helper: ", e);
-
-            return null;
-        }
-    }
-
-    /**
-     * Creates an XML element containting a snapshot of a job group.
-     * @param helper The namespace helper to use.
-     * @param jobGroup The job group.
-     * @return An XMl element.
-     * @throws SchedulerException when something went wrong.
-     */
-    protected Element createSnapshot(
-        NamespaceHelper helper,
-        Publication publication,
-        JobWrapper[] jobs)
-        throws SchedulerException {
-        Element jobGroupElement = helper.createElement(ELEMENT_JOB_GROUP);
-        jobGroupElement.setAttribute("name", publication.getId());
-
-        for (int i = 0; i < jobs.length; i++) {
-
-            ServletJob job = jobs[i].getJob();
-            Element jobElement = job.save(helper, jobs[i].getJobDetail());
-            jobGroupElement.appendChild(jobElement);
-
-            Trigger trigger = jobs[i].getTrigger();
-
-            if (trigger != null) {
-                Element triggerElement = TriggerHelper.createElement(helper, trigger);
-                jobElement.appendChild(triggerElement);
-            }
-        }
-
-        return jobGroupElement;
-    }
-
-    /**
-     * Restores the jobs of a certain job group from the snapshot file.
-     * @param jobGroup The job group.
-     * @throws SchedulerException when something went wrong.
-     */
-    public JobWrapper[] restoreJobs(Publication publication) throws SchedulerException {
-        
-        log.debug("Restoring jobs for publication [" + publication.getId() + "]");
-
-        List wrappers = new ArrayList();
-        File jobsFile = getJobsFile(publication);
-        
-        if (jobsFile.exists()) {
-            Element[] jobElements = getJobElements(publication);
-            Document document;
-            try {
-                document = DocumentHelper.readDocument(jobsFile);
-            } catch (Exception e) {
-                throw new SchedulerException(e);
-            }
-            NamespaceHelper helper = SchedulerStore.getNamespaceHelper(document);
-
-            for (int i = 0; i < jobElements.length; i++) {
-                wrappers.add(restoreJob(helper, jobElements[i], publication));
-            }
-        }
-        else {
-            log.debug("Could not restore jobs for publication [" + publication.getId() + "] - jobs file does not exist.");
-        }
-
-        return (JobWrapper[]) wrappers.toArray(new JobWrapper[wrappers.size()]);
-    }
-
-    /**
-     * Restores the jobs from a certain XML element.
-     * @param jobElement The XML element.
-     * @param jobGroup The job group the job belongs to.
-     */
-    protected JobWrapper restoreJob(
-        NamespaceHelper helper,
-        Element jobElement,
-        Publication publication)
-        throws SchedulerException {
-        log.debug("Restoring job ");
-        JobWrapper wrapper;
-
-        try {
-            String jobClassName = jobElement.getAttribute(ServletJob.ATTRIBUTE_CLASS);
-            ServletJob job = ServletJobFactory.createJob(jobClassName);
-            JobDetail jobDetail =
-                job.load(
-                    jobElement,
-                    publication.getId(),
-                    publication.getServletContext().getAbsolutePath());
-
-            Trigger trigger = null;
-
-            Element triggerElement = helper.getFirstChild(jobElement, "trigger");
-            if (triggerElement != null) {
-                trigger =
-                    TriggerHelper.createTrigger(
-                        triggerElement,
-                        jobDetail.getName(),
-                        jobDetail.getGroup());
-
-                Date now = new GregorianCalendar().getTime();
-                if (log.isDebugEnabled()) {
-                    DateFormat format = new SimpleDateFormat();
-                    log.debug(
-                        "    Trigger time: [" + format.format(trigger.getFinalFireTime()) + "]");
-                    log.debug("    Current time: [" + format.format(now) + "]");
-                }
-                if (!trigger.getFinalFireTime().after(now)) {
-                    trigger = null;
-                }
-            }
-            wrapper = new JobWrapper(jobDetail, trigger);
-
-        } catch (Exception e) {
-            throw new SchedulerException(e);
-        }
-        return wrapper;
-    }
-
-    /**
-     * Returns the job elements of a publication.
-     * @param publication
-     * @return
-     * @throws SchedulerException when something went wrong.
-     */
-    protected Element[] getJobElements(Publication publication) throws SchedulerException {
-        Element[] jobElements;
-        try {
-            File jobsFile = getJobsFile(publication);
-            if (jobsFile.exists()) {
-                Document document = DocumentHelper.readDocument(jobsFile);
-                Element schedulerElement = document.getDocumentElement();
-                NamespaceHelper helper = SchedulerStore.getNamespaceHelper(document);
-
-                Element jobGroupElement =
-                    helper.getFirstChild(schedulerElement, SchedulerStore.ELEMENT_JOB_GROUP);
-                if (jobGroupElement == null) {
-                    throw new SchedulerException("No <job-group> element found!");
-                }
-
-                String jobGroupAttribute = jobGroupElement.getAttribute("name");
-
-                if (!jobGroupAttribute.equals(publication.getId())) {
-                    throw new SchedulerException(
-                        "The jobs.xml file contains a wrong job group: ["
-                            + jobGroupAttribute
-                            + "]");
-                } else {
-                    jobElements = helper.getChildren(jobGroupElement, SchedulerStore.ELEMENT_JOB);
-
-                }
-            } else {
-                throw new SchedulerException(
-                    "The jobs file [" + jobsFile.getAbsolutePath() + "] does not exist!");
-            }
-        } catch (SchedulerException e) {
-            throw e;
-        } catch (Exception e) {
+   private static Logger log = Logger.getLogger(SchedulerStore.class);
+   public static final String ELEMENT_JOB_GROUP = "job-group";
+   public static final String ELEMENT_JOB = "job";
+   public static final String TITLE_ELEMENT = "title";
+   public static final String SNAPSHOT_FILE = "config/scheduler/jobs.xml".replace('/', File.separatorChar);
+   /**
+    * Ctor.
+    * 
+    * @param publication
+    *           The publication.
+    */
+   public SchedulerStore() {
+   }
+   /**
+    * Returns the job snapshot file for a publication..
+    * 
+    * @param Publication
+    *           The publication.
+    * @return A file.
+    * @throws SchedulerException
+    *            when the publication could not be built.
+    */
+   protected File getJobsFile(Publication publication) throws SchedulerException {
+      File jobsFile;
+      jobsFile = new File(publication.getDirectory(), SNAPSHOT_FILE);
+      log.debug("Resolved job snapshot file: [" + jobsFile.getAbsolutePath() + "]");
+      return jobsFile;
+   }
+   /**
+    * Writes a job snapshot.
+    * 
+    * @param publication
+    *           The publication.
+    * @throws SchedulerException
+    *            when something went wrong.
+    */
+   protected void writeSnapshot(Publication publication, JobWrapper[] jobs) throws SchedulerException {
+      log.debug("Writing job snapshot for publication [" + publication.getId() + "]");
+      File jobsFile = getJobsFile(publication);
+      try{
+         File directory = jobsFile.getParentFile();
+         if(!directory.exists()){
+            directory.mkdirs();
+            log.debug("Creating job snapshot directory: " + directory.getPath());
+         }
+         jobsFile.createNewFile();
+         DocumentHelper.writeDocument(getSnapshot(publication, jobs), jobsFile);
+      }catch(Exception e){
+         log.error("Writing job snapshot failed: ", e);
+      }
+   }
+   /**
+    * Return an xml description of all scheduled jobs for the given publication.
+    * 
+    * @param publication
+    *           The publication.
+    * @return An XML document.
+    * @exception SchedulerException
+    *               if an error occurs
+    */
+   public Document getSnapshot(Publication publication, JobWrapper[] jobs) throws SchedulerException {
+      NamespaceHelper helper = SchedulerStore.getNamespaceHelper();
+      Document document = helper.getDocument();
+      Element root = document.getDocumentElement();
+      log.debug("Creating job snapshot for publication [" + publication.getId() + "]");
+      root.appendChild(createSnapshot(helper, publication, jobs));
+      return document;
+   }
+   /** The namespace for the <code>jobs.xml</code> file. */
+   public static final String NAMESPACE = "http://apache.org/cocoon/lenya/scheduler/1.0";
+   /**
+    * Returns a scheduler namespace helper for a document.
+    * 
+    * @param document
+    *           The XML document.
+    * @return a namespace helper.
+    */
+   public static NamespaceHelper getNamespaceHelper(Document document) {
+      return new NamespaceHelper(NAMESPACE, "sch", document);
+   }
+   /**
+    * Returns a new scheduler namespace helper with an document containing a &lt;sch:scheduler&gt; element.
+    * 
+    * @return a namespace helper.
+    */
+   public static NamespaceHelper getNamespaceHelper() {
+      try{
+         return new NamespaceHelper(NAMESPACE, "sch", "scheduler");
+      }catch(Exception e){
+         log.error("Could not create namespace helper: ", e);
+         return null;
+      }
+   }
+   /**
+    * Creates an XML element containting a snapshot of a job group.
+    * 
+    * @param helper
+    *           The namespace helper to use.
+    * @param jobGroup
+    *           The job group.
+    * @return An XMl element.
+    * @throws SchedulerException
+    *            when something went wrong.
+    */
+   protected Element createSnapshot(NamespaceHelper helper, Publication publication, JobWrapper[] jobs) throws SchedulerException {
+      Element jobGroupElement = helper.createElement(ELEMENT_JOB_GROUP);
+      jobGroupElement.setAttribute("name", publication.getId());
+      for(int i = 0; i < jobs.length; i++){
+         ServletJob job = jobs[i].getJob();
+         Element jobElement = job.save(helper, jobs[i].getJobDetail());
+         jobGroupElement.appendChild(jobElement);
+         Trigger trigger = jobs[i].getTrigger();
+         if(trigger != null){
+            Element triggerElement = TriggerHelper.createElement(helper, trigger);
+            jobElement.appendChild(triggerElement);
+         }
+      }
+      return jobGroupElement;
+   }
+   /**
+    * Restores the jobs of a certain job group from the snapshot file.
+    * 
+    * @param jobGroup
+    *           The job group.
+    * @throws SchedulerException
+    *            when something went wrong.
+    */
+   public JobWrapper[] restoreJobs(Publication publication) throws SchedulerException {
+      log.debug("Restoring jobs for publication [" + publication.getId() + "]");
+      List wrappers = new ArrayList();
+      File jobsFile = getJobsFile(publication);
+      if(jobsFile.exists()){
+         Element[] jobElements = getJobElements(publication);
+         Document document;
+         try{
+            document = DocumentHelper.readDocument(jobsFile);
+         }catch(Exception e){
             throw new SchedulerException(e);
-        }
-        return jobElements;
-    }
+         }
+         NamespaceHelper helper = SchedulerStore.getNamespaceHelper(document);
+         for(int i = 0; i < jobElements.length; i++){
+            wrappers.add(restoreJob(helper, jobElements[i], publication));
+         }
+      }else{
+         log.debug("Could not restore jobs for publication [" + publication.getId() + "] - jobs file does not exist.");
+      }
+      return (JobWrapper[]) wrappers.toArray(new JobWrapper[wrappers.size()]);
+   }
+   /**
+    * Restores the jobs from a certain XML element.
+    * 
+    * @param jobElement
+    *           The XML element.
+    * @param jobGroup
+    *           The job group the job belongs to.
+    */
+   protected JobWrapper restoreJob(NamespaceHelper helper, Element jobElement, Publication publication) throws SchedulerException {
+      log.debug("Restoring job ");
+      JobWrapper wrapper;
+      try{
+         String jobClassName = jobElement.getAttribute(ServletJob.ATTRIBUTE_CLASS);
+         ServletJob job = ServletJobFactory.createJob(jobClassName);
+         JobDetail jobDetail = job.load(jobElement, publication.getId(), publication.getServletContext().getAbsolutePath());
+         Trigger trigger = null;
+         Element triggerElement = helper.getFirstChild(jobElement, "trigger");
+         if(triggerElement != null){
+            trigger = TriggerHelper.createTrigger(triggerElement, jobDetail.getName(), jobDetail.getGroup());
+            Date now = new GregorianCalendar().getTime();
+            if(log.isDebugEnabled()){
+               DateFormat format = new SimpleDateFormat();
+               log.debug("    Trigger time: [" + format.format(trigger.getFinalFireTime()) + "]");
+               log.debug("    Current time: [" + format.format(now) + "]");
+            }
+            if(!trigger.getFinalFireTime().after(now)){
+               trigger = null;
+            }
+         }
+         wrapper = new JobWrapper(jobDetail, trigger);
+      }catch(Exception e){
+         throw new SchedulerException(e);
+      }
+      return wrapper;
+   }
+   /**
+    * Returns the job elements of a publication.
+    * 
+    * @param publication
+    * @return
+    * @throws SchedulerException
+    *            when something went wrong.
+    */
+   protected Element[] getJobElements(Publication publication) throws SchedulerException {
+      Element[] jobElements;
+      try{
+         File jobsFile = getJobsFile(publication);
+         if(jobsFile.exists()){
+            Document document = DocumentHelper.readDocument(jobsFile);
+            Element schedulerElement = document.getDocumentElement();
+            NamespaceHelper helper = SchedulerStore.getNamespaceHelper(document);
+            Element jobGroupElement = helper.getFirstChild(schedulerElement, SchedulerStore.ELEMENT_JOB_GROUP);
+            if(jobGroupElement == null){
+               throw new SchedulerException("No <job-group> element found!");
+            }
+            String jobGroupAttribute = jobGroupElement.getAttribute("name");
+            if(!jobGroupAttribute.equals(publication.getId())){
+               throw new SchedulerException("The jobs.xml file contains a wrong job group: [" + jobGroupAttribute + "]");
+            }else{
+               jobElements = helper.getChildren(jobGroupElement, SchedulerStore.ELEMENT_JOB);
+            }
+         }else{
+            throw new SchedulerException("The jobs file [" + jobsFile.getAbsolutePath() + "] does not exist!");
+         }
+      }catch(SchedulerException e){
+         throw e;
+      }catch(Exception e){
+         throw new SchedulerException(e);
+      }
+      return jobElements;
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/scheduler/SchedulerWrapper.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/scheduler/SchedulerWrapper.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/scheduler/SchedulerWrapper.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/scheduler/SchedulerWrapper.java Wed Jan 30 23:44:03 2008
@@ -14,11 +14,8 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.cms.scheduler;
-
 import java.io.File;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
@@ -26,9 +23,7 @@
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.List;
-
 import javax.servlet.http.HttpServletRequest;
-
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
 import org.apache.lenya.cms.publication.Publication;
@@ -36,7 +31,7 @@
 import org.apache.lenya.cms.publication.PublicationFactory;
 import org.apache.lenya.cms.scheduler.xml.TriggerHelper;
 import org.apache.lenya.xml.NamespaceHelper;
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
 import org.quartz.JobDataMap;
 import org.quartz.JobDetail;
 import org.quartz.Scheduler;
@@ -46,488 +41,469 @@
 import org.quartz.impl.StdSchedulerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
-
 public class SchedulerWrapper {
-
-    private static Category log = Category.getInstance(SchedulerWrapper.class);
-    public static final String JOB_PREFIX = "job";
-    public static final String JOB_ID = "id";
-    private static int jobId = 0;
-    private Scheduler scheduler = null;
-    private String servletContextPath;
-    private String schedulerConfigurationPath;
-    private SchedulerStore store = new SchedulerStore();
-
-    /**
-     * Creates a new instance of SchedulerWrapper
-     *
-     * @param servletContextPath The servlet context path.
-     * @param schedulerConfigurationPath The scheduler configuration path.
-     */
-    public SchedulerWrapper(String servletContextPath, String schedulerConfigurationPath) {
-        this.servletContextPath = servletContextPath;
-        this.schedulerConfigurationPath = schedulerConfigurationPath;
-
-        SchedulerFactory factory = new StdSchedulerFactory();
-        log.info("------- Starting up -----------------------");
-
-        try {
-            scheduler = factory.getScheduler();
-
-            scheduler.addSchedulerListener(new AbstractSchedulerListener());
-            scheduler.start();
-        } catch (SchedulerException e) {
-            log.error("Can't initialize SchedulerWrapper: ", e);
-            log.error("------- Startup failed -------------------");
-        }
-
-        log.info("------- Startup complete ------------------");
-    }
-
-    /**
-     * Returns the store.
-     * @return A scheduler store.
-     */
-    protected SchedulerStore getStore() {
-        return store;
-    }
-
-    /**
-     * Returns the scheduler.
-     * @return A scheduler.
-     */
-    private Scheduler getScheduler() {
-        return scheduler;
-    }
-
-    /**
-     * Shuts down the scheduler.
-     */
-    public void shutdown() {
-        log.info("------- Shutting Down ---------------------");
-
-        // try to save state here
-        try {
-            getScheduler().shutdown();
-        } catch (SchedulerException e) {
-            log.error("------- Shutdown Failed -----------------", e);
-        }
-
-        log.info("------- Shutdown Complete -----------------");
-    }
-
-    /**
-     * Returns the servlet context path.
-     * @return The servlet context path.
-     */
-    protected String getServletContextPath() {
-        return servletContextPath;
-    }
-
-    /**
-     * Returns the scheduler configuration path.
-     * @return A string.
-     */
-    protected String getSchedulerConfigurationPath() {
-        return schedulerConfigurationPath;
-    }
-
-    /**
-     * Returns the next job ID to use (calculated using the current time).
-     * @return A string.
-     */
-    protected synchronized static String getNextJobId() {
-        return "job_" + jobId++ +System.currentTimeMillis();
-    }
-
-    /**
-     * Adds a job.
-     * @param jobGroup The job group.
-     * @param startTime The start time.
-     * @param jobClass The class of the job.
-     * @param map The job parameters.
-     * @throws SchedulerException if an error occurs.
-     * @throws PublicationException if an error occurs.
-     */
-    protected void addJob(String jobGroup, Date startTime, Class jobClass, JobDataMap map)
-        throws SchedulerException, PublicationException {
-        String uniqueJobId = getNextJobId();
-        log.debug("Job ID: [" + uniqueJobId + "]");
-        
-        JobDetail jobDetail = new JobDetail(uniqueJobId, jobGroup, jobClass);
-        jobDetail.setJobDataMap(map);
-        
-        Date now = new GregorianCalendar().getTime();
-        if (log.isDebugEnabled()) {
-            DateFormat format = new SimpleDateFormat();
-            log.debug("Trigger time: [" + format.format(startTime) + "]");
-            log.debug("Current time: [" + format.format(now) + "]");
-        }
-        
-        if (startTime.after(now)) {
-            Trigger trigger =
-                TriggerHelper.createSimpleTrigger(uniqueJobId, jobGroup, startTime);
-            addJob(jobDetail, trigger);
-            log.debug("Scheduling job.");
-        } else {
-            addJob(jobDetail);
-            log.debug("Adding job without scheduling.");
-        }
-        
-        log.debug("----------------------------------------------");
-        
-        store.writeSnapshot(getPublication(jobGroup), getJobWrappers(jobGroup));
-    }
-
-    /**
-     * Adds a job.
-     * @param jobGroup The job group.
-     * @param startTime The start time.
-     * @param request The request to obtain the parameters from.
-     * @throws SchedulerException when something went wrong.
-     */
-    public void addJob(String jobGroup, Date startTime, HttpServletRequest request)
-        throws SchedulerException {
-
-        if (jobGroup == null) {
-            throw new SchedulerException("Job group must not be null!");
-        }
-
-        try {
-            log.debug("----------------------------------------------");
-            log.debug("Adding Job for group [" + jobGroup + "]");
-
-            // FIXME: more flexible
-            Class jobClass = TaskJob.class;
-
-            ServletJob job = ServletJobFactory.createJob(jobClass);
-            JobDataMap map = job.createJobData(request);
-
-            addJob(jobGroup, startTime, jobClass, map);
-        } catch (Exception e) {
-            log.error("Adding job failed: ", e);
-            throw new SchedulerException(e);
-        }
-    }
-
-    /**
-     * Returns the publication for a job group.
-     * @param jobGroup A job group.
-     * @return A publication.
-     * @throws PublicationException when the publication does not exist.
-     */
-    protected Publication getPublication(String jobGroup) throws PublicationException {
-        return PublicationFactory.getPublication(jobGroup, getServletContextPath());
-    }
-
-    /**
-     * Adds a job.
-     * @param detail The job information.
-     * @param trigger The trigger to trigger the job.
-     */
-    protected void addJob(JobDetail detail, Trigger trigger) {
-        try {
-            detail.setDurability(true);
-
-            Date ft = getScheduler().scheduleJob(detail, trigger);
-            log.debug("Job " + detail.getFullName() + " will run at: " + ft);
-        } catch (Exception e) {
-            log.error("Adding job failed: ", e);
-        }
-    }
-
-    /**
-     * Adds a job.
-     * @param detail The job information.
-     */
-    protected void addJob(JobDetail detail) {
-        try {
-            detail.setDurability(true);
-            getScheduler().addJob(detail, true);
-        } catch (SchedulerException e) {
-            log.error("Adding job failed: ", e);
-        }
-    }
-
-    /**
-     * Deletes a job.
-     * @param jobName The job name.
-     * @param jobGroup The job group.
-     */
-    protected void deleteJob(String jobName, String jobGroup) {
-        try {
-            log.debug("-----------------------------------");
-            log.debug("\n Deleting job [" + jobGroup + "/" + jobName + "]");
-            log.debug("-----------------------------------");
-            getScheduler().deleteJob(jobName, jobGroup);
-            getStore().writeSnapshot(getPublication(jobGroup), getJobWrappers(jobGroup));
-        } catch (Exception e) {
-            log.error("Deleting job failed: ", e);
-        }
-    }
-
-    /**
-     * Reads the scheduler configuration.
-     * @return A configuration.
-     */
-    protected Configuration getSchedulerConfiguration() {
-        try {
-            DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
-            String path = getServletContextPath() + getSchedulerConfigurationPath();
-            log.debug("Initializing scheduler configuration: " + path);
-
-            File configurationFile = new File(path);
-            Configuration configuration = builder.buildFromFile(configurationFile);
-
-            return configuration;
-        } catch (Exception e) {
-            log.error("Can't initialize scheduler configuration: ", e);
-
-            return null;
-        }
-    }
-
-    public static final String ELEMENT_TRIGGERS = "triggers";
-    public static final String ELEMENT_TRIGGER = "trigger";
-    public static final String TYPE_ATTRIBUTE = "type";
-    public static final String CLASS_ATTRIBUTE = "class";
-
-    /**
-     * Returns an XML element containing the trigger types.
-     * @param helper The namespace helper of the document that shall contain the element.
-     * @return An XML element.
-     */
-    protected Element getTriggerTypes(NamespaceHelper helper) {
-        try {
-            Configuration configuration = getSchedulerConfiguration();
-            Configuration[] triggerConfigurations =
-                configuration.getChild(ELEMENT_TRIGGERS).getChildren(ELEMENT_TRIGGER);
-
-            Element triggersElement = helper.createElement("triggers");
-
-            for (int i = 0; i < triggerConfigurations.length; i++) {
-                Configuration conf = triggerConfigurations[i];
-                String type = conf.getAttribute(TYPE_ATTRIBUTE);
-                String className = conf.getAttribute(CLASS_ATTRIBUTE);
-
-                Element triggerElement = helper.createElement("trigger");
-                triggerElement.setAttribute("name", type);
-                triggerElement.setAttribute("src", className);
-                triggersElement.appendChild(triggerElement);
+   private static Logger log = Logger.getLogger(SchedulerWrapper.class);
+   public static final String JOB_PREFIX = "job";
+   public static final String JOB_ID = "id";
+   private static int jobId = 0;
+   private Scheduler scheduler = null;
+   private String servletContextPath;
+   private String schedulerConfigurationPath;
+   private SchedulerStore store = new SchedulerStore();
+   /**
+    * Creates a new instance of SchedulerWrapper
+    * 
+    * @param servletContextPath
+    *           The servlet context path.
+    * @param schedulerConfigurationPath
+    *           The scheduler configuration path.
+    */
+   public SchedulerWrapper(String servletContextPath, String schedulerConfigurationPath) {
+      this.servletContextPath = servletContextPath;
+      this.schedulerConfigurationPath = schedulerConfigurationPath;
+      SchedulerFactory factory = new StdSchedulerFactory();
+      log.info("------- Starting up -----------------------");
+      try{
+         scheduler = factory.getScheduler();
+         scheduler.addSchedulerListener(new AbstractSchedulerListener());
+         scheduler.start();
+      }catch(SchedulerException e){
+         log.error("Can't initialize SchedulerWrapper: ", e);
+         log.error("------- Startup failed -------------------");
+      }
+      log.info("------- Startup complete ------------------");
+   }
+   /**
+    * Returns the store.
+    * 
+    * @return A scheduler store.
+    */
+   protected SchedulerStore getStore() {
+      return store;
+   }
+   /**
+    * Returns the scheduler.
+    * 
+    * @return A scheduler.
+    */
+   private Scheduler getScheduler() {
+      return scheduler;
+   }
+   /**
+    * Shuts down the scheduler.
+    */
+   public void shutdown() {
+      log.info("------- Shutting Down ---------------------");
+      // try to save state here
+      try{
+         getScheduler().shutdown();
+      }catch(SchedulerException e){
+         log.error("------- Shutdown Failed -----------------", e);
+      }
+      log.info("------- Shutdown Complete -----------------");
+   }
+   /**
+    * Returns the servlet context path.
+    * 
+    * @return The servlet context path.
+    */
+   protected String getServletContextPath() {
+      return servletContextPath;
+   }
+   /**
+    * Returns the scheduler configuration path.
+    * 
+    * @return A string.
+    */
+   protected String getSchedulerConfigurationPath() {
+      return schedulerConfigurationPath;
+   }
+   /**
+    * Returns the next job ID to use (calculated using the current time).
+    * 
+    * @return A string.
+    */
+   protected synchronized static String getNextJobId() {
+      return "job_" + jobId++ + System.currentTimeMillis();
+   }
+   /**
+    * Adds a job.
+    * 
+    * @param jobGroup
+    *           The job group.
+    * @param startTime
+    *           The start time.
+    * @param jobClass
+    *           The class of the job.
+    * @param map
+    *           The job parameters.
+    * @throws SchedulerException
+    *            if an error occurs.
+    * @throws PublicationException
+    *            if an error occurs.
+    */
+   protected void addJob(String jobGroup, Date startTime, Class jobClass, JobDataMap map) throws SchedulerException, PublicationException {
+      String uniqueJobId = getNextJobId();
+      log.debug("Job ID: [" + uniqueJobId + "]");
+      JobDetail jobDetail = new JobDetail(uniqueJobId, jobGroup, jobClass);
+      jobDetail.setJobDataMap(map);
+      Date now = new GregorianCalendar().getTime();
+      if(log.isDebugEnabled()){
+         DateFormat format = new SimpleDateFormat();
+         log.debug("Trigger time: [" + format.format(startTime) + "]");
+         log.debug("Current time: [" + format.format(now) + "]");
+      }
+      if(startTime.after(now)){
+         Trigger trigger = TriggerHelper.createSimpleTrigger(uniqueJobId, jobGroup, startTime);
+         addJob(jobDetail, trigger);
+         log.debug("Scheduling job.");
+      }else{
+         addJob(jobDetail);
+         log.debug("Adding job without scheduling.");
+      }
+      log.debug("----------------------------------------------");
+      store.writeSnapshot(getPublication(jobGroup), getJobWrappers(jobGroup));
+   }
+   /**
+    * Adds a job.
+    * 
+    * @param jobGroup
+    *           The job group.
+    * @param startTime
+    *           The start time.
+    * @param request
+    *           The request to obtain the parameters from.
+    * @throws SchedulerException
+    *            when something went wrong.
+    */
+   public void addJob(String jobGroup, Date startTime, HttpServletRequest request) throws SchedulerException {
+      if(jobGroup == null){
+         throw new SchedulerException("Job group must not be null!");
+      }
+      try{
+         log.debug("----------------------------------------------");
+         log.debug("Adding Job for group [" + jobGroup + "]");
+         // FIXME: more flexible
+         Class jobClass = TaskJob.class;
+         ServletJob job = ServletJobFactory.createJob(jobClass);
+         JobDataMap map = job.createJobData(request);
+         addJob(jobGroup, startTime, jobClass, map);
+      }catch(Exception e){
+         log.error("Adding job failed: ", e);
+         throw new SchedulerException(e);
+      }
+   }
+   /**
+    * Returns the publication for a job group.
+    * 
+    * @param jobGroup
+    *           A job group.
+    * @return A publication.
+    * @throws PublicationException
+    *            when the publication does not exist.
+    */
+   protected Publication getPublication(String jobGroup) throws PublicationException {
+      return PublicationFactory.getPublication(jobGroup, getServletContextPath());
+   }
+   /**
+    * Adds a job.
+    * 
+    * @param detail
+    *           The job information.
+    * @param trigger
+    *           The trigger to trigger the job.
+    */
+   protected void addJob(JobDetail detail, Trigger trigger) {
+      try{
+         detail.setDurability(true);
+         Date ft = getScheduler().scheduleJob(detail, trigger);
+         log.debug("Job " + detail.getFullName() + " will run at: " + ft);
+      }catch(Exception e){
+         log.error("Adding job failed: ", e);
+      }
+   }
+   /**
+    * Adds a job.
+    * 
+    * @param detail
+    *           The job information.
+    */
+   protected void addJob(JobDetail detail) {
+      try{
+         detail.setDurability(true);
+         getScheduler().addJob(detail, true);
+      }catch(SchedulerException e){
+         log.error("Adding job failed: ", e);
+      }
+   }
+   /**
+    * Deletes a job.
+    * 
+    * @param jobName
+    *           The job name.
+    * @param jobGroup
+    *           The job group.
+    */
+   protected void deleteJob(String jobName, String jobGroup) {
+      try{
+         log.debug("-----------------------------------");
+         log.debug("\n Deleting job [" + jobGroup + "/" + jobName + "]");
+         log.debug("-----------------------------------");
+         getScheduler().deleteJob(jobName, jobGroup);
+         getStore().writeSnapshot(getPublication(jobGroup), getJobWrappers(jobGroup));
+      }catch(Exception e){
+         log.error("Deleting job failed: ", e);
+      }
+   }
+   /**
+    * Reads the scheduler configuration.
+    * 
+    * @return A configuration.
+    */
+   protected Configuration getSchedulerConfiguration() {
+      try{
+         DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
+         String path = getServletContextPath() + getSchedulerConfigurationPath();
+         log.debug("Initializing scheduler configuration: " + path);
+         File configurationFile = new File(path);
+         Configuration configuration = builder.buildFromFile(configurationFile);
+         return configuration;
+      }catch(Exception e){
+         log.error("Can't initialize scheduler configuration: ", e);
+         return null;
+      }
+   }
+   public static final String ELEMENT_TRIGGERS = "triggers";
+   public static final String ELEMENT_TRIGGER = "trigger";
+   public static final String TYPE_ATTRIBUTE = "type";
+   public static final String CLASS_ATTRIBUTE = "class";
+   /**
+    * Returns an XML element containing the trigger types.
+    * 
+    * @param helper
+    *           The namespace helper of the document that shall contain the element.
+    * @return An XML element.
+    */
+   protected Element getTriggerTypes(NamespaceHelper helper) {
+      try{
+         Configuration configuration = getSchedulerConfiguration();
+         Configuration[] triggerConfigurations = configuration.getChild(ELEMENT_TRIGGERS).getChildren(ELEMENT_TRIGGER);
+         Element triggersElement = helper.createElement("triggers");
+         for(int i = 0; i < triggerConfigurations.length; i++){
+            Configuration conf = triggerConfigurations[i];
+            String type = conf.getAttribute(TYPE_ATTRIBUTE);
+            String className = conf.getAttribute(CLASS_ATTRIBUTE);
+            Element triggerElement = helper.createElement("trigger");
+            triggerElement.setAttribute("name", type);
+            triggerElement.setAttribute("src", className);
+            triggersElement.appendChild(triggerElement);
+         }
+         return triggersElement;
+      }catch(Exception e){
+         log.error("Can't configure trigger types: " + e);
+         return null;
+      }
+   }
+   /**
+    * Returns the trigger of a certain job.
+    * 
+    * @param jobName
+    *           The job name.
+    * @param jobGroup
+    *           The job group.
+    * @return A trigger.
+    * @throws SchedulerException
+    *            when something went wrong.
+    */
+   protected Trigger getTrigger(String jobName, String jobGroup) throws SchedulerException {
+      log.debug("Resolving trigger for job [" + jobName + " ][ " + jobGroup + "]");
+      String[] triggerGroups = getScheduler().getTriggerGroupNames();
+      for(int groupIndex = 0; groupIndex < triggerGroups.length; groupIndex++){
+         String[] triggerNames = getScheduler().getTriggerNames(triggerGroups[groupIndex]);
+         for(int nameIndex = 0; nameIndex < triggerNames.length; nameIndex++){
+            log.debug("Trigger name:  " + triggerNames[nameIndex]);
+            Trigger trigger = getScheduler().getTrigger(triggerNames[nameIndex], triggerGroups[groupIndex]);
+            log.debug("Job group:     " + trigger.getJobGroup());
+            if(trigger.getJobGroup().equals(jobGroup) && trigger.getJobName().equals(jobName)){
+               return trigger;
             }
-
-            return triggersElement;
-        } catch (Exception e) {
-            log.error("Can't configure trigger types: " + e);
-
-            return null;
-        }
-    }
-
-    /**
-     * Returns the trigger of a certain job.
-     * @param jobName The job name.
-     * @param jobGroup The job group.
-     * @return A trigger.
-     * @throws SchedulerException when something went wrong.
-     */
-    protected Trigger getTrigger(String jobName, String jobGroup) throws SchedulerException {
-        log.debug("Resolving trigger for job [" + jobName + " ][ " + jobGroup + "]");
-        String[] triggerGroups = getScheduler().getTriggerGroupNames();
-
-        for (int groupIndex = 0; groupIndex < triggerGroups.length; groupIndex++) {
-            String[] triggerNames = getScheduler().getTriggerNames(triggerGroups[groupIndex]);
-
-            for (int nameIndex = 0; nameIndex < triggerNames.length; nameIndex++) {
-                log.debug("Trigger name:  " + triggerNames[nameIndex]);
-
-                Trigger trigger =
-                    getScheduler().getTrigger(triggerNames[nameIndex], triggerGroups[groupIndex]);
-                log.debug("Job group:     " + trigger.getJobGroup());
-
-                if (trigger.getJobGroup().equals(jobGroup)
-                    && trigger.getJobName().equals(jobName)) {
-                    return trigger;
-                }
+         }
+      }
+      return null;
+   }
+   /**
+    * Return an XML description certain job groups.
+    * 
+    * @param jobGroupNames
+    *           The job group names.
+    * @return An XML document.
+    * @exception SchedulerException
+    *               if an error occurs
+    */
+   public Document getSnapshot(String[] jobGroupNames) throws SchedulerException {
+      log.debug("Creating job snapshot");
+      NamespaceHelper helper = SchedulerStore.getNamespaceHelper();
+      Document document = helper.getDocument();
+      Element root = document.getDocumentElement();
+      // print a list of all available trigger types
+      root.appendChild(getTriggerTypes(helper));
+      for(int groupIndex = 0; groupIndex < jobGroupNames.length; groupIndex++){
+         log.debug("Creating job snapshot for group [" + jobGroupNames[groupIndex] + "]");
+         root.appendChild(getSnapshot(helper, jobGroupNames[groupIndex]));
+      }
+      return document;
+   }
+   /**
+    * Returns the snapshot of a certain job group.
+    * 
+    * @param helper
+    *           The namespace helper.
+    * @param group
+    *           The job group.
+    * @return An XML element.
+    * @throws SchedulerException
+    *            when something went wrong.
+    */
+   protected Element getSnapshot(NamespaceHelper helper, String group) throws SchedulerException {
+      JobWrapper[] jobs = getJobWrappers(group);
+      Element element;
+      try{
+         element = getStore().createSnapshot(helper, getPublication(group), jobs);
+      }catch(SchedulerException e){
+         throw e;
+      }catch(PublicationException e){
+         throw new SchedulerException(e);
+      }
+      return element;
+   }
+   /**
+    * Returns the job wrappers for a certain job group.
+    * 
+    * @param jobGroupName
+    *           The job group.
+    * @return An array of job wrappers.
+    * @throws SchedulerException
+    *            when something went wrong.
+    */
+   protected JobWrapper[] getJobWrappers(String jobGroupName) throws SchedulerException {
+      List wrappers = new ArrayList();
+      String[] jobNames = getScheduler().getJobNames(jobGroupName);
+      for(int nameIndex = 0; nameIndex < jobNames.length; nameIndex++){
+         JobDetail jobDetail = getScheduler().getJobDetail(jobNames[nameIndex], jobGroupName);
+         Trigger trigger = getTrigger(jobNames[nameIndex], jobGroupName);
+         wrappers.add(new JobWrapper(jobDetail, trigger));
+      }
+      return (JobWrapper[]) wrappers.toArray(new JobWrapper[wrappers.size()]);
+   }
+   /**
+    * Return an xml description of all scheduled jobs.
+    * 
+    * @return DOCUMENT ME!
+    * @exception SchedulerException
+    *               if an error occurs
+    */
+   public Document getSnapshot() throws SchedulerException {
+      String[] jobGroupNames = getScheduler().getJobGroupNames();
+      return getSnapshot(jobGroupNames);
+   }
+   /**
+    * Restores the jobs of a certain job group from the snapshot file.
+    * 
+    * @param jobGroup
+    *           The job group.
+    * @throws SchedulerException
+    *            when something went wrong.
+    */
+   public void restoreJobs(String jobGroup) throws SchedulerException {
+      log.debug("--------------------------------------------------");
+      log.debug("Restoring jobs for job group [" + jobGroup + "]");
+      log.debug("--------------------------------------------------");
+      try{
+         JobWrapper[] jobs = getStore().restoreJobs(getPublication(jobGroup));
+         for(int i = 0; i < jobs.length; i++){
+            if(jobs[i].getTrigger() != null){
+               if(log.isDebugEnabled()){
+                  log.debug("    Trigger time in future - scheduling job.");
+               }
+               addJob(jobs[i].getJobDetail(), jobs[i].getTrigger());
+            }else{
+               if(log.isDebugEnabled()){
+                  log.debug("    Trigger time has expired - adding job without scheduling.");
+               }
+               addJob(jobs[i].getJobDetail());
             }
-        }
-
-        return null;
-    }
-
-    /**
-     * Return an XML description certain job groups.
-     * @param jobGroupNames The job group names.
-     * @return An XML document.
-     * @exception SchedulerException if an error occurs
-     */
-    public Document getSnapshot(String[] jobGroupNames) throws SchedulerException {
-        log.debug("Creating job snapshot");
-
-        NamespaceHelper helper = SchedulerStore.getNamespaceHelper();
-        Document document = helper.getDocument();
-        Element root = document.getDocumentElement();
-
-        // print a list of all available trigger types
-        root.appendChild(getTriggerTypes(helper));
-
-        for (int groupIndex = 0; groupIndex < jobGroupNames.length; groupIndex++) {
-            log.debug("Creating job snapshot for group [" + jobGroupNames[groupIndex] + "]");
-            root.appendChild(getSnapshot(helper, jobGroupNames[groupIndex]));
-        }
-
-        return document;
-    }
-
-    /**
-     * Returns the snapshot of a certain job group.
-     * @param helper The namespace helper.
-     * @param group The job group.
-     * @return An XML element.
-     * @throws SchedulerException when something went wrong.
-     */
-    protected Element getSnapshot(NamespaceHelper helper, String group) throws SchedulerException {
-        JobWrapper[] jobs = getJobWrappers(group);
-        Element element;
-        try {
-            element = getStore().createSnapshot(helper, getPublication(group), jobs);
-        } catch (SchedulerException e) {
+         }
+      }catch(Exception e){
+         log.error("Restoring jobs failed: ", e);
+      }
+   }
+   /**
+    * Modifies the execution time of a job.
+    * 
+    * @param jobId
+    *           The job ID.
+    * @param jobGroup
+    *           The job group.
+    * @param startTime
+    *           The new start time.
+    * @throws SchedulerException
+    *            when the job was not found.
+    */
+   public void modifyJob(String jobId, String jobGroup, Date startTime) throws SchedulerException {
+      log.debug("Modifying job [" + jobId + "][" + jobGroup + "]");
+      JobDetail jobDetail = getScheduler().getJobDetail(jobId, jobGroup);
+      if(jobDetail == null){
+         throw new SchedulerException("Job not found!");
+      }
+      Trigger trigger = getTrigger(jobDetail.getName(), jobGroup);
+      if(trigger == null){
+         log.debug("    No trigger found.");
+      }else{
+         log.debug("    Trigger found. Setting new start time.");
+         jobDetail.setDurability(true);
+         if(startTime.after(new GregorianCalendar().getTime())){
+            log.debug("    Start time is in future - re-scheduling job.");
+            getScheduler().unscheduleJob(trigger.getName(), trigger.getGroup());
+            trigger = TriggerHelper.createSimpleTrigger(jobId, jobGroup, startTime);
+            getScheduler().scheduleJob(trigger);
+         }else{
+            log.debug("    Start time has already expired - deleting job.");
+            getScheduler().deleteJob(jobId, jobGroup);
+         }
+         try{
+            getStore().writeSnapshot(getPublication(jobGroup), getJobWrappers(jobGroup));
+         }catch(SchedulerException e){
             throw e;
-        } catch (PublicationException e) {
+         }catch(PublicationException e){
             throw new SchedulerException(e);
-        }
-        return element;
-    }
-
-    /**
-     * Returns the job wrappers for a certain job group.
-     * @param jobGroupName The job group.
-     * @return An array of job wrappers.
-     * @throws SchedulerException when something went wrong.
-     */
-    protected JobWrapper[] getJobWrappers(String jobGroupName) throws SchedulerException {
-
-        List wrappers = new ArrayList();
-        String[] jobNames = getScheduler().getJobNames(jobGroupName);
-
-        for (int nameIndex = 0; nameIndex < jobNames.length; nameIndex++) {
-            JobDetail jobDetail = getScheduler().getJobDetail(jobNames[nameIndex], jobGroupName);
-            Trigger trigger = getTrigger(jobNames[nameIndex], jobGroupName);
-            wrappers.add(new JobWrapper(jobDetail, trigger));
-        }
-
-        return (JobWrapper[]) wrappers.toArray(new JobWrapper[wrappers.size()]);
-    }
-
-    /**
-     * Return an xml description of all scheduled jobs.
-     * @return DOCUMENT ME!
-     * @exception SchedulerException if an error occurs
-     */
-    public Document getSnapshot() throws SchedulerException {
-        String[] jobGroupNames = getScheduler().getJobGroupNames();
-        return getSnapshot(jobGroupNames);
-    }
-
-    /**
-     * Restores the jobs of a certain job group from the snapshot file.
-     * @param jobGroup The job group.
-     * @throws SchedulerException when something went wrong.
-     */
-    public void restoreJobs(String jobGroup) throws SchedulerException {
-
-        log.debug("--------------------------------------------------");
-        log.debug("Restoring jobs for job group [" + jobGroup + "]");
-        log.debug("--------------------------------------------------");
-
-        try {
-            JobWrapper[] jobs = getStore().restoreJobs(getPublication(jobGroup));
-            for (int i = 0; i < jobs.length; i++) {
-                if (jobs[i].getTrigger() != null) {
-                    if (log.isDebugEnabled()) {
-                        log.debug("    Trigger time in future - scheduling job.");
-                    }
-                    addJob(jobs[i].getJobDetail(), jobs[i].getTrigger());
-                } else {
-                    if (log.isDebugEnabled()) {
-                        log.debug("    Trigger time has expired - adding job without scheduling.");
-                    }
-                    addJob(jobs[i].getJobDetail());
-                }
-            }
-        } catch (Exception e) {
-            log.error("Restoring jobs failed: ", e);
-        }
-
-    }
-
-    /**
-     * Modifies the execution time of a job.
-     * @param jobId The job ID.
-     * @param jobGroup The job group.
-     * @param startTime The new start time.
-     * @throws SchedulerException when the job was not found.
-     */
-    public void modifyJob(String jobId, String jobGroup, Date startTime)
-        throws SchedulerException {
-        log.debug("Modifying job [" + jobId + "][" + jobGroup + "]");
-
-        JobDetail jobDetail = getScheduler().getJobDetail(jobId, jobGroup);
-        if (jobDetail == null) {
-            throw new SchedulerException("Job not found!");
-        }
-
-        Trigger trigger = getTrigger(jobDetail.getName(), jobGroup);
-        if (trigger == null) {
-            log.debug("    No trigger found.");
-        } else {
-            log.debug("    Trigger found. Setting new start time.");
-            jobDetail.setDurability(true);
-            if (startTime.after(new GregorianCalendar().getTime())) {
-                log.debug("    Start time is in future - re-scheduling job.");
-                getScheduler().unscheduleJob(trigger.getName(), trigger.getGroup());
-                trigger = TriggerHelper.createSimpleTrigger(jobId, jobGroup, startTime);
-                getScheduler().scheduleJob(trigger);
-            } else {
-                log.debug("    Start time has already expired - deleting job.");
-                getScheduler().deleteJob(jobId, jobGroup);
-            }
-            try {
-                getStore().writeSnapshot(getPublication(jobGroup), getJobWrappers(jobGroup));
-            } catch (SchedulerException e) {
-                throw e;
-            } catch (PublicationException e) {
-                throw new SchedulerException(e);
-            }
-        }
-    }
-
-    /**
-     * Deletes the jobs for a certain document. This method is called when
-     * a document has been moved or deleted.
-     * @param document A document.
-     * @throws SchedulerException when something went wrong.
-     * @throws PublicationException when something went wrong.
-     */
-    public void deleteJobs(org.apache.lenya.cms.publication.Document document)
-        throws SchedulerException, PublicationException {
-            
-        log.debug("Deleting jobs for document [" + document + "]");
-            
-        String jobGroup = document.getPublication().getId();
-        JobWrapper[] jobs = getJobWrappers(jobGroup);
-        boolean changed = false;
-        for (int i = 0; i < jobs.length; i++) {
-            ServletJob job = jobs[i].getJob();
-            String documentUrl = job.getDocumentUrl(jobs[i].getJobDetail());
-            if (documentUrl.equals(document.getCompleteURL())) {
-                deleteJob(jobs[i].getJobDetail().getName(), jobGroup);
-                changed = true;
-            }
-        }
-        if (changed) {
-            getStore().writeSnapshot(getPublication(jobGroup), getJobWrappers(jobGroup));
-        }
-    }
-
+         }
+      }
+   }
+   /**
+    * Deletes the jobs for a certain document. This method is called when a document has been moved or deleted.
+    * 
+    * @param document
+    *           A document.
+    * @throws SchedulerException
+    *            when something went wrong.
+    * @throws PublicationException
+    *            when something went wrong.
+    */
+   public void deleteJobs(org.apache.lenya.cms.publication.Document document) throws SchedulerException, PublicationException {
+      log.debug("Deleting jobs for document [" + document + "]");
+      String jobGroup = document.getPublication().getId();
+      JobWrapper[] jobs = getJobWrappers(jobGroup);
+      boolean changed = false;
+      for(int i = 0; i < jobs.length; i++){
+         ServletJob job = jobs[i].getJob();
+         String documentUrl = job.getDocumentUrl(jobs[i].getJobDetail());
+         if(documentUrl.equals(document.getCompleteURL())){
+            deleteJob(jobs[i].getJobDetail().getName(), jobGroup);
+            changed = true;
+         }
+      }
+      if(changed){
+         getStore().writeSnapshot(getPublication(jobGroup), getJobWrappers(jobGroup));
+      }
+   }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org