001: /**********************************************************************************
002: *
003: * Header:
004: *
005: ***********************************************************************************
006: *
007: * Copyright (c) 2003, 2004 The Sakai Foundation.
008: *
009: * Licensed under the Educational Community License, Version 1.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.opensource.org/licenses/ecl1.php
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: *
021: **********************************************************************************/package org.sakaiproject.jsf.renderer;
022:
023: import java.io.IOException;
024: import java.util.Iterator;
025: import java.util.List;
026:
027: import javax.faces.component.UIComponent;
028: import javax.faces.component.UIViewRoot;
029: import javax.faces.context.FacesContext;
030: import javax.faces.context.ResponseWriter;
031: import javax.faces.render.Renderer;
032:
033: import org.sakaiproject.jsf.util.RendererUtil;
034:
035: /**
036: * <p>This does not render children, but can deal with children by surrounding them in a comment.</p>
037: *
038: */
039: public class ToolBarRenderer extends Renderer {
040: /**
041: * This component renders its children
042: * @return true
043: */
044: public boolean getRendersChildren() {
045: return true;
046: }
047:
048: public boolean supportsComponentType(UIComponent component) {
049: return (component instanceof org.sakaiproject.jsf.component.ToolBarComponent);
050: }
051:
052: public void encodeBegin(FacesContext context, UIComponent component)
053: throws IOException {
054: if (!component.isRendered()) {
055: //tool_bar tag is not to be rendered, return now
056: return;
057: }
058: ResponseWriter writer = context.getResponseWriter();
059: writer.write("<div class=\"navIntraTool\">");
060:
061: return;
062: }
063:
064: /**
065: * We put all our processing in the encodeChildren method
066: * @param context
067: * @param component
068: * @throws IOException
069: */
070: public void encodeChildren(FacesContext context,
071: UIComponent component) throws IOException {
072: if (!component.isRendered()) {
073: return;
074: }
075:
076: String clientId = null;
077:
078: if (component.getId() != null
079: && !component.getId().startsWith(
080: UIViewRoot.UNIQUE_ID_PREFIX)) {
081: clientId = component.getClientId(context);
082: }
083:
084: ResponseWriter writer = context.getResponseWriter();
085:
086: if (clientId != null) {
087: writer.startElement("div", component);
088: }
089:
090: List children = component.getChildren();
091:
092: // this is a special separator attribute, not supported by UIData
093: String separator = (String) RendererUtil.getAttribute(context,
094: component, "separator");
095: if (separator == null)
096: separator = "";
097:
098: boolean first = true;
099: for (Iterator iter = children.iterator(); iter.hasNext();) {
100: UIComponent child = (UIComponent) iter.next();
101:
102: if (child.isRendered()) {
103: if (!first && separator != null && separator != "")
104: writer.write("<span class=\"separator\">"
105: + separator + "</span>");
106:
107: RendererUtil.encodeRecursive(context, child);
108: first = false;
109: }
110: }
111: if (clientId != null) {
112: writer.endElement("div");
113: }
114:
115: }
116:
117: public void encodeEnd(FacesContext context, UIComponent component)
118: throws IOException {
119: ResponseWriter writer = context.getResponseWriter();
120: writer.write("</div>");
121: }
122: }
|