1 28 29 package com.caucho.server.dispatch; 30 31 import com.caucho.config.BuilderProgram; 32 import com.caucho.config.BuilderProgramContainer; 33 import com.caucho.config.ConfigELContext; 34 import com.caucho.config.types.RawString; 35 import com.caucho.el.EL; 36 import com.caucho.util.L10N; 37 38 import javax.el.ELContext; 39 import javax.servlet.ServletContext ; 40 import javax.servlet.ServletException ; 41 import java.util.ArrayList ; 42 import java.util.HashMap ; 43 44 47 public class ServletRegexp { 48 private static final L10N L = new L10N(ServletRegexp.class); 49 50 private String _urlRegexp; 51 52 private String _servletName; 53 private String _servletClassName; 54 55 private BuilderProgramContainer _program = new BuilderProgramContainer(); 57 58 61 public ServletRegexp() 62 { 63 } 64 65 68 public void setURLRegexp(String pattern) 69 { 70 _urlRegexp = pattern; 71 } 72 73 76 public String getURLRegexp() 77 { 78 return _urlRegexp; 79 } 80 81 84 public void setServletName(RawString string) 85 { 86 _servletName = string.getValue(); 87 } 88 89 92 public String getServletName() 93 { 94 return _servletName; 95 } 96 97 100 public void setServletClass(RawString string) 101 { 102 _servletClassName = string.getValue(); 103 } 104 105 108 public String getServletClass() 109 { 110 return _servletClassName; 111 } 112 113 116 public void addBuilderProgram(BuilderProgram program) 117 { 118 _program.addProgram(program); 119 } 120 121 124 public BuilderProgram getBuilderProgram() 125 { 126 return _program; 127 } 128 129 132 String initRegexp(ServletContext application, 133 ServletManager manager, 134 ArrayList <String > vars) 135 throws ServletException 136 { 137 ELContext env = EL.getEnvironment(); 138 139 HashMap <String ,Object > map = new HashMap <String ,Object >(); 140 map.put("regexp", vars); 141 142 ELContext mapEnv = new ConfigELContext(map); 143 144 String rawName = _servletName; 145 String rawClassName = _servletClassName; 146 147 if (rawName == null) 148 rawName = rawClassName; 149 150 try { 151 String servletName = EL.evalString(rawName, mapEnv); 152 153 if (manager.getServletConfig(servletName) != null) 154 return servletName; 155 156 String className = EL.evalString(rawClassName, mapEnv); 157 158 ServletConfigImpl config = new ServletConfigImpl(); 159 160 config.setServletName(servletName); 161 config.setServletClass(className); 162 config.setServletContext(application); 163 164 _program.configure(config); 165 166 config.init(); 167 168 manager.addServlet(config); 169 170 return servletName; 171 } catch (RuntimeException e) { 172 throw e; 173 } catch (ServletException e) { 174 throw e; 175 } catch (Throwable e) { 176 throw new ServletException (e); 177 } 178 } 179 180 183 public String toString() 184 { 185 return "ServletRegexp[" + _urlRegexp + "]"; 186 } 187 } 188 | Popular Tags |