1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
112
113 /** If specified, stores the userinfo for this URI; otherwise null */
114 private String m_userinfo = null;
115
116 /** If specified, stores the host for this URI; otherwise null */
117 private String m_host = null;
118
119 /** If specified, stores the port for this URI; otherwise -1 */
120 private int m_port = -1;
121
122 /** If specified, stores the path for this URI; otherwise null */
123 private String m_path = null;
124
125 /** If specified, stores the query string for this URI; otherwise
126 null. */
127 private String m_queryString = null;
128
129 /** If specified, stores the fragment for this URI; otherwise null */
130 private String m_fragment = null;
131
132 private static boolean DEBUG = false;
133
134 /**
135 * Construct a new and uninitialized URI.
136 */
137 public JaxmURI() {
138 }
139
140 /**
141 * Construct a new URI from another URI. All fields for this URI are
142 * set equal to the fields of the URI passed in.
143 *
144 * @param p_other the URI to copy (cannot be null)
145 */
146 public JaxmURI(JaxmURI p_other) {
147 initialize(p_other);
148 }
149
150 /**
151 * Construct a new URI from a URI specification string. If the
152 * specification follows the "generic URI" syntax, (two slashes
153 * following the first colon), the specification will be parsed
708 m_fragment = p_uriSpec.substring(start, index);
709 }
710 }
711
712 /**
713 * Get the scheme for this URI.
714 *
715 * @return the scheme for this URI
716 */
717 public String getScheme() {
718 return m_scheme;
719 }
720
721 /**
722 * Get the scheme-specific part for this URI (everything following the
723 * scheme and the first colon). See RFC 2396 Section 5.2 for spec.
724 *
725 * @return the scheme-specific part for this URI
726 */
727 public String getSchemeSpecificPart() {
728 StringBuffer schemespec = new StringBuffer();
729
730 if (m_userinfo != null || m_host != null || m_port != -1) {
731 schemespec.append("//");
732 }
733
734 if (m_userinfo != null) {
735 schemespec.append(m_userinfo);
736 schemespec.append('@');
737 }
738
739 if (m_host != null) {
740 schemespec.append(m_host);
741 }
742
743 if (m_port != -1) {
744 schemespec.append(':');
745 schemespec.append(m_port);
746 }
747
748 if (m_path != null) {
788 public int getPort() {
789 return m_port;
790 }
791
792 /**
793 * Get the path for this URI (optionally with the query string and
794 * fragment).
795 *
796 * @param p_includeQueryString if true (and query string is not null),
797 * then a "?" followed by the query string
798 * will be appended
799 * @param p_includeFragment if true (and fragment is not null),
800 * then a "#" followed by the fragment
801 * will be appended
802 *
803 * @return the path for this URI possibly including the query string
804 * and fragment
805 */
806 public String getPath(boolean p_includeQueryString,
807 boolean p_includeFragment) {
808 StringBuffer pathString = new StringBuffer(m_path);
809
810 if (p_includeQueryString && m_queryString != null) {
811 pathString.append('?');
812 pathString.append(m_queryString);
813 }
814
815 if (p_includeFragment && m_fragment != null) {
816 pathString.append('#');
817 pathString.append(m_fragment);
818 }
819 return pathString.toString();
820 }
821
822 /**
823 * Get the path for this URI. Note that the value returned is the path
824 * only and does not include the query string or fragment.
825 *
826 * @return the path for this URI.
827 */
828 public String getPath() {
1131 ((m_fragment == null && testURI.m_fragment == null) ||
1132 (m_fragment != null && testURI.m_fragment != null &&
1133 m_fragment.equals(testURI.m_fragment)))) {
1134 return true;
1135 }
1136 }
1137 return false;
1138 }
1139
1140 public int hashCode() {
1141 // No members safe to use, just default to a constant.
1142 return 153214;
1143 }
1144
1145 /**
1146 * Get the URI as a string specification. See RFC 2396 Section 5.2.
1147 *
1148 * @return the URI string specification
1149 */
1150 public String toString() {
1151 StringBuffer uriSpecString = new StringBuffer();
1152
1153 if (m_scheme != null) {
1154 uriSpecString.append(m_scheme);
1155 uriSpecString.append(':');
1156 }
1157 uriSpecString.append(getSchemeSpecificPart());
1158 return uriSpecString.toString();
1159 }
1160
1161 /**
1162 * Get the indicator as to whether this URI uses the "generic URI"
1163 * syntax.
1164 *
1165 * @return true if this URI uses the "generic URI" syntax, false
1166 * otherwise
1167 */
1168 public boolean isGenericURI() {
1169 // presence of the host (whether valid or empty) means
1170 // double-slashes which means generic uri
1171 return (m_host != null);
|
1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
112
113 /** If specified, stores the userinfo for this URI; otherwise null */
114 private String m_userinfo = null;
115
116 /** If specified, stores the host for this URI; otherwise null */
117 private String m_host = null;
118
119 /** If specified, stores the port for this URI; otherwise -1 */
120 private int m_port = -1;
121
122 /** If specified, stores the path for this URI; otherwise null */
123 private String m_path = null;
124
125 /** If specified, stores the query string for this URI; otherwise
126 null. */
127 private String m_queryString = null;
128
129 /** If specified, stores the fragment for this URI; otherwise null */
130 private String m_fragment = null;
131
132 /**
133 * Construct a new and uninitialized URI.
134 */
135 public JaxmURI() {
136 }
137
138 /**
139 * Construct a new URI from another URI. All fields for this URI are
140 * set equal to the fields of the URI passed in.
141 *
142 * @param p_other the URI to copy (cannot be null)
143 */
144 public JaxmURI(JaxmURI p_other) {
145 initialize(p_other);
146 }
147
148 /**
149 * Construct a new URI from a URI specification string. If the
150 * specification follows the "generic URI" syntax, (two slashes
151 * following the first colon), the specification will be parsed
706 m_fragment = p_uriSpec.substring(start, index);
707 }
708 }
709
710 /**
711 * Get the scheme for this URI.
712 *
713 * @return the scheme for this URI
714 */
715 public String getScheme() {
716 return m_scheme;
717 }
718
719 /**
720 * Get the scheme-specific part for this URI (everything following the
721 * scheme and the first colon). See RFC 2396 Section 5.2 for spec.
722 *
723 * @return the scheme-specific part for this URI
724 */
725 public String getSchemeSpecificPart() {
726 StringBuilder schemespec = new StringBuilder();
727
728 if (m_userinfo != null || m_host != null || m_port != -1) {
729 schemespec.append("//");
730 }
731
732 if (m_userinfo != null) {
733 schemespec.append(m_userinfo);
734 schemespec.append('@');
735 }
736
737 if (m_host != null) {
738 schemespec.append(m_host);
739 }
740
741 if (m_port != -1) {
742 schemespec.append(':');
743 schemespec.append(m_port);
744 }
745
746 if (m_path != null) {
786 public int getPort() {
787 return m_port;
788 }
789
790 /**
791 * Get the path for this URI (optionally with the query string and
792 * fragment).
793 *
794 * @param p_includeQueryString if true (and query string is not null),
795 * then a "?" followed by the query string
796 * will be appended
797 * @param p_includeFragment if true (and fragment is not null),
798 * then a "#" followed by the fragment
799 * will be appended
800 *
801 * @return the path for this URI possibly including the query string
802 * and fragment
803 */
804 public String getPath(boolean p_includeQueryString,
805 boolean p_includeFragment) {
806 StringBuilder pathString = new StringBuilder(m_path);
807
808 if (p_includeQueryString && m_queryString != null) {
809 pathString.append('?');
810 pathString.append(m_queryString);
811 }
812
813 if (p_includeFragment && m_fragment != null) {
814 pathString.append('#');
815 pathString.append(m_fragment);
816 }
817 return pathString.toString();
818 }
819
820 /**
821 * Get the path for this URI. Note that the value returned is the path
822 * only and does not include the query string or fragment.
823 *
824 * @return the path for this URI.
825 */
826 public String getPath() {
1129 ((m_fragment == null && testURI.m_fragment == null) ||
1130 (m_fragment != null && testURI.m_fragment != null &&
1131 m_fragment.equals(testURI.m_fragment)))) {
1132 return true;
1133 }
1134 }
1135 return false;
1136 }
1137
1138 public int hashCode() {
1139 // No members safe to use, just default to a constant.
1140 return 153214;
1141 }
1142
1143 /**
1144 * Get the URI as a string specification. See RFC 2396 Section 5.2.
1145 *
1146 * @return the URI string specification
1147 */
1148 public String toString() {
1149 StringBuilder uriSpecString = new StringBuilder();
1150
1151 if (m_scheme != null) {
1152 uriSpecString.append(m_scheme);
1153 uriSpecString.append(':');
1154 }
1155 uriSpecString.append(getSchemeSpecificPart());
1156 return uriSpecString.toString();
1157 }
1158
1159 /**
1160 * Get the indicator as to whether this URI uses the "generic URI"
1161 * syntax.
1162 *
1163 * @return true if this URI uses the "generic URI" syntax, false
1164 * otherwise
1165 */
1166 public boolean isGenericURI() {
1167 // presence of the host (whether valid or empty) means
1168 // double-slashes which means generic uri
1169 return (m_host != null);
|