1 31 32 package org.apache.commons.httpclient; 33 34 import org.apache.commons.httpclient.util.URIUtil; 35 36 42 public class HttpsURL extends HttpURL { 43 44 46 49 protected HttpsURL() { 50 } 51 52 53 63 public HttpsURL(char[] escaped, String charset) 64 throws URIException, NullPointerException { 65 protocolCharset = charset; 66 parseUriReference(new String (escaped), true); 67 checkValid(); 68 } 69 70 71 79 public HttpsURL(char[] escaped) throws URIException, NullPointerException { 80 parseUriReference(new String (escaped), true); 81 checkValid(); 82 } 83 84 85 94 public HttpsURL(String original, String charset) throws URIException { 95 protocolCharset = charset; 96 parseUriReference(original, false); 97 checkValid(); 98 } 99 100 101 108 public HttpsURL(String original) throws URIException { 109 parseUriReference(original, false); 110 checkValid(); 111 } 112 113 114 123 public HttpsURL(String host, int port, String path) throws URIException { 124 this(null, host, port, path, null, null); 125 checkValid(); 126 } 127 128 129 139 public HttpsURL(String host, int port, String path, String query) 140 throws URIException { 141 142 this(null, host, port, path, query, null); 143 checkValid(); 144 } 145 146 147 156 public HttpsURL(String user, String password, String host) 157 throws URIException { 158 159 this((user == null) ? null : user 160 + ((password == null) ? "" : ':' + password), 161 host, -1, null, null, null); 162 checkValid(); 163 } 164 165 166 176 public HttpsURL(String user, String password, String host, int port) 177 throws URIException { 178 179 this((user == null) ? null : user 180 + ((password == null) ? "" : ':' + password), 181 host, port, null, null, null); 182 checkValid(); 183 } 184 185 186 197 public HttpsURL(String user, String password, String host, int port, 198 String path) throws URIException { 199 200 this((user == null) ? null : user 201 + ((password == null) ? "" : ':' + password), 202 host, port, path, null, null); 203 checkValid(); 204 } 205 206 207 219 public HttpsURL(String user, String password, String host, int port, 220 String path, String query) throws URIException { 221 222 this((user == null) ? null : user 223 + ((password == null) ? "" : ':' + password), 224 host, port, path, query, null); 225 checkValid(); 226 } 227 228 229 239 public HttpsURL(String host, String path, String query, String fragment) 240 throws URIException { 241 242 this(null, host, -1, path, query, fragment); 243 checkValid(); 244 } 245 246 247 258 public HttpsURL(String userinfo, String host, String path, String query, 259 String fragment) throws URIException { 260 261 this(userinfo, host, -1, path, query, fragment); 262 checkValid(); 263 } 264 265 266 276 public HttpsURL(String userinfo, String host, int port, String path) 277 throws URIException { 278 279 this(userinfo, host, port, path, null, null); 280 checkValid(); 281 } 282 283 284 295 public HttpsURL(String userinfo, String host, int port, String path, 296 String query) throws URIException { 297 298 this(userinfo, host, port, path, query, null); 299 checkValid(); 300 } 301 302 303 315 public HttpsURL(String userinfo, String host, int port, String path, 316 String query, String fragment) throws URIException { 317 318 StringBuffer buff = new StringBuffer (); 320 if (userinfo != null || host != null || port != -1) { 321 _scheme = DEFAULT_SCHEME; buff.append(_default_scheme); 323 buff.append("://"); 324 if (userinfo != null) { 325 buff.append(URIUtil.encode(userinfo, URI.allowed_userinfo)); 326 buff.append('@'); 327 } 328 if (host != null) { 329 buff.append(URIUtil.encode(host, URI.allowed_host)); 330 if (port != -1 || port != DEFAULT_PORT) { 331 buff.append(':'); 332 buff.append(port); 333 } 334 } 335 } 336 if (path != null) { if (scheme != null && !path.startsWith("/")) { 338 throw new URIException(URIException.PARSING, 339 "abs_path requested"); 340 } 341 buff.append(URIUtil.encode(path, URI.allowed_abs_path)); 342 } 343 if (query != null) { 344 buff.append('?'); 345 buff.append(URIUtil.encode(query, URI.allowed_query)); 346 } 347 if (fragment != null) { 348 buff.append('#'); 349 buff.append(URIUtil.encode(fragment, URI.allowed_fragment)); 350 } 351 parseUriReference(buff.toString(), true); 352 checkValid(); 353 } 354 355 356 363 public HttpsURL(HttpsURL base, String relative) throws URIException { 364 this(base, new HttpsURL(relative)); 365 } 366 367 368 375 public HttpsURL(HttpsURL base, HttpsURL relative) throws URIException { 376 super(base, relative); 377 checkValid(); 378 } 379 380 382 385 public static final char[] DEFAULT_SCHEME = { 'h', 't', 't', 'p', 's' }; 386 387 392 public static final char[] _default_scheme = DEFAULT_SCHEME; 393 394 395 398 public static final int DEFAULT_PORT = 443; 399 400 405 public static final int _default_port = DEFAULT_PORT; 406 407 408 411 static final long serialVersionUID = 887844277028676648L; 412 413 415 420 public char[] getRawScheme() { 421 return (_scheme == null) ? null : HttpsURL.DEFAULT_SCHEME; 422 } 423 424 425 430 public String getScheme() { 431 return (_scheme == null) ? null : new String (HttpsURL.DEFAULT_SCHEME); 432 } 433 434 436 440 public int getPort() { 441 return (_port == -1) ? HttpsURL.DEFAULT_PORT : _port; 442 } 443 444 446 451 protected void checkValid() throws URIException { 452 if (!(equals(_scheme, DEFAULT_SCHEME) || _scheme == null)) { 454 throw new URIException(URIException.PARSING, "wrong class use"); 455 } 456 } 457 458 } 459 460 | Popular Tags |