private void initializePath()

in modules/adb/src/org/apache/axis2/databinding/types/URI.java [824:953]


    private void initializePath(String p_uriSpec, int p_nStartIndex)
            throws MalformedURIException {
        if (p_uriSpec == null) {
            throw new MalformedURIException(
                    "Cannot initialize path from null string!");
        }

        int index = p_nStartIndex;
        int start = p_nStartIndex;
        int end = p_uriSpec.length();
        char testChar = '\0';

        // path - everything up to query string or fragment
        if (start < end) {
            // RFC 2732 only allows '[' and ']' to appear in the opaque part.
            if (getScheme() == null || p_uriSpec.charAt(start) == '/') {

                // Scan path.
                // abs_path = "/"  path_segments
                // rel_path = rel_segment [ abs_path ]
                while (index < end) {
                    testChar = p_uriSpec.charAt(index);

                    // check for valid escape sequence
                    if (testChar == '%') {
                        if (index + 2 >= end ||
                                !isHex(p_uriSpec.charAt(index + 1)) ||
                                !isHex(p_uriSpec.charAt(index + 2))) {
                            throw new MalformedURIException(
                                    "Path contains invalid escape sequence!");
                        }
                        index += 2;
                    }
                    // Path segments cannot contain '[' or ']' since pchar
                    // production was not changed by RFC 2732.
                    else if (!isPathCharacter(testChar)) {
                        if (testChar == '?' || testChar == '#') {
                            break;
                        }
                        throw new MalformedURIException(
                                "Path contains invalid character: " + testChar);
                    }
                    ++index;
                }
            } else {

                // Scan opaque part.
                // opaque_part = uric_no_slash *uric
                while (index < end) {
                    testChar = p_uriSpec.charAt(index);

                    if (testChar == '?' || testChar == '#') {
                        break;
                    }

                    // check for valid escape sequence
                    if (testChar == '%') {
                        if (index + 2 >= end ||
                                !isHex(p_uriSpec.charAt(index + 1)) ||
                                !isHex(p_uriSpec.charAt(index + 2))) {
                            throw new MalformedURIException(
                                    "Opaque part contains invalid escape sequence!");
                        }
                        index += 2;
                    }
                    // If the scheme specific part is opaque, it can contain '['
                    // and ']'. uric_no_slash wasn't modified by RFC 2732, which
                    // I've interpreted as an error in the spec, since the
                    // production should be equivalent to (uric - '/'), and uric
                    // contains '[' and ']'. - mrglavas
                    else if (!isURICharacter(testChar)) {
                        throw new MalformedURIException(
                                "Opaque part contains invalid character: " + testChar);
                    }
                    ++index;
                }
            }
        }
        m_path = p_uriSpec.substring(start, index);

        // query - starts with ? and up to fragment or end
        if (testChar == '?') {
            index++;
            start = index;
            while (index < end) {
                testChar = p_uriSpec.charAt(index);
                if (testChar == '#') {
                    break;
                }
                if (testChar == '%') {
                    if (index + 2 >= end ||
                            !isHex(p_uriSpec.charAt(index + 1)) ||
                            !isHex(p_uriSpec.charAt(index + 2))) {
                        throw new MalformedURIException(
                                "Query string contains invalid escape sequence!");
                    }
                    index += 2;
                } else if (!isURICharacter(testChar)) {
                    throw new MalformedURIException(
                            "Query string contains invalid character: " + testChar);
                }
                index++;
            }
            m_queryString = p_uriSpec.substring(start, index);
        }

        // fragment - starts with #
        if (testChar == '#') {
            index++;
            start = index;
            while (index < end) {
                testChar = p_uriSpec.charAt(index);

                if (testChar == '%') {
                    if (index + 2 >= end ||
                            !isHex(p_uriSpec.charAt(index + 1)) ||
                            !isHex(p_uriSpec.charAt(index + 2))) {
                        throw new MalformedURIException(
                                "Fragment contains invalid escape sequence!");
                    }
                    index += 2;
                } else if (!isURICharacter(testChar)) {
                    throw new MalformedURIException(
                            "Fragment contains invalid character: " + testChar);
                }
                index++;
            }
            m_fragment = p_uriSpec.substring(start, index);
        }
    }