001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/jsf/widgets/src/java/org/theospi/jsf/renderer/XHeaderTitleRenderer.java $
003: * $Id: XHeaderTitleRenderer.java 15703 2006-10-05 18:16:51Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.jsf.renderer;
021:
022: import java.io.IOException;
023:
024: import javax.faces.component.UIComponent;
025: import javax.faces.component.UIOutput;
026: import javax.faces.context.FacesContext;
027: import javax.faces.context.ResponseWriter;
028: import javax.faces.render.Renderer;
029: import javax.servlet.http.HttpServletRequest;
030:
031: import org.sakaiproject.jsf.util.RendererUtil;
032: import org.theospi.jsf.component.XHeaderComponent;
033: import org.theospi.jsf.component.XHeaderDrawerComponent;
034: import org.theospi.jsf.component.XHeaderTitleComponent;
035: import org.theospi.jsf.util.ConfigurationResource;
036: import org.theospi.jsf.util.OspxTagHelper;
037:
038: public class XHeaderTitleRenderer extends Renderer {
039: private static final String RESOURCE_PATH;
040: private static final String BARIMG_RIGHT;
041: private static final String BARIMG_DOWN;
042: private static final String CURSOR;
043: private static final String JS_LOC;
044: private static final String CSS_LOC;
045:
046: static {
047: ConfigurationResource cr = new ConfigurationResource();
048: RESOURCE_PATH = "/" + cr.get("resources");
049: BARIMG_RIGHT = RESOURCE_PATH + "/" + cr.get("xheaderRight");
050: BARIMG_DOWN = RESOURCE_PATH + "/" + cr.get("xheaderDown");
051: CURSOR = cr.get("picker_style");
052: JS_LOC = RESOURCE_PATH + "/" + cr.get("xheaderScript");
053: CSS_LOC = RESOURCE_PATH + "/" + cr.get("cssFile");
054: }
055:
056: public boolean supportsComponentType(UIComponent component) {
057: return (component instanceof UIOutput);
058: }
059:
060: public void encodeBegin(FacesContext context,
061: UIComponent inComponent) throws IOException {
062: if (!(inComponent instanceof XHeaderTitleComponent))
063: throw new IOException(
064: "the xheadertitle was expecting an xheadertitlecomponent");
065:
066: ResponseWriter writer = context.getResponseWriter();
067: HttpServletRequest request = (HttpServletRequest) context
068: .getExternalContext().getRequest();
069:
070: RendererUtil.writeExternalCSSDependencies(context, writer,
071: "osp.jsf.css", CSS_LOC);
072: RendererUtil.writeExternalJSDependencies(context, writer,
073: "osp.jsf.xheader.js", JS_LOC);
074:
075: XHeaderTitleComponent component = (XHeaderTitleComponent) inComponent;
076:
077: String id = (String) RendererUtil.getAttribute(context,
078: component, "id");
079: String cssclass = (String) RendererUtil.getAttribute(context,
080: component, "cssclass");
081: String value = (String) RendererUtil.getAttribute(context,
082: component, "value");
083:
084: if (cssclass == null)
085: cssclass = "xheader";
086:
087: writer.write("<div");
088:
089: RendererUtil.writeAttr(writer, "class", cssclass);
090: RendererUtil.writeAttr(writer, "id", id);
091:
092: writer.write(">");
093:
094: XHeaderComponent parent = (XHeaderComponent) component
095: .getParent();
096: //if(component.getDrawerComponent() != null) {
097: XHeaderDrawerComponent drawer = parent.getDrawerComponent();
098: if (drawer != null) {
099: String divId = "div" + drawer.getClientId(context);
100: drawer.setDivId(divId);
101: writer.write("<span onclick=\"showHideDiv('" + divId
102: + "', '" + RESOURCE_PATH + "');"
103: + request.getAttribute("sakai.html.body.onload")
104: + " refreshChildren"
105: + Math.abs(drawer.getDivId().hashCode()) + "(); "
106: + "\">");
107:
108: writer.startElement("img", component);
109: writer
110: .writeAttribute(
111: "style",
112: "position:relative; float:left; margin-right:10px; left:3px; top:2px;",
113: "style");
114: writer.writeAttribute("id", "img" + divId, "id");
115: String initiallyexpandedStr = (String) RendererUtil
116: .getAttribute(context, drawer, "initiallyexpanded");
117: if (initiallyexpandedStr == null)
118: initiallyexpandedStr = "false";
119: if (OspxTagHelper.parseBoolean(initiallyexpandedStr))
120: writer.writeAttribute("src", BARIMG_RIGHT, "src");
121: else
122: writer.writeAttribute("src", BARIMG_DOWN, "src");
123: writer.endElement("img");
124:
125: if (value != null) {
126: writer.write(value);
127: }
128:
129: writer.write("</span>");
130: }
131: }
132:
133: /**
134: * @param context FacesContext for the request we are processing
135: * @param component UIComponent to be rendered
136: * @exception IOException if an input/output error occurs while rendering
137: * @exception NullPointerException if <code>context</code> or <code>component</code> is null
138: */
139: public void encodeEnd(FacesContext context, UIComponent component)
140: throws IOException {
141: ResponseWriter writer = context.getResponseWriter();
142: writer.write("</div>");
143: }
144:
145: /**
146: * This component renders its children
147: * @return true
148: */
149: public boolean getRendersChildren() {
150: return false;
151: }
152: }
|