1 36 package com.sslexplorer.vfs.utils; 37 38 import java.io.IOException ; 39 import java.io.Serializable ; 40 41 69 public class URI implements Serializable { 70 71 77 public static class MalformedURIException extends IOException { 78 79 83 public MalformedURIException() { 84 super(); 85 } 86 87 93 public MalformedURIException(String p_msg) { 94 super(p_msg); 95 } 96 } 97 98 99 private static final String RESERVED_CHARACTERS = ";/?:@&=+$,"; 100 101 105 private static final String MARK_CHARACTERS = "-_.!~*'() "; 106 107 108 private static final String SCHEME_CHARACTERS = "+-."; 109 110 113 private static final String USERINFO_CHARACTERS = ";:&=+$,"; 114 115 120 private String m_scheme = null; 121 122 127 private String m_userinfo = null; 128 129 134 private String m_host = null; 135 136 141 private int m_port = -1; 142 143 148 private String m_path = null; 149 150 155 private String m_queryString = null; 156 157 162 private String m_fragment = null; 163 164 165 169 public URI() { 170 } 171 172 178 public URI(URI p_other) { 179 initialize(p_other); 180 } 181 182 195 public URI(String p_uriSpec) throws MalformedURIException { 196 this((URI) null, p_uriSpec); 197 } 198 199 209 public URI(URI p_base, String p_uriSpec) throws MalformedURIException { 210 initialize(p_base, p_uriSpec); 211 } 212 213 223 public URI(String p_scheme, String p_schemeSpecificPart) throws MalformedURIException { 224 225 if (p_scheme == null || p_scheme.trim().length() == 0) { 226 throw new MalformedURIException("Cannot construct URI with null/empty scheme!"); 227 } 228 229 if (p_schemeSpecificPart == null || p_schemeSpecificPart.trim().length() == 0) { 230 throw new MalformedURIException("Cannot construct URI with null/empty scheme-specific part!"); 231 } 232 233 setScheme(p_scheme); 234 setPath(p_schemeSpecificPart); 235 } 236 237 256 public URI(String p_scheme, String p_host, String p_path, String p_queryString, String p_fragment) throws MalformedURIException { 257 this(p_scheme, null, p_host, -1, p_path, p_queryString, p_fragment); 258 } 259 260 282 public URI(String p_scheme, String p_userinfo, String p_host, int p_port, String p_path, String p_queryString, String p_fragment) 283 throws MalformedURIException { 284 285 if (p_scheme == null || p_scheme.trim().length() == 0) { 286 throw new MalformedURIException("Scheme is required!"); 287 } 288 289 if (p_host == null) { 290 if (p_userinfo != null) { 291 throw new MalformedURIException("Userinfo may not be specified if host is not specified!"); 292 } 293 294 if (p_port != -1) { 295 throw new MalformedURIException("Port may not be specified if host is not specified!"); 296 } 297 } 298 299 if (p_path != null) { 300 if (p_path.indexOf('?') != -1 && p_queryString != null) { 301 throw new MalformedURIException("Query string cannot be specified in path and query string!"); 302 } 303 304 if (p_path.indexOf('#') != -1 && p_fragment != null) { 305 throw new MalformedURIException("Fragment cannot be specified in both the path and fragment!"); 306 } 307 } 308 309 setScheme(p_scheme); 310 setHost(p_host); 311 setPort(p_port); 312 setUserinfo(p_userinfo); 313 setPath(p_path); 314 setQueryString(p_queryString); 315 setFragment(p_fragment); 316 } 317 318 323 private void initialize(URI p_other) { 324 325 m_scheme = p_other.getScheme(); 326 m_userinfo = p_other.getUserinfo(); 327 m_host = p_other.getHost(); 328 m_port = p_other.getPort(); 329 m_path = p_other.getPath(); 330 m_queryString = p_other.getQueryString(); 331 m_fragment = p_other.getFragment(); 332 } 333 334 347 private void initialize(URI p_base, String p_uriSpec) throws MalformedURIException { 348 349 if (p_base == null && (p_uriSpec == null || p_uriSpec.trim().length() == 0)) { 350 throw new MalformedURIException("Cannot initialize URI with empty parameters."); 351 } 352 353 if (p_uriSpec == null || p_uriSpec.trim().length() == 0) { 355 initialize(p_base); 356 357 return; 358 } 359 360 String uriSpec = p_uriSpec.trim(); 361 int uriSpecLen = uriSpec.length(); 362 int index = 0; 363 364 if (uriSpec.indexOf(':') == -1) { 366 if (p_base == null) { 367 throw new MalformedURIException("No scheme found in URI: " + uriSpec); 368 } 369 } else { 370 initializeScheme(uriSpec); 371 372 index = m_scheme.length() + 1; 373 } 374 375 if (((index + 1) < uriSpecLen) && (uriSpec.substring(index).startsWith("//"))) { 377 index += 2; 378 379 int startPos = index; 380 381 char testChar = '\0'; 383 384 while (index < uriSpecLen) { 385 testChar = uriSpec.charAt(index); 386 387 if (testChar == '/' || testChar == '?' || testChar == '#') { 388 break; 389 } 390 391 index++; 392 } 393 394 if (index > startPos) { 397 initializeAuthority(uriSpec.substring(startPos, index)); 398 } else { 399 m_host = ""; 400 } 401 } 402 403 initializePath(uriSpec.substring(index)); 404 405 if (p_base != null) { 411 412 if (m_path.length() == 0 && m_scheme == null && m_host == null) { 420 m_scheme = p_base.getScheme(); 421 m_userinfo = p_base.getUserinfo(); 422 m_host = p_base.getHost(); 423 m_port = p_base.getPort(); 424 m_path = p_base.getPath(); 425 426 if (m_queryString == null) { 427 m_queryString = p_base.getQueryString(); 428 } 429 430 return; 431 } 432 433 if (m_scheme == null) { 436 m_scheme = p_base.getScheme(); 437 } else { 438 return; 439 } 440 441 if (m_host == null) { 444 m_userinfo = p_base.getUserinfo(); 445 m_host = p_base.getHost(); 446 m_port = p_base.getPort(); 447 } else { 448 return; 449 } 450 451 if (m_path.length() > 0 && m_path.startsWith("/")) { 453 return; 454 } 455 456 String path = new String (); 459 String basePath = p_base.getPath(); 460 461 if (basePath != null) { 463 int lastSlash = basePath.lastIndexOf('/'); 464 465 if (lastSlash != -1) { 466 path = basePath.substring(0, lastSlash + 1); 467 } 468 } 469 470 path = path.concat(m_path); 472 473 index = -1; 475 476 while ((index = path.indexOf("/./")) != -1) { 477 path = path.substring(0, index + 1).concat(path.substring(index + 3)); 478 } 479 480 if (path.endsWith("/.")) { 482 path = path.substring(0, path.length() - 1); 483 } 484 485 index = -1; 488 489 int segIndex = -1; 490 String tempString = null; 491 492 while ((index = path.indexOf("/../")) > 0) { 493 tempString = path.substring(0, path.indexOf("/../")); 494 segIndex = tempString.lastIndexOf('/'); 495 496 if (segIndex != -1) { 497 if (!tempString.substring(segIndex++).equals("..")) { 498 path = path.substring(0, segIndex).concat(path.substring(index + 4)); 499 } 500 } 501 } 502 503 if (path.endsWith("/..")) { 506 tempString = path.substring(0, path.length() - 3); 507 segIndex = tempString.lastIndexOf('/'); 508 509 if (segIndex != -1) { 510 path = path.substring(0, segIndex + 1); 511 } 512 } 513 514 m_path = path; 515 } 516 } 517 518 525 private void initializeScheme(String p_uriSpec) throws MalformedURIException { 526 527 int uriSpecLen = p_uriSpec.length(); 528 int index = 0; 529 String scheme = null; 530 char testChar = '\0'; 531 532 while (index < uriSpecLen) { 533 testChar = p_uriSpec.charAt(index); 534 535 if (testChar == ':' || testChar == '/' || testChar == '?' || testChar == '#') { 536 break; 537 } 538 539 index++; 540 } 541 542 scheme = p_uriSpec.substring(0, index); 543 544 if (scheme.length() == 0) { 545 throw new MalformedURIException("No scheme found in URI."); 546 } else { 547 setScheme(scheme); 548 } 549 } 550 551 559 private void initializeAuthority(String p_uriSpec) throws MalformedURIException { 560 561 int index = 0; 562 int start = 0; 563 int end = p_uriSpec.length(); 564 char testChar = '\0'; 565 String userinfo = null; 566 567 if (p_uriSpec.indexOf('@', start) != -1) { 569 while (index < end) { 570 testChar = p_uriSpec.charAt(index); 571 572 if (testChar == '@') { 573 break; 574 } 575 576 index++; 577 } 578 579 userinfo = p_uriSpec.substring(start, index); 580 581 index++; 582 } 583 584 String host = null; 586 587 start = index; 588 589 while (index < end) { 590 testChar = p_uriSpec.charAt(index); 591 592 if (testChar == ':') { 593 break; 594 } 595 596 index++; 597 } 598 599 host = p_uriSpec.substring(start, index); 600 601 int port = -1; 602 603 if (host.length() > 0) { 604 605 if (testChar == ':') { 607 index++; 608 609 start = index; 610 611 while (index < end) { 612 index++; 613 } 614 615 String portStr = p_uriSpec.substring(start, index); 616 617 if (portStr.length() > 0) { 618 for (int i = 0; i < portStr.length(); i++) { 619 if (!isDigit(portStr.charAt(i))) { 620 throw new MalformedURIException(portStr + " is invalid. Port should only contain digits!"); 621 } 622 } 623 624 try { 625 port = Integer.parseInt(portStr); 626 } catch (NumberFormatException nfe) { 627 628 } 630 } 631 } 632 } 633 634 setHost(host); 635 setPort(port); 636 setUserinfo(userinfo); 637 } 638 639 646 private void initializePath(String p_uriSpec) throws MalformedURIException { 647 648 if (p_uriSpec == null) { 649 throw new MalformedURIException("Cannot initialize path from null string!"); 650 } 651 652 int index = 0; 653 int start = 0; 654 int end = p_uriSpec.length(); 655 char testChar = '\0'; 656 657 while (index < end) { 659 testChar = p_uriSpec.charAt(index); 660 661 if (testChar == '?' || testChar == '#') { 662 break; 663 } 664 665 if (testChar == '%') { 667 if (index + 2 >= end || !isHex(p_uriSpec.charAt(index + 1)) || !isHex(p_uriSpec.charAt(index + 2))) { 668 throw new MalformedURIException("Path contains invalid escape sequence!"); 669 } 670 } 671 683 index++; 684 } 685 686 m_path = p_uriSpec.substring(start, index); 687 688 if (testChar == '?') { 690 index++; 691 692 start = index; 693 694 while (index < end) { 695 testChar = p_uriSpec.charAt(index); 696 697 if (testChar == '#') { 698 break; 699 } 700 701 if (testChar == '%') { 702 if (index + 2 >= end || !isHex(p_uriSpec.charAt(index + 1)) || !isHex(p_uriSpec.charAt(index + 2))) { 703 throw new MalformedURIException("Query string contains invalid escape sequence!"); 704 } 705 } else if (!isReservedCharacter(testChar) && !isUnreservedCharacter(testChar)) { 706 throw new MalformedURIException("Query string contains invalid character:" + testChar); 707 } 708 709 index++; 710 } 711 712 m_queryString = p_uriSpec.substring(start, index); 713 } 714 715 if (testChar == '#') { 717 index++; 718 719 start = index; 720 721 while (index < end) { 722 testChar = p_uriSpec.charAt(index); 723 724 if (testChar == '%') { 725 if (index + 2 >= end || !isHex(p_uriSpec.charAt(index + 1)) || !isHex(p_uriSpec.charAt(index + 2))) { 726 throw new MalformedURIException("Fragment contains invalid escape sequence!"); 727 } 728 } else if (!isReservedCharacter(testChar) && !isUnreservedCharacter(testChar)) { 729 throw new MalformedURIException("Fragment contains invalid character:" + testChar); 730 } 731 732 index++; 733 } 734 735 m_fragment = p_uriSpec.substring(start, index); 736 } 737 } 738 739 744 public String getScheme() { 745 return m_scheme; 746 } 747 748 754 public String getSchemeSpecificPart() { 755 756 StringBuffer schemespec = new StringBuffer (); 757 758 if (m_userinfo != null || m_host != null || m_port != -1) { 759 schemespec.append("//"); 760 } 761 762 if (m_userinfo != null) { 763 schemespec.append(m_userinfo); 764 schemespec.append('@'); 765 } 766 767 if (m_host != null) { 768 schemespec.append(m_host); 769 } 770 771 if (m_port != -1) { 772 schemespec.append(':'); 773 schemespec.append(m_port); 774 } 775 776 if (m_path != null) { 777 schemespec.append((m_path)); 778 } 779 780 if (m_queryString != null) { 781 schemespec.append('?'); 782 schemespec.append(m_queryString); 783 } 784 785 if (m_fragment != null) { 786 schemespec.append('#'); 787 schemespec.append(m_fragment); 788 } 789 790 return schemespec.toString(); 791 } 792 793 public String getSchemeSpecificPartEncoded() { 794 795 StringBuffer schemespec = new StringBuffer (); 796 797 if (m_userinfo != null || m_host != null || m_port != -1) { 798 schemespec.append("//"); 799 } 800 801 if (m_userinfo != null) { 802 schemespec.append(m_userinfo); 803 schemespec.append('@'); 804 } 805 806 if (m_host != null) { 807 schemespec.append(m_host); 808 } 809 810 if (m_port != -1) { 811 schemespec.append(':'); 812 schemespec.append(m_port); 813 } 814 815 if (m_path != null) { 816 schemespec.append((m_path.replaceAll(" ", "%20"))); 817 } 818 819 if (m_queryString != null) { 820 schemespec.append('?'); 821 schemespec.append(m_queryString); 822 } 823 824 if (m_fragment != null) { 825 schemespec.append('#'); 826 schemespec.append(m_fragment); 827 } 828 829 return schemespec.toString(); 830 } 831 832 837 public String getUserinfo() { 838 return m_userinfo; 839 } 840 841 846 public String getHost() { 847 return m_host; 848 } 849 850 855 public int getPort() { 856 return m_port; 857 } 858 859 871 public String getPath(boolean p_includeQueryString, boolean p_includeFragment) { 872 873 StringBuffer pathString = new StringBuffer (m_path); 874 875 if (p_includeQueryString && m_queryString != null) { 876 pathString.append('?'); 877 pathString.append(m_queryString); 878 } 879 880 if (p_includeFragment && m_fragment != null) { 881 pathString.append('#'); 882 pathString.append(m_fragment); 883 } 884 885 return pathString.toString(); 886 } 887 888 894 public String getPath() { 895 return m_path; 896 } 897 898 905 public String getQueryString() { 906 return m_queryString; 907 } 908 909 916 public String getFragment() { 917 return m_fragment; 918 } 919 920 928 public void setScheme(String p_scheme) throws MalformedURIException { 929 930 if (p_scheme == null) { 931 throw new MalformedURIException("Cannot set scheme from null string!"); 932 } 933 934 if (!isConformantSchemeName(p_scheme)) { 935 throw new MalformedURIException("The scheme is not conformant."); 936 } 937 938 m_scheme = p_scheme.toLowerCase(); 939 } 940 941 949 public void setUserinfo(String p_userinfo) throws MalformedURIException { 950 951 if (p_userinfo == null) { 952 m_userinfo = null; 953 } else { 954 if (m_host == null) { 955 throw new MalformedURIException("Userinfo cannot be set when host is null!"); 956 } 957 958 int index = 0; 961 int end = p_userinfo.length(); 962 char testChar = '\0'; 963 964 while (index < end) { 965 testChar = p_userinfo.charAt(index); 966 967 if (testChar == '%') { 968 if (index + 2 >= end || !isHex(p_userinfo.charAt(index + 1)) || !isHex(p_userinfo.charAt(index + 2))) { 969 throw new MalformedURIException("Userinfo contains invalid escape sequence!"); 970 } 971 } else if (!isUnreservedCharacter(testChar) && USERINFO_CHARACTERS.indexOf(testChar) == -1) { 972 throw new MalformedURIException("Userinfo contains invalid character:" + testChar); 973 } 974 975 index++; 976 } 977 } 978 979 m_userinfo = p_userinfo; 980 } 981 982 991 public void setHost(String p_host) throws MalformedURIException { 992 993 if (p_host == null || p_host.trim().length() == 0) { 994 m_host = p_host; 995 m_userinfo = null; 996 m_port = -1; 997 } else if (!isWellFormedAddress(p_host)) { 998 throw new MalformedURIException("Host is not a well formed address!"); 999 } 1000 1001 m_host = p_host; 1002 } 1003 1004 1015 public void setPort(int p_port) throws MalformedURIException { 1016 1017 if (p_port >= 0 && p_port <= 65535) { 1018 if (m_host == null) { 1019 throw new MalformedURIException("Port cannot be set when host is null!"); 1020 } 1021 } else if (p_port != -1) { 1022 throw new MalformedURIException("Invalid port number!"); 1023 } 1024 1025 m_port = p_port; 1026 } 1027 1028 1040 public void setPath(String p_path) throws MalformedURIException { 1041 1042 if (p_path == null) { 1043 m_path = null; 1044 m_queryString = null; 1045 m_fragment = null; 1046 } else { 1047 initializePath(p_path); 1048 } 1049 } 1050 1051 1063 public void appendPath(String p_addToPath) throws MalformedURIException { 1064 1065 if (p_addToPath == null || p_addToPath.trim().length() == 0) { 1066 return; 1067 } 1068 1069 if (!isURIString(p_addToPath)) { 1070 throw new MalformedURIException("Path contains invalid character!"); 1071 } 1072 1073 if (m_path == null || m_path.trim().length() == 0) { 1074 if (p_addToPath.startsWith("/")) { 1075 m_path = p_addToPath; 1076 } else { 1077 m_path = "/" + p_addToPath; 1078 } 1079 } else if (m_path.endsWith("/")) { 1080 if (p_addToPath.startsWith("/")) { 1081 m_path = m_path.concat(p_addToPath.substring(1)); 1082 } else { 1083 m_path = m_path.concat(p_addToPath); 1084 } 1085 } else { 1086 if (p_addToPath.startsWith("/")) { 1087 m_path = m_path.concat(p_addToPath); 1088 } else { 1089 m_path = m_path.concat("/" + p_addToPath); 1090 } 1091 } 1092 } 1093 1094 1104 public void setQueryString(String p_queryString) throws MalformedURIException { 1105 1106 if (p_queryString == null) { 1107 m_queryString = null; 1108 } else if (!isGenericURI()) { 1109 throw new MalformedURIException("Query string can only be set for a generic URI!"); 1110 } else if (getPath() == null) { 1111 throw new MalformedURIException("Query string cannot be set when path is null!"); 1112 } else if (!isURIString(p_queryString)) { 1113 throw new MalformedURIException("Query string contains invalid character!"); 1114 } else { 1115 m_queryString = p_queryString; 1116 } 1117 } 1118 1119 1129 public void setFragment(String p_fragment) throws MalformedURIException { 1130 1131 if (p_fragment == null) { 1132 m_fragment = null; 1133 } else if (!isGenericURI()) { 1134 throw new MalformedURIException("Fragment can only be set for a generic URI!"); 1135 } else if (getPath() == null) { 1136 throw new MalformedURIException("Fragment cannot be set when path is null!"); 1137 } else if (!isURIString(p_fragment)) { 1138 throw new MalformedURIException("Fragment contains invalid character!"); 1139 } else { 1140 m_fragment = p_fragment; 1141 } 1142 } 1143 1144 1152 public boolean equals(Object p_test) { 1153 1154 if (p_test instanceof URI) { 1155 URI testURI = (URI) p_test; 1156 1157 if (((m_scheme == null && testURI.m_scheme == null) || (m_scheme != null && testURI.m_scheme != null && m_scheme 1158 .equals(testURI.m_scheme))) 1159 && ((m_userinfo == null && testURI.m_userinfo == null) || (m_userinfo != null 1160 && testURI.m_userinfo != null && m_userinfo.equals(testURI.m_userinfo))) 1161 && ((m_host == null && testURI.m_host == null) || (m_host != null && testURI.m_host != null && m_host 1162 .equals(testURI.m_host))) 1163 && m_port == testURI.m_port 1164 && ((m_path == null && testURI.m_path == null) || (m_path != null && testURI.m_path != null && m_path 1165 .equals(testURI.m_path))) 1166 && ((m_queryString == null && testURI.m_queryString == null) || (m_queryString != null 1167 && testURI.m_queryString != null && m_queryString.equals(testURI.m_queryString))) 1168 && ((m_fragment == null && testURI.m_fragment == null) || (m_fragment != null 1169 && testURI.m_fragment != null && m_fragment.equals(testURI.m_fragment)))) { 1170 return true; 1171 } 1172 } 1173 1174 return false; 1175 } 1176 1177 1182 public String toString() { 1183 1184 StringBuffer uriSpecString = new StringBuffer (); 1185 1186 if (m_scheme != null) { 1187 uriSpecString.append(m_scheme); 1188 uriSpecString.append(':'); 1189 } 1190 1191 uriSpecString.append(getSchemeSpecificPart()); 1192 1193 return uriSpecString.toString(); 1194 } 1195 1196 public String toExternalForm() { 1197 1198 StringBuffer uriSpecString = new StringBuffer (); 1199 1200 if (m_scheme != null) { 1201 uriSpecString.append(m_scheme); 1202 uriSpecString.append(':'); 1203 } 1204 1205 uriSpecString.append(getSchemeSpecificPartEncoded()); 1206 1207 return uriSpecString.toString(); 1208 } 1209 1210 1215 public boolean isGenericURI() { 1216 1217 return (m_host != null); 1220 } 1221 1222 1230 public static boolean isConformantSchemeName(String p_scheme) { 1231 1232 if (p_scheme == null || p_scheme.trim().length() == 0) { 1233 return false; 1234 } 1235 1236 if (!isAlpha(p_scheme.charAt(0))) { 1237 return false; 1238 } 1239 1240 char testChar; 1241 1242 for (int i = 1; i < p_scheme.length(); i++) { 1243 testChar = p_scheme.charAt(i); 1244 1245 if (!isAlphanum(testChar) && SCHEME_CHARACTERS.indexOf(testChar) == -1) { 1246 return false; 1247 } 1248 } 1249 1250 return true; 1251 } 1252 1253 1265 public static boolean isWellFormedAddress(String p_address) { 1266 1267 if (p_address == null) { 1268 return false; 1269 } 1270 1271 String address = p_address.trim(); 1272 int addrLength = address.length(); 1273 1274 if (addrLength == 0 || addrLength > 255) { 1275 return false; 1276 } 1277 1278 if (address.startsWith(".") || address.startsWith("-")) { 1279 return false; 1280 } 1281 1282 int index = address.lastIndexOf('.'); 1286 1287 if (address.endsWith(".")) { 1288 index = address.substring(0, index).lastIndexOf('.'); 1289 } 1290 1291 if (index + 1 < addrLength && isDigit(p_address.charAt(index + 1))) { 1292 char testChar; 1293 int numDots = 0; 1294 1295 for (int i = 0; i < addrLength; i++) { 1299 testChar = address.charAt(i); 1300 1301 if (testChar == '.') { 1302 if (!isDigit(address.charAt(i - 1)) || (i + 1 < addrLength && !isDigit(address.charAt(i + 1)))) { 1303 return false; 1304 } 1305 1306 numDots++; 1307 } else if (!isDigit(testChar)) { 1308 return false; 1309 } 1310 } 1311 1312 if (numDots != 3) { 1313 return false; 1314 } 1315 } else { 1316 1317 char testChar; 1320 1321 for (int i = 0; i < addrLength; i++) { 1322 testChar = address.charAt(i); 1323 1324 if (testChar == '.') { 1325 if (!isAlphanum(address.charAt(i - 1))) { 1326 return false; 1327 } 1328 1329 if (i + 1 < addrLength && !isAlphanum(address.charAt(i + 1))) { 1330 return false; 1331 } 1332 } else if (!isAlphanum(testChar) && testChar != '-') { 1333 return false; 1334 } 1335 } 1336 } 1337 1338 return true; 1339 } 1340 1341 1347 private static boolean isDigit(char p_char) { 1348 return p_char >= '0' && p_char <= '9'; 1349 } 1350 1351 1358 private static boolean isHex(char p_char) { 1359 return (isDigit(p_char) || (p_char >= 'a' && p_char <= 'f') || (p_char >= 'A' && p_char <= 'F')); 1360 } 1361 1362 1368 private static boolean isAlpha(char p_char) { 1369 return ((p_char >= 'a' && p_char <= 'z') || (p_char >= 'A' && p_char <= 'Z')); 1370 } 1371 1372 1378 private static boolean isAlphanum(char p_char) { 1379 return (isAlpha(p_char) || isDigit(p_char)); 1380 } 1381 1382 1389 private static boolean isReservedCharacter(char p_char) { 1390 return RESERVED_CHARACTERS.indexOf(p_char) != -1; 1391 } 1392 1393 1399 private static boolean isUnreservedCharacter(char p_char) { 1400 return (isAlphanum(p_char) || MARK_CHARACTERS.indexOf(p_char) != -1); 1401 } 1402 1403 1411 private static boolean isURIString(String p_uric) { 1412 1413 if (p_uric == null) { 1414 return false; 1415 } 1416 1417 int end = p_uric.length(); 1418 char testChar = '\0'; 1419 1420 for (int i = 0; i < end; i++) { 1421 testChar = p_uric.charAt(i); 1422 1423 if (testChar == '%') { 1424 if (i + 2 >= end || !isHex(p_uric.charAt(i + 1)) || !isHex(p_uric.charAt(i + 2))) { 1425 return false; 1426 } else { 1427 i += 2; 1428 1429 continue; 1430 } 1431 } 1432 1433 if (isReservedCharacter(testChar) || isUnreservedCharacter(testChar)) { 1434 continue; 1435 } else { 1436 return false; 1437 } 1438 } 1439 1440 return true; 1441 } 1442} 1443 | Popular Tags |