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.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 45 public class OrderPage3 46 extends BasePO { 47 48 private static final int AUTH_LEVEL = AirSentConstants.CUSTOMER_USER; 49 50 56 public int getRequiredAuthLevel() { 57 return AUTH_LEVEL; 58 } 59 60 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 e) { 78 throw new AirSentPresentationException("System error finding user", e); 79 } 80 } 81 82 89 private XMLObject showPage3(String 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 }catch(NullPointerException 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 e) { 112 throw new AirSentPresentationException("System error finding user", e); 113 } 114 return page; 115 } 116 117 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 e) { 140 throw new AirSentPresentationException("", e); 141 } 142 } 143 144 150 public XMLObject handleOrder3() 151 throws AirSentPresentationException { 152 153 try { 154 String 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 }catch(NullPointerException 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 e) { 192 throw new AirSentPresentationException("System error processing OrderStep1.", e); 193 } 194 } 195 196 199 private boolean isNumber(String n) { 200 if (n == null) { 201 return false; 202 } 203 try { 204 Integer i = Integer.valueOf(n); 205 } catch (NumberFormatException e) { 206 return false; 207 } 208 return true; 209 } 210 } 211 212 213 214 | Popular Tags |