private URI buildURI(boolean fromEncoded, String thePath, String theQuery, String theFragment) throws URISyntaxException { if (fromEncoded) { return buildURIFromEncoded(thePath, theQuery, theFragment); } else if (!isSchemeOpaque()) { if ((scheme != null || host != null || userInfo != null) && thePath.length() != 0 && !(thePath.startsWith("/") || thePath.startsWith(";"))) { thePath = "/" + thePath; } try { return buildURIFromEncoded(thePath, theQuery, theFragment); } catch (Exception ex) { // lets try the option below } URI uri = new URI(scheme, userInfo, host, port, thePath, theQuery, theFragment); if (thePath.contains("%2F")) { // TODO: the bogus case of segments containing encoded '/' // Not sure if we have a cleaner solution though. String realPath = uri.getRawPath().replace("%252F", "%2F"); uri = buildURIFromEncoded(realPath, uri.getRawQuery(), uri.getRawFragment()); } return uri; } else { return new URI(scheme, schemeSpecificPart, theFragment); } }
private URI buildURI(boolean fromEncoded, String thePath, String theQuery, String theFragment) throws URISyntaxException { if (fromEncoded) { return buildURIFromEncoded(thePath, theQuery, theFragment); } else if (!isSchemeOpaque()) { if ((scheme != null || host != null || userInfo != null) && thePath.length() != 0 && !thePath.startsWith("/")) { thePath = "/" + thePath; } try { return buildURIFromEncoded(thePath, theQuery, theFragment); } catch (Exception ex) { // lets try the option below } URI uri = new URI(scheme, userInfo, host, port, thePath, theQuery, theFragment); if (thePath.contains("%2F")) { // TODO: the bogus case of segments containing encoded '/' // Not sure if we have a cleaner solution though. String realPath = uri.getRawPath().replace("%252F", "%2F"); uri = buildURIFromEncoded(realPath, uri.getRawQuery(), uri.getRawFragment()); } return uri; } else { return new URI(scheme, schemeSpecificPart, theFragment); } }