kom.gateway
Class DBHigh

java.lang.Object
  |
  +--kom.gateway.DBLow
        |
        +--kom.gateway.DBHigh
Direct Known Subclasses:
KOMutil

public class DBHigh
extends DBLow

High (or intermediate) level database handling


Field Summary
(package private) static java.lang.String AdminURL
          URL for Administrator (distinguished user)
(package private) static KomData cache
          Cache for form data
(package private) static java.lang.String HomeURL
          URL for Home
(package private) static java.lang.String UsersURL
          URL for Users
 
Fields inherited from class kom.gateway.DBLow
absCDBpath, config, fSep, fSeparator, msgAuth, msgParts
 
Constructor Summary
DBHigh(ServerConfig config)
          Class constructor
 
Method Summary
 void addContent(java.lang.String ref, KomData kd)
          Adds cont* (content) record to the file database
 void addContent(java.lang.String ref, java.lang.String key, KomData kd)
          Adds data to the file database
(package private)  void addDraft(java.lang.String ref, KomData kd, java.lang.String xnr)
          Adds a file to the draft database
 void addInfo(java.lang.String key, KomData kd)
          Adds data to the main info file.
 void addLast(java.lang.String user, java.lang.String curr)
          Saves date-time of last notification sent for user
 void addMember(java.lang.String act, java.lang.String user, KomData kd)
          Adds member data to an activity
 void addNews(java.lang.String user, java.lang.String act, KomData kd)
          Adds data to a user news database part
 void addObj(java.lang.String ref, java.lang.String part, java.lang.String data)
          Adds (appends) data to the file database
 void addObj(java.lang.String ref, java.lang.String part, java.lang.String data, boolean apnd)
          Adds data to the file database
 void addObject(java.lang.String ref, KomData kd)
          Adds object data to the database
 void addObject(java.lang.String ref, java.lang.String key, KomData kd)
          Adds "labeled" object data to the database
 java.lang.String addQuery(java.lang.String userRef, KomData kd)
          Stores a query in the query database.
 void cleanDrafts(java.lang.String ref)
          Removes any left-over MIME-formatted draft files
 java.lang.String contentCount(java.lang.String ref)
          Counts valid cont* (content) records
 void createNews(java.lang.String user, KomData kd)
          Create a new news file for a user
 int depth(java.lang.String id)
          Determines the "depth" of a URL by counting slashes.
(package private)  boolean expungeRef(java.lang.String ref)
          Deletes all files accessed via a reference (directory and subdirs)
 java.lang.String findContent(java.lang.String ref)
          Finds data in the file database
 KomData findDraft(java.lang.String ref, java.lang.String xnr)
          Finds data for a draft (uncommitted entry)
 java.lang.String findDraftData(java.lang.String ref, java.lang.String xnr)
          Finds data for a draft (uncommitted entry)
 java.lang.String findInfo()
          Finds data in the file database
 java.lang.String findMemb(java.lang.String act)
          Finds member data for an activity
 java.lang.String findNews(java.lang.String user)
          Finds news data for a user
 java.lang.String findObject(java.lang.String ref)
          Finds data in the file database
 java.lang.String findObject(java.lang.String ref, java.lang.String part)
          Finds data in the file database
 java.lang.String findQuery(java.lang.String userRef, java.lang.String queryRef)
          Retrieves a query from the query database.
 java.lang.String getFormContents(java.lang.String form)
          Gets data for a form (HTML template)
 java.lang.String getQryDefault()
          Gets default value fields for a query
(package private)  java.lang.String[] getQueries(java.lang.String userRef)
           
 java.lang.String getseq(java.lang.String ref)
          Gets the next free sequence number for a ref.
(package private)  java.lang.String[] getStringValues(java.lang.String ref, java.lang.String part, java.lang.String key)
          Gets a String array of values from an object part
(package private)  java.util.Vector getValues(java.lang.String ref, java.lang.String part, java.lang.String key)
          Gets a vector of values from an object part
(package private)  void invalidateCount(java.lang.String ref)
           
static boolean isEmpty(java.lang.String s)
          Is the string empty or null?
static boolean isStandard(java.lang.String url)
          Determines if a url refers to one of a few standard directories
 java.lang.String[] listDraft(java.lang.String ref)
          Makes a list of "drafts", i e uncommitted message file names
 void makeArea(java.lang.String path)
          Allocates a database area if it does not exist already.
 void modObject(java.lang.String ref, KomData kd)
          Modifies object data in the database
 boolean msgExists(java.lang.String ref)
          Finds any old mail
