Skip to content

Commit

Permalink
Issue #7891 - Introduce MatchedPath.from
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed May 4, 2022
1 parent 6c2968a commit 7adf903
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
Expand Up @@ -33,8 +33,38 @@ public String getPathInfo()
{
return null;
}

@Override
public String toString()
{
return "MatchedPath.EMPTY";
}
};

static MatchedPath from(String pathMatch, String pathInfo)
{
return new MatchedPath()
{
@Override
public String getPathMatch()
{
return pathMatch;
}

@Override
public String getPathInfo()
{
return pathInfo;
}

@Override
public String toString()
{
return "MatchedPath.from[pathMatch=" + pathMatch + ", pathInfo=" + pathInfo + "]";
}
};
}

/**
* Return the portion of the path that matches a path spec.
*
Expand Down
Expand Up @@ -291,7 +291,7 @@ public MatchedPath matched(String path)
{
case EXACT:
if (_declaration.equals(path))
return new ServletMatchedPath(path, null); // TODO: return final matchedpath
return MatchedPath.from(path, null);
break;
case PREFIX_GLOB:
if (isWildcardMatch(path))
Expand All @@ -303,21 +303,21 @@ public MatchedPath matched(String path)
pathMatch = path.substring(0, _specLength - 2);
pathInfo = path.substring(_specLength - 2);
}
return new ServletMatchedPath(pathMatch, pathInfo);
return MatchedPath.from(pathMatch, pathInfo);
}
break;
case SUFFIX_GLOB:
if (path.regionMatches((path.length() - _specLength) + 1, _declaration, 1, _specLength - 1))
return new ServletMatchedPath(path, null);
return MatchedPath.from(path, null);
break;
case ROOT:
// Only "/" matches
if ("/".equals(path))
return new ServletMatchedPath("", path); // TODO: review this
return MatchedPath.from("", path);
break;
case DEFAULT:
// If we reached this point, then everything matches
return new ServletMatchedPath(path, null);
return MatchedPath.from(path, null);
}
return null;
}
Expand All @@ -343,28 +343,4 @@ public boolean matches(String path)
return false;
}
}

public static class ServletMatchedPath implements MatchedPath
{
private final String servletName;
private final String pathInfo;

public ServletMatchedPath(String servletName, String pathInfo)
{
this.servletName = servletName;
this.pathInfo = pathInfo;
}

@Override
public String getPathMatch()
{
return this.servletName;
}

@Override
public String getPathInfo()
{
return this.pathInfo;
}
}
}

0 comments on commit 7adf903

Please sign in to comment.