1 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 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 43 public class OrderPage2 44 extends BasePO { 45 46 49 private static final int AUTH_LEVEL = AirSentConstants.CUSTOMER_USER; 50 51 57 public int getRequiredAuthLevel() { 58 return AUTH_LEVEL; 59 } 60 61 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 e) { 77 throw new AirSentPresentationException("System error finding user", e); 78 } 79 } 80 81 88 private XMLObject showPage2(String 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 }catch(NullPointerException 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 e) { 110 throw new AirSentPresentationException("System error showing page 1", e); 111 } 112 return page; 113 } 114 115 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 if (orderForm.getDropOffDirections() != null) { 140 Text commentText = (page.getDocument()).createTextNode(orderForm.getDropOffDirections()); 141 page.getElementDropoffdirections().appendChild(commentText); 142 } 143 } catch (Exception e) { 144 throw new AirSentPresentationException("", e); 145 } 146 } 147 148 154 public XMLObject handleOrder2() 155 throws AirSentPresentationException { 156 try { 157 String 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 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 e) { 192 throw new AirSentPresentationException("System error processing OrderStep2.", e); 193 } 194 } 195 } 196 197 198 199 | Popular Tags |