(package private)  java.lang.String nextDraft(java.lang.String ref, KomData kd)
           
 boolean queryExists(java.lang.String userRef, java.lang.String queryRef)
          Checks if query with specified ref exists in the database.
 java.lang.String ref2path(java.lang.String ref, java.lang.String part)
          Converts a reference to an object, plus a part identification, to a path in the database (relative to the document root).
 boolean refExists(java.lang.String ref)
          Checks for existing KOM object
 void removeDraft(java.lang.String ref, java.lang.String xnr, java.lang.String old)
          Removes a message from the draft database
 void removeQuery(java.lang.String userRef, java.lang.String queryRef)
          Removes a query from the query database
 void replaceObject(java.lang.String ref, KomData kd)
          Replaces an object
 java.lang.String Stream2String(java.io.InputStream is)
          Creates a String from an InputStream
 java.io.InputStream String2Stream(java.lang.String data)
          Creates an InputStream from a String
 java.io.InputStream StringBuffer2Stream(java.lang.StringBuffer data)
          Creates an InputStream from a StringBuffer
(package private)  java.lang.String updateCount(java.lang.String ref)
          Updates count of live objects at this level.
 java.lang.String updCount(java.lang.String ref, java.lang.String key, boolean create, java.lang.String value)
          Updates a "count" object part (e g "seq")
 java.lang.String updref(java.lang.String ref)
          Gets a reference for the next child of a reference, creating a new area if necessary.
 java.lang.String updseq(java.lang.String ref)
          Updates a "seq" object part
 
Methods inherited from class kom.gateway.DBLow
accessPart, addFile, areaExists, basedRef, createArea, debugLog, errorLog, expungeFile, File2Stream, File2String, findPart, getFile, getFileContents, getFileStream, getPath, getStandard, isMailSpool, lastModified, length, listFiles, makePart, msgPartStream, partfile, partpath, printStackTrace, readObject, removeFile, replaceMime, updseq1, validate, validate, writeObject
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

HomeURL

static final java.lang.String HomeURL
URL for Home

UsersURL

static final java.lang.String UsersURL
URL for Users

AdminURL

static final java.lang.String AdminURL
URL for Administrator (distinguished user)

cache

static KomData cache
Cache for form data
Constructor Detail

DBHigh

public DBHigh(ServerConfig config)
Class constructor
Parameters:
config - Server configuration data
Method Detail

getFormContents

public java.lang.String getFormContents(java.lang.String form)
Gets data for a form (HTML template)
Parameters:
form - Name of form
Returns:
Form data as a String

getQryDefault

public java.lang.String getQryDefault()
Gets default value fields for a query
Returns:
KomData-formatted String

msgExists

public boolean msgExists(java.lang.String ref)
Finds any old mail
Parameters:
ref - Like "/mail/47/"
Returns:
true if it exists in the mail database.

refExists

public boolean refExists(java.lang.String ref)
Checks for existing KOM object
Parameters:
ref - Reference to object
Returns:
true if an object with that reference exists in the database

addObject

public void addObject(java.lang.String ref,
                      KomData kd)
Adds object data to the database
Parameters:
ref - Object reference
kd - Object data as a KomData instance

modObject

public void modObject(java.lang.String ref,
                      KomData kd)
Modifies object data in the database
Parameters:
ref - Object reference
kd - Object data as a KomData instance

addObject

public void addObject(java.lang.String ref,
                      java.lang.String key,
                      KomData kd)
Adds "labeled" object data to the database
Parameters:
ref - Object reference
key - Key for labeling the data
kd - Object data as a KomData instance

findObject

public java.lang.String findObject(java.lang.String ref)
Finds data in the file database
Returns:
Contents of the data file

addContent

public void addContent(java.lang.String ref,
                       KomData kd)
Adds cont* (content) record to the file database
Parameters:
ref - Object ref
kd - Content data

invalidateCount

void invalidateCount(java.lang.String ref)

contentCount

public java.lang.String contentCount(java.lang.String ref)
Counts valid cont* (content) records
Parameters:
ref - What count refers to

addContent

public void addContent(java.lang.String ref,
                       java.lang.String key,
                       KomData kd)
