1 16 package org.mortbay.jetty.servlet; 17 18 import org.apache.commons.logging.Log; 19 import org.mortbay.log.LogFactory; 20 import org.mortbay.http.ContextLoader; 21 import org.mortbay.jetty.servlet.WebApplicationContext.Configuration; 22 import org.mortbay.util.Resource; 23 import org.mortbay.xml.XmlConfiguration; 24 25 26 34 public class JettyWebConfiguration implements Configuration 35 { 36 private static Log log= LogFactory.getLog(JettyWebConfiguration.class); 37 private WebApplicationContext _context; 38 39 40 43 public void setWebApplicationContext (WebApplicationContext context) 44 { 45 _context = context; 46 } 47 48 public WebApplicationContext getWebApplicationContext () 49 { 50 return _context; 51 } 52 53 57 public void configureClassPath () throws Exception 58 { 59 } 60 61 65 public void configureDefaults () throws Exception 66 { 67 } 68 69 73 public void configureWebApp () throws Exception 74 { 75 if (_context.isStarted()) 77 { 78 if (log.isDebugEnabled()){log.debug("Cannot configure webapp after it is started");}; 79 return; 80 } 81 82 if(log.isDebugEnabled()) 83 log.debug("Configuring web-jetty.xml"); 84 85 Resource webInf=getWebApplicationContext().getWebInf(); 86 if(webInf!=null&&webInf.isDirectory()) 88 { 89 Resource jetty=webInf.addPath("web-jetty.xml"); 91 if(!jetty.exists()) 92 jetty=webInf.addPath("jetty-web.xml"); 93 if(!getWebApplicationContext().isIgnoreWebJetty()&&jetty.exists()) 94 { 95 96 String [] old_server_classes = _context.getServerClasses(); 98 String [] server_classes = new String [1+(old_server_classes==null?0:old_server_classes.length)]; 99 server_classes[0]="-org.mortbay."; 100 if (server_classes!=null) 101 System.arraycopy(old_server_classes, 0, server_classes, 1, old_server_classes.length); 102 103 try 104 { 105 _context.setServerClasses(server_classes); 106 if(log.isDebugEnabled()) 107 log.debug("Configure: "+jetty); 108 109 XmlConfiguration jetty_config=new XmlConfiguration(jetty.getURL()); 110 jetty_config.configure(getWebApplicationContext()); 111 } 112 finally 113 { 114 if (_context.getServerClasses()==server_classes) 115 _context.setServerClasses(old_server_classes); 116 } 117 } 118 } 119 120 } 121 } 122 | Popular Tags |