Set the path. @param path the path string @throws URIException set incorrectly or fragment only @see #encode
(String path)
| 2929 | * @see #encode |
| 2930 | */ |
| 2931 | public void setPath(String path) throws URIException { |
| 2932 | |
| 2933 | if (path == null || path.length() == 0) { |
| 2934 | _path = _opaque = (path == null) ? null : path.toCharArray(); |
| 2935 | setURI(); |
| 2936 | return; |
| 2937 | } |
| 2938 | // set the charset to do escape encoding |
| 2939 | String charset = getProtocolCharset(); |
| 2940 | |
| 2941 | if (_is_net_path || _is_abs_path) { |
| 2942 | _path = encode(path, allowed_abs_path, charset); |
| 2943 | } else if (_is_rel_path) { |
| 2944 | StringBuilder buff = new StringBuilder(path.length()); |
| 2945 | int at = path.indexOf('/'); |
| 2946 | if (at == 0) { // never 0 |
| 2947 | throw new URIException(URIException.PARSING, |
| 2948 | "incorrect relative path"); |
| 2949 | } |
| 2950 | if (at > 0) { |
| 2951 | buff.append(encode(path.substring(0, at), allowed_rel_path, |
| 2952 | charset)); |
| 2953 | buff.append(encode(path.substring(at), allowed_abs_path, |
| 2954 | charset)); |
| 2955 | } else { |
| 2956 | buff.append(encode(path, allowed_rel_path, charset)); |
| 2957 | } |
| 2958 | _path = buff.toString().toCharArray(); |
| 2959 | } else if (_is_opaque_part) { |
| 2960 | StringBuilder buf = new StringBuilder(); |
| 2961 | buf.insert(0, encode(path.substring(0, 1), uric_no_slash, charset)); |
| 2962 | buf.insert(1, encode(path.substring(1), uric, charset)); |
| 2963 | _opaque = buf.toString().toCharArray(); |
| 2964 | } else { |
| 2965 | throw new URIException(URIException.PARSING, "incorrect path"); |
| 2966 | } |
| 2967 | setURI(); |
| 2968 | } |
| 2969 | |
| 2970 | |
| 2971 | /** |