KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portal > impl > NodeImpl


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.portal.impl;
6
7 import java.util.* ;
8 import org.exoplatform.commons.utils.ExpressionUtil;
9 import org.exoplatform.services.portal.PortalACL;
10 import org.exoplatform.services.portal.model.Node;
11 import org.exoplatform.services.portal.model.NodeVisitor;
12 import org.exoplatform.services.portal.model.PageNode;
13
14 /**
15  * Thu, Apr 01, 2004 @ 11:02
16  * @author: Tuan Nguyen
17  * @email: tuan08@users.sourceforge.net
18  * @version: $Id: NodeImpl.java,v 1.8 2004/10/27 03:11:17 tuan08 Exp $
19  */

20 public class NodeImpl extends PageNode implements Node {
21   transient private Node parent ;
22   transient String JavaDoc resolvedLabel_ ;
23   transient private int level ;
24   transient boolean selected ;
25   transient boolean share = false ;
26   transient boolean visible = true ;
27   
28   public NodeImpl() {
29     
30   }
31   
32   public NodeImpl(String JavaDoc uri , String JavaDoc name, String JavaDoc label) {
33     this.uri = uri ;
34     this.name = name;
35     this.label = label ;
36   }
37   
38   public NodeImpl(Node nodeImpl , Node parent, int level) {
39     copyPageNode((PageNode)nodeImpl) ;
40     this.parent = parent ;
41     this.level = level ;
42     this.selected = nodeImpl.isSelectedPath() ;
43     this.share = nodeImpl.isShare() ;
44     this.visible = nodeImpl.isVisible() ;
45     List list = nodeImpl.getChildren() ;
46     if (list != null) {
47       children = new ArrayList(3) ;
48       for (int i = 0; i < list.size(); i++) {
49         nodeImpl = (NodeImpl)list.get(i) ;
50         Node childNode = new NodeImpl(nodeImpl, this , level + 1) ;
51         children.add(childNode) ;
52       }
53     }
54   }
55   
56   public NodeImpl(PageNode pageNode , Node parent, int level) {
57     copyPageNode(pageNode) ;
58     this.parent = parent ;
59     this.level = level ;
60     selected = false ;
61     List list = pageNode.getChildren() ;
62     if (list != null) {
63       children = new ArrayList(3) ;
64       for (int i = 0; i < list.size(); i++) {
65         pageNode = (PageNode)list.get(i) ;
66         Node childNode = new NodeImpl(pageNode, this , level + 1) ;
67         children.add(childNode) ;
68       }
69     }
70   }
71   
72   private void copyPageNode(PageNode node) {
73     this.uri = node.getUri();
74     this.name = node.getName();
75     this.label = node.getLabel();
76     this.viewPermission = node.getViewPermission();
77     this.editPermission = node.getEditPermission() ;
78     this.icon = node.getIcon();
79     this.pageReference = node.getClonePageReference() ;
80     this.description = node.getDescription();
81   }
82   
83   public void setLabel(String JavaDoc s) {
84     super.setLabel(s) ;
85     resolvedLabel_ = s ;
86   }
87   
88   public String JavaDoc getResolvedLabel() { return resolvedLabel_ ; }
89   public void setResolvedLabel(ResourceBundle res) {
90     resolvedLabel_ = ExpressionUtil.getExpressionValue(res, label) ;
91   }
92   
93   public boolean isShare() { return share ; }
94   public void setShare(boolean b) {
95     share = b ;
96     if(children == null) return ;
97     for(int i = 0; i < children.size(); i++) {
98         NodeImpl child = (NodeImpl) children.get(i) ;
99       child.setShare(b) ;
100     }
101   }
102   
103   public boolean isVisible() { return visible ; }
104   public void setVisible(PortalACL acl, String JavaDoc owner, String JavaDoc remoteUser) {
105     if(PortalACL.ANY_PERMISSION.equals(getViewPermission())) visible = true ;
106     if(!visible) visible = owner.equals(remoteUser) ;
107     if(children == null) return ;
108     for(int i = 0; i < children.size(); i++) {
109       NodeImpl child = (NodeImpl) children.get(i) ;
110       child.setVisible(acl, owner, remoteUser) ;
111     }
112   }
113   
114   public void setParent(Node node) { parent = node ;}
115   public Node getParent() { return parent ; }
116
117   public int getLevel() { return level ; }
118   
119   public void setSelectedPath(boolean b) {
120     selected = b ;
121     if(parent != null) {
122       parent.setSelectedPath(b);
123     }
124   }
125   public boolean isSelectedPath() {
126     return selected ;
127   }
128   
129   public Node getChild(int pos) {
130     if (pos >= children.size()) return null ;
131     return (Node)children.get(pos) ;
132   }
133
134   public void addChild(Node node) {
135     node.setParent(this) ;
136     if (children == null) children = new ArrayList(3) ;
137     children.add(node) ;
138   }
139
140   public Node removeChild(int pos) {
141     if (pos >= children.size()) return null ;
142     NodeImpl node = (NodeImpl) children.remove(pos) ;
143     node.setParent(null) ;
144     return node ;
145   }
146   
147   public Node removeChild(String JavaDoc uri) {
148     if(children == null) return null ;
149     for (Iterator i = children.iterator() ; i.hasNext() ; ) {
150         NodeImpl child = (NodeImpl) i.next() ;
151         if(child.getUri().equals(uri)) {
152             i.remove() ;
153             child.setParent(null) ;
154         return child ;
155       }
156     }
157     return null ;
158   }
159   
160   public int getChildrenSize() {
161     if(children == null ) return 0 ;
162     return children.size() ;
163   }
164   
165   public Node findNode(String JavaDoc uri) {
166     if(this.uri.equals(uri)) return this ;
167     if (children == null) return null ;
168     for(int i = 0; i < children.size(); i++) {
169       Node child = (Node) children.get(i) ;
170       Node result = child.findNode(uri) ;
171       if(result != null) return result ;
172     }
173     return null ;
174   }
175   
176   public boolean hasChild(String JavaDoc name) {
177     if(children == null ) return false ;
178     for(int i = 0; i < children.size(); i++) {
179       NodeImpl child = (NodeImpl) children.get(i) ;
180       if(name.equals(child.getName())) return true ;
181     }
182     return false ;
183   }
184   
185   public NodeImpl getThisNode() { return this ; }
186   
187   public void visit(NodeVisitor visitor) {
188     visitor.visit(this) ;
189     if(children != null) {
190       for(int i = 0 ; i < children.size(); i++) {
191         NodeImpl child = (NodeImpl) children.get(i) ;
192         child.visit(visitor) ;
193       }
194     }
195   }
196 }
Popular Tags