Adds data to the file database
Parameters:
ref - Object ref
key - Data key
kd - Data content

findContent

public java.lang.String findContent(java.lang.String ref)
Finds data in the file database
Returns:
Contents of the data file

addLast

public void addLast(java.lang.String user,
                    java.lang.String curr)
Saves date-time of last notification sent for user
Parameters:
user - User ref
curr - Current time-date

addNews

public void addNews(java.lang.String user,
                    java.lang.String act,
                    KomData kd)
Adds data to a user news database part
Parameters:
user - User ref
act - Activity ref
kd - (Additional) news data

createNews

public void createNews(java.lang.String user,
                       KomData kd)
Create a new news file for a user
Parameters:
user - User reference
kd - Data to put in the file

findNews

public java.lang.String findNews(java.lang.String user)
Finds news data for a user
Parameters:
user - Ref to a user
Returns:
Contents of "news" file for user

addMember

public void addMember(java.lang.String act,
                      java.lang.String user,
                      KomData kd)
Adds member data to an activity
Parameters:
act - Activity reference
user - User ref
kd - (Additional) member data

findMemb

public java.lang.String findMemb(java.lang.String act)
Finds member data for an activity
Parameters:
act - Activity reference
Returns:
Contents of the "memb" file

updateCount

java.lang.String updateCount(java.lang.String ref)
Updates count of live objects at this level.

addObj

public void addObj(java.lang.String ref,
                   java.lang.String part,
                   java.lang.String data)
Adds (appends) data to the file database
Parameters:
ref - Object reference
part - Part of object (e g "cont")
data - Data to put in the file

addObj

public void addObj(java.lang.String ref,
                   java.lang.String part,
                   java.lang.String data,
                   boolean apnd)
Adds data to the file database
Parameters:
ref - Object reference
part - Part of object (e g "cont")
data - Data to put in the file
apnd - True if data should be appended, false if overwriting

findObject

public java.lang.String findObject(java.lang.String ref,
                                   java.lang.String part)
Finds data in the file database
Returns:
Contents of the data file

ref2path

public java.lang.String ref2path(java.lang.String ref,
                                 java.lang.String part)
Converts a reference to an object, plus a part identification, to a path in the database (relative to the document root).
Parameters:
ref - Main reference
part - Part identification
Returns:
path commencing with "/CDB/"

addInfo

public void addInfo(java.lang.String key,
                    KomData kd)
Adds data to the main info file.
Parameters:
key - Key for retrieving the data
kd - Data to put in the file

findInfo

public java.lang.String findInfo()
Finds data in the file database
Returns:
Contents of the data file

addQuery

public java.lang.String addQuery(java.lang.String userRef,
                                 KomData kd)
Stores a query in the query database. Attribue Ploc must be set, since it is used as a key for the query. Attempts to store a query when Ploc is not set will always fail and return null. Hence, a programmer must explicitly write code for this. Adding a query with same Ploc as a previously stored query will erase the old one. Queries are stored in the user's database segment.
Parameters:
userRef - User reference.
kd - Query to put in the database.
Returns:
Reference for the stored query, to be used when retrieving query with findQuery.

findQuery

public java.lang.String findQuery(java.lang.String userRef,
                                  java.lang.String queryRef)
Retrieves a query from the query database.
Parameters:
userRef - User reference.
queryRef - Thread reference.
Returns:
String representation of KOMquery if query is found, which can be used with a KOMquery constructor, null otherwise.

queryExists

public boolean queryExists(java.lang.String userRef,
                           java.lang.String queryRef)
Checks if query with specified ref exists in the database.
Parameters:
userRef - User reference.
queryRef - Query reference.
Returns:
True if query exist, false otherwise.

removeQuery

public void removeQuery(java.lang.String userRef,
                        java.lang.String queryRef)
Removes a query from the query database
Parameters:
userRef - Reference to user
queryRef - Reference to query to remove from the database

getQueries

java.lang.String[] getQueries(java.lang.String userRef)

addDraft

void addDraft(java.lang.String ref,
              KomData kd,
              java.lang.String xnr)
Adds a file to the draft database
Parameters:
ref - Parent ref for draft
kd - Data to put in the draft
Returns:
Draft id (last part of draft ref) "xnn"

nextDraft

java.lang.String nextDraft(java.lang.String ref,
                           KomData kd)

String2Stream

