jakarta.faces.render.RenderKit Maven / Gradle / Ivy
Show all versions of jakarta.faces Show documentation
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package jakarta.faces.render;
import java.io.OutputStream;
import java.io.Writer;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import jakarta.faces.component.UIComponent;
import jakarta.faces.context.ResponseStream;
import jakarta.faces.context.ResponseWriter;
/**
*
* RenderKit represents a collection of {@link Renderer}
* instances that, together, know how to render Jakarta Faces {@link UIComponent} instances for a specific
* client. Typically, {@link RenderKit}s are specialized for some combination of client device type, markup language,
* and/or user Locale
. A {@link RenderKit} also acts as a Factory for associated {@link Renderer}
* instances, which perform the actual rendering process for each component.
*
*
*
* A typical Jakarta Faces implementation will configure one or more {@link RenderKit} instances at web
* application startup. They are made available through calls to the getRenderKit()
methods of
* {@link RenderKitFactory}. Because {@link RenderKit} instances are shared, they must be implemented in a thread-safe
* manner. Due to limitations in the current specification having multiple RenderKit
instances at play in
* the same application requires a custom {@link jakarta.faces.application.ViewHandler} instance that is aware of how to
* deal with this case. This limitation will be lifted in a future version of the spec.
*
*
*
* The RenderKit
instance must also vend a {@link ResponseStateManager} instance, which is used in the
* process of saving and restoring tree structure and state.
*
*/
public abstract class RenderKit {
/**
*
* Register the specified {@link Renderer} instance, associated with the specified component family
and
* rendererType
, to the set of {@link Renderer}s registered with this {@link RenderKit}, replacing any
* previously registered {@link Renderer} for this combination of identifiers.
*
*
* @param family Component family of the {@link Renderer} to register
* @param rendererType Renderer type of the {@link Renderer} to register
* @param renderer {@link Renderer} instance we are registering
*
* @throws NullPointerException if family
or rendererType
or renderer
is null
*/
public abstract void addRenderer(String family, String rendererType, Renderer renderer);
/**
*
* Return the {@link Renderer} instance most recently registered for the specified component family
and
* rendererType
, if any; otherwise, return null
.
*
*
* @param family Component family of the requested {@link Renderer} instance
* @param rendererType Renderer type of the requested {@link Renderer} instance
*
* @throws NullPointerException if family
or rendererType
is null
*
* @return the {@link Renderer} instance
*/
public abstract Renderer getRenderer(String family, String rendererType);
/**
*
* Return an instance of {@link ResponseStateManager} to handle rendering technology specific state management
* decisions.
*
*
* @return the {@link ResponseStateManager}
*/
public abstract ResponseStateManager getResponseStateManager();
/**
*
* Use the provided Writer
to create a new {@link ResponseWriter} instance for the specified (optional)
* content type, and character encoding.
*
*
*
* Implementors are advised to consult the getCharacterEncoding()
method of class
* {@link jakarta.servlet.ServletResponse} to get the required value for the characterEncoding for this method. Since
* the Writer
for this response will already have been obtained (due to it ultimately being passed to this
* method), we know that the character encoding cannot change during the rendering of the response.
*
*
* @param writer the Writer around which this {@link ResponseWriter} must be built.
*
* @param contentTypeList an "Accept header style" list of content types for this response, or null
if the
* RenderKit should choose the best fit. As of the current version, the values accepted by the Standard render-kit for
* this parameter include any valid "Accept header style" String that includes the String text/html
,
* application/xhtml+xml
, application/xml
or text/xml
. This may change in a
* future version. The RenderKit must support a value for this argument that comes straight from the Accept
* HTTP header, and therefore requires parsing according to the specification of the Accept
header. Please
* see Section 14.1 of RFC 2616 for the specification of
* the Accept
header.
*
* @param characterEncoding such as "ISO-8859-1" for this ResponseWriter, or null
if the
* RenderKit
should choose the best fit. Please see
* the IANA for a list of character encodings.
*
* @return a new {@link ResponseWriter}.
*
* @throws IllegalArgumentException if no matching content type can be found in contentTypeList
, no
* appropriate content type can be found with the implementation dependent best fit algorithm, or no matching character
* encoding can be found for the argument characterEncoding
.
*
*/
public abstract ResponseWriter createResponseWriter(Writer writer, String contentTypeList, String characterEncoding);
/**
*
* Use the provided OutputStream
to create a new {@link ResponseStream} instance.
*
*
* @param out the {@code OutputStream} around which to create the {@link ResponseStream}
*
* @return the new {@link ResponseStream}
*
*/
public abstract ResponseStream createResponseStream(OutputStream out);
/**
*
* Return an Iterator
over the component-family entries supported by this RenderKit
instance.
*
*
*
* The default implementation of this method returns an empty Iterator
*
*
* @since 2.0
*
* @return Return an Iterator
over the component-family entries
*
*/
public Iterator getComponentFamilies() {
Set empty = Collections.emptySet();
return empty.iterator();
}
/**
*
* Return an Iterator
over the renderer-type entries for the given component-family.
*
*
*
* If the specified componentFamily
is not known to this RenderKit
implementation, return an
* empty Iterator
*
*
*
* The default implementation of this method returns an empty Iterator
*
*
* @param componentFamily one of the members of the Iterator
returned by {@link #getComponentFamilies}.
*
* @since 2.0
*
* @return an Iterator
over the renderer-type
*
*/
public Iterator getRendererTypes(String componentFamily) {
Set empty = Collections.emptySet();
return empty.iterator();
}
/**
*
* Register the specified {@link ClientBehaviorRenderer} instance, associated with the specified component
* type
, to the set of {@link ClientBehaviorRenderer}s registered with this {@link RenderKit}, replacing
* any previously registered {@link ClientBehaviorRenderer} for this type.
*
*
* @param type type of the {@link ClientBehaviorRenderer} to register
* @param renderer {@link ClientBehaviorRenderer} instance we are registering
*
* @throws NullPointerException if type
or renderer
is null
*
* @since 2.0
*/
public void addClientBehaviorRenderer(String type, ClientBehaviorRenderer renderer) {
throw new UnsupportedOperationException("The default implementation must override this method");
}
/**
*
* Return the {@link ClientBehaviorRenderer} instance most recently registered for the specified type
, if
* any; otherwise, return null
.
*
*
* @param type type of the requested {@link ClientBehaviorRenderer} instance
*
* @throws NullPointerException if type
is null
*
* @since 2.0
*
* @return the {@link ClientBehaviorRenderer} instance
*/
public ClientBehaviorRenderer getClientBehaviorRenderer(String type) {
throw new UnsupportedOperationException("The default implementation must override this method");
}
/**
*
* Return an Iterator
over the {@link ClientBehaviorRenderer} types.
*
*
* @since 2.0
*
* @return an Iterator
over the {@link ClientBehaviorRenderer}
*/
public Iterator getClientBehaviorRendererTypes() {
throw new UnsupportedOperationException("The default implementation must override this method");
}
}