Find a point in URI where URI can be split into a namespace part and a local name : URI « Network « Java Tutorial






/*
 * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
 *
 * Licensed under the Aduna BSD-style license.
 */


public class Utils {

  /**
   * Tries to find a point in the supplied URI where this URI can be safely
   * split into a namespace part and a local name. According to the XML
   * specifications, a local name must start with a letter or underscore and
   * can be followed by zero or more 'NCName' characters.
   *
   * @param uri The URI to split.
   * @return The index of the first character of the local name, or
   * <tt>-1</tt> if the URI can not be split into a namespace and local name.
   */
  public static int findURISplitIndex(String uri) {
    int uriLength = uri.length();

    // Search last character that is not an NCName character
    int i = uriLength - 1;
    while (i >= 0) {
      char c = uri.charAt(i);

      // Check for # and / characters explicitly as these
      // are used as the end of a namespace very frequently
      if (c == '#' || c == '/' || !XMLUtil.isNCNameChar(c)) {
        // Found it at index i
        break;
      }

      i--;
    }

    // Character after the just found non-NCName character could
    // be an NCName character, but not a letter or underscore.
    // Skip characters that are not letters or underscores.
    i++;
    while (i < uriLength) {
      char c = uri.charAt(i);

      if (c == '_' || XMLUtil.isLetter(c)) {
        break;
      }

      i++;
    }

    // Check that a legal split point has been found
    if (i == uriLength) {
      i = -1;
    }

    return i;
  }

}








19.1.URI
19.1.1.Get URI from File
19.1.2.Convert a URL to a URI
19.1.3.Converting Between a URL and a URI
19.1.4.Convert an absolute URI to a URL
19.1.5.Normalize a uri containing ../ and ./ paths.
19.1.6.Converting Between a Filename Path and a URL
19.1.7.A class to represent a Uniform Resource Identifier (URI).
19.1.8.Add parameters stored in the Map to the uri string.
19.1.9.Remove parameters from a uri.
19.1.10.Remove any authorisation details from a URI
19.1.11.URI
19.1.12.Add two URI path segments
19.1.13.Create and resolve URI
19.1.14.Encode a URI path
19.1.15.Find a point in URI where URI can be split into a namespace part and a local name
19.1.16.Get Parent URI
19.1.17.Is Equal URI
19.1.18.Return True if the uri has a scheme