use of org.webpieces.util.urlparse.RegExResult in project webpieces by deanhiller.
the class ScopedRouteBuilderImpl method createMatchInfo.
private MatchInfo createMatchInfo(UrlPath urlPath, Port exposedPort, HttpMethod httpMethod, Charset urlEncoding) {
RegExResult result = RegExUtil.parsePath(urlPath.getSubPath());
Pattern patternToMatch = Pattern.compile(result.regExToMatch);
List<String> pathParamNames = result.argNames;
return new MatchInfo(urlPath, exposedPort, httpMethod, urlEncoding, patternToMatch, pathParamNames);
}
use of org.webpieces.util.urlparse.RegExResult in project webpieces by deanhiller.
the class TestRegEx method testTwo.
@Test
public void testTwo() {
String path = "/path/{id}/user/{user}";
RegExResult parsePath = RegExUtil.parsePath(path);
Pattern pattern = Pattern.compile(parsePath.regExToMatch);
Assert.assertTrue(pattern.matcher("/path/myid/user/user").matches());
Assert.assertTrue(pattern.matcher("/path/myid/user/userA").matches());
Assert.assertFalse(pattern.matcher("/something/path/myid/user").matches());
Assert.assertFalse(pattern.matcher("/path/myid/user/ending/asdf").matches());
Assert.assertEquals("id", parsePath.argNames.get(0));
Assert.assertEquals("user", parsePath.argNames.get(1));
}
use of org.webpieces.util.urlparse.RegExResult in project webpieces by deanhiller.
the class ContentTypeBuilderImpl method createMatchInfo.
private MatchInfo createMatchInfo(UrlPath urlPath, Port exposedPort, HttpMethod httpMethod, Charset urlEncoding) {
RegExResult result = RegExUtil.parsePath(urlPath.getSubPath());
Pattern patternToMatch = Pattern.compile(result.regExToMatch);
List<String> pathParamNames = result.argNames;
return new MatchInfo(urlPath, exposedPort, httpMethod, urlEncoding, patternToMatch, pathParamNames);
}
use of org.webpieces.util.urlparse.RegExResult in project webpieces by deanhiller.
the class TestRegEx method testRegEx.
@Test
public void testRegEx() {
String path = "/path/{id}/user";
RegExResult parsePath = RegExUtil.parsePath(path);
Pattern pattern = Pattern.compile(parsePath.regExToMatch);
Assert.assertTrue(pattern.matcher("/path/myid/user").matches());
Assert.assertFalse(pattern.matcher("/something/path/myid/user").matches());
Assert.assertFalse(pattern.matcher("/path/myid/user/ending").matches());
Assert.assertFalse(pattern.matcher("/path/my/id/user").matches());
Assert.assertFalse(pattern.matcher("/path//myid/user").matches());
Assert.assertFalse(pattern.matcher("/path/asdf/myid/user").matches());
Matcher matcher = pattern.matcher("/path/myid/user");
// must run matching operation first
matcher.matches();
String group = matcher.group("id");
Assert.assertEquals("myid", group);
Assert.assertEquals("id", parsePath.argNames.get(0));
}
Aggregations