com.sun.faces.renderkit
Class RenderKitUtils

java.lang.Object
  extended by com.sun.faces.renderkit.RenderKitUtils

public class RenderKitUtils
extends java.lang.Object

A set of utilities for use in RenderKits.


Field Summary
protected static java.util.logging.Logger LOGGER
           
 
Method Summary
static char[] compressJS(java.lang.String JSString)
          This is a utility method for compressing multi-lined javascript.
static java.lang.String createValidECMAIdentifier(java.lang.String origIdentifier)
          Replaces all occurrences of - with $_.
static java.lang.String determineContentType(java.lang.String accept, java.lang.String serverSupportedTypes, java.lang.String preferredType)
          Given an accept String from the client, and a String of server supported content types, determine the best qualified content type for the client.
static java.lang.String getCommandLinkOnClickScript(java.lang.String formClientId, java.lang.String commandClientId, java.lang.String target, HtmlBasicRenderer.Param[] params)
          Returns a string that can be inserted into the onclick handler of a command.
static javax.faces.render.RenderKit getCurrentRenderKit(javax.faces.context.FacesContext context)
          Return the RenderKit for the current request.
static javax.faces.render.ResponseStateManager getResponseStateManager(javax.faces.context.FacesContext context, java.lang.String renderKitId)
          Obtain and return the ResponseStateManager for the specified #renderKitId.
