/**
* License Agreement.
*
* Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
*
* Copyright (C) 2007 Exadel, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.richfaces.renderkit.html;
//
// Imports
//
import java.util.Iterator;
import java.util.Collection;
import java.util.Map;
import java.io.IOException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.ComponentsVariableResolver;
import org.ajax4jsf.renderkit.ComponentVariables;
//
//
//
import org.richfaces.renderkit.TabRendererBase;
/**
* Renderer for component class org.richfaces.renderkit.html.TabRenderer
*/
public class TabRenderer extends TabRendererBase {
public TabRenderer () {
super();
}
//
// Declarations
//
//
//
//
private String convertToString(Object obj ) {
return ( obj == null ? "" : obj.toString() );
}
private String convertToString(boolean b ) {
return String.valueOf(b);
}
private String convertToString(int b ) {
return b!=Integer.MIN_VALUE?String.valueOf(b):"";
}
private String convertToString(long b ) {
return b!=Long.MIN_VALUE?String.valueOf(b):"";
}
private boolean isEmpty(Object o) {
if (null == o) {
return true;
}
if (o instanceof String ) {
return (0 == ((String)o).length());
}
if (o instanceof Collection) {
return (0 == ((Collection)o).size());
}
if (o instanceof Map) {
return (0 == ((Map)o).size());
}
if (o.getClass().isArray()) {
return (0 == ((Object [])o).length);
}
return false;
}
/**
* Get base component class, targetted for this renderer. Used for check arguments in decode/encode.
* @return
*/
protected Class getComponentClass() {
return org.richfaces.component.UITab.class;
}
public void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent component ) throws IOException {
ComponentVariables variables = ComponentsVariableResolver.getVariables(this, component);
doEncodeBegin(writer, context, (org.richfaces.component.UITab)component, variables );
}
public void doEncodeBegin(ResponseWriter writer, FacesContext context, org.richfaces.component.UITab component, ComponentVariables variables ) throws IOException {
java.lang.String clientId = component.getClientId(context);
writer.startElement("td", component);
getUtils().writeAttribute(writer, "id", clientId );
getUtils().writeAttribute(writer, "style", convertToString(getTabDisplay(context,component)) + ";height:100%" );
writer.startElement("table", component);
getUtils().writeAttribute(writer, "border", "0" );
getUtils().writeAttribute(writer, "cellpadding", "10" );
getUtils().writeAttribute(writer, "cellspacing", "0" );
getUtils().writeAttribute(writer, "class", "dr-tbpnl-cntnt-pstn rich-tabpanel-content-position" );
getUtils().writeAttribute(writer, "style", "" );
getUtils().writeAttribute(writer, "width", "100%" );
writer.startElement("tr", component);
writer.startElement("td", component);
getUtils().writeAttribute(writer, "class", "dr-tbpnl-cntnt rich-tabpanel-content " + convertToString(component.getPane().getAttributes().get("contentClass")) + " " + convertToString(component.getAttributes().get("styleClass")) );
getUtils().writeAttribute(writer, "style", convertToString(component.getAttributes().get("contentStyle")) + "; " + convertToString(component.getAttributes().get("style")) );
//
// pass thru attributes
//
getUtils().encodeAttributesFromArray(context,component,new String[] {
"abbr" ,
"align" ,
"axis" ,
"bgcolor" ,
"char" ,
"charoff" ,
"colspan" ,
"dir" ,
"headers" ,
"height" ,
"lang" ,
"nowrap" ,
"onclick" ,
"ondblclick" ,
"onkeydown" ,
"onkeypress" ,
"onkeyup" ,
"onmousedown" ,
"onmousemove" ,
"onmouseout" ,
"onmouseover" ,
"onmouseup" ,
"rowspan" ,
"scope" ,
"title" ,
"valign" ,
"width" ,
"xml:lang" });
//
//
//
}
public void doEncodeEnd(ResponseWriter writer, FacesContext context, org.richfaces.component.UITab component, ComponentVariables variables) throws IOException {
writer.endElement("td");
writer.endElement("tr");
writer.endElement("table");
writer.endElement("td");
}
public void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent component) throws IOException {
ComponentVariables variables = ComponentsVariableResolver.getVariables(this, component);
doEncodeEnd(writer, context, (org.richfaces.component.UITab)component, variables );
ComponentsVariableResolver.removeVariables(this, component);
}
}