org.barracudamvc.core.helper.servlet
Class ScriptDetector

java.lang.Object
  extended by org.barracudamvc.core.helper.servlet.ScriptDetector

public class ScriptDetector
extends Object

This class simply detects whether or not the client has scripting enabled.

Since:
1.0.1 (2001-10-22)
Version:
%I%, %G%
Author:
Christian Cryder [christianc@granitepeaks.com], Jacob Kjome

Field Summary
static boolean DETECT_CLIENT_SCRIPTING_ENABLED
          Flag indicating whether or not to check for client-side scripting
protected static org.apache.log4j.Logger logger
           
static String SCRIPT_FLAG
          Flag added to URL's and Forms and sent with requests allowing the server to determine if the client supports scripting
 
Constructor Summary
ScriptDetector()
           
 
Method Summary
static boolean checkClientReq(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          This method checks an incoming request to see if it has a scripting flag which indicates whether or not the client supports scripting.
static void prepareClientResp(Document doc, ViewContext vc)
          The purpose of this method is to prepare an outgoing Document with a scripting flag.
static void prepareClientResp(org.w3c.dom.html.HTMLDocument doc, ViewContext vc)
          The purpose of this method is to prepare an outgoing HTMLDocument with a scripting flag.
static String prepareRedirectURL(String url, ViewCapabilities vc)
          This method prepares a URL for redirect by adding the appropriate client scripting flag.
static Boolean scriptingEnabled(javax.servlet.http.HttpServletRequest req)
          This method evaluates a client request to see whether or not scripting is enabled (based on the presence of the SCRIPT_FLAG in the parameters).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.apache.log4j.Logger logger

DETECT_CLIENT_SCRIPTING_ENABLED

public static boolean DETECT_CLIENT_SCRIPTING_ENABLED
Flag indicating whether or not to check for client-side scripting


SCRIPT_FLAG

public static final String SCRIPT_FLAG
Flag added to URL's and Forms and sent with requests allowing the server to determine if the client supports scripting

See Also:
Constant Field Values
Constructor Detail

ScriptDetector

public ScriptDetector()
Method Detail

checkClientReq

public static boolean checkClientReq(javax.servlet.http.HttpServletRequest req,
                                     javax.servlet.http.HttpServletResponse resp)
                              throws IOException,
                                     javax.servlet.ServletException
This method checks an incoming request to see if it has a scripting flag which indicates whether or not the client supports scripting. If not, it writes a response that is sent back to the client which immediately causes the client to return again. However, this time, with the scripting flag set.

Right now, we only call this method if we are handling a GET request (the assumption being that if the client is POSTing data, it probably came from the server in the first place and, thus, should already have the script flag).

Parameters:
req - the servlet request
resp - the servlet response
Returns:
true if we actually wrote a response
Throws:
IOException
javax.servlet.ServletException

prepareClientResp

public static void prepareClientResp(org.w3c.dom.html.HTMLDocument doc,
                                     ViewContext vc)
The purpose of this method is to prepare an outgoing HTMLDocument with a scripting flag. This ensures that, upon follow-up requests, client scripting support can be determined.

This method adjusts all links and forms with a flag marking the client as not supporting scripting. In the case of links it adds the flag to the query string and in the case of forms, a hidden field. When the page is rendered on the client, if the client supports scripting, a script is invoked which re-sets the value of flags to indicate that scripting is supported.

Note that this method should not be called until AFTER all standard DOM manipulation has been completed (in other words, think of this as a filter that should be applied right before the final page gets sent back to the client).

Parameters:
doc - the DOM HTMLDocument that we wish to process
vc - the ViewContext in which this doc is to be rendered

prepareClientResp

public static void prepareClientResp(Document doc,
                                     ViewContext vc)
                              throws DOMException
The purpose of this method is to prepare an outgoing Document with a scripting flag. This ensures that, upon follow-up requests, client scripting support can be determined.

Note that it is preferable to send a specific type of document to this method such as an HTMLDocument or a WMLDocument since they provide the advantage of compile-time checking for the type where here, given a generic Document, we use instanceof to check the type of document and then cast Document to the appropriate document type. For instance, use the prepareClientResp(HTMLDocument, ViewContext) form if you have an HTMLDocument to prepare

This method claims to throw a DOMException for unsupported DOM's. However, since we don't have explicit support for WML, XHTML, or XML documents yet, we'll just let them pass unchanged rather than throw the exception. Leaving the throws clause here for future use to avoid modifying the interface.

Parameters:
doc - the DOM Document that we wish to process
vc - the ViewContext in which this doc is to be rendered
Throws:
DOMException - - if the document passed in cannot be cast to one of the currently supported types

prepareRedirectURL

public static String prepareRedirectURL(String url,
                                        ViewCapabilities vc)
This method prepares a URL for redirect by adding the appropriate client scripting flag.

Parameters:
url - the URL to redirect the client to
vc - the ViewCapabilities of the client
Returns:
a modified url if script detection is enabled, unmodified if not

scriptingEnabled

public static Boolean scriptingEnabled(javax.servlet.http.HttpServletRequest req)
This method evaluates a client request to see whether or not scripting is enabled (based on the presence of the SCRIPT_FLAG in the parameters). This function will either return true, false, or null (which means indeterminate).

Parameters:
req - the servlet request
Returns:
true if we can tell for sure that the client has scripting enabled, false if we know for sure that it does not, and null if we cannot determine for sure


Copyright © 2006 BarracudaMVC.org All Rights Reserved.