1 20 package org.enhydra.barracuda.core.event.helper; 21 22 import java.io.*; 23 import java.util.*; 24 import javax.servlet.*; 25 26 import org.w3c.dom.*; 27 28 import org.enhydra.barracuda.core.comp.*; 29 import org.enhydra.barracuda.core.event.*; 30 import org.enhydra.barracuda.core.util.dom.*; 31 32 38 public abstract class BTemplateViewHandler extends DefaultViewHandler { 39 40 protected BTemplate templateComp = null; 42 48 public abstract Object getTemplateModels(); 51 54 public abstract Class getTemplateClass(); 55 56 60 public BTemplate getBTemplate() { 61 return templateComp; 62 } 63 64 67 public Document handleViewEvent(BComponent root) throws EventException, ServletException, IOException { ViewContext vc = this.getViewContext(); 71 Document page = DefaultDOMLoader.getGlobalInstance().getDOM(getTemplateClass(), vc.getViewCapabilities().getClientLocale()); 75 77 templateComp = new BTemplate(); Object o = getTemplateModels(); 83 if (o instanceof TemplateModel) templateComp.addModel((TemplateModel) o); 84 else if (o instanceof List) templateComp.addModels((List) o); 85 else if (o==null) { } 87 else throw new RuntimeException ("Fatal err: Model must return either TemplateModel or List"); 89 templateComp.setView(new DefaultTemplateView(page.getDocumentElement())); 91 root.addChild(templateComp); 92 93 return page; 95 } 96 } 97 | Popular Tags |