Index Special Tags Predefined Tags Implementation Home
Implementation of PReP
The config file

    The config file was made to improve the security level. However it can contain also some configuration details as for example the settings of the database. Mainly it consists of the FILE and the SECURITY tag.

    We may not want to allow the user to read from all the files in our filesystem. Therefor we are going to create a config file which includes a list of files and a security flag with one can turn the security on and off. This file is to be read right on the beginning and every time a file is added. There should be a possibility to reload this file.

    The *FILE in the config file includes all names and nicknames of the files which are readable by the user. They are written like the following:

    name::filename
    or
    filename
    or
    default::filename

    The names left of the two colons are the nicknames and the key for a hashtable at the same time. If the nickname is "default", this file will be loaded as standard file. If no default is defined, nothing will be done.

    The *SECURITY includes all tags which do not have to be secure. For instance if we want to allow the user to see all of the files, without any restrictions, we set the flag to "off":

    FILE::off

    We are able to extend the security later.

    We have a hashtable for the list of the files and one for the list of the security flags. These are stored in a hashtable again.

    If the flag in the *SECURITY is on, then it gets every line of the *FILE part and takes it into key and value and put it in the hashtable.

    The *DB may be used to set the details for the database. Please use following keys:

    JDBCDRIVER::your_jdbc_driver
    URL::your_URL
    UID::your_UID
    PWD::your_Password

    It is possible to reload the config file without disconnecting the servlet. Just provide a tag RELOAD=yes and the servlet will automatically get the new config file. (Please do not use RELOAD=no, it is not necessary.)

Implementation of ExceptionHandler

    This is an interface and provides the method handleException(Exception exception) which are used right now in the PRePTagDBMS and in the PRePTagObject.

Implementation of ExceptionList

    This is subclass from the java.util.Vector class. It stores PRePExceptions which consists of an exception and an errorlevel.

    Constructor:

    ExceptionList()
    default constructor

    Methods:

    outErrorlevel(PrintWriter pwriter, int iErrorlevel)
    prints all stored PRePExceptions with that specified errorlevel

    outExceptionList(PrintWriter pwriter)
    prints all exceptions which are stored in the list

Implementation of InputServlet

    InputServlet is nothing but a subclass of the PRePServlet and does not provide any further methods. It was created because we have some programs which still run under this class.

    Constructor:

    default constructor

Class information of PReP

    The PReP class reads arguments from the commandline which are either tags and values or input files and an output file and stores them into a TagList, compiles it and outputs the result in the PrintWriter. It contains the main method.

    To create a subclass, it is important to know, if you need a database connection. You may specify it in the setDBConnection() where you also can specify how many connections you want. For this is the commandline version, you may want only one connection, because you can only use one. This is actually more important for the servlet version.

    Constructor:

    public PReP(String[] strArgs)
    Checks whether there are some arguments. If there are none, a help text will be printed. It creates a PRePHandler and uses it as an interface to the methods The constructor processes the arguments.

    Methods:

    protected PRePHandler provideHandler()
    Returns a new PRePHandler with a security int of 0

    protected void fillSpecialArgs(Arguments arguments)
    Puts special arguments to a list (for example "DB")

    protected void setDBConnection()
    This may be overwritten in a subclass. The PRePHandler will take the default values for the database.

    public void handleNormalArg(Argument argument, Arguments arguments)
    This method handles all normal tags in the argument array (-tagname tagvalue)

    public void handleSpecialArg(Argument argument, Arguments arguments)
    This argument must be a filename because it is not a minus argument (like -tagname) nor a name value pair. So it just calls the handleFileArg(arguments, argument) method.

    public boolean handleArgInList(int iKey, Arguments args)
    Gets the argument with the specified key out of the list and handles special. It returns a boolean, if the argument was handled or not.

    protected void handleFileArg(Arguments arguments, Argument argument)
    It checks whether the output file was already handled. If not, the last argument (which has to be the output file) is handled first. Then the putFile(prepMain, file) method of the PRePHandler is called.

    protected void handleOutputFileArg(Arguments arguments)
    This handles the last argument which has to be the output file. The printWriter will be set.

    protected void handleDBTag(Arguments args)
    As soon as the DB tag appears, the database setting will be set with the setDatabaseConnection(JDBCDriver, URL, DBUSER, DBPWD) method of PRePHandler.

    protected void printHelp()
    Prints a help text. This method will be called if no arguments where defined.

    public static void main(String argv[])
    Constructor of PReP.

