/** * Verify the valid class use for construction. * * @throws URIException the wrong scheme use */ protected void checkValid() throws URIException { // could be explicit protocol or undefined. if (!(equals(_scheme, DEFAULT_SCHEME) || _scheme == null)) { throw new URIException(URIException.PARSING, "wrong class use"); } }
/** * Verify the valid class use for construction. * * @throws URIException the wrong scheme use */ protected void checkValid() throws URIException { // could be explicit protocol or undefined. if (!(equals(_scheme, DEFAULT_SCHEME) || _scheme == null)) { throw new URIException(URIException.PARSING, "wrong class use"); } }
/** * Get the raw-escaped current hierarchy level in the given path. * If the last namespace is a collection, the slash mark ('/') should be * ended with at the last character of the path string. * * @param path the path * @return the current hierarchy level * @throws URIException no hierarchy level */ protected char[] getRawCurrentHierPath(char[] path) throws URIException { if (_is_opaque_part) { throw new URIException(URIException.PARSING, "no hierarchy level"); } if (path == null) { throw new URIException(URIException.PARSING, "empty path"); } String buff = new String(path); int first = buff.indexOf('/'); int last = buff.lastIndexOf('/'); if (last == 0) { return rootPath; } else if (first != last && last != -1) { return buff.substring(0, last).toCharArray(); } // FIXME: it could be a document on the server side return path; }
/** * Set the raw-escaped fragment. * * @param escapedFragment the raw-escaped fragment * @throws URIException escaped fragment not valid */ public void setRawFragment(char[] escapedFragment) throws URIException { if (escapedFragment == null || escapedFragment.length == 0) { _fragment = escapedFragment; hash = 0; return; } if (!validate(escapedFragment, fragment)) { throw new URIException(URIException.ESCAPING, "escaped fragment not valid"); } _fragment = escapedFragment; hash = 0; }
/** * Set the raw-escaped user. * * @param escapedUser the raw-escaped user * @throws URIException escaped user not valid or user required */ public void setRawUser(char[] escapedUser) throws URIException { if (escapedUser == null || escapedUser.length == 0) { throw new URIException(URIException.PARSING, "user required"); } if (!validate(escapedUser, within_userinfo)) { throw new URIException(URIException.ESCAPING, "escaped user not valid"); } String username = new String(escapedUser); char[] rawPassword = getRawPassword(); String password = rawPassword == null ? null : new String(rawPassword); String userinfo = username + ((password == null) ? "" : ":" + password); String hostname = new String(getRawHost()); String hostport = (_port == -1) ? hostname : hostname + ":" + _port; String authority = userinfo + "@" + hostport; _userinfo = userinfo.toCharArray(); _authority = authority.toCharArray(); setURI(); }
if ((scheme != null || authority != null) && !path.startsWith("/")) { throw new URIException(URIException.PARSING, "abs_path requested");
/** * Set the raw-escaped user and password. * * @param escapedUser the raw-escaped user * @param escapedPassword the raw-escaped password; could be null * @throws URIException escaped user not valid or user required; escaped * password not valid or username missed */ public void setRawUserinfo(char[] escapedUser, char[] escapedPassword) throws URIException { if (escapedUser == null || escapedUser.length == 0) { throw new URIException(URIException.PARSING, "user required"); } if (!validate(escapedUser, within_userinfo) || ((escapedPassword != null) && !validate(escapedPassword, within_userinfo))) { throw new URIException(URIException.ESCAPING, "escaped userinfo not valid"); } String username = new String(escapedUser); String password = (escapedPassword == null) ? null : new String(escapedPassword); String userinfo = username + ((password == null) ? "" : ":" + password); String hostname = new String(getRawHost()); String hostport = (_port == -1) ? hostname : hostname + ":" + _port; String authority = userinfo + "@" + hostport; _userinfo = userinfo.toCharArray(); _authority = authority.toCharArray(); setURI(); }
/** * Set the query as the name and value pairs. * * @param queryName the array of the query string. * @param queryValue the array of the query string. * @throws URIException incomplete trailing escape pattern, * unsupported character encoding or wrong array size * @throws NullPointerException null query * @see #encode */ public void setQuery(String[] queryName, String[] queryValue) throws URIException, NullPointerException { int length = queryName.length; if (length != queryValue.length) { throw new URIException("wrong array size of query"); } StringBuffer buff = new StringBuffer(); // set the charset to do escape encoding String charset = getProtocolCharset(); for (int i = 0; i < length; i++) { buff.append(encode(queryName[i], allowed_within_query, charset)); buff.append('='); buff.append(encode(queryValue[i], allowed_within_query, charset)); if (i + 1 < length) { buff.append('&'); } } _query = buff.toString().toCharArray(); setURI(); }
throw new URIException(URIException.PARSING, "scheme required"); throw new URIException(URIException.PARSING, "incorrect scheme");
/** * Set the raw-escaped password. * * @param escapedPassword the raw-escaped password; could be null * @throws URIException escaped password not valid or username missed */ public void setRawPassword(char[] escapedPassword) throws URIException { if (escapedPassword != null && !validate(escapedPassword, within_userinfo)) { throw new URIException(URIException.ESCAPING, "escaped password not valid"); } if (getRawUser() == null || getRawUser().length == 0) { throw new URIException(URIException.PARSING, "username required"); } String username = new String(getRawUser()); String password = escapedPassword == null ? null : new String(escapedPassword); // an emtpy string is allowed as a password String userinfo = username + ((password == null) ? "" : ":" + password); String hostname = new String(getRawHost()); String hostport = (_port == -1) ? hostname : hostname + ":" + _port; String authority = userinfo + "@" + hostport; _userinfo = userinfo.toCharArray(); _authority = authority.toCharArray(); setURI(); }
if (_is_net_path || _is_abs_path) { if (escapedPath[0] != '/') { throw new URIException(URIException.PARSING, "not absolute path"); throw new URIException(URIException.ESCAPING, "escaped absolute path not valid"); int at = indexFirstOf(escapedPath, '/'); if (at == 0) { throw new URIException(URIException.PARSING, "incorrect path"); || at < 0 && !validate(escapedPath, 0, -1, rel_segment)) { throw new URIException(URIException.ESCAPING, "escaped relative path not valid"); if (!uric_no_slash.get(escapedPath[0]) && !validate(escapedPath, 1, -1, uric)) { throw new URIException(URIException.ESCAPING, "escaped opaque part not valid"); throw new URIException(URIException.PARSING, "incorrect path");
int at = path.indexOf('/'); if (at == 0) { // never 0 throw new URIException(URIException.PARSING, "incorrect relative path"); _opaque = buf.toString().toCharArray(); } else { throw new URIException(URIException.PARSING, "incorrect path");
throw new URIException(URIException.PARSING, "abs_path requested");
throw new URIException(URIException.PARSING, "abs_path requested");
next = original.indexOf(']', from); if (next == -1) { throw new URIException(URIException.PARSING, "IPv6reference"); } else { next++; _authority = original.toCharArray(); if (!validate(_authority, reg_name)) { throw new URIException("Invalid authority"); _port = Integer.parseInt(original.substring(from)); } catch (NumberFormatException error) { throw new URIException(URIException.PARSING, "invalid port number");
throw new URIException("URI-Reference required"); _scheme = target; } else { throw new URIException("incorrect scheme"); _query = tmp.substring(at + 1, next).toCharArray(); if (!validate(_query, uric)) { throw new URIException("Invalid query");
/** * Set the raw-escaped query. * * @param escapedQuery the raw-escaped query * @throws URIException escaped query not valid */ public void setRawQuery(char[] escapedQuery) throws URIException { if (escapedQuery == null || escapedQuery.length == 0) { _query = escapedQuery; setURI(); return; } // remove the fragment identifier escapedQuery = removeFragmentIdentifier(escapedQuery); if (!validate(escapedQuery, query)) { throw new URIException(URIException.ESCAPING, "escaped query not valid"); } _query = escapedQuery; setURI(); }
rawdata = URLCodec.decodeUrl(EncodingUtil.getAsciiBytes(component)); } catch (DecoderException e) { throw new URIException(e.getMessage());
/** * Unescape and decode a given string regarded as an escaped string with the * default protocol charset. * * @param escaped a string * @return the unescaped string * * @throws URIException if the string cannot be decoded (invalid) * * @see URI#getDefaultProtocolCharset */ public static String decode(String escaped) throws URIException { try { byte[] rawdata = URLCodec.decodeUrl(EncodingUtil.getAsciiBytes(escaped)); return EncodingUtil.getString(rawdata, URI.getDefaultProtocolCharset()); } catch (DecoderException e) { throw new URIException(e.getMessage()); } }
throw new URIException(URIException.PARSING, "base URI required");