@Test public void testURLEncoding() throws Exception { String path = "/some spaces in url/and query"; URI uri = parser.uriFromString("https: path + "?q=some space&some other space#anchor"); Assert.assertEquals(8080, uri.getPort()); Assert.assertEquals("google.com", uri.getHost()); Assert.assertEquals("https", uri.getScheme()); Assert.assertEquals(path, uri.getPath()); Assert.assertEquals(path.replace(" ", "%20"), uri.getRawPath()); }
public URI uriFromString(String s) throws URISyntaxException { String scheme = null; int port = -1; String userinfo = null; String host; String path = ""; String query = null; String fragment = null; URLEncodedUtils.parse(s, Charset.defaultCharset()); Matcher m = Pattern.compile("([^:]+): if(m.matches()) { scheme = m.group(1); } m = Pattern.compile("[^:]+: if(m.matches()) { userinfo = m.group(1); m = Pattern.compile("[^:]+: } else { m = Pattern.compile("[^:]+: } if(m.matches()) { host = m.group(1); } else { throw new URISyntaxException(s, "No host specified"); } m = Pattern.compile("[^:]+: if(m.matches()) { port = Integer.parseInt(m.group(1)); } m = Pattern.compile("[^:]+: if(m.matches()) { path = m.group(1); } m = Pattern.compile("[^:]+: if(m.matches()) { query = m.group(1); } m = Pattern.compile("[^:]+: if(m.matches()) { fragment = m.group(1); } return new URI(scheme, userinfo, host, port, path, query, fragment); }
UriParser { public URI uriFromString(String s) throws URISyntaxException { String scheme = null; int port = -1; String userinfo = null; String host; String path = ""; String query = null; String fragment = null; URLEncodedUtils.parse(s, Charset.defaultCharset()); Matcher m = Pattern.compile("([^:]+): if(m.matches()) { scheme = m.group(1); } m = Pattern.compile("[^:]+: if(m.matches()) { userinfo = m.group(1); m = Pattern.compile("[^:]+: } else { m = Pattern.compile("[^:]+: } if(m.matches()) { host = m.group(1); } else { throw new URISyntaxException(s, "No host specified"); } m = Pattern.compile("[^:]+: if(m.matches()) { port = Integer.parseInt(m.group(1)); } m = Pattern.compile("[^:]+: if(m.matches()) { path = m.group(1); } m = Pattern.compile("[^:]+: if(m.matches()) { query = m.group(1); } m = Pattern.compile("[^:]+: if(m.matches()) { fragment = m.group(1); } return new URI(scheme, userinfo, host, port, path, query, fragment); } }
UriParser { public URI uriFromString(String s) throws URISyntaxException { String scheme = null; int port = -1; String userinfo = null; String host; String path = ""; String query = null; String fragment = null; URLEncodedUtils.parse(s, Charset.defaultCharset()); Matcher m = Pattern.compile("([^:]+): if(m.matches()) { scheme = m.group(1); } m = Pattern.compile("[^:]+: if(m.matches()) { userinfo = m.group(1); m = Pattern.compile("[^:]+: } else { m = Pattern.compile("[^:]+: } if(m.matches()) { host = m.group(1); } else { throw new URISyntaxException(s, "No host specified"); } m = Pattern.compile("[^:]+: if(m.matches()) { port = Integer.parseInt(m.group(1)); } m = Pattern.compile("[^:]+: if(m.matches()) { path = m.group(1); } m = Pattern.compile("[^:]+: if(m.matches()) { query = m.group(1); } m = Pattern.compile("[^:]+: if(m.matches()) { fragment = m.group(1); } return new URI(scheme, userinfo, host, port, path, query, fragment); }  }
UriParser { public URI uriFromString(String s) throws URISyntaxException { String scheme = null; int port = -1; String userinfo = null; String host; String path = ""; String query = null; String fragment = null; URLEncodedUtils.parse(s, Charset.defaultCharset()); Matcher m = Pattern.compile("([^:]+): if(m.matches()) { scheme = m.group(1); } m = Pattern.compile("[^:]+: if(m.matches()) { userinfo = m.group(1); m = Pattern.compile("[^:]+: } else { m = Pattern.compile("[^:]+: } if(m.matches()) { host = m.group(1); } else { throw new URISyntaxException(s, "No host specified"); } m = Pattern.compile("[^:]+: if(m.matches()) { port = Integer.parseInt(m.group(1)); } m = Pattern.compile("[^:]+: if(m.matches()) { path = m.group(1); } m = Pattern.compile("[^:]+: if(m.matches()) { query = m.group(1); } m = Pattern.compile("[^:]+: if(m.matches()) { fragment = m.group(1); } return new URI(scheme, userinfo, host, port, path, query, fragment); }  URI uriFromString(String s); List<URL> getUrlsFromObject(Object urlsObject); }
UriParser { public URI uriFromString(String s) throws URISyntaxException { String scheme = null; int port = -1; String userinfo = null; String host; String path = ""; String query = null; String fragment = null; URLEncodedUtils.parse(s, Charset.defaultCharset()); Matcher m = Pattern.compile("([^:]+): if(m.matches()) { scheme = m.group(1); } m = Pattern.compile("[^:]+: if(m.matches()) { userinfo = m.group(1); m = Pattern.compile("[^:]+: } else { m = Pattern.compile("[^:]+: } if(m.matches()) { host = m.group(1); } else { throw new URISyntaxException(s, "No host specified"); } m = Pattern.compile("[^:]+: if(m.matches()) { port = Integer.parseInt(m.group(1)); } m = Pattern.compile("[^:]+: if(m.matches()) { path = m.group(1); } m = Pattern.compile("[^:]+: if(m.matches()) { query = m.group(1); } m = Pattern.compile("[^:]+: if(m.matches()) { fragment = m.group(1); } return new URI(scheme, userinfo, host, port, path, query, fragment); }  URI uriFromString(String s); List<URL> getUrlsFromObject(Object urlsObject);  }