/* * The contents of this file are subject to the terms * of the Common Development and Distribution License * (the License). You may not use this file except in * compliance with the License. * * You can obtain a copy of the license at * https://jsftemplating.dev.java.net/cddl1.html or * jsftemplating/cddl1.txt. * See the License for the specific language governing * permissions and limitations under the License. * * When distributing Covered Code, include this CDDL * Header Notice in each file and include the License file * at jsftemplating/cddl1.txt. * If applicable, add the following below the CDDL Header, * with the fields enclosed by brackets [] replaced by * you own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. */ /* * ScopeHandlers.java * * Created on December 2, 2004, 3:06 AM */ package com.sun.jsftemplating.handlers; import com.sun.jsftemplating.annotation.Handler; import com.sun.jsftemplating.annotation.HandlerInput; import com.sun.jsftemplating.annotation.HandlerOutput; import com.sun.jsftemplating.el.PageSessionResolver; import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext; import com.sun.jsftemplating.resource.ResourceBundleManager; import com.sun.jsftemplating.util.Util; import java.io.Serializable; import java.util.Formatter; import java.util.HashMap; import java.util.Iterator; import java.util.Locale; import java.util.Map; import java.util.ResourceBundle; import javax.faces.component.UIComponent; import javax.faces.component.UIViewRoot; import javax.faces.context.FacesContext; /** *
This class contains * {@link com.sun.jsftemplating.layout.descriptors.handler.Handler} * methods that perform common utility-type functions.
* * @author Ken Paulsen (ken.paulsen@sun.com) */ public class ScopeHandlers { /** *Default Constructor.
*/ public ScopeHandlers() { } /** *This handler gets a request attribute. It requires "key" as an * input value. It returns "value" as an output value. Note this * can also be done via #{requestScope["attributeName"]}.
* * @param context The {@link HandlerContext}. */ @Handler(id="getAttribute", input={ @HandlerInput(name="key", type=String.class, required=true)}, output={ @HandlerOutput(name="value", type=Object.class)}) public static void getAttribute(HandlerContext context) { String key = (String) context.getInputValue("key"); Object value = context.getFacesContext().getExternalContext(). getRequestMap().get(key); context.setOutputValue("value", value); } /** *This handler sets a request attribute. It requires "key" and * "value" input values to be passed in.
* * @param context The {@link HandlerContext}. */ @Handler(id="setAttribute", input={ @HandlerInput(name="key", type=String.class, required=true), @HandlerInput(name="value", required=true)}) public static void setAttribute(HandlerContext context) { String key = (String) context.getInputValue("key"); Object value = context.getInputValue("value"); context.getFacesContext().getExternalContext(). getRequestMap().put(key, value); } /** *This handler produces a String consisting of all the request * attributes. It outputs this via the "value" output value.
*/ @Handler(id="dumpAttributes", output={ @HandlerOutput(name="value", type=String.class) }) public static void dumpAttributes(HandlerContext context) { Map This handler gets a "page" session attribute. It requires
* key as an input value. It returns value
* as an output value. You may pass in the page
* (UIViewRoot) as an input value via the
* page input value, if you don't the current
* UIViewRoot will be used.
This handler sets a page session attribute. It requires
* key and value input values to be passed
* in. page may optionally be passed in to specify the
* page (UIViewRoot) that should be used -- otherwise
* the current UIViewRoot is used.
This handler produces a String consisting of all the page session
* attributes. It outputs this via the value output
* value. This handler optionally accepts the page input
* value (UIViewRoot) -- if not supplied the current
* UIViewRoot is used.
This handler gets a session attribute. It requires "key" as an * input value. It returns "value" as an output value. Note this * can also be done via #{sessionScope["attributeName"]}.
* * @param context The {@link HandlerContext}. */ @Handler(id="getSessionAttribute", input={ @HandlerInput(name="key", type=String.class, required=true)}, output={ @HandlerOutput(name="value", type=Object.class)}) public static void getSessionAttribute(HandlerContext context) { String key = (String) context.getInputValue("key"); Object value = context.getFacesContext().getExternalContext(). getSessionMap().get(key); context.setOutputValue("value", value); } /** *This handler sets a session attribute. It requires "key" and * "value" input values to be passed in.
* * @param context The {@link HandlerContext}. */ @Handler(id="setSessionAttribute", input={ @HandlerInput(name="key", type=String.class, required=true), @HandlerInput(name="value", required=true)}) public static void setSessionAttribute(HandlerContext context) { String key = (String) context.getInputValue("key"); Object value = context.getInputValue("value"); context.getFacesContext().getExternalContext(). getSessionMap().put(key, value); } /** *This handler produces a String consisting of all the request * attributes. It outputs this via the "value" output value.
*/ @Handler(id="dumpSessionAttributes", output={ @HandlerOutput(name="value", type=String.class) }) public static void dumpSessionAttributes(HandlerContext context) { MapThis handler gets a application attribute. It requires "key" as an * input value. It returns "value" as an output value. Note this * can also be done via #{applicationScope["attributeName"]}.
* * @param context The {@link HandlerContext}. */ @Handler(id="getApplicationAttribute", input={ @HandlerInput(name="key", type=String.class, required=true)}, output={ @HandlerOutput(name="value", type=Object.class)}) public static void getApplicationAttribute(HandlerContext context) { String key = (String) context.getInputValue("key"); Object value = context.getFacesContext().getExternalContext(). getApplicationMap().get(key); context.setOutputValue("value", value); } /** *This handler sets a application attribute. It requires "key" and * "value" input values to be passed in.
* * @param context The {@link HandlerContext}. */ @Handler(id="setApplicationAttribute", input={ @HandlerInput(name="key", type=String.class, required=true), @HandlerInput(name="value", required=true)}) public static void setApplicationAttribute(HandlerContext context) { String key = (String) context.getInputValue("key"); Object value = context.getInputValue("value"); context.getFacesContext().getExternalContext(). getApplicationMap().put(key, value); } /** *This handler produces a String consisting of all the request * attributes. It outputs this via the "value" output value.
*/ @Handler(id="dumpApplicationAttributes", output={ @HandlerOutput(name="value", type=String.class) }) public static void dumpApplicationAttributes(HandlerContext context) { Map This method formats attributes from a Map. This is
* used with the dump handlers.
This handler sets a ResourceBundle in desired request
* attribute. It requires "key" as an input value, which is the
* request attribute key used to store the bundle. "bundle" is also
* required as an input value, this is the fully qualified name of the
* bundle. Optionally the "locale" can be specified, if not the web
* user's locale will be used. It returns "bundle" as an output
* value.