View Javadoc
1 /* 2 * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpURL.java,v 1.12.2.2 2004/02/11 23:20:17 olegk Exp $ 3 * $Revision: 1.12.2.2 $ 4 * $Date: 2004/02/11 23:20:17 $ 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 HTTP 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 HttpURL extends URI { 73 74 // ----------------------------------------------------------- Constructors 75 76 /*** Create an instance as an internal use. */ 77 protected HttpURL() { 78 } 79 80 81 /*** 82 * Construct a HTTP URL as an escaped form of a character array with the 83 * given charset to do escape encoding. 84 * 85 * @param escaped the HTTP URL character sequence 86 * @param charset the charset string to do escape encoding 87 * @throws URIException If {@link #checkValid()} fails 88 * @throws NullPointerException if <code>escaped</code> is <code>null</code> 89 * @see #getProtocolCharset 90 */ 91 public HttpURL(char[] escaped, String charset) 92 throws URIException, NullPointerException { 93 protocolCharset = charset; 94 parseUriReference(new String(escaped), true); 95 checkValid(); 96 } 97 98 99 /*** 100 * Construct a HTTP URL as an escaped form of a character array. 101 * 102 * @param escaped the HTTP URL character sequence 103 * @throws URIException If {@link #checkValid()} fails 104 * @throws NullPointerException if <code>escaped</code> is <code>null</code> 105 * @see #getDefaultProtocolCharset 106 */ 107 public HttpURL(char[] escaped) throws URIException, NullPointerException { 108 parseUriReference(new String(escaped), true); 109 checkValid(); 110 } 111 112 113 /*** 114 * Construct a HTTP URL from a given string with the given charset to do 115 * escape encoding. 116 * 117 * @param original the HTTP URL string 118 * @param charset the charset string to do escape encoding 119 * @throws URIException If {@link #checkValid()} fails 120 * @see #getProtocolCharset 121 */ 122 public HttpURL(String original, String charset) throws URIException { 123 protocolCharset = charset; 124 parseUriReference(original, false); 125 checkValid(); 126 } 127 128 129 /*** 130 * Construct a HTTP URL from a given string. 131 * 132 * @param original the HTTP URL string 133 * @throws URIException If {@link #checkValid()} fails 134 * @see #getDefaultProtocolCharset 135 */ 136 public HttpURL(String original) throws URIException { 137 parseUriReference(original, false); 138 checkValid(); 139 } 140 141 142 /*** 143 * Construct a HTTP URL from given components. 144 * 145 * @param host the host string 146 * @param port the port number 147 * @param path the path string 148 * @throws URIException If {@link #checkValid()} fails 149 * @see #getDefaultProtocolCharset 150 */ 151 public HttpURL(String host, int port, String path) throws URIException { 152 this(null, host, port, path, null, null); 153 checkValid(); 154 } 155 156 157 /*** 158 * Construct a HTTP URL from given components. 159 * 160 * @param host the host string 161 * @param port the port number 162 * @param path the path string 163 * @param query the query string 164 * @throws URIException If {@link #checkValid()} fails 165 * @see #getDefaultProtocolCharset 166 */ 167 public HttpURL(String host, int port, String path, String query) 168 throws URIException { 169 170 this(null, host, port, path, query, null); 171 checkValid(); 172 } 173 174 175 /*** 176 * Construct a HTTP URL from given components. 177 * 178 * @param user the user name 179 * @param password his or her password 180 * @param host the host string 181 * @throws URIException If {@link #checkValid()} fails 182 * @see #getDefaultProtocolCharset 183 */ 184 public HttpURL(String user, String password, String host) 185 throws URIException { 186 187 this((user == null) ? null : user 188 + ((password == null) ? "" : ':' + password), 189 host, -1, null, null, null); 190 checkValid(); 191 } 192 193 194 /*** 195 * Construct a HTTP URL from given components. 196 * 197 * @param user the user name 198 * @param password his or her password 199 * @param host the host string 200 * @param port the port number 201 * @throws URIException If {@link #checkValid()} fails 202 * @see #getDefaultProtocolCharset 203 */ 204 public HttpURL(String user, String password, String host, int port) 205 throws URIException { 206 207 this((user == null) ? null : user 208 + ((password == null) ? "" : ':' + password), 209 host, port, null, null, null); 210 checkValid(); 211 } 212 213 214 /*** 215 * Construct a HTTP URL from given components. 216 * 217 * @param user the user name 218 * @param password his or her password 219 * @param host the host string 220 * @param port the port number 221 * @param path the path string 222 * @throws URIException If {@link #checkValid()} fails 223 * @see #getDefaultProtocolCharset 224 */ 225 public HttpURL(String user, String password, String host, int port, 226 String path) throws URIException { 227 228 this((user == null) ? null : user 229 + ((password == null) ? "" : ':' + password), 230 host, port, path, null, null); 231 checkValid(); 232 } 233 234 235 /*** 236 * Construct a HTTP URL from given components. 237 * 238 * @param user the user name 239 * @param password his or her password 240 * @param host the host string 241 * @param port the port number 242 * @param path the path string 243 * @param query The query string. 244 * @throws URIException If {@link #checkValid()} fails 245 * @see #getDefaultProtocolCharset 246 */ 247 public HttpURL(String user, String password, String host, int port, 248 String path, String query) throws URIException { 249 250 this((user == null) ? null : user 251 + ((password == null) ? "" : ':' + password), 252 host, port, path, query, null); 253 checkValid(); 254 } 255 256 257 /*** 258 * Construct a HTTP URL from given components. 259 * 260 * @param host the host string 261 * @param path the path string 262 * @param query the query string 263 * @param fragment the fragment string 264 * @throws URIException If {@link #checkValid()} fails 265 * @see #getDefaultProtocolCharset 266 */ 267 public HttpURL(String host, String path, String query, String fragment) 268 throws URIException { 269 270 this(null, host, -1, path, query, fragment); 271 checkValid(); 272 } 273 274 275 /*** 276 * Construct a HTTP URL from given components. 277 * 278 * @param userinfo the userinfo string 279 * @param host the host string 280 * @param path the path string 281 * @param query the query string 282 * @param fragment the fragment string 283 * @throws URIException If {@link #checkValid()} fails 284 * @see #getDefaultProtocolCharset 285 */ 286 public HttpURL(String userinfo, String host, String path, String query, 287 String fragment) throws URIException { 288 289 this(userinfo, host, -1, path, query, fragment); 290 checkValid(); 291 } 292 293 294 /*** 295 * Construct a HTTP URL from given components. 296 * 297 * @param userinfo the userinfo string 298 * @param host the host string 299 * @param port the port number 300 * @param path the path string 301 * @throws URIException If {@link #checkValid()} fails 302 * @see #getDefaultProtocolCharset 303 */ 304 public HttpURL(String userinfo, String host, int port, String path) 305 throws URIException { 306 307 this(userinfo, host, port, path, null, null); 308 checkValid(); 309 } 310 311 312 /*** 313 * Construct a HTTP URL from given components. 314 * 315 * @param userinfo the userinfo string 316 * @param host the host string 317 * @param port the port number 318 * @param path the path string 319 * @param query the query string 320 * @throws URIException If {@link #checkValid()} fails 321 * @see #getDefaultProtocolCharset 322 */ 323 public HttpURL(String userinfo, String host, int port, String path, 324 String query) throws URIException { 325 326 this(userinfo, host, port, path, query, null); 327 checkValid(); 328 } 329 330 331 /*** 332 * Construct a HTTP URL from given components. 333 * 334 * @param userinfo the userinfo string 335 * @param host the host string 336 * @param port the port number 337 * @param path the path string 338 * @param query the query string 339 * @param fragment the fragment string 340 * @throws URIException If {@link #checkValid()} fails 341 * @see #getDefaultProtocolCharset 342 */ 343 public HttpURL(String userinfo, String host, int port, String path, 344 String query, String fragment) throws URIException { 345 346 // validate and contruct the URI character sequence 347 StringBuffer buff = new StringBuffer(); 348 if (userinfo != null || host != null || port != -1) { 349 _scheme = DEFAULT_SCHEME; // in order to verify the own protocol 350 buff.append(_default_scheme); 351 buff.append("://"); 352 if (userinfo != null) { 353 buff.append(userinfo); 354 buff.append('@'); 355 } 356 if (host != null) { 357 buff.append(host); 358 if (port != -1 || port != DEFAULT_PORT) { 359 buff.append(':'); 360 buff.append(port); 361 } 362 } 363 } 364 if (path != null) { // accept empty path 365 if (scheme != null && !path.startsWith("/")) { 366 throw new URIException(URIException.PARSING, 367 "abs_path requested"); 368 } 369 buff.append(path); 370 } 371 if (query != null) { 372 buff.append('?'); 373 buff.append(query); 374 } 375 if (fragment != null) { 376 buff.append('#'); 377 buff.append(fragment); 378 } 379 parseUriReference(buff.toString(), false); 380 checkValid(); 381 } 382 383 384 /*** 385 * Construct a HTTP URL with a given relative URL string. 386 * 387 * @param base the base HttpURL 388 * @param relative the relative HTTP URL string 389 * @throws URIException If {@link #checkValid()} fails 390 */ 391 public HttpURL(HttpURL base, String relative) throws URIException { 392 this(base, new HttpURL(relative)); 393 } 394 395 396 /*** 397 * Construct a HTTP URL with a given relative URL. 398 * 399 * @param base the base HttpURL 400 * @param relative the relative HttpURL 401 * @throws URIException If {@link #checkValid()} fails 402 */ 403 public HttpURL(HttpURL base, HttpURL relative) throws URIException { 404 super(base, relative); 405 checkValid(); 406 } 407 408 // -------------------------------------------------------------- Constants 409 410 /*** 411 * Default scheme for HTTP URL. 412 */ 413 public static final char[] DEFAULT_SCHEME = { 'h', 't', 't', 'p' }; 414 415 /*** 416 * Default scheme for HTTP URL. 417 * @deprecated Use {@link #DEFAULT_SCHEME} instead. This one doesn't 418 * conform to the project naming conventions. 419 */ 420 public static final char[] _default_scheme = DEFAULT_SCHEME; 421 422 /*** 423 * Default port for HTTP URL. 424 */ 425 public static final int DEFAULT_PORT = 80; 426 427 /*** 428 * Default port for HTTP URL. 429 * @deprecated Use {@link #DEFAULT_PORT} instead. This one doesn't conform 430 * to the project naming conventions. 431 */ 432 public static final int _default_port = DEFAULT_PORT; 433 434 /*** 435 * The serialVersionUID. 436 */ 437 static final long serialVersionUID = -7158031098595039459L; 438 439 // ------------------------------------------------------------- The scheme 440 441 /*** 442 * Get the scheme. You can get the scheme explicitly. 443 * 444 * @return the scheme 445 */ 446 public char[] getRawScheme() { 447 return (_scheme == null) ? null : HttpURL.DEFAULT_SCHEME; 448 } 449 450 451 /*** 452 * Get the scheme. You can get the scheme explicitly. 453 * 454 * @return the scheme null if empty or undefined 455 */ 456 public String getScheme() { 457 return (_scheme == null) ? null : new String(HttpURL.DEFAULT_SCHEME); 458 } 459 460 // --------------------------------------------------------------- The port 461 462 /*** 463 * Get the port number. 464 * @return the port number 465 */ 466 public int getPort() { 467 return (_port == -1) ? HttpURL.DEFAULT_PORT : _port; 468 } 469 470 // ----------------------------------------------------------- The userinfo 471 472 /*** 473 * Set the raw-escaped user and password. 474 * 475 * @param escapedUser the raw-escaped user 476 * @param escapedPassword the raw-escaped password; could be null 477 * @throws URIException escaped user not valid or user required; escaped 478 * password not valid or username missed 479 */ 480 public void setRawUserinfo(char[] escapedUser, char[] escapedPassword) 481 throws URIException { 482 483 if (escapedUser == null || escapedUser.length == 0) { 484 throw new URIException(URIException.PARSING, "user required"); 485 } 486 if (!validate(escapedUser, within_userinfo) 487 || ((escapedPassword != null) 488 && !validate(escapedPassword, within_userinfo))) { 489 throw new URIException(URIException.ESCAPING, 490 "escaped userinfo not valid"); 491 } 492 String username = new String(escapedUser); 493 String password = (escapedPassword == null) 494 ? null : new String(escapedPassword); 495 String userinfo = username + ((password == null) ? "" : ":" + password); 496 String hostname = new String(getRawHost()); 497 String hostport = (_port == -1) ? hostname : hostname + ":" + _port; 498 String authority = userinfo + "@" + hostport; 499 _userinfo = userinfo.toCharArray(); 500 _authority = authority.toCharArray(); 501 setURI(); 502 } 503 504 505 /*** 506 * Set the raw-escaped user and password. 507 * 508 * @param escapedUser the escaped user 509 * @param escapedPassword the escaped password; could be null 510 * @throws URIException escaped user not valid or user required; escaped 511 * password not valid or username missed 512 * @throws NullPointerException null user 513 */ 514 public void setEscapedUserinfo(String escapedUser, String escapedPassword) 515 throws URIException, NullPointerException { 516 517 setRawUserinfo(escapedUser.toCharArray(), (escapedPassword == null) 518 ? null : escapedPassword.toCharArray()); 519 } 520 521 522 /*** 523 * Set the user and password. 524 * 525 * @param user the user 526 * @param password the password; could be null 527 * @throws URIException encoding error or username missed 528 * @throws NullPointerException null user 529 */ 530 public void setUserinfo(String user, String password) 531 throws URIException, NullPointerException { 532 // set the charset to do escape encoding 533 String charset = getProtocolCharset(); 534 setRawUserinfo(encode(user, within_userinfo, charset), 535 (password == null) 536 ? null 537 : encode(password, within_userinfo, charset)); 538 } 539 540 541 /*** 542 * Set the raw-escaped user. 543 * 544 * @param escapedUser the raw-escaped user 545 * @throws URIException escaped user not valid or user required 546 */ 547 public void setRawUser(char[] escapedUser) throws URIException { 548 if (escapedUser == null || escapedUser.length == 0) { 549 throw new URIException(URIException.PARSING, "user required"); 550 } 551 if (!validate(escapedUser, within_userinfo)) { 552 throw new URIException(URIException.ESCAPING, 553 "escaped user not valid"); 554 } 555 String username = new String(escapedUser); 556 String password = new String(getRawPassword()); 557 String userinfo = username + ((password == null) ? "" : ":" + password); 558 String hostname = new String(getRawHost()); 559 String hostport = (_port == -1) ? hostname : hostname + ":" + _port; 560 String authority = userinfo + "@" + hostport; 561 _userinfo = userinfo.toCharArray(); 562 _authority = authority.toCharArray(); 563 setURI(); 564 } 565 566 567 /*** 568 * Set the escaped user string. 569 * 570 * @param escapedUser the escaped user string 571 * @throws URIException escaped user not valid 572 * @throws NullPointerException null user 573 */ 574 public void setEscapedUser(String escapedUser) 575 throws URIException, NullPointerException { 576 setRawUser(escapedUser.toCharArray()); 577 } 578 579 580 /*** 581 * Set the user string. 582 * 583 * @param user the user string 584 * @throws URIException user encoding error 585 * @throws NullPointerException null user 586 */ 587 public void setUser(String user) throws URIException, NullPointerException { 588 setRawUser(encode(user, allowed_within_userinfo, getProtocolCharset())); 589 } 590 591 592 /*** 593 * Get the raw-escaped user. 594 * 595 * @return the raw-escaped user 596 */ 597 public char[] getRawUser() { 598 if (_userinfo == null || _userinfo.length == 0) { 599 return null; 600 } 601 int to = indexFirstOf(_userinfo, ':'); 602 // String.indexOf(':', 0, _userinfo.length, _userinfo, 0, 1, 0); 603 if (to == -1) { 604 return _userinfo; // only user. 605 } 606 char[] result = new char[to]; 607 System.arraycopy(_userinfo, 0, result, 0, to); 608 return result; 609 } 610 611 612 /*** 613 * Get the escaped user 614 * 615 * @return the escaped user 616 */ 617 public String getEscapedUser() { 618 char[] user = getRawUser(); 619 return (user == null) ? null : new String(user); 620 } 621 622 623 /*** 624 * Get the user. 625 * 626 * @return the user name 627 * @throws URIException If {@link #decode} fails 628 */ 629 public String getUser() throws URIException { 630 char[] user = getRawUser(); 631 return (user == null) ? null : decode(user, getProtocolCharset()); 632 } 633 634 635 /*** 636 * Set the raw-escaped password. 637 * 638 * @param escapedPassword the raw-escaped password; could be null 639 * @throws URIException escaped password not valid or username missed 640 */ 641 public void setRawPassword(char[] escapedPassword) throws URIException { 642 if (escapedPassword != null 643 && !validate(escapedPassword, within_userinfo)) { 644 throw new URIException(URIException.ESCAPING, 645 "escaped password not valid"); 646 } 647 if (getRawUser() == null || getRawUser().length == 0) { 648 throw new URIException(URIException.PARSING, "username required"); 649 } 650 String username = new String(getRawUser()); 651 String password = new String(escapedPassword); 652 // an emtpy string is allowed as a password 653 String userinfo = username + ((password == null) ? "" : ":" + password); 654 String hostname = new String(getRawHost()); 655 String hostport = (_port == -1) ? hostname : hostname + ":" + _port; 656 String authority = userinfo + "@" + hostport; 657 _userinfo = userinfo.toCharArray(); 658 _authority = authority.toCharArray(); 659 setURI(); 660 } 661 662 663 /*** 664 * Set the escaped password string. 665 * 666 * @param escapedPassword the escaped password string; could be null 667 * @throws URIException escaped password not valid or username missed 668 */ 669 public void setEscapedPassword(String escapedPassword) throws URIException { 670 setRawPassword((escapedPassword == null) ? null 671 : escapedPassword.toCharArray()); 672 } 673 674 675 /*** 676 * Set the password string. 677 * 678 * @param password the password string; could be null 679 * @throws URIException encoding error or username missed 680 */ 681 public void setPassword(String password) throws URIException { 682 setRawPassword((password == null) ? null : encode(password, 683 allowed_within_userinfo, getProtocolCharset())); 684 } 685 686 687 /*** 688 * Get the raw-escaped password. 689 * 690 * @return the raw-escaped password 691 */ 692 public char[] getRawPassword() { 693 int from = indexFirstOf(_userinfo, ':'); 694 if (from == -1) { 695 return null; // null or only user. 696 } 697 int len = _userinfo.length - from - 1; 698 char[] result = new char[len]; 699 System.arraycopy(_userinfo, from + 1, result, 0, len); 700 return result; 701 } 702 703 704 /*** 705 * Get the escaped password. 706 * 707 * @return the escaped password 708 */ 709 public String getEscapedPassword() { 710 char[] password = getRawPassword(); 711 return (password == null) ? null : new String(password); 712 } 713 714 715 /*** 716 * Get the password. 717 * 718 * @return the password 719 * @throws URIException If {@link #decode(char[],String)} fails. 720 */ 721 public String getPassword() throws URIException { 722 char[] password = getRawPassword(); 723 return (password == null) ? null : decode(password, 724 getProtocolCharset()); 725 } 726 727 // --------------------------------------------------------------- The path 728 729 /*** 730 * Get the raw-escaped current hierarchy level. 731 * 732 * @return the raw-escaped current hierarchy level 733 * @throws URIException If {@link #getRawCurrentHierPath(char[])} fails. 734 */ 735 public char[] getRawCurrentHierPath() throws URIException { 736 return (_path == null || _path.length == 0) ? rootPath 737 : super.getRawCurrentHierPath(_path); 738 } 739 740 741 /*** 742 * Get the level above the this hierarchy level. 743 * 744 * @return the raw above hierarchy level 745 * @throws URIException If {@link #getRawCurrentHierPath(char[])} fails. 746 */ 747 public char[] getRawAboveHierPath() throws URIException { 748 char[] path = getRawCurrentHierPath(); 749 return (path == null || path.length == 0) ? rootPath : getRawCurrentHierPath(path); 750 } 751 752 753 /*** 754 * Get the raw escaped path. 755 * 756 * @return the path '/' if empty or undefined 757 */ 758 public char[] getRawPath() { 759 char[] path = super.getRawPath(); 760 return (path == null || path.length == 0) ? rootPath : path; 761 } 762 763 // -------------------------------------------------------------- The query 764 765 /*** 766 * Set the query as the name and value pair. 767 * 768 * @param queryName the query string. 769 * @param queryValue the query string. 770 * @throws URIException incomplete trailing escape pattern 771 * Or unsupported character encoding 772 * @throws NullPointerException null query 773 * @see #encode 774 */ 775 public void setQuery(String queryName, String queryValue) 776 throws URIException, NullPointerException { 777 778 StringBuffer buff = new StringBuffer(); 779 // set the charset to do escape encoding 780 String charset = getProtocolCharset(); 781 buff.append(encode(queryName, allowed_within_query, charset)); 782 buff.append('='); 783 buff.append(encode(queryValue, allowed_within_query, charset)); 784 _query = buff.toString().toCharArray(); 785 setURI(); 786 } 787 788 789 /*** 790 * Set the query as the name and value pairs. 791 * 792 * @param queryName the array of the query string. 793 * @param queryValue the array of the query string. 794 * @throws URIException incomplete trailing escape pattern, 795 * unsupported character encoding or wrong array size 796 * @throws NullPointerException null query 797 * @see #encode 798 */ 799 public void setQuery(String[] queryName, String[] queryValue) 800 throws URIException, NullPointerException { 801 802 int length = queryName.length; 803 if (length != queryValue.length) { 804 throw new URIException("wrong array size of query"); 805 } 806 807 StringBuffer buff = new StringBuffer(); 808 // set the charset to do escape encoding 809 String charset = getProtocolCharset(); 810 for (int i = 0; i < length; i++) { 811 buff.append(encode(queryName[i], allowed_within_query, charset)); 812 buff.append('='); 813 buff.append(encode(queryValue[i], allowed_within_query, charset)); 814 if (i + 1 < length) { 815 buff.append('&'); 816 } 817 } 818 _query = buff.toString().toCharArray(); 819 setURI(); 820 } 821 822 // ---------------------------------------------------------------- Utility 823 824 /*** 825 * Verify the valid class use for construction. 826 * 827 * @throws URIException the wrong scheme use 828 */ 829 protected void checkValid() throws URIException { 830 // could be explicit protocol or undefined. 831 if (!(equals(_scheme, DEFAULT_SCHEME) || _scheme == null)) { 832 throw new URIException(URIException.PARSING, "wrong class use"); 833 } 834 } 835 836 } 837

This page was automatically generated by Maven