Search in sources :

Example 1 with RegExResult

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);
}
Also used : Pattern(java.util.regex.Pattern) MatchInfo(org.webpieces.router.impl.routers.MatchInfo) RegExResult(org.webpieces.util.urlparse.RegExResult)

Example 2 with RegExResult

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));
}
Also used : Pattern(java.util.regex.Pattern) RegExResult(org.webpieces.util.urlparse.RegExResult) Test(org.junit.Test)

Example 3 with RegExResult

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);
}
Also used : Pattern(java.util.regex.Pattern) MatchInfo(org.webpieces.router.impl.routers.MatchInfo) RegExResult(org.webpieces.util.urlparse.RegExResult)

Example 4 with RegExResult

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));
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) RegExResult(org.webpieces.util.urlparse.RegExResult) Test(org.junit.Test)

Aggregations

Pattern (java.util.regex.Pattern)4 RegExResult (org.webpieces.util.urlparse.RegExResult)4 Test (org.junit.Test)2 MatchInfo (org.webpieces.router.impl.routers.MatchInfo)2 Matcher (java.util.regex.Matcher)1