001: /*
002: * Enhydra Java Application Server
003: * The Initial Developer of the Original Code is Lutris Technologies Inc.
004: * Portions created by Lutris are Copyright (C) 1997-2000 Lutris Technologies
005: * Inc.
006: * All Rights Reserved.
007: *
008: * The contents of this file are subject to the Enhydra Public License Version
009: * 1.0 (the "License"); you may not use this file except in compliance with the
010: * License. You may obtain a copy of the License at
011: * http://www.enhydra.org/software/license/epl.html
012: *
013: * Software distributed under the License is distributed on an "AS IS" basis,
014: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
015: * License for the specific language governing rights and limitations under the
016: * License.
017: *
018: *
019: */
020:
021: package golfShop.data.item;
022:
023: import java.io.*;
024: import java.util.*;
025: import com.lutris.util.Config;
026: import com.lutris.util.ConfigException;
027: import com.lutris.logging.Logger;
028: import com.lutris.logging.LogChannel;
029: import com.lutris.appserver.server.Enhydra;
030: import golfShop.data.item.CategoryDO;
031: import golfShop.data.item.CategoryStore;
032:
033: /**
034: *
035: * @author Scott Pirie
036: * @version $Revision: 1.1 $
037: */
038: public class CategoryStoreFile extends CategoryStore {
039:
040: /*----------------------------------------------------------------------*/
041: // Class Data
042: /*----------------------------------------------------------------------*/
043:
044: private static Vector allCategories = new Vector();
045:
046: /*----------------------------------------------------------------------*/
047: // Class Methods
048: /*----------------------------------------------------------------------*/
049: protected void initializeCategoryStore() {
050:
051: }
052:
053: protected void initializeCategoryStore(String dir) {
054:
055: // Create the top level directory
056: CategoryDO newCategory = new CategoryDO(0, 0, "Main Menu");
057: allCategories.addElement(newCategory);
058:
059: // Fill in the subcategories
060: dirList(dir, newCategory, "");
061: }
062:
063: protected boolean isCategoryInStore(long findId) {
064: Enumeration e = allCategories.elements();
065: while (e.hasMoreElements()) {
066: CategoryDO c = (CategoryDO) e.nextElement();
067: if (c.getObjectId() == findId)
068: return true;
069: }
070: return false;
071: }
072:
073: protected CategoryDO findCategoryInStore(long findId) {
074: Enumeration e = allCategories.elements();
075: while (e.hasMoreElements()) {
076: CategoryDO c = (CategoryDO) e.nextElement();
077: if (c.getObjectId() == findId) {
078: return c;
079: }
080: }
081: return null;
082: }
083:
084: /*----------------------------------------------------------------------*/
085: // Private Methods
086: /*----------------------------------------------------------------------*/
087: private static int nextObjectId = 1;
088:
089: private static void dirList(String root, CategoryDO pc, String dir) {
090:
091: String names[] = new String[0]; // list of files in a diretory
092: String filename;
093: File path, fpath;
094:
095: path = new File(root
096: + ((dir.length()) > 0 ? File.separator + dir : ""));
097:
098: // get list of files in this dir
099: names = path.list();
100: if (names == null) {
101: return;
102: }
103: for (int i = 0; i < names.length; i++) {
104: filename = root
105: + ((dir.length()) > 0 ? File.separator + dir : "")
106: + File.separator + names[i];
107:
108: fpath = new File(filename);
109: if (fpath.isDirectory()) {
110: CategoryDO newCategory = new CategoryDO(nextObjectId++,
111: pc.getObjectId(), names[i]);
112:
113: allCategories.addElement(newCategory);
114:
115: // recursively descend dir tree
116: dirList(root, newCategory, dir + File.separator
117: + names[i]);
118: }
119: if (fpath.isFile()) {
120: pc.addItem(Long.parseLong(names[i]));
121: }
122:
123: }
124: }
125:
126: }
|