Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.
*/
/*
* UtilHandlers.java
*
* Created on December 2, 2004, 3:06 AM
*/
package com.sun.jsftemplating.handlers;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
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.LayoutViewHandler;
import com.sun.jsftemplating.layout.descriptors.LayoutElement;
import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;
import com.sun.jsftemplating.util.Util;
/**
*
This class contains
* {@link com.sun.jsftemplating.layout.descriptors.handler.Handler}
* methods that perform common utility-type functions.
*
* @author Ken Paulsen ([email protected])
*/
public class UtilHandlers {
/**
*
Default Constructor.
*/
public UtilHandlers() {
}
/**
*
This handler uses the special "condition" attribute to determine if
* it should execute (and therefor any of its child handlers. So the
* implementation itself does nothing.
*/
@Handler(id="if",
input={@HandlerInput(name="condition", type=String.class)})
public static void ifHandler(HandlerContext context) {
// Do nothing, the purpose of this handler is to provide condition
// support which is handled by the parser / runtime.
}
/**
*
A utility handler that resembles the for() method in Java. Handlers
* inside the for loop will be executed in a loop. The starting index
* is specified by start. The index will increase
* sequentially untill it is equal to end.
* var will be a request attribute that is set to the
* current index value as the loop iterates.
The handlers inside the {...} will be executed 2 times
* (with foo=1 and foo=2).
*
*
start -- type: Integer Starting
* index, defaults to zero if not specified.
*
end -- type: Integer; Ending index.
* Required.
*
var -- type: String; Request
* attribute to be set in the for loop to the value of the
* index.
*
* @param handlerCtx The {@link HandlerContext}.
*/
@Handler(id="for",
input={
@HandlerInput(name="start", type=Integer.class),
@HandlerInput(name="end", type=Integer.class, required=true),
@HandlerInput(name="var", type=String.class, required=true)})
public static boolean forLoop(HandlerContext handlerCtx) {
Integer startInt = (Integer) handlerCtx.getInputValue("start");
int start = (startInt == null) ? 0 : startInt;
int end = (Integer) handlerCtx.getInputValue("end");
String var = (String) handlerCtx.getInputValue("var");
List handlers =
handlerCtx.getHandler().getChildHandlers();
if (handlers.size() > 0) {
// We have child handlers in the loop... execute while we iterate
LayoutElement elt = handlerCtx.getLayoutElement();
Map requestMap = handlerCtx.getFacesContext().
getExternalContext().getRequestMap();
for (int idx=start; idx < end; idx++) {
requestMap.put(var, idx);
// Ignore whats returned by the handler... we need to return
// false anyway to prevent children from being executed again
elt.dispatchHandlers(handlerCtx, handlers);
}
}
// This will prevent the child handlers from executing again
return false;
}
/**
*
This handler writes using System.out.println. It
* requires that value be supplied as a String input
* parameter.
*
* @param context The HandlerContext.
*/
@Handler(id="println",
input={@HandlerInput(name="value", type=String.class, required=true)})
public static void println(HandlerContext context) {
String value = (String) context.getInputValue("value");
System.out.println(value);
}
/**
*
This handler writes using
* FacesContext.getResponseWriter().
*
* @param context The HandlerContext.
*/
@Handler(id="write",
input={@HandlerInput(name="value", type=String.class, required=true)})
public static void write(HandlerContext context) {
String text = (String) context.getInputValue("value");
if (text == null) {
// Even though this is required, an expression can evaluate to null
text = "";
}
try {
context.getFacesContext().getResponseWriter().write(text);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
/**
*
This handler decrements a number by 1. This handler requires
* "number" to be supplied as an Integer input value. It sets an
* output value "value" to number-1.
*
* @param context The HandlerContext.
*/
@Handler(id="dec",
input={
@HandlerInput(name="number", type=Integer.class, required=true)},
output={
@HandlerOutput(name="value", type=Integer.class)})
public static void dec(HandlerContext context) {
Integer value = (Integer) context.getInputValue("number");
context.setOutputValue("value", new Integer(value.intValue() - 1));
}
/**
*
This handler increments a number by 1. This handler requires
* "number" to be supplied as an Integer input value. It sets an
* output value "value" to number+1.
*
* @param context The HandlerContext.
*/
@Handler(id="inc",
input={
@HandlerInput(name="number", type=Integer.class, required=true)},
output={
@HandlerOutput(name="value", type=Integer.class)})
public static void inc(HandlerContext context) {
Integer value = (Integer) context.getInputValue("number");
context.setOutputValue("value", new Integer(value.intValue() + 1));
}
/**
*
This method returns an Iterator for the given
* List. The List input value key is:
* "list". The output value key for the Iterator is:
* "iterator".
*
* @param context The HandlerContext.
*/
@Handler(id="getIterator",
input={
@HandlerInput(name="list", type=List.class, required=true)},
output={
@HandlerOutput(name="iterator", type=Iterator.class)})
public static void getIterator(HandlerContext context) {
List