org.moremotion.servlet
Class MoreMotionRequest

java.lang.Object
  extended by org.moremotion.servlet.MoreMotionRequest
Direct Known Subclasses:
DummyRequest, MoreMotionServletRequest

public abstract class MoreMotionRequest
extends java.lang.Object

MoreMotionRequest is the most important class of the MoreMotion Application Framework. It provides methods suitable with the way MoreMotion responds to request. One significant functionality provided by this class is decoding the request parameters correctly.

Request Parameter Decoding

When a request is sent to the server, the parameters existing in the request are encoded by the browsers using an encoding, i.e. ISO-8859-1. When an application server receives a request, it decodes these parameters and prepare a request object to pass to the Servlet.

If the application server does not use the same encoding that the browser used to encode the parameters during the decoding, the request parameters can get corrupted. Unfortunately this is the case for Tomcat. Tomcat always decode the request parameters using ISO-8859-1.

MoreMotion solves this problem with the help of the request parameter "_enc". In order to benefit from this functionality, a hidden input field with name "_enc" must be placed in the form elements and their values must be set to the encoding of the current page.

If you get the value of a request parameter by using the methods provided by this class, i.e. getParameter(), the value will be decoded using the encoding value supplied by this "_enc" parameter.

 String name = request.getParameter("name",null);
 // The name string will get the decoded "name" parameter.
 
However, some application servers can nicely guess the case and reads request parameters correctly. In that case you should disable the parameter conversion by setting the following system parameter to false.
 <enableParameterConversion>false</enableParameterConversion>
 

Version:
$Id: MoreMotionRequest.java 651 2010-10-04 08:24:02Z erkan $

Constructor Summary
MoreMotionRequest()
           
 
Method Summary
 void adjustVarsToPage(java.lang.String pageName)
          Lets the Vars object adjust itself to the specified page
abstract  void buildErrorResponse(java.lang.String name)
           
abstract  void buildingErrorResponse()
           
abstract  void buildResponse(java.lang.String name)
           
 ADOMNode createMessage(java.lang.Exception exception)
          Creates a new Request Datasource for the message if not already created and adds the given message in it.
 ADOMNode createMessage(java.lang.String unitName, java.lang.String messageId, java.lang.String[] arguments, java.lang.Object details)
          Creates a new Request Datasource for the message if not already created and adds the given message in it.
 void generateDefaultErrorPage()
          Deprecated.  
 void generatePage(java.lang.String pageName)
          Deprecated.  
 ADOM getApplicationADOM(java.lang.String name)
          Returns the ADOM saved to servlet context by the given name.
abstract  java.lang.String getApplicationPath()
           
abstract  java.lang.Object getAttribute(java.lang.String name)
           
abstract  java.lang.String getConfigurationScope()
           
 javax.servlet.ServletContext getContext()
           
abstract  java.lang.String getContextPath()
           
abstract  java.lang.String getCookieValue(java.lang.String cookieName)
           
 java.util.Hashtable getForcedDatasources()
          Returns the list of the datasource thats were forced to be included in the page XML data.
abstract  java.lang.String getLanguage()
          Returns the current language code
abstract  java.lang.String getMethod()
           
 MoreMotionResponse getMMResponse()
          Returns the session object.
 MoreMotionSession getMMSession()
          Returns the session object.
 java.io.File getOutputFile(java.lang.String fileName, java.lang.String type)
          Returns the file object of the real file for the specified file name relative to web application path.
abstract  java.lang.String getParameter(java.lang.String parmName)
          Returns the value of the specified request parameter.
abstract  java.lang.String getParameter(java.lang.String parmName, java.lang.String defValue)
          Returns the value of the specified request parameter.
 boolean getParameterAsBoolean(java.lang.String prmname, boolean defVal)
          Returns the value of the request parameters as boolean.
 double getParameterAsDouble(java.lang.String parmName, double defValue)
          Returns the value of the request parameters as double.
 int getParameterAsInt(java.lang.String parmName, int defValue)
          Returns the value of the request parameters as int.
abstract  java.util.Enumeration getParameterNames()
           
abstract  java.lang.String[] getParameterValues(java.lang.String parmName)
          Returns a String array that contains the values of the specified parameter.
abstract  java.lang.String getPlainParameter(java.lang.String parmName)
          Returns the value of the specified parameter.
abstract  java.lang.String getPlainParameter(java.lang.String parmName, java.lang.String defValue)
          Returns the value of the specified parameter.
 java.io.File getRealFile(java.lang.String fileName)
          Returns the file object of the real file for the specified file name relative to web application path.
 java.io.File getRealFile(java.lang.String fileName, java.lang.String path)
          Returns the file object of the real file for the specified file name relative to web application path.
 java.lang.String getRealPath(java.lang.String str)
           
 java.lang.String getRelativePath(java.io.File file)
          Returns the relative path (relative to the web application root)of the specified file.
 ADOM getRequestADOM(java.lang.String name)
          Returns the ADOM saved to request by the given name.
