1 5 package org.exoplatform.portlets.content.explorer.component; 6 7 import java.io.File ; 8 import java.util.ArrayList ; 9 import java.util.List ; 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 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 getChildren(UIExplorer uiExplorer, NodeDescriptor node) { 35 List nodeChildren = (List ) cache_.get(node.getUri()) ; 36 if(nodeChildren != null) return nodeChildren; 37 UIFileExplorer explorer = (UIFileExplorer) uiExplorer ; 38 String realPath = explorer.getRealPathBaseDir() + node.getUri() ; 39 File file = new File (realPath) ; 40 File [] children = file.listFiles() ; 41 nodeChildren = new ArrayList () ; 42 String parentUri = node.getUri() ; 43 if ("/".equals(parentUri)) parentUri = "" ; 44 for (int i = 0 ; i < children.length ; i++) { 45 File child = children[i] ; 46 String 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 |