1 package phoneList.presentation; 2 3 import com.lutris.appserver.server.httpPresentation.*; 4 5 import phoneList.spec.*; 6 7 public class DoActionPresentation implements HttpPresentation { 8 9 public void run(HttpPresentationComms comms) throws Exception { 10 String first = null; 11 try { 12 first = comms.request.getParameter("first"); 13 } catch (Exception e) { 14 } 15 String last = null; 16 try { 17 last = comms.request.getParameter("last"); 18 } catch (Exception e) { 19 } 20 String phone = null; 21 try { 22 phone = comms.request.getParameter("phone"); 23 } catch (Exception e) { 24 } 25 String id = null; 26 try { 27 id = comms.request.getParameter("id"); 28 } catch (Exception e) { 29 } 30 String action = null; 31 try { 32 action = comms.request.getParameter("action"); 33 } catch (Exception e) { 34 } 35 36 PhoneList phoneList = PhoneListFactory.getPhoneList("phoneList.business.PhoneListImpl"); 37 String okTarget = comms.request.getAppFileURIPath("ListPresentation.po"); 38 String errTarget = comms.request.getAppFileURIPath("ErrorPresentation.po"); 39 ClientPageRedirectException err = 40 new ClientPageRedirectException(errTarget); 41 42 if (action.equals("delete")) { 43 if ((id == null) || (id.length() == 0)) { 44 err.addArgument("err", "Error: no id specified."); 45 throw err; 46 } 47 try{ 48 phoneList.deletePerson(id); 49 53 } catch(NullPointerException ex) { 54 err.addArgument("err", "Error: You cannot delete person while runing phoneBookClient_pres!"); 55 throw err; 56 } 57 } else if (action.equals("edit")) { 58 if ((id == null) || (id.length() == 0)) { 59 err.addArgument("err", "Error: no id specified."); 60 throw err; 61 } 62 if ((first == null) || (first.length() == 0)) { 63 err.addArgument("err", "Error: no first name specified."); 64 throw err; 65 } 66 if ((last == null) || (last.length() == 0)) { 67 err.addArgument("err", "Error: no last name specified."); 68 throw err; 69 } 70 if ((phone == null) || (phone.length() == 0)) { 71 err.addArgument("err", "Error: no phone number specified."); 72 throw err; 73 } 74 try{ 75 phoneList.modifyPerson(id, first, last, phone); 76 } catch(NullPointerException ex) { 78 err.addArgument("err", "Error: You cannot modify person while runing phoneBookClient_pres!"); 79 throw err; 80 } 81 82 } else if (action.equals("create")) { 83 if ((first == null) || (first.length() == 0)) { 84 err.addArgument("err", "Error: no first name specified."); 85 throw err; 86 } 87 if ((last == null) || (last.length() == 0)) { 88 err.addArgument("err", "Error: no last name specified."); 89 throw err; 90 } 91 if ((phone == null) || (phone.length() == 0)) { 92 err.addArgument("err", "Error: no phone number specified."); 93 throw err; 94 } 95 try{ 96 phoneList.addPerson(first, last, phone); 97 } catch(NullPointerException ex) { 99 err.addArgument("err", "Error: You cannot add person while runing phoneBookClient_pres!"); 100 throw err; 101 } 102 103 104 } else { 105 } 107 108 109 110 throw new ClientPageRedirectException(okTarget); 111 } 112 113 } 114 115 | Popular Tags |