http://www.eteks.com

com.eteks.awt.servlet
Class PJAServlet

java.lang.Object
  extended byjavax.servlet.GenericServlet
      extended byjavax.servlet.http.HttpServlet
          extended bycom.eteks.awt.servlet.PJAServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
PJARedirectServlet, PJAServletTest, TeksSurveyPie

public abstract class PJAServlet
extends javax.servlet.http.HttpServlet

This is a model of super class which tries its best to get an AWT toolkit default instance (either default system one or PJA). You must override these methods :

instead of their counterpart standard servlet methods without the PJA extension. All these standard methods are overriden in this class as final methods to ensure they won't be overriden again in PJAServlet.
From the extending servlet, servlet standard methods calls following a super. (like super.init (config)) must use also their PJA postfixed counterpart methods (resulting to super.initPJA (config)). If not this will cause a stack overflow.
If you want to change existing code of a servlet, the fastest way should be to postfix with PJA all standard servlet methods names (either used to override servlet methods, or used in a method call). Any call to AWT methods using default toolkit can be made from all the previous PJA postfixed methods. If current security manager is too restrictive, some required properties may be impossible to set and com.eteks.awt.PJAToolkit can't be loaded. You can call createImage (width, height) to instantiate an image, or do it yourself with standard AWT code.
Notice that in some servlet configurations the static and instance initializers, as default constructor may be called twice because PJAServlet may need to reload and instantiate classes with a special class loader to ensure that the classes java.awt.Toolkit, com.eteks.awt.PJAToolkit, com.eteks.awt.servlet.PJAServlet and the class extending PJAServlet shares the same classpath. This implies that for example, JDBC connections should be initialized in initPJA () rather than in a constructor or in an initializer.

Since:
PJA2.1
Version:
2.1
Author:
Emmanuel Puybaret
See Also:
PJAToolkit, PJAServlet(boolean), createImage(int,int), Serialized Form

Constructor Summary
PJAServlet()
          Creates a default PJAServlet instance that tries its best to instantiate a default toolkit.
PJAServlet(boolean forcePJA)
          Creates a PJAServlet instance that tries to instantiate a default toolkit.
 
Method Summary
 java.awt.Image createImage(int width, int height)
          Returns an image of width x height pixels using default toolkit.
 void destroy()
          Override destroyPJA () instead of this final method.
 void destroyPJA()
          Override this method instead of the final method destroy ().
protected  void doDelete(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Override doDeletePJA () instead of this final method.
 void doDeletePJA(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Override this method instead of the final method doDelete ().
protected  void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Override doGetPJA () instead of this final method.
 void doGetPJA(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Override this method instead of the final method doGet ().
protected  void doOptions(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Override doOptionsPJA () instead of this final method.
 void doOptionsPJA(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Override this method instead of the final method doOptions ().
protected  void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Override doPostPJA () instead of this final method.
 void doPostPJA(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Override this method instead of the final method doPost ().
protected  void doPut(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Override doPutPJA () instead of this final method.
 void doPutPJA(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Override this method instead of the final method doPut ().
protected  void doTrace(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Override doTracePJA () instead of this final method.
 void doTracePJA(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Override this method instead of the final method doTrace ().
 java.lang.String getFontsPath()
          Override this method to return the fonts path where .pjaf files (JDK 1.1) or True Type files (JDK >= 1.2) can be found.
 java.lang.String getServletInfo()
          Override getServletInfoPJA () instead of this final method.
 java.lang.String getServletInfoPJA()
          Override this method instead of the final method getServletInfo ().
 java.lang.String getSystemProperty(java.lang.String property, java.lang.String defaultValue)
          Same as System.getProperty (String prop, String default) but System.getProperty () is called in a try catch block to catch SecurityException exceptions.
 java.lang.String getUserHomeDir()
          Override this method to return the user home directory where the file lib/font.properties can be found.
 void init()
          Override initPJA () instead of this final method.
 void init(javax.servlet.ServletConfig config)
          Override initPJA (ServletConfig config) instead of this final method.
 void initPJA()
          Override this method instead of the final method init ().
 void initPJA(javax.servlet.ServletConfig config)
          Override this method instead of the final method init (ServletConfig config).
 boolean isDefaultToolkitAvailable()
          This is a convenience method to know if default toolkit is available or not.
protected  void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Override servicePJA (HttpServletRequest req, HttpServletResponse resp) instead of this final method.
 void service(javax.servlet.ServletRequest req, javax.servlet.ServletResponse resp)
          Override servicePJA (ServletRequest req, ServletResponse resp) instead of this final method.
 void servicePJA(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Override this method instead of the final method service (HttpServletRequest req, HttpServletResponse resp).
 void servicePJA(javax.servlet.ServletRequest req, javax.servlet.ServletResponse resp)
          Override this method instead of the final method service (ServletRequest req, ServletResponse resp).
protected  boolean testDefaultToolkit()
           
 
Methods inherited from class javax.servlet.http.HttpServlet
getLastModified
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PJAServlet

public PJAServlet()
Creates a default PJAServlet instance that tries its best to instantiate a default toolkit.

See Also:
PJAServlet(boolean)

PJAServlet

public PJAServlet(boolean forcePJA)
Creates a PJAServlet instance that tries to instantiate a default toolkit.
If forcePJA is set to false, this constructor tries to instantiate a default toolkit with Toolkit.getDefaultToolkit () with different procedures in the following order : If forcePJA is set to true, PJAToolkit and PJAImage will always be used. This disables all Java2D features but ensures the same results on all platforms where subclasses of PJAServlet are used.

Method Detail

testDefaultToolkit

protected boolean testDefaultToolkit()

getFontsPath

public java.lang.String getFontsPath()
Override this method to return the fonts path where .pjaf files (JDK 1.1) or True Type files (JDK >= 1.2) can be found. If you want to return more than one directory separate them with File.pathSeparator.
Note : This method is called from within PJAServlet constructor.

Returns:
PJAServlet implementation returns "." + File.pathSeparator + getSystemProperty ("user.dir") + File.pathSeparator + getSystemProperty ("java.home")

getUserHomeDir

public java.lang.String getUserHomeDir()
Override this method to return the user home directory where the file lib/font.properties can be found. This is usefull for JDK 1.2.
Note : This method is called from within PJAServlet constructor.

Returns:
PJAServlet implementation returns getSystemProperty ("user.home")

getSystemProperty

public java.lang.String getSystemProperty(java.lang.String property,
                                          java.lang.String defaultValue)
Same as System.getProperty (String prop, String default) but System.getProperty () is called in a try catch block to catch SecurityException exceptions. If a SecurityException exception is catched, a log is done and defaultValue is returned.


isDefaultToolkitAvailable

public boolean isDefaultToolkitAvailable()
This is a convenience method to know if default toolkit is available or not. It avoids to run a Toolkit.getDefaultToolkit () and catch all the exeptions that may be thrown. java.awt.Font class can't be instantiated if this method returns false.

See Also:
PJAImage

createImage

public java.awt.Image createImage(int width,
                                  int height)
Returns an image of width x height pixels using default toolkit. If isDefaultToolkitAvailable () returns false, an instance of com.eteks.awt.PJAImage is returned.


getServletInfo

public final java.lang.String getServletInfo()
Override getServletInfoPJA () instead of this final method. Don't call super.getServletInfo () from getServletInfoPJA ().


getServletInfoPJA

public java.lang.String getServletInfoPJA()
Override this method instead of the final method getServletInfo (). PJAServlet implementation calls super.getServletInfo ().


init

public final void init(javax.servlet.ServletConfig config)
                throws javax.servlet.ServletException
Override initPJA (ServletConfig config) instead of this final method. Don't call super.init (config) from initPJA (ServletConfig config).

Throws:
javax.servlet.ServletException

initPJA

public void initPJA(javax.servlet.ServletConfig config)
             throws javax.servlet.ServletException
Override this method instead of the final method init (ServletConfig config). PJAServlet implementation calls super.init (config).

Throws:
javax.servlet.ServletException

init

public final void init()
                throws javax.servlet.ServletException
Override initPJA () instead of this final method. Don't call super.init () from initPJA ().

Throws:
javax.servlet.ServletException

initPJA

public void initPJA()
             throws javax.servlet.ServletException
Override this method instead of the final method init (). PJAServlet implementation calls super.init ().

Throws:
javax.servlet.ServletException

destroy

public final void destroy()
Override destroyPJA () instead of this final method. Don't call super.destroy () from destroyPJA ().


destroyPJA

public void destroyPJA()
Override this method instead of the final method destroy (). PJAServlet implementation calls super.destroy ().


service

public final void service(javax.servlet.ServletRequest req,
                          javax.servlet.ServletResponse resp)
                   throws javax.servlet.ServletException,
                          java.io.IOException
Override servicePJA (ServletRequest req, ServletResponse resp) instead of this final method. Don't call super.service (req, resp) from servicePJA (ServletRequest req, ServletResponse resp).

Throws:
javax.servlet.ServletException
java.io.IOException

servicePJA

public void servicePJA(javax.servlet.ServletRequest req,
                       javax.servlet.ServletResponse resp)
                throws javax.servlet.ServletException,
                       java.io.IOException
Override this method instead of the final method service (ServletRequest req, ServletResponse resp). PJAServlet implementation calls super.service (req, resp).

Throws:
javax.servlet.ServletException
java.io.IOException

doGet

protected final void doGet(javax.servlet.http.HttpServletRequest req,
                           javax.servlet.http.HttpServletResponse resp)
                    throws javax.servlet.ServletException,
                           java.io.IOException
Override doGetPJA () instead of this final method. Don't call super.doGet (req, resp) from doGetPJA (HttpServletRequest req, HttpServletResponse resp).

Throws:
javax.servlet.ServletException
java.io.IOException

doGetPJA

public void doGetPJA(javax.servlet.http.HttpServletRequest req,
                     javax.servlet.http.HttpServletResponse resp)
              throws javax.servlet.ServletException,
                     java.io.IOException
Override this method instead of the final method doGet (). PJAServlet implementation calls super.doGet ().

Throws:
javax.servlet.ServletException
java.io.IOException

doPost

protected final void doPost(javax.servlet.http.HttpServletRequest req,
                            javax.servlet.http.HttpServletResponse resp)
                     throws javax.servlet.ServletException,
                            java.io.IOException
Override doPostPJA () instead of this final method. Don't call super.doPost (req, resp) from doPostPJA (HttpServletRequest req, HttpServletResponse resp).

Throws:
javax.servlet.ServletException
java.io.IOException

doPostPJA

public void doPostPJA(javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse resp)
               throws javax.servlet.ServletException,
                      java.io.IOException
Override this method instead of the final method doPost (). PJAServlet implementation calls super.doPost ().

Throws:
javax.servlet.ServletException
java.io.IOException

doPut

protected final void doPut(javax.servlet.http.HttpServletRequest req,
                           javax.servlet.http.HttpServletResponse resp)
                    throws javax.servlet.ServletException,
                           java.io.IOException
Override doPutPJA () instead of this final method. Don't call super.doPut (req, resp) from doPutPJA (HttpServletRequest req, HttpServletResponse resp).

Throws:
javax.servlet.ServletException
java.io.IOException

doPutPJA

public void doPutPJA(javax.servlet.http.HttpServletRequest req,
                     javax.servlet.http.HttpServletResponse resp)
              throws javax.servlet.ServletException,
                     java.io.IOException
Override this method instead of the final method doPut (). PJAServlet implementation calls super.doPut ().

Throws:
javax.servlet.ServletException
java.io.IOException

doDelete

protected final void doDelete(javax.servlet.http.HttpServletRequest req,
                              javax.servlet.http.HttpServletResponse resp)
                       throws javax.servlet.ServletException,
                              java.io.IOException
Override doDeletePJA () instead of this final method. Don't call super.doDelete (req, resp) from doDeletePJA (HttpServletRequest req, HttpServletResponse resp).

Throws:
javax.servlet.ServletException
java.io.IOException

doDeletePJA

public void doDeletePJA(javax.servlet.http.HttpServletRequest req,
                        javax.servlet.http.HttpServletResponse resp)
                 throws javax.servlet.ServletException,
                        java.io.IOException
Override this method instead of the final method doDelete (). PJAServlet implementation calls super.doDelete ().

Throws:
javax.servlet.ServletException
java.io.IOException

doOptions

protected final void doOptions(javax.servlet.http.HttpServletRequest req,
                               javax.servlet.http.HttpServletResponse resp)
                        throws javax.servlet.ServletException,
                               java.io.IOException
Override doOptionsPJA () instead of this final method. Don't call super.doOptions (req, resp) from doOptionsPJA (HttpServletRequest req, HttpServletResponse resp).

Throws:
javax.servlet.ServletException
java.io.IOException

doOptionsPJA

public void doOptionsPJA(javax.servlet.http.HttpServletRequest req,
                         javax.servlet.http.HttpServletResponse resp)
                  throws javax.servlet.ServletException,
                         java.io.IOException
Override this method instead of the final method doOptions (). PJAServlet implementation calls super.doOptions ().

Throws:
javax.servlet.ServletException
java.io.IOException

doTrace

protected final void doTrace(javax.servlet.http.HttpServletRequest req,
                             javax.servlet.http.HttpServletResponse resp)
                      throws javax.servlet.ServletException,
                             java.io.IOException
Override doTracePJA () instead of this final method. Don't call super.doTrace (req, resp) from doTracetPJA (HttpServletRequest req, HttpServletResponse resp).

Throws:
javax.servlet.ServletException
java.io.IOException

doTracePJA

public void doTracePJA(javax.servlet.http.HttpServletRequest req,
                       javax.servlet.http.HttpServletResponse resp)
                throws javax.servlet.ServletException,
                       java.io.IOException
Override this method instead of the final method doTrace (). PJAServlet implementation calls super.doTrace ().

Throws:
javax.servlet.ServletException
java.io.IOException

service

protected final void service(javax.servlet.http.HttpServletRequest req,
                             javax.servlet.http.HttpServletResponse resp)
                      throws javax.servlet.ServletException,
                             java.io.IOException
Override servicePJA (HttpServletRequest req, HttpServletResponse resp) instead of this final method. Don't call super.service (req, resp) from servicePJA (HttpServletRequest req, HttpServletResponse resp).

Throws:
javax.servlet.ServletException
java.io.IOException

servicePJA

public void servicePJA(javax.servlet.http.HttpServletRequest req,
                       javax.servlet.http.HttpServletResponse resp)
                throws javax.servlet.ServletException,
                       java.io.IOException
Override this method instead of the final method service (HttpServletRequest req, HttpServletResponse resp). PJAServlet implementation calls super.service (req, resp).

Throws:
javax.servlet.ServletException
java.io.IOException

© 1997-2003 eTeks - All rights reserved