KickJava   Java API By Example, From Geeks To Geeks.

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


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: ChangeVisibilityTask.java 42616 2004-09-22 12:56:33Z jaf $ */
19
20 package org.apache.lenya.cms.ant;
21
22 import org.apache.lenya.cms.publication.SiteTree;
23 import org.apache.lenya.cms.publication.DocumentException;
24 import org.apache.lenya.cms.publication.SiteTreeException;
25 import org.apache.lenya.cms.publication.SiteTreeNode;
26 import org.apache.lenya.cms.publication.SiteTreeNodeImpl;
27 import org.apache.tools.ant.BuildException;
28
29 /**
30  * Ant task to change the visbility of a node in the navigation.
31  */

32 public class ChangeVisibilityTask extends PublicationTask {
33     private String JavaDoc documentid;
34     private String JavaDoc area;
35
36     /**
37      * Creates a new instance of InsertLabelTask
38      */

39     public ChangeVisibilityTask() {
40         super();
41     }
42
43     /**
44      * Get the area of the site tree.
45      *
46      * @return the area of the tree.
47      */

48     protected String JavaDoc getArea() {
49         return area;
50     }
51
52     /**
53      * Set the area.
54      *
55      * @param area the area.
56      */

57     public void setArea(String JavaDoc area) {
58         this.area = area;
59     }
60
61     /**
62      * Return the document-id corresponding to the node to delete.
63      *
64      * @return string The document-id.
65      */

66     protected String JavaDoc getDocumentid() {
67         return documentid;
68     }
69
70     /**
71      * Set the value of the document-id corresponding to the node to delete.
72      *
73      * @param string The document-id.
74      */

75     public void setDocumentid(String JavaDoc string) {
76         documentid = string;
77     }
78
79     /**
80      * Change the visibility of an existing node in the tree.
81      *
82      * @param documentid the document-id of the document.
83      * @param area determines in which sitetree the label is to be renamed
84      *
85      * @throws SiteTreeException if an error occurs.
86      */

87     public void changeVisibility(
88         String JavaDoc documentid,
89         String JavaDoc area)
90         throws SiteTreeException, DocumentException {
91
92         SiteTree tree = null;
93         tree = getPublication().getTree(area);
94         SiteTreeNode node = tree.getNode(documentid);
95
96         if (node == null) {
97             throw new DocumentException(
98                 "Document-id " + documentid + " not found.");
99         }
100  
101         //if node is visible change to fale and vice versa
102
String JavaDoc visibility = "false";
103         if (!node.visibleInNav()) visibility = "true";
104         node.setNodeAttribute(SiteTreeNodeImpl.VISIBLEINNAV_ATTRIBUTE_NAME, visibility);
105
106         tree.save();
107     }
108
109     /** (non-Javadoc)
110      * @see org.apache.tools.ant.Task#execute()
111      */

112     public void execute() throws BuildException {
113         try {
114             log("document-id corresponding to the node: " + getDocumentid());
115             log("area: " + getArea());
116             changeVisibility(
117                 getDocumentid(),
118                 getArea());
119         } catch (Exception JavaDoc e) {
120             throw new BuildException(e);
121         }
122     }
123 }
124
Popular Tags