1 56 57 package org.enhydra.apache.xerces.utils; 58 59 import java.io.IOException ; 60 import java.io.Serializable ; 61 62 94 public class URI implements Serializable { 95 96 102 public static class MalformedURIException extends IOException { 103 104 108 public MalformedURIException() { 109 super(); 110 } 111 112 118 public MalformedURIException(String p_msg) { 119 super(p_msg); 120 } 121 } 122 123 124 private static final String RESERVED_CHARACTERS = ";/?:@&=+$,"; 125 126 128 private static final String MARK_CHARACTERS = "-_.!~*'() "; 129 130 131 private static final String SCHEME_CHARACTERS = "+-."; 132 133 135 private static final String USERINFO_CHARACTERS = ";:&=+$,"; 136 137 138 private String m_scheme = null; 139 140 141 private String m_userinfo = null; 142 143 144 private String m_host = null; 145 146 147 private int m_port = -1; 148 149 150 private String m_path = null; 151 152 154 private String m_queryString = null; 155 156 157 private String m_fragment = null; 158 159 private static boolean DEBUG = false; 160 161 164 public URI() { 165 } 166 167 173 public URI(URI p_other) { 174 initialize(p_other); 175 } 176 177 192 public URI(String p_uriSpec) throws MalformedURIException { 193 this((URI)null, p_uriSpec); 194 } 195 196 208 public URI(URI p_base, String p_uriSpec) throws MalformedURIException { 209 initialize(p_base, p_uriSpec); 210 } 211 212 224 public URI(String p_scheme, String p_schemeSpecificPart) 225 throws MalformedURIException { 226 if (p_scheme == null || p_scheme.trim().length() == 0) { 227 throw new MalformedURIException( 228 "Cannot construct URI with null/empty scheme!"); 229 } 230 if (p_schemeSpecificPart == null || 231 p_schemeSpecificPart.trim().length() == 0) { 232 throw new MalformedURIException( 233 "Cannot construct URI with null/empty scheme-specific part!"); 234 } 235 setScheme(p_scheme); 236 setPath(p_schemeSpecificPart); 237 } 238 239 260 public URI(String p_scheme, String p_host, String p_path, 261 String p_queryString, String p_fragment) 262 throws MalformedURIException { 263 this(p_scheme, null, p_host, -1, p_path, p_queryString, p_fragment); 264 } 265 266 291 public URI(String p_scheme, String p_userinfo, 292 String p_host, int p_port, String p_path, 293 String p_queryString, String p_fragment) 294 throws MalformedURIException { 295 if (p_scheme == null || p_scheme.trim().length() == 0) { 296 throw new MalformedURIException("Scheme is required!"); 297 } 298 299 if (p_host == null) { 300 if (p_userinfo != null) { 301 throw new MalformedURIException( 302 "Userinfo may not be specified if host is not specified!"); 303 } 304 if (p_port != -1) { 305 throw new MalformedURIException( 306 "Port may not be specified if host is not specified!"); 307 } 308 } 309 310 if (p_path != null) { 311 if (p_path.indexOf('?') != -1 && p_queryString != null) { 312 throw new MalformedURIException( 313 "Query string cannot be specified in path and query string!"); 314 } 315 316 if (p_path.indexOf('#') != -1 && p_fragment != null) { 317 throw new MalformedURIException( 318 "Fragment cannot be specified in both the path and fragment!"); 319 } 320 } 321 322 setScheme(p_scheme); 323 setHost(p_host); 324 setPort(p_port); 325 setUserinfo(p_userinfo); 326 setPath(p_path); 327 setQueryString(p_queryString); 328 setFragment(p_fragment); 329 } 330 331 336 private void initialize(URI p_other) { 337 m_scheme = p_other.getScheme(); 338 m_userinfo = p_other.getUserinfo(); 339 m_host = p_other.getHost(); 340 m_port = p_other.getPort(); 341 m_path = p_other.getPath(); 342 m_queryString = p_other.getQueryString(); 343 m_fragment = p_other.getFragment(); 344 } 345 346 362 private void initialize(URI p_base, String p_uriSpec) 363 throws MalformedURIException { 364 if (p_base == null && 365 (p_uriSpec == null || p_uriSpec.trim().length() == 0)) { 366 throw new MalformedURIException( 367 "Cannot initialize URI with empty parameters."); 368 } 369 370 if (p_uriSpec == null || p_uriSpec.trim().length() == 0) { 372 initialize(p_base); 373 return; 374 } 375 376 String uriSpec = p_uriSpec.trim(); 377 int uriSpecLen = uriSpec.length(); 378 int index = 0; 379 380 int colonIdx = uriSpec.indexOf(':'); 384 int slashIdx = uriSpec.indexOf('/'); 385 int queryIdx = uriSpec.indexOf('?'); 386 int fragmentIdx = uriSpec.indexOf('#'); 387 388 if ((colonIdx < 2) || 389 (colonIdx > slashIdx && slashIdx != -1) || 390 (colonIdx > queryIdx && queryIdx != -1) || 391 (colonIdx > fragmentIdx && fragmentIdx != -1)) { 392 if (p_base == null && fragmentIdx != 0) { 394 throw new MalformedURIException("No scheme found in URI."); 395 } 396 } 397 else { 398 initializeScheme(uriSpec); 399 index = m_scheme.length()+1; 400 } 401 402 if (((index+1) < uriSpecLen) && 404 (uriSpec.substring(index).startsWith("//"))) { 405 index += 2; 406 int startPos = index; 407 408 char testChar = '\0'; 410 while (index < uriSpecLen) { 411 testChar = uriSpec.charAt(index); 412 if (testChar == '/' || testChar == '?' || testChar == '#') { 413 break; 414 } 415 index++; 416 } 417 418 if (index > startPos) { 421 initializeAuthority(uriSpec.substring(startPos, index)); 422 } 423 else { 424 m_host = ""; 425 } 426 } 427 428 initializePath(uriSpec.substring(index)); 429 430 if (p_base != null) { 436 437 if (m_path.length() == 0 && m_scheme == null && 445 m_host == null) { 446 m_scheme = p_base.getScheme(); 447 m_userinfo = p_base.getUserinfo(); 448 m_host = p_base.getHost(); 449 m_port = p_base.getPort(); 450 m_path = p_base.getPath(); 451 452 if (m_queryString == null) { 453 m_queryString = p_base.getQueryString(); 454 } 455 return; 456 } 457 458 if (m_scheme == null) { 461 m_scheme = p_base.getScheme(); 462 } 463 else { 464 return; 465 } 466 467 if (m_host == null) { 470 m_userinfo = p_base.getUserinfo(); 471 m_host = p_base.getHost(); 472 m_port = p_base.getPort(); 473 } 474 else { 475 return; 476 } 477 478 if (m_path.length() > 0 && 480 m_path.startsWith("/")) { 481 return; 482 } 483 484 String path = new String (); 487 String basePath = p_base.getPath(); 488 489 if (basePath != null) { 491 int lastSlash = basePath.lastIndexOf('/'); 492 if (lastSlash != -1) { 493 path = basePath.substring(0, lastSlash+1); 494 } 495 } 496 497 path = path.concat(m_path); 499 500 index = -1; 502 while ((index = path.indexOf("/./")) != -1) { 503 path = path.substring(0, index+1).concat(path.substring(index+3)); 504 } 505 506 if (path.endsWith("/.")) { 508 path = path.substring(0, path.length()-1); 509 } 510 511 index = 1; 514 int segIndex = -1; 515 516 while ((index = path.indexOf("/../", index)) > 0) { 517 segIndex = path.lastIndexOf('/', index-1); 518 if (segIndex != -1 && !path.substring(segIndex+1, index).equals("..")) { 519 path = path.substring(0, segIndex).concat(path.substring(index+3)); 520 index = segIndex; 521 } else { 522 index += 4; 523 } 524 } 525 526 if (path.endsWith("/..")) { 529 index = path.length()-3; 530 segIndex = path.lastIndexOf('/', index-1); 531 if (segIndex != -1 && !path.substring(segIndex+1, index).equals("..")) { 532 path = path.substring(0, segIndex+1); 533 } 534 } 535 536 m_path = path; 537 } 538 } 539 540 548 private void initializeScheme(String p_uriSpec) 549 throws MalformedURIException { 550 int uriSpecLen = p_uriSpec.length(); 551 int index = 0; 552 String scheme = null; 553 char testChar = '\0'; 554 555 while (index < uriSpecLen) { 556 testChar = p_uriSpec.charAt(index); 557 if (testChar == ':' || testChar == '/' || 558 testChar == '?' || testChar == '#') { 559 break; 560 } 561 index++; 562 } 563 scheme = p_uriSpec.substring(0, index); 564 565 if (scheme.length() == 0) { 566 throw new MalformedURIException("No scheme found in URI."); 567 } 568 else { 569 setScheme(scheme); 570 } 571 } 572 573 581 private void initializeAuthority(String p_uriSpec) 582 throws MalformedURIException { 583 int index = 0; 584 int start = 0; 585 int end = p_uriSpec.length(); 586 char testChar = '\0'; 587 String userinfo = null; 588 589 if (p_uriSpec.indexOf('@', start) != -1) { 591 while (index < end) { 592 testChar = p_uriSpec.charAt(index); 593 if (testChar == '@') { 594 break; 595 } 596 index++; 597 } 598 userinfo = p_uriSpec.substring(start, index); 599 index++; 600 } 601 602 String host = null; 604 start = index; 605 while (index < end) { 606 testChar = p_uriSpec.charAt(index); 607 if (testChar == ':') { 608 break; 609 } 610 index++; 611 } 612 host = p_uriSpec.substring(start, index); 613 int port = -1; 614 if (host.length() > 0) { 615 if (testChar == ':') { 617 index++; 618 start = index; 619 while (index < end) { 620 index++; 621 } 622 String portStr = p_uriSpec.substring(start, index); 623 if (portStr.length() > 0) { 624 for (int i = 0; i < portStr.length(); i++) { 625 if (!isDigit(portStr.charAt(i))) { 626 throw new MalformedURIException( 627 portStr + 628 " is invalid. Port should only contain digits!"); 629 } 630 } 631 try { 632 port = Integer.parseInt(portStr); 633 } 634 catch (NumberFormatException nfe) { 635 } 637 } 638 } 639 } 640 setHost(host); 641 setPort(port); 642 setUserinfo(userinfo); 643 } 644 645 652 private void initializePath(String p_uriSpec) 653 throws MalformedURIException { 654 if (p_uriSpec == null) { 655 throw new MalformedURIException( 656 "Cannot initialize path from null string!"); 657 } 658 659 int index = 0; 660 int start = 0; 661 int end = p_uriSpec.length(); 662 char testChar = '\0'; 663 664 while (index < end) { 666 testChar = p_uriSpec.charAt(index); 667 if (testChar == '?' || testChar == '#') { 668 break; 669 } 670 if (testChar == '%') { 672 if (index+2 >= end || 673 !isHex(p_uriSpec.charAt(index+1)) || 674 !isHex(p_uriSpec.charAt(index+2))) { 675 throw new MalformedURIException( 676 "Path contains invalid escape sequence!"); 677 } 678 } 679 else if (!isReservedCharacter(testChar) && 680 !isUnreservedCharacter(testChar)) { 681 throw new MalformedURIException( 682 "Path contains invalid character: " + testChar); 683 } 684 index++; 685 } 686 m_path = p_uriSpec.substring(start, index); 687 688 if (testChar == '?') { 690 index++; 691 start = index; 692 while (index < end) { 693 testChar = p_uriSpec.charAt(index); 694 if (testChar == '#') { 695 break; 696 } 697 if (testChar == '%') { 698 if (index+2 >= end || 699 !isHex(p_uriSpec.charAt(index+1)) || 700 !isHex(p_uriSpec.charAt(index+2))) { 701 throw new MalformedURIException( 702 "Query string contains invalid escape sequence!"); 703 } 704 } 705 else if (!isReservedCharacter(testChar) && 706 !isUnreservedCharacter(testChar)) { 707 throw new MalformedURIException( 708 "Query string contains invalid character:" + testChar); 709 } 710 index++; 711 } 712 m_queryString = p_uriSpec.substring(start, index); 713 } 714 715 if (testChar == '#') { 717 index++; 718 start = index; 719 while (index < end) { 720 testChar = p_uriSpec.charAt(index); 721 722 if (testChar == '%') { 723 if (index+2 >= end || 724 !isHex(p_uriSpec.charAt(index+1)) || 725 !isHex(p_uriSpec.charAt(index+2))) { 726 throw new MalformedURIException( 727 "Fragment contains invalid escape sequence!"); 728 } 729 } 730 else if (!isReservedCharacter(testChar) && 731 !isUnreservedCharacter(testChar)) { 732 throw new MalformedURIException( 733 "Fragment contains invalid character:"+testChar); 734 } 735 index++; 736 } 737 m_fragment = p_uriSpec.substring(start, index); 738 } 739 } 740 741 746 public String getScheme() { 747 return m_scheme; 748 } 749 750 756 public String getSchemeSpecificPart() { 757 StringBuffer schemespec = new StringBuffer (); 758 759 if (m_userinfo != null || m_host != null || m_port != -1) { 760 schemespec.append("//"); 761 } 762 763 if (m_userinfo != null) { 764 schemespec.append(m_userinfo); 765 schemespec.append('@'); 766 } 767 768 if (m_host != null) { 769 schemespec.append(m_host); 770 } 771 772 if (m_port != -1) { 773 schemespec.append(':'); 774 schemespec.append(m_port); 775 } 776 777 if (m_path != null) { 778 schemespec.append((m_path)); 779 } 780 781 if (m_queryString != null) { 782 schemespec.append('?'); 783 schemespec.append(m_queryString); 784 } 785 786 if (m_fragment != null) { 787 schemespec.append('#'); 788 schemespec.append(m_fragment); 789 } 790 791 return schemespec.toString(); 792 } 793 794 799 public String getUserinfo() { 800 return m_userinfo; 801 } 802 803 808 public String getHost() { 809 return m_host; 810 } 811 812 817 public int getPort() { 818 return m_port; 819 } 820 821 835 public String getPath(boolean p_includeQueryString, 836 boolean p_includeFragment) { 837 StringBuffer pathString = new StringBuffer (m_path); 838 839 if (p_includeQueryString && m_queryString != null) { 840 pathString.append('?'); 841 pathString.append(m_queryString); 842 } 843 844 if (p_includeFragment && m_fragment != null) { 845 pathString.append('#'); 846 pathString.append(m_fragment); 847 } 848 return pathString.toString(); 849 } 850 851 857 public String getPath() { 858 return m_path; 859 } 860 861 868 public String getQueryString() { 869 return m_queryString; 870 } 871 872 879 public String getFragment() { 880 return m_fragment; 881 } 882 883 892 public void setScheme(String p_scheme) throws MalformedURIException { 893 if (p_scheme == null) { 894 throw new MalformedURIException( 895 "Cannot set scheme from null string!"); 896 } 897 if (!isConformantSchemeName(p_scheme)) { 898 throw new MalformedURIException("The scheme is not conformant."); 899 } 900 901 m_scheme = p_scheme.toLowerCase(); 902 } 903 904 913 public void setUserinfo(String p_userinfo) throws MalformedURIException { 914 if (p_userinfo == null) { 915 m_userinfo = null; 916 } 917 else { 918 if (m_host == null) { 919 throw new MalformedURIException( 920 "Userinfo cannot be set when host is null!"); 921 } 922 923 int index = 0; 926 int end = p_userinfo.length(); 927 char testChar = '\0'; 928 while (index < end) { 929 testChar = p_userinfo.charAt(index); 930 if (testChar == '%') { 931 if (index+2 >= end || 932 !isHex(p_userinfo.charAt(index+1)) || 933 !isHex(p_userinfo.charAt(index+2))) { 934 throw new MalformedURIException( 935 "Userinfo contains invalid escape sequence!"); 936 } 937 } 938 else if (!isUnreservedCharacter(testChar) && 939 USERINFO_CHARACTERS.indexOf(testChar) == -1) { 940 throw new MalformedURIException( 941 "Userinfo contains invalid character:"+testChar); 942 } 943 index++; 944 } 945 } 946 m_userinfo = p_userinfo; 947 } 948 949 958 public void setHost(String p_host) throws MalformedURIException { 959 if (p_host == null || p_host.trim().length() == 0) { 960 m_host = p_host; 961 m_userinfo = null; 962 m_port = -1; 963 } 964 else if (!isWellFormedAddress(p_host)) { 965 throw new MalformedURIException("Host is not a well formed address!"); 966 } 967 m_host = p_host; 968 } 969 970 981 public void setPort(int p_port) throws MalformedURIException { 982 if (p_port >= 0 && p_port <= 65535) { 983 if (m_host == null) { 984 throw new MalformedURIException( 985 "Port cannot be set when host is null!"); 986 } 987 } 988 else if (p_port != -1) { 989 throw new MalformedURIException("Invalid port number!"); 990 } 991 m_port = p_port; 992 } 993 994 1008 public void setPath(String p_path) throws MalformedURIException { 1009 if (p_path == null) { 1010 m_path = null; 1011 m_queryString = null; 1012 m_fragment = null; 1013 } 1014 else { 1015 initializePath(p_path); 1016 } 1017 } 1018 1019 1032 public void appendPath(String p_addToPath) 1033 throws MalformedURIException { 1034 if (p_addToPath == null || p_addToPath.trim().length() == 0) { 1035 return; 1036 } 1037 1038 if (!isURIString(p_addToPath)) { 1039 throw new MalformedURIException( 1040 "Path contains invalid character!"); 1041 } 1042 1043 if (m_path == null || m_path.trim().length() == 0) { 1044 if (p_addToPath.startsWith("/")) { 1045 m_path = p_addToPath; 1046 } 1047 else { 1048 m_path = "/" + p_addToPath; 1049 } 1050 } 1051 else if (m_path.endsWith("/")) { 1052 if (p_addToPath.startsWith("/")) { 1053 m_path = m_path.concat(p_addToPath.substring(1)); 1054 } 1055 else { 1056 m_path = m_path.concat(p_addToPath); 1057 } 1058 } 1059 else { 1060 if (p_addToPath.startsWith("/")) { 1061 m_path = m_path.concat(p_addToPath); 1062 } 1063 else { 1064 m_path = m_path.concat("/" + p_addToPath); 1065 } 1066 } 1067 } 1068 1069 1080 public void setQueryString(String p_queryString) throws MalformedURIException { 1081 if (p_queryString == null) { 1082 m_queryString = null; 1083 } 1084 else if (!isGenericURI()) { 1085 throw new MalformedURIException( 1086 "Query string can only be set for a generic URI!"); 1087 } 1088 else if (getPath() == null) { 1089 throw new MalformedURIException( 1090 "Query string cannot be set when path is null!"); 1091 } 1092 else if (!isURIString(p_queryString)) { 1093 throw new MalformedURIException( 1094 "Query string contains invalid character!"); 1095 } 1096 else { 1097 m_queryString = p_queryString; 1098 } 1099 } 1100 1101 1112 public void setFragment(String p_fragment) throws MalformedURIException { 1113 if (p_fragment == null) { 1114 m_fragment = null; 1115 } 1116 else if (!isGenericURI()) { 1117 throw new MalformedURIException( 1118 "Fragment can only be set for a generic URI!"); 1119 } 1120 else if (getPath() == null) { 1121 throw new MalformedURIException( 1122 "Fragment cannot be set when path is null!"); 1123 } 1124 else if (!isURIString(p_fragment)) { 1125 throw new MalformedURIException( 1126 "Fragment contains invalid character!"); 1127 } 1128 else { 1129 m_fragment = p_fragment; 1130 } 1131 } 1132 1133 1141 public boolean equals(Object p_test) { 1142 if (p_test instanceof URI) { 1143 URI testURI = (URI) p_test; 1144 if (((m_scheme == null && testURI.m_scheme == null) || 1145 (m_scheme != null && testURI.m_scheme != null && 1146 m_scheme.equals(testURI.m_scheme))) && 1147 ((m_userinfo == null && testURI.m_userinfo == null) || 1148 (m_userinfo != null && testURI.m_userinfo != null && 1149 m_userinfo.equals(testURI.m_userinfo))) && 1150 ((m_host == null && testURI.m_host == null) || 1151 (m_host != null && testURI.m_host != null && 1152 m_host.equals(testURI.m_host))) && 1153 m_port == testURI.m_port && 1154 ((m_path == null && testURI.m_path == null) || 1155 (m_path != null && testURI.m_path != null && 1156 m_path.equals(testURI.m_path))) && 1157 ((m_queryString == null && testURI.m_queryString == null) || 1158 (m_queryString != null && testURI.m_queryString != null && 1159 m_queryString.equals(testURI.m_queryString))) && 1160 ((m_fragment == null && testURI.m_fragment == null) || 1161 (m_fragment != null && testURI.m_fragment != null && 1162 m_fragment.equals(testURI.m_fragment)))) { 1163 return true; 1164 } 1165 } 1166 return false; 1167 } 1168 1169 1174 public String toString() { 1175 StringBuffer uriSpecString = new StringBuffer (); 1176 1177 if (m_scheme != null) { 1178 uriSpecString.append(m_scheme); 1179 uriSpecString.append(':'); 1180 } 1181 uriSpecString.append(getSchemeSpecificPart()); 1182 return uriSpecString.toString(); 1183 } 1184 1185 1192 public boolean isGenericURI() { 1193 return (m_host != null); 1196 } 1197 1198 1205 public static boolean isConformantSchemeName(String p_scheme) { 1206 if (p_scheme == null || p_scheme.trim().length() == 0) { 1207 return false; 1208 } 1209 1210 if (!isAlpha(p_scheme.charAt(0))) { 1211 return false; 1212 } 1213 1214 char testChar; 1215 for (int i = 1; i < p_scheme.length(); i++) { 1216 testChar = p_scheme.charAt(i); 1217 if (!isAlphanum(testChar) && 1218 SCHEME_CHARACTERS.indexOf(testChar) == -1) { 1219 return false; 1220 } 1221 } 1222 1223 return true; 1224 } 1225 1226 1237 public static boolean isWellFormedAddress(String p_address) { 1238 if (p_address == null) { 1239 return false; 1240 } 1241 1242 String address = p_address.trim(); 1243 int addrLength = address.length(); 1244 if (addrLength == 0 || addrLength > 255) { 1245 return false; 1246 } 1247 1248 if (address.startsWith(".") || address.startsWith("-")) { 1249 return false; 1250 } 1251 1252 int index = address.lastIndexOf('.'); 1256 if (address.endsWith(".")) { 1257 index = address.substring(0, index).lastIndexOf('.'); 1258 } 1259 1260 if (index+1 < addrLength && isDigit(p_address.charAt(index+1))) { 1261 char testChar; 1262 int numDots = 0; 1263 1264 for (int i = 0; i < addrLength; i++) { 1268 testChar = address.charAt(i); 1269 if (testChar == '.') { 1270 if (!isDigit(address.charAt(i-1)) || 1271 (i+1 < addrLength && !isDigit(address.charAt(i+1)))) { 1272 return false; 1273 } 1274 numDots++; 1275 } 1276 else if (!isDigit(testChar)) { 1277 return false; 1278 } 1279 } 1280 if (numDots != 3) { 1281 return false; 1282 } 1283 } 1284 else { 1285 char testChar; 1288 1289 for (int i = 0; i < addrLength; i++) { 1290 testChar = address.charAt(i); 1291 if (testChar == '.') { 1292 if (!isAlphanum(address.charAt(i-1))) { 1293 return false; 1294 } 1295 if (i+1 < addrLength && !isAlphanum(address.charAt(i+1))) { 1296 return false; 1297 } 1298 } 1299 else if (!isAlphanum(testChar) && testChar != '-') { 1300 return false; 1301 } 1302 } 1303 } 1304 return true; 1305 } 1306 1307 1308 1313 private static boolean isDigit(char p_char) { 1314 return p_char >= '0' && p_char <= '9'; 1315 } 1316 1317 1323 private static boolean isHex(char p_char) { 1324 return (isDigit(p_char) || 1325 (p_char >= 'a' && p_char <= 'f') || 1326 (p_char >= 'A' && p_char <= 'F')); 1327 } 1328 1329 1334 private static boolean isAlpha(char p_char) { 1335 return ((p_char >= 'a' && p_char <= 'z') || 1336 (p_char >= 'A' && p_char <= 'Z' )); 1337 } 1338 1339 1344 private static boolean isAlphanum(char p_char) { 1345 return (isAlpha(p_char) || isDigit(p_char)); 1346 } 1347 1348 1354 private static boolean isReservedCharacter(char p_char) { 1355 return RESERVED_CHARACTERS.indexOf(p_char) != -1; 1356 } 1357 1358 1363 private static boolean isUnreservedCharacter(char p_char) { 1364 return (isAlphanum(p_char) || 1365 MARK_CHARACTERS.indexOf(p_char) != -1); 1366 } 1367 1368 1375 private static boolean isURIString(String p_uric) { 1376 if (p_uric == null) { 1377 return false; 1378 } 1379 int end = p_uric.length(); 1380 char testChar = '\0'; 1381 for (int i = 0; i < end; i++) { 1382 testChar = p_uric.charAt(i); 1383 if (testChar == '%') { 1384 if (i+2 >= end || 1385 !isHex(p_uric.charAt(i+1)) || 1386 !isHex(p_uric.charAt(i+2))) { 1387 return false; 1388 } 1389 else { 1390 i += 2; 1391 continue; 1392 } 1393 } 1394 if (isReservedCharacter(testChar) || 1395 isUnreservedCharacter(testChar)) { 1396 continue; 1397 } 1398 else { 1399 return false; 1400 } 1401 } 1402 return true; 1403 } 1404} 1405 | Popular Tags |