public java.io.InputStream String2Stream(java.lang.String data)
Creates an InputStream from a String
Parameters:
data - String
Returns:
ByteArrayInputStream for the contents of the String

StringBuffer2Stream

public java.io.InputStream StringBuffer2Stream(java.lang.StringBuffer data)
Creates an InputStream from a StringBuffer
Parameters:
data - StringBuffer instance
Returns:
ByteArrayInputStream for the contents of the StringBuffer

findDraft

public KomData findDraft(java.lang.String ref,
                         java.lang.String xnr)
Finds data for a draft (uncommitted entry)
Parameters:
ref - Parent id
xnr - Draft identification
Returns:
Contents of the draft, as a KomData object

findDraftData

public java.lang.String findDraftData(java.lang.String ref,
                                      java.lang.String xnr)
Finds data for a draft (uncommitted entry)
Parameters:
ref - Parent id
xnr - Draft identification
Returns:
Contents of the draft, as a String

Stream2String

public java.lang.String Stream2String(java.io.InputStream is)
Creates a String from an InputStream
Parameters:
is - InputStream
Returns:
Contents of stream as a String

removeDraft

public void removeDraft(java.lang.String ref,
                        java.lang.String xnr,
                        java.lang.String old)
Removes a message from the draft database
Parameters:
ref - Parent ref
xnr - Draft no
old - Older draft

cleanDrafts

public void cleanDrafts(java.lang.String ref)
Removes any left-over MIME-formatted draft files
Parameters:
ref - Parent ref

replaceObject

public void replaceObject(java.lang.String ref,
                          KomData kd)
Replaces an object
Parameters:
ref - Object ref
kd - New object data

getValues

java.util.Vector getValues(java.lang.String ref,
                           java.lang.String part,
                           java.lang.String key)
Gets a vector of values from an object part
Parameters:
ref - Object ref
part - Object part
key - Key to values

getStringValues

java.lang.String[] getStringValues(java.lang.String ref,
                                   java.lang.String part,
                                   java.lang.String key)
Gets a String array of values from an object part
Parameters:
ref - Object ref
part - Object part
key - Key to values

listDraft

public java.lang.String[] listDraft(java.lang.String ref)
Makes a list of "drafts", i e uncommitted message file names
Parameters:
ref - parent area of possible drafts
Returns:
File names as a String array.

expungeRef

boolean expungeRef(java.lang.String ref)
Deletes all files accessed via a reference (directory and subdirs)
Parameters:
ref - Ref to an object or area

updref

public java.lang.String updref(java.lang.String ref)
Gets a reference for the next child of a reference, creating a new area if necessary.
Parameters:
ref - Parent reference
Returns:
id/nnn/, where id is the value of ref, and nnn is the updated sequence #

makeArea

public void makeArea(java.lang.String path)
Allocates a database area if it does not exist already.
Parameters:
path - Reference to area (representing a thread, e g)

depth

public int depth(java.lang.String id)
Determines the "depth" of a URL by counting slashes. It is assumed that the URL, if non-null, starts with a slash (/).
Parameters:
id - URL of the form /cat/act/thr/msg/, where one or more levels may be missing at the end.
Returns:
Number of slashes in id - 1: 0 for top url, 1 for category, 2 for activity (forum, user, chat), 3 for message thread, 4 for individual message.

getseq

public java.lang.String getseq(java.lang.String ref)
Gets the next free sequence number for a ref.
Parameters:
ref - Reference to an area with a "seq" entry.
Returns:
current value of "seq", as a String.

updseq

public java.lang.String updseq(java.lang.String ref)
Updates a "seq" object part
Parameters:
ref - Object ref
Returns:
New value of "seq", as a String

updCount

public java.lang.String updCount(java.lang.String ref,
                                 java.lang.String key,
                                 boolean create,
                                 java.lang.String value)
Updates a "count" object part (e g "seq")
Parameters:
ref - Object ref
key - Part name
create - True if part should be created if missing
value - If non-null, place the value in the part (otherwise add 1 to previous value)

isStandard

public static boolean isStandard(java.lang.String url)
Determines if a url refers to one of a few standard directories
Parameters:
url - File url
Returns:
true if url starts with some standard directory prefix string The url can then be used directly as a file reference, usually

isEmpty

public static boolean isEmpty(java.lang.String s)
Is the string empty or null?
Parameters:
s - String
Returns:
true if string == null or == ""