## org.apache.myfaces.component.html.util
Class AddResource

    java.lang.Object
      org.apache.myfaces.component.html.util.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: 291865 $ $Date: 2005-09-27 05:07:57 -0400 (Tue, 27 Sep 2005) $
Author:
  Sylvain Vieujot (latest modification by $Author: mmarinschek $)

Field Summary
`protected static org.apache.commons.logging.Log` `log`

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

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### log

    protected static final org.apache.commons.logging.Log log

Method Detail

### addJavaScriptHere

    public static void addJavaScriptHere(java.lang.Class componentClass,
                                         java.lang.String resourceFileName,
                                         javax.faces.context.FacesContext context,
                                         javax.faces.component.UIComponent component)
                                  throws java.io.IOException

  Adds the given Javascript resource to the document body.

  Throws:
    `java.io.IOException`

### addJavaScriptHere

    public static void addJavaScriptHere(java.lang.Class componentClass,
                                         java.lang.String resourceFileName,
                                         javax.faces.context.FacesContext context)
                                  throws java.io.IOException

  Adds the given Javascript resource to the document body, without passing UIComponent.

  Throws:
    `java.io.IOException`

### addJavaScriptHere

    public static void addJavaScriptHere(java.lang.String baseDirectory,
                                         java.lang.String resourceFileName,
                                         javax.faces.context.FacesContext context)
                                  throws java.io.IOException

  Adds the given Javascript resource to the document body, without passing UIComponent.

  Throws:
    `java.io.IOException`

### addJavaScriptToHeader

    public static void addJavaScriptToHeader(java.lang.Class componentClass,
                                             java.lang.String resourceFileName,
                                             javax.faces.context.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(java.lang.Class componentClass,
                                             java.lang.String resourceFileName,
                                             boolean defer,
                                             javax.faces.context.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(java.lang.String baseDirectory,
                                             java.lang.String resourceFileName,
                                             javax.faces.context.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(java.lang.String baseDirectory,
                                             java.lang.String resourceFileName,
                                             boolean defer,
                                             javax.faces.context.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(java.lang.Class componentClass,
                                     java.lang.String resourceFileName,
                                     javax.faces.context.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.

### addStyleSheet

    public static void addStyleSheet(java.lang.String baseDirectory,
                                     java.lang.String resourceFileName,
                                     javax.faces.context.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.

### addInlineStyleToHeader

    public static void addInlineStyleToHeader(java.lang.String inlineStyle,
                                              javax.faces.context.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.

### addInlineScriptToHeader

    public static void addInlineScriptToHeader(java.lang.String inlineScript,
                                               javax.faces.context.FacesContext context)

  Adds the given Script to the document Header. If the style sheet is already has already been referenced, it's added only once.

### getResourceMappedPath

    public static java.lang.String getResourceMappedPath(java.lang.Class componentClass,
                                                         java.lang.String resourceFileName,
                                                         javax.faces.context.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.

### getResourceBasePath

    public static java.lang.String getResourceBasePath(java.lang.String baseDirectory)

### getResourceBasePath

    public static java.lang.String getResourceBasePath(java.lang.Class componentClass,
                                                       javax.faces.context.FacesContext context)

### getResourceBasePath

    public static java.lang.String getResourceBasePath(java.lang.String componentName,
                                                       java.lang.String contextPath)

### getResourceMappedPath

    protected static java.lang.String getResourceMappedPath(java.lang.String componentName,
                                                            java.lang.String resourceFileName,
                                                            java.lang.String contextPath)

### isResourceMappedPath

    public static boolean isResourceMappedPath(javax.servlet.http.HttpServletRequest request)

### getComponentName

    protected static java.lang.String getComponentName(java.lang.Class componentClass)

### serveResource

    public static void serveResource(javax.servlet.http.HttpServletRequest request,
                                     javax.servlet.http.HttpServletResponse response)
                              throws java.io.IOException

  Throws:
    `java.io.IOException`

### hasAdditionalHeaderInfoToRender

    public static boolean hasAdditionalHeaderInfoToRender(javax.servlet.http.HttpServletRequest request)

### writeWithFullHeader

    public static void writeWithFullHeader(javax.servlet.http.HttpServletRequest request,
                                           ExtensionsResponseWrapper responseWrapper,
                                           javax.servlet.http.HttpServletResponse response)
                                    throws java.io.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.

  Throws:
    `java.io.IOException`