KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > ant > DeleteSchedulerEntryTask


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: DeleteSchedulerEntryTask.java 160149 2005-04-05 09:51:54Z michi $ */
19
20 package org.apache.lenya.cms.ant;
21
22 import java.io.File JavaDoc;
23
24 import org.apache.lenya.cms.publication.Document;
25 import org.apache.lenya.cms.publication.DocumentBuilder;
26 import org.apache.lenya.cms.publication.DocumentException;
27 import org.apache.lenya.cms.publication.Label;
28 import org.apache.lenya.cms.publication.Publication;
29 import org.apache.lenya.cms.publication.SiteTree;
30 import org.apache.lenya.cms.publication.SiteTreeNode;
31 import org.apache.lenya.cms.publication.SiteTreeNodeVisitor;
32 import org.apache.lenya.cms.scheduler.LoadQuartzServlet;
33 import org.apache.tools.ant.BuildException;
34
35 /**
36  * Moves the scheduler entry for a document.
37  */

38 public class DeleteSchedulerEntryTask extends PublicationTask implements SiteTreeNodeVisitor {
39
40     /**
41      * @see org.apache.tools.ant.Task#execute()
42      */

43     public void execute() throws BuildException {
44         try {
45             log("Document ID: [" + documentId + "]");
46             log("Area: [" + area + "]");
47
48             Publication publication = getPublication();
49             SiteTree tree = publication.getTree(area);
50             SiteTreeNode node = tree.getNode(documentId);
51
52             node.acceptSubtree(this);
53         } catch (Exception JavaDoc e) {
54             throw new BuildException(e);
55         }
56     }
57
58     private String JavaDoc area, documentId, servletContextPath;
59
60     /**
61      * @param string The area.
62      */

63     public void setArea(String JavaDoc string) {
64         area = string;
65     }
66
67     /**
68      * @param string The document-id.
69      */

70     public void setDocumentId(String JavaDoc string) {
71         documentId = string;
72     }
73
74     /**
75      * Sets the servlet context path.
76      * @param servletContextPath A string.
77      */

78     public void setServletContextPath(String JavaDoc servletContextPath) {
79         this.servletContextPath = servletContextPath;
80     }
81
82     /**
83      * @see org.apache.lenya.cms.publication.SiteTreeNodeVisitor#visitSiteTreeNode(org.apache.lenya.cms.publication.SiteTreeNode)
84      */

85     public void visitSiteTreeNode(SiteTreeNode node) throws DocumentException {
86         Publication publication = getPublication();
87
88         Label[] labels = node.getLabels();
89         for (int i = 0; i < labels.length; i++) {
90
91             String JavaDoc language = labels[i].getLanguage();
92             DocumentBuilder builder = publication.getDocumentBuilder();
93
94             try {
95                 String JavaDoc url = builder.buildCanonicalUrl(publication, area, documentId, language);
96                 Document document = builder.buildDocument(publication, url);
97
98                 String JavaDoc servletContext = new File JavaDoc(servletContextPath).getCanonicalPath();
99                 log("Deleting scheduler entry for document [" + document + "]");
100                 log("Resolving servlet [" + servletContext + "]");
101
102                 LoadQuartzServlet servlet = LoadQuartzServlet.getServlet(servletContext);
103                 servlet.deleteDocumentJobs(document);
104
105             } catch (Exception JavaDoc e) {
106                 throw new DocumentException(e);
107             }
108
109         }
110     }
111
112 }
113
Popular Tags