KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > input > tags > FrameTag


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.input.tags;
21
22 import java.util.StringTokenizer JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.jsp.JspException JavaDoc;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.struts.taglib.TagUtils;
30 import org.apache.struts.taglib.html.BaseFieldTag;
31 import org.apache.struts.util.MessageResources;
32
33 import com.sslexplorer.core.CoreUtil;
34 import com.sslexplorer.core.Panel;
35 import com.sslexplorer.core.PanelManager;
36
37 public class FrameTag extends BaseFieldTag {
38
39     public final static String JavaDoc FRAME_NORMAL = "normal";
40     public final static String JavaDoc FRAME_MINIMIZED = "minimized";
41     public final static String JavaDoc FRAME_COLLAPSED = "collapsed";
42     public final static String JavaDoc FRAME_CLOSED = "closed";
43
44     final static Log log = LogFactory.getLog(FrameTag.class);
45
46     // Protected instance variables
47

48     protected String JavaDoc titleKey;
49     protected String JavaDoc title;
50     protected String JavaDoc titleClass;
51     protected String JavaDoc titleId;
52     protected boolean expander;
53     protected String JavaDoc panelId;
54
55     /**
56      * The message resources for this package.
57      */

58     protected static MessageResources messages = MessageResources.getMessageResources("org.apache.struts.taglib.bean.LocalStrings");
59
60     /**
61      * Constructor
62      */

63     public FrameTag() {
64     }
65
66     /**
67      * Set the messsage resources key to use for the title
68      *
69      * @param titleKey title message resources key
70      */

71     public void setTitleKey(String JavaDoc titleKey) {
72         this.titleKey = titleKey;
73     }
74
75     /**
76      * Set the text
77      *
78      * @param title title
79      */

80     public void setTitle(String JavaDoc title) {
81         this.title = title;
82     }
83
84     /**
85      * Set title class
86      *
87      * @param titleClass title
88      */

89     public void setTitleClass(String JavaDoc titleClass) {
90         this.titleClass = titleClass;
91     }
92
93     /**
94      * Set title id
95      *
96      * @param titleId title id
97      */

98     public void setTitleId(String JavaDoc titleId) {
99         this.titleId = titleId;
100     }
101
102     /**
103      * Set if this frame should have an expander
104      *
105      * @param expander expander
106      */

107     public void setExpander(boolean expander) {
108         this.expander = expander;
109     }
110
111     /**
112      * Set if the panel id
113      *
114      * @param expander expander
115      */

116     public void setPanelId(String JavaDoc panelId) {
117         this.panelId = panelId;
118         if (getStyleId() == null) {
119             setStyleId("component_" + panelId);
120         }
121     }
122
123     /*
124      * (non-Javadoc)
125      *
126      * @see javax.servlet.jsp.tagext.BodyTagSupport#doEndTag()
127      */

128     public int doEndTag() throws JspException JavaDoc {
129         TagUtils.getInstance().write(pageContext, generateFragment());
130         return (EVAL_PAGE);
131     }
132
133     /*
134      * (non-Javadoc)
135      *
136      * @see javax.servlet.jsp.tagext.BodyTagSupport#release()
137      */

138     public void release() {
139         super.release();
140         titleKey = null;
141         title = null;
142         expander = false;
143         panelId = null;
144         titleClass = null;
145         titleId = null;
146     }
147
148     /*
149      * (non-Javadoc)
150      *
151      * @see javax.servlet.jsp.tagext.BodyTagSupport#doStartTag()
152      */

153     public int doStartTag() throws JspException JavaDoc {
154         if (getBundle() == null || getBundle().equals("")) {
155             setBundle("navigation");
156         }
157         return EVAL_BODY_BUFFERED;
158     }
159
160     String JavaDoc generateFragment() throws JspException JavaDoc {
161         String JavaDoc framePosition = CoreUtil.getCookieValue("frame_" + getStyleId() + "_pos",
162             (HttpServletRequest JavaDoc) pageContext.getRequest(),
163             "");
164         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
165         Panel p = panelId == null ? null : PanelManager.getInstance().getPanel(panelId);
166         if (p == null && getStyleId() == null) {
167             throw new JspException JavaDoc("Frame tag requires either panelId or styleId attributes");
168         }
169         String JavaDoc frameState = CoreUtil.getCookieValue("frame_" + getStyleId(),
170             (HttpServletRequest JavaDoc) pageContext.getRequest(),
171             p != null ? p.getDefaultFrameState() : FRAME_NORMAL);
172         buf.append("<div ");
173         buf.append("id=\"");
174         buf.append(getStyleId());
175         buf.append("\"");
176         if (getStyleClass() != null) {
177             buf.append(" class=\"");
178             buf.append(getStyleClass());
179             buf.append("\"");
180         }
181         if (!framePosition.equals("") || frameState.equals(FRAME_CLOSED)) {
182             buf.append(" style=\"");
183             if (!framePosition.equals("")) {
184                 try {
185                     StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(framePosition, ",");
186                     int x = Integer.parseInt(t.nextToken());
187                     int y = Integer.parseInt(t.nextToken());
188                     buf.append("left: ");
189                     buf.append(x);
190                     buf.append("px; top: ");
191                     buf.append(y);
192                     buf.append("px;");
193                 } catch (Exception JavaDoc e) {
194                 }
195             }
196             if (frameState.equals("closed") && (p == null || p.isCloseable())) {
197                 buf.append("display: none;");
198             }
199             buf.append("\" ");
200         }
201         buf.append(">");
202         buf.append("<div id=\"");
203         buf.append(getStyleId());
204         buf.append("Container\"");
205         if (frameState.equals(FRAME_COLLAPSED)) {
206             buf.append(" style=\"position: relative; left: -17.2em\"");
207         }
208         buf.append(">");
209
210         if (titleKey != null) {
211             title = TagUtils.getInstance().message(pageContext, getBundle(), getLocale(), titleKey, new String JavaDoc[] {});
212         }
213
214         if (title != null && !title.equals("")) {
215             buf.append("<div class=\"titleBar\"");
216             if (p != null && p.isDragable()) {
217                 if (p.isDropable()) {
218                     buf.append(" onmousedown=\"registerDragAndDrop(event,'");
219                 } else {
220                     buf.append(" onmousedown=\"registerDrag(event, \'");
221                 }
222                 buf.append(getStyleId());
223                 buf.append("')\"");
224             }
225             buf.append(">");
226             buf.append("<div class=\"titleInner\">");
227             if (expander && (p == null || p.isCloseable())) {
228                 buf.append("<div class=\"expander\">");
229                 buf.append("<img id=\"");
230                 buf.append(getStyleId());
231                 buf.append("_collapse");
232                 buf.append("\" onclick=\"frameCollapse('");
233                 buf.append(getStyleId());
234                 buf.append("');\" SRC=\"");
235                 buf.append(CoreUtil.getThemePath(pageContext.getSession()) + "/images/collapse.gif");
236                 buf.append("\"/>");
237                 buf.append("</div>");
238             }
239             buf.append("<div class=\"");
240             buf.append(titleClass != null ? titleClass : "title");
241             buf.append("\"");
242             if (titleId != null) {
243                 buf.append(" id=\"");
244                 buf.append(titleId);
245                 buf.append("\"");
246             }
247             buf.append(">");
248             buf.append(title);
249             buf.append("</div>");
250             if (p == null || p.isCloseable() || p.isMinimizable()) {
251                 buf.append("<div class=\"actions\">");
252                 if (p == null || p.isMinimizable()) {
253                     buf.append("<img id=\"");
254                     buf.append(getStyleId());
255                     buf.append("_minimize");
256                     buf.append("\" onclick=\"frameMinimize('");
257                     buf.append(getStyleId());
258                     buf.append("');\" SRC=\"");
259                     buf.append(CoreUtil.getThemePath(pageContext.getSession()) + "/images/minimize.gif");
260                     if (frameState.equals(FRAME_MINIMIZED)) {
261                         buf.append("\" style=\"display: none");
262                     }
263                     buf.append("\"/>");
264                     buf.append("<img id=\"");
265                     buf.append(getStyleId());
266                     buf.append("_restore");
267                     buf.append("\" onclick=\"frameRestore('");
268                     buf.append(getStyleId());
269                     buf.append("');\" SRC=\"");
270                     buf.append(CoreUtil.getThemePath(pageContext.getSession()) + "/images/maximize.gif");
271                     if (frameState.equals(FRAME_NORMAL)) {
272                         buf.append("\" style=\"display: none");
273                     }
274                     buf.append("\"/>");
275                 }
276                 if (p == null || p.isCloseable()) {
277                     buf.append("<img id=\"");
278                     buf.append(getStyleId());
279                     buf.append("_close");
280                     buf.append("\" onclick=\"frameClose('");
281                     buf.append(getStyleId());
282                     buf.append("');\" SRC=\"");
283                     buf.append(CoreUtil.getThemePath(pageContext.getSession()) + "/images/close.gif");
284                     if (frameState.equals(FRAME_CLOSED)) {
285                         buf.append("\" style=\"display: none\"");
286                     }
287                     buf.append("\"/>");
288                 }
289                 if (expander) {
290                     buf.append("<img id=\"");
291                     buf.append(getStyleId());
292                     buf.append("_expand");
293                     buf.append("\" onclick=\"frameExpand('");
294                     buf.append(getStyleId());
295                     buf.append("');\" SRC=\"");
296                     buf.append(CoreUtil.getThemePath(pageContext.getSession()) + "/images/expand.gif");
297                     if (!frameState.equals(FRAME_COLLAPSED)) {
298                         buf.append("\" style=\"display: none");
299                     }
300                     buf.append("\"/>");
301                 }
302                 buf.append("</div>");
303             }
304             buf.append("</div>");
305             buf.append("</div>");
306         }
307         buf.append("<div class=\"frameContent\">");
308         buf.append("<div class=\"frameContentContainer\" id=\"");
309         buf.append(getStyleId() + "Content");
310         if (frameState.equals(FRAME_MINIMIZED)) {
311             buf.append("\" style=\"display: none");
312         }
313         buf.append("\">");
314         buf.append(bodyContent.getString());
315         buf.append("</div>");
316         buf.append("</div>");
317         buf.append("</div>");
318         buf.append("</div>");
319         if(getStyleId() != null) {
320             buf.append("<script language=\"JavaScript\">addDropTarget('");
321             buf.append(getStyleId());
322             buf.append("');</script>");
323         }
324         return buf.toString();
325     }
326 }
327
Popular Tags