private AlternativeUrlInfo GetAlternativeUrlInfo(string url, int altUrlId = 0)
    {
        AlternativeUrlInfo alternativeUrl;

        if (altUrlId > 0)
        {
            alternativeUrl = AlternativeUrlInfoProvider.GetAlternativeUrlInfo(altUrlId);
            if (alternativeUrl == null)
            {
                return(null);
            }
        }
        else
        {
            alternativeUrl = new AlternativeUrlInfo
            {
                AlternativeUrlDocumentID = EditedDocument.DocumentID,
                AlternativeUrlSiteID     = SiteContext.CurrentSiteID
            };
        }

        alternativeUrl.AlternativeUrlUrl = AlternativeUrlHelper.NormalizeAlternativeUrl(url);

        return(alternativeUrl);
    }
        /// <summary>
        /// Returns a page by its URL.
        /// </summary>
        /// <param name="pageUrl">Page preview URL.</param>
        /// <returns><see cref="TreeNode"/> representing the page, otherwise returns null.</returns>
        /// <exception cref="ArgumentNullException"> if <paramref name="pageUrl"/> is <c>null</c>.</exception>
        public TreeNode GetPage(string pageUrl)
        {
            pageUrl = pageUrl ?? throw new ArgumentNullException(nameof(pageUrl));

            NormalizedAlternativeUrl alternativeUrl = AlternativeUrlHelper.NormalizeAlternativeUrl(pageUrl);

            // Handle the site root
            if (String.IsNullOrEmpty(alternativeUrl.NormalizedUrl))
            {
                return(new TreeProvider().SelectSingleNode(site.SiteName, "/", site.DefaultVisitorCulture));
            }

            return(AlternativeUrlHelper.GetConflictingPage(new AlternativeUrlInfo()
            {
                AlternativeUrlSiteID = site.SiteID,
                AlternativeUrlUrl = alternativeUrl,
            }));
        }
    /// <summary>
    /// Returns <see cref="String.Empty"/> when <paramref name="alternativeUrl"/> was saved.
    /// If error occurs during saving the <paramref name="alternativeUrl"/>, corresponding error message is returned.
    /// </summary>
    private string SaveData(AlternativeUrlInfo alternativeUrl)
    {
        alternativeUrl.AlternativeUrlUrl = AlternativeUrlHelper.NormalizeAlternativeUrl(txtAltUrl.Text);

        if (String.IsNullOrWhiteSpace(alternativeUrl.AlternativeUrlUrl.NormalizedUrl))
        {
            return(GetString("general.requiresvalue"));
        }

        try
        {
            AlternativeUrlInfoProvider.SetInfoCheckForConflictingPage(alternativeUrl);
        }
        catch (InvalidAlternativeUrlException ex) when(ex.CollisionData != null)
        {
            var collisionData = ex.CollisionData;

            if (collisionData.CultureVersionExists)
            {
                var editDocumentLink = $"<a onclick=\"window.CMSContentManager.changed(false); EditDocument({collisionData.NodeID}, 'Properties.URLs', {ScriptHelper.GetString(collisionData.CultureCode)})\">{GetDocumentIdentification(collisionData.PageName, collisionData.CultureCode)}</a>";
                return(String.Format(GetString("alternativeurl.isinconflictwithpage"), alternativeUrl.AlternativeUrlUrl, editDocumentLink));
            }
            else
            {
                var editDocumentLink = $"<a onclick=\"window.CMSContentManager.changed(false); EditDocument({collisionData.NodeID}, 'Properties.URLs|{PageRoutingUIHelper.SLUGS_LIST_SUBTAB_NAME}', {ScriptHelper.GetString(collisionData.ExistingCultureCode)})\">{collisionData.PageName}</a>";
                return(String.Format(GetString("alternativeurl.isinconflictwithnottranslatedpage"), alternativeUrl.AlternativeUrlUrl, GetCultureShortName(collisionData.CultureCode), editDocumentLink));
            }
        }
        catch (InvalidAlternativeUrlException ex) when(ex.ConflictingAlternativeUrl != null)
        {
            var page             = DocumentHelper.GetDocument(ex.ConflictingAlternativeUrl.AlternativeUrlDocumentID, new TreeProvider());
            var editDocumentLink = $"<a onclick=\"window.CMSContentManager.changed(false); EditDocument({page.NodeID}, 'Properties.URLs', {ScriptHelper.GetString(page.DocumentCulture)})\">{GetDocumentIdentification(page)}</a>";

            return(String.Format(GetString("alternativeurl.isinconflictwithalternativeurl"), alternativeUrl.AlternativeUrlUrl, editDocumentLink));
        }
        catch (InvalidAlternativeUrlException ex) when(!String.IsNullOrEmpty(ex.ExcludedUrl) || ex.AlternativeUrl != null)
        {
            var errorMessage = SettingsKeyInfoProvider.GetValue("CMSAlternativeURLsErrorMessage", Node.NodeSiteID);

            return(String.IsNullOrEmpty(errorMessage) ?
                   GetString("settingskey.cmsalternativeurlsfallbackerrormessage") :
                   ResHelper.LocalizeString(errorMessage));
        }
        catch (InvalidAlternativeUrlException)
        {
            return(String.Format(GetString("general.mustbeunique"), TypeHelper.GetNiceObjectTypeName(AlternativeUrlInfo.OBJECT_TYPE)));
        }
        catch (RegexMatchTimeoutException)
        {
            return(String.Format(GetString("settingskey.cmsalternativeurlstimeouterrormessage"), alternativeUrl.AlternativeUrlUrl));
        }
        catch (Exception ex)
        {
            Service.Resolve <IEventLogService>().LogException("Alternative URLs", "EDIT", ex);
            return(GetString("alternativeurl.generalerror"));
        }

        DocumentManager.SaveDocument();

        txtAltUrl.Text = alternativeUrl.AlternativeUrlUrl.NormalizedUrl;

        return(String.Empty);
    }