KickJava   Java API By Example, From Geeks To Geeks.

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


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: OrderPage4.java,v 1.1 2004/08/16 09:33:18 slobodan Exp $
18  */

19
20 package com.lutris.airsent.presentation.customer;
21 import com.lutris.airsent.spec.AirSentException;
22 import com.lutris.airsent.presentation.*;
23
24
25 import com.lutris.airsent.spec.customer.Customer;
26 import com.lutris.airsent.spec.delivery.*;
27 import com.lutris.airsent.spec.*;
28
29 import com.lutris.appserver.server.httpPresentation.*;
30 import com.lutris.util.*;
31 //import com.lutris.xml.xmlc.*;
32
//import com.lutris.xml.xmlc.html.*;
33
import org.w3c.dom.*;
34 import org.w3c.dom.html.*;
35 import org.enhydra.xml.xmlc.XMLObject;
36 import java.util.*;
37
38 /**
39  * Presentation object for order page 4
40  */

41 public class OrderPage4
42     extends BasePO {
43
44     /**
45      * Constants
46      */

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

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

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

87     private XMLObject showPage4(String JavaDoc errorMsg, OrderForm orderForm)
88         throws AirSentPresentationException {
89
90         ConfirmationHTML page = (ConfirmationHTML) myComms.xmlcFactory.create(ConfirmationHTML.class);
91     if (null != errorMsg || null != (errorMsg = getSessionData().getAndClearUserMessage())) {
92         page.setTextErrorText(errorMsg);
93     } else {
94         page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText());
95     }
96
97     try {
98         page.setTextPickupname(orderForm.getPickUpName());
99         page.setTextPickupaddress(orderForm.getPickUpAddress1());
100         page.setTextPickupphone(orderForm.getPickUpPhone());
101         page.setTextDropoffname(orderForm.getDropOffName());
102         page.setTextDropoffaddress(orderForm.getDropOffAddress1());
103         page.setTextDropoffphone(orderForm.getDropOffPhone());
104             
105         if (orderForm.getUrgent() == true) {
106         page.getElementPickupurgent().setSrc(AirSentConstants.URGENT_IMAGE);
107         page.getElementDropoffurgent().setSrc(AirSentConstants.URGENT_IMAGE);
108         } else {
109         page.getElementPickupurgent().setSrc(AirSentConstants.BLANK_IMAGE);
110         page.getElementDropoffurgent().setSrc(AirSentConstants.BLANK_IMAGE);
111         }
112         
113         
114         if (orderForm.getFragile() == true) {
115         page.getElementPickupfragile().setSrc(AirSentConstants.URGENT_IMAGE);
116         page.getElementDropofffragile().setSrc(AirSentConstants.URGENT_IMAGE);
117         } else {
118         page.getElementPickupfragile().setSrc(AirSentConstants.BLANK_IMAGE);
119         page.getElementDropofffragile().setSrc(AirSentConstants.BLANK_IMAGE);
120         }
121         page.setTextPickupdescription(orderForm.getDescription());
122         page.setTextDropoffdescription(orderForm.getDescription());
123          
124         
125         
126     //We need to allow AirSent_pres to be functional , responsed will be default HTML page
127
}catch(NullPointerException JavaDoc e){
128            
129          ConfirmationHTML defaultPage = (ConfirmationHTML) myComms.xmlcFactory.create(ConfirmationHTML.class);
130       defaultPage.setTextErrorText("This is a default HTML page");
131     return defaultPage;
132     } catch (Exception JavaDoc ex) {
133         throw new AirSentPresentationException("Error in confimation", ex);
134     }
135     return page;
136     }
137
138     /**
139      * process the form submission
140      *
141      * @return html page
142      * @exception if an error occurs
143      */

144     public XMLObject handleOrder4()
145         throws AirSentPresentationException {
146     try {
147             OrderForm orderForm = getSessionData().getOrderForm();
148             if (orderForm == null) {
149                 System.err.println("ERROR: no order form");
150                 throw new ClientPageRedirectException(AirSentConstants.ORDERSTEP1_PO);
151             }
152             Customer customer = getSessionData().getCustomer();
153             HomeManager hf = getApplication().getHomeManager();
154             DeliveryManager df = hf.getDeliveryManager();
155             Delivery delivery = df.create(customer, orderForm);
156             delivery.save();
157             if (orderForm.getOrderId() == null) {
158                 getSessionData().setUserMessage("Thanks for your order! Your order # is:" + delivery.getHandle());
159             } else {
160                 getSessionData().setUserMessage("Your changes to order #:" + delivery.getHandle() + " have been saved.");
161             }
162             getSessionData().setOrderForm(null);
163             throw new ClientPageRedirectException(AirSentConstants.ORDERSTEP1_PO);
164         //We need to allow AirSent_pres to be functional , responsed will be default HTML page
165
}catch(NullPointerException JavaDoc e){
166          throw new ClientPageRedirectException(AirSentConstants.ORDERSTEP1_PO);
167   
168         } catch (AirSentException ex) {
169             throw new AirSentPresentationException("Exception logging in order: ", ex);
170         }
171     }
172
173     /**
174      * process the cancel event
175      *
176      * @return html page
177      * @exception if an error occurs
178      */

179     public XMLObject handleCancel() {
180         getSessionData().setOrderForm(null);
181         throw new ClientPageRedirectException(AirSentConstants.ORDERSTEP1_PO);
182     }
183 }
184
185
186
187
Popular Tags