Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 0f9c174

Browse files
committed
Merge pull request #82 from kingsfleet/declarative_linking_reading
Declarative linking reading
2 parents 5f23719 + 3419b4e commit 0f9c174

File tree

28 files changed

+2088
-541
lines changed

28 files changed

+2088
-541
lines changed

core-common/src/main/java/org/glassfish/jersey/uri/PathPattern.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2014 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -64,11 +64,11 @@ public final class PathPattern extends PatternWithGroups {
6464
* Path pattern matching the end of a URI path. Can be either empty {@code ""}
6565
* or contain a trailing slash {@code "/"}.
6666
*/
67-
public static final PathPattern END_OF_PATH_PATTERN = new PathPattern("", PathPattern.RightHandPath.capturingZeroSegments);
67+
public static final PathPattern END_OF_PATH_PATTERN = new PathPattern("", PathPattern.RightHandPath.capturingZeroSegments);
6868
/**
6969
* Path pattern matching the any URI path.
7070
*/
71-
public static final PathPattern OPEN_ROOT_PATH_PATTERN = new PathPattern("", RightHandPath.capturingZeroOrMoreSegments);
71+
public static final PathPattern OPEN_ROOT_PATH_PATTERN = new PathPattern("", RightHandPath.capturingZeroOrMoreSegments);
7272
/**
7373
* Path pattern comparator that defers to {@link UriTemplate#COMPARATOR comparing
7474
* the templates} associated with the patterns.
@@ -119,6 +119,7 @@ private String getRegex() {
119119
public static PathPattern asClosed(PathPattern pattern) {
120120
return new PathPattern(pattern.getTemplate().getTemplate(), RightHandPath.capturingZeroSegments);
121121
}
122+
122123
//
123124
private final UriTemplate template;
124125

@@ -132,7 +133,6 @@ private PathPattern() {
132133
* {@link RightHandPath#capturingZeroOrMoreSegments}.
133134
*
134135
* @param template the path template.
135-
*
136136
* @see #PathPattern(String, PathPattern.RightHandPath)
137137
*/
138138
public PathPattern(String template) {
@@ -144,12 +144,11 @@ public PathPattern(String template) {
144144
* {@link RightHandPath#capturingZeroOrMoreSegments}.
145145
*
146146
* @param template the path template
147-
*
148147
* @see #PathPattern(PathTemplate, PathPattern.RightHandPath)
149148
*/
150149
public PathPattern(PathTemplate template) {
151150
super(postfixWithCapturingGroup(template.getPattern().getRegex()),
152-
addIndexForRightHandPathCapturingGroup(template.getPattern().getGroupIndexes()));
151+
addIndexForRightHandPathCapturingGroup(template.getNumberOfRegexGroups(), template.getPattern().getGroupIndexes()));
153152

154153
this.template = template;
155154
}
@@ -158,7 +157,7 @@ public PathPattern(PathTemplate template) {
158157
* Create a path pattern and post fix with a right hand path pattern.
159158
*
160159
* @param template the path template.
161-
* @param rhpp the right hand path pattern postfix.
160+
* @param rhpp the right hand path pattern postfix.
162161
*/
163162
public PathPattern(String template, RightHandPath rhpp) {
164163
this(new PathTemplate(template), rhpp);
@@ -168,11 +167,11 @@ public PathPattern(String template, RightHandPath rhpp) {
168167
* Create a path pattern and post fix with a right hand path pattern.
169168
*
170169
* @param template the path template.
171-
* @param rhpp the right hand path pattern postfix.
170+
* @param rhpp the right hand path pattern postfix.
172171
*/
173172
public PathPattern(PathTemplate template, RightHandPath rhpp) {
174173
super(postfixWithCapturingGroup(template.getPattern().getRegex(), rhpp),
175-
addIndexForRightHandPathCapturingGroup(template.getPattern().getGroupIndexes()));
174+
addIndexForRightHandPathCapturingGroup(template.getNumberOfRegexGroups(), template.getPattern().getGroupIndexes()));
176175

177176
this.template = template;
178177
}
@@ -193,15 +192,15 @@ private static String postfixWithCapturingGroup(String regex, RightHandPath rhpp
193192
return regex + rhpp.getRegex();
194193
}
195194

196-
private static int[] addIndexForRightHandPathCapturingGroup(int[] indexes) {
195+
private static int[] addIndexForRightHandPathCapturingGroup(int numberOfGroups, int[] indexes) {
197196
if (indexes.length == 0) {
198197
return indexes;
199198
}
200199

201200
int[] cgIndexes = new int[indexes.length + 1];
202201
System.arraycopy(indexes, 0, cgIndexes, 0, indexes.length);
203202

204-
cgIndexes[indexes.length] = cgIndexes[indexes.length - 1] + 1;
203+
cgIndexes[indexes.length] = numberOfGroups + 1;
205204
return cgIndexes;
206205
}
207206
}

core-common/src/main/java/org/glassfish/jersey/uri/PatternWithGroups.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
* the expression.
5353
*
5454
* @author Paul Sandoz
55+
* @author Gerard Davison (gerard.davison at oracle.com)
5556
*/
5657
public class PatternWithGroups {
5758

@@ -96,7 +97,8 @@ public PatternWithGroups(final String regex) throws PatternSyntaxException {
9697
/**
9798
* Construct a new pattern.
9899
*
99-
* @param regex the regular expression. If the expression is {@code null} or an empty string then the pattern will only
100+
* @param regex the regular expression. If the expression is {@code null} or an empty string then the pattern will
101+
* only
100102
* match
101103
* a {@code null} or empty string.
102104
* @param groupIndexes the array of group indexes to capturing groups.
@@ -260,7 +262,7 @@ public String group(final int group) {
260262

261263
@Override
262264
public int groupCount() {
263-
return groupIndexes.length - 1;
265+
return groupIndexes.length;
264266
}
265267
}
266268

@@ -323,7 +325,7 @@ public final boolean match(final CharSequence cs, final List<String> groupValues
323325

324326
groupValues.clear();
325327
if (groupIndexes.length > 0) {
326-
for (int i = 0; i < groupIndexes.length - 1; i++) {
328+
for (int i = 0; i < groupIndexes.length; i++) {
327329
groupValues.add(m.group(groupIndexes[i]));
328330
}
329331
} else {
@@ -354,7 +356,7 @@ public final boolean match(final CharSequence cs, final List<String> groupValues
354356
* @throws IllegalArgumentException if group values is {@code null}.
355357
*/
356358
public final boolean match(final CharSequence cs, final List<String> groupNames, final Map<String,
357-
String> groupValues) throws IllegalArgumentException {
359+
String> groupValues) throws IllegalArgumentException {
358360
if (groupValues == null) {
359361
throw new IllegalArgumentException();
360362
}
@@ -374,6 +376,7 @@ public final boolean match(final CharSequence cs, final List<String> groupNames,
374376

375377
// Assign the matched group values to group names
376378
groupValues.clear();
379+
377380
for (int i = 0; i < groupNames.size(); i++) {
378381
String name = groupNames.get(i);
379382
String currentValue = m.group((groupIndexes.length > 0) ? groupIndexes[i] : i + 1);

0 commit comments

Comments
 (0)