KickJava   Java API By Example, From Geeks To Geeks.

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


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: OrderPage2.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 import com.lutris.airsent.spec.AirSentException;
32
33 import com.lutris.airsent.presentation.AirSentPresentationException;
34 import com.lutris.airsent.presentation.AirSentConstants;
35 import java.util.*;
36 import com.lutris.airsent.spec.address.*;
37 import com.lutris.airsent.spec.customer.Customer;
38 import com.lutris.airsent.spec.delivery.OrderForm;
39
40 /**
41  * Presentation object for order page 2
42  */

43 public class OrderPage2
44     extends BasePO {
45
46     /**
47      * Constants
48      */

49     private static final int AUTH_LEVEL = AirSentConstants.CUSTOMER_USER;
50
51     /**
52      * Superclass method override. returns the authorization
53      * level necessary to access this po.
54      *
55      * @return int required authorization level
56      */

57     public int getRequiredAuthLevel() {
58     return AUTH_LEVEL;
59     }
60
61     /**
62      * displays default page
63      *
64      * @return html page
65      * @exception if an error occurs
66      */

67     public XMLObject handleDefault()
68         throws HttpPresentationException {
69     try {
70             OrderForm orderForm = getSessionData().getOrderForm();
71             if (orderForm == null) {
72                 System.err.println("ERROR: no order form");
73                 throw new ClientPageRedirectException(AirSentConstants.ORDERSTEP1_PO);
74             }
75             return showPage2(null, orderForm);
76     } catch (Exception JavaDoc e) {
77         throw new AirSentPresentationException("System error finding user", e);
78     }
79     }
80
81     /**
82      * creates the html page
83      *
84      * @param errorMsg error message to display
85      * @param orderData data to populate the page with
86      * @exception if an error occurs
87      */

88     private XMLObject showPage2(String JavaDoc errorMsg, OrderForm orderForm)
89         throws AirSentPresentationException {
90     OrderStep2HTML page = (OrderStep2HTML) myComms.xmlcFactory.create(OrderStep2HTML.class);
91     try {
92         if (null != errorMsg || null != (errorMsg = getSessionData().getAndClearUserMessage())) {
93         page.setTextErrorText(errorMsg);
94         } else {
95         page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText());
96         }
97             if(orderForm.getOrderId() == null) {
98                 Node n = page.getElementNavPickup().getParentNode();
99                 n.removeChild(page.getElementNavPickup());
100                 n.removeChild(page.getElementNavDetails());
101             }
102             populatePage2(page, orderForm);
103     //We need to allow AirSent_pres to be functional , responsed will be default HTML page
104
}catch(NullPointerException JavaDoc e){
105            
106          OrderStep2HTML defaultPage = (OrderStep2HTML) myComms.xmlcFactory.create(OrderStep2HTML.class);
107       defaultPage.setTextErrorText("This is a default HTML page");
108     return defaultPage;
109     } catch (Exception JavaDoc e) {
110         throw new AirSentPresentationException("System error showing page 1", e);
111     }
112     return page;
113     }
114
115     /**
116      * populates the page
117      *
118      * @param page to populate
119      * @param orderData data to populate it with
120      * @exception if an error occurs
121      */

122     private void populatePage2(OrderStep2HTML page, OrderForm orderForm)
123         throws AirSentPresentationException {
124         
125         try {
126             if(orderForm.getOrderId() != null) {
127                 page.setTextOrderHeader("Order");
128                 page.setTextOrdernumber(orderForm.getOrderId());
129          page.getElementDropoffname().setValue(orderForm.getDropOffName());
130          page.getElementDropoffaddress().setValue(orderForm.getDropOffAddress1());
131          page.getElementDropoffphone().setValue(orderForm.getDropOffPhone());
132             }else {
133                 page.setTextOrdernumber("");
134             }
135             
136            // page.getElementDropoffname().setValue(orderForm.getDropOffName());
137
// page.getElementDropoffaddress().setValue(orderForm.getDropOffAddress1());
138
// page.getElementDropoffphone().setValue(orderForm.getDropOffPhone());
139
if (orderForm.getDropOffDirections() != null) {
140                 Text commentText = (page.getDocument()).createTextNode(orderForm.getDropOffDirections());
141                 page.getElementDropoffdirections().appendChild(commentText);
142             }
143         } catch (Exception JavaDoc e) {
144             throw new AirSentPresentationException("", e);
145         }
146     }
147
148     /**
149      * process the form submission
150      *
151      * @return html page
152      * @exception if an error occurs
153      */

154     public XMLObject handleOrder2()
155         throws AirSentPresentationException {
156     try {
157             String JavaDoc p;
158             OrderForm orderForm = getSessionData().getOrderForm();
159
160             p = this.getComms().request.getParameter(AirSentConstants.DROPOFF_NAME);
161         if (checkField(p, Address.MAX_NAME) == false) {
162         return showPage2("Please provide a drop off name", orderForm);
163         }
164             orderForm.setDropOffName(p);
165             
166             p = this.getComms().request.getParameter(AirSentConstants.DROPOFF_ADDRESS);
167         if (checkField(p, Address.MAX_ADDRESS) == false) {
168         return showPage2("Please provide a drop off address", orderForm);
169         }
170             orderForm.setDropOffAddress1(p);
171                 
172             p = this.getComms().request.getParameter(AirSentConstants.DROPOFF_PHONE);
173         if (checkField(p, Address.MAX_PHONE) == false) {
174         return showPage2("Please provide a drop off phone", orderForm);
175         }
176             orderForm.setDropOffPhone(p);
177
178             p = this.getComms().request.getParameter(AirSentConstants.DROPOFF_DIRECTIONS);
179         if (checkField(p, Address.MAX_DIRECTIONS) == false) {
180         return showPage2("Please provide a drop off directions", orderForm);
181         }
182             orderForm.setDropOffDirections(p);
183             
184             getSessionData().setOrderForm(orderForm);
185         throw new ClientPageRedirectException(AirSentConstants.ORDERSTEP3_PO);
186      }catch(NullPointerException JavaDoc e){
187            OrderStep3HTML defaultPage = (OrderStep3HTML) myComms.xmlcFactory.create(OrderStep3HTML.class);
188       defaultPage.setTextErrorText("This is a default HTML page");
189     return defaultPage;
190      
191     } catch (Exception JavaDoc e) {
192         throw new AirSentPresentationException("System error processing OrderStep2.", e);
193     }
194     }
195 }
196
197
198
199
Popular Tags