org.apache.myfaces.component.html.util

Class AddResource


public final class AddResource
extends java.lang.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 Log
log

Method Summary

static void
addInlineStyleToHeader(String inlineStyle, FacesContext context)
Adds the given Style Sheet to the document Header.
static void
addJavaScriptHere(Class componentClass, String resourceFileName, FacesContext context)
Adds the given Javascript resource to the document body, without passing UIComponent.
static void
addJavaScriptHere(Class componentClass, String resourceFileName, FacesContext context, UIComponent component)
Adds the given Javascript resource to the document body.
static void
addJavaScriptToHeader(Class componentClass, String resourceFileName, FacesContext context)
Adds the given Javascript resource to the document Header.
static void
addJavaScriptToHeader(Class componentClass, String resourceFileName, boolean defer, FacesContext context)
Adds the given Javascript resource to the document Header.
static void
addStyleSheet(Class componentClass, String resourceFileName, FacesContext context)
Adds the given Style Sheet to the document Header.
protected static String
getComponentName(Class componentClass)
static String
getResourceMappedPath(Class componentClass, String resourceFileName, FacesContext context)
Get the Path used to retrieve an internal resource for a custom component.
protected static String
getResourceMappedPath(String componentName, String resourceFileName, String contextPath)
static boolean
hasAdditionalHeaderInfoToRender(HttpServletRequest request)
static boolean
isResourceMappedPath(HttpServletRequest request)
static void
serveResource(HttpServletRequest request, HttpServletResponse response)
static void
writeWithFullHeader(HttpServletRequest request, ExtensionsResponseWrapper responseWrapper, HttpServletResponse response)
Add the resources to the <head> of the page.

Field Details

log

protected static final Log log

Method Details

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)
            throws IOException
Adds the given Javascript resource to the document body, without passing UIComponent.

addJavaScriptHere

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

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)
            throws IOException

writeWithFullHeader

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