org.apache.myfaces.renderkit.html.util
Interface AddResource

All Known Implementing Classes:
AddResource2, DefaultAddResource, NonBufferingAddResource, StreamingAddResource

public interface AddResource

This interface defines methods necessary to render links to resources used by custom components. Mostly used to avoid having to include [script src="..."][/script] in the head of the pages before using a component.

Version:
$Revision: 673833 $ $Date: 2008-07-03 16:58:05 -0500 (Thu, 03 Jul 2008) $
Author:
Sylvain Vieujot (latest modification by $Author: skitching $)

Field Summary
static ResourcePosition BODY_END
           
static ResourcePosition BODY_ONLOAD
           
static ResourcePosition HEADER_BEGIN
           
 
Method Summary
 void addInlineScriptAtPosition(javax.faces.context.FacesContext context, ResourcePosition position, String inlineScript)
          Adds the given Inline Script at the specified document position.
 void addInlineStyleAtPosition(javax.faces.context.FacesContext context, ResourcePosition position, String inlineStyle)
          Adds the given Inline Style at the specified document position.
 void addJavaScriptAtPosition(javax.faces.context.FacesContext context, ResourcePosition position, Class myfacesCustomComponent, String resourceName)
          Insert a [script src="url"] entry into the document header at the specified document position.
 void addJavaScriptAtPosition(javax.faces.context.FacesContext context, ResourcePosition position, Class myfacesCustomComponent, String resourceName, boolean defer)
          Insert a [script src="url"] entry into the document header at the specified document position.
 void addJavaScriptAtPosition(javax.faces.context.FacesContext context, ResourcePosition position, ResourceHandler resourceHandler)
          Adds the given Javascript resource to the document header at the specified document positioy by supplying a resourcehandler instance.
 void addJavaScriptAtPosition(javax.faces.context.FacesContext context, ResourcePosition position, ResourceHandler resourceHandler, boolean defer)
          Adds the given Javascript resource at the specified document position.
 void addJavaScriptAtPosition(javax.faces.context.FacesContext context, ResourcePosition position, String uri)
          Insert a [script src="url"] entry into the document header at the specified document position.
 void addJavaScriptAtPosition(javax.faces.context.FacesContext context, ResourcePosition position, String uri, boolean defer)
          Adds the given Javascript resource at the specified document position.
 void addJavaScriptAtPositionPlain(javax.faces.context.FacesContext context, ResourcePosition position, Class myfacesCustomComponent, String resourceName)
          Deprecated. just to help to workaround a dojo bug
 void addJavaScriptHere(javax.faces.context.FacesContext context, Class myfacesCustomComponent, String resourceName)
          Insert a [script src="url"] entry at the current location in the response.
 void addJavaScriptHere(javax.faces.context.FacesContext context, ResourceHandler resourceHandler)
          Insert a [script src="url"] entry at the current location in the response.
 void addJavaScriptHere(javax.faces.context.FacesContext context, String uri)
          Insert a [script src="url"] entry at the current location in the response.
 void addJavaScriptHerePlain(javax.faces.context.FacesContext context, String uri)
          Deprecated. just to help to workaround a dojo bug
 void addJavaScriptToBodyTag(javax.faces.context.FacesContext context, String javascriptEventName, String addedJavaScript)
           
 void addResourceHere(javax.faces.context.FacesContext context, ResourceHandler resourceHandler)
           
 void addStyleSheet(javax.faces.context.FacesContext context, ResourcePosition position, Class myfacesCustomComponent, String resourceName)
          Adds the given Style Sheet at the specified document position.
 void addStyleSheet(javax.faces.context.FacesContext context, ResourcePosition position, ResourceHandler resourceHandler)
          Adds the given Style Sheet at the specified document position.
 void addStyleSheet(javax.faces.context.FacesContext context, ResourcePosition position, String uri)
          Adds the given Style Sheet at the specified document position.
 String getResourceUri(javax.faces.context.FacesContext context, Class myfacesCustomComponent, String resource)
           
 String getResourceUri(javax.faces.context.FacesContext context, Class myfacesCustomComponent, String resource, boolean withContextPath)
          Return a URI that can be embedded into an HTML page to reference a resource from a Tomahawk jarfile.
 String getResourceUri(javax.faces.context.FacesContext context, ResourceHandler resourceHandler)
          Get the Path used to retrieve an resource.
 String getResourceUri(javax.faces.context.FacesContext context, ResourceHandler resourceHandler, boolean withContextPath)
          Get the Path used to retrieve an resource.
 String getResourceUri(javax.faces.context.FacesContext context, String uri)
          Get the Path used to retrieve an resource.
 String getResourceUri(javax.faces.context.FacesContext context, String uri, boolean withContextPath)
          Get the Path used to retrieve an resource.
 boolean hasHeaderBeginInfos()
          check there is something to write to the header
 boolean isResourceUri(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletRequest request)
           
 void parseResponse(javax.servlet.http.HttpServletRequest request, String bufferedResponse, javax.servlet.http.HttpServletResponse response)
          Parses the response to mark the positions where code will be inserted
 boolean requiresBuffer()
          return true if you require the complete response buffered
 void responseFinished()
          called when the response has finished
 void responseStarted()
          called when the response start
 void serveResource(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 void setContextPath(String contextPath)
          set the context path of the web-app
 void writeMyFacesJavascriptBeforeBodyEnd(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Writes the javascript code necessary for myfaces in every page, just befode the closing </body> tag
 void writeResponse(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Writes the response
 void writeWithFullHeader(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Add the resources to the <head> of the page.
 

Field Detail

HEADER_BEGIN

static final ResourcePosition HEADER_BEGIN

BODY_END

static final ResourcePosition BODY_END

BODY_ONLOAD

static final ResourcePosition BODY_ONLOAD
Method Detail

setContextPath

void setContextPath(String contextPath)
set the context path of the web-app


addJavaScriptHere

void addJavaScriptHere(javax.faces.context.FacesContext context,
                       Class myfacesCustomComponent,
                       String resourceName)
                       throws IOException
Insert a [script src="url"] entry at the current location in the response. The resource is expected to be in the classpath, at the same location as the specified component + "/resource".

Example: when customComponent is class example.Widget, and resourceName is script.js, the resource will be retrieved from "example/Widget/resource/script.js" in the classpath.

Throws:
IOException

addJavaScriptHere

void addJavaScriptHere(javax.faces.context.FacesContext context,
                       String uri)
                       throws IOException
Insert a [script src="url"] entry at the current location in the response.

Parameters:
uri - is the location of the desired resource, relative to the base directory of the webapp (ie its contextPath).
Throws:
IOException

addJavaScriptHerePlain

void addJavaScriptHerePlain(javax.faces.context.FacesContext context,
                            String uri)
                            throws IOException
Deprecated. just to help to workaround a dojo bug

Insert a [script src="url"] entry at the current location in the response.
In constrast to the other methods this will not encode the url. So ,depending on the use case, it wont work in cookie-only environments.

Parameters:
uri - is the location of the desired resource, relative to the base directory of the webapp (ie its contextPath).
Throws:
IOException

addJavaScriptHere

void addJavaScriptHere(javax.faces.context.FacesContext context,
                       ResourceHandler resourceHandler)
                       throws IOException
Insert a [script src="url"] entry at the current location in the response.

Parameters:
context -
resourceHandler - is an object which specifies exactly how to build the url that is emitted into the script tag. Code which needs to generate URLs in ways that this class does not support by default can implement a custom ResourceHandler.
Throws:
IOException

addResourceHere

void addResourceHere(javax.faces.context.FacesContext context,
                     ResourceHandler resourceHandler)
                     throws IOException
Throws:
IOException

addJavaScriptAtPosition

void addJavaScriptAtPosition(javax.faces.context.FacesContext context,
                             ResourcePosition position,
                             ResourceHandler resourceHandler)
Adds the given Javascript resource to the document header at the specified document positioy by supplying a resourcehandler instance.

Use this method to have full control about building the reference url to identify the resource and to customize how the resource is written to the response. In most cases, however, one of the convenience methods on this class can be used without requiring a custom ResourceHandler to be provided.

If the script has already been referenced, it's added only once.

Note that this method queues the javascript for insertion, and that the script is inserted into the buffered response by the ExtensionsFilter after the page is complete.


addJavaScriptAtPosition

void addJavaScriptAtPosition(javax.faces.context.FacesContext context,
                             ResourcePosition position,
                             Class myfacesCustomComponent,
                             String resourceName)
Insert a [script src="url"] entry into the document header at the specified document position. If the script has already been referenced, it's added only once.

The resource is expected to be in the classpath, at the same location as the specified component + "/resource".

Example: when customComponent is class example.Widget, and resourceName is script.js, the resource will be retrieved from "example/Widget/resource/script.js" in the classpath.


addJavaScriptAtPosition

void addJavaScriptAtPosition(javax.faces.context.FacesContext context,
                             ResourcePosition position,
                             Class myfacesCustomComponent,
                             String resourceName,
                             boolean defer)
Insert a [script src="url"] entry into the document header at the specified document position. If the script has already been referenced, it's added only once.

Parameters:
defer - specifies whether the html attribute "defer" is set on the generated script tag. If this is true then the browser will continue processing the html page without waiting for the specified script to load and be run.

addJavaScriptAtPosition

void addJavaScriptAtPosition(javax.faces.context.FacesContext context,
                             ResourcePosition position,
                             String uri)
Insert a [script src="url"] entry into the document header at the specified document position. If the script has already been referenced, it's added only once.

Parameters:
uri - is the location of the desired resource, relative to the base directory of the webapp (ie its contextPath).

addJavaScriptAtPosition

void addJavaScriptAtPosition(javax.faces.context.FacesContext context,
                             ResourcePosition position,
                             String uri,
                             boolean defer)
Adds the given Javascript resource at the specified document position. If the script has already been referenced, it's added only once.


addJavaScriptToBodyTag

void addJavaScriptToBodyTag(javax.faces.context.FacesContext context,
                            String javascriptEventName,
                            String addedJavaScript)

addJavaScriptAtPosition

void addJavaScriptAtPosition(javax.faces.context.FacesContext context,
                             ResourcePosition position,
                             ResourceHandler resourceHandler,
                             boolean defer)
Adds the given Javascript resource at the specified document position. If the script has already been referenced, it's added only once.


addJavaScriptAtPositionPlain

void addJavaScriptAtPositionPlain(javax.faces.context.FacesContext context,
                                  ResourcePosition position,
                                  Class myfacesCustomComponent,
                                  String resourceName)
Deprecated. just to help to workaround a dojo bug

Adds the given Javascript resource at the specified document position. If the script has already been referenced, it's added only once.
In constrast to the other methods this will not encode the url. So ,depending on the use case, it wont work in cookie-only environments.


addStyleSheet

void addStyleSheet(javax.faces.context.FacesContext context,
                   ResourcePosition position,
                   Class myfacesCustomComponent,
                   String resourceName)
Adds the given Style Sheet at the specified document position. If the style sheet has already been referenced, it's added only once.


addStyleSheet

void addStyleSheet(javax.faces.context.FacesContext context,
                   ResourcePosition position,
                   String uri)
Adds the given Style Sheet at the specified document position. If the style sheet has already been referenced, it's added only once.


addStyleSheet

void addStyleSheet(javax.faces.context.FacesContext context,
                   ResourcePosition position,
                   ResourceHandler resourceHandler)
Adds the given Style Sheet at the specified document position. If the style sheet has already been referenced, it's added only once.


addInlineStyleAtPosition

void addInlineStyleAtPosition(javax.faces.context.FacesContext context,
                              ResourcePosition position,
                              String inlineStyle)
Adds the given Inline Style at the specified document position.


addInlineScriptAtPosition

void addInlineScriptAtPosition(javax.faces.context.FacesContext context,
                               ResourcePosition position,
                               String inlineScript)
Adds the given Inline Script at the specified document position.


getResourceUri

String getResourceUri(javax.faces.context.FacesContext context,
                      Class myfacesCustomComponent,
                      String resource,
                      boolean withContextPath)
Return a URI that can be embedded into an HTML page to reference a resource from a Tomahawk jarfile.

This method is intended for internal use by the Tomahawk project only, and will not serve resources for other projects (unless a custom AddResource implementation has been configured). Non-tomahawk code should use the variants that take an explicit ResourceHandler class.

Parameter myfacesCustomComponent is a tomahawk class that the resource is associated with. The resource is then expected to be in the classpath in the same package as the specified class (or a subpackage).

Parameter resource is a path relative to the .class file of the specified myfacesCustomComponent class. Param withContextPath controls whether the webapp name is prefixed to the generated url.


getResourceUri

String getResourceUri(javax.faces.context.FacesContext context,
                      Class myfacesCustomComponent,
                      String resource)

getResourceUri

String getResourceUri(javax.faces.context.FacesContext context,
                      ResourceHandler resourceHandler)
Get the Path used to retrieve an resource.


getResourceUri

String getResourceUri(javax.faces.context.FacesContext context,
                      ResourceHandler resourceHandler,
                      boolean withContextPath)
Get the Path used to retrieve an resource.


getResourceUri

String getResourceUri(javax.faces.context.FacesContext context,
                      String uri)
Get the Path used to retrieve an resource.


getResourceUri

String getResourceUri(javax.faces.context.FacesContext context,
                      String uri,
                      boolean withContextPath)
Get the Path used to retrieve an resource.


isResourceUri

boolean isResourceUri(javax.servlet.ServletContext servletContext,
                      javax.servlet.http.HttpServletRequest request)

serveResource

void serveResource(javax.servlet.ServletContext context,
                   javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
                   throws IOException
Throws:
IOException

parseResponse

void parseResponse(javax.servlet.http.HttpServletRequest request,
                   String bufferedResponse,
                   javax.servlet.http.HttpServletResponse response)
                   throws IOException
Parses the response to mark the positions where code will be inserted

Throws:
IOException

writeMyFacesJavascriptBeforeBodyEnd

void writeMyFacesJavascriptBeforeBodyEnd(javax.servlet.http.HttpServletRequest request,
                                         javax.servlet.http.HttpServletResponse response)
                                         throws IOException
Writes the javascript code necessary for myfaces in every page, just befode the closing </body> tag

Throws:
IOException

writeWithFullHeader

void writeWithFullHeader(javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response)
                         throws IOException
Add the resources to the <head> of the page. If the head tag is missing, but the <body> tag is present, the head tag is added. If both are missing, no resource is added. The ordering is such that the user header CSS & JS override the MyFaces' ones.

Throws:
IOException

writeResponse

void writeResponse(javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
                   throws IOException
Writes the response

Throws:
IOException

requiresBuffer

boolean requiresBuffer()
return true if you require the complete response buffered


responseStarted

void responseStarted()
called when the response start


responseFinished

void responseFinished()
called when the response has finished


hasHeaderBeginInfos

boolean hasHeaderBeginInfos()
check there is something to write to the header



Copyright © 2012 The Apache Software Foundation. All Rights Reserved.