kom.gateway
Class DBLow

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

public class DBLow
extends java.lang.Object

Low level database handling


Field Summary
static java.lang.String absCDBpath
          Absolute path to the CDB directory
(package private) static ServerConfig config
          Server configuration data
(package private) static char fSep
           
(package private) static java.lang.String fSeparator
          File path separator, e g "/" in Unix, "\" in Windows
(package private) static java.util.Hashtable msgAuth
          Table of authorization data for terminal URLs
(package private) static java.util.Hashtable msgParts
          Cache of message parts (such as images)
 
Constructor Summary
(package private) DBLow(ServerConfig config)
          Class constructor
 
Method Summary
private  boolean accessPart(java.lang.String p, java.lang.String sid)
          Checks if access to a component is allowed
(package private)  void addFile(java.lang.String path, java.io.InputStream is, boolean apnd)
          Adds data to the file database.
(package private)  boolean areaExists(java.lang.String area)
          Check if user area exists already
(package private)  java.lang.String basedRef(java.lang.String ref)
          Returns a reference starting with current servletBase.
(package private)  void createArea(java.lang.String path)
          Creates object area (directory).
(package private)  void debugLog(java.lang.String s)
           
(package private)  void errorLog(java.lang.String s)
           
protected  boolean expungeFile(java.io.File f)
          Deletes a file.
private  java.io.InputStream File2Stream(java.io.File f)
          Makes an InputStream from a File
(package private)  java.lang.String File2String(java.io.File f)
          Gets contents of a File
(package private)  boolean findPart(java.lang.String path, java.lang.String sid)
          Looks up a part in msgParts or as a file
protected  java.io.File getFile(java.lang.String fRef)
          Defines (file) path corresponding to an object
(package private)  java.lang.String getFileContents(java.lang.String url)
          Gets contents of a file
(package private)  java.io.InputStream getFileStream(java.lang.String path)
          Finds data in the file database
(package private)  java.lang.String getPath(java.lang.String fRef)
          Defines path corresponding to an object.
(package private)  java.io.InputStream getStandard(java.lang.String url)
          Gets contents (of a file) corresponding to an url.
(package private)  boolean isMailSpool(java.lang.String path)
          Returns true if file path indicates a mail spool file.
 long lastModified(java.lang.String url)
          Gets time of last modification of object
 long length(java.lang.String url)
          Gets size of object
(package private)  java.lang.String[] listFiles(java.lang.String path, java.lang.String pfx)
          Gets a list of file names from a directory
(package private)  void makePart(java.lang.String rId, java.lang.String part, java.io.InputStream b)
          Makes a body part (attachment) file
(package private)  java.io.InputStream msgPartStream(java.lang.String rId, java.lang.String partName, java.io.File msgfile, java.lang.String sid)
          Creates an InputStream for a message part
(package private)  java.io.File partfile(java.lang.String url, java.lang.String part, boolean full)
          Creates a File object
(package private)  java.lang.String partpath(java.lang.String url, java.lang.String part, boolean full)
          Determines path of part file.
(package private)  void printStackTrace(java.lang.Throwable x, java.lang.String debugmessage)
           
(package private)  java.lang.Object readObject(java.lang.String name)
          Reads an object from a file
(package private)  boolean removeFile(java.lang.String path)
          Deletes a file in the database
(package private)  void replaceMime(java.lang.String path, java.lang.String repl)
          Replaces a file
(package private)  java.lang.String updseq1(java.lang.String path, boolean update, java.lang.String value)
          Updates or just gets a sequence number
private  void validate(java.lang.String p, java.lang.String sid)
          Registers sid as a valid key to p
protected  void validate(java.lang.String id, java.lang.String part, java.lang.String sid)
           
(package private)  void writeObject(java.lang.String name, java.lang.Object obj)
          Writes an object
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

config

static ServerConfig config
Server configuration data

fSeparator

static java.lang.String fSeparator
File path separator, e g "/" in Unix, "\" in Windows

fSep

static char fSep

absCDBpath

public static java.lang.String absCDBpath
Absolute path to the CDB directory

msgParts

static java.util.Hashtable msgParts
Cache of message parts (such as images)

msgAuth

static java.util.Hashtable msgAuth
Table of authorization data for terminal URLs
Constructor Detail

DBLow

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

areaExists

boolean areaExists(java.lang.String area)
Check if user area exists already
Parameters:
area - Path to the area

length

public long length(java.lang.String url)
Gets size of object
Parameters:
url - Object url
Returns:
file length

lastModified

public long lastModified(java.lang.String url)
Gets time of last modification of object
Parameters:
url - Object url
Returns:
modification time

createArea

void createArea(java.lang.String path)
Creates object area (directory).
Parameters:
path - Path to the area

addFile

void addFile(java.lang.String path,
             java.io.InputStream is,
             boolean apnd)
Adds data to the file database.
Parameters:
path - Path to the object file
is - Data to put in the file
apnd - true if data should be appended, false means overwrite

getFileStream

