1 17 package org.apache.geronimo.console.apache.jk; 18 19 import java.io.Serializable ; 20 import java.util.ArrayList ; 21 import java.util.List ; 22 import java.util.Map ; 23 import javax.portlet.ActionResponse; 24 import javax.portlet.PortletRequest; 25 import javax.portlet.PortletSession; 26 import org.apache.geronimo.console.MultiPageAbstractHandler; 27 import org.apache.geronimo.console.MultiPageModel; 28 import org.apache.geronimo.console.util.PortletManager; 29 import org.apache.geronimo.kernel.repository.Artifact; 30 import org.apache.geronimo.gbean.AbstractName; 31 32 37 public abstract class BaseApacheHandler extends MultiPageAbstractHandler { 38 protected static final String INDEX_MODE = "index"; 39 protected static final String BASIC_CONFIG_MODE = "basic"; 40 protected static final String AJP_MODE = "ajp"; 41 protected static final String WEB_APP_MODE = "webapp"; 42 protected static final String RESULTS_MODE = "results"; 43 44 protected BaseApacheHandler(String mode, String viewName) { 45 super(mode, viewName); 46 } 47 48 public final static class WebAppData implements Serializable { 49 private String parentConfigId; 50 private String childName; 51 private String moduleBeanName; 52 private boolean enabled; 53 private String dynamicPattern; 54 private boolean serveStaticContent; 55 private String contextRoot; 56 private String webAppDir; 57 58 public WebAppData(Artifact parentConfigId, String childName, AbstractName moduleBeanName, boolean enabled, String dynamicPattern, boolean serveStaticContent) { 59 this.parentConfigId = parentConfigId.toString(); 60 this.enabled = enabled; 61 this.dynamicPattern = dynamicPattern; 62 this.serveStaticContent = serveStaticContent; 63 this.moduleBeanName = moduleBeanName == null ? null : moduleBeanName.toString(); 64 this.childName = childName; 65 } 66 67 public WebAppData(PortletRequest request, String prefix) { 68 parentConfigId = request.getParameter(prefix+"configId"); 69 childName = request.getParameter(prefix+"childName"); 70 moduleBeanName = request.getParameter(prefix+"moduleBeanName"); 71 dynamicPattern = request.getParameter(prefix+"dynamicPattern"); 72 String test = request.getParameter(prefix+"enabled"); 73 enabled = test != null && !test.equals("") && !test.equals("false"); 74 test = request.getParameter(prefix+"serveStaticContent"); 75 serveStaticContent = test != null && !test.equals("") && !test.equals("false"); 76 contextRoot = request.getParameter(prefix+"contextRoot"); 77 webAppDir = request.getParameter(prefix+"webAppDir"); 78 } 79 80 public void save(ActionResponse response, String prefix) { 81 response.setRenderParameter(prefix+"configId", parentConfigId); 82 response.setRenderParameter(prefix+"moduleBeanName", moduleBeanName); 83 response.setRenderParameter(prefix+"dynamicPattern", dynamicPattern); 84 response.setRenderParameter(prefix+"enabled", Boolean.toString(enabled)); 85 response.setRenderParameter(prefix+"serveStaticContent", Boolean.toString(serveStaticContent)); 86 if(!isEmpty(contextRoot)) response.setRenderParameter(prefix+"contextRoot", contextRoot); 87 if(!isEmpty(webAppDir)) response.setRenderParameter(prefix+"webAppDir", webAppDir); 88 if(!isEmpty(childName)) response.setRenderParameter(prefix+"childName", childName); 89 } 90 91 public boolean isEnabled() { 92 return enabled; 93 } 94 95 public void setEnabled(boolean enabled) { 96 this.enabled = enabled; 97 } 98 99 public String getParentConfigId() { 100 return parentConfigId; 101 } 102 103 public void setParentConfigId(String parentConfigId) { 104 this.parentConfigId = parentConfigId; 105 } 106 107 public String getDynamicPattern() { 108 return dynamicPattern; 109 } 110 111 public void setDynamicPattern(String dynamicPattern) { 112 this.dynamicPattern = dynamicPattern; 113 } 114 115 public boolean isServeStaticContent() { 116 return serveStaticContent; 117 } 118 119 public void setServeStaticContent(boolean serveStaticContent) { 120 this.serveStaticContent = serveStaticContent; 121 } 122 123 public String getContextRoot() { 124 return contextRoot; 125 } 126 127 public void setContextRoot(String contextRoot) { 128 this.contextRoot = contextRoot; 129 } 130 131 public String getWebAppDir() { 132 return webAppDir; 133 } 134 135 public void setWebAppDir(String webAppDir) { 136 this.webAppDir = webAppDir; 137 } 138 139 public String getChildName() { 140 return childName; 141 } 142 143 public String getModuleBeanName() { 144 return moduleBeanName; 145 } 146 147 public String getName() { 148 return isEmpty(childName) ? parentConfigId : childName; 149 } 150 151 public boolean isRunning() { 152 return webAppDir != null; 153 } 154 } 155 156 public final static class ApacheModel implements MultiPageModel { 157 public final static String WEB_APP_SESSION_KEY = "console.apache.jk.WebApps"; 158 private String os; 159 private Integer addAjpPort; 160 private String logFilePath; 161 private String workersPath; 162 private List webApps = new ArrayList (); 163 164 public ApacheModel(PortletRequest request) { 165 Map map = request.getParameterMap(); 166 os = request.getParameter("os"); 167 logFilePath = request.getParameter("logFilePath"); 168 if(logFilePath == null) { 169 logFilePath = PortletManager.getCurrentServer(request).getServerInfo().resolve("var/log/apache_mod_jk.log").getPath(); 170 } 171 workersPath = request.getParameter("workersPath"); 172 if(workersPath == null) { 173 workersPath = PortletManager.getCurrentServer(request).getServerInfo().resolve("var/config/workers.properties").getPath(); 174 } 175 String ajp = request.getParameter("addAjpPort"); 176 if(!isEmpty(ajp)) addAjpPort = new Integer (ajp); 177 int index = 0; 178 boolean found = false; 179 while(true) { 180 String key = "webapp."+(index++)+"."; 181 if(!map.containsKey(key+"configId")) { 182 break; 183 } 184 found = true; 185 WebAppData data = new WebAppData(request, key); 186 webApps.add(data); 187 } 188 if(!found) { 189 List list = (List ) request.getPortletSession(true).getAttribute(WEB_APP_SESSION_KEY); 190 if(list != null) { 191 webApps = list; 192 } 193 } 194 } 195 196 public void save(ActionResponse response, PortletSession session) { 197 if(!isEmpty(os)) response.setRenderParameter("os", os); 198 if(!isEmpty(logFilePath)) response.setRenderParameter("logFilePath", logFilePath); 199 if(!isEmpty(workersPath)) response.setRenderParameter("workersPath", workersPath); 200 if(addAjpPort != null) response.setRenderParameter("addAjpPort", addAjpPort.toString()); 201 if(webApps.size() > 0) { 202 session.setAttribute(WEB_APP_SESSION_KEY, webApps); 203 } 204 } 205 206 public String getOs() { 207 return os; 208 } 209 210 public void setOs(String os) { 211 this.os = os; 212 } 213 214 public Integer getAddAjpPort() { 215 return addAjpPort; 216 } 217 218 public void setAddAjpPort(Integer addAjpPort) { 219 this.addAjpPort = addAjpPort; 220 } 221 222 public String getLogFilePath() { 223 return logFilePath; 224 } 225 226 public void setLogFilePath(String logFilePath) { 227 this.logFilePath = logFilePath; 228 } 229 230 public String getWorkersPath() { 231 return workersPath; 232 } 233 234 public void setWorkersPath(String workersPath) { 235 this.workersPath = workersPath; 236 } 237 238 public List getWebApps() { 239 return webApps; 240 } 241 242 public void setWebApps(List webApps) { 243 this.webApps = webApps; 244 } 245 } 246 } 247 | Popular Tags |