4769l1 Listing 1. Category Class API package net.confidentialfiles.OpenReference; import java.util.*; import java.sql.*; // net.confidentialfiles.DBUtils.* is a // collection of basic functions to assembly // SQL strings from Hashtables and arrays import net.confidentialfiles.DBUtils.*; public class Category extends DatabaseTable { // Data Table definition static public String TABLE = "Category"; static public String[] FIELDS = new String[] { "CategoryID", "Name", "OrderWeight", "ParentCategory" }; static public String[] SEARCH_FIELDS = new String[] { "Name" }; static public String[] USER_FIELDS = new String[] { "Name", "OrderWeight" }; static public String PRIMARY_FIELD = "Name"; // Data Table preset values static public String ROOT_CATEGORY_ID="-1"; static public String ROOT_PARENT_CATEGORY="-2"; // A list of public methods. Implementation omitted // test if an category is leaf static public boolean isLeaf( String catid ); // add a new subcategory to "cat.ParentCategory" static public long addCategory(Hashtable cat); // delete a category and connect its children // to its parent static public boolean deleteCatNode(String catid); // get the parent category static public Hashtable getParent( String catid); // add a new level of subcategory "cat" between // "cat.ParentCategory" and its current children static public boolean expandLevel(Hashtable cat); // Get sibling categories static public Vector getSiblings(String catid); // Update category "newCat.CategoryID" with // values in this hash static public boolean updateCategory( Hashtable newCat); // Get subcategories and order them according to // "OrderWeight" field in the return // Vector; "order" is "ASC" or "DESC" static public Vector getSubCategories( String catid, String order); // Get a category's fields static public Hashtable getCatInfo(String catid); // Return a Vector containing categories on the // path from root to catid static public Vector tracePath(String catid); // search the keywords in the "SEARCH_FIELDS" // and return matched categories. The "searchOp" // is "AND" or "OR" static public Vector search(String[] keywords, String searchOp); }