Project Wonder 5.0

er.extensions.appserver
Class ERXResponseRewriter

java.lang.Object
  extended by er.extensions.appserver.ERXResponseRewriter

public class ERXResponseRewriter
extends java.lang.Object

ERXResponseRewriter provides several utilities for manipulating a WOResponse after it has already been "drawn" by previous components.

Author:
mschrag
Properties
er.extensions.loadOnDemand if true, javascript files included in Ajax responses will be loaded on-demand (defaults to true)
           
er.ajax.secureResources if true, load all resources with https (default false)
           
er.ajax.AJComponent.htmlCloseHead the tag to insert in front of (defaults to </head>)
           
er.extensions.ERXResponseRewriter.javascriptTypeAttribute if true, type="text/javascript" will be added to injected script tags (defaults true)
           

Nested Class Summary
static class ERXResponseRewriter.ContextObserver
          ERXResponseRewriter uses the ContextObserver to reset the topIndex value at the end of the request.
static interface ERXResponseRewriter.Delegate
          The delegate that is called prior to adding resources into the page, which gives you a chance to deny the addition, or rewrite the addition to a custom resource.
static class ERXResponseRewriter.Resource
          Represents a resource in a framework, or a fully-qualified URL if fileName starts with a / or contains :// .
static class ERXResponseRewriter.TagMissingBehavior
          TagMissingBehavior specifies several ways the response rewriter should handle the case of having a missing tag that you attempted to insert in front of (for instance, if you ask to insert in the head tag and the head tag does not exist).
 
Field Summary
static org.apache.log4j.Logger log
           
 
Constructor Summary
ERXResponseRewriter()
           
 
Method Summary
static java.lang.String _htmlCloseHeadTag()
          Returns the tag name that scripts and resources should be inserted above.
static void addResourceInHead(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, java.lang.String framework, java.lang.String fileName, java.lang.String startTag, java.lang.String endTag)
          Adds a reference to an arbitrary file with a correct resource url wrapped between startTag and endTag in the html head tag if it isn't already present in the response.
static boolean addResourceInHead(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, java.lang.String framework, java.lang.String fileName, java.lang.String startTag, java.lang.String endTag, ERXResponseRewriter.TagMissingBehavior tagMissingBehavior)
          Adds a reference to an arbitrary file with a correct resource url wrapped between startTag and endTag in the html head tag if it isn't already present in the response.
static boolean addResourceInHead(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, java.lang.String framework, java.lang.String fileName, java.lang.String startTag, java.lang.String endTag, java.lang.String fallbackStartTag, java.lang.String fallbackEndTag, ERXResponseRewriter.TagMissingBehavior tagMissingBehavior)
          Adds a reference to an arbitrary file with a correct resource url wrapped between startTag and endTag in the html head tag if it isn't already present in the response.
static void addScriptCodeInHead(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, java.lang.String script)
          Adds javascript code in a script tag in the html head tag (without a name).
static void addScriptCodeInHead(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, java.lang.String script, java.lang.String scriptName)
          Adds javascript code in a script tag in the html head tag or inline if the request is an Ajax request.
static void addScriptResourceInHead(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, java.lang.String framework, java.lang.String fileName)
          Adds a script tag with a correct resource url into the html head tag if it isn't already present in the response, or inserts an Ajax OnDemand tag if the current request is an Ajax request.
static void addStylesheetResourceInHead(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, java.lang.String framework, java.lang.String fileName)
          Adds a stylesheet link tag with a correct resource url in the html head tag if it isn't already present in the response.
static void addStylesheetResourceInHead(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, java.lang.String framework, java.lang.String fileName, java.lang.String media)
          Adds a stylesheet link tag with a correct resource url in the html head tag if it isn't already present in the response.
static com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.Object> ajaxPageUserInfo(com.webobjects.appserver.WOContext context)
          Returns the page userInfo for the page component of the given context.
static boolean insertInResponseBeforeHead(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, java.lang.String content, ERXResponseRewriter.TagMissingBehavior tagMissingBehavior)
          Utility to add the given content into the response before the close of the head tag.
static boolean insertInResponseBeforeTag(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, java.lang.String content, java.lang.String tag, ERXResponseRewriter.TagMissingBehavior tagMissingBehavior)
          Utility to add the given content into the response before a particular HTML tag.
static boolean isResourceAddedToHead(com.webobjects.appserver.WOContext context, java.lang.String frameworkName, java.lang.String resourceName)
          Returns whether or not the given resource has been added to the HEAD tag.
static com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.Object> pageUserInfo(com.webobjects.appserver.WOComponent page)
          Returns the page userInfo for the given page component.
static com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.Object> pageUserInfo(com.webobjects.appserver.WOContext context)
          Returns the page userInfo for the page component of the given context.
static void replaceAllInResponse(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, java.util.regex.Pattern pattern, java.lang.String replacement)
          Replaces all occurrences of the given pattern in the response with the replacement string.
