1 20 21 package golfShop.data.item; 22 23 import java.io.*; 24 import java.util.*; 25 import com.lutris.util.Config; 26 import com.lutris.util.ConfigException; 27 import com.lutris.logging.Logger; 28 import com.lutris.logging.LogChannel; 29 import com.lutris.appserver.server.Enhydra; 30 import golfShop.data.item.CategoryDO; 31 import golfShop.data.item.CategoryStore; 32 33 34 39 public class CategoryStoreFile extends CategoryStore { 40 41 42 44 45 private static Vector allCategories = new Vector(); 46 47 48 50 protected void initializeCategoryStore() { 51 52 } 53 protected void initializeCategoryStore(String dir) { 54 55 CategoryDO newCategory = new CategoryDO(0, 0, "Main Menu"); 57 allCategories.addElement(newCategory); 58 59 dirList(dir,newCategory, ""); 61 } 62 63 64 protected boolean isCategoryInStore(long findId) { 65 Enumeration e = allCategories.elements(); 66 while (e.hasMoreElements()) { 67 CategoryDO c = (CategoryDO) e.nextElement(); 68 if (c.getObjectId() == findId) 69 return true; 70 } 71 return false; 72 } 73 74 protected CategoryDO findCategoryInStore(long findId) { 75 Enumeration e = allCategories.elements(); 76 while (e.hasMoreElements()) { 77 CategoryDO c = (CategoryDO) e.nextElement(); 78 if (c.getObjectId() == findId) { 79 return c; 80 } 81 } 82 return null; 83 } 84 85 86 88 private static int nextObjectId = 1; 89 90 private static void dirList (String root, CategoryDO pc, String dir) { 91 92 String names[] = new String [0]; String filename; 94 File path, fpath; 95 96 97 98 path = new File(root + 99 ((dir.length())>0 ? File.separator + dir : "")); 100 101 names = path.list(); 103 if (names == null) { 104 return; 105 } 106 for (int i=0; i < names.length; i++) { 107 filename = root + 108 ((dir.length())>0 ? File.separator + dir : "") + 109 File.separator + names[i]; 110 111 fpath = new File(filename); 112 if (fpath.isDirectory()) { 113 CategoryDO newCategory = new CategoryDO(nextObjectId++, 114 pc.getObjectId(), 115 names[i]); 116 117 allCategories.addElement(newCategory); 118 119 dirList(root, newCategory, dir+File.separator+names[i]); 121 } 122 if (fpath.isFile()) { 123 pc.addItem(Long.parseLong(names[i])); 124 } 125 126 } 127 } 128 129 } 130 | Popular Tags |