1 19 20 package com.sslexplorer.input.tags; 21 22 import java.util.StringTokenizer ; 23 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.jsp.JspException ; 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 FRAME_NORMAL = "normal"; 40 public final static String FRAME_MINIMIZED = "minimized"; 41 public final static String FRAME_COLLAPSED = "collapsed"; 42 public final static String FRAME_CLOSED = "closed"; 43 44 final static Log log = LogFactory.getLog(FrameTag.class); 45 46 48 protected String titleKey; 49 protected String title; 50 protected String titleClass; 51 protected String titleId; 52 protected boolean expander; 53 protected String panelId; 54 55 58 protected static MessageResources messages = MessageResources.getMessageResources("org.apache.struts.taglib.bean.LocalStrings"); 59 60 63 public FrameTag() { 64 } 65 66 71 public void setTitleKey(String titleKey) { 72 this.titleKey = titleKey; 73 } 74 75 80 public void setTitle(String title) { 81 this.title = title; 82 } 83 84 89 public void setTitleClass(String titleClass) { 90 this.titleClass = titleClass; 91 } 92 93 98 public void setTitleId(String titleId) { 99 this.titleId = titleId; 100 } 101 102 107 public void setExpander(boolean expander) { 108 this.expander = expander; 109 } 110 111 116 public void setPanelId(String panelId) { 117 this.panelId = panelId; 118 if (getStyleId() == null) { 119 setStyleId("component_" + panelId); 120 } 121 } 122 123 128 public int doEndTag() throws JspException { 129 TagUtils.getInstance().write(pageContext, generateFragment()); 130 return (EVAL_PAGE); 131 } 132 133 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 153 public int doStartTag() throws JspException { 154 if (getBundle() == null || getBundle().equals("")) { 155 setBundle("navigation"); 156 } 157 return EVAL_BODY_BUFFERED; 158 } 159 160 String generateFragment() throws JspException { 161 String framePosition = CoreUtil.getCookieValue("frame_" + getStyleId() + "_pos", 162 (HttpServletRequest ) pageContext.getRequest(), 163 ""); 164 StringBuffer buf = new StringBuffer (); 165 Panel p = panelId == null ? null : PanelManager.getInstance().getPanel(panelId); 166 if (p == null && getStyleId() == null) { 167 throw new JspException ("Frame tag requires either panelId or styleId attributes"); 168 } 169 String frameState = CoreUtil.getCookieValue("frame_" + getStyleId(), 170 (HttpServletRequest ) 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 t = new StringTokenizer (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 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 [] {}); 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 |