com.sas.servlet.util
Class JavaScriptIncludeHandler

com.sas.servlet.util.JavaScriptIncludeHandler

public class JavaScriptIncludeHandler

JavaScriptIncludeHandler handles writing JavaScript include statements and preventing multiple includes of the same file on a page.

The path to the JavaScript files may be set at a request/page scope with static method JavaScriptIncludeHandler.setPath. This value will override the value set by ComponentPropertyManager.setJavaScriptLocation(String) which may also may be used to set this path.

The map of tbean keys to filenames may be set on a local level as well with the static method JavaScriptIncludeHandler.addLocalMapping.

The list of tbeans which have already been included is maintained as an attribute in the request object, as are the path and the local mappings.

A JSP writer could set the JavaScript path and add a mapping with the following code:

 JavaScriptIncludeHandler.setPath( "myjspath/", request );
 JavaScriptIncludeHandler.addLocalMapping(
     TreeView.class, "local_TreeView.js", request );
 

See Also:
ComponentPropertyManager.setJavaScriptLocation(String)

Field Summary
static java.lang.String DOJO_JS
           
static java.lang.String SAS_COMMON_JS
           
static java.lang.String SAS_FASTCLICKPROTECTION_CUSTOMFUNCTIONS_JS
           
static java.lang.String SAS_FASTCLICKPROTECTION_JS
           
static java.lang.String SAS_MODALSELECTOR_JS
           
static java.lang.String SAS_RESIZING_JS
           
static java.lang.String SAS_TRANSFORMATIONBEAN_JS
           
 
Constructor Summary
JavaScriptIncludeHandler(java.io.Writer out, javax.servlet.http.HttpServletRequest request)
          Constructor for JavaScriptIncludeHandler.
 
Method Summary
static void addLocalMapping(java.lang.Object key, java.lang.String filename, javax.servlet.http.HttpServletRequest request)
          Add to the local mapping of tbean names to filenames and dependencies.
static void addLocalMapping(java.lang.Object key, java.lang.String filename, java.lang.Object[] dependencies, javax.servlet.http.HttpServletRequest request)
          Add to the local mapping of tbean names to filenames.
static java.lang.Object[] getDependencies(java.lang.Object key)
          Get the dependencies associated with a tbean key.
static java.lang.String getEndScript(java.lang.String noScript)
           
static java.lang.String getFilename(java.lang.Object key)
          Get the filename associated with a tbean key.
static boolean getIncluded(java.lang.Object tbean, javax.servlet.http.HttpServletRequest request)
          Indicate if the JavaScriptIncludeHandler has already included a tbean on a request/page.
static java.lang.Object[] getLocalDependencies(java.lang.Object key, javax.servlet.http.HttpServletRequest request)
          Get the dependencies associated with a tbean key in the local mapping, which is only valid for the provided request.
static java.lang.String getLocalFilename(java.lang.Object key, javax.servlet.http.HttpServletRequest request)
          Get the filename associated with a tbean key in the local mapping, which is only valid for the provided request.
static java.lang.String getPath(javax.servlet.http.HttpServletRequest request)
          Get the path to the location of the JavaScript files.
static java.lang.String getStartScript()
           
static void setEnabled(boolean enable, javax.servlet.http.HttpServletRequest request)
          Enable or disable the writing of include statements on a request/page.
static void setIncluded(java.lang.Object tbean, boolean included, javax.servlet.http.HttpServletRequest request)
          Tell the JavaScriptIncludeHandler if a tbean has already been included on a request/page.
static void setPath(java.lang.String path, javax.servlet.http.HttpServletRequest request)
          Set the path to the location of the JavaScript files.
 void writeIncludes(java.lang.Object tbean)
          Write the JavaScript include statement if it hasn't already been included.
static void writeIncludes(java.io.Writer out, java.lang.Object tbean, javax.servlet.http.HttpServletRequest request)
          Write the JavaScript include statement if it hasn't already been included.
static void writeIncludeStatement(java.io.Writer out, java.lang.String filename, java.lang.String path)
           
 

Field Detail

DOJO_JS

public static final java.lang.String DOJO_JS
See Also:
Constant Field Values

SAS_COMMON_JS

public static final java.lang.String SAS_COMMON_JS
See Also:
Constant Field Values

SAS_MODALSELECTOR_JS

public static final java.lang.String SAS_MODALSELECTOR_JS
See Also:
Constant Field Values

