src/share/classes/java/net/URI.java

Print this page




 171  * removed only if it is preceded by a non-{@code ".."} segment.
 172  * Normalization has no effect upon opaque URIs.
 173  *
 174  * <p> <i>Resolution</i> is the process of resolving one URI against another,
 175  * <i>base</i> URI.  The resulting URI is constructed from components of both
 176  * URIs in the manner specified by RFC&nbsp;2396, taking components from the
 177  * base URI for those not specified in the original.  For hierarchical URIs,
 178  * the path of the original is resolved against the path of the base and then
 179  * normalized.  The result, for example, of resolving
 180  *
 181  * <blockquote>
 182  * {@code docs/guide/collections/designfaq.html#28}
 183  * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 184  * &nbsp;&nbsp;&nbsp;&nbsp;(1)
 185  * </blockquote>
 186  *
 187  * against the base URI {@code http://java.sun.com/j2se/1.3/} is the result
 188  * URI
 189  *
 190  * <blockquote>
 191  * {@code http://java.sun.com/j2se/1.3/docs/guide/collections/designfaq.html#28}
 192  * </blockquote>
 193  *
 194  * Resolving the relative URI
 195  *
 196  * <blockquote>
 197  * {@code ../../../demo/jfc/SwingSet2/src/SwingSet2.java}&nbsp;&nbsp;&nbsp;&nbsp;(2)
 198  * </blockquote>
 199  *
 200  * against this result yields, in turn,
 201  *
 202  * <blockquote>
 203  * {@code http://java.sun.com/j2se/1.3/demo/jfc/SwingSet2/src/SwingSet2.java}
 204  * </blockquote>
 205  *
 206  * Resolution of both absolute and relative URIs, and of both absolute and
 207  * relative paths in the case of hierarchical URIs, is supported.  Resolving
 208  * the URI {@code file:///~calendar} against any other URI simply yields the
 209  * original URI, since it is absolute.  Resolving the relative URI (2) above
 210  * against the relative base URI (1) yields the normalized, but still relative,
 211  * URI
 212  *
 213  * <blockquote>
 214  * {@code demo/jfc/SwingSet2/src/SwingSet2.java}
 215  * </blockquote>
 216  *
 217  * <p> <i>Relativization</i>, finally, is the inverse of resolution: For any
 218  * two normalized URIs <i>u</i> and&nbsp;<i>v</i>,
 219  *
 220  * <blockquote>
 221  *   <i>u</i>{@code .relativize(}<i>u</i>{@code .resolve(}<i>v</i>{@code )).equals(}<i>v</i>{@code )}&nbsp;&nbsp;and<br>
 222  *   <i>u</i>{@code .resolve(}<i>u</i>{@code .relativize(}<i>v</i>{@code )).equals(}<i>v</i>{@code )}&nbsp;&nbsp;.<br>
 223  * </blockquote>
 224  *
 225  * This operation is often useful when constructing a document containing URIs
 226  * that must be made relative to the base URI of the document wherever
 227  * possible.  For example, relativizing the URI
 228  *
 229  * <blockquote>
 230  * {@code http://java.sun.com/j2se/1.3/docs/guide/index.html}
 231  * </blockquote>
 232  *
 233  * against the base URI
 234  *
 235  * <blockquote>
 236  * {@code http://java.sun.com/j2se/1.3}
 237  * </blockquote>
 238  *
 239  * yields the relative URI {@code docs/guide/index.html}.
 240  *
 241  *
 242  * <h4> Character categories </h4>
 243  *
 244  * RFC&nbsp;2396 specifies precisely which characters are permitted in the
 245  * various components of a URI reference.  The following categories, most of
 246  * which are taken from that specification, are used below to describe these
 247  * constraints:
 248  *
 249  * <blockquote><table cellspacing=2 summary="Describes categories alpha,digit,alphanum,unreserved,punct,reserved,escaped,and other">
 250  *   <tr><th valign=top><i>alpha</i></th>




 171  * removed only if it is preceded by a non-{@code ".."} segment.
 172  * Normalization has no effect upon opaque URIs.
 173  *
 174  * <p> <i>Resolution</i> is the process of resolving one URI against another,
 175  * <i>base</i> URI.  The resulting URI is constructed from components of both
 176  * URIs in the manner specified by RFC&nbsp;2396, taking components from the
 177  * base URI for those not specified in the original.  For hierarchical URIs,
 178  * the path of the original is resolved against the path of the base and then
 179  * normalized.  The result, for example, of resolving
 180  *
 181  * <blockquote>
 182  * {@code docs/guide/collections/designfaq.html#28}
 183  * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 184  * &nbsp;&nbsp;&nbsp;&nbsp;(1)
 185  * </blockquote>
 186  *
 187  * against the base URI {@code http://java.sun.com/j2se/1.3/} is the result
 188  * URI
 189  *
 190  * <blockquote>
 191  * {@code http://docs.oracle.com/javase/1.3/docs/guide/collections/designfaq.html#28}
 192  * </blockquote>
 193  *
 194  * Resolving the relative URI
 195  *
 196  * <blockquote>
 197  * {@code ../../../demo/jfc/SwingSet2/src/SwingSet2.java}&nbsp;&nbsp;&nbsp;&nbsp;(2)
 198  * </blockquote>
 199  *
 200  * against this result yields, in turn,
 201  *
 202  * <blockquote>
 203  * {@code http://java.sun.com/j2se/1.3/demo/jfc/SwingSet2/src/SwingSet2.java}
 204  * </blockquote>
 205  *
 206  * Resolution of both absolute and relative URIs, and of both absolute and
 207  * relative paths in the case of hierarchical URIs, is supported.  Resolving
 208  * the URI {@code file:///~calendar} against any other URI simply yields the
 209  * original URI, since it is absolute.  Resolving the relative URI (2) above
 210  * against the relative base URI (1) yields the normalized, but still relative,
 211  * URI
 212  *
 213  * <blockquote>
 214  * {@code demo/jfc/SwingSet2/src/SwingSet2.java}
 215  * </blockquote>
 216  *
 217  * <p> <i>Relativization</i>, finally, is the inverse of resolution: For any
 218  * two normalized URIs <i>u</i> and&nbsp;<i>v</i>,
 219  *
 220  * <blockquote>
 221  *   <i>u</i>{@code .relativize(}<i>u</i>{@code .resolve(}<i>v</i>{@code )).equals(}<i>v</i>{@code )}&nbsp;&nbsp;and<br>
 222  *   <i>u</i>{@code .resolve(}<i>u</i>{@code .relativize(}<i>v</i>{@code )).equals(}<i>v</i>{@code )}&nbsp;&nbsp;.<br>
 223  * </blockquote>
 224  *
 225  * This operation is often useful when constructing a document containing URIs
 226  * that must be made relative to the base URI of the document wherever
 227  * possible.  For example, relativizing the URI
 228  *
 229  * <blockquote>
 230  * {@code http://docs.oracle.com/javase/1.3/docs/guide/index.html}
 231  * </blockquote>
 232  *
 233  * against the base URI
 234  *
 235  * <blockquote>
 236  * {@code http://java.sun.com/j2se/1.3}
 237  * </blockquote>
 238  *
 239  * yields the relative URI {@code docs/guide/index.html}.
 240  *
 241  *
 242  * <h4> Character categories </h4>
 243  *
 244  * RFC&nbsp;2396 specifies precisely which characters are permitted in the
 245  * various components of a URI reference.  The following categories, most of
 246  * which are taken from that specification, are used below to describe these
 247  * constraints:
 248  *
 249  * <blockquote><table cellspacing=2 summary="Describes categories alpha,digit,alphanum,unreserved,punct,reserved,escaped,and other">
 250  *   <tr><th valign=top><i>alpha</i></th>