org.apache.myfaces.component.html.util

Class AddResource

public final class AddResource extends Object

This is a utility class to render link to resources used by custom components. Mostly used to avoid having to include in the head of the pages before using a component.

Version: $Revision: 265021 $ $Date: 2005-08-31 13:40:37 +0200 (Wed, 31 Aug 2005) $

Author: Sylvain Vieujot (latest modification by $Author: svieujot $)

Field Summary
protected static Loglog
Method Summary
static voidaddInlineStyleToHeader(String inlineStyle, FacesContext context)
Adds the given Style Sheet to the document Header.
static voidaddJavaScriptHere(Class componentClass, String resourceFileName, FacesContext context, UIComponent component)
Adds the given Javascript resource to the document body.
static voidaddJavaScriptHere(Class componentClass, String resourceFileName, FacesContext context)
Adds the given Javascript resource to the document body, without passing UIComponent.
static voidaddJavaScriptToHeader(Class componentClass, String resourceFileName, FacesContext context)
Adds the given Javascript resource to the document Header.
static voidaddJavaScriptToHeader(Class componentClass, String resourceFileName, boolean defer, FacesContext context)
Adds the given Javascript resource to the document Header.
static voidaddStyleSheet(Class componentClass, String resourceFileName, FacesContext context)
Adds the given Style Sheet to the document Header.
protected static StringgetComponentName(Class componentClass)
static StringgetResourceMappedPath(Class componentClass, String resourceFileName, FacesContext context)
Get the Path used to retrieve an internal resource for a custom component.
protected static StringgetResourceMappedPath(String componentName, String resourceFileName, String contextPath)
static booleanhasAdditionalHeaderInfoToRender(HttpServletRequest request)
static booleanisResourceMappedPath(HttpServletRequest request)
static voidserveResource(HttpServletRequest request, HttpServletResponse response)
static voidwriteWithFullHeader(HttpServletRequest request, ExtensionsResponseWrapper responseWrapper, HttpServletResponse response)
Add the resources to the <head> of the page.

Field Detail

log

protected static final Log log

Method Detail

addInlineStyleToHeader

public static void addInlineStyleToHeader(String inlineStyle, FacesContext context)
Adds the given Style Sheet to the document Header. If the style sheet is already has already been referenced, it's added only once.

addJavaScriptHere

public static void addJavaScriptHere(Class componentClass, String resourceFileName, FacesContext context, UIComponent component)
Adds the given Javascript resource to the document body.

addJavaScriptHere

public static void addJavaScriptHere(Class componentClass, String resourceFileName, FacesContext context)
Adds the given Javascript resource to the document body, without passing UIComponent.

addJavaScriptToHeader

public static void addJavaScriptToHeader(Class componentClass, String resourceFileName, FacesContext context)
Adds the given Javascript resource to the document Header. If the script is already has already been referenced, it's added only once.

addJavaScriptToHeader

public static void addJavaScriptToHeader(Class componentClass, String resourceFileName, boolean defer, FacesContext context)
Adds the given Javascript resource to the document Header. If the script is already has already been referenced, it's added only once.

addStyleSheet

public static void addStyleSheet(Class componentClass, String resourceFileName, FacesContext context)
Adds the given Style Sheet to the document Header. If the style sheet is already has already been referenced, it's added only once.

getComponentName

protected static String getComponentName(Class componentClass)

getResourceMappedPath

public static String getResourceMappedPath(Class componentClass, String resourceFileName, FacesContext context)
Get the Path used to retrieve an internal resource for a custom component. Example : You can use this to initialize javascript scripts so that they know the path of some other resources (image, css, ...). AddResource.addJavaScriptOncePerPage(HtmlCalendarRenderer.class, "popcalendar.js", facesContext, "jscalendarSetImageDirectory("+AddResource.getResourceMappedPath(HtmlCalendarRenderer.class, "DB", facesContext)+")"); Note : set context to null if you want the path after the application context path.

getResourceMappedPath

protected static String getResourceMappedPath(String componentName, String resourceFileName, String contextPath)

hasAdditionalHeaderInfoToRender

public static boolean hasAdditionalHeaderInfoToRender(HttpServletRequest request)

isResourceMappedPath

public static boolean isResourceMappedPath(HttpServletRequest request)

serveResource

public static void serveResource(HttpServletRequest request, HttpServletResponse response)

writeWithFullHeader

public static void writeWithFullHeader(HttpServletRequest request, ExtensionsResponseWrapper responseWrapper, HttpServletResponse response)
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 resources is added. TODO : Change the ordering so that the user header CSS & JS override MyFaces' ones.