001: /*
002: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
003: *
004: * This file is part of TransferCM.
005: *
006: * TransferCM is free software; you can redistribute it and/or modify it under the
007: * terms of the GNU General Public License as published by the Free Software
008: * Foundation; either version 2 of the License, or (at your option) any later
009: * version.
010: *
011: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
014: * details.
015: *
016: * You should have received a copy of the GNU General Public License along with
017: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018: * Fifth Floor, Boston, MA 02110-1301 USA
019: */
020:
021: package com.methodhead.shim;
022:
023: import javax.servlet.jsp.JspException;
024: import javax.servlet.jsp.tagext.TagSupport;
025: import java.util.Map;
026: import java.io.IOException;
027: import java.util.HashMap;
028: import javax.servlet.http.HttpServletRequest;
029: import javax.servlet.http.HttpServletResponse;
030: import org.apache.struts.util.MessageResources;
031: import org.apache.struts.Globals;
032: import com.methodhead.menu.MenuRenderer;
033: import com.methodhead.util.ServletUtils;
034: import com.methodhead.tree.FoldingTreeNode;
035: import com.methodhead.sitecontext.SiteContextFilter;
036:
037: public class BodyTag extends TagSupport {
038:
039: // constructors /////////////////////////////////////////////////////////////
040:
041: // constants ////////////////////////////////////////////////////////////////
042:
043: // classes //////////////////////////////////////////////////////////////////
044:
045: // methods //////////////////////////////////////////////////////////////////
046:
047: public int doStartTag() throws JspException {
048:
049: String mode = (String) pageContext.getRequest().getAttribute(
050: ShimGlobals.MODE_KEY);
051:
052: HttpServletRequest request = (HttpServletRequest) pageContext
053: .getRequest();
054:
055: String editPanel = (String) request
056: .getAttribute(ShimGlobals.EDITPANEL_KEY);
057:
058: try {
059: String onload = "";
060: String onbeforeunload = "";
061:
062: //
063: // get attributes html
064: //
065: StringBuffer atts = new StringBuffer();
066:
067: if (!"".equals(id_))
068: atts.append(" id=\"" + id_ + "\"");
069: if (!"".equals(styleClass_))
070: atts.append(" class=\"" + styleClass_ + "\"");
071: if (!"".equals(lang_))
072: atts.append(" lang=\"" + lang_ + "\"");
073: if (!"".equals(dir_))
074: atts.append(" dir=\"" + dir_ + "\"");
075: if (!"".equals(title_))
076: atts.append(" title=\"" + title_ + "\"");
077: if (!"".equals(style_))
078: atts.append(" style=\"" + style_ + "\"");
079: if (!"".equals(bgcolor_))
080: atts.append(" bgcolor=\"" + bgcolor_ + "\"");
081: if (!"".equals(onunload_))
082: atts.append(" onunload=\"" + onunload_ + "\"");
083: if (!"".equals(onclick_))
084: atts.append(" onclick=\"" + onclick_ + "\"");
085: if (!"".equals(onmousedown_))
086: atts.append(" onmousedown=\"" + onmousedown_ + "\"");
087: if (!"".equals(onmouseup_))
088: atts.append(" onmouseup=\"" + onmouseup_ + "\"");
089: if (!"".equals(onmouseover_))
090: atts.append(" onmouseover=\"" + onmouseover_ + "\"");
091: if (!"".equals(onmousemove_))
092: atts.append(" onmousemove=\"" + onmousemove_ + "\"");
093: if (!"".equals(onmouseout_))
094: atts.append(" onmouseout=\"" + onmouseout_ + "\"");
095: if (!"".equals(onkeypress_))
096: atts.append(" onkeypress=\"" + onkeypress_ + "\"");
097: if (!"".equals(onkeydown_))
098: atts.append(" onkeydown=\"" + onkeydown_ + "\"");
099: if (!"".equals(onkeyup_))
100: atts.append(" onkeyup=\"" + onkeyup_ + "\"");
101:
102: //
103: // update onload and onbeforeunload if we're in the editor
104: //
105: if (ShimGlobals.MODE_RICHEDIT.equals(mode)) {
106:
107: //
108: // onload
109: //
110: onload = " onload=\"";
111:
112: if (onload_.length() > 0)
113: onload += onload_ + ",";
114:
115: onload += "window.parent.init()" + "\"";
116:
117: //
118: // onbeforeunload
119: //
120: onbeforeunload = " onbeforeunload="
121: + "\"return window.parent.toolbarFrame.onBeforeUnload()\"";
122: } else {
123: if (onload_.length() > 0) {
124: onload = " onload=\"" + onload_ + "\"";
125: }
126:
127: if (onbeforeunload_.length() > 0) {
128: onbeforeunload = " onbeforeunload=\""
129: + onbeforeunload_ + "\"";
130: }
131: }
132:
133: pageContext.getOut().println(
134: "<body" + onload + onbeforeunload + atts + ">");
135:
136: //
137: // edit mode but not rich text editing?
138: //
139: mode = (String) pageContext.getSession().getAttribute(
140: ShimGlobals.MODE_KEY);
141:
142: if (ShimGlobals.MODE_EDIT.equals(mode)
143: && (editPanel == null)
144: && ShimUtils
145: .displayEditElements((HttpServletRequest) pageContext
146: .getRequest())) {
147:
148: MenuRenderer renderer = new MenuRenderer();
149:
150: //
151: // get the menu
152: //
153: pageContext.getOut().println(
154: "<script type=\"text/javascript\" " + "src=\""
155: + SiteContextFilter.APPROOT
156: + "/js/menu-config.js\"></script>\n");
157:
158: //
159: // render the menu (menu will be null when including templates for
160: // panel defs)
161: //
162: FoldingTreeNode menu = (FoldingTreeNode) request
163: .getAttribute(ShimGlobals.MENU_KEY);
164:
165: if (menu != null) {
166: pageContext.getOut().println(
167: "<script type=\"text/javascript\">");
168:
169: pageContext.getOut().println(
170: renderer.renderMenu(menu));
171:
172: pageContext.getOut().println("</script>");
173:
174: pageContext.getOut().println(
175: "<script type=\"text/javascript\" "
176: + "src=\""
177: + SiteContextFilter.APPROOT
178: + "/js/menu_com.js\"></script>");
179: }
180: }
181: } catch (IOException e) {
182: throw new JspException(
183: "Unexpected IOException when writing body tag: "
184: + e.toString());
185: }
186:
187: return EVAL_BODY_INCLUDE;
188: }
189:
190: public int doEndTag() throws JspException {
191:
192: try {
193: pageContext.getOut().println("</body>");
194: } catch (IOException e) {
195: throw new JspException(
196: "Unexpected IOException when writing body end tag: "
197: + e.toString());
198: }
199:
200: return EVAL_PAGE;
201: }
202:
203: // properties ///////////////////////////////////////////////////////////////
204:
205: public String getOnload() {
206: return onload_;
207: }
208:
209: public void setOnload(String onload) {
210: onload_ = onload;
211: }
212:
213: public String getOnbeforeunload() {
214: return onbeforeunload_;
215: }
216:
217: public void setOnbeforeunload(String onbeforeunload) {
218: onbeforeunload_ = onbeforeunload;
219: }
220:
221: public String getId() {
222: return id_;
223: }
224:
225: public void setId(String id) {
226: id_ = id;
227: }
228:
229: public String getStyleClass() {
230: return styleClass_;
231: }
232:
233: public void setStyleClass(String styleClass) {
234: styleClass_ = styleClass;
235: }
236:
237: public String getLang() {
238: return lang_;
239: }
240:
241: public void setLang(String lang) {
242: lang_ = lang;
243: }
244:
245: public String getDir() {
246: return dir_;
247: }
248:
249: public void setDir(String dir) {
250: dir_ = dir;
251: }
252:
253: public String getTitle() {
254: return title_;
255: }
256:
257: public void setTitle(String title) {
258: title_ = title;
259: }
260:
261: public String getStyle() {
262: return style_;
263: }
264:
265: public void setStyle(String style) {
266: style_ = style;
267: }
268:
269: public String getBgcolor() {
270: return bgcolor_;
271: }
272:
273: public void setBgcolor(String bgcolor) {
274: bgcolor_ = bgcolor;
275: }
276:
277: public String getOnunload() {
278: return onunload_;
279: }
280:
281: public void setOnunload(String onunload) {
282: onunload_ = onunload;
283: }
284:
285: public String getOnclick() {
286: return onclick_;
287: }
288:
289: public void setOnclick(String onclick) {
290: onclick_ = onclick;
291: }
292:
293: public String getOnmousedown() {
294: return onmousedown_;
295: }
296:
297: public void setOnmousedown(String onmousedown) {
298: onmousedown_ = onmousedown;
299: }
300:
301: public String getOnmouseup() {
302: return onmouseup_;
303: }
304:
305: public void setOnmouseup(String onmouseup) {
306: onmouseup_ = onmouseup;
307: }
308:
309: public String getOnmouseover() {
310: return onmouseover_;
311: }
312:
313: public void setOnmouseover(String onmouseover) {
314: onmouseover_ = onmouseover;
315: }
316:
317: public String getOnmousemove() {
318: return onmousemove_;
319: }
320:
321: public void setOnmousemove(String onmousemove) {
322: onmousemove_ = onmousemove;
323: }
324:
325: public String getOnmouseout() {
326: return onmouseout_;
327: }
328:
329: public void setOnmouseout(String onmouseout) {
330: onmouseout_ = onmouseout;
331: }
332:
333: public String getOnkeypress() {
334: return onkeypress_;
335: }
336:
337: public void setOnkeypress(String onkeypress) {
338: onkeypress_ = onkeypress;
339: }
340:
341: public String getOnkeydown() {
342: return onkeydown_;
343: }
344:
345: public void setOnkeydown(String onkeydown) {
346: onkeydown_ = onkeydown;
347: }
348:
349: public String getOnkeyup() {
350: return onkeyup_;
351: }
352:
353: public void setOnkeyup(String onkeyup) {
354: onkeyup_ = onkeyup;
355: }
356:
357: // attributes ///////////////////////////////////////////////////////////////
358:
359: private String onload_ = "";
360: private String onbeforeunload_ = "";
361: private String id_ = "";
362: private String styleClass_ = "";
363: private String lang_ = "";
364: private String dir_ = "";
365: private String title_ = "";
366: private String style_ = "";
367: private String bgcolor_ = "";
368: private String onunload_ = "";
369: private String onclick_ = "";
370: private String onmousedown_ = "";
371: private String onmouseup_ = "";
372: private String onmouseover_ = "";
373: private String onmousemove_ = "";
374: private String onmouseout_ = "";
375: private String onkeypress_ = "";
376: private String onkeydown_ = "";
377: private String onkeyup_ = "";
378: }
|