View Javadoc
1 /* 2 * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpsURL.java,v 1.6.2.1 2004/01/29 18:33:32 oglueck Exp $ 3 * $Revision: 1.6.2.1 $ 4 * $Date: 2004/01/29 18:33:32 $ 5 * 6 * ==================================================================== 7 * 8 * The Apache Software License, Version 1.1 9 * 10 * Copyright (c) 2002-2003 The Apache Software Foundation. All rights 11 * reserved. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 20 * 2. Redistributions in binary form must reproduce the above copyright 21 * notice, this list of conditions and the following disclaimer in 22 * the documentation and/or other materials provided with the 23 * distribution. 24 * 25 * 3. The end-user documentation included with the redistribution, if 26 * any, must include the following acknowlegement: 27 * "This product includes software developed by the 28 * Apache Software Foundation (http://www.apache.org/)." 29 * Alternately, this acknowlegement may appear in the software itself, 30 * if and wherever such third-party acknowlegements normally appear. 31 * 32 * 4. The names "The Jakarta Project", "Commons", and "Apache Software 33 * Foundation" must not be used to endorse or promote products derived 34 * from this software without prior written permission. For written 35 * permission, please contact apache@apache.org. 36 * 37 * 5. Products derived from this software may not be called "Apache" 38 * nor may "Apache" appear in their names without prior written 39 * permission of the Apache Group. 40 * 41 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 42 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 43 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 44 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 45 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 47 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 48 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 49 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 50 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 51 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 52 * SUCH DAMAGE. 53 * ==================================================================== 54 * 55 * This software consists of voluntary contributions made by many 56 * individuals on behalf of the Apache Software Foundation. For more 57 * information on the Apache Software Foundation, please see 58 * <http://www.apache.org/>. 59 * 60 * [Additional notices, if required by prior licensing conditions] 61 * 62 */ 63 64 package org.apache.commons.httpclient; 65 66 /*** 67 * The HTTPS URL. 68 * 69 * @author <a href="mailto:jericho at apache.org">Sung-Gu</a> 70 * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a> 71 */ 72 public class HttpsURL extends HttpURL { 73 74 // ----------------------------------------------------------- Constructors 75 76 /*** 77 * Create an instance as an internal use. 78 */ 79 protected HttpsURL() { 80 } 81 82 83 /*** 84 * Construct a HTTPS URL as an escaped form of a character array with the 85 * given charset to do escape encoding. 86 * 87 * @param escaped the HTTPS URL character sequence 88 * @param charset the charset to do escape encoding 89 * @throws URIException If {@link #checkValid()} fails 90 * @throws NullPointerException if <code>escaped</code> is <code>null</code> 91 * @see #getProtocolCharset 92 */ 93 public HttpsURL(char[] escaped, String charset) 94 throws URIException, NullPointerException { 95 protocolCharset = charset; 96 parseUriReference(new String(escaped), true); 97 checkValid(); 98 } 99 100 101 /*** 102 * Construct a HTTPS URL as an escaped form of a character array. 103 * 104 * @param escaped the HTTPS URL character sequence 105 * @throws URIException If {@link #checkValid()} fails 106 * @throws NullPointerException if <code>escaped</code> is <code>null</code> 107 * @see #getDefaultProtocolCharset 108 */ 109 public HttpsURL(char[] escaped) throws URIException, NullPointerException { 110 parseUriReference(new String(escaped), true); 111 checkValid(); 112 } 113 114 115 /*** 116 * Construct a HTTPS URL from a given string with the given charset to do 117 * escape encoding. 118 * 119 * @param original the HTTPS URL string 120 * @param charset the charset to do escape encoding 121 * @throws URIException If {@link #checkValid()} fails 122 * @see #getProtocolCharset 123 */ 124 public HttpsURL(String original, String charset) throws URIException { 125 protocolCharset = charset; 126 parseUriReference(original, false); 127 checkValid(); 128 } 129 130 131 /*** 132 * Construct a HTTPS URL from a given string. 133 * 134 * @param original the HTTPS URL string 135 * @throws URIException If {@link #checkValid()} fails 136 * @see #getDefaultProtocolCharset 137 */ 138 public HttpsURL(String original) throws URIException { 139 parseUriReference(original, false); 140 checkValid(); 141 } 142 143 144 /*** 145 * Construct a HTTPS URL from given components. 146 * 147 * @param host the host string 148 * @param port the port number 149 * @param path the path string 150 * @throws URIException If {@link #checkValid()} fails 151 * @see #getDefaultProtocolCharset 152 */ 153 public HttpsURL(String host, int port, String path) throws URIException { 154 this(null, host, port, path, null, null); 155 checkValid(); 156 } 157 158 159 /*** 160 * Construct a HTTPS URL from given components. 161 * 162 * @param host the host string 163 * @param port the port number 164 * @param path the path string 165 * @param query the query string 166 * @throws URIException If {@link #checkValid()} fails 167 * @see #getDefaultProtocolCharset 168 */ 169 public HttpsURL(String host, int port, String path, String query) 170 throws URIException { 171 172 this(null, host, port, path, query, null); 173 checkValid(); 174 } 175 176 177 /*** 178 * Construct a HTTPS URL from given components. 179 * 180 * @param user the user name 181 * @param password his or her password 182 * @param host the host string 183 * @throws URIException If {@link #checkValid()} fails 184 * @see #getDefaultProtocolCharset 185 */ 186 public HttpsURL(String user, String password, String host) 187 throws URIException { 188 189 this((user == null) ? null : user 190 + ((password == null) ? "" : ':' + password), 191 host, -1, null, null, null); 192 checkValid(); 193 } 194 195 196 /*** 197 * Construct a HTTPS URL from given components. 198 * 199 * @param user the user name 200 * @param password his or her password 201 * @param host the host string 202 * @param port the port number 203 * @throws URIException If {@link #checkValid()} fails 204 * @see #getDefaultProtocolCharset 205 */ 206 public HttpsURL(String user, String password, String host, int port) 207 throws URIException { 208 209 this((user == null) ? null : user 210 + ((password == null) ? "" : ':' + password), 211 host, port, null, null, null); 212 checkValid(); 213 } 214 215 216 /*** 217 * Construct a HTTPS URL from given components. 218 * 219 * @param user the user name 220 * @param password his or her password 221 * @param host the host string 222 * @param port the port number 223 * @param path the path string 224 * @throws URIException If {@link #checkValid()} fails 225 * @see #getDefaultProtocolCharset 226 */ 227 public HttpsURL(String user, String password, String host, int port, 228 String path) throws URIException { 229 230 this((user == null) ? null : user 231 + ((password == null) ? "" : ':' + password), 232 host, port, path, null, null); 233 checkValid(); 234 } 235 236 237 /*** 238 * Construct a HTTPS URL from given components. 239 * 240 * @param user the user name 241 * @param password his or her password 242 * @param host the host string 243 * @param port the port number 244 * @param path the path string 245 * @param query The query string. 246 * @throws URIException If {@link #checkValid()} fails 247 * @see #getDefaultProtocolCharset 248 */ 249 public HttpsURL(String user, String password, String host, int port, 250 String path, String query) throws URIException { 251 252 this((user == null) ? null : user 253 + ((password == null) ? "" : ':' + password), 254 host, port, path, query, null); 255 checkValid(); 256 } 257 258 259 /*** 260 * Construct a HTTPS URL from given components. 261 * 262 * @param host the host string 263 * @param path the path string 264 * @param query the query string 265 * @param fragment the fragment string 266 * @throws URIException If {@link #checkValid()} fails 267 * @see #getDefaultProtocolCharset 268 */ 269 public HttpsURL(String host, String path, String query, String fragment) 270 throws URIException { 271 272 this(null, host, -1, path, query, fragment); 273 checkValid(); 274 } 275 276 277 /*** 278 * Construct a HTTPS URL from given components. 279 * 280 * @param userinfo the userinfo string 281 * @param host the host string 282 * @param path the path string 283 * @param query the query string 284 * @param fragment the fragment string 285 * @throws URIException If {@link #checkValid()} fails 286 * @see #getDefaultProtocolCharset 287 */ 288 public HttpsURL(String userinfo, String host, String path, String query, 289 String fragment) throws URIException { 290 291 this(userinfo, host, -1, path, query, fragment); 292 checkValid(); 293 } 294 295 296 /*** 297 * Construct a HTTPS URL from given components. 298 * 299 * @param userinfo the userinfo string 300 * @param host the host string 301 * @param port the port number 302 * @param path the path string 303 * @throws URIException If {@link #checkValid()} fails 304 * @see #getDefaultProtocolCharset 305 */ 306 public HttpsURL(String userinfo, String host, int port, String path) 307 throws URIException { 308 309 this(userinfo, host, port, path, null, null); 310 checkValid(); 311 } 312 313 314 /*** 315 * Construct a HTTPS URL from given components. 316 * 317 * @param userinfo the userinfo string 318 * @param host the host string 319 * @param port the port number 320 * @param path the path string 321 * @param query the query string 322 * @throws URIException If {@link #checkValid()} fails 323 * @see #getDefaultProtocolCharset 324 */ 325 public HttpsURL(String userinfo, String host, int port, String path, 326 String query) throws URIException { 327 328 this(userinfo, host, port, path, query, null); 329 checkValid(); 330 } 331 332 333 /*** 334 * Construct a HTTPS URL from given components. 335 * 336 * @param userinfo the userinfo string 337 * @param host the host string 338 * @param port the port number 339 * @param path the path string 340 * @param query the query string 341 * @param fragment the fragment string 342 * @throws URIException If {@link #checkValid()} fails 343 * @see #getDefaultProtocolCharset 344 */ 345 public HttpsURL(String userinfo, String host, int port, String path, 346 String query, String fragment) throws URIException { 347 348 // validate and contruct the URI character sequence 349 StringBuffer buff = new StringBuffer(); 350 if (userinfo != null || host != null || port != -1) { 351 _scheme = DEFAULT_SCHEME; // in order to verify the own protocol 352 buff.append(_default_scheme); 353 buff.append("://"); 354 if (userinfo != null) { 355 buff.append(userinfo); 356 buff.append('@'); 357 } 358 if (host != null) { 359 buff.append(host); 360 if (port != -1 || port != DEFAULT_PORT) { 361 buff.append(':'); 362 buff.append(port); 363 } 364 } 365 } 366 if (path != null) { // accept empty path 367 if (scheme != null && !path.startsWith("/")) { 368 throw new URIException(URIException.PARSING, 369 "abs_path requested"); 370 } 371 buff.append(path); 372 } 373 if (query != null) { 374 buff.append('?'); 375 buff.append(query); 376 } 377 if (fragment != null) { 378 buff.append('#'); 379 buff.append(fragment); 380 } 381 parseUriReference(buff.toString(), false); 382 checkValid(); 383 } 384 385 386 /*** 387 * Construct a HTTPS URL with a given relative HTTPS URL string. 388 * 389 * @param base the base HttpsURL 390 * @param relative the relative HTTPS URL string 391 * @throws URIException If {@link #checkValid()} fails 392 */ 393 public HttpsURL(HttpsURL base, String relative) throws URIException { 394 this(base, new HttpsURL(relative)); 395 } 396 397 398 /*** 399 * Construct a HTTPS URL with a given relative URL. 400 * 401 * @param base the base HttpsURL 402 * @param relative the relative HttpsURL 403 * @throws URIException If {@link #checkValid()} fails 404 */ 405 public HttpsURL(HttpsURL base, HttpsURL relative) throws URIException { 406 super(base, relative); 407 checkValid(); 408 } 409 410 // -------------------------------------------------------------- Constants 411 412 /*** 413 * Default scheme for HTTPS URL. 414 */ 415 public static final char[] DEFAULT_SCHEME = { 'h', 't', 't', 'p', 's' }; 416 417 /*** 418 * Default scheme for HTTPS URL. 419 * @deprecated Use {@link #DEFAULT_SCHEME} instead. This one doesn't 420 * conform to the project naming conventions. 421 */ 422 public static final char[] _default_scheme = DEFAULT_SCHEME; 423 424 425 /*** 426 * Default port for HTTPS URL. 427 */ 428 public static final int DEFAULT_PORT = 443; 429 430 /*** 431 * Default port for HTTPS URL. 432 * @deprecated Use {@link #DEFAULT_PORT} instead. This one doesn't conform 433 * to the project naming conventions. 434 */ 435 public static final int _default_port = DEFAULT_PORT; 436 437 438 /*** 439 * The serialVersionUID. 440 */ 441 static final long serialVersionUID = 887844277028676648L; 442 443 // ------------------------------------------------------------- The scheme 444 445 /*** 446 * Get the scheme. You can get the scheme explicitly. 447 * 448 * @return the scheme 449 */ 450 public char[] getRawScheme() { 451 return (_scheme == null) ? null : HttpsURL.DEFAULT_SCHEME; 452 } 453 454 455 /*** 456 * Get the scheme. You can get the scheme explicitly. 457 * 458 * @return the scheme null if empty or undefined 459 */ 460 public String getScheme() { 461 return (_scheme == null) ? null : new String(HttpsURL.DEFAULT_SCHEME); 462 } 463 464 // --------------------------------------------------------------- The port 465 466 /*** 467 * Get the port number. 468 * @return the port number 469 */ 470 public int getPort() { 471 return (_port == -1) ? HttpsURL.DEFAULT_PORT : _port; 472 } 473 474 // ---------------------------------------------------------------- Utility 475 476 /*** 477 * Verify the valid class use for construction. 478 * 479 * @throws URIException the wrong scheme use 480 */ 481 protected void checkValid() throws URIException { 482 // could be explicit protocol or undefined. 483 if (!(equals(_scheme, DEFAULT_SCHEME) || _scheme == null)) { 484 throw new URIException(URIException.PARSING, "wrong class use"); 485 } 486 } 487 488 } 489

This page was automatically generated by Maven