KickJava   Java API By Example, From Geeks To Geeks.

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


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: MoveSiteTreeNodeTask.java 160149 2005-04-05 09:51:54Z michi $ */
19
20 package org.apache.lenya.cms.ant;
21
22 import org.apache.lenya.cms.publication.SiteTree;
23 import org.apache.lenya.cms.publication.Publication;
24 import org.apache.tools.ant.BuildException;
25
26 /**
27  * Task to move a node amongst the siblings
28  */

29 public class MoveSiteTreeNodeTask extends PublicationTask {
30
31     public static final String JavaDoc UP = "up";
32     public static final String JavaDoc DOWN = "down";
33
34     /**
35      * Returns the document ID.
36      * @return A string.
37      */

38     protected String JavaDoc getDocumentId() {
39         return documentId;
40     }
41
42     /**
43      * Sets the document ID.
44      * @param documentId A string.
45      */

46     public void setDocumentId(String JavaDoc documentId) {
47         this.documentId = documentId;
48     }
49
50     /**
51      * Returns the direction.
52      * @return A string.
53      */

54     protected String JavaDoc getDirection() {
55         return direction;
56     }
57
58     /**
59      * Sets the direction.
60      * @param direction A string.
61      */

62     public void setDirection(String JavaDoc direction) {
63         this.direction = direction;
64     }
65
66     /**
67      * @see org.apache.tools.ant.Task#execute()
68      */

69     public void execute() throws BuildException {
70         
71         log("Moving sitetree node:");
72         log(" Document ID: [" + getDocumentId() + "]");
73         log(" Direction: [" + getDirection() + "]");
74
75         try {
76             SiteTree tree = getPublication().getTree(Publication.AUTHORING_AREA);
77             if (getDirection().equals(UP)) {
78                 tree.moveUp(getDocumentId());
79             } else if (getDirection().equals(DOWN)) {
80                 tree.moveDown(getDocumentId());
81             } else {
82                 throw new BuildException(
83                     "The direction in which the node should be moved isn't specified.");
84             }
85             tree.save();
86         } catch (BuildException e) {
87             throw e;
88         } catch (Exception JavaDoc e) {
89             throw new BuildException(e);
90         }
91     }
92     
93     private String JavaDoc direction;
94     private String JavaDoc documentId;
95
96 }
97
Popular Tags