PVF Server

pvf.site
Class PVFSite

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--pvf.site.PVFSite
All Implemented Interfaces:
java.lang.Runnable

public class PVFSite
extends java.lang.Thread

This class should be extended by every class that must run on PVFServer. You should override the init method to ensure initialization of custom variables. You should not modify the constructor of this class. If you must override it you should call super() or write custom code to initialize the streams.
WARNING: You should not make any assumptions regarding the way that the streams are handled by the server. You must note that these streams are not connected directly to a socket (this mean that what you send on them will not be imediately send to the client). Usually, a message on the error stream will cause the server to ignore the data on the output stream and send a custom error message to the client (if you want to send your own error message, you should not use the error stream!).

Since:
1.0
Author:
Pais Vasile Florian

Field Summary
 java.lang.String[] env
          The environment
 java.io.PrintWriter err
          The PrintWriter used to send errors back to the client
 java.io.OutputStream errStream
          The stream used to send errors back to the client
 PVFInputStream in
          The stream used to get post data (the same with inStream).
 PVFInputStream inStream
          The stream used to read post data
 java.io.PrintWriter out
          The PrintWriter used to send data back to the client
 java.io.OutputStream outStream
          The stream used to send data back to the client
 java.net.Socket sock
          The socket for this connection.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
PVFSite()
          If you override the constructor please place a call to super().
PVFSite(java.io.OutputStream outStream)
          If you override the constructor please place a call to super().
 
Method Summary
 boolean ASPHandler(java.lang.String fname, java.lang.String var)
          This method is called by sendASPFile for every variable.
 void ASPNotFound(java.lang.String fname)
          This method is called by sendASPFile if the requested file can not be read.
 boolean defaultASPHandler(java.lang.String fname, java.lang.String cmd)
           
 void finish()
          This method is called when the script is finished.
 java.lang.String getAbsPath(java.lang.String rel)
          Return the absolute path of a file (relative to the site root).
 java.lang.String getAbsPath(java.lang.String base, java.lang.String rel)
          Return the absolute path of a file.
 java.lang.String getCookie()
          Return the current cookie value.
 java.lang.String getCookieValue(java.lang.String var)
          Return a value from the cookie.
 java.lang.String getCookieWebified()
          Return the current cookie value ready for web.
 java.lang.String getEnv(java.lang.String var)
          Return the specified environment variable.
 java.io.OutputStream getErrorStream()
          Used by the server to get the associated error stream
 java.io.InputStream getFormFileInputStream(java.lang.String fname)
          This method will return a FileInputStream for the specified form file.
 java.lang.String getFormValue(java.lang.String name)
          Return a value from the form data.
 PVFInputStream getInputStream()
          Used by the server to get the associated input stream
 java.io.OutputStream getOutputStream()
          Used by the server to get the associated output stream
 java.lang.String getQuery(java.lang.String var)
          Return the value of a variable in the query string
 java.lang.String getScriptRoot()
          Return the path of this script.
 void init()
          Allow you to initialize custom fields.
static void main(java.lang.String[] args)
          Display a message if the user trys to directly execute this class.
 void onExit()
          This method is called when the script is finished.
 void run()
          This method will call the script method.
 void script()
          The method that define the function of this class.
 void sendASPFile(java.lang.String fname)
          Send an ASP file.
 void sendASPFileAbsolutePath(java.lang.String fname)
           
 void sendASPFileAbsolutePath(java.lang.String s, java.lang.String relativeFname)
          Send an ASP file if you know its absolute path.
 void sendDataFile(java.lang.String s)
          Send a data file
 void sendDataFileAbsolutePath(java.lang.String fname)
          Send a data file
 void setASPErrors(boolean ASPErrors)
           
 void setCookie(java.lang.String cookie)
          Replace the current cookie with a new one.
 void setCookieValue(java.lang.String var, int val)
          Set a value in the cookie.
 void setCookieValue(java.lang.String var, java.lang.String val)
          Set a value in the cookie.
 void setEnv(java.lang.String[] env)
          Used by the server to set the environment for this class.
 void setErrorStream(java.io.OutputStream errStream)
          Set the error stream used by this script.
 Objects setFormData()
          Set the form data from the query string or from the POST data.
 void setInputStream(java.io.InputStream ins)
          Set the input stream used by this script.
 void setOutputStream(java.io.OutputStream outStream)
          Set the output stream used by this script.
 void setScriptRoot(java.lang.String path)
          Set the scriptRoot for this object (the path of this class).
static java.lang.String unWebify(java.lang.String s)
          "unWebify" a string by replacing %code and '+' with the corresponding characters.
 boolean useDirectClientConnection()
          This method should return true if the script has its own error checking methods (or if it can not generate errors).
static java.lang.String webify(java.lang.String str)
          Encode a string for transmission.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

inStream

public PVFInputStream inStream
The stream used to read post data


outStream

public java.io.OutputStream outStream
The stream used to send data back to the client


errStream

public java.io.OutputStream errStream
The stream used to send errors back to the client


in

public PVFInputStream in
The stream used to get post data (the same with inStream). This is kept only for compatibility with version 2.0


out

public java.io.PrintWriter out
The PrintWriter used to send data back to the client


err

public java.io.PrintWriter err
The PrintWriter used to send errors back to the client


sock

public java.net.Socket sock
The socket for this connection. You should not use input/output directly based on this socket. Instead, you should use the predefined streams and writers/readers. When the PVFSite object is created, data may be buffered, so if you try to use directly the socket, the script may block.


env

public java.lang.String[] env
The environment

Constructor Detail

PVFSite

public PVFSite()
If you override the constructor please place a call to super(). For initialization you should use the init() method.


PVFSite

public PVFSite(java.io.OutputStream outStream)
If you override the constructor please place a call to super(). For initialization you should use the init() method.

Method Detail

setOutputStream

public void setOutputStream(java.io.OutputStream outStream)
Set the output stream used by this script.


setInputStream

public void setInputStream(java.io.InputStream ins)
Set the input stream used by this script.


setErrorStream

public void setErrorStream(java.io.OutputStream errStream)
Set the error stream used by this script.


getInputStream

public PVFInputStream getInputStream()
Used by the server to get the associated input stream


getOutputStream

public java.io.OutputStream getOutputStream()
Used by the server to get the associated output stream


getErrorStream

public java.io.OutputStream getErrorStream()
Used by the server to get the associated error stream


setEnv

public void setEnv(java.lang.String[] env)
Used by the server to set the environment for this class. This class is loaded inside the server so you could use the server internal objects to access the settings, but it is recommended to rely on the environment passed by this method.

Parameters:
env - the environment
Since:
1.0

main

public static void main(java.lang.String[] args)
Display a message if the user trys to directly execute this class. You can change this message with whatever you want!

Parameters:
args - the command line arguments
Since:
1.0

init

public void init()
Allow you to initialize custom fields. You should not override the constructor for this. If you want to define your own fields that need initialization you should do this here. Also you could display a message confirming that the class was succesfully loaded.

Since:
1.0

script

public void script()
            throws java.lang.Exception
The method that define the function of this class. You must override this method in order to obtain something from this class!

java.lang.Exception
Since:
1.0

run

public void run()
This method will call the script method. You should not override this method. The script function should be defined in the script method.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread
Since:
1.0

getEnv

public java.lang.String getEnv(java.lang.String var)
Return the specified environment variable. The check is not case sensitive.

Parameters:
var - the requested variable
Returns:
the variable value or null
Since:
1.0

sendDataFile

public void sendDataFile(java.lang.String s)
Send a data file

Parameters:
s - the file name relative to the class
Since:
1.1

sendDataFileAbsolutePath

public void sendDataFileAbsolutePath(java.lang.String fname)
Send a data file

Since:
1.4

getQuery

public java.lang.String getQuery(java.lang.String var)
Return the value of a variable in the query string

Parameters:
var - the variable name
Returns:
the value or null
Since:
1.1

setFormData

public Objects setFormData()
Set the form data from the query string or from the POST data. This method is automtically called by the getFormValue() method.

Returns:
the formObjects object
Since:
1.1

getFormValue

public java.lang.String getFormValue(java.lang.String name)
Return a value from the form data. If no formObjects are available then setFormData() is called.

Parameters:
name - the variable name
Returns:
the variable value
Since:
1.1

unWebify

public static final java.lang.String unWebify(java.lang.String s)
"unWebify" a string by replacing %code and '+' with the corresponding characters. In versions prior to 1.1 you can use the unwebify method from the HTTPShell class.

Parameters:
s - the string to unwebify
Returns:
the new string
Since:
1.1

webify

public static final java.lang.String webify(java.lang.String str)
Encode a string for transmission. This method is the reverse of unWebify.

Parameters:
str - the decoded string
Returns:
the encoded string
Since:
1.2

setScriptRoot

public void setScriptRoot(java.lang.String path)
Set the scriptRoot for this object (the path of this class).

Since:
1.1

getScriptRoot

public java.lang.String getScriptRoot()
Return the path of this script.

Since:
1.1

sendASPFile

public void sendASPFile(java.lang.String fname)
Send an ASP file. It will stop when it encounters <% =var %> and it will call ASPHandler(var). It may call ASPNotFound if the requested ASP file can not be read. This may be modified in future versions to allow full ASP compatibility.

Since:
1.1

sendASPFileAbsolutePath

public void sendASPFileAbsolutePath(java.lang.String fname)

sendASPFileAbsolutePath

public void sendASPFileAbsolutePath(java.lang.String s,
                                    java.lang.String relativeFname)
Send an ASP file if you know its absolute path. You should normally use the sendASPFile method (this will automatically determine the location of your ASP file relative to the class path.

Since:
1.2

setASPErrors

public void setASPErrors(boolean ASPErrors)

ASPNotFound

public void ASPNotFound(java.lang.String fname)
This method is called by sendASPFile if the requested file can not be read.

Since:
1.1

ASPHandler

public boolean ASPHandler(java.lang.String fname,
                          java.lang.String var)
This method is called by sendASPFile for every variable.

Since:
1.1

finish

public final void finish()
This method is called when the script is finished. When this is called it will also call onExit(). So, if you want to run some clean up code write something in the onExit() method. You should never call the finish method manually ! The method will call onExit first and then will delete temporary files (this mean that in the onExit method you can use all the form elements in formObjects and all the temporary files). Warning: this method will not delete temporary files created by you!

Since:
1.2

onExit

public void onExit()
This method is called when the script is finished. You can use this to perform some clean-up. The default behavior is to simply return.

Since:
1.2

getFormFileInputStream

public java.io.InputStream getFormFileInputStream(java.lang.String fname)
This method will return a FileInputStream for the specified form file. You don't need to close this InputStream (the server will close it for you when it is no longer needed). However it will not raise any error if you close it yourself !

Since:
1.2

getAbsPath

public java.lang.String getAbsPath(java.lang.String base,
                                   java.lang.String rel)
Return the absolute path of a file. If rel starts with "/" then the path will be calculated relative to the site root, else the function will simply concatenate base with rel.

Parameters:
base - the base path (can be "")
rel - the relative path
Since:
1.2

getAbsPath

public java.lang.String getAbsPath(java.lang.String rel)
Return the absolute path of a file (relative to the site root).

Since:
1.2

getCookie

public java.lang.String getCookie()
Return the current cookie value.

Since:
1.3

getCookieWebified

public java.lang.String getCookieWebified()
Return the current cookie value ready for web. The result is similar to webify(getCookie()) but is faster.

Since:
1.3

getCookieValue

public java.lang.String getCookieValue(java.lang.String var)
Return a value from the cookie. The value must be set by setCookieValue or the result may be incorect.

Parameters:
var - the requested variable from the cookie
Since:
1.3

setCookieValue

public void setCookieValue(java.lang.String var,
                           java.lang.String val)
Set a value in the cookie. This value can be read with getCookieValue.

Parameters:
var - the variable name
val - the value of that variable
Since:
1.3

setCookieValue

public void setCookieValue(java.lang.String var,
                           int val)
Set a value in the cookie. This value can be read with getCookieValue.

Parameters:
var - the variable name
val - the value of that variable
Since:
1.3

setCookie

public void setCookie(java.lang.String cookie)
Replace the current cookie with a new one.

Parameters:
cookie - the new cookie
Since:
1.3

useDirectClientConnection

public boolean useDirectClientConnection()
This method should return true if the script has its own error checking methods (or if it can not generate errors). In this case the output will be sent directly to the client without delays caused by the server filesystem. By default this method will return false.

Since:
1.3

defaultASPHandler

public boolean defaultASPHandler(java.lang.String fname,
                                 java.lang.String cmd)

PVF Server

PVF Server official site: http://pvfserver.sourceforge.net