KickJava   Java API By Example, From Geeks To Geeks.

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


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: PublicationTask.java 42616 2004-03-03 12:56:33Z gregor $ */
19
20 package org.apache.lenya.cms.ant;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24
25 import org.apache.lenya.cms.publication.Publication;
26 import org.apache.lenya.cms.publication.PublicationException;
27 import org.apache.lenya.cms.publication.PublicationFactory;
28 import org.apache.lenya.cms.task.AntTask;
29 import org.apache.tools.ant.BuildException;
30 import org.apache.tools.ant.Task;
31
32 /**
33  * Abstract base class for publication-dependent Ant tasks.
34  * It requires some project parameters that are set by the AntTask.
35  */

36 public abstract class PublicationTask extends Task {
37     /** Creates a new instance of PublicationTask */
38     public PublicationTask() {}
39
40     /**
41      * Returns the publication directory.
42      *
43      * @return a the path to the publication directory as a <code>File</code>
44      */

45     protected File JavaDoc getPublicationDirectory() {
46         return new File JavaDoc(
47             getProject().getProperty(AntTask.PUBLICATION_DIRECTORY));
48     }
49     
50     /**
51      * Return the context prefix.
52      *
53      * @return the context-prefix
54      */

55     protected String JavaDoc getContextPrefix() {
56         return getProject().getProperty(AntTask.CONTEXT_PREFIX);
57     }
58
59     /**
60      * Returns the publication ID.
61      *
62      * @return the publication-id
63      */

64     protected String JavaDoc getPublicationId() {
65         return getProject().getProperty(AntTask.PUBLICATION_ID);
66     }
67
68     /**
69      * Returns the servlet context (e.g., <code>tomcat/webapp/lenya</code>)
70      *
71      * @return the servlet-context
72      */

73     protected File JavaDoc getServletContext() {
74         return new File JavaDoc(getProject().getProperty(AntTask.SERVLET_CONTEXT_PATH));
75     }
76
77     /**
78      * Get the publication
79      *
80      * @return the publication
81      *
82      * @throws BuildException if the publication could not be found
83      */

84     protected Publication getPublication() throws BuildException {
85         try {
86             return PublicationFactory.getPublication(
87                 getPublicationId(),
88                 getServletContext().getCanonicalPath());
89         } catch (IOException JavaDoc e) {
90             throw new BuildException(e);
91         } catch (PublicationException e) {
92             throw new BuildException(e);
93         }
94     }
95
96     /**
97      * Utility method for assertion that a string is != null and != ""
98      *
99      * @param string the string to check
100      */

101     protected void assertString(String JavaDoc string) {
102         assert(string != null) && !string.equals("");
103     }
104 }
105
Popular Tags