001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/jsf/tags/sakai_2-4-1/widgets/src/java/org/sakaiproject/jsf/renderer/HideDivisionRenderer.java $
003: * $Id: HideDivisionRenderer.java 9278 2006-05-10 23:29:21Z ray@media.berkeley.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004 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.sakaiproject.jsf.renderer;
021:
022: import java.io.IOException;
023: import java.util.Iterator;
024: import javax.faces.component.UIComponent;
025: import javax.faces.component.UIOutput;
026: import javax.faces.component.UIViewRoot;
027: import javax.faces.context.FacesContext;
028: import javax.faces.context.ResponseWriter;
029: import javax.faces.render.Renderer;
030:
031: import org.sakaiproject.jsf.util.RendererUtil;
032: import org.sakaiproject.jsf.util.ConfigurationResource;
033:
034: /**
035: * <p>Description: </p>
036: * <p>Render a stylesheet link for the value of our component's
037: * <code>path</code> attribute, prefixed by the context path of this
038: * web application.</p>
039: * <p>Copyright: Copyright (c) 2004</p>
040: * <p>Organization: Sakai Project</p>
041: * @author Ed Smiley
042: * @version $Id: HideDivisionRenderer.java 9278 2006-05-10 23:29:21Z ray@media.berkeley.edu $
043: */
044:
045: public class HideDivisionRenderer extends Renderer {
046: // private static final String BARSTYLE = "navModeAction";
047: private static final String BARSTYLE = "";
048: private static final String BARTAG = "h4";
049: private static final String RESOURCE_PATH;
050: private static final String BARIMG;
051: private static final String CURSOR;
052:
053: static {
054: ConfigurationResource cr = new ConfigurationResource();
055: RESOURCE_PATH = "/" + cr.get("resources");
056: BARIMG = RESOURCE_PATH + "/" + cr.get("hideDivisionRight");
057: CURSOR = cr.get("picker_style");
058: }
059:
060: public boolean supportsComponentType(UIComponent component) {
061: return (component instanceof UIOutput);
062: }
063:
064: public void decode(FacesContext context, UIComponent component) {
065: }
066:
067: /**
068: * Simple passthru.
069: * @param context
070: * @param component
071: * @throws IOException
072: */
073: public void encodeChildren(FacesContext context,
074: UIComponent component) throws IOException {
075: if (!component.isRendered()) {
076: return;
077: }
078:
079: ResponseWriter writer = context.getResponseWriter();
080: Iterator children = component.getChildren().iterator();
081: while (children.hasNext()) {
082: UIComponent child = (UIComponent) children.next();
083: writer.writeText(child, null);
084: }
085:
086: }
087:
088: /**
089: * <p>Faces render output method .</p>
090: * <p>Method Generator: org.sakaiproject.tool.assessment.devtoolsRenderMaker</p>
091: *
092: * @param context <code>FacesContext</code> for the current request
093: * @param component <code>UIComponent</code> being rendered
094: *
095: * @throws IOException if an input/output error occurs
096: */
097: public void encodeBegin(FacesContext context, UIComponent component)
098: throws IOException {
099:
100: if (!component.isRendered()) {
101: return;
102: }
103:
104: ResponseWriter writer = context.getResponseWriter();
105: String jsfId = (String) RendererUtil.getAttribute(context,
106: component, "id");
107: String id = jsfId;
108:
109: if (component.getId() != null
110: && !component.getId().startsWith(
111: UIViewRoot.UNIQUE_ID_PREFIX)) {
112: id = component.getClientId(context);
113: }
114:
115: String title = (String) RendererUtil.getAttribute(context,
116: component, "title");
117:
118: writer.write("<" + BARTAG
119: + " onclick=\"javascript:showHideDiv('" + id + "', '"
120: + RESOURCE_PATH + "');\" class=\"" + BARSTYLE + "\">");
121: writer.write(" <img id=\"" + id + "__img_hide_division_"
122: + "\" alt=\"" + title + "\"");
123: writer.write(" src=\"" + BARIMG + "\" style=\"" + CURSOR
124: + "\" />");
125: writer.write(" " + title + "");
126: writer.write("</" + BARTAG + ">");
127: writer.write("<div \" style=\"display:none\" " + " id=\"" + id
128: + "__hide_division_" + "\">");
129: }
130:
131: /**
132: * <p>Render end of hidable DIV.</p>
133: *
134: * @param context FacesContext for the request we are processing
135: * @param component UIComponent to be rendered
136: *
137: * @throws IOException if an input/output error occurs while rendering
138: * @throws NullPointerException if <code>context</code>
139: * or <code>component</code> is null
140: */
141: /**
142: * <p>Faces render output method to output script tag.</p>
143: * <p>Method Generator: org.sakaiproject.tool.assessment.devtoolsRenderMaker</p>
144: *
145: * @param context <code>FacesContext</code> for the current request
146: * @param component <code>UIComponent</code> being rendered
147: *
148: * @throws IOException if an input/output error occurs
149: */
150: public void encodeEnd(FacesContext context, UIComponent component)
151: throws IOException {
152: if (!component.isRendered()) {
153: return;
154: }
155:
156: ResponseWriter writer = context.getResponseWriter();
157:
158: String jsfId = (String) RendererUtil.getAttribute(context,
159: component, "id");
160: String id = jsfId;
161:
162: if (component.getId() != null
163: && !component.getId().startsWith(
164: UIViewRoot.UNIQUE_ID_PREFIX)) {
165: id = component.getClientId(context);
166: }
167:
168: writer.write("</div>");
169:
170: writer.write("<script type=\"text/javascript\">");
171: writer.write(" showHideDiv('" + id + "', '" + RESOURCE_PATH
172: + "');");
173: writer.write("</script>");
174: }
175:
176: }
|