// static
std::string LLURLDispatcherImpl::stripProtocol(const std::string& url)
{
	std::string stripped = url;
	if (isIZURL(url))
	{
		if (matchPrefix(stripped, IZURL_IZ_HELP_PREFIX))
		{
			stripped.erase(0, IZURL_IZ_HELP_PREFIX.length());
		}
		else if (matchPrefix(stripped, IZURL_IZ_PREFIX))
		{
			stripped.erase(0, IZURL_IZ_PREFIX.length());
		}
		else if (matchPrefix(stripped, IZURL_INWORLDZ_PREFIX))
		{
			stripped.erase(0, IZURL_INWORLDZ_PREFIX.length());
		}
		else if (matchPrefix(stripped, IZURL_IZURL_PREFIX))
		{
			stripped.erase(0, IZURL_IZURL_PREFIX.length());
		}
	}
	else if (isSLURL(url))
	{
		if (matchPrefix(stripped, SLURL_SL_HELP_PREFIX))
		{
			stripped.erase(0, SLURL_SL_HELP_PREFIX.length());
		}
		else if (matchPrefix(stripped, SLURL_SL_PREFIX))
		{
			stripped.erase(0, SLURL_SL_PREFIX.length());
		}
		else if (matchPrefix(stripped, SLURL_SECONDLIFE_PREFIX))
		{
			stripped.erase(0, SLURL_SECONDLIFE_PREFIX.length());
		}
		else if (matchPrefix(stripped, SLURL_SLURL_PREFIX))
		{
			stripped.erase(0, SLURL_SLURL_PREFIX.length());
		}
		else if (matchPrefix(stripped, SLURL_SLURL_ALT_PREFIX))
		{
			stripped.erase(0, SLURL_SLURL_ALT_PREFIX.length());
		}
	}
	return stripped;
}
// static
bool LLURLDispatcherImpl::dispatchApp(const std::string& url, 
									  bool right_mouse,
									  LLWebBrowserCtrl* web,
									  bool trusted_browser)
{
	if (!isSLURL(url))
	{
		return false;
	}

	LLURI uri(url);
	LLSD pathArray = uri.pathArray();
	pathArray.erase(0); // erase "app"
	std::string cmd = pathArray.get(0);
	pathArray.erase(0); // erase "cmd"
	bool handled = LLCommandDispatcher::dispatch(
			cmd, pathArray, uri.queryMap(), web, trusted_browser);
	return handled;
}
// static
bool LLURLDispatcherImpl::dispatchApp(const std::string& url, 
									  bool right_mouse,
									  LLMediaCtrl* web,
									  bool trusted_browser)
{
	// we support legacy secondlife:///app links as well as inworldz:/// *only* in the text editor -- MC
	if (isIZURL(url) || isSLURL(url))
	{
		LLURI uri(url);
		LLSD pathArray = uri.pathArray();
		pathArray.erase(0); // erase "app"
		std::string cmd = pathArray.get(0);
		pathArray.erase(0); // erase "cmd"
		bool handled = LLCommandDispatcher::dispatch(
				cmd, pathArray, uri.queryMap(), web, trusted_browser);
		return handled;
	}
	return false;
}
// static
bool LLURLDispatcherImpl::dispatchRegion(const std::string& url, bool right_mouse)
{
	if (!isSLURL(url))
	{
		return false;
	}

	// Before we're logged in, need to update the startup screen
	// to tell the user where they are going.
	if (LLStartUp::getStartupState() < STATE_LOGIN_CLEANUP)
	{
		// Parse it and stash in globals, it will be dispatched in
		// STATE_CLEANUP.
		LLURLSimString::setString(url);
		// We're at the login screen, so make sure user can see
		// the login location box to know where they are going.
		
		LLPanelLogin::refreshLocation( true );
		return true;
	}

	std::string sim_string = stripProtocol(url);
	std::string region_name;
	S32 x = 128;
	S32 y = 128;
	S32 z = 0;
	LLURLSimString::parse(sim_string, &region_name, &x, &y, &z);

	LLFloaterURLDisplay* url_displayp = LLFloaterURLDisplay::getInstance(LLSD());
	url_displayp->setName(region_name);

	// Request a region handle by name
	LLWorldMap::getInstance()->sendNamedRegionRequest(region_name,
									  LLURLDispatcherImpl::regionNameCallback,
									  url,
									  false);	// don't teleport
	return true;
}