1 /* |
1 /* |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
37 * is designed to handle the parsing of URIs and provide access to |
37 * is designed to handle the parsing of URIs and provide access to |
38 * the various components (scheme, host, port, userinfo, path, query |
38 * the various components (scheme, host, port, userinfo, path, query |
39 * string and fragment) that may constitute a URI. |
39 * string and fragment) that may constitute a URI. |
40 * <p> |
40 * <p> |
41 * Parsing of a URI specification is done according to the URI |
41 * Parsing of a URI specification is done according to the URI |
42 * syntax described in <a href="http://www.ietf.org/rfc/rfc2396.txt?number=2396">RFC 2396</a>. |
42 * syntax described in <a href="http://www.ietf.org/rfc/rfc2396.txt?number=2396"> |
43 * Every URI consists of a scheme, followed by a colon (':'), followed by a scheme-specific |
43 * RFC 2396</a>. Every URI consists |
|
44 * of a scheme, followed by a colon (':'), followed by a scheme-specific |
44 * part. For URIs that follow the "generic URI" syntax, the scheme- |
45 * part. For URIs that follow the "generic URI" syntax, the scheme- |
45 * specific part begins with two slashes ("//") and may be followed |
46 * specific part begins with two slashes ("//") and may be followed |
46 * by an authority segment (comprised of user information, host, and |
47 * by an authority segment (comprised of user information, host, and |
47 * port), path segment, query segment and fragment. Note that RFC 2396 |
48 * port), path segment, query segment and fragment. Note that RFC 2396 |
48 * no longer specifies the use of the parameters segment and excludes |
49 * no longer specifies the use of the parameters segment and excludes |
58 * any built-in network access functionality nor does it provide any |
59 * any built-in network access functionality nor does it provide any |
59 * scheme-specific functionality (for example, it does not know a |
60 * scheme-specific functionality (for example, it does not know a |
60 * default port for a specific scheme). Rather, it only knows the |
61 * default port for a specific scheme). Rather, it only knows the |
61 * grammar and basic set of operations that can be applied to a URI. |
62 * grammar and basic set of operations that can be applied to a URI. |
62 * |
63 * |
63 * @version |
|
64 * |
|
65 **********************************************************************/ |
64 **********************************************************************/ |
66 public class JaxmURI implements Serializable { |
65 public class JaxmURI implements Serializable { |
67 |
66 |
68 /******************************************************************* |
67 /******************************************************************* |
69 * MalformedURIExceptions are thrown in the process of building a URI |
68 * MalformedURIExceptions are thrown in the process of building a URI |
1104 * @param p_test the Object to test for equality. |
1103 * @param p_test the Object to test for equality. |
1105 * |
1104 * |
1106 * @return true if p_test is a URI with all values equal to this |
1105 * @return true if p_test is a URI with all values equal to this |
1107 * URI, false otherwise |
1106 * URI, false otherwise |
1108 */ |
1107 */ |
|
1108 @Override |
1109 public boolean equals(Object p_test) { |
1109 public boolean equals(Object p_test) { |
1110 if (p_test instanceof JaxmURI) { |
1110 if (p_test instanceof JaxmURI) { |
1111 JaxmURI testURI = (JaxmURI) p_test; |
1111 JaxmURI testURI = (JaxmURI) p_test; |
1112 if (((m_scheme == null && testURI.m_scheme == null) || |
1112 if (((m_scheme == null && testURI.m_scheme == null) || |
1113 (m_scheme != null && testURI.m_scheme != null && |
1113 (m_scheme != null && testURI.m_scheme != null && |
1132 } |
1132 } |
1133 } |
1133 } |
1134 return false; |
1134 return false; |
1135 } |
1135 } |
1136 |
1136 |
|
1137 @Override |
1137 public int hashCode() { |
1138 public int hashCode() { |
1138 // No members safe to use, just default to a constant. |
1139 // No members safe to use, just default to a constant. |
1139 return 153214; |
1140 return 153214; |
1140 } |
1141 } |
1141 |
1142 |
1142 /** |
1143 /** |
1143 * Get the URI as a string specification. See RFC 2396 Section 5.2. |
1144 * Get the URI as a string specification. See RFC 2396 Section 5.2. |
1144 * |
1145 * |
1145 * @return the URI string specification |
1146 * @return the URI string specification |
1146 */ |
1147 */ |
|
1148 @Override |
1147 public String toString() { |
1149 public String toString() { |
1148 StringBuilder uriSpecString = new StringBuilder(); |
1150 StringBuilder uriSpecString = new StringBuilder(); |
1149 |
1151 |
1150 if (m_scheme != null) { |
1152 if (m_scheme != null) { |
1151 uriSpecString.append(m_scheme); |
1153 uriSpecString.append(m_scheme); |
1170 |
1172 |
1171 /** |
1173 /** |
1172 * Determine whether a scheme conforms to the rules for a scheme name. |
1174 * Determine whether a scheme conforms to the rules for a scheme name. |
1173 * A scheme is conformant if it starts with an alphanumeric, and |
1175 * A scheme is conformant if it starts with an alphanumeric, and |
1174 * contains only alphanumerics, '+','-' and '.'. |
1176 * contains only alphanumerics, '+','-' and '.'. |
|
1177 * |
|
1178 * @param p_scheme scheme name |
1175 * |
1179 * |
1176 * @return true if the scheme is conformant, false otherwise |
1180 * @return true if the scheme is conformant, false otherwise |
1177 */ |
1181 */ |
1178 public static boolean isConformantSchemeName(String p_scheme) { |
1182 public static boolean isConformantSchemeName(String p_scheme) { |
1179 if (p_scheme == null || p_scheme.trim().length() == 0) { |
1183 if (p_scheme == null || p_scheme.trim().length() == 0) { |
1200 * Determine whether a string is syntactically capable of representing |
1204 * Determine whether a string is syntactically capable of representing |
1201 * a valid IPv4 address or the domain name of a network host. A valid |
1205 * a valid IPv4 address or the domain name of a network host. A valid |
1202 * IPv4 address consists of four decimal digit groups separated by a |
1206 * IPv4 address consists of four decimal digit groups separated by a |
1203 * '.'. A hostname consists of domain labels (each of which must |
1207 * '.'. A hostname consists of domain labels (each of which must |
1204 * begin and end with an alphanumeric but may contain '-') separated |
1208 * begin and end with an alphanumeric but may contain '-') separated |
1205 & by a '.'. See RFC 2396 Section 3.2.2. |
1209 * by a '.'. See RFC 2396 Section 3.2.2. |
|
1210 * |
|
1211 * @param p_address address |
1206 * |
1212 * |
1207 * @return true if the string is a syntactically valid IPv4 address |
1213 * @return true if the string is a syntactically valid IPv4 address |
1208 * or hostname |
1214 * or hostname |
1209 */ |
1215 */ |
1210 public static boolean isWellFormedAddress(String p_address) { |
1216 public static boolean isWellFormedAddress(String p_address) { |