KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > content > explorer > component > UIFileChildrenInfo


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.portlets.content.explorer.component;
6
7 import java.io.File JavaDoc;
8 import java.util.ArrayList JavaDoc;
9 import java.util.List JavaDoc;
10 import org.exoplatform.portlets.content.explorer.component.model.FileNodeDescriptor;
11 import org.exoplatform.portlets.content.explorer.component.model.NodeDescriptor;
12 import org.exoplatform.services.cache.SimpleExoCache ;
13 /**
14  * @email: tuan08@users.sourceforge.net
15  * @version: $Id: UIContentDisplayer.java,v 1.2 2004/08/07 18:11:26 tuan08 Exp $
16  */

17 public class UIFileChildrenInfo extends UIChildrenInfo {
18   private static SimpleExoCache cache_ = new SimpleExoCache(200) ;
19   
20   public void onRemove(UIExplorer uiExplorer, NodeDescriptor node) {
21     UIFileExplorer explorer = (UIFileExplorer) uiExplorer ;
22     if(!node.isLeafNode()) {
23       cache_.remove(explorer.getRelativePathBaseDir() + node.getUri()) ;
24     }
25     cache_.remove(explorer.getRelativePathBaseDir() + node.getParentUri()) ;
26   }
27   
28   public void onAddChild(UIExplorer uiExplorer, NodeDescriptor node) {
29     UIFileExplorer explorer = (UIFileExplorer) uiExplorer ;
30     cache_.remove(explorer.getRelativePathBaseDir() + node.getUri()) ;
31     onChange(uiExplorer, node) ;
32   }
33   
34   protected List JavaDoc getChildren(UIExplorer uiExplorer, NodeDescriptor node) {
35     List JavaDoc nodeChildren = (List JavaDoc) cache_.get(node.getUri()) ;
36     if(nodeChildren != null) return nodeChildren;
37     UIFileExplorer explorer = (UIFileExplorer) uiExplorer ;
38     String JavaDoc realPath = explorer.getRealPathBaseDir() + node.getUri() ;
39     File JavaDoc file = new File JavaDoc(realPath) ;
40     File JavaDoc[] children = file.listFiles() ;
41     nodeChildren = new ArrayList JavaDoc() ;
42     String JavaDoc parentUri = node.getUri() ;
43     if ("/".equals(parentUri)) parentUri = "" ;
44     for (int i = 0 ; i < children.length ; i++) {
45       File JavaDoc child = children[i] ;
46       String JavaDoc childUri = parentUri + "/" + child.getName() ;
47       NodeDescriptor uiChild = new FileNodeDescriptor(child, childUri, parentUri) ;
48       nodeChildren.add(uiChild) ;
49     }
50     cache_.put(explorer.getRelativePathBaseDir() + node.getUri(), nodeChildren) ;
51     return nodeChildren ;
52   }
53 }
Popular Tags