KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > airsent > presentation > customer > OrderPage1


1 /*
2  * Copyright (c) 1999-2001 Lutris Technologies, Inc. All Rights
3  * Reserved.
4  *
5  * This source code file is distributed by Lutris Technologies, Inc. for
6  * use only by licensed users of product(s) that include this source
7  * file. Use of this source file or the software that uses it is covered
8  * by the terms and conditions of the Lutris Enhydra Development License
9  * Agreement included with this product.
10  *
11  * This Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
12  * ANY KIND, either express or implied. See the License for the specific terms
13  * governing rights and limitations under the License.
14  *
15  * Contributor(s):
16  *
17  * $Id: OrderPage1.java,v 1.1 2004/08/16 09:33:18 slobodan Exp $
18  */

19
20 package com.lutris.airsent.presentation.customer;
21
22 import com.lutris.airsent.presentation.BasePO;
23 import com.lutris.appserver.server.httpPresentation.*;
24 import com.lutris.appserver.server.session.*;
25 import com.lutris.util.*;
26 //import com.lutris.xml.xmlc.*;
27
//import com.lutris.xml.xmlc.html.*;
28
import org.w3c.dom.*;
29 import org.w3c.dom.html.*;
30 import org.enhydra.xml.xmlc.XMLObject;
31
32
33 import com.lutris.airsent.spec.AirSentException;
34
35 import com.lutris.airsent.presentation.AirSentPresentationException;
36 import com.lutris.airsent.presentation.AirSentConstants;
37 import java.util.*;
38 import com.lutris.airsent.spec.address.*;
39 import com.lutris.airsent.spec.customer.*;
40 import com.lutris.airsent.spec.*;
41
42
43 import com.lutris.airsent.spec.delivery.*;
44 /**
45  * Presentation object for order page 1
46  */

47 public class OrderPage1
48     extends BasePO {
49
50     /**
51      * Constants
52      */

53     private static final int AUTH_LEVEL = AirSentConstants.CUSTOMER_USER;
54
55
56     /**
57      * Superclass method override.
58      * returns the authorization level necessary to access this po.
59      *
60      * @return int required authorization level
61      */

62     public int getRequiredAuthLevel() {
63     return AUTH_LEVEL;
64     }
65
66     /**
67      * displays default page
68      *
69      * @return html page
70      * @exception if an error occurs
71      */

72     public XMLObject handleDefault()
73         throws HttpPresentationException {
74     try {
75         String JavaDoc id = getComms().request.getParameter(AirSentConstants.DELIVERYID);
76             OrderForm d = getOrder(id);
77             getSessionData().setOrderForm(d);
78             return showPage1(null, d);
79     } catch (Exception JavaDoc e) {
80         throw new AirSentPresentationException("System error finding user", e);
81     }
82     }
83     
84     /**
85      * process the form submission
86      *
87      * @return html page
88      * @exception if an error occurs
89      */

90     public XMLObject handleOrder1()
91         throws AirSentPresentationException {
92     try {
93             String JavaDoc p;
94             OrderForm orderForm = getOrder(null);
95             
96             p = getComms().request.getParameter(AirSentConstants.PICKUP_NAME);
97         if (checkField(p, Address.MAX_NAME) == false) {
98         return showPage1("Please provide a pickupname", orderForm);
99         }
100             orderForm.setPickUpName(p);
101
102             p = getComms().request.getParameter(AirSentConstants.PICKUP_ADDRESS);
103         if (checkField(p, Address.MAX_ADDRESS) == false) {
104         return showPage1("Please provide a pickupaddress", orderForm);
105         }
106             orderForm.setPickUpAddress1(p);
107                 
108             p = getComms().request.getParameter(AirSentConstants.PICKUP_PHONE);
109         if (checkField(p, Address.MAX_PHONE) == false) {
110         return showPage1("Please provide a pickupphone", orderForm);
111         }
112             orderForm.setPickUpPhone(p);
113
114             p = getComms().request.getParameter(AirSentConstants.PICKUP_DIRECTIONS);
115         if (checkField(p, Address.MAX_DIRECTIONS) == false) {
116         return showPage1("Please provide a pickupdirections", orderForm);
117         }
118             orderForm.setPickUpDirections(p);
119             
120             getSessionData().setOrderForm(orderForm);
121         throw new ClientPageRedirectException(AirSentConstants.ORDERSTEP2_PO);
122     
123     //We need to allow AirSent_pres to be functional , response will be default HTML page
124
}catch(NullPointerException JavaDoc e){
125            OrderStep2HTML defaultPage = (OrderStep2HTML) myComms.xmlcFactory.create(OrderStep2HTML.class);
126       defaultPage.setTextErrorText("This is a default HTML page");
127     return defaultPage;
128     } catch (Exception JavaDoc e) {
129         throw new AirSentPresentationException("System error processing OrderStep1.", e);
130     }
131     }
132
133     /**
134      * creates the html page
135      *
136      * @param errorMsg error message to display
137      * @param orderData data to populate the page with
138      * @exception if an error occurs
139      */

140     private XMLObject showPage1(String JavaDoc errorMsg, OrderForm orderForm)
141         throws AirSentPresentationException {
142
143     OrderStep1HTML page = (OrderStep1HTML) myComms.xmlcFactory.create(OrderStep1HTML.class);
144     try {
145         if (null != errorMsg || null != (errorMsg = getSessionData().getAndClearUserMessage())) {
146         page.setTextErrorText(errorMsg);
147         } else {
148         page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText());
149         }
150             if(orderForm.getOrderId() == null) {
151                 Node n = page.getElementNavDestination().getParentNode();
152                 n.removeChild(page.getElementNavDestination());
153                 n.removeChild(page.getElementNavDetails());
154             }
155             populatePage1(page, orderForm);
156 //We need to allow AirSent_pres to be functional , response will be default HTML page
157
}catch(NullPointerException JavaDoc e){
158            
159          OrderStep1HTML defaultPage = (OrderStep1HTML) myComms.xmlcFactory.create(OrderStep1HTML.class);
160       defaultPage.setTextErrorText("This is a default HTML page");
161     return defaultPage;
162     } catch (Exception JavaDoc e) {
163         throw new AirSentPresentationException("System error showing page 1", e);
164     }
165     return page;
166     }
167     
168     /**
169      * populates the page
170      *
171      * @param page to populate
172      * @param orderData data to populate it with
173      * @exception if an error occurs
174      */

175     private void populatePage1(OrderStep1HTML page, OrderForm orderForm)
176         throws AirSentPresentationException {
177
178     try {
179         if(orderForm.getOrderId() != null) {
180                 page.setTextOrderHeader("Order");
181         page.setTextOrdernumber(orderForm.getOrderId());
182         page.getElementPickupname().setValue(orderForm.getPickUpName());
183         page.getElementPickupaddress().setValue(orderForm.getPickUpAddress1());
184         page.getElementPickupphone().setValue(orderForm.getPickUpPhone());
185         } else {
186         page.setTextOrdernumber("");
187         }
188         // page.getElementPickupname().setValue(orderForm.getPickUpName());
189
// page.getElementPickupaddress().setValue(orderForm.getPickUpAddress1());
190
// page.getElementPickupphone().setValue(orderForm.getPickUpPhone());
191

192         if (orderForm.getPickUpDirections() != null) {
193         Text commentText = (page.getDocument()).createTextNode(orderForm.getPickUpDirections());
194         page.getElementPickupdirections().appendChild(commentText);
195         }
196     } catch (Exception JavaDoc e) {
197         throw new AirSentPresentationException("System error populating page1", e);
198     }
199     }
200
201     /**
202      * gets the order data from session or persisten store
203      */

204     private OrderForm getOrder(String JavaDoc id)
205         throws AirSentPresentationException {
206         try {
207             OrderForm orderForm = getSessionData().getOrderForm();
208             if ((orderForm == null) && (id == null)) {
209                 // new order session
210
// System.out.println("new order session");
211

212                 orderForm = OrderFormFactory.getOrderForm("com.lutris.airsent.business.delivery.OrderFormImpl");
213                 
214             
215             
216             } else if (id != null) {
217                 // editing previous order session
218
// System.out.println("editing previous order session: id = " + id);
219
HomeManager homeManager = getApplication().getHomeManager();
220                 Delivery d = homeManager.getDeliveryManager().findByHandle(id);
221               
222                 orderForm = OrderFormFactory.getOrderForm("com.lutris.airsent.business.delivery.OrderFormImpl",d);
223             }
224             return orderForm;
225  
226
227         } catch (Exception JavaDoc e) {
228             throw new AirSentPresentationException("System error getting order", e);
229         }
230     }
231 }
232
233
234
Popular Tags