public UriBuilder uriAsTemplate(String uri) { // This can be a start of replacing URI class Parser completely // but it can be too complicated, the following code is needed for now // to deal with URIs containing template variables. int index = uri.indexOf(":"); if (index != -1) { this.scheme = uri.substring(0, index); uri = uri.substring(index + 1); if (uri.indexOf("//") == 0) { uri = uri.substring(2); index = uri.indexOf("/"); if (index != -1) { String[] schemePair = uri.substring(0, index).split(":"); this.host = schemePair[0]; this.port = schemePair.length == 2 ? Integer.valueOf(schemePair[1]) : -1; } uri = uri.substring(index); } } setPathAndMatrix(uri); return this; }
uri = uri.substring(0, index); setPathAndMatrix(uri); if (rawQuery != null) { query = JAXRSUtils.getStructuredParams(rawQuery, "&", false, true);
private void setUriParts(URI uri) { if (uri == null) { throw new IllegalArgumentException("uri is null"); } String theScheme = uri.getScheme(); if (theScheme != null) { scheme = theScheme; } String rawPath = uri.getRawPath(); if (!uri.isOpaque() && (theScheme != null || rawPath != null && rawPath.startsWith("/"))) { port = uri.getPort(); host = uri.getHost(); if (rawPath != null) { setPathAndMatrix(uri.getRawPath()); } String rawQuery = uri.getRawQuery(); if (rawQuery != null) { query = JAXRSUtils.getStructuredParams(rawQuery, "&", false, true); } userInfo = uri.getUserInfo(); schemeSpecificPart = null; } else { schemeSpecificPart = uri.getSchemeSpecificPart(); } String theFragment = uri.getFragment(); if (theFragment != null) { fragment = theFragment; } }
host = uri.getHost(); if (rawPath != null) { setPathAndMatrix(rawPath);
@Override public UriBuilder replacePath(String path) { if (path == null) { clearPathAndMatrix(); } else if (isAbsoluteUriPath(path)) { clearPathAndMatrix(); uri(URI.create(path)); } else { setPathAndMatrix(path); } return this; }
@Override public UriBuilder replacePath(String path) { if (path == null) { clearPathAndMatrix(); } else if (isAbsoluteUriPath(path)) { clearPathAndMatrix(); uri(URI.create(path)); } else { setPathAndMatrix(path); } return this; }