public String toString()

in wicket-request/src/main/java/org/apache/wicket/request/Url.java [748:823]


	public String toString(StringMode mode, Charset charset)
	{
		// this method is rarely called with StringMode == FULL.

		final CharSequence path = getPathInternal(charset);
		final String queryString = getQueryString(charset);
		String _fragment = getFragment();

		// short circuit all the processing in the most common cases
		if (StringMode.FULL != mode && Strings.isEmpty(_fragment))
		{
			if (queryString == null)
			{
				return path.toString();
			}
			else
			{
				return path + "?" + queryString;
			}
		}

		// fall through into the traditional code path

		StringBuilder result = new StringBuilder(64);

		if (StringMode.FULL == mode)
		{
			if (Strings.isEmpty(host))
			{
				throw new IllegalStateException("Cannot render this url in " +
					StringMode.FULL.name() + " mode because it does not have a host set.");
			}

			if (Strings.isEmpty(protocol) == false)
			{
				result.append(protocol);
				result.append("://");
			}
			else if (Strings.isEmpty(protocol) && Strings.isEmpty(host) == false)
			{
				result.append("//");
			}
			result.append(host);

			if (port != null && port.equals(getDefaultPortForProtocol(protocol)) == false)
			{
				result.append(':');
				result.append(port);
			}

			if (segments.contains(".."))
			{
				throw new IllegalStateException("Cannot render this url in " +
					StringMode.FULL.name() + " mode because it has a `..` segment: " + toString());
			}

			if (!path.isEmpty() && !(path.charAt(0) == '/'))
			{
				result.append('/');
			}
		}

		result.append(path);

		if (queryString != null)
		{
			result.append('?').append(queryString);
		}

		if (Strings.isEmpty(_fragment) == false)
		{
			result.append('#').append(_fragment);
		}

		return result.toString();
	}