SAS_RESIZING_JS

public static final java.lang.String SAS_RESIZING_JS
See Also:
Constant Field Values

SAS_TRANSFORMATIONBEAN_JS

public static final java.lang.String SAS_TRANSFORMATIONBEAN_JS
See Also:
Constant Field Values

SAS_FASTCLICKPROTECTION_JS

public static final java.lang.String SAS_FASTCLICKPROTECTION_JS
See Also:
Constant Field Values

SAS_FASTCLICKPROTECTION_CUSTOMFUNCTIONS_JS

public static final java.lang.String SAS_FASTCLICKPROTECTION_CUSTOMFUNCTIONS_JS
See Also:
Constant Field Values
Constructor Detail

JavaScriptIncludeHandler

public JavaScriptIncludeHandler(java.io.Writer out,
                                javax.servlet.http.HttpServletRequest request)
Constructor for JavaScriptIncludeHandler.

Method Detail

writeIncludes

public void writeIncludes(java.lang.Object tbean)
                   throws java.io.IOException
Write the JavaScript include statement if it hasn't already been included.

Throws:
java.io.IOException

writeIncludeStatement

public static void writeIncludeStatement(java.io.Writer out,
                                         java.lang.String filename,
                                         java.lang.String path)
                                  throws java.io.IOException
Throws:
java.io.IOException

getStartScript

public static java.lang.String getStartScript()

getEndScript

public static java.lang.String getEndScript(java.lang.String noScript)

writeIncludes

public static void writeIncludes(java.io.Writer out,
                                 java.lang.Object tbean,
                                 javax.servlet.http.HttpServletRequest request)
                          throws java.io.IOException
Write the JavaScript include statement if it hasn't already been included.

Throws:
java.io.IOException

getFilename

public static java.lang.String getFilename(java.lang.Object key)
Get the filename associated with a tbean key.


getDependencies

public static java.lang.Object[] getDependencies(java.lang.Object key)
Get the dependencies associated with a tbean key.

Returns:
An array of keys of tbeans/files which the tbean dependends on. These dependencies are included before the current tbean's include.

addLocalMapping

public static void addLocalMapping(java.lang.Object key,
                                   java.lang.String filename,
                                   java.lang.Object[] dependencies,
                                   javax.servlet.http.HttpServletRequest request)
Add to the local mapping of tbean names to filenames. This mapping overrides the static map for any key, and the path is part of the filename if using a local mapping so the path set with setPath will not be used.


addLocalMapping

public static void addLocalMapping(java.lang.Object key,
                                   java.lang.String filename,
                                   javax.servlet.http.HttpServletRequest request)
Add to the local mapping of tbean names to filenames and dependencies. This mapping overrides the static map for any key, and the path is part of the filename if using a local mapping so the path set with setPath will not be used.


getLocalFilename

public static java.lang.String getLocalFilename(java.lang.Object key,
                                                javax.servlet.http.HttpServletRequest request)
Get the filename associated with a tbean key in the local mapping, which is only valid for the provided request.


getLocalDependencies

public static java.lang.Object[] getLocalDependencies(java.lang.Object key,
                                                      javax.servlet.http.HttpServletRequest request)
Get the dependencies associated with a tbean key in the local mapping, which is only valid for the provided request.

Returns:
An array of keys of tbeans/files which the tbean dependends on. These dependencies are included before the current tbean's include.

setPath

public static void setPath(java.lang.String path,
                           javax.servlet.http.HttpServletRequest request)
Set the path to the location of the JavaScript files. The path should end in a "/" if it is a directory.


getPath

public static java.lang.String getPath(javax.servlet.http.HttpServletRequest request)
Get the path to the location of the JavaScript files.


setEnabled

public static void setEnabled(boolean enable,
                              javax.servlet.http.HttpServletRequest request)
Enable or disable the writing of include statements on a request/page.


setIncluded

public static void setIncluded(java.lang.Object tbean,
                               boolean included,
                               javax.servlet.http.HttpServletRequest request)
Tell the JavaScriptIncludeHandler if a tbean has already been included on a request/page.


getIncluded

public static boolean getIncluded(java.lang.Object tbean,
                                  javax.servlet.http.HttpServletRequest request)
Indicate if the JavaScriptIncludeHandler has already included a tbean on a request/page.




Copyright © 2009 SAS Institute Inc. All Rights Reserved.