static void replaceFirstInResponse(com.webobjects.appserver.WOResponse response, com.webobjects.appserver.WOContext context, java.util.regex.Pattern pattern, java.lang.String replacement)
          Replaces the first occurrence of the given pattern in the response with the replacement string.
static void resourceAddedToHead(com.webobjects.appserver.WOContext context, java.lang.String frameworkName, java.lang.String resourceName)
          Records that the given resource (within the given framework) has been added to the head of this page.
static com.webobjects.foundation.NSMutableSet<java.lang.String> resourcesAddedToHead(com.webobjects.appserver.WOContext context)
          Returns the resources that have been added to the head of this page.
static void setDelegate(ERXResponseRewriter.Delegate delegate)
          Sets the response rewriter delegate to be used by this Application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final org.apache.log4j.Logger log
Constructor Detail

ERXResponseRewriter

public ERXResponseRewriter()
Method Detail

setDelegate

public static void setDelegate(ERXResponseRewriter.Delegate delegate)
Sets the response rewriter delegate to be used by this Application.

Parameters:
delegate - the response rewriter delegate to be used by this Application, or null to use the default

ajaxPageUserInfo

public static com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.Object> ajaxPageUserInfo(com.webobjects.appserver.WOContext context)
Returns the page userInfo for the page component of the given context. If this is the first request for the page user info for a non-ajax request, the user info will be cleared (so that reloading a page doesn't make the system believe it has already rendered script and css tags, for instance). If you do not want this behavior, use pageUserInfo(WOContext) instead.

Parameters:
context - the context to lookup
Returns:
the user info for the page component of the given context

pageUserInfo

public static com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.Object> pageUserInfo(com.webobjects.appserver.WOContext context)
Returns the page userInfo for the page component of the given context. Unlike ajaxPageUserInfo, information put into pageUserInfo will stay associated with the page as long as the page exists.

Parameters:
context - the context to lookup
Returns:
the user info for the page component of the given context

pageUserInfo

public static com.webobjects.foundation.NSMutableDictionary<java.lang.String,java.lang.Object> pageUserInfo(com.webobjects.appserver.WOComponent page)
Returns the page userInfo for the given page component. Unlike ajaxPageUserInfo, information put into pageUserInfo will stay associated with the page as long as the page exists.

Parameters:
page - the component to lookup
Returns:
the user info for the page component of the given context

_htmlCloseHeadTag

public static java.lang.String _htmlCloseHeadTag()
Returns the tag name that scripts and resources should be inserted above. Defaults to </head>, but this can be overridden by setting the property er.ajax.AJComponent.htmlCloseHead.


insertInResponseBeforeHead

public static boolean insertInResponseBeforeHead(com.webobjects.appserver.WOResponse response,
                                                 com.webobjects.appserver.WOContext context,
                                                 java.lang.String content,
                                                 ERXResponseRewriter.TagMissingBehavior tagMissingBehavior)
Utility to add the given content into the response before the close of the head tag.

Parameters:
response - the WOResponse
context - the WOContext
content - the content to insert.
tagMissingBehavior - how to handle the case where the tag is missing
Returns:
whether or not the content was inserted

replaceAllInResponse

public static void replaceAllInResponse(com.webobjects.appserver.WOResponse response,
                                        com.webobjects.appserver.WOContext context,
                                        java.util.regex.Pattern pattern,
                                        java.lang.String replacement)
Replaces all occurrences of the given pattern in the response with the replacement string.

Parameters:
response - the response
context - the context
pattern - the pattern to match
replacement - the replacement value

replaceFirstInResponse

public static void replaceFirstInResponse(com.webobjects.appserver.WOResponse response,
                                          com.webobjects.appserver.WOContext context,
                                          java.util.regex.Pattern pattern,
                                          java.lang.String replacement)
Replaces the first occurrence of the given pattern in the response with the replacement string.

Parameters:
response - the response
context - the context
pattern - the pattern to match
replacement - the replacement value

insertInResponseBeforeTag

public static boolean insertInResponseBeforeTag(com.webobjects.appserver.WOResponse response,
                                                com.webobjects.appserver.WOContext context,
                                                java.lang.String content,
                                                java.lang.String tag,
                                                ERXResponseRewriter.TagMissingBehavior tagMissingBehavior)
Utility to add the given content into the response before a particular HTML tag.

Parameters:
response - the WOResponse
context - the WOContext
content - the content to insert.
tag - the tag to insert before (in html syntax)
tagMissingBehavior - how to handle the case where the tag is missing
Returns:
whether or not the content was inserted

addScriptResourceInHead

public static void addScriptResourceInHead(com.webobjects.appserver.WOResponse response,
                                           com.webobjects.appserver.WOContext context,
                                           java.lang.String framework,
                                           java.lang.String fileName)
Adds a script tag with a correct resource url into the html head tag if it isn't already present in the response, or inserts an Ajax OnDemand tag if the current request is an Ajax request.

Parameters:
response - the response
context - the context
framework - the framework that contains the file
fileName - the name of the javascript file to add

addStylesheetResourceInHead

public static void addStylesheetResourceInHead(com.webobjects.appserver.WOResponse response,
                                               com.webobjects.appserver.WOContext context,
                                               java.lang.String framework,
                                               java.lang.String fileName)
Adds a stylesheet link tag with a correct resource url in the html head tag if it isn't already present in the response.

Parameters:
context - the context
response - the response
framework - the framework that contains the file
fileName - the name of the css file to add

addStylesheetResourceInHead

public static void addStylesheetResourceInHead(com.webobjects.appserver.WOResponse response,
                                               com.webobjects.appserver.WOContext context,
                                               java.lang.String framework,
                                               java.lang.String fileName,
                                               java.lang.String media)
Adds a stylesheet link tag with a correct resource url in the html head tag if it isn't already present in the response.

Parameters:
context - the context
response - the response
framework - the framework that contains the file
fileName - the name of the css file to add
media - the media type of the stylesheet (or null for default)

addScriptCodeInHead

public static void addScriptCodeInHead(com.webobjects.appserver.WOResponse response,
                                       com.webobjects.appserver.WOContext context,
                                       java.lang.String script)
Adds javascript code in a script tag in the html head tag (without a name). If you call this method multiple times with the same script code, it will add multiple times. To prevent this, call addScriptCodeInHead(WOResponse, String, String) passing in a name for your script.

Parameters:
response - the response to write into
script - the javascript code to insert

addScriptCodeInHead

public static void addScriptCodeInHead(com.webobjects.appserver.WOResponse response,
                                       com.webobjects.appserver.WOContext context,
                                       java.lang.String script,
                                       java.lang.String scriptName)
Adds javascript code in a script tag in the html head tag or inline if the request is an Ajax request.

Parameters:
response - the response to write into
script - the javascript code to insert
scriptName - the name of the script to insert (for duplicate checking)

addResourceInHead

public static void addResourceInHead(com.webobjects.appserver.WOResponse response,
                                     com.webobjects.appserver.WOContext context,
                                     java.lang.String framework,
                                     java.lang.String fileName,
                                     java.lang.String startTag,
                                     java.lang.String endTag)
Adds a reference to an arbitrary file with a correct resource url wrapped between startTag and endTag in the html head tag if it isn't already present in the response.

Parameters:
context - the context
response - the response
framework - the framework that contains the file
fileName - the name of the file to add
startTag - the HTML to prepend before the URL
endTag - the HTML to append after the URL

resourcesAddedToHead

public static com.webobjects.foundation.NSMutableSet<java.lang.String> resourcesAddedToHead(com.webobjects.appserver.WOContext context)
Returns the resources that have been added to the head of this page.

Parameters:
context - the WOContext
Returns:
the resources that have been added to the head of this page.

isResourceAddedToHead

public static boolean isResourceAddedToHead(com.webobjects.appserver.WOContext context,
                                            java.lang.String frameworkName,
                                            java.lang.String resourceName)
Returns whether or not the given resource has been added to the HEAD tag.

Parameters:
resourceName - the name of the resource to check
Returns:
true if the resource has been added to head

resourceAddedToHead

public static void resourceAddedToHead(com.webobjects.appserver.WOContext context,
                                       java.lang.String frameworkName,
                                       java.lang.String resourceName)
Records that the given resource (within the given framework) has been added to the head of this page.

Parameters:
context - the WOContext
frameworkName - the framework name of the resource
resourceName - the name of the resource

addResourceInHead

public static boolean addResourceInHead(com.webobjects.appserver.WOResponse response,
                                        com.webobjects.appserver.WOContext context,
                                        java.lang.String framework,
                                        java.lang.String fileName,
                                        java.lang.String startTag,
                                        java.lang.String endTag,
                                        ERXResponseRewriter.TagMissingBehavior tagMissingBehavior)
Adds a reference to an arbitrary file with a correct resource url wrapped between startTag and endTag in the html head tag if it isn't already present in the response.

Parameters:
response -
fileName -
startTag -
endTag -
Returns:
whether or not the content was added

addResourceInHead

public static boolean addResourceInHead(com.webobjects.appserver.WOResponse response,
                                        com.webobjects.appserver.WOContext context,
                                        java.lang.String framework,
                                        java.lang.String fileName,
                                        java.lang.String startTag,
                                        java.lang.String endTag,
                                        java.lang.String fallbackStartTag,
                                        java.lang.String fallbackEndTag,
                                        ERXResponseRewriter.TagMissingBehavior tagMissingBehavior)
Adds a reference to an arbitrary file with a correct resource url wrapped between startTag and endTag in the html head tag if it isn't already present in the response.

Parameters:
response -
context -
framework -
fileName -
startTag -
endTag -
fallbackStartTag -
fallbackEndTag -
tagMissingBehavior -
Returns:
whether or not the content was added

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.