01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.jsp.tag.basic;
16:
17: import java.io.Writer;
18: import java.util.Iterator;
19: import java.util.Map;
20: import org.araneaframework.http.PopupServiceInfo;
21: import org.araneaframework.http.PopupWindowContext;
22: import org.araneaframework.jsp.tag.BaseTag;
23: import org.araneaframework.jsp.util.JspUtil;
24:
25: /**
26: * Popup registering and rendering tag -- opens popups when HTML file BODY has onload event processing enabled.
27: * @author Taimo Peelo (taimo@araneaframework.org)
28: *
29: * @jsp.tag
30: * name = "registerPopups"
31: * body-content = "empty"
32: * description = "Registers popups present in current popupcontext for opening."
33: */
34: public class PopupRegistrationHtmlTag extends BaseTag {
35:
36: protected int doEndTag(Writer out) throws Exception {
37: PopupWindowContext popupWindowContext = (PopupWindowContext) getEnvironment()
38: .requireEntry(PopupWindowContext.class);
39: Map popups = popupWindowContext.getPopups();
40:
41: if (popups != null && !popups.isEmpty()) {
42: JspUtil.writeOpenStartTag(out, "script");
43: JspUtil.writeAttribute(out, "type", "text/javascript");
44: JspUtil.writeCloseStartTag(out);
45: out
46: .write("_ap.addSystemLoadEvent(Aranea.Popups.processPopups);\n");
47:
48: addPopups(out, popups);
49: JspUtil.writeEndTag(out, "script");
50: }
51:
52: return super .doEndTag(out);
53: }
54:
55: protected void addPopups(Writer out, Map popups) throws Exception {
56: for (Iterator i = popups.entrySet().iterator(); i.hasNext();) {
57: addPopup(out, (Map.Entry) i.next());
58: }
59: }
60:
61: protected void addPopup(Writer out, Map.Entry popup)
62: throws Exception {
63: String serviceId = (String) popup.getKey();
64: PopupServiceInfo serviceInfo = (PopupServiceInfo) popup
65: .getValue();
66:
67: out.write("Aranea.Popups.addPopup('" + serviceId + "'");
68: out.write(", '");
69: out
70: .write(serviceInfo.getPopupProperties() != null ? serviceInfo
71: .getPopupProperties().toString()
72: : "");
73: out.write("', '");
74: out.write(serviceInfo.toURL());
75: out.write("');");
76: }
77: }
|