1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.portlet; |
18 |
|
|
19 |
|
import java.io.IOException; |
20 |
|
import java.util.HashMap; |
21 |
|
import java.util.Map; |
22 |
|
|
23 |
|
import javax.portlet.ActionRequest; |
24 |
|
import javax.portlet.ActionResponse; |
25 |
|
import javax.portlet.PortletConfig; |
26 |
|
import javax.portlet.PortletException; |
27 |
|
import javax.portlet.PortletPreferences; |
28 |
|
import javax.portlet.RenderRequest; |
29 |
|
import javax.portlet.RenderResponse; |
30 |
|
import javax.portlet.WindowState; |
31 |
|
|
32 |
|
import org.apache.portals.bridges.velocity.GenericVelocityPortlet; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
0 |
public class IFrameGenericPortlet extends GenericVelocityPortlet |
41 |
|
{ |
42 |
|
|
43 |
0 |
private Map attributes = new HashMap(); |
44 |
|
|
45 |
0 |
private Map maxAttributes = new HashMap(); |
46 |
|
|
47 |
|
public void init(PortletConfig config) throws PortletException |
48 |
|
{ |
49 |
0 |
super.init(config); |
50 |
0 |
attributes.put("SRC", "http://www.apache.org"); |
51 |
0 |
attributes.put("ALIGN", "BOTTOM"); |
52 |
0 |
attributes.put("CLASS", ""); |
53 |
0 |
attributes.put("FRAMEBORDER", "0"); |
54 |
0 |
attributes.put("ID", ""); |
55 |
0 |
attributes.put("MARGINHEIGHT", "0"); |
56 |
0 |
attributes.put("MARGINWIDTH", "0"); |
57 |
0 |
attributes.put("NAME", ""); |
58 |
|
|
59 |
0 |
attributes.put("HEIGHT", ""); |
60 |
0 |
attributes.put("WIDTH", "100%"); |
61 |
0 |
attributes.put("SCROLLING", "NO"); |
62 |
0 |
attributes.put("STYLE", ""); |
63 |
|
|
64 |
0 |
maxAttributes.put("HEIGHT", "800"); |
65 |
0 |
maxAttributes.put("WIDTH", "100%"); |
66 |
0 |
maxAttributes.put("SCROLLING", "AUTO"); |
67 |
0 |
maxAttributes.put("STYLE", ""); |
68 |
0 |
} |
69 |
|
|
70 |
|
private String getAttributePreference(PortletPreferences prefs, String attribute) |
71 |
|
{ |
72 |
0 |
return this.getMappedAttributePreference(prefs, attribute, attributes); |
73 |
|
} |
74 |
|
|
75 |
|
private String getMaxAttributePreference(PortletPreferences prefs, String attribute) |
76 |
|
{ |
77 |
0 |
return this.getMappedAttributePreference(prefs, "MAX-" + attribute, maxAttributes); |
78 |
|
} |
79 |
|
|
80 |
|
private String getMappedAttributePreference(PortletPreferences prefs, String attribute, Map map) |
81 |
|
{ |
82 |
0 |
return prefs.getValue(attribute, (String) map.get(attribute)); |
83 |
|
} |
84 |
|
|
85 |
|
private void appendAttribute(PortletPreferences prefs, StringBuffer content, String attribute, Map map) |
86 |
|
{ |
87 |
|
String value; |
88 |
|
|
89 |
0 |
if (map == maxAttributes) |
90 |
0 |
value = getMaxAttributePreference(prefs, attribute); |
91 |
|
else |
92 |
0 |
value = getAttributePreference(prefs, attribute); |
93 |
|
|
94 |
0 |
if (value == null || value.length() == 0) { return; } |
95 |
0 |
content.append(" ").append(attribute).append("=\"").append(value).append("\""); |
96 |
0 |
} |
97 |
|
|
98 |
|
private void appendAttribute(PortletPreferences prefs, StringBuffer content, String attribute) |
99 |
|
{ |
100 |
0 |
appendAttribute(prefs, content, attribute, attributes); |
101 |
0 |
} |
102 |
|
|
103 |
|
private void appendMaxAttribute(PortletPreferences prefs, StringBuffer content, String attribute) |
104 |
|
{ |
105 |
0 |
appendAttribute(prefs, content, attribute, maxAttributes); |
106 |
0 |
} |
107 |
|
|
108 |
|
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException |
109 |
|
{ |
110 |
0 |
String viewPage = (String)request.getAttribute(PARAM_VIEW_PAGE); |
111 |
0 |
if (viewPage != null) |
112 |
|
{ |
113 |
0 |
super.doView(request, response); |
114 |
|
} |
115 |
|
else |
116 |
|
{ |
117 |
0 |
doIFrame(request, response); |
118 |
|
} |
119 |
0 |
} |
120 |
|
|
121 |
|
public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException |
122 |
|
{ |
123 |
0 |
response.setContentType("text/html"); |
124 |
0 |
doPreferencesEdit(request, response); |
125 |
0 |
} |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
protected void doIFrame(RenderRequest request, RenderResponse response) throws IOException |
131 |
|
{ |
132 |
0 |
PortletPreferences prefs = request.getPreferences(); |
133 |
0 |
String source = getURLSource(request, response, prefs); |
134 |
|
|
135 |
0 |
StringBuffer content = new StringBuffer(4096); |
136 |
|
|
137 |
|
|
138 |
0 |
content.append("<TABLE CLASS='iframePortletTableContainer' WIDTH='100%'><TBODY CLASS='iframePortletTbodyContainer'><TR><TD>"); |
139 |
|
|
140 |
0 |
content.append("<IFRAME"); |
141 |
|
|
142 |
|
|
143 |
0 |
content.append(" ").append("SRC").append("=\"").append(source).append("\""); |
144 |
|
|
145 |
0 |
appendAttribute(prefs, content, "ALIGN"); |
146 |
0 |
appendAttribute(prefs, content, "CLASS"); |
147 |
0 |
appendAttribute(prefs, content, "FRAMEBORDER"); |
148 |
0 |
appendAttribute(prefs, content, "ID"); |
149 |
0 |
appendAttribute(prefs, content, "MARGINHEIGHT"); |
150 |
0 |
appendAttribute(prefs, content, "MARGINWIDTH"); |
151 |
0 |
appendAttribute(prefs, content, "NAME"); |
152 |
0 |
if (request.getWindowState().equals(WindowState.MAXIMIZED)) |
153 |
|
{ |
154 |
0 |
appendMaxAttribute(prefs, content, "HEIGHT"); |
155 |
0 |
appendMaxAttribute(prefs, content, "WIDTH"); |
156 |
0 |
appendMaxAttribute(prefs, content, "SCROLLING"); |
157 |
0 |
appendMaxAttribute(prefs, content, "STYLE"); |
158 |
|
} |
159 |
|
else |
160 |
|
{ |
161 |
0 |
appendAttribute(prefs, content, "HEIGHT"); |
162 |
0 |
appendAttribute(prefs, content, "WIDTH"); |
163 |
0 |
appendAttribute(prefs, content, "SCROLLING"); |
164 |
0 |
appendAttribute(prefs, content, "STYLE"); |
165 |
|
} |
166 |
0 |
content.append(">"); |
167 |
0 |
content.append("<P STYLE=\"textAlign:center\"><A HREF=\"").append(source).append("\">").append(source).append( |
168 |
|
"</A></P>"); |
169 |
0 |
content.append("</IFRAME>"); |
170 |
|
|
171 |
|
|
172 |
0 |
content.append("</TD></TR></TBODY></TABLE>"); |
173 |
|
|
174 |
|
|
175 |
0 |
response.setContentType("text/html"); |
176 |
0 |
response.getWriter().print(content.toString()); |
177 |
0 |
} |
178 |
|
|
179 |
|
public String getURLSource(RenderRequest request, RenderResponse response, PortletPreferences prefs) |
180 |
|
{ |
181 |
0 |
String source = getAttributePreference(prefs, "SRC"); |
182 |
0 |
if (source == null) source = ""; |
183 |
0 |
return source; |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
public void processAction(ActionRequest request, ActionResponse actionResponse) throws PortletException, |
190 |
|
IOException |
191 |
|
{ |
192 |
0 |
processPreferencesAction(request, actionResponse); |
193 |
0 |
} |
194 |
|
|
195 |
|
} |