001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/trunk/jsf/widgets/src/java/org/theospi/jsf/renderer/ScrollableAreaRenderer.java $
003: * $Id: ScrollableAreaRenderer.java 10835 2006-06-17 03:25:03Z lance@indiana.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.portfolio.help.jsf.renderer;
021:
022: import java.io.IOException;
023: import java.io.StringWriter;
024: import java.io.StringReader;
025: import java.util.Set;
026: import java.util.Map;
027:
028: import javax.faces.component.UIComponent;
029: import javax.faces.component.UIOutput;
030: import javax.faces.context.FacesContext;
031: import javax.faces.context.ResponseWriter;
032: import javax.faces.render.Renderer;
033:
034: import org.sakaiproject.jsf.util.RendererUtil;
035: import org.theospi.portfolio.help.helper.HelpTagHelper;
036: import org.theospi.portfolio.help.model.GlossaryEntry;
037:
038: /**
039: *
040: * @author andersjb
041: *
042: */
043: public class GlossaryRenderer extends Renderer {
044: ResponseWriter originalWriter = null;
045: StringWriter tempWriter = null;
046: private static final String TERM_TAG = "org.theospi.portfolio.help.jsf.renderer.GlossaryRenderer.terms";
047:
048: public boolean supportsComponentType(UIComponent component) {
049: return (component instanceof UIOutput);
050: }
051:
052: /**
053: * This renders html for the beginning of the tag.
054: *
055: * @param context
056: * @param component
057: * @throws IOException
058: */
059: public void encodeBegin(FacesContext context, UIComponent component)
060: throws IOException {
061: ResponseWriter writer = context.getResponseWriter();
062:
063: writer
064: .write("<script type=\"text/javascript\" src=\"/osp-common-tool/js/eport.js\"></script>");
065: originalWriter = writer;
066:
067: tempWriter = new StringWriter();
068: ResponseWriter newResponseWriter = writer
069: .cloneWithWriter(tempWriter);
070: context.setResponseWriter(newResponseWriter);
071: }
072:
073: /**
074: * @param context FacesContext for the request we are processing
075: * @param component UIComponent to be rendered
076: * @exception IOException if an input/output error occurs while rendering
077: * @exception NullPointerException if <code>context</code> or <code>component</code> is null
078: */
079: public void encodeEnd(FacesContext context, UIComponent component)
080: throws IOException {
081: String hoverStr = (String) RendererUtil.getAttribute(context,
082: component, "hover");
083: String linkStr = (String) RendererUtil.getAttribute(context,
084: component, "link");
085: String firstOnlyStr = (String) RendererUtil.getAttribute(
086: context, component, "firstOnly");
087:
088: if (hoverStr == null)
089: hoverStr = "";
090: if (linkStr == null)
091: linkStr = "";
092: if (firstOnlyStr == null)
093: firstOnlyStr = "";
094:
095: //Get the temp writer
096: ResponseWriter writer = context.getResponseWriter();
097:
098: //place the original writer back
099: context.setResponseWriter(originalWriter);
100:
101: //ensure everything is passed out to the string writer
102: writer.flush();
103:
104: //read the result
105: String content = tempWriter.toString();
106: StringReader strReader = new StringReader(content);
107:
108: Set termSet = getTerms(context.getExternalContext()
109: .getRequestMap());
110: GlossaryEntry[] terms = new GlossaryEntry[termSet.size()];
111: terms = (GlossaryEntry[]) termSet.toArray(terms);
112:
113: HelpTagHelper.renderHelp(strReader, content.length(),
114: originalWriter, terms, firstOnlyStr.equals("true"),
115: hoverStr.equals("true"), linkStr.equals("true"));
116:
117: //originalWriter.writeText("--" + tempWriter.toString()+"--", null);
118: }
119:
120: protected Set getTerms(Map requestMap) {
121: if (requestMap.containsKey(TERM_TAG)) {
122: return (Set) requestMap.get(TERM_TAG);
123: }
124: Set returned = HelpTagHelper.getHelpManager()
125: .getSortedWorksiteTerms();
126: requestMap.put(TERM_TAG, returned);
127: return returned;
128: }
129: }
|