Implementation of PRePException

    Consists of the class which caused the exception, the exception itself and a number (errorlevel). The default errorlevel is 1. A list of PRePExceptions is stored in session

    Constructor:

    PRePException(Object objclass, Object objException)
    gets the class where the exception occurred and the Exception itself PRePException(Object objclass, Object objException, int iErrorlevel)
    gets the class, the exception and the errorlevel of the PRePException

    Methods:

    outException()
    returns a string with the class, exception and errorlevel

    getCausingClass()
    returns the class object

    getException()
    returns the Exception object

    getErrorlevel()
    returns the errorlevel

Implementation of PRePHandler

    The PRePHandler class is a helper class which allows to deal between the Servlet and the PRePMain class as well as between a commandline version of PReP and the PRePMain - without having any knowledge of JSDK. It configurates the data coming from the servlet or commandline version of PReP.

    Constructor:

    default constructor

    Methods:

    setDatabaseConnection()
    Creates a new ConnectionPool and initialises it with the default values

    setDatabaseConnection(String JDBCDriver, String URL, String UID, String PWD)
    Creates a new ConnectionPool and initialises it with the given values.

    setDatabaseConnection(String JDBCDriver, String URL, String UID, String PWD, int iConnections)
    Creates a new ConnectionPool and initialises it with the given values. You will get as many connections as you specified in iConnections.

    getPRePMain()
    returns a new PRePMain object

    setPrintWriter(PRePMain, PrintWriter)
    calls the setPrintWriter() method of the specified PRePMain object

    putPRePTags(PRePMain)
    calls the putField() for each predefined PRePTag, specified in this method

    putField(PRePMain, String strName, String strValue)
    calls the putField() method of PRePMain

    putField(PRePMain, PRePTag)
    calls the putField() method of PRePMain

    getNewCookies(PRePMain)
    if there are cookies to set on the HttpServletResponse, call them here (like the UINFO cookie, checkUser() in DOCHandler!)

    loginOk(PRePMain)
    if checkCookie returned true, this method invokes. It manages the filehandling and returns nothing.

    loginNotOk(PRePMain)
    if checkCookie returned false, this method invokes. It manages also the filehandling and returns nothing.

    finishHandle(PRePMain)
    calls the output() method of PRePMain and deletes the PRePMain after that.

    putFile(File file)
    calls the putFile() method of PRePMain

    destroy()
    calls the destroy() method of the ConnectionPool which will close every connection

Implementation of PRePMain

    The PRePMain stays mostly in its old structure.There are some methods which are not used anymore, removed (as for instance the method setDatabaseConnection()) and some other may be slightly changed.

    Constructor:

    default constructor, which creates a Session object

    Methods:

    setPrintWriter(PrintWriter pWriter)
    sets the specified PrintWriter

    getSession()
    returns the Session object

    putFile(File file)
    gets all tags from this file

    putField(String name, String value)
    creates a PRePTag with the name and the value and adds it to the TagList

    putField(PRePTag)
    adds the PRePTag to the TagList

    output(PrintWriter pwClient)
    compiles the __TEMPLATE__ in the specified PrintWriter

    output()
    compiles the __TEMPLATE__ tag

    getValue(String strTagName)
    returns the value of the specified tag. If it does not exist, it returns null

Implementation of PRePPreparse

    Removes all the comments in the prep file (@@)

    Constructor:

    default constructor

    Methods:

    preparse(BufferedReader, Session)
    preparse will skip all comments (begin with @@) in the file (BufferedReader). It returns the file without the comments.