abstract  java.lang.String getRequestInfo(java.lang.String info)
           
 java.lang.String getResourceText(java.lang.String resid, java.lang.String[] args)
           
 java.lang.String getResourceText(java.lang.String resid, java.lang.String[] args, java.lang.String bundle)
           
 boolean getResponded()
          Returns true if the a response is already prepared for this request.
 javax.servlet.http.HttpServletResponse getResponse()
          Deprecated.  
 javax.servlet.http.HttpSession getSession()
          Deprecated.  
 ADOM getSessionADOM(java.lang.String name)
          Returns the ADOM saved to session by the given name.
 java.util.Stack getStack(java.lang.String stackName)
           
 MMSymbolResolver getSymbolResolver()
          Returns the MoreMotion Symbol Resolver that this request is associated.
 Vars getVars()
          Returns the Vars object associated with this request
 VariablePool getVPool()
          Returns the variable pool object that is associated with this request
 void includeInPageXML(java.lang.String dsname, java.lang.String resBundleName, ADOM adom)
          This method forces MoreMotion to include the content of the specified datasource to the page XML data even though there is no explicit reference to it in the page to be displayed next.
 ADOM newApplicationADOM(java.lang.String name)
          Creates a new Application ADOM and saves it in the servlet context.
 ADOM newRequestADOM(java.lang.String name)
          Creates a new protected Request ADOM and saves it in the request.
 ADOM newSessionADOM(java.lang.String name)
          Creates a new protected Session ADOM and saves it in the session.
 java.lang.Object peek(java.lang.String stackName)
           
 void pop(java.lang.String stackName)
           
 void processClosables()
           
 void push(java.lang.String stackName, java.lang.Object o)
           
 void registerClosable(Closable object)
           
 void removeApplicationADOM(java.lang.String name)
          Removes ADOM from servlet context by given name.
abstract  void removeAttribute(java.lang.String name)
           
 void removeRequestADOM(java.lang.String name)
          Removes ADOM from request by given name.
 void removeSessionADOM(java.lang.String name)
          Removes ADOM from session by given name.
 java.lang.String resolve(java.lang.String str)
          Resolves the MScript functions existing in the given string and returns it.
abstract  void setAttribute(java.lang.String name, java.lang.Object value)
           
abstract  void setCookieValue(java.lang.String cookieName, java.lang.String cookieValue, int maxAge)
           
abstract  void setNoCache()
           
 void setResponded(boolean value)
          This method can be used to notify to the MoreMotion that a response is already given by you so he should not bother generating one.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MoreMotionRequest

public MoreMotionRequest()
Method Detail

setResponded

public void setResponded(boolean value)
This method can be used to notify to the MoreMotion that a response is already given by you so he should not bother generating one.


getResponded

public boolean getResponded()
Returns true if the a response is already prepared for this request.


getConfigurationScope

public abstract java.lang.String getConfigurationScope()

getMethod

public abstract java.lang.String getMethod()

getSymbolResolver

public MMSymbolResolver getSymbolResolver()
Returns the MoreMotion Symbol Resolver that this request is associated.


adjustVarsToPage

public void adjustVarsToPage(java.lang.String pageName)
Lets the Vars object adjust itself to the specified page

Parameters:
pageName - The name of the page to adjust the page variables

getVars

public Vars getVars()
Returns the Vars object associated with this request


getVPool

public VariablePool getVPool()
Returns the variable pool object that is associated with this request


getLanguage

public abstract java.lang.String getLanguage()
Returns the current language code


getResourceText

public java.lang.String getResourceText(java.lang.String resid,
                                        java.lang.String[] args)
                                 throws ResourceException
Throws:
ResourceException

getResourceText

public java.lang.String getResourceText(java.lang.String resid,
                                        java.lang.String[] args,
                                        java.lang.String bundle)
                                 throws ResourceException
Throws:
ResourceException

createMessage

public ADOMNode createMessage(java.lang.String unitName,
                              java.lang.String messageId,
                              java.lang.String[] arguments,
                              java.lang.Object details)
Creates a new Request Datasource for the message if not already created and adds the given message in it.

Parameters:
unitName - Name of the reporting unit. This name will be used to name the data source to be created and the resource associated with it.
messageId - Either a message text or a resource Id. The message will be taken from the resource file unitName.res with this Id. If no resource is found with the given id in the resource file then messageId is used as the message text.
arguments - the message arguments which will be used to replace argument symbols (%0, %1, etc.) existing in the message text.
details - Either an Exception object that keeps the original exception or a String object that keeps the message details.
Returns:
created ADOMNode object to let you add extra information to the message created.

