1
18
19 package io.undertow.servlet.handlers;
20
21 import javax.servlet.http.MappingMatch;
22
23
26 public class ServletPathMatch {
27
28 private final String matched;
29 private final String remaining;
30 private final boolean requiredWelcomeFileMatch;
31 private final ServletChain servletChain;
32 private final String rewriteLocation;
33 private final Type type;
34
35 public ServletPathMatch(final ServletChain target, final String uri, boolean requiredWelcomeFileMatch) {
36 this.servletChain = target;
37 this.requiredWelcomeFileMatch = requiredWelcomeFileMatch;
38 this.type = Type.NORMAL;
39 this.rewriteLocation = null;
40 if (target.getServletPath() == null) {
41
42 this.matched = uri;
43 this.remaining = null;
44 } else {
45 this.matched = target.getServletPath();
46 if(uri.length() == matched.length()) {
47 remaining = null;
48 } else {
49 remaining = uri.substring(matched.length());
50 }
51 }
52 }
53
54 public ServletPathMatch(final ServletChain target, final String matched, final String remaining, final Type type, final String rewriteLocation) {
55 this.servletChain = target;
56 this.matched = matched;
57 this.remaining = remaining;
58 this.requiredWelcomeFileMatch = false;
59 this.type = type;
60 this.rewriteLocation = rewriteLocation;
61 }
62
63 public String getMatched() {
64 return matched;
65 }
66
67 public String getRemaining() {
68 return remaining;
69 }
70
71 public boolean isRequiredWelcomeFileMatch() {
72 return requiredWelcomeFileMatch;
73 }
74
75 public ServletChain getServletChain() {
76 return servletChain;
77 }
78
79 public String getRewriteLocation() {
80 return rewriteLocation;
81 }
82
83 public Type getType() {
84 return type;
85 }
86
87 public String getMatchString() {
88 return servletChain.getPattern();
89 }
90
91 public MappingMatch getMappingMatch() {
92 return servletChain.getMappingMatch();
93 }
94
95 public enum Type {
96
99 NORMAL,
100
103 REDIRECT,
104
108 REWRITE;
109 }
110 }
111