You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2004/01/09 12:14:40 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/scheduler SchedulerWrapper.java SchedulerStore.java LoadQuartzServlet.java
andreas 2004/01/09 03:14:40
Modified: src/java/org/apache/lenya/cms/publication
CollectionImpl.java Collection.java
src/java/org/apache/lenya/cms/scheduler
SchedulerWrapper.java SchedulerStore.java
LoadQuartzServlet.java
Added: src/java/org/apache/lenya/cms/ant
DeleteSchedulerEntryTask.java
Removed: src/java/org/apache/lenya/cms/ant
MoveSchedulerEntryTask.java
Log:
deleting scheduler entry when document is moved
Revision Changes Path
1.7 +8 -1 cocoon-lenya/src/java/org/apache/lenya/cms/publication/CollectionImpl.java
Index: CollectionImpl.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/CollectionImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CollectionImpl.java 30 Dec 2003 18:18:56 -0000 1.6
+++ CollectionImpl.java 9 Jan 2004 11:14:39 -0000 1.7
@@ -292,4 +292,11 @@
return documents().indexOf(document);
}
+ /**
+ * @see org.apache.lenya.cms.publication.Collection#size()
+ */
+ public int size() throws DocumentException {
+ return documents().size();
+ }
+
}
1.4 +8 -1 cocoon-lenya/src/java/org/apache/lenya/cms/publication/Collection.java
Index: Collection.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/Collection.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Collection.java 10 Dec 2003 09:41:22 -0000 1.3
+++ Collection.java 9 Jan 2004 11:14:39 -0000 1.4
@@ -123,4 +123,11 @@
*/
int getFirstPosition(Document document) throws DocumentException;
+ /**
+ * Returns the number of documents in this collection.
+ * @return An integer value.
+ * @throws DocumentException when something went wrong.
+ */
+ int size() throws DocumentException;
+
}
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ant/DeleteSchedulerEntryTask.java
Index: DeleteSchedulerEntryTask.java
===================================================================
/*
* $Id: DeleteSchedulerEntryTask.java,v 1.1 2004/01/09 11:14:39 andreas Exp $ <License>
*
* ============================================================================ The Apache Software
* License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica- tion, are permitted
* provided that the following conditions are met: 1. Redistributions of source code must retain
* the above copyright notice, this list of conditions and the following disclaimer. 2.
* Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided
* with the distribution. 3. The end-user documentation included with the redistribution, if any,
* must include the following acknowledgment: "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may
* appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4.
* The names "Apache Lenya" and "Apache Software Foundation" must not be used to endorse or promote
* products derived from this software without prior written permission. For written permission,
* please contact apache@apache.org. 5. Products derived from this software may not be called
* "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache
* Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals on behalf of the
* Apache Software Foundation and was originally created by Michael Wechner <mi...@apache.org> .
* For more information on the Apache Soft- ware Foundation, please see <http://www.apache.org/> .
*
* Lenya includes software developed by the Apache Software Foundation, W3C, DOM4J Project,
* BitfluxEditor, Xopus, and WebSHPINX. </License>
*/
package org.apache.lenya.cms.ant;
import java.io.File;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentBuilder;
import org.apache.lenya.cms.publication.DocumentException;
import org.apache.lenya.cms.publication.Label;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.SiteTree;
import org.apache.lenya.cms.publication.SiteTreeNode;
import org.apache.lenya.cms.publication.SiteTreeNodeVisitor;
import org.apache.lenya.cms.scheduler.LoadQuartzServlet;
import org.apache.tools.ant.BuildException;
/**
* Moves the scheduler entry for a document.
*
* @author <a href="andreas@apache.org">Andreas Hartmann</a>
*/
public class DeleteSchedulerEntryTask extends PublicationTask implements SiteTreeNodeVisitor {
/**
* @see org.apache.tools.ant.Task#execute()
*/
public void execute() throws BuildException {
try {
log("Document ID: [" + documentId + "]");
log("Area: [" + area + "]");
Publication publication = getPublication();
SiteTree tree = publication.getSiteTree(area);
SiteTreeNode node = tree.getNode(documentId);
node.acceptSubtree(this);
} catch (Exception e) {
throw new BuildException(e);
}
}
private String area, documentId, servletContextPath;
/**
* @param string The area.
*/
public void setArea(String string) {
area = string;
}
/**
* @param string The document-id.
*/
public void setDocumentId(String string) {
documentId = string;
}
/**
* Sets the servlet context path.
* @param servletContextPath A string.
*/
public void setServletContextPath(String servletContextPath) {
this.servletContextPath = servletContextPath;
}
/**
* @see org.apache.lenya.cms.publication.SiteTreeNodeVisitor#visitSiteTreeNode(org.apache.lenya.cms.publication.SiteTreeNode)
*/
public void visitSiteTreeNode(SiteTreeNode node) throws DocumentException {
Publication publication = getPublication();
Label[] labels = node.getLabels();
for (int i = 0; i < labels.length; i++) {
String language = labels[i].getLanguage();
DocumentBuilder builder = publication.getDocumentBuilder();
try {
String url = builder.buildCanonicalUrl(publication, area, documentId, language);
Document document = builder.buildDocument(publication, url);
String servletContext = new File(servletContextPath).getCanonicalPath();
log("Deleting scheduler entry for document [" + document + "]");
log("Resolving servlet [" + servletContext + "]");
LoadQuartzServlet servlet = LoadQuartzServlet.getServlet(servletContext);
servlet.deleteDocumentJobs(document);
} catch (Exception e) {
throw new DocumentException(e);
}
}
}
}
1.26 +35 -7 cocoon-lenya/src/java/org/apache/lenya/cms/scheduler/SchedulerWrapper.java
Index: SchedulerWrapper.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/scheduler/SchedulerWrapper.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- SchedulerWrapper.java 7 Jan 2004 18:37:23 -0000 1.25
+++ SchedulerWrapper.java 9 Jan 2004 11:14:39 -0000 1.26
@@ -416,7 +416,7 @@
return document;
}
-
+
/**
* Returns the snapshot of a certain job group.
* @param helper The namespace helper.
@@ -436,7 +436,7 @@
}
return element;
}
-
+
/**
* Returns the job wrappers for a certain job group.
* @param jobGroupName The job group.
@@ -444,7 +444,7 @@
* @throws SchedulerException when something went wrong.
*/
protected JobWrapper[] getJobWrappers(String jobGroupName) throws SchedulerException {
-
+
List wrappers = new ArrayList();
String[] jobNames = getScheduler().getJobNames(jobGroupName);
@@ -453,7 +453,7 @@
Trigger trigger = getTrigger(jobNames[nameIndex], jobGroupName);
wrappers.add(new JobWrapper(jobDetail, trigger));
}
-
+
return (JobWrapper[]) wrappers.toArray(new JobWrapper[wrappers.size()]);
}
@@ -473,11 +473,11 @@
* @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++) {
@@ -537,6 +537,34 @@
} 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));
}
}
1.2 +2 -33 cocoon-lenya/src/java/org/apache/lenya/cms/scheduler/SchedulerStore.java
Index: SchedulerStore.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/scheduler/SchedulerStore.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SchedulerStore.java 7 Jan 2004 18:37:23 -0000 1.1
+++ SchedulerStore.java 9 Jan 2004 11:14:40 -0000 1.2
@@ -301,37 +301,6 @@
}
/**
- * Called when a document has moved. This updates the corresponding
- * entry in the scheduler store.
- * @param source The source document.
- * @param destination The destination document.
- */
- public void documentMoved(
- org.apache.lenya.cms.publication.Document source,
- org.apache.lenya.cms.publication.Document destination)
- throws SchedulerException {
-
- Publication publication = source.getPublication();
- if (!publication.equals(destination.getPublication())) {
- throw new SchedulerException("Source and destination document must be in the same publication!");
- }
-
- JobWrapper[] wrappers = restoreJobs(publication);
- boolean changed = false;
- for (int i = 0; i < wrappers.length; i++) {
- ServletJob job = wrappers[i].getJob();
- String documentUrl = job.getDocumentUrl(wrappers[i].getJobDetail());
- if (documentUrl.equals(source.getCompleteURL())) {
- job.setDocumentUrl(wrappers[i].getJobDetail(), destination.getCompleteURL());
- changed = true;
- }
- }
- if (changed) {
- writeSnapshot(publication, wrappers);
- }
- }
-
- /**
* Returns the job elements of a publication.
* @param publication
* @return
1.35 +89 -3 cocoon-lenya/src/java/org/apache/lenya/cms/scheduler/LoadQuartzServlet.java
Index: LoadQuartzServlet.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/scheduler/LoadQuartzServlet.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- LoadQuartzServlet.java 7 Jan 2004 18:37:23 -0000 1.34
+++ LoadQuartzServlet.java 9 Jan 2004 11:14:40 -0000 1.35
@@ -55,6 +55,9 @@
*/
package org.apache.lenya.cms.scheduler;
+import org.apache.lenya.cms.publication.DocumentBuildException;
+import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.publication.PublicationException;
import org.apache.lenya.cms.publication.PublicationFactory;
import org.apache.lenya.cms.publishing.PublishingEnvironment;
import org.apache.lenya.cms.scheduler.xml.TriggerHelper;
@@ -103,6 +106,7 @@
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";
/**
@@ -114,6 +118,11 @@
}
/**
+ * 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.
@@ -121,10 +130,21 @@
public void init(ServletConfig config) throws ServletException {
super.init(config);
- this.servletContext = config.getServletContext();
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 {
@@ -218,6 +238,7 @@
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.
@@ -277,6 +298,17 @@
} 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
@@ -294,6 +326,19 @@
}
/**
+ * 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.
@@ -357,5 +402,46 @@
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;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org