1 23 24 package com.sun.enterprise.tools.guiframework.view; 25 26 import com.iplanet.jato.RequestContext; 27 import com.iplanet.jato.SecurityCheckException; 28 import com.iplanet.jato.command.Command; 29 import com.iplanet.jato.command.CommandEvent; 30 import com.iplanet.jato.command.CommandException; 31 import com.iplanet.jato.model.ModelControlException; 32 import com.iplanet.jato.view.View; 33 import com.iplanet.jato.view.ViewBean; 34 import com.iplanet.jato.view.ViewBeanBase; 35 import com.iplanet.jato.view.event.ChildContentDisplayEvent; 36 import com.iplanet.jato.view.event.ChildDisplayEvent; 37 import com.iplanet.jato.view.event.DisplayEvent; 38 39 import java.util.EventObject ; 40 import java.util.Iterator ; 41 import java.util.List ; 42 import java.util.Locale ; 43 import java.util.Map ; 44 import java.util.logging.Level ; 45 import java.util.logging.Logger ; 46 47 import com.sun.enterprise.tools.guiframework.event.descriptors.EventDescriptor; 48 import com.sun.enterprise.tools.guiframework.exception.FrameworkError; 49 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 50 import com.sun.enterprise.tools.guiframework.util.LogUtil; 51 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 52 53 54 60 public class DescriptorViewBeanBase extends ViewBeanBase implements Command, DescriptorContainerView { 61 62 70 public DescriptorViewBeanBase(RequestContext context, String pageName, ViewDescriptor desc) { 71 super(pageName); 72 73 setRequestContext(context); 75 setLocale(context.getRequest().getLocale()); 76 77 setDescriptor(desc); 78 registerViewDescriptorChildren(); 79 } 80 81 82 87 public ViewDescriptor getViewDescriptor() { 88 return _viewDesc; 89 } 90 91 92 95 public void setDescriptor(ViewDescriptor desc) { 96 if (desc == null) { 97 throw new FrameworkException("Cannot set null ViewDescriptor!", 98 desc, this); 99 } 100 101 String url = desc.getDisplayURL(); 103 104 if (LogUtil.isLoggable(LogUtil.FINER)) { 106 LogUtil.log(LogUtil.FINER, "trace.setDisplayURL", url); 107 } 108 109 if (url == null) { 110 throw new FrameworkException( 111 "DisplayURL in ViewDescriptor cannot be NULL for ViewBeans!", 112 desc, this); 113 } 114 setDefaultDisplayURL(getLocalizedURL(url)); 115 116 _viewDesc = desc; 118 } 119 120 121 122 126 134 public void registerViewDescriptorChildren() { 135 DescriptorViewHelper.registerViewDescriptorChildren(getViewDescriptor(), this); 136 } 137 138 139 142 public View createChild(String name) { 143 return DescriptorViewHelper.createChild(this, name); 144 } 145 146 147 148 152 158 public void beginDisplay(DisplayEvent event) throws ModelControlException { 159 DescriptorViewHelper.beginDisplay(this, event); 160 super.beginDisplay(event); 161 } 162 163 164 167 public boolean beginChildDisplay(ChildDisplayEvent event) throws ModelControlException { 168 return DescriptorViewHelper.beginChildDisplay(this, event); 169 } 170 171 172 175 public String endChildDisplay(ChildContentDisplayEvent event) throws ModelControlException { 176 return DescriptorViewHelper.endChildDisplay(this, event); 177 } 178 179 180 183 public void securityCheck() throws SecurityCheckException { 184 super.securityCheck(); 186 } 187 188 189 public void endDisplay(DisplayEvent event) { 190 DescriptorViewHelper.endDisplay(this, event); 191 super.endDisplay(event); 192 } 193 194 195 199 209 public void execute(CommandEvent event) throws CommandException { 210 DescriptorViewHelper.execute( 211 getRequestContext(), (View)event.getSource(), event); 212 } 213 214 215 221 public ViewBean getViewBean(String viewBeanName) { 222 ViewBean viewBean = null; 223 try { 224 viewBean = getRequestContext().getViewBeanManager(). 225 getViewBean(viewBeanName); 226 } catch (ClassNotFoundException ex) { 227 throw new RuntimeException ("Unable to forward to: '"+viewBeanName+ 228 "', cannot find that ViewBean!", ex); 229 } 230 return viewBean; 231 } 232 233 234 235 239 242 public void setAttributes(Map attributes) { 243 _attributes = attributes; 244 } 245 246 247 250 protected Object getAttribute(String name) { 251 return (_attributes == null) ? null : _attributes.get(name); 252 } 253 254 255 260 public Locale getLocale() { 261 return _locale; 262 } 263 264 265 271 public void setLocale(Locale locale) { 272 _locale = locale; 273 } 274 275 276 280 public String getLocalizedURL(String fileName) { 281 if (getLocale().equals(Locale.ENGLISH) || getLocale().getLanguage().equals("en")) { 282 return fileName; 283 } 284 285 int index = fileName.indexOf('?'); 286 String newName = null; 287 288 if(index != -1) { 289 newName = fileName.substring(0, index); 290 } else { 291 newName = fileName; 292 } 293 int lastdot = newName.lastIndexOf(".jsp"); 294 newName = newName.substring(0,lastdot) + "_" + getLocale().getLanguage() + ".jsp"; 295 296 try { 297 DescriptorViewHelper.verifyClassExists(getRequestContext().getServletContext(), newName); 298 if(index >= 0) { 299 newName += fileName.substring(fileName.indexOf('?')); 300 } 301 } catch (ClassNotFoundException ex) { 302 return fileName; 304 } 305 return newName; 306 } 307 308 private Locale _locale = null; 309 310 private ViewDescriptor _viewDesc = null; 311 private Map _attributes = null; 312 } 313 | Popular Tags |