69
69
* <p>
70
70
* Here is an example for a template using simple variables:
71
71
*
72
- * <pre>
72
+ * <pre>{@code
73
73
* PathTemplate template = PathTemplate.create("v1/shelves/{shelf}/books/{book}");
74
74
* assert template.matches("v2/shelves") == false;
75
75
* Map<String, String> values = template.match("v1/shelves/s1/books/b1");
78
78
* expectedValues.put("book", "b1");
79
79
* assert values.equals(expectedValues);
80
80
* assert template.instantiate(values).equals("v1/shelves/s1/books/b1");
81
- * </pre>
81
+ * } </pre>
82
82
*
83
83
* Templates can use variables which match sub-paths. Example:
84
84
*
85
- * <pre>
85
+ * <pre>{@code
86
86
* PathTemplate template = PathTemplate.create("v1/{name=shelves/*/books/*}"};
87
87
* assert template.match("v1/shelves/books/b1") == null;
88
88
* Map<String, String> expectedValues = new HashMap<>();
89
89
* expectedValues.put("name", "shelves/s1/books/b1");
90
90
* assert template.match("v1/shelves/s1/books/b1").equals(expectedValues);
91
- * </pre>
91
+ * } </pre>
92
92
*
93
93
* Path templates can also be used with only wildcards. Each wildcard is associated with an implicit
94
94
* variable {@code $n}, where n is the zero-based position of the wildcard. Example:
95
95
*
96
- * <pre>
96
+ * <pre>{@code
97
97
* PathTemplate template = PathTemplate.create("shelves/*/books/*"};
98
98
* assert template.match("shelves/books/b1") == null;
99
99
* Map<String, String> values = template.match("v1/shelves/s1/books/b1");
100
100
* Map<String, String> expectedValues = new HashMap<>();
101
101
* expectedValues.put("$0", s1");
102
102
* expectedValues.put("$1", "b1");
103
103
* assert values.equals(expectedValues);
104
- * </pre>
104
+ * } </pre>
105
105
*
106
106
* Paths input to matching can use URL relative syntax to indicate a host name by prefixing the host
107
107
* name, as in {@code //somewhere.io/some/path}. The host name is matched into the special variable
108
108
* {@link #HOSTNAME_VAR}. Patterns are agnostic about host names, and the same pattern can be used
109
109
* for URL relative syntax and simple path syntax:
110
110
*
111
- * <pre>
111
+ * <pre>{@code
112
112
* PathTemplate template = PathTemplate.create("shelves/*"};
113
113
* Map<String, String> expectedValues = new HashMap<>();
114
114
* expectedValues.put(PathTemplate.HOSTNAME_VAR, "//somewhere.io");
117
117
* expectedValues.clear();
118
118
* expectedValues.put("$0", s1");
119
119
* assert template.match("shelves/s1").equals(expectedValues);
120
- * </pre>
120
+ * } </pre>
121
121
*
122
122
* For the representation of a <em>resource name</em> see {@link TemplatedResourceName}, which is
123
123
* based on path templates.
@@ -347,10 +347,10 @@ public PathTemplate withoutVars() {
347
347
/**
348
348
* Returns a path template for the sub-path of the given variable. Example:
349
349
*
350
- * <pre>
350
+ * <pre>{@code
351
351
* PathTemplate template = PathTemplate.create("v1/{name=shelves/*/books/*}");
352
352
* assert template.subTemplate("name").toString().equals("shelves/*/books/*");
353
- * </pre>
353
+ * } </pre>
354
354
*
355
355
* The returned template will never have named variables, but only wildcards, which are dealt with
356
356
* in matching and instantiation using '$n'-variables. See the documentation of
@@ -446,7 +446,7 @@ public void validate(String path, String exceptionMessagePrefix) {
446
446
* For free wildcards in the template, the matching process creates variables named '$n', where
447
447
* 'n' is the wildcard's position in the template (starting at n=0). For example:
448
448
*
449
- * <pre>
449
+ * <pre>{@code
450
450
* PathTemplate template = PathTemplate.create("shelves/*/books/*");
451
451
* Map<String, String> expectedValues = new HashMap<>();
452
452
* expectedValues.put("$0", "s1");
@@ -459,7 +459,7 @@ public void validate(String path, String exceptionMessagePrefix) {
459
459
* expectedValues.put("$1", "b1");
460
460
* assert template.validatedMatch("//somewhere.io/shelves/s1/books/b2", "User exception string")
461
461
* .equals(expectedValues);
462
- * </pre>
462
+ * } </pre>
463
463
*
464
464
* All matched values will be properly unescaped using URL encoding rules (so long as URL encoding
465
465
* has not been disabled by the {@link #createWithoutUrlEncoding} method).
@@ -498,7 +498,7 @@ public boolean matches(String path) {
498
498
* For free wildcards in the template, the matching process creates variables named '$n', where
499
499
* 'n' is the wildcard's position in the template (starting at n=0). For example:
500
500
*
501
- * <pre>
501
+ * <pre>{@code
502
502
* PathTemplate template = PathTemplate.create("shelves/*/books/*");
503
503
* Map<String, String> expectedValues = new HashMap<>();
504
504
* expectedValues.put("$0", "s1");
@@ -509,7 +509,7 @@ public boolean matches(String path) {
509
509
* expectedValues.put("$0", "s1");
510
510
* expectedValues.put("$1", "b1");
511
511
* assert template.match("//somewhere.io/shelves/s1/books/b2").equals(expectedValues);
512
- * </pre>
512
+ * } </pre>
513
513
*
514
514
* All matched values will be properly unescaped using URL encoding rules (so long as URL encoding
515
515
* has not been disabled by the {@link #createWithoutUrlEncoding} method).
@@ -523,13 +523,13 @@ public Map<String, String> match(String path) {
523
523
* Matches the path, where the first segment is interpreted as the host name regardless of whether
524
524
* it starts with '//' or not. Example:
525
525
*
526
- * <pre>
526
+ * <pre>{@code
527
527
* Map<String, String> expectedValues = new HashMap<>();
528
528
* expectedValues.put(HOSTNAME_VAR, "//somewhere.io");
529
529
* expectedValues.put("name", "shelves/s1");
530
530
* assert template("{name=shelves/*}").matchFromFullName("somewhere.io/shelves/s1")
531
531
* .equals(expectedValues);
532
- * </pre>
532
+ * } </pre>
533
533
*/
534
534
@ Nullable
535
535
public Map <String , String > matchFromFullName (String path ) {
@@ -721,12 +721,12 @@ public String instantiate(String... keysAndValues) {
721
721
* Same like {@link #instantiate(Map)} but allows for unbound variables, which are substituted
722
722
* using their original syntax. Example:
723
723
*
724
- * <pre>
724
+ * <pre>{@code
725
725
* PathTemplate template = PathTemplate.create("v1/shelves/{shelf}/books/{book}");
726
726
* Map<String, String> partialMap = new HashMap<>();
727
727
* partialMap.put("shelf", "s1");
728
728
* assert template.instantiatePartial(partialMap).equals("v1/shelves/s1/books/{book}");
729
- * </pre>
729
+ * } </pre>
730
730
*
731
731
* The result of this call can be used to create a new template.
732
732
*/
0 commit comments