001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License version 2
011: * as published by the Free Software Foundation.
012: *
013: * Resin Open Source is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016: * of NON-INFRINGEMENT. See the GNU General Public License for more
017: * details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with Resin Open Source; if not, write to the
021: *
022: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.jsf.html;
030:
031: import java.io.*;
032: import java.util.*;
033:
034: import javax.faces.*;
035: import javax.faces.component.*;
036: import javax.faces.component.html.*;
037: import javax.faces.context.*;
038: import javax.faces.render.*;
039:
040: /**
041: * The HTML panel/group renderer
042: */
043: class HtmlPanelGroupRenderer extends Renderer {
044: public static final Renderer RENDERER = new HtmlPanelGroupRenderer();
045:
046: /**
047: * True if the renderer is responsible for rendering the children.
048: */
049: @Override
050: public boolean getRendersChildren() {
051: return true;
052: }
053:
054: /**
055: * Renders the open tag for the text.
056: */
057: @Override
058: public void encodeBegin(FacesContext context, UIComponent component)
059: throws IOException {
060: ResponseWriter out = context.getResponseWriter();
061:
062: String layout = null;
063: String style = null;
064: String styleClass = null;
065:
066: if (component instanceof HtmlPanelGroup) {
067: HtmlPanelGroup html = (HtmlPanelGroup) component;
068:
069: layout = html.getLayout();
070: style = html.getStyle();
071: styleClass = html.getStyleClass();
072: } else {
073: Map<String, Object> attrMap = component.getAttributes();
074:
075: layout = (String) attrMap.get("layout");
076: style = (String) attrMap.get("style");
077: styleClass = (String) attrMap.get("styleClass");
078: }
079:
080: boolean isDiv = "block".equals(layout);
081:
082: if (isDiv)
083: out.startElement("div", component);
084: else
085: out.startElement("span", component);
086:
087: if (layout != null)
088: out.writeAttribute("layout", layout, "layout");
089:
090: if (style != null)
091: out.writeAttribute("style", style, "style");
092:
093: if (styleClass != null)
094: out.writeAttribute("class", styleClass, "styleClass");
095:
096: int childCount = component.getChildCount();
097: if (childCount > 0) {
098: List<UIComponent> children = component.getChildren();
099:
100: for (int i = 0; i < childCount; i++) {
101: UIComponent child = children.get(i);
102:
103: if (child.isRendered()) {
104: child.encodeBegin(context);
105: child.encodeChildren(context);
106: child.encodeEnd(context);
107: }
108: }
109: }
110:
111: if (isDiv)
112: out.endElement("div");
113: else
114: out.endElement("span");
115: }
116:
117: /**
118: * Renders the content for the component.
119: */
120: @Override
121: public void encodeChildren(FacesContext context,
122: UIComponent component) throws IOException {
123: }
124:
125: /**
126: * Renders the closing tag for the component.
127: */
128: @Override
129: public void encodeEnd(FacesContext context, UIComponent component)
130: throws IOException {
131: }
132:
133: public String toString() {
134: return "HtmlPanelGroupRenderer[]";
135: }
136: }
|