1 20 package org.openi.web.controller.admin; 21 22 import org.apache.log4j.Logger; 23 import org.openi.application.Application; 24 import org.openi.xml.BeanStorage; 25 import org.springframework.validation.BindException; 26 import org.springframework.web.servlet.ModelAndView; 27 import org.springframework.web.servlet.mvc.SimpleFormController; 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 31 32 45 public class ApplicationFormController extends SimpleFormController { 46 private static Logger logger = Logger.getLogger(ApplicationFormController.class); 47 48 54 protected Object formBackingObject(HttpServletRequest request) 55 throws Exception { 56 try { 57 new BeanStorage().restoreBeanFromFile(getApplicationConfigPath(), 58 Application.getInstance()); 59 60 return Application.getInstance(); 61 } catch (Exception e) { 62 logger.error("Exception:", e); 63 throw e; 64 } 65 } 66 67 75 protected void onBindAndValidate(HttpServletRequest request, 76 Object command, BindException errors) throws Exception { 77 if (request.getParameter("basicAuthentication") == null) { 78 Application.getInstance().setBasicAuthentication(false); 79 } else { 80 Application.getInstance().setBasicAuthentication(true); 81 } 82 83 if(request.getParameter("sql2005Compatiblilty") == null ) { 84 Application.getInstance().setSql2005Compatiblilty(false); 85 } else { 86 Application.getInstance().setSql2005Compatiblilty(true); 87 } 88 } 89 90 100 protected ModelAndView onSubmit(HttpServletRequest request, 101 HttpServletResponse response, Object command, BindException errors) 102 throws Exception { 103 try { 104 if (request.getParameter("save") != null) { 105 new BeanStorage().saveBeanToFile(getApplicationConfigPath(), 106 command); 107 108 if(!Application.getInstance().isSql2005Compatiblilty() ) { 109 System.setProperty("javax.xml.soap.SOAPConnectionFactory","com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnectionFactory"); 110 } else { 111 System.setProperty("javax.xml.soap.SOAPConnectionFactory","org.openi.soap.client.HttpSOAPConnectionFactory"); 112 } 113 114 this.getServletContext() 116 .setAttribute("application", (Application) command); 117 } 118 119 return super.onSubmit(request, response, command, errors); 120 } catch (Exception e) { 121 logger.error("Exception:", e); 122 throw e; 123 } 124 } 125 126 130 private String getApplicationConfigPath() { 131 String appPath = this.getServletContext().getRealPath("/"); 133 134 if ((appPath.charAt(appPath.length() - 1) == '\\') 136 || (appPath.charAt(appPath.length() - 1) == '/')) { 137 appPath = appPath.substring(0, appPath.length() - 1); 138 } 139 140 String appConfigPath = appPath + "-projects/WEB-INF/application.xml"; 141 142 logger.info("app config path:" + appConfigPath); 143 144 return appConfigPath; 145 } 146 } 147 | Popular Tags |