01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/syllabus/tags/sakai_2-4-1/syllabus-app/src/java/org/sakaiproject/jsf/syllabus/SyllabusIframeRender.java $
03: * $Id: SyllabusIframeRender.java 8802 2006-05-03 15:06:26Z cwen@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.jsf.syllabus;
21:
22: import java.io.IOException;
23:
24: import javax.faces.component.UIComponent;
25: import javax.faces.context.FacesContext;
26: import javax.faces.context.ResponseWriter;
27: import javax.faces.render.Renderer;
28:
29: public class SyllabusIframeRender extends Renderer {
30: public boolean supportsComponentType(UIComponent component) {
31: return (component instanceof org.sakaiproject.jsf.syllabus.SyllabusIframeComponent);
32: }
33:
34: public void encodeBegin(FacesContext context, UIComponent component)
35: throws IOException {
36: ResponseWriter writer = context.getResponseWriter();
37:
38: String widthIn = (String) component.getAttributes()
39: .get("width");
40: String heightIn = (String) component.getAttributes().get(
41: "height");
42: String redirectUrl = (String) component.getAttributes().get(
43: "redirectUrl");
44:
45: if (widthIn == null) {
46: widthIn = new Integer(450).toString();
47: }
48:
49: if (heightIn == null) {
50: heightIn = new Integer(80).toString();
51: }
52:
53: if ((redirectUrl != null) && (!redirectUrl.equals(""))) {
54: /* if(!redirectUrl.startsWith("http://"))
55: {
56: if((!redirectUrl.toLowerCase().endsWith(".doc")) && (!redirectUrl.toLowerCase().endsWith(".pdf"))
57: && (!redirectUrl.toLowerCase().startsWith("https://")))
58: {
59: redirectUrl = "http://" + redirectUrl;
60: }
61: }*/
62: if (redirectUrl.toLowerCase().startsWith("www.")) {
63: redirectUrl = "http://" + redirectUrl;
64: }
65: if (!redirectUrl.toLowerCase().startsWith("http://")
66: && !redirectUrl.toLowerCase()
67: .startsWith("https://")) {
68: redirectUrl = "http://" + redirectUrl;
69: }
70: writer.write("<iframe src=\"" + redirectUrl + "\"");
71: writer.write(" width=\"" + widthIn + "\"");
72: writer.write(" height=\"" + heightIn + "\"");
73: writer.write(" style=\"margin-top:1em;clear:both\"");
74: writer.write(" frameborder=\"0\"");
75: writer.write(" scrolling=\"auto\"");
76: writer.write("></iframe>");
77: }
78: }
79: }
|