1 23 package org.enhydra.barracuda.config; 24 25 import java.io.*; 26 import java.util.*; 27 import java.lang.ref.*; 28 import java.net.*; 29 import javax.servlet.*; 30 import javax.servlet.http.*; 31 32 import org.apache.log4j.*; 33 import org.w3c.dom.*; 34 import org.w3c.dom.html.*; 35 36 import org.enhydra.barracuda.config.events.*; 37 import org.enhydra.barracuda.config.xmlc.*; 38 import org.enhydra.barracuda.core.comp.*; 39 import org.enhydra.barracuda.core.event.*; 40 import org.enhydra.barracuda.core.event.helper.*; 41 import org.enhydra.barracuda.core.forms.*; 42 import org.enhydra.barracuda.core.helper.servlet.*; 43 import org.enhydra.barracuda.core.util.dom.*; 44 import org.enhydra.xml.io.*; 46 import org.enhydra.barracuda.core.util.http.*; 47 import org.enhydra.barracuda.core.view.*; 48 import org.enhydra.barracuda.plankton.data.*; 49 50 55 public class BarracudaConfig extends DefaultEventGateway { 56 57 protected static final Logger logger = Logger.getLogger(BarracudaConfig.class.getName()); 59 60 public static final String MASTER_SCREEN = BarracudaConfig.class.getName()+".MasterScreen"; 61 public static final String FORM = BarracudaConfig.class.getName()+".Form"; 62 public static final String ERR = BarracudaConfig.class.getName()+".Errors"; 63 64 private ListenerFactory getConfigFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new GetConfigHandler();} public String getListenerID() {return getID(GetConfigHandler.class);}}; 66 private ListenerFactory getNextConfigFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new GetNextConfigHandler();} public String getListenerID() {return getID(GetConfigHandler.class);}}; 67 private ListenerFactory renderConfigFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new RenderConfigHandler();} public String getListenerID() {return getID(RenderConfigHandler.class);}}; 68 69 73 public BarracudaConfig() { 74 specifyLocalEventInterests(getConfigFactory, GetBConfig.class); 76 specifyLocalEventInterests(getNextConfigFactory, GetNextBConfig.class); 77 specifyLocalEventInterests(renderConfigFactory, RenderBConfig.class); 78 79 this.add(new CompConfig()); 81 this.add(new DataConfig()); 82 this.add(new DomConfig()); 83 this.add(new EventConfig()); 84 this.add(new FormsConfig()); 85 this.add(new UtilConfig()); 86 this.add(new ViewConfig()); 87 this.add(new MasterConfig()); 88 } 89 90 91 98 class GetConfigHandler extends DefaultBaseEventListener { 99 public void handleControlEvent(ControlEventContext context) throws EventException, ServletException, IOException { 100 Locale locale = context.getViewCapabilities().getClientLocale(); 102 MasterScreen screen = new MasterScreenFactory().getInstance(BarracudaConfig.this, context, locale); 103 104 HttpSession session = SessionServices.getSession(context.getRequest()); 106 String curtab = (String ) session.getAttribute(TabsModel.CUR_TAB); 107 screen.tabsModel.setCurrentTab(curtab); 108 109 context.putState(MASTER_SCREEN, screen); 111 112 context.getQueue().addEvent(new RenderBConfig()); 114 } 115 } 116 117 121 class GetNextConfigHandler extends DefaultBaseEventListener { 122 public void handleControlEvent(ControlEventContext context) throws EventException, ServletException, IOException { 123 String curtab = context.getRequest().getParameter(TabsModel.CUR_TAB); 125 126 HttpSession session = SessionServices.getSession(context.getRequest()); 129 session.setAttribute(TabsModel.CUR_TAB, curtab); 130 131 throw new ClientSideRedirectException(new GetBConfig()); 133 } 134 } 135 136 143 class RenderConfigHandler extends DefaultBaseEventListener { 144 public void handleViewEvent(ViewEventContext context) throws EventException, ServletException, IOException { 145 MasterScreen screen = (MasterScreen) context.getState(MASTER_SCREEN); 147 148 151 ViewContext vc = new DefaultViewContext(context); 153 try {screen.bcRoot.render(vc);} 154 catch (RenderException e) {logger.debug ("Error rendering views:", e);} 155 156 ScriptDetector.prepareClientResp(screen.dom, vc); 160 161 OutputOptions oo = DefaultDOMWriter.getDefaultOutputOptions(screen.dom.getOwnerDocument()); 165 166 oo.setOmitDocType(false); 168 oo.setPublicId("-//W3C//DTD HTML 4.01 Transitional//EN"); 169 oo.setSystemId("http://www.w3.org/TR/html401/loose.dtd"); 170 171 new DefaultDOMWriter(oo).write(screen.dom, context.getResponse()); 174 } 176 } 177 } | Popular Tags |