@Test public void testGetMappedUrlWithRegexes() { URLPatternParser regexParser = new URLPatternParser("/(foo|bar|baz|cat|dog).jsf"); List<PathParameter> params = regexParser.parse(new URL("/foo.jsf")); Assert.assertTrue(params.isEmpty()); }
public List<PathParameter> parse(final URL url) { List<PathParameter> result = new ArrayList<PathParameter>(); String inboundUrl = url.toURL(); if (this.matches(url)) { Iterator<Segment> iter = pathSegments.iterator(); while (iter.hasNext()) { Segment segment = iter.next(); String regex = ""; if (url.hasLeadingSlash() && !"/".equals(url.toURL())) { regex += "/"; } regex += segment.getRegex(); if (iter.hasNext() || url.hasTrailingSlash()) { regex += "/"; } Matcher segmentMatcher = Pattern.compile(regex).matcher(inboundUrl); if (segmentMatcher.find()) { for (int j = 0; j < segment.numParameters(); j++) { String value = segmentMatcher.group(j + 1); PathParameter param = segment.getParameter(j).copy(); param.setValue(value); result.add(param); } int regionEnd = segmentMatcher.end(); inboundUrl = inboundUrl.substring(regionEnd - 1); } else { throw new PrettyException("Error parsing url: <" + url + ">, a parameter did not match compiled segment in pattern: " + originalPattern); } } } else { throw new IllegalArgumentException("The given URL: " + url + ", cannot be parsed by the pattern: " + originalPattern); } return result; }
URLPatternParser { public List<PathParameter> parse(final URL url) { List<PathParameter> result = new ArrayList<PathParameter>(); String inboundUrl = url.toURL(); if (this.matches(url)) { Iterator<Segment> iter = pathSegments.iterator(); while (iter.hasNext()) { Segment segment = iter.next(); String regex = ""; if (url.hasLeadingSlash() && !"/".equals(url.toURL())) { regex += "/"; } regex += segment.getRegex(); if (iter.hasNext() || url.hasTrailingSlash()) { regex += "/"; } Matcher segmentMatcher = Pattern.compile(regex).matcher(inboundUrl); if (segmentMatcher.find()) { for (int j = 0; j < segment.numParameters(); j++) { String value = segmentMatcher.group(j + 1); PathParameter param = segment.getParameter(j).copy(); param.setValue(value); result.add(param); } int regionEnd = segmentMatcher.end(); inboundUrl = inboundUrl.substring(regionEnd - 1); } else { throw new PrettyException("Error parsing url: <" + url + ">, a parameter did not match compiled segment in pattern: " + originalPattern); } } } else { throw new IllegalArgumentException("The given URL: " + url + ", cannot be parsed by the pattern: " + originalPattern); } return result; } }
URLPatternParser { public List<PathParameter> parse(final URL url) { List<PathParameter> result = new ArrayList<PathParameter>(); String inboundUrl = url.toURL(); if (this.matches(url)) { Iterator<Segment> iter = pathSegments.iterator(); while (iter.hasNext()) { Segment segment = iter.next(); String regex = ""; if (url.hasLeadingSlash() && !"/".equals(url.toURL())) { regex += "/"; } regex += segment.getRegex(); if (iter.hasNext() || url.hasTrailingSlash()) { regex += "/"; } Matcher segmentMatcher = Pattern.compile(regex).matcher(inboundUrl); if (segmentMatcher.find()) { for (int j = 0; j < segment.numParameters(); j++) { String value = segmentMatcher.group(j + 1); PathParameter param = segment.getParameter(j).copy(); param.setValue(value); result.add(param); } int regionEnd = segmentMatcher.end(); inboundUrl = inboundUrl.substring(regionEnd - 1); } else { throw new PrettyException("Error parsing url: <" + url + ">, a parameter did not match compiled segment in pattern: " + originalPattern); } } } else { throw new IllegalArgumentException("The given URL: " + url + ", cannot be parsed by the pattern: " + originalPattern); } return result; } URLPatternParser(final String pattern); }
URLPatternParser { public List<PathParameter> parse(final URL url) { List<PathParameter> result = new ArrayList<PathParameter>(); String inboundUrl = url.toURL(); if (this.matches(url)) { Iterator<Segment> iter = pathSegments.iterator(); while (iter.hasNext()) { Segment segment = iter.next(); String regex = ""; if (url.hasLeadingSlash() && !"/".equals(url.toURL())) { regex += "/"; } regex += segment.getRegex(); if (iter.hasNext() || url.hasTrailingSlash()) { regex += "/"; } Matcher segmentMatcher = Pattern.compile(regex).matcher(inboundUrl); if (segmentMatcher.find()) { for (int j = 0; j < segment.numParameters(); j++) { String value = segmentMatcher.group(j + 1); PathParameter param = segment.getParameter(j).copy(); param.setValue(value); result.add(param); } int regionEnd = segmentMatcher.end(); inboundUrl = inboundUrl.substring(regionEnd - 1); } else { throw new PrettyException("Error parsing url: <" + url + ">, a parameter did not match compiled segment in pattern: " + originalPattern); } } } else { throw new IllegalArgumentException("The given URL: " + url + ", cannot be parsed by the pattern: " + originalPattern); } return result; } URLPatternParser(final String pattern); boolean matches(final URL target); @Deprecated boolean matches(final String target); List<PathParameter> getPathParameters(); List<PathParameter> parse(final URL url); URL getMappedURL(final Object... params); int getParameterCount(); Object getPattern(); boolean isElPattern(); }
URLPatternParser { public List<PathParameter> parse(final URL url) { List<PathParameter> result = new ArrayList<PathParameter>(); String inboundUrl = url.toURL(); if (this.matches(url)) { Iterator<Segment> iter = pathSegments.iterator(); while (iter.hasNext()) { Segment segment = iter.next(); String regex = ""; if (url.hasLeadingSlash() && !"/".equals(url.toURL())) { regex += "/"; } regex += segment.getRegex(); if (iter.hasNext() || url.hasTrailingSlash()) { regex += "/"; } Matcher segmentMatcher = Pattern.compile(regex).matcher(inboundUrl); if (segmentMatcher.find()) { for (int j = 0; j < segment.numParameters(); j++) { String value = segmentMatcher.group(j + 1); PathParameter param = segment.getParameter(j).copy(); param.setValue(value); result.add(param); } int regionEnd = segmentMatcher.end(); inboundUrl = inboundUrl.substring(regionEnd - 1); } else { throw new PrettyException("Error parsing url: <" + url + ">, a parameter did not match compiled segment in pattern: " + originalPattern); } } } else { throw new IllegalArgumentException("The given URL: " + url + ", cannot be parsed by the pattern: " + originalPattern); } return result; } URLPatternParser(final String pattern); boolean matches(final URL target); @Deprecated boolean matches(final String target); List<PathParameter> getPathParameters(); List<PathParameter> parse(final URL url); URL getMappedURL(final Object... params); int getParameterCount(); Object getPattern(); boolean isElPattern();  }