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