Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions core-common/src/main/java/org/glassfish/jersey/uri/PathPattern.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010-2014 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -64,11 +64,11 @@ public final class PathPattern extends PatternWithGroups {
* Path pattern matching the end of a URI path. Can be either empty {@code ""}
* or contain a trailing slash {@code "/"}.
*/
public static final PathPattern END_OF_PATH_PATTERN = new PathPattern("", PathPattern.RightHandPath.capturingZeroSegments);
public static final PathPattern END_OF_PATH_PATTERN = new PathPattern("", PathPattern.RightHandPath.capturingZeroSegments);
/**
* Path pattern matching the any URI path.
*/
public static final PathPattern OPEN_ROOT_PATH_PATTERN = new PathPattern("", RightHandPath.capturingZeroOrMoreSegments);
public static final PathPattern OPEN_ROOT_PATH_PATTERN = new PathPattern("", RightHandPath.capturingZeroOrMoreSegments);
/**
* Path pattern comparator that defers to {@link UriTemplate#COMPARATOR comparing
* the templates} associated with the patterns.
Expand Down Expand Up @@ -119,6 +119,7 @@ private String getRegex() {
public static PathPattern asClosed(PathPattern pattern) {
return new PathPattern(pattern.getTemplate().getTemplate(), RightHandPath.capturingZeroSegments);
}

//
private final UriTemplate template;

Expand All @@ -132,7 +133,6 @@ private PathPattern() {
* {@link RightHandPath#capturingZeroOrMoreSegments}.
*
* @param template the path template.
*
* @see #PathPattern(String, PathPattern.RightHandPath)
*/
public PathPattern(String template) {
Expand All @@ -144,12 +144,11 @@ public PathPattern(String template) {
* {@link RightHandPath#capturingZeroOrMoreSegments}.
*
* @param template the path template
*
* @see #PathPattern(PathTemplate, PathPattern.RightHandPath)
*/
public PathPattern(PathTemplate template) {
super(postfixWithCapturingGroup(template.getPattern().getRegex()),
addIndexForRightHandPathCapturingGroup(template.getPattern().getGroupIndexes()));
addIndexForRightHandPathCapturingGroup(template.getNumberOfRegexGroups(), template.getPattern().getGroupIndexes()));

this.template = template;
}
Expand All @@ -158,7 +157,7 @@ public PathPattern(PathTemplate template) {
* Create a path pattern and post fix with a right hand path pattern.
*
* @param template the path template.
* @param rhpp the right hand path pattern postfix.
* @param rhpp the right hand path pattern postfix.
*/
public PathPattern(String template, RightHandPath rhpp) {
this(new PathTemplate(template), rhpp);
Expand All @@ -168,11 +167,11 @@ public PathPattern(String template, RightHandPath rhpp) {
* Create a path pattern and post fix with a right hand path pattern.
*
* @param template the path template.
* @param rhpp the right hand path pattern postfix.
* @param rhpp the right hand path pattern postfix.
*/
public PathPattern(PathTemplate template, RightHandPath rhpp) {
super(postfixWithCapturingGroup(template.getPattern().getRegex(), rhpp),
addIndexForRightHandPathCapturingGroup(template.getPattern().getGroupIndexes()));
addIndexForRightHandPathCapturingGroup(template.getNumberOfRegexGroups(), template.getPattern().getGroupIndexes()));

this.template = template;
}
Expand All @@ -193,15 +192,15 @@ private static String postfixWithCapturingGroup(String regex, RightHandPath rhpp
return regex + rhpp.getRegex();
}

private static int[] addIndexForRightHandPathCapturingGroup(int[] indexes) {
private static int[] addIndexForRightHandPathCapturingGroup(int numberOfGroups, int[] indexes) {
if (indexes.length == 0) {
return indexes;
}

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

cgIndexes[indexes.length] = cgIndexes[indexes.length - 1] + 1;
cgIndexes[indexes.length] = numberOfGroups + 1;
return cgIndexes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
* the expression.
*
* @author Paul Sandoz
* @author Gerard Davison (gerard.davison at oracle.com)
*/
public class PatternWithGroups {

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

@Override
public int groupCount() {
return groupIndexes.length - 1;
return groupIndexes.length;
}
}

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

groupValues.clear();
if (groupIndexes.length > 0) {
for (int i = 0; i < groupIndexes.length - 1; i++) {
for (int i = 0; i < groupIndexes.length; i++) {
groupValues.add(m.group(groupIndexes[i]));
}
} else {
Expand Down Expand Up @@ -354,7 +356,7 @@ public final boolean match(final CharSequence cs, final List<String> groupValues
* @throws IllegalArgumentException if group values is {@code null}.
*/
public final boolean match(final CharSequence cs, final List<String> groupNames, final Map<String,
String> groupValues) throws IllegalArgumentException {
String> groupValues) throws IllegalArgumentException {
if (groupValues == null) {
throw new IllegalArgumentException();
}
Expand All @@ -374,6 +376,7 @@ public final boolean match(final CharSequence cs, final List<String> groupNames,

// Assign the matched group values to group names
groupValues.clear();

for (int i = 0; i < groupNames.size(); i++) {
String name = groupNames.get(i);
String currentValue = m.group((groupIndexes.length > 0) ? groupIndexes[i] : i + 1);
Expand Down
Loading