View Javadoc

1   /*
2    * Copyright 2007 Hippo
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" 
12   * BASIS, 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  package nl.hippo.portal.cms.repository;
17  
18  import java.util.Iterator;
19  import java.util.List;
20  import java.util.TreeSet;
21  
22  import nl.hippo.client.api.content.Document;
23  
24  public class WebdavCollection extends WebdavResource {
25  
26      private TreeSet children;
27  
28      public WebdavCollection(Document document){
29          super(document);
30          children=new TreeSet();
31      }
32      
33      public TreeSet getChildren() {
34          return children;
35      }
36  
37     public void addChild(WebdavResource n){
38         this.children.add(n);
39     }
40     
41     public void addChildren(List children){
42         this.children.addAll(children);
43     }
44     
45     public int countNodes(){
46         int result = 0;
47         for (Iterator iter = children.iterator(); iter.hasNext(); result++) {
48             WebdavResource node = (WebdavResource) iter.next();
49             if (node instanceof WebdavCollection){
50                 result+=((WebdavCollection)node).countNodes();
51             }
52         }     
53         return result;
54     }
55         
56  }