KickJava   Java API By Example, From Geeks To Geeks.

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


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

45 public class OrderPage3
46     extends BasePO {
47
48     private static final int AUTH_LEVEL = AirSentConstants.CUSTOMER_USER;
49
50     /**
51      * Superclass method override. returns the authorization
52      * level necessary to access this po.
53      *
54      * @return int required authorization level
55      */

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

66     public XMLObject handleDefault()
67         throws HttpPresentationException {
68
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             
76             return showPage3(null, orderForm);
77     } catch (Exception JavaDoc e) {
78         throw new AirSentPresentationException("System error finding user", e);
79     }
80     }
81
82     /**
83      * creates the html page
84      *
85      * @param errorMsg error message to display
86      * @param orderData data to populate the page with
87      * @exception if an error occurs
88      */

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

124     private void populatePage3(OrderStep3HTML page, OrderForm orderForm)
125         throws AirSentPresentationException {
126         
127         try {
128             if(orderForm.getFragile() == true) {
129                 page.getElementFragile().setChecked(true);
130             }
131             if(orderForm.getUrgent() == true) {
132                 page.getElementUrgent().setChecked(true);
133             }
134             page.getElementSize().setValue(orderForm.getSize());
135             if (orderForm.getDescription() != null) {
136                 Text commentText = (page.getDocument()).createTextNode(orderForm.getDescription());
137                 page.getElementDescription().appendChild(commentText);
138             }
139         } catch (Exception JavaDoc e) {
140             throw new AirSentPresentationException("", e);
141         }
142     }
143
144     /**
145      * process the form submission
146      *
147      * @return html page
148      * @exception if an error occurs
149      */

150     public XMLObject handleOrder3()
151         throws AirSentPresentationException {
152
153     try {
154             String JavaDoc p;
155             OrderForm orderForm = getSessionData().getOrderForm();
156
157             p = this.getComms().request.getParameter(AirSentConstants.FRAGILE);
158             if (!isNullField(p)) {
159                 orderForm.setFragile(true);
160         } else {
161                 orderForm.setFragile(false);
162         }
163
164             p = this.getComms().request.getParameter(AirSentConstants.URGENT);
165         if (!isNullField(p)) {
166                 orderForm.setUrgent(true);
167         } else {
168                 orderForm.setUrgent(false);
169         }
170
171             p = this.getComms().request.getParameter(AirSentConstants.DESCRIPTION);
172         if (checkField(p, Delivery.MAX_DESC) == false) {
173         return showPage3("Please provide a description.", orderForm);
174         }
175             orderForm.setDescription(p);
176
177             p = this.getComms().request.getParameter(AirSentConstants.SIZE);
178         if (checkField(p, Delivery.MAX_SIZE) == false) {
179         return showPage3("Please enter a valid size.", orderForm);
180         }
181             orderForm.setSize(p);
182             
183             getSessionData().setOrderForm(orderForm);
184         throw new ClientPageRedirectException(AirSentConstants.CONFIRMATION_PO);
185     //We need to allow AirSent_pres to be functional , responsed will be default HTML page
186
}catch(NullPointerException JavaDoc e){
187        ConfirmationHTML defaultPage = (ConfirmationHTML) myComms.xmlcFactory.create(ConfirmationHTML.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 OrderStep1.", e);
193     }
194     }
195
196     /*
197      * check to see if a string is a number
198      */

199     private boolean isNumber(String JavaDoc n) {
200         if (n == null) {
201             return false;
202         }
203         try {
204             Integer JavaDoc i = Integer.valueOf(n);
205         } catch (NumberFormatException JavaDoc e) {
206             return false;
207         }
208         return true;
209     }
210 }
211
212
213
214
Popular Tags