|
47 | 47 | */ |
48 | 48 | @Path("/") |
49 | 49 | public class TikaWelcome { |
50 | | - private static final String DOCS_URL = "https://wiki.apache.org/tika/TikaJAXRS"; |
| 50 | + private static final String DOCS_URL = |
| 51 | + "https://cwiki.apache.org/confluence/display/TIKA/TikaJAXRS"; |
| 52 | + |
| 53 | + /** Matches {@code {name : regex}} in a JAX-RS path, capturing the parameter name. */ |
| 54 | + private static final Pattern PATH_TEMPLATE_REGEX = |
| 55 | + Pattern.compile("\\{\\s*(\\w+)\\s*:[^}]*}"); |
51 | 56 |
|
52 | 57 | private static final Map<Class<? extends Annotation>, String> HTTP_METHODS = new HashMap<>(); |
53 | 58 |
|
@@ -164,13 +169,21 @@ public String getWelcomeHTML() { |
164 | 169 |
|
165 | 170 | h.append("<ul>\n"); |
166 | 171 | for (Endpoint e : identifyEndpoints()) { |
| 172 | + String displayPath = simplifyPathTemplate(e.path); |
167 | 173 | h.append("<li><b>"); |
168 | 174 | h.append(e.httpMethod); |
169 | | - h.append("</b> <i><a href=\""); |
170 | | - h.append(e.path); |
171 | | - h.append("\">"); |
172 | | - h.append(e.path); |
173 | | - h.append("</a></i><br />"); |
| 175 | + h.append("</b> <i>"); |
| 176 | + // Only linkify concrete paths; one with a {param} is not fetchable as written. |
| 177 | + if (displayPath.indexOf('{') < 0) { |
| 178 | + h.append("<a href=\""); |
| 179 | + h.append(displayPath); |
| 180 | + h.append("\">"); |
| 181 | + h.append(displayPath); |
| 182 | + h.append("</a>"); |
| 183 | + } else { |
| 184 | + h.append(displayPath); |
| 185 | + } |
| 186 | + h.append("</i><br />"); |
174 | 187 | h.append("Class: "); |
175 | 188 | h.append(e.className); |
176 | 189 | h.append("<br />Method: "); |
@@ -213,6 +226,17 @@ public String getWelcomePlain() { |
213 | 226 | return text.toString(); |
214 | 227 | } |
215 | 228 |
|
| 229 | + /** |
| 230 | + * Strips the regex from a JAX-RS path template so {@code /rmeta/{handler : (\w+)?}} |
| 231 | + * renders as {@code /rmeta/{handler}}. |
| 232 | + */ |
| 233 | + static String simplifyPathTemplate(String path) { |
| 234 | + if (path == null || path.indexOf('{') < 0) { |
| 235 | + return path; |
| 236 | + } |
| 237 | + return PATH_TEMPLATE_REGEX.matcher(path).replaceAll("{$1}"); |
| 238 | + } |
| 239 | + |
216 | 240 | protected static class Endpoint { |
217 | 241 | public final String className; |
218 | 242 | public final String methodName; |
|
0 commit comments