1 17 18 19 package org.apache.catalina.deploy; 20 21 22 import org.apache.catalina.util.RequestUtil; 23 import java.io.Serializable ; 24 25 26 35 36 public class FilterMap implements Serializable { 37 38 39 41 42 46 47 public static final int ERROR = 1; 48 public static final int FORWARD = 2; 49 public static final int FORWARD_ERROR =3; 50 public static final int INCLUDE = 4; 51 public static final int INCLUDE_ERROR = 5; 52 public static final int INCLUDE_ERROR_FORWARD =6; 53 public static final int INCLUDE_FORWARD = 7; 54 public static final int REQUEST = 8; 55 public static final int REQUEST_ERROR = 9; 56 public static final int REQUEST_ERROR_FORWARD = 10; 57 public static final int REQUEST_ERROR_FORWARD_INCLUDE = 11; 58 public static final int REQUEST_ERROR_INCLUDE = 12; 59 public static final int REQUEST_FORWARD = 13; 60 public static final int REQUEST_INCLUDE = 14; 61 public static final int REQUEST_FORWARD_INCLUDE= 15; 62 63 private static final int NOT_SET = -1; 66 67 private int dispatcherMapping=NOT_SET; 68 69 private String filterName = null; 70 71 public String getFilterName() { 72 return (this.filterName); 73 } 74 75 public void setFilterName(String filterName) { 76 this.filterName = filterName; 77 } 78 79 80 83 private String [] servletNames = new String [0]; 84 85 public String [] getServletNames() { 86 return (this.servletNames); 87 } 88 89 public void addServletName(String servletName) { 90 String [] results = new String [servletNames.length + 1]; 91 System.arraycopy(servletNames, 0, results, 0, servletNames.length); 92 results[servletNames.length] = servletName; 93 servletNames = results; 94 } 95 96 97 100 private boolean allMatch = false; 101 102 public boolean getAllMatch() { 103 return allMatch; 104 } 105 106 107 110 private String [] urlPatterns = new String [0]; 111 112 public String [] getURLPatterns() { 113 return (this.urlPatterns); 114 } 115 116 public void addURLPattern(String urlPattern) { 117 if ("*".equals(urlPattern)) { 118 this.allMatch = true; 119 } else { 120 String [] results = new String [urlPatterns.length + 1]; 121 System.arraycopy(urlPatterns, 0, results, 0, urlPatterns.length); 122 results[urlPatterns.length] = RequestUtil.URLDecode(urlPattern); 123 urlPatterns = results; 124 } 125 } 126 127 147 public void setDispatcher(String dispatcherString) { 148 String dispatcher = dispatcherString.toUpperCase(); 149 150 if (dispatcher.equals("FORWARD")) { 151 152 switch (dispatcherMapping) { 154 case NOT_SET : dispatcherMapping = FORWARD; break; 155 case ERROR : dispatcherMapping = FORWARD_ERROR; break; 156 case INCLUDE : dispatcherMapping = INCLUDE_FORWARD; break; 157 case INCLUDE_ERROR : dispatcherMapping = INCLUDE_ERROR_FORWARD; break; 158 case REQUEST : dispatcherMapping = REQUEST_FORWARD; break; 159 case REQUEST_ERROR : dispatcherMapping = REQUEST_ERROR_FORWARD; break; 160 case REQUEST_ERROR_INCLUDE : dispatcherMapping = REQUEST_ERROR_FORWARD_INCLUDE; break; 161 case REQUEST_INCLUDE : dispatcherMapping = REQUEST_FORWARD_INCLUDE; break; 162 } 163 } else if (dispatcher.equals("INCLUDE")) { 164 switch (dispatcherMapping) { 166 case NOT_SET : dispatcherMapping = INCLUDE; break; 167 case ERROR : dispatcherMapping = INCLUDE_ERROR; break; 168 case FORWARD : dispatcherMapping = INCLUDE_FORWARD; break; 169 case FORWARD_ERROR : dispatcherMapping = INCLUDE_ERROR_FORWARD; break; 170 case REQUEST : dispatcherMapping = REQUEST_INCLUDE; break; 171 case REQUEST_ERROR : dispatcherMapping = REQUEST_ERROR_INCLUDE; break; 172 case REQUEST_ERROR_FORWARD : dispatcherMapping = REQUEST_ERROR_FORWARD_INCLUDE; break; 173 case REQUEST_FORWARD : dispatcherMapping = REQUEST_FORWARD_INCLUDE; break; 174 } 175 } else if (dispatcher.equals("REQUEST")) { 176 switch (dispatcherMapping) { 178 case NOT_SET : dispatcherMapping = REQUEST; break; 179 case ERROR : dispatcherMapping = REQUEST_ERROR; break; 180 case FORWARD : dispatcherMapping = REQUEST_FORWARD; break; 181 case FORWARD_ERROR : dispatcherMapping = REQUEST_ERROR_FORWARD; break; 182 case INCLUDE : dispatcherMapping = REQUEST_INCLUDE; break; 183 case INCLUDE_ERROR : dispatcherMapping = REQUEST_ERROR_INCLUDE; break; 184 case INCLUDE_FORWARD : dispatcherMapping = REQUEST_FORWARD_INCLUDE; break; 185 case INCLUDE_ERROR_FORWARD : dispatcherMapping = REQUEST_ERROR_FORWARD_INCLUDE; break; 186 } 187 } else if (dispatcher.equals("ERROR")) { 188 switch (dispatcherMapping) { 190 case NOT_SET : dispatcherMapping = ERROR; break; 191 case FORWARD : dispatcherMapping = FORWARD_ERROR; break; 192 case INCLUDE : dispatcherMapping = INCLUDE_ERROR; break; 193 case INCLUDE_FORWARD : dispatcherMapping = INCLUDE_ERROR_FORWARD; break; 194 case REQUEST : dispatcherMapping = REQUEST_ERROR; break; 195 case REQUEST_INCLUDE : dispatcherMapping = REQUEST_ERROR_INCLUDE; break; 196 case REQUEST_FORWARD : dispatcherMapping = REQUEST_ERROR_FORWARD; break; 197 case REQUEST_FORWARD_INCLUDE : dispatcherMapping = REQUEST_ERROR_FORWARD_INCLUDE; break; 198 } 199 } 200 } 201 202 public int getDispatcherMapping() { 203 if (dispatcherMapping == NOT_SET) return REQUEST; 206 else return dispatcherMapping; 207 } 208 209 210 212 213 216 public String toString() { 217 218 StringBuffer sb = new StringBuffer ("FilterMap["); 219 sb.append("filterName="); 220 sb.append(this.filterName); 221 for (int i = 0; i < servletNames.length; i++) { 222 sb.append(", servletName="); 223 sb.append(servletNames[i]); 224 } 225 for (int i = 0; i < urlPatterns.length; i++) { 226 sb.append(", urlPattern="); 227 sb.append(urlPatterns[i]); 228 } 229 sb.append("]"); 230 return (sb.toString()); 231 232 } 233 234 235 } 236 | Popular Tags |