KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > testapp > interactive > testscreen > ClientConfigurationTest


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package nextapp.echo2.testapp.interactive.testscreen;
31
32 import nextapp.echo2.app.Alignment;
33 import nextapp.echo2.app.Border;
34 import nextapp.echo2.app.Button;
35 import nextapp.echo2.app.Color;
36 import nextapp.echo2.app.Column;
37 import nextapp.echo2.app.Extent;
38 import nextapp.echo2.app.Grid;
39 import nextapp.echo2.app.Insets;
40 import nextapp.echo2.app.Label;
41 import nextapp.echo2.app.MutableStyle;
42 import nextapp.echo2.app.Style;
43 import nextapp.echo2.app.TextField;
44 import nextapp.echo2.app.event.ActionEvent;
45 import nextapp.echo2.app.event.ActionListener;
46 import nextapp.echo2.app.layout.GridLayoutData;
47 import nextapp.echo2.app.layout.SplitPaneLayoutData;
48 import nextapp.echo2.webcontainer.ContainerContext;
49 import nextapp.echo2.webrender.ClientConfiguration;
50 import nextapp.echo2.webrender.WebRenderServlet;
51
52 /**
53  * Interactive test for client configuration settings.
54  */

55 public class ClientConfigurationTest extends Column {
56
57     private static final Style PROMPT_STYLE;
58     static {
59         MutableStyle style = new MutableStyle();
60         GridLayoutData layoutData = new GridLayoutData();
61         layoutData.setAlignment(new Alignment(Alignment.RIGHT, Alignment.TOP));
62         style.setProperty(PROPERTY_LAYOUT_DATA, layoutData);
63         PROMPT_STYLE = style;
64     }
65
66     private TextField serverErrorUriText, serverErrorMessageText, sessionExpirationUriText, sessionExpirationMessageText;
67     
68     /**
69      * Default constructor.
70      */

71     public ClientConfigurationTest() {
72         super();
73         SplitPaneLayoutData splitPaneLayoutData = new SplitPaneLayoutData();
74         splitPaneLayoutData.setInsets(new Insets(10));
75         setLayoutData(splitPaneLayoutData);
76         setCellSpacing(new Extent(20));
77         
78         Grid grid = new Grid(2);
79         grid.setBorder(new Border(2, Color.BLUE, Border.STYLE_GROOVE));
80         grid.setInsets(new Insets(10, 5));
81         add(grid);
82         
83         Label label;
84         
85         label = new Label("Server Error URI:");
86         label.setStyle(PROMPT_STYLE);
87         grid.add(label);
88         
89         serverErrorUriText = new TextField();
90         serverErrorUriText.setStyleName("Default");
91         grid.add(serverErrorUriText);
92         
93         label = new Label("Server Error Message:");
94         label.setStyle(PROMPT_STYLE);
95         grid.add(label);
96         
97         serverErrorMessageText = new TextField();
98         serverErrorMessageText.setStyleName("Default");
99         grid.add(serverErrorMessageText);
100         
101         label = new Label("Session Expiration URI:");
102         label.setStyle(PROMPT_STYLE);
103         grid.add(label);
104         
105         sessionExpirationUriText = new TextField();
106         sessionExpirationUriText.setStyleName("Default");
107         grid.add(sessionExpirationUriText);
108         
109         label = new Label("Session Expiration Message:");
110         label.setStyle(PROMPT_STYLE);
111         grid.add(label);
112         
113         sessionExpirationMessageText = new TextField();
114         sessionExpirationMessageText.setStyleName("Default");
115         grid.add(sessionExpirationMessageText);
116         
117         Button updateButton = new Button("Update ClientConfiguration");
118         updateButton.setStyleName("Default");
119         updateButton.addActionListener(new ActionListener(){
120             public void actionPerformed(ActionEvent e) {
121                 updateClientConfiguration();
122             }
123         });
124         add(updateButton);
125         
126         Button exceptionButton = new Button("Throw a RuntimeException");
127         exceptionButton.setStyleName("Default");
128         exceptionButton.addActionListener(new ActionListener(){
129             public void actionPerformed(ActionEvent e) {
130                 throw new RuntimeException JavaDoc("Test RuntimeException thrown at user request by ClientConfigurationTest.");
131             }
132         });
133         add(exceptionButton);
134         
135         Button expireSessionButton = new Button("Expire Session");
136         expireSessionButton.setStyleName("Default");
137         expireSessionButton.addActionListener(new ActionListener(){
138             public void actionPerformed(ActionEvent e) {
139                 WebRenderServlet.getActiveConnection().getRequest().getSession().invalidate();
140             }
141         });
142         add(expireSessionButton);
143     }
144     
145     /**
146      * Performs <code>ClientConfigurationUpdate</code>.
147      */

148     private void updateClientConfiguration() {
149         ClientConfiguration clientConfiguration = new ClientConfiguration();
150         if (serverErrorUriText.getText().trim().length() > 0) {
151             clientConfiguration.setProperty(ClientConfiguration.PROPERTY_SERVER_ERROR_URI, serverErrorUriText.getText());
152         }
153         if (serverErrorMessageText.getText().trim().length() > 0) {
154             clientConfiguration.setProperty(ClientConfiguration.PROPERTY_SERVER_ERROR_MESSAGE, serverErrorMessageText.getText());
155         }
156         if (sessionExpirationUriText.getText().trim().length() > 0) {
157             clientConfiguration.setProperty(ClientConfiguration.PROPERTY_SESSION_EXPIRATION_URI,
158                     sessionExpirationUriText.getText());
159         }
160         if (sessionExpirationMessageText.getText().trim().length() > 0) {
161             clientConfiguration.setProperty(ClientConfiguration.PROPERTY_SESSION_EXPIRATION_MESSAGE,
162                     sessionExpirationMessageText.getText());
163         }
164         
165         ContainerContext containerContext
166                 = (ContainerContext) getApplicationInstance().getContextProperty(ContainerContext.CONTEXT_PROPERTY_NAME);
167         containerContext.setClientConfiguration(clientConfiguration);
168     }
169 }
170
Popular Tags