1 23 24 package com.sun.enterprise.tools.admingui.handlers; 25 26 import com.iplanet.jato.*; 27 import com.iplanet.jato.model.*; 28 import com.iplanet.jato.view.*; 29 import com.iplanet.jato.view.event.*; 30 import com.iplanet.jato.view.html.*; 31 import com.iplanet.jato.util.NonSyncStringBuffer; 32 33 import com.sun.web.ui.taglib.header.*; 34 import com.sun.web.ui.taglib.pagetitle.*; 35 import com.sun.web.ui.common.CCI18N; 36 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView; 37 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 38 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 39 import com.sun.enterprise.tools.guiframework.view.descriptors.CCActionTableDescriptor; 40 import com.sun.enterprise.tools.admingui.util.Util; 41 import com.sun.enterprise.tools.admingui.tree.IndexTreeNode; 42 43 import java.util.EventObject ; 44 import java.util.StringTokenizer ; 45 import java.util.Iterator ; 46 47 import com.sun.enterprise.tools.admingui.ConfigProperties; 48 49 public class HtmlHeaderHandler { 50 51 private boolean refreshForOpenNodes(RequestContext ctx) { 52 IndexTreeNode node = Util.getSelectedNode(); 53 if (node == null) 54 return false; 55 56 node = node.getParent(); 57 if (node == null) 58 return false; 59 60 return node.openNode(ctx); 63 } 64 65 private void setHeaderDisplayValues(CCHtmlHeaderTag tag, HandlerContext handlerCtx) { 66 String onUnload = (String )handlerCtx.getInputValue("onUnload"); 67 if (onUnload != null) 68 tag.setOnUnload(onUnload); 69 70 String copyRight = (String )handlerCtx.getInputValue("copyRight"); 71 if (copyRight != null) 72 tag.setCopyrightYear(copyRight); 73 74 String title = (String )handlerCtx.getInputValue("pageTitle"); 75 if (title != null) 76 tag.setPageTitle(title); 77 } 78 79 public void beginHtmlHeaderDisplay(RequestContext ctx, HandlerContext handlerCtx) { 80 ViewDescriptor vd = handlerCtx.getViewDescriptor(); 81 if (vd.getParent() != null) 82 vd = vd.getParent(); Iterator it = vd.getChildDescriptors().iterator(); 84 String tableButtonInitScript = ""; 85 while (it.hasNext()) { 86 ViewDescriptor child = (ViewDescriptor)it.next(); 87 if (child instanceof CCActionTableDescriptor) { 88 tableButtonInitScript = 89 (String )handlerCtx.getInputValue("tableButtonInitScript"); 90 break; 92 } 93 } 94 if (tableButtonInitScript == null) { 95 tableButtonInitScript = ""; 96 } 97 98 CCHtmlHeaderTag tag = (CCHtmlHeaderTag)handlerCtx.getEvent().getSource(); 99 100 boolean refresh = ctx.getRequest().getAttribute("refreshTree") != null; 101 String onLoad = null; 102 if (refreshForOpenNodes(ctx) || refresh) { 103 onLoad = (String )handlerCtx.getInputValue("onLoadRefreshTree"); 104 } else { 105 onLoad = (String )handlerCtx.getInputValue("onLoad"); 106 } 107 if (onLoad != null) { 108 tag.setOnLoad(tableButtonInitScript+onLoad); 109 } 110 setHeaderDisplayValues(tag, handlerCtx); 111 } 112 113 public void beginTreeHtmlHeaderDisplay(RequestContext ctx, HandlerContext handlerCtx) { 114 CCHtmlHeaderTag tag = (CCHtmlHeaderTag)handlerCtx.getEvent().getSource(); 115 116 boolean refresh = ctx.getRequest().getAttribute("refreshRightSide") != null; 117 if (refresh) { 118 String onLoad = (String )handlerCtx.getInputValue("onLoadRefreshRight"); 119 if (onLoad != null) 120 tag.setOnLoad(onLoad); 121 } else { 122 String onLoad = (String )handlerCtx.getInputValue("onLoad"); 123 if (onLoad != null) 124 tag.setOnLoad(onLoad); 125 } 126 ctx.getRequest().removeAttribute("refreshRightSide"); setHeaderDisplayValues(tag, handlerCtx); 128 } 129 130 131 private static CCI18N peHelpIds = null; 132 private static CCI18N eeHelpIds = null; 133 134 private static String getHelpHTMLName(String key) { 135 Boolean isEE = ConfigProperties.getInstance().getTargetSupported(); 136 if (isEE.booleanValue() && eeHelpIds == null) { 137 eeHelpIds = new CCI18N(RequestManager.getRequestContext(), 138 "com.sun.enterprise.ee.tools.admingui.resources.Helplinks"); 139 } 140 if (peHelpIds == null) { 141 peHelpIds = new CCI18N(RequestManager.getRequestContext(), 142 "com.sun.enterprise.tools.admingui.resources.Helplinks"); 143 } 144 String htmlFileName = null; 145 if (eeHelpIds != null) { 146 htmlFileName = eeHelpIds.getMessage(key); 147 if (htmlFileName.equals(key)) 148 htmlFileName = null; } 150 if (htmlFileName == null) { 151 htmlFileName = peHelpIds.getMessage(key); 152 } 153 if (htmlFileName != null) { 154 htmlFileName = htmlFileName.trim(); 155 } 156 if (htmlFileName == null || htmlFileName.length() == 0 || htmlFileName.equals(key)) { 157 htmlFileName = peHelpIds.getMessage("default"); 158 } 159 if (htmlFileName != null) { 160 htmlFileName = htmlFileName.trim(); 161 } 162 if (htmlFileName == null || htmlFileName.equals("")) { 163 htmlFileName = key; 164 } 165 if (htmlFileName.endsWith(".html") == false) { 166 htmlFileName += ".html"; 167 } 168 return htmlFileName; 169 } 170 171 private void addHiddenAttrValue(NonSyncStringBuffer buff, RequestContext ctx, 172 IndexTreeNode node, String attrName, boolean lookUpInTreeHierarchy) { 173 String attr = null; 174 Object obj = node.getAttribute(attrName, lookUpInTreeHierarchy); 175 if (obj == null) obj = ctx.getRequest().getAttribute(attrName); 177 if (obj != null) 179 attr = obj.toString(); 181 if (attr != null && attr.length() > 0) { 182 buff.append("\n<input name=\"") 183 .append(attrName) 184 .append("\" type=\"hidden\" value=\"") 185 .append(attr).append("\">"); 186 } 187 } 188 189 private void setCurrentView(RequestContext ctx, View view) { 190 String currentView = view.getName(); 194 String editKeyValue = (String )ctx.getRequest().getAttribute("editKeyValue"); 195 if (editKeyValue != null) 196 currentView += "?editKeyValue="+Util.URLencode(ctx, editKeyValue); 197 198 Util.setCurrentViewURL(currentView); 199 } 200 201 public String endExtraDisplay(RequestContext ctx, HandlerContext handlerCtx) { 203 ChildContentDisplayEvent ev = (ChildContentDisplayEvent)handlerCtx.getEvent(); 204 View bean = handlerCtx.getView(); 205 206 while (!(bean instanceof DescriptorContainerView)) { 207 bean = bean.getParent(); 209 } 210 setCurrentView(ctx, bean); 212 213 NonSyncStringBuffer buff = new NonSyncStringBuffer(ev.getContent(), 512); 214 215 String script = (String )handlerCtx.getInputValue("script") ; 216 if (script != null) { 217 buff.append("\n").append(script); 218 } 219 220 221 IndexTreeNode selectedNode = Util.getSelectedNode(); 222 if (selectedNode != null) { 223 String id = selectedNode.getHighlightIDPath(); 224 buff.append("\n<input name=\"highlightid\" type=\"hidden\" value=\"") 225 .append(id).append("\">"); 226 227 addHiddenAttrValue(buff, ctx, selectedNode, IndexTreeNode.INSTANCE_NAME, true); 228 addHiddenAttrValue(buff, ctx, selectedNode, IndexTreeNode.CONFIG_NAME, true); 229 addHiddenAttrValue(buff, ctx, selectedNode, IndexTreeNode.CLUSTER_NAME, true); 230 addHiddenAttrValue(buff, ctx, selectedNode, IndexTreeNode.NODEAGENT_NAME, true); 231 addHiddenAttrValue(buff, ctx, selectedNode, IndexTreeNode.APPLICATION_TYPE, true); 232 addHiddenAttrValue(buff, ctx, selectedNode, IndexTreeNode.OBJECT_NAME, false); 233 } 234 235 String helpID = (String )handlerCtx.getInputValue("helpID") ; 236 if (helpID == null) 237 helpID = bean.getName(); 238 String helpHTMLName = getHelpHTMLName(helpID); 239 buff.append("\n<input name=\"helplink\" type=\"hidden\" value=\"") 240 .append(helpHTMLName).append("\">"); 241 242 return buff.toString(); 243 } 244 245 public String endResourceStringsDisplay(RequestContext ctx, HandlerContext handlerCtx) { 246 ChildContentDisplayEvent ev = (ChildContentDisplayEvent)handlerCtx.getEvent(); 247 String keys = ev.getContent(); 248 if (keys == null | keys.length() == 0) 249 return ""; 250 251 String result = ""; 252 StringTokenizer st = new StringTokenizer (keys); 253 while (st.hasMoreTokens()) { 254 String key = st.nextToken().trim(); 255 if (key.length() == 0) 256 continue; 257 result += "<input name=\"" + key + "\" type=\"hidden\" value=\"" + 258 Util.getMessage(key) + "\">\n"; 259 } 260 return result; 261 } 262 263 public void beginLinksPageTitleDisplay(RequestContext ctx, HandlerContext handlerCtx) { 264 CCPageTitleTag tag = (CCPageTitleTag)handlerCtx.getEvent().getSource(); 265 IndexTreeNode selectedNode = Util.getSelectedNode(); 266 tag.setPageTitleText(selectedNode.getName()); 267 } 268 269 public String endChildPageLinkDisplay(RequestContext ctx, HandlerContext handlerCtx) { 270 final String hrefExtras = "title=\"@@@@\" " + 271 "onmouseover=\"window.status='@@@@'; return true\" " + 272 "onmouseout=\"window.status=''; return true\" " + 273 "onblur=\"window.status=''; return true\" " + 274 "onfocus=\"window.status='@@@@'; return true\" "; 275 276 ChildContentDisplayEvent ev = (ChildContentDisplayEvent)handlerCtx.getEvent(); 277 String html = ev.getContent(); 278 String replace = (String )handlerCtx.getInputValue("replace"); 279 if (Util.isEmpty(replace)) 280 replace = "links"; 281 IndexTreeNode selectedNode = Util.getSelectedNode(); 282 if (selectedNode != null) { 283 html = Util.removeHtmlProp(html, "name"); 285 html = html.replaceAll(replace, "Index"); 287 html = html.replaceAll("childPageLink", "TreeView1.showContainer"); 288 289 int i = html.indexOf("__"); 291 int j = html.indexOf("__", i+2); 292 if (i < 0 || j < 0) 293 return ""; 294 int index = new Integer (html.substring(i+2, j)).intValue(); 295 296 IndexTreeNode kid = (IndexTreeNode)selectedNode.getChildren().get(index); 298 if (kid == null) 299 return ""; 300 html = html.replaceAll(html.substring(i, j+2), kid.getName()); 301 html = html.replaceAll("_VALUE_", kid.getPath()); 302 303 html = Util.addHtmlProp(html, hrefExtras.replaceAll("@@@@", kid.getName())); 304 return html; 305 } 306 return ""; 307 } 308 309 } 310 | Popular Tags |