java.io.InputStream getFileStream(java.lang.String path)
Finds data in the file database
Parameters:
path - Path to the object
Returns:
InputStream of the data

partfile

java.io.File partfile(java.lang.String url,
                      java.lang.String part,
                      boolean full)
Creates a File object
Parameters:
url - URL, which may correspond to a file/directory path
part - Last part of path, or null
full - True if url is known to correspond to an absolute path
Returns:
Absolute path of file

partpath

java.lang.String partpath(java.lang.String url,
                          java.lang.String part,
                          boolean full)
Determines path of part file.
Parameters:
url - Message url (like "/mail/7/")
part - Part identification (like "part-3")
full - True if url is known to correspond to an absolute path
Returns:
path for part file ("$BASE/CDB/mail/7/part-3" in the example). $BASE is the document root, e g //KOM

isMailSpool

boolean isMailSpool(java.lang.String path)
Returns true if file path indicates a mail spool file.
Parameters:
path - File path (must be non-null)

msgPartStream

java.io.InputStream msgPartStream(java.lang.String rId,
                                  java.lang.String partName,
                                  java.io.File msgfile,
                                  java.lang.String sid)
Creates an InputStream for a message part
Parameters:
rId - Message id, or file path if partName == null
partName - Name of part
msgfile - Path of spool file
Returns:
Open InputStream for the part

basedRef

java.lang.String basedRef(java.lang.String ref)
Returns a reference starting with current servletBase.
Parameters:
ref - Full (starting with servletBase) or relative ref
Returns:
A ref starting with servletBase

findPart

boolean findPart(java.lang.String path,
                 java.lang.String sid)
Looks up a part in msgParts or as a file
Parameters:
path - File path for part
sid - Security id
Returns:
true if part exists either in the table or as a file

validate

protected void validate(java.lang.String id,
                        java.lang.String part,
                        java.lang.String sid)

validate

private void validate(java.lang.String p,
                      java.lang.String sid)
Registers sid as a valid key to p
Parameters:
p - Path of file, key to table data
sid - Authorization for accessing p data

accessPart

private boolean accessPart(java.lang.String p,
                           java.lang.String sid)
Checks if access to a component is allowed
Parameters:
p - Path of component
sid - Security id
Returns:
true if sid is found in proper part of msgAuth table.

replaceMime

void replaceMime(java.lang.String path,
                 java.lang.String repl)
Replaces a file
Parameters:
path - Path of file to be replaced (possibly except "text")
repl - Path of replacing file (possibly except "text")

removeFile

boolean removeFile(java.lang.String path)
Deletes a file in the database
Parameters:
path - Path to the object

expungeFile

protected boolean expungeFile(java.io.File f)
Deletes a file. If the file is a directory, the contained files are first deleted, recursively.
Parameters:
f - Abstract file path

listFiles

java.lang.String[] listFiles(java.lang.String path,
                             java.lang.String pfx)
Gets a list of file names from a directory
Parameters:
path - Directory path
pfx - Prefix of names to be included, or null
Returns:
String array of file names, or null

updseq1

java.lang.String updseq1(java.lang.String path,
                         boolean update,
                         java.lang.String value)
Updates or just gets a sequence number
Parameters:
path - Path to a file which should contain a sequence number
update - true: update to next sequence number
value - If non-null, use this value as sequence number
Returns:
String representation of (updated) number

getStandard

java.io.InputStream getStandard(java.lang.String url)
Gets contents (of a file) corresponding to an url. Contents may have been cached.
Parameters:
url - File url
Returns:
InputStream for contents

getFileContents

final java.lang.String getFileContents(java.lang.String url)
Gets contents of a file
Parameters:
url - File url
Returns:
File contents

getFile

protected final java.io.File getFile(java.lang.String fRef)
Defines (file) path corresponding to an object
Parameters:
fRef - File reference string
Returns:
File object reference

getPath

java.lang.String getPath(java.lang.String fRef)
Defines path corresponding to an object.
Parameters:
fRef - File reference
Returns:
File path string

File2String

java.lang.String File2String(java.io.File f)
Gets contents of a File
Parameters:
f - File
Returns:
Contents of f, as a String

File2Stream

private java.io.InputStream File2Stream(java.io.File f)
Makes an InputStream from a File
Parameters:
f - File
Returns:
InputStream or null

makePart

void makePart(java.lang.String rId,
              java.lang.String part,
              java.io.InputStream b)
Makes a body part (attachment) file
Parameters:
rId - Object ref, or full path
part - Part name
b - InputStream for part data

writeObject

void writeObject(java.lang.String name,
                 java.lang.Object obj)
Writes an object
Parameters:
name - Name of CDB file
obj - Object

readObject

java.lang.Object readObject(java.lang.String name)
Reads an object from a file
Parameters:
name - Name of CDB file
Returns:
Object instance

debugLog

void debugLog(java.lang.String s)

errorLog

void errorLog(java.lang.String s)

printStackTrace

void printStackTrace(java.lang.Throwable x,
                     java.lang.String debugmessage)