static java.util.Iterator<javax.faces.model.SelectItem> getSelectItems(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Return an Iterator over SelectItem instances representing the available options for this component, assembled from the set of UISelectItem and/or UISelectItems components that are direct children of this component.
static boolean isXml(java.lang.String contentType)
           
static void loadSunJsfJs(javax.faces.context.ExternalContext extContext)
          Loads the contents of the sunjsf.js file into memory removing any comments/empty lines it encoutners, and, if enabled, compressing the result.
static java.lang.String prefixAttribute(java.lang.String attrName, boolean isXhtml)
           
static java.lang.String prefixAttribute(java.lang.String attrName, javax.faces.context.ResponseWriter writer)
           
static void renderFormInitScript(javax.faces.context.ResponseWriter writer, javax.faces.context.FacesContext context)
          Renders the Javascript necessary to add and remove request parameters to the current form.
static void renderPassThruAttributes(javax.faces.context.FacesContext context, javax.faces.context.ResponseWriter writer, javax.faces.component.UIComponent component)
          Render any "passthru" attributes, where we simply just output the raw name and value of the attribute.
static void renderPassThruAttributes(javax.faces.context.FacesContext context, javax.faces.context.ResponseWriter writer, javax.faces.component.UIComponent component, java.lang.String[] excludes)
          Render any "passthru" attributes, where we simply just output the raw name and value of the attribute.
static void renderXHTMLStyleBooleanAttributes(javax.faces.context.ResponseWriter writer, javax.faces.component.UIComponent component)
          Renders the attributes from BOOLEAN_ATTRIBUTES using XHMTL semantics (i.e., disabled="disabled").
static void renderXHTMLStyleBooleanAttributes(javax.faces.context.ResponseWriter writer, javax.faces.component.UIComponent component, java.lang.String[] excludes)
          Renders the attributes from BOOLEAN_ATTRIBUTES using XHMTL semantics (i.e., disabled="disabled").
static void writeSunJS(javax.faces.context.FacesContext context, java.io.Writer writer)
          Return the implementation JavaScript.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

protected static final java.util.logging.Logger LOGGER
Method Detail

getCurrentRenderKit

public static javax.faces.render.RenderKit getCurrentRenderKit(javax.faces.context.FacesContext context)

Return the RenderKit for the current request.

Parameters:
context - the FacesContext of the current request
Returns:
the RenderKit for the current request.

getResponseStateManager

public static javax.faces.render.ResponseStateManager getResponseStateManager(javax.faces.context.FacesContext context,
                                                                              java.lang.String renderKitId)
                                                                       throws javax.faces.FacesException

Obtain and return the ResponseStateManager for the specified #renderKitId.

Parameters:
context - the FacesContext of the current request
renderKitId - RenderKit ID
Returns:
the ResponseStateManager for the specified #renderKitId
Throws:
javax.faces.FacesException - if an exception occurs while trying to obtain the ResponseStateManager

getSelectItems

public static java.util.Iterator<javax.faces.model.SelectItem> getSelectItems(javax.faces.context.FacesContext context,
                                                                              javax.faces.component.UIComponent component)

Return an Iterator over SelectItem instances representing the available options for this component, assembled from the set of UISelectItem and/or UISelectItems components that are direct children of this component. If there are no such children, an empty Iterator is returned.

Parameters:
context - The FacesContext for the current request. If null, the UISelectItems behavior will not work.
component - the component
Throws:
java.lang.IllegalArgumentException - if context is null

renderPassThruAttributes

public static void renderPassThruAttributes(javax.faces.context.FacesContext context,
                                            javax.faces.context.ResponseWriter writer,
                                            javax.faces.component.UIComponent component)
                                     throws java.io.IOException

Render any "passthru" attributes, where we simply just output the raw name and value of the attribute. This method is aware of the set of HTML4 attributes that fall into this bucket. Examples are all the javascript attributes, alt, rows, cols, etc.

This version of the method allows the user to exclude certain attributes from being processed.

Parameters:
context - context the FacesContext of the current request
writer - writer the ResponseWriter to be used when writing the attributes
component - the component
Throws:
java.io.IOException - if an error occurs writing the attributes
See Also:
renderPassThruAttributes(javax.faces.context.FacesContext, javax.faces.context.ResponseWriter, javax.faces.component.UIComponent, String[])

renderPassThruAttributes

public static void renderPassThruAttributes(javax.faces.context.FacesContext context,
                                            javax.faces.context.ResponseWriter writer,
                                            javax.faces.component.UIComponent component,
                                            java.lang.String[] excludes)
                                     throws java.io.IOException

Render any "passthru" attributes, where we simply just output the raw name and value of the attribute. This method is aware of the set of HTML4 attributes that fall into this bucket. Examples are all the javascript attributes, alt, rows, cols, etc.

This version of the method allows the user to exclude certain attributes from being processed.

Parameters:
context - context the FacesContext of the current request
writer - writer the ResponseWriter to be used when writing the attributes
component - the component
excludes - any attributes that should be excluded from writing to the response
Throws:
java.io.IOException - if an error occurs writing the attributes

prefixAttribute

public static java.lang.String prefixAttribute(java.lang.String attrName,
                                               javax.faces.context.ResponseWriter writer)

prefixAttribute

public static java.lang.String prefixAttribute(java.lang.String attrName,
                                               boolean isXhtml)

renderXHTMLStyleBooleanAttributes

public static void renderXHTMLStyleBooleanAttributes(javax.faces.context.ResponseWriter writer,
                                                     javax.faces.component.UIComponent component)
                                              throws java.io.IOException

Renders the attributes from BOOLEAN_ATTRIBUTES using XHMTL semantics (i.e., disabled="disabled").

Parameters:
writer - writer the ResponseWriter to be used when writing the attributes
component - the component
Throws:
java.io.IOException - if an error occurs writing the attributes

renderXHTMLStyleBooleanAttributes

public static void renderXHTMLStyleBooleanAttributes(javax.faces.context.ResponseWriter writer,
                                                     javax.faces.component.UIComponent component,
                                                     java.lang.String[] excludes)
                                              throws java.io.IOException

Renders the attributes from BOOLEAN_ATTRIBUTES using XHMTL semantics (i.e., disabled="disabled").

This version of the method allows the user to exclude certain attributes from being processed.

Parameters:
writer - writer the ResponseWriter to be used when writing the attributes
component - the component
excludes - any attributes that should be excluded from writing to the response
Throws:
java.io.IOException - if an error occurs writing the attributes

determineContentType

public static java.lang.String determineContentType(java.lang.String accept,
                                                    java.lang.String serverSupportedTypes,
                                                    java.lang.String preferredType)

Given an accept String from the client, and a String of server supported content types, determine the best qualified content type for the client. If no match is found, or either of the arguments are null, null is returned.

Parameters:
accept - The client accept String
serverSupportedTypes - The types that the server supports
preferredType - The preferred content type if another type is found with the same highest quality factor.
Returns:
The content type String

isXml

public static boolean isXml(java.lang.String contentType)
Parameters:
contentType - the content type in question
Returns:
true if the content type is a known XML-based content type, otherwise, false

createValidECMAIdentifier

public static java.lang.String createValidECMAIdentifier(java.lang.String origIdentifier)

Replaces all occurrences of - with $_.

Parameters:
origIdentifier - the original identifer that needs to be 'ECMA-ized'
Returns:
an ECMA valid identifer

renderFormInitScript

public static void renderFormInitScript(javax.faces.context.ResponseWriter writer,
                                        javax.faces.context.FacesContext context)
                                 throws java.io.IOException

Renders the Javascript necessary to add and remove request parameters to the current form.

Parameters:
writer - the ResponseWriter
context - the FacesContext for the current request
Throws:
java.io.IOException - if an error occurs writing to the response

getCommandLinkOnClickScript

public static java.lang.String getCommandLinkOnClickScript(java.lang.String formClientId,
                                                           java.lang.String commandClientId,
                                                           java.lang.String target,
                                                           HtmlBasicRenderer.Param[] params)

Returns a string that can be inserted into the onclick handler of a command. This string will add all request parameters as well as the client ID of the activated command to the form as hidden input parameters, update the target of the link if necessary, and handle the form submission. The content of SUN_JSF_JS must be rendered prior to using this method.

Parameters:
formClientId - the client ID of the form
commandClientId - the client ID of the command
target -
params - the nested parameters, if any @return a String suitable for the onclick handler of a command

compressJS

public static char[] compressJS(java.lang.String JSString)

This is a utility method for compressing multi-lined javascript. In the case of SUN_JSF_JS it offers about a 47% decrease in length.

For our purposes, compression is just trimming each line and then writing it out. It's pretty simplistic, but it works.

Parameters:
JSString - the string to compress
Returns:
the compressed string

writeSunJS

public static void writeSunJS(javax.faces.context.FacesContext context,
                              java.io.Writer writer)
                       throws java.io.IOException

Return the implementation JavaScript. If compression is enabled, the result will be compressed.

Parameters:
context - - the FacesContext for the current request
writer - - the Writer to write the JS to
Throws:
java.io.IOException

loadSunJsfJs

public static void loadSunJsfJs(javax.faces.context.ExternalContext extContext)

Loads the contents of the sunjsf.js file into memory removing any comments/empty lines it encoutners, and, if enabled, compressing the result.

This method should only be called when the application is being initialized.



Copyright ? 2002-2006 Sun Microsystems, Inc. All Rights Reserved.