KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > config > BarracudaConfig


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site (http://www.enhydra.org/).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: BarracudaConfig.java,v 1.1 2004/05/28 19:39:27 slobodan Exp $
22  */

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.barracuda.core.util.dom.io.*;
45
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 /**
51  * This mini-app is can be used to configure the core Barracuda
52  * classes. This class contains event handlers (both Controller
53  * and View) for the Config screen (which is the only screen)
54  */

55 public class BarracudaConfig extends DefaultEventGateway {
56
57     //public constants
58
protected static final Logger logger = Logger.getLogger(BarracudaConfig.class.getName());
59
60     public static final String JavaDoc MASTER_SCREEN = BarracudaConfig.class.getName()+".MasterScreen";
61     public static final String JavaDoc FORM = BarracudaConfig.class.getName()+".Form";
62     public static final String JavaDoc ERR = BarracudaConfig.class.getName()+".Errors";
63
64     //this defines the various event handlers
65
private ListenerFactory getConfigFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new GetConfigHandler();} public String JavaDoc getListenerID() {return getID(GetConfigHandler.class);}};
66     private ListenerFactory getNextConfigFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new GetNextConfigHandler();} public String JavaDoc getListenerID() {return getID(GetConfigHandler.class);}};
67     private ListenerFactory renderConfigFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new RenderConfigHandler();} public String JavaDoc getListenerID() {return getID(RenderConfigHandler.class);}};
68
69     //------------------- BarracudaConfig ------------------------
70
/**
71      * Public constructor
72      */

73     public BarracudaConfig() {
74         //specify who's interested in what
75
specifyLocalEventInterests(getConfigFactory, GetBConfig.class);
76         specifyLocalEventInterests(getNextConfigFactory, GetNextBConfig.class);
77         specifyLocalEventInterests(renderConfigFactory, RenderBConfig.class);
78
79         //add in sub-gateways
80
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     //------------------------------------------------------------
92
// Model 2 - Controller Event Handlers
93
//------------------------------------------------------------
94
/**
95      * GetConfigHandler - handle the request to get the config
96      * screen.
97      */

98     class GetConfigHandler extends DefaultBaseEventListener {
99         public void handleControlEvent(ControlEventContext context) throws EventException, ServletException, IOException {
100             //get the appropriate screen for the desired context and locale
101
Locale locale = context.getViewCapabilities().getClientLocale();
102             MasterScreen screen = new MasterScreenFactory().getInstance(BarracudaConfig.this, context, locale);
103             
104             //make sure the proper tab is selected (get curtab from session)
105
HttpSession session = SessionServices.getSession(context.getRequest());
106             String JavaDoc curtab = (String JavaDoc) session.getAttribute(TabsModel.CUR_TAB);
107             screen.tabsModel.setCurrentTab(curtab);
108             
109             //place the screen in the context (so the renderer can access it)
110
context.putState(MASTER_SCREEN, screen);
111
112             //forward control to the renderer
113
context.getQueue().addEvent(new RenderBConfig());
114         }
115     }
116
117     /**
118      * GetNextConfigHandler - get the next barracuda config screen (expects
119      * a TabsModel.CUR_TAB parameter in the request
120      */

121     class GetNextConfigHandler extends DefaultBaseEventListener {
122         public void handleControlEvent(ControlEventContext context) throws EventException, ServletException, IOException {
123             //get the curtab parameter
124
String JavaDoc curtab = context.getRequest().getParameter(TabsModel.CUR_TAB);
125             
126             //place it in the session (so it'll be available when we handle
127
//the get event request)
128
HttpSession session = SessionServices.getSession(context.getRequest());
129             session.setAttribute(TabsModel.CUR_TAB, curtab);
130
131             //now redirect to the main get event
132
throw new ClientSideRedirectException(new GetBConfig());
133         }
134     }
135
136     //------------------------------------------------------------
137
// Model 2 - View Event Handlers
138
//------------------------------------------------------------
139
/**
140      * RenderConfigHandler - handle the request to render the config
141      * screen
142      */

143     class RenderConfigHandler extends DefaultBaseEventListener {
144         public void handleViewEvent(ViewEventContext context) throws EventException, ServletException, IOException {
145             //get the screen from context
146
MasterScreen screen = (MasterScreen) context.getState(MASTER_SCREEN);
147
148 //TODO: note we really should be calling the initCycle and destroyCycle methods
149
//on this component hierarchy (not here of course, but it does need to be done)
150

151             //grab the component hierarchy and render it
152
ViewContext vc = new DefaultViewContext(context);
153             try {screen.bcRoot.render(vc);}
154             catch (RenderException e) {logger.debug ("Error rendering views:", e);}
155
156             //csc_112901.2
157
//now adjust the outgoing page (this is critical to make sure we
158
//can accurately detect client scripting)
159
ScriptDetector.prepareClientResp(screen.dom, vc);
160
161             //now render the DOM
162
//06_19_2001_Jacob_Kjome_start - hoju@visi.com
163
//get the output options
164
OutputOptions oo = DefaultDOMWriter.getDefaultOutputOptions(screen.dom.getOwnerDocument());
165
166             //add doctype - need to do here because XMLC can't yet add the one embedded in the html to the DOM
167
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             //now render the DOM
172
// new DefaultDOMWriter().write(screen.dom, context.getResponse());
173
new DefaultDOMWriter(oo).write(screen.dom, context.getResponse());
174             //06_19_2001_Jacob_Kjome_end
175
}
176     }
177 }
Popular Tags