Implementation of PRePServlet

    First of all the init() method of the PRePServlet will be called from the servletrunner. There a new PRePHandler (providePRePHandler()) will be created as well as the ConnectionPool initialised (default values). You may specify (if you create a subclass) how many connections you will need for your servlet. The default size is 5.

    As soon as a request from the servletrunner arrives, the handle() method of the PRePServlet is called. This method handles the request and does everything from setting the PrintWriter to the login and finally output of the PRePFile. It is build out of different methods which all work over the PRePHandler. The PRePHandler is unique - unlike the PRePMain which is given to the PRePServlet at the beginning. It will be deleted after the handle() method finished.

    If the servletrunner closes, it calls the destroy() method of the PRePServlet class which itself calls the destroy() method of the PRePHandler class. The ConnectionPool will be destroyed and its connection closed one for one.

    Constructor:

    Methods:

    init(ServletConfig servletConfig)
    calls the method provideHandler() and the setDatabaseConnection() method

    handle(HttpServletRequest req, HttpServletResponse res)
    calls different methods to handle the servletrunner's request. It first will get a PRePMain object and create a new Instance object which will contain the PRePMain, the HttpServletRequest and the HttpServletResponse object.

    getPRePMain()
    gets a new PRePMain object

    setPrintWriter(Instance instance)
    gets the PrintWriter of the HttpServletRequest and calls the setPrintWriter() method of the PrePHandler class

    putPRePTags(Instance instance)
    calls the putPRePTags() method of the PRePHandler class

    setParams(Instance instance)
    calls the putField() method of the PRePHandler class for each incoming PRePTag of the HttpServletRequest

    setCookies(Instance instance)
    calls the putField() method of the PRePHandler class for each incoming cookie

    setContext(Instance instance)
    sets the context of the HttpServletResponse to a specified format (most likely "text/html")

    getNewCookies(Instance instance)
    will call the getNewCookies() method of the PRePHandler which returns an array of objects (cookies). Then it will provoke the putField() method for each cookie.

    loginOk(Instance instance)
    will call the loginOk() method of the PRePHandler class

    loginNotOk(Instance instance)
    will call the loginNotOk() method of the PRePHandler class

    finishHandle(Instance instance)
    will call the finishHandle() method of the PRePHandler class

    destroy()
    is automatically called by the servletrunner and calls the destroy() method of the PRePHandler

    Related sites:
Other information about PRePServlet
Implementation of PRePTag

    This is the super class of all the PRePTags. It is abstract and consists of a tag name and a value.

    Constructor:

    PRePTag(String sTagName)
    sets the tag name

    Methods:

    compile(Session)
    compile

    compile(Session session, PrintWriter pw)
    compile the tag to a given PrintWriter

    debugOutput()
    debugOutput: helps to find some exceptions

    getAllValue()
    getAllValue: gets the whole value and returns it as a String

    getName()
    getName: returns the name of this tag as a String

    getValue()
    getValue: gets one line of the value of a tag and returns it as a String

    setValue(Object)
    setValue: sets the specified object as value in the tag

    toString()
    return the tag name and the value

Implementation of PRePTagArg

    This is a subclass of PRePTagText. It is a tag for temporary stored arguments which are given with two colons (e.g. ). For more information see the chapter "How to work with arguments".

    Constructor:

    PRePTagArg(String sTagName)
    names the tag with the given string

    PRePTagArg(String sTagName, String arg, Session session)
    checks whether a '!' is before the string arg (argument) and calls the compile method

    Methods:

    compile(PrintWriter, TagList)
    calls the compile method from the super class (PRePTagText)

Implementation of PRePTagBOOLEAN

    It can be very useful to check if something is true or false. This is possible with the BOOLEAN tag. With that you can compare to numbers and compile either the true_output or the false_output.

    Constructor:

    PRePTagBOOLEAN()
    names the tag with "BOOLEAN"

    Methods:

    compile(Session)
    compares the two number and compiles either the true_- or the false_output

    Related sites:
How the BOOLEAN Tag works
Implementation of PRePTagCALCULATE

    this tag can add, substract, divide, multiply, calculate the mod and the power of two arguments which are floats.

    Constructor:

    PRePTagCALCULATE()
    names the tag with "CALCULATE"

    Methods:

    compile(Session)
    calculates the result of the the two numbers with the specified operationsign and pushes a RESULT tag on the TagList

    Related sites:
How the CALCULATE Tag works
Implementation of

    Constructor:

    PRePTagCode(String sTagName)
    names the tag with the given string

Implementation of PRePTagCount

    This is a subclass of PRePTagArg. It counts all ARGs (arguments) which are temporarily stored in the TagList. This tag is used for validating the number of arguments of a predefined tag.

    Constructor:

    PRePTagCount()
    names the tag with "ARG0"

    Methods:

    getIntValue()
    gets the counter of the tag

    setCount(int)
    sets the counter in the tag

Implementation of PRePTagDatabase

    A superclass for all tags which use a database connection and have to execute a SQL statement. It creates a store object which represents the result. PReP works with a Connectionpool - for more information about this and also about how to use and change it have a look at the package itself (com.delec.global.dbms).

    Constructor:

    PRePTagDatabase()
    default constructor PRePTagDatabase(String name)
    sets a name

    Methods:

    checkSQLServe(Session, SQLServe)
    returns a SQLServe - if it was null before, it creates a new one and puts it in the session

    executeSQL(String SQLStatement, Session session)
    calls the execStmtStore() method in SQLServe and creates a Store object with all the results in it which will be returned.

    executeUPDATE(String SQLStatement, Session session)
    calls the execUpdate() method in SQLServe. It also returns a Store object with the results.

    handleException(Exception)
    if the Exception damages the connection object, it will call the recoverConnection() method in SQLServe. Otherwise it creates a new PRePTagException and add it to the ExceptionList in the Session object

Implementation of PRePTagDATE

    This is a subclass of PRePTagCode. This predefined tag gets the actual date or calculates with date formats. For further information see chapter "The DATE tag".

    Constructor:

    PRePTagDATE()
    names the tag with "DATE"

    Methods:

    compile(Session)
    calculates the actual or a modified date

    Related sites:
How the DATE Tag works
Implementation of PRePTagDBMS

    This is a subclass of PRePTagCode which implements an ExceptionHandler. With the ExceptionHandler it is possible to keep the handling of any exception more flexible. The connection of the database must be predefined with the DB tag which may be given with the call of the PReP program. The methods specific for the database (e.g. connection() or close()) are provided in another class (SQLServe) and the result is stored in a Store object. The DBMS tag also needs an OUTPUT tag which will format the result and outputs it in a specified matter. For further information please see chapter "The DBMS tag".

    Constructor:

    PRePTagDBMS()
    names the tag with "DBMS" PRePTagDBMS(String strName)
    names the tag with the given string

    Methods:

    compile(Session)
    does the whole database handling and gets the requested fields in a store object

    handleException(Exception exception)
    stores the exception in an exception list

    Related sites:
How the DBMS Tag works
Implementation of PRePTagDEF

    This is a subclass of PRePTagCode which defines the DEF tag. It must have two arguments. For further information see chapter "The DEF tag".

    Constructor:

    PRePTagDEF()
    names the tag "DEF"

    Methods:

    compile(Session)
    checks the arguments and prepare the output

    Related sites:
How the DEF Tag works
Implementation of PRePTagEXCEPTION

    This is a subclass of PRePTagCode which defines the EXCEPTION tag. With this tag you may retrieve any exceptions with a specified errorlevel. For more informations see chapter "The EXCEPTION tag".

    Constructor:

    PRePTagEXCEPTION()
    names the tag "EXCEPTION"

    Methods:

    compile(Session)
    checks whether there is an integer as argument or not and outputs the exception list. If there was an integer argument, it outputs just those exceptions with the specified errorlevel.

    Related sites:
How the EXCEPTION Tag works
Implementation of PRePTagEXEC

    This is a subclass of PRePTagCode which will call a DOS batch file with a specified argument. It will examine the errorcode the DOS program returned with. It needs four arguments. For further information see chapter "The EXEC tag".

    Constructor:

    PRePTagEXEC()
    names the tag "EXEC"

    Methods:

    compile(Session)
    makes a DOS batchfile and a textfile with the value of the arguments as content and executes the batchfile with the textfile as argument

    fileMaker(Session session, String strPrefix, String strSuffix, File fileDirectory)
    creates a file with the specified prefix and suffix in the file directory. The session is needed for the exception list.

    writeTextToFile(PRePTag prepTag, Session session, File file)
    writes the arguments as contents into the specified file

    Related sites:
How the EXEC Tag works
Implementation of FOREACHARG

    This is a subclass of PRePTagCode which will call another PRePTag with as many arguments as wanted to. For further information see chapter "The FOREACHARG tag".

    Constructor:

    PRePTagFOREACHARG()
    names the tag "FOREACHARG"

    Methods:

    compile(Session)
    gets each argument and create a new tag with the arguments as values

    Related sites:
How the FOREACHARG Tag works
Implementation of PRePTagIF

    This is a subclass of PRePTagCode which defines the IF tag. It will examine the specified PRePTag (given as first argument) whether it has the specified value (given as second argument). It needs at least three arguments, but maximum four.

    Constructor:

    PRePTagIF()
    names the tag "IF"

    Methods:

    compile(Session)
    gets the first argument and checks whether there is a tag with a value which is equal to the second argument.

    Related sites:
How the IF Tag works
Implementation of PRePTagIFDEF

    This is a subclass of PRePTagCode which defines the IFDEF tag. It is similar to the IF tag but it just examines whether the specified PRePTag exists or not.

    Constructor:

    PRePTagIFDEF()
    names the tag "IFDEF"

    Methods:

    compile(Session)
    gets the first argument and checks if a tag with that name exists

    Related sites:
How the IFDEF Tag works
Implementation of PRePTagNBSP

    This is a subclass of PRePTagCode which defines the NBSP tag. It gets the first argument and changes the whitespaces there with an HTML " ". If there is a second argument it should be an integer and represents the number of " " which should replace the tabs in the first argument ('\t').

    Constructor:

    PRePTagNBSP()
    names the tag "NBSP"

    Methods:

    compile(Session)
    replaces the whitespaces and the tabs with a HTML " "

    Related sites:
How the NBSP Tag works
Implementation of PRePTagObject

    This is a subclass of PRePTag. It gets a format order as argument and formats its value in this way (for more information see the part about the OUTPUT tag in the DBMS tag chapter).

    Constructor:

    PRePTagObject(String sTagName)
    names the tag with the given string

    Methods:

    compile(Session)
    checks whether the argument is a format or not

    format(PrintWriter, String, ExceptionHandler)
    formats the output as specified

    getObjectValue()
    gets the value of the tag (object)

    getValue()
    gets the value of the tag

    handleException(Exception exception)
    adds the exception to the exceptionlist with the default errorlevel (1)

    setValue(double)
    sets the value of the tag

    setValue(int)
    sets the value of the tag

    setValue(Object)
    sets the value of the tag

    setValue(char)
    sets the value of the tag

    setValue(float)
    sets the value of the tag

Implementation of PRePTagPARSE

    This is a subclass of PRePTagCode which defines the PARSE tag. The PARSE tag opens a specified file, parses this file and compiles a certain tag. After that the taglist is resized to the normal size.

    Constructor:

    PRePTagPARSE()
    names the tag "PARSE"

    Methods:

    compile(Session)
    gets the filename (first argument)and opens the file. It gets the PRePMain object from the session object and calls the putFile() method - this will parse the file. Then it gets the tag which is to be executed (second argument) and compiles it. After that the taglist is to be resized to the normal size.

    Related sites:
How the PARSE Tag works
Implementation of PRePTagTAGLIST

    This is a subclass of PRePTagCode which defines the TAGLIST tag. It outputs the actual tag list in an HTML format.

    Constructor:

    PRePTagTAGLIST()
    names the tag "TAGLIST"

    Methods:

    compile(Session)
    calls the outTag method in the TagList class

    Related sites:
How the TAGLIST Tag works
Implementation of PRePTagText

    This is a subclass of PRePTag and compiles by printing the value with the PrintWriter. If the noparse flag is set (like: *MAIN:noparse) then the tag is just print the way it looks (without any formats or substitutes)

    Constructor:

    PRePTagText(String sTagName)
    checks if the tag has a noparse flag set

    Methods:

    compile(Session)
    checks all brackets and arguments

    debugOutput()
    debugOutput: helps to find some exceptions

    getAllValue()
    gets the whole value of the tag

    getValue()
    gets one line of the value of the tag

    setValue(String)
    sets the value of the tag

Implementation of Session

    The session object encapsulates all objects that are used for a session (one execution) of the PReP environment. This is needed to allow a multithreaded execution of PReP. It also provides the TagList, User and PrintWriter object which are stored separately and have to be set and retrieved with special methods.

    Constructor:

    Session()
    initialises the hashtable, the tag list and the exception list

    Methods:

    put(Object key, Object value)
    put an object with a specified key object

    Object get(Object key)
    gets an object, specified with the key object

    Object remove(Object)
    remove an object, specified with the key object

    toString()
    returns the hashtable content as a string

    setTagList(TagList)
    sets the actual TagList

    getTagList()
    gets the actual TagList that has been set by setTagList

    setUser(Object)
    sets the User object for the session. Will be used by prep tags to retrieve user settings

    getUser()
    gets the actual User that has been set by setUser

    setPrintWriter(PrintWriter)
    sets the actual PrintWriter for the session. Use getPrintWriter to retrieve it again

    getPrintWriter()
    gets the actual PrintWriter that has been set by setPrintWriter

    setExceptionList(ExceptionList)
    sets the exception list

    getExceptionList()
    gets the actual exception list that has been set by setExceptionList method

Implementation of SQLServe

    This class provides all methods which are necessary to build a database connection. It also handles the SQL statements and returns a Store object in which the result of a SQL statement is stored.

    Constructor:

    SQLServe()
    default constructor

    Methods:

    public static Connection getConnection(ConnectionPool connectionPool)
    Gets a connection out of the ConnectionPool

    public static void recoverConnection()
    handles a broken connection

    public static CallableStatement getCallableStatement(String strCallableStmt, Connection dbmsCon)
    gets the statement for a stored procedure

    public static CallableStatement loopThroughResultSet(CallableStatement callableStmt, boolean hasResultSet, ResultSet rs)
    Dummy procedure - is necessary for a stored procedure

    execStmtStore(String sqlStatement, Session session, ExceptionHandler exceptionHandler)
    executes the SQL statement and store the result in a Store object. It only gets the specified maximum (int argument) except the int value is 0. If an exception occurres, it will be call the method handleException in the interface ExceptionHandler

    execStmtStore(String sqlStatement, int i MaxRows, Session session, ExceptionHandler exceptionHandler)
    it calls the execStmtStore method with an int value of 0, which means, that every row is required

    execSpStore(String)
    executes a stored procedure and returns a Store object with the result

    execUpdate(String)
    executes an update and returns how many rows that have been affected

Implementation of Store

    Object to store tables from a database received with a specified SQL statement. It is necessary to handle more than one access with a SQL statement.

    Constructor:

    Store()
    Constructor with a default integer (4) Store(int)
    initialises the vectors with the size of the specified int

    Methods:

    addName(String, int)
    adds a name with a specified object type to the column

    addValue (PRePTagObject)
    adds a value to the row

    getValue(String)
    gets the first record value with the specified label

    getValue(int)
    gets the first record value at the specified column

    values()
    returns the number of the values stored

    moveTo(int)
    move the cursor to the specified position (row)

    getNbrOfColumns()
    returns the number of columns

    getLabel(int)
    returns the label of the specified column

    push(Session)
    pushes one row of the store on the taglist

    compileFields(Session, PRePTag, int)
    compiles a specified number of fields of the store with the PRePTag (output tag)

    compileFields(Session, PRePTag)
    compiles all fields of the store with the PRePTag (output tag)

    Inner Class:

    HeaderInfo used for output label and type Constructor of Inner class: HeaderInfo(String label, int type)
    saves the label and the type of this column

Implementation of TagList

    This is a subclass of java.util.Vector which stores all PRePTags. The predefined PRePTags are stored when the TagList is created. The argument tags (ARGs) are stored only temporarily.

    Constructor:

    TagList()
    adds all predefined tags into the list

    Methods:

    compile(String name, Session session)
    searches for a tag with the specified name and compiles it

    find(String name)
    find a PRePTag in the TagList

    outTag()
    outputs the whole TagList

    outTag(PrintWriter pwriter)
    outputs the whole TagList with the specified PrintWriter