1 20 package org.openi.util; 21 22 import org.apache.log4j.Logger; 23 import org.openi.web.controller.admin.ManageFilesFormController; 24 import java.util.*; 25 import java.util.Collection ; 26 27 28 public class Folder { 29 private static Logger logger = Logger.getLogger(Folder.class); 30 private String path = ""; 31 private String displayName = ""; 32 private Collection children = null; 33 34 public String getPath() { 35 return path; 36 } 37 38 public String getDisplayName() { 39 return displayName; 40 } 41 42 public Collection getChildren() { 43 return children; 44 } 45 46 public void setPath(String path) { 47 this.path = path; 48 } 49 50 public void setDisplayName(String displayName) { 51 this.displayName = displayName; 52 } 53 54 public void setChildren(Collection children) { 55 this.children = children; 56 } 57 58 public static Folder findChildFolder(String path, Folder folder) { 59 Folder current = folder; 60 path = path.replace('\\', '/'); 61 logger.info("checking:" + folder.getPath()); 62 63 if (path.equals(current.getPath().replace('\\', '/'))) { 64 logger.info("found path:" + path + " at folder:" 65 + current.getPath()); 66 67 return current; 68 } 69 70 if ((current.getChildren() == null) 71 || (current.getChildren().size() == 0)) { 72 return null; 73 } 74 75 Iterator iter = current.getChildren().iterator(); 76 77 while (iter.hasNext()) { 78 Object item = iter.next(); 79 80 if (item instanceof Folder) { 81 Folder fol = findChildFolder(path, (Folder) item); 82 83 if (fol != null) { 84 return fol; 85 } 86 } 87 } 88 89 return null; 90 } 91 92 public static void buildChildList(Folder folder, List folders, List files) { 93 if (folder == null) { 94 return; 95 } 96 97 if ((folder.getChildren() == null) 98 || (folder.getChildren().size() == 0)) { 99 return; 100 } 101 102 Iterator iter = folder.getChildren().iterator(); 103 104 while (iter.hasNext()) { 105 Object item = iter.next(); 106 107 if ((files != null) && item instanceof FileItem) { 108 files.add(((FileItem) item).getPath()); 109 } else if (item instanceof Folder) { 110 Folder current = (Folder) item; 111 112 if (folders != null) { 113 folders.add(current.getPath()); 114 } 115 116 buildChildList(current, folders, files); 117 } 118 } 119 } 120 } 121 | Popular Tags |