The XML Structure of the created message datasource is as follows:

 <unitName_messages>
    <message id="messageId">
      <text>Message text taken from the resource file with the given messageId</text>
      <unitname>Given unit name</unitname>
      <details>Message Details. Either the Stack Trace of the orginal exception or the given details as String</details>
    </message>
 </unitName_messages>
 

Example:

  ADOMNode msg = request.CreateMessage("myunit","MISSING_TABLE",new String[]{databaseName, tableName},e);
  msg.setNodeValue("extrainfo","extra info .....");
  request.generateDefaultErrorPage();  // To display messages using MoreMotion's default error page
  request.generatePage("MyErrorPage"); // To display messages using your error page.
                                       // You can prepare your Error Page using template element "\cpn\mor\ErrorPageTemplate.mmel"
 


createMessage

public ADOMNode createMessage(java.lang.Exception exception)
Creates a new Request Datasource for the message if not already created and adds the given message in it. If the Exception object is an instance of a MoreMotionException this method can extract the message id, arguments end details from it.

See Also:

If the given exception is or contains a java.sql.SQLException the returned ADOMNode object contains two additional entries that are "jdbc-error-code" and "jdbc-sql-state".


includeInPageXML

public void includeInPageXML(java.lang.String dsname,
                             java.lang.String resBundleName,
                             ADOM adom)
This method forces MoreMotion to include the content of the specified datasource to the page XML data even though there is no explicit reference to it in the page to be displayed next.

Parameters:
dsname - The name of the datasource to include to the page XML.
resBundleName - The name of the resource bundle that will be used to resolve $res() functions existing in the datasource content.
adom - the ADOM object that will provide the content.

getForcedDatasources

public java.util.Hashtable getForcedDatasources()
Returns the list of the datasource thats were forced to be included in the page XML data.


resolve

public java.lang.String resolve(java.lang.String str)
                         throws MScriptException
Resolves the MScript functions existing in the given string and returns it.

Parameters:
str - the input string
Returns:
resolved String
Throws:
MScriptException

getPlainParameter

public abstract java.lang.String getPlainParameter(java.lang.String parmName)
Returns the value of the specified parameter. Note that this method cannot be used to retrieve the values of the encrypted parameters.


getPlainParameter

public abstract java.lang.String getPlainParameter(java.lang.String parmName,
                                                   java.lang.String defValue)
Returns the value of the specified parameter. Note that this method cannot be used to retrieve the values of the encrypted parameters.


getParameter

public abstract java.lang.String getParameter(java.lang.String parmName)
Returns the value of the specified request parameter. It returns null if the parameters is not found.


getParameter

public abstract java.lang.String getParameter(java.lang.String parmName,
                                              java.lang.String defValue)
Returns the value of the specified request parameter. If the parameter is not found returns the default value.


getParameterAsInt

public int getParameterAsInt(java.lang.String parmName,
                             int defValue)
Returns the value of the request parameters as int. If the parameter is not found returns the default value.


getParameterAsDouble

public double getParameterAsDouble(java.lang.String parmName,
                                   double defValue)
Returns the value of the request parameters as double. If the parameter is not found returns the default value.


getParameterAsBoolean

public boolean getParameterAsBoolean(java.lang.String prmname,
                                     boolean defVal)
Returns the value of the request parameters as boolean. If the parameter is not found returns the default value.


getParameterNames

public abstract java.util.Enumeration getParameterNames()

setNoCache

public abstract void setNoCache()

getParameterValues

public abstract java.lang.String[] getParameterValues(java.lang.String parmName)
Returns a String array that contains the values of the specified parameter. This method is used if the request potentially contains the same parameter more than one. i.e. MyServlet?code=1&code=4&code=11


getRequestInfo

public abstract java.lang.String getRequestInfo(java.lang.String info)

getMMResponse

public MoreMotionResponse getMMResponse()
Returns the session object.


buildResponse

public abstract void buildResponse(java.lang.String name)
                            throws ResponseBuildingException
Throws:
ResponseBuildingException

buildErrorResponse

public abstract void buildErrorResponse(java.lang.String name)
                                 throws ResponseBuildingException
Throws:
ResponseBuildingException

buildingErrorResponse

public abstract void buildingErrorResponse()

generatePage

public void generatePage(java.lang.String pageName)
                  throws PageGenerationException
Deprecated. 

Throws:
PageGenerationException

generateDefaultErrorPage

public void generateDefaultErrorPage()
                              throws PageGenerationException
Deprecated. 

Throws:
PageGenerationException

getMMSession

public MoreMotionSession getMMSession()
Returns the session object.


getSession

public javax.servlet.http.HttpSession getSession()
Deprecated. 


getResponse

public javax.servlet.http.HttpServletResponse getResponse()
Deprecated. 


getContext

public javax.servlet.ServletContext getContext()

getContextPath

public abstract java.lang.String getContextPath()

getRealPath

public java.lang.String getRealPath(java.lang.String str)

getRelativePath

public java.lang.String getRelativePath(java.io.File file)
Returns the relative path (relative to the web application root)of the specified file. If the file is outside the web application root folder then the absolute file name of the specified file is returned.

Parameters:
file - File object
Returns:
relative path of the given file.

getApplicationPath

public abstract java.lang.String getApplicationPath()

setAttribute

public abstract void setAttribute(java.lang.String name,
                                  java.lang.Object value)

getAttribute

public abstract java.lang.Object getAttribute(java.lang.String name)

removeAttribute

public abstract void removeAttribute(java.lang.String name)

setCookieValue

public abstract void setCookieValue(java.lang.String cookieName,
                                    java.lang.String cookieValue,
                                    int maxAge)

getCookieValue

public abstract java.lang.String getCookieValue(java.lang.String cookieName)

getRealFile

public java.io.File getRealFile(java.lang.String fileName)
Returns the file object of the real file for the specified file name relative to web application path.

Note that this function may also return a handle to a temporary file under "WEB-INF/MM-INF/~tempfiles" folder whose name is stored in a variable incase of fileName is specified in a special way.

For example request.getRealFile("v:TEMPF") means return the handle of the temporary file whose name is stored in pool variable "TEMPF".

Parameters:
fileName - Relative file name
Returns:
File object of the real file.

getRealFile

public java.io.File getRealFile(java.lang.String fileName,
                                java.lang.String path)
Returns the file object of the real file for the specified file name relative to web application path.

Note that this function may also return a handle to a temporary file under "WEB-INF/MM-INF/~tempfiles" folder whose name is stored in a variable incase of fileName is specified in a special way.

For example request.getRealFile("v:TEMPF") means return the handle of the temporary file whose name is stored in pool variable "TEMPF".

Parameters:
fileName - Relative file name
path - The relative path of the file
Returns:
File object of the real file.

getOutputFile

public java.io.File getOutputFile(java.lang.String fileName,
                                  java.lang.String type)
Returns the file object of the real file for the specified file name relative to web application path.

Note that this function may also return a handle to a temporary file that will be created under "WEB-INF/MM-INF/~tempfiles" folder incase of fileName is specified in a special way. For example request.getOutputFile("v:TEMPF","text/plain") means create a file that will be automatically deleted in 1 hour under "WEB-INF/MM-INF/~tempfiles" folder and save its name in pool variable "TEMPF".

Parameters:
fileName - The relative name of the output file
type - The content types of the output file
Returns:
The File object

newRequestADOM

public ADOM newRequestADOM(java.lang.String name)
Creates a new protected Request ADOM and saves it in the request.

Parameters:
name - Name of the ADOM.
Returns:
Newly created ADOM.

newSessionADOM

public ADOM newSessionADOM(java.lang.String name)
Creates a new protected Session ADOM and saves it in the session.

Parameters:
name - Name of the ADOM.
Returns:
Newly created ADOM.

newApplicationADOM

public ADOM newApplicationADOM(java.lang.String name)
Creates a new Application ADOM and saves it in the servlet context.

Parameters:
name - Name of the ADOM.
Returns:
Newly created ADOM.

getRequestADOM

public ADOM getRequestADOM(java.lang.String name)
Returns the ADOM saved to request by the given name.

Parameters:
name - Name of the ADOM.
Returns:
null if ADOM cannot be found.

getSessionADOM

public ADOM getSessionADOM(java.lang.String name)
Returns the ADOM saved to session by the given name.

Parameters:
name - Name of the ADOM.
Returns:
null if ADOM cannot be found.

getApplicationADOM

public ADOM getApplicationADOM(java.lang.String name)
Returns the ADOM saved to servlet context by the given name.

Parameters:
name - Name of the ADOM.
Returns:
null if ADOM cannot be found.

removeRequestADOM

public void removeRequestADOM(java.lang.String name)
Removes ADOM from request by given name.


removeSessionADOM

public void removeSessionADOM(java.lang.String name)
Removes ADOM from session by given name.


removeApplicationADOM

public void removeApplicationADOM(java.lang.String name)
Removes ADOM from servlet context by given name.


registerClosable

public void registerClosable(Closable object)

processClosables

public void processClosables()
                      throws java.lang.Exception
Throws:
java.lang.Exception

push

public void push(java.lang.String stackName,
                 java.lang.Object o)

peek

public java.lang.Object peek(java.lang.String stackName)

pop

public void pop(java.lang.String stackName)

getStack

public java.util.Stack getStack(java.lang.String stackName)


Copyright © 2002-2011 MOR YAZILIM. All Rights Reserved.