1 package com.instantbank.collections.basicInfo.web; 2 3 import java.io.IOException; 4 import javax.servlet.RequestDispatcher; 5 import javax.servlet.ServletConfig; 6 import javax.servlet.ServletContext; 7 import javax.servlet.ServletException; 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletResponse; 11 import javax.servlet.http.HttpSession; 12 import com.instantbank.collections.basicInfo.ejb.BasicInfoServices; 13 import com.instantbank.collections.basicInfo.ejb.BasicInfoServicesHome; 14 import com.instantbank.collections.util.FilterChain; 15 import com.instantbank.collections.util.InstantbankException; 16 import com.instantbank.collections.util.ServiceLocator; 17 18 public class PhoneTypesMaintenanceController extends HttpServlet { 19 private String debug; 20 private BasicInfoServices services; 21 private HttpSession session; 22 private Long userId; 23 24 25 public void init(ServletConfig config) throws ServletException { 26 super.init(config); 27 try { 28 BasicInfoServicesHome home = (BasicInfoServicesHome) 29 ServiceLocator.instance().createEJB("BasicInfoServicesHome", BasicInfoServicesHome.class, false); 30 services = home.create(); 31 } 32 catch(Exception e) { 33 throw new ServletException(e); 34 } 35 } 36 37 38 public void doGet(HttpServletRequest request, HttpServletResponse response) throws 39 ServletException, IOException { 40 41 doPost(request, response); 42 } 43 44 45 public void doPost(HttpServletRequest request, HttpServletResponse response) throws 46 ServletException, IOException { 47 48 String action; 49 com.instantbank.collections.util.FilterChain chain; 50 51 try { 52 action = request.getParameter("action"); 53 session = request.getSession(false); 54 try { 55 56 chain = new com.instantbank.collections.util.FilterChain(true, getServletConfig().getServletContext()); 57 if(chain.processFilter(request, response)) { 58 return; 59 } 60 if(action.equals("initialize")) { 61 initialize(request, response); 62 } 63 else if(action.equals("save")) { 64 save(request, response); 65 } 66 else { 67 throw new InstantbankException("112001", "Action " + action + " not supported"); 68 } 69 } 70 catch(Exception e) { 71 throw new InstantbankException(e, "112002", "Failed to execute controller action " + action); 72 } 73 } 74 catch(InstantbankException e) { 75 session.setAttribute("Exception", e); 76 response.sendRedirect("../main_web/ControllerError.jsp?showTechnical=0"); 77 } 78 } 79 80 81 public String getServletInfo() { 82 return "com.instantbank.collections.basicInfo.web.PhoneTypesMaintenanceController Information"; 83 } 84 85 86 private void initialize(HttpServletRequest request, HttpServletResponse response) throws 87 ServletException, IOException, InstantbankException { 88 String xml; 89 90 xml = services.getPhoneTypes(); 91 ServletContext sc = getServletConfig().getServletContext(); 92 request.setAttribute("title", "Phone Types Maintenance"); 93 request.setAttribute("data", xml); 94 RequestDispatcher rd = sc.getRequestDispatcher("/basicInfo_web/PhoneTypesView.jsp"); 95 rd.forward(request, response); 96 } 97 98 99 private void save(HttpServletRequest request, HttpServletResponse response) throws 100 ServletException, IOException, InstantbankException { 101 String xml; 102 103 userId = (Long)session.getAttribute("userId"); 104 xml = request.getParameter("data"); 105 services.savePhoneTypes(userId, xml); 106 initialize(request, response); 107 } 108 } 109