001: /*
002: * Copyright (c) 1999-2001 Lutris Technologies, Inc. All Rights
003: * Reserved.
004: *
005: * This source code file is distributed by Lutris Technologies, Inc. for
006: * use only by licensed users of product(s) that include this source
007: * file. Use of this source file or the software that uses it is covered
008: * by the terms and conditions of the Lutris Enhydra Development License
009: * Agreement included with this product.
010: *
011: * This Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
012: * ANY KIND, either express or implied. See the License for the specific terms
013: * governing rights and limitations under the License.
014: *
015: * Contributor(s):
016: *
017: * $Id: OrderPage2.java,v 1.1 2006-09-11 12:29:26 sinisa Exp $
018: */
019:
020: package com.lutris.airsent.presentation.customer;
021:
022: import com.lutris.airsent.presentation.BasePO;
023: import com.lutris.appserver.server.httpPresentation.*;
024: import com.lutris.appserver.server.session.*;
025: import com.lutris.util.*; //import com.lutris.xml.xmlc.*;
026: //import com.lutris.xml.xmlc.html.*;
027: import org.w3c.dom.*;
028: import org.w3c.dom.html.*;
029: import org.enhydra.xml.xmlc.XMLObject;
030: import com.lutris.airsent.spec.AirSentException;
031:
032: import com.lutris.airsent.presentation.AirSentPresentationException;
033: import com.lutris.airsent.presentation.AirSentConstants;
034: import java.util.*;
035: import com.lutris.airsent.spec.address.*;
036: import com.lutris.airsent.spec.customer.Customer;
037: import com.lutris.airsent.spec.delivery.OrderForm;
038:
039: /**
040: * Presentation object for order page 2
041: */
042: public class OrderPage2 extends BasePO {
043:
044: /**
045: * Constants
046: */
047: private static final int AUTH_LEVEL = AirSentConstants.CUSTOMER_USER;
048:
049: /**
050: * Superclass method override. returns the authorization
051: * level necessary to access this po.
052: *
053: * @return int required authorization level
054: */
055: public int getRequiredAuthLevel() {
056: return AUTH_LEVEL;
057: }
058:
059: /**
060: * displays default page
061: *
062: * @return html page
063: * @exception if an error occurs
064: */
065: public XMLObject handleDefault() throws HttpPresentationException {
066: try {
067: OrderForm orderForm = getSessionData().getOrderForm();
068: if (orderForm == null) {
069: System.err.println("ERROR: no order form");
070: throw new ClientPageRedirectException(
071: AirSentConstants.ORDERSTEP1_PO);
072: }
073: return showPage2(null, orderForm);
074: } catch (Exception e) {
075: throw new AirSentPresentationException(
076: "System error finding user", e);
077: }
078: }
079:
080: /**
081: * creates the html page
082: *
083: * @param errorMsg error message to display
084: * @param orderData data to populate the page with
085: * @exception if an error occurs
086: */
087: private XMLObject showPage2(String errorMsg, OrderForm orderForm)
088: throws AirSentPresentationException {
089: OrderStep2HTML page = (OrderStep2HTML) myComms.xmlcFactory
090: .create(OrderStep2HTML.class);
091: try {
092: if (null != errorMsg
093: || null != (errorMsg = getSessionData()
094: .getAndClearUserMessage())) {
095: page.setTextErrorText(errorMsg);
096: } else {
097: page.getElementErrorText().getParentNode().removeChild(
098: page.getElementErrorText());
099: }
100: if (orderForm.getOrderId() == null) {
101: Node n = page.getElementNavPickup().getParentNode();
102: n.removeChild(page.getElementNavPickup());
103: n.removeChild(page.getElementNavDetails());
104: }
105: populatePage2(page, orderForm);
106: //We need to allow AirSent_pres to be functional , responsed will be default HTML page
107: } catch (NullPointerException e) {
108:
109: OrderStep2HTML defaultPage = (OrderStep2HTML) myComms.xmlcFactory
110: .create(OrderStep2HTML.class);
111: defaultPage.setTextErrorText("This is a default HTML page");
112: return defaultPage;
113: } catch (Exception e) {
114: throw new AirSentPresentationException(
115: "System error showing page 1", e);
116: }
117: return page;
118: }
119:
120: /**
121: * populates the page
122: *
123: * @param page to populate
124: * @param orderData data to populate it with
125: * @exception if an error occurs
126: */
127: private void populatePage2(OrderStep2HTML page, OrderForm orderForm)
128: throws AirSentPresentationException {
129:
130: try {
131: if (orderForm.getOrderId() != null) {
132: page.setTextOrderHeader("Order");
133: page.setTextOrdernumber(orderForm.getOrderId());
134: page.getElementDropoffname().setValue(
135: orderForm.getDropOffName());
136: page.getElementDropoffaddress().setValue(
137: orderForm.getDropOffAddress1());
138: page.getElementDropoffphone().setValue(
139: orderForm.getDropOffPhone());
140: } else {
141: page.setTextOrdernumber("");
142: }
143:
144: // page.getElementDropoffname().setValue(orderForm.getDropOffName());
145: // page.getElementDropoffaddress().setValue(orderForm.getDropOffAddress1());
146: // page.getElementDropoffphone().setValue(orderForm.getDropOffPhone());
147: if (orderForm.getDropOffDirections() != null) {
148: Text commentText = (page.getDocument())
149: .createTextNode(orderForm
150: .getDropOffDirections());
151: page.getElementDropoffdirections().appendChild(
152: commentText);
153: }
154: } catch (Exception e) {
155: throw new AirSentPresentationException("", e);
156: }
157: }
158:
159: /**
160: * process the form submission
161: *
162: * @return html page
163: * @exception if an error occurs
164: */
165: public XMLObject handleOrder2() throws AirSentPresentationException {
166: try {
167: String p;
168: OrderForm orderForm = getSessionData().getOrderForm();
169:
170: p = this .getComms().request
171: .getParameter(AirSentConstants.DROPOFF_NAME);
172: if (checkField(p, Address.MAX_NAME) == false) {
173: return showPage2("Please provide a drop off name",
174: orderForm);
175: }
176: orderForm.setDropOffName(p);
177:
178: p = this .getComms().request
179: .getParameter(AirSentConstants.DROPOFF_ADDRESS);
180: if (checkField(p, Address.MAX_ADDRESS) == false) {
181: return showPage2("Please provide a drop off address",
182: orderForm);
183: }
184: orderForm.setDropOffAddress1(p);
185:
186: p = this .getComms().request
187: .getParameter(AirSentConstants.DROPOFF_PHONE);
188: if (checkField(p, Address.MAX_PHONE) == false) {
189: return showPage2("Please provide a drop off phone",
190: orderForm);
191: }
192: orderForm.setDropOffPhone(p);
193:
194: p = this .getComms().request
195: .getParameter(AirSentConstants.DROPOFF_DIRECTIONS);
196: if (checkField(p, Address.MAX_DIRECTIONS) == false) {
197: return showPage2(
198: "Please provide a drop off directions",
199: orderForm);
200: }
201: orderForm.setDropOffDirections(p);
202:
203: getSessionData().setOrderForm(orderForm);
204: throw new ClientPageRedirectException(
205: AirSentConstants.ORDERSTEP3_PO);
206: } catch (NullPointerException e) {
207: OrderStep3HTML defaultPage = (OrderStep3HTML) myComms.xmlcFactory
208: .create(OrderStep3HTML.class);
209: defaultPage.setTextErrorText("This is a default HTML page");
210: return defaultPage;
211:
212: } catch (Exception e) {
213: throw new AirSentPresentationException(
214: "System error processing OrderStep2.", e);
215: }
216: }
217: }
|