1 18 19 20 package org.apache.struts.plugins; 21 22 23 import javax.servlet.ServletException ; 24 import org.apache.struts.action.ActionServlet; 25 import org.apache.struts.action.PlugIn; 26 import org.apache.struts.config.ForwardConfig; 27 import org.apache.struts.config.MessageResourcesConfig; 28 import org.apache.struts.config.ModuleConfig; 29 import org.apache.struts.config.PlugInConfig; 30 import org.apache.struts.util.RequestUtils; 31 32 33 48 49 public class ModuleConfigVerifier implements PlugIn { 50 51 52 54 55 58 protected ModuleConfig config = null; 59 60 61 64 protected ActionServlet servlet = null; 65 66 67 69 70 73 private boolean fatal = true; 74 75 76 79 public boolean isFatal() { 80 81 return (this.fatal); 82 83 } 84 85 86 91 public void setFatal(boolean fatal) { 92 93 this.fatal = fatal; 94 95 } 96 97 98 100 101 105 public void destroy() { 106 107 ; 109 } 110 111 112 public void init(ActionServlet servlet, ModuleConfig config) 114 throws ServletException { 115 116 this.servlet = servlet; 117 this.config = config; 118 boolean ok = true; 119 log(servlet.getInternal().getMessage("configVerifying")); 120 121 128 if (!verifyActionMappingClass()) { 129 ok = false; 130 } 131 145 if (!verifyForwardConfigs()) { 146 ok = false; 147 } 148 if (!verifyMessageResourcesConfigs()) { 149 ok = false; 150 } 151 if (!verifyPlugInConfigs()) { 152 ok = false; 153 } 154 155 log(servlet.getInternal().getMessage("configCompleted")); 157 if (!ok && isFatal()) { 158 throw new ServletException 159 (servlet.getInternal().getMessage("configFatal")); 160 } 161 162 163 } 164 165 166 167 169 170 176 protected void log(String message) { 177 178 String output = "[" + config.getPrefix() + "]: " + message; 179 servlet.log(output); 180 181 } 182 183 184 189 protected boolean verifyActionMappingClass() { 190 191 String amcName = config.getActionMappingClass(); 192 if (amcName == null) { 193 log(servlet.getInternal().getMessage 194 ("verifyActionMappingClass.missing")); 195 return (false); 196 } 197 try { 198 Class amcClass = RequestUtils.applicationClass(amcName); 199 } catch (ClassNotFoundException e) { 200 log(servlet.getInternal().getMessage 201 ("verifyActionMappingClass.invalid", amcName)); 202 return (false); 203 } 204 return (true); 205 206 } 207 208 209 214 protected boolean verifyForwardConfigs() { 215 216 boolean ok = true; 217 ForwardConfig fcs[] = config.findForwardConfigs(); 218 for (int i = 0; i < fcs.length; i++) { 219 String path = fcs[i].getPath(); 220 if (path == null) { 221 log(servlet.getInternal().getMessage 222 ("verifyForwardConfigs.missing", 223 fcs[i].getName())); 224 ok = false; 225 } else if (!path.startsWith("/")) { 226 log(servlet.getInternal().getMessage 227 ("verifyForwardConfigs.invalid", path, 228 fcs[i].getName())); 229 } 230 } 231 return (ok); 232 233 } 234 235 236 241 protected boolean verifyMessageResourcesConfigs() { 242 243 boolean ok = true; 244 MessageResourcesConfig mrcs[] = config.findMessageResourcesConfigs(); 245 for (int i = 0; i < mrcs.length; i++) { 246 String factory = mrcs[i].getFactory(); 247 if (factory == null) { 248 log(servlet.getInternal().getMessage 249 ("verifyMessageResourcesConfigs.missing")); 250 ok = false; 251 } else { 252 try { 253 Class clazz = RequestUtils.applicationClass(factory); 254 } catch (ClassNotFoundException e) { 255 log(servlet.getInternal().getMessage 256 ("verifyMessageResourcesConfigs.invalid", 257 factory)); 258 ok = false; 259 } 260 } 261 String key = mrcs[i].getKey(); 262 if (key == null) { 263 log(servlet.getInternal().getMessage 264 ("verifyMessageResourcesConfigs.key")); 265 } 266 } 267 return (ok); 268 269 } 270 271 272 277 protected boolean verifyPlugInConfigs() { 278 279 boolean ok = true; 280 PlugInConfig pics[] = config.findPlugInConfigs(); 281 for (int i = 0; i < pics.length; i++) { 282 String className = pics[i].getClassName(); 283 if (className == null) { 284 log(servlet.getInternal().getMessage 285 ("verifyPlugInConfigs.missing")); 286 ok = false; 287 } else { 288 try { 289 Class clazz = RequestUtils.applicationClass(className); 290 } catch (ClassNotFoundException e) { 291 log(servlet.getInternal().getMessage 292 ("verifyPlugInConfigs.invalid", className)); 293 ok = false; 294 } 295 } 296 } 297 return (ok); 298 299 } 300 301 302 } 303 | Popular Tags |