001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/jsf/tags/sakai_2-4-1/widgets/src/java/org/sakaiproject/jsf/renderer/PopupRenderer.java $
003: * $Id: PopupRenderer.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:
025: import javax.faces.component.UIComponent;
026: import javax.faces.component.UIOutput;
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:
033: /**
034: * <p>Description:<br />
035: * This class is the class that renders the <code>popup</code>
036: * custom tag.</p>
037: * <p>Copyright: Copyright (c) 2004</p>
038: * <p>Organization: Sakai Project</p>
039: * @author Ed Smiley
040: * @version $Id: PopupRenderer.java 9278 2006-05-10 23:29:21Z ray@media.berkeley.edu $
041: */
042:
043: public class PopupRenderer extends Renderer {
044:
045: public boolean supportsComponentType(UIComponent component) {
046: return (component instanceof UIOutput);
047: }
048:
049: public void decode(FacesContext context, UIComponent component) {
050: }
051:
052: /**
053: * This component renders its children
054: * @return true
055: */
056: public boolean getRendersChildren() {
057: return true;
058: }
059:
060: /**
061: * Do nothing if a button, otherwise, default.
062: * @param context FacesContext
063: * @param component UIComponent
064: * @throws IOException
065: */
066: public void encodeChildren(FacesContext context,
067: UIComponent component) throws IOException {
068: String buttonSwitch = (String) RendererUtil.getAttribute(
069: context, component, "useButton");
070: boolean useButton = Boolean.getBoolean(RendererUtil
071: .makeSwitchString(buttonSwitch, false, true, true,
072: false, false, false));
073:
074: if (useButton) {
075: return;
076: } else {
077: Iterator iter = component.getChildren().iterator();
078: while (iter.hasNext()) {
079: UIComponent kid = (UIComponent) iter.next();
080: RendererUtil.encodeRecursive(context, kid);
081: }
082:
083: }
084: }
085:
086: /**
087: * <p>Faces render output method .</p>
088: * <p>Method Generator: org.sakaiproject.tool.assessment.devtoolsRenderMaker</p>
089: *
090: * @param context <code>FacesContext</code> for the current request
091: * @param component <code>UIComponent</code> being rendered
092: *
093: * @throws IOException if an input/output error occurs
094: */
095: public void encodeBegin(FacesContext context, UIComponent component)
096: throws IOException {
097:
098: if (!component.isRendered()) {
099: return;
100: }
101:
102: ResponseWriter writer = context.getResponseWriter();
103: String id = (String) component.getClientId(context);
104: String title = (String) RendererUtil.getAttribute(context,
105: component, "title");
106: String url = (String) RendererUtil.getAttribute(context,
107: component, "url");
108: String target = (String) RendererUtil.getAttribute(context,
109: component, "target");
110: String toolbar = (String) RendererUtil.getAttribute(context,
111: component, "toolbar");
112: String menubar = (String) RendererUtil.getAttribute(context,
113: component, "menubar");
114: String personalbar = (String) RendererUtil.getAttribute(
115: context, component, "personalbar");
116: // temporary workaround ClassCastException
117: String width = null;//(String) RendererUtil.getAttribute(context, component, "width");
118: String height = null; //(String) RendererUtil.getAttribute(context, component, "height");
119: String scrollbars = (String) RendererUtil.getAttribute(context,
120: component, "scrollbars");
121: String resizable = (String) RendererUtil.getAttribute(context,
122: component, "resizable");
123:
124: if (title == null) {
125: title = " ";
126: }
127: if (target == null) {
128: target = "sakai_popup";
129: /** todo: put in resource*/
130: }
131: if (width == null) {
132: width = "650";
133: }
134: if (height == null) {
135: height = "375";
136: }
137: toolbar = RendererUtil.makeSwitchString(toolbar, false, true,
138: true, true, false, false);
139: menubar = RendererUtil.makeSwitchString(menubar, false, true,
140: true, true, false, false);
141: personalbar = RendererUtil.makeSwitchString(personalbar, false,
142: true, true, true, false, false);
143: scrollbars = RendererUtil.makeSwitchString(scrollbars, false,
144: true, true, true, false, false);
145: resizable = RendererUtil.makeSwitchString(resizable, false,
146: true, true, true, false, false);
147:
148: String buttonSwitch = (String) RendererUtil.getAttribute(
149: context, component, "useButton");
150: boolean useButton = Boolean.getBoolean(RendererUtil
151: .makeSwitchString(buttonSwitch, false, true, true,
152: false, false, false));
153:
154: if (useButton) {
155: writer.write("<!-- DEBUG: useButton=true -->");
156: writer.write("<input");
157: writer.write(" id=\"" + id + "\"");
158: writer.write(" type=\"button\"");
159: writer.write(" title=\"" + title + "\"");
160: writer.write(" value=\"" + title + "\"");
161: writer.write(" onclick=\"window.open('" + url + "','"
162: + target + "', 'toolbar=" + toolbar + ",menubar="
163: + menubar + ",personalbar=" + personalbar
164: + ",width=" + width + ",height=" + height
165: + ",scrollbars=" + scrollbars + ",resizable="
166: + resizable + "');\" />");
167: } else {
168:
169: writer.write("<!-- DEBUG: useButton=false -->");
170: writer.write("<a");
171: writer.write(" id=\"" + id + "\"");
172: writer.write(" title=\"" + title + "\"");
173: writer.write(" href=\"#\"");
174: writer.write(" onclick=\"window.open('" + url + "','"
175: + target + "', 'toolbar=" + toolbar + ",menubar="
176: + menubar + ",personalbar=" + personalbar
177: + ",width=" + width + ",height=" + height
178: + ",scrollbars=" + scrollbars + ",resizable="
179: + resizable + "');\" >");
180: writer.write(title);
181: }
182:
183: }
184:
185: /**
186: * <p>Render end of ANCHOR.</p>
187: *
188: * @param context FacesContext for the request we are processing
189: * @param component UIComponent to be rendered
190: *
191: * @param context <code>FacesContext</code> for the current request
192: * @param component <code>UIComponent</code> being rendered
193: *
194: * @throws IOException if an input/output error occurs
195: */
196: public void encodeEnd(FacesContext context, UIComponent component)
197: throws IOException {
198: if (!component.isRendered()) {
199: return;
200: }
201:
202: ResponseWriter writer = context.getResponseWriter();
203: String buttonSwitch = (String) RendererUtil.getAttribute(
204: context, component, "useButton");
205: boolean useButton = Boolean.getBoolean(RendererUtil
206: .makeSwitchString(buttonSwitch, false, true, true,
207: false, false, false));
208:
209: if (!useButton) {
210: writer.write("</a>");
211: }
212: }
213:
214: }
|