1
17 package org.apache.catalina.core;
18
19 import javax.servlet.http.HttpServletMapping;
20 import javax.servlet.http.MappingMatch;
21
22 import org.apache.catalina.mapper.MappingData;
23
24 public class ApplicationMapping {
25
26 private final MappingData mappingData;
27
28 private volatile HttpServletMapping mapping = null;
29
30 public ApplicationMapping(MappingData mappingData) {
31 this.mappingData = mappingData;
32 }
33
34 public HttpServletMapping getHttpServletMapping() {
35 if (mapping == null) {
36 String servletName;
37 if (mappingData.wrapper == null) {
38 servletName = "";
39 } else {
40 servletName = mappingData.wrapper.getName();
41 }
42 if (mappingData.matchType == null) {
43 mapping = new MappingImpl("", "", null, servletName);
44 } else {
45 switch (mappingData.matchType) {
46 case CONTEXT_ROOT:
47 mapping = new MappingImpl("", "", mappingData.matchType, servletName);
48 break;
49 case DEFAULT:
50 mapping = new MappingImpl("", "/", mappingData.matchType, servletName);
51 break;
52 case EXACT:
53 mapping = new MappingImpl(mappingData.wrapperPath.toString().substring(1),
54 mappingData.wrapperPath.toString(), mappingData.matchType, servletName);
55 break;
56 case EXTENSION:
57 String path = mappingData.wrapperPath.toString();
58 int extIndex = path.lastIndexOf('.');
59 mapping = new MappingImpl(path.substring(1, extIndex),
60 "*" + path.substring(extIndex), mappingData.matchType, servletName);
61 break;
62 case PATH:
63 String matchValue;
64 if (mappingData.pathInfo.isNull()) {
65 matchValue = null;
66 } else {
67 matchValue = mappingData.pathInfo.toString().substring(1);
68 }
69 mapping = new MappingImpl(matchValue, mappingData.wrapperPath.toString() + "/*",
70 mappingData.matchType, servletName);
71 break;
72 }
73 }
74 }
75
76 return mapping;
77 }
78
79 public void recycle() {
80 mapping = null;
81 }
82
83 private static class MappingImpl implements HttpServletMapping {
84
85 private final String matchValue;
86 private final String pattern;
87 private final MappingMatch mappingType;
88 private final String servletName;
89
90 public MappingImpl(String matchValue, String pattern, MappingMatch mappingType,
91 String servletName) {
92 this.matchValue = matchValue;
93 this.pattern = pattern;
94 this.mappingType = mappingType;
95 this.servletName = servletName;
96 }
97
98 @Override
99 public String getMatchValue() {
100 return matchValue;
101 }
102
103 @Override
104 public String getPattern() {
105 return pattern;
106 }
107
108 @Override
109 public MappingMatch getMappingMatch() {
110 return mappingType;
111 }
112
113 @Override
114 public String getServletName() {
115 return servletName;
116 }
117 }
118 }
119