private static void BuildFolderPaths(SitemapBuildingData pagesData, IEnumerable<XElement> elements, IDictionary<string, Guid> urlToIdLookup, IPageUrlBuilder builder) { foreach (XElement element in elements) { Guid pageId = new Guid(element.Attribute(AttributeNames.Id).Value); IPage page = pagesData.PageById[pageId]; IPageStructure pageStructure = pagesData.StructureById[pageId]; if (pageStructure == null) { continue; } Guid parentId = pageStructure.ParentId; PageUrlSet pageUrls = builder.BuildUrlSet(page, parentId); if(pageUrls == null) { continue; } element.Add(new XAttribute(AttributeNames.URL, pageUrls.PublicUrl)); string lookupUrl = pageUrls.PublicUrl; if(pageUrls.FriendlyUrl != null) { element.Add(new XAttribute(AttributeNames.FriendlyUrl, pageUrls.FriendlyUrl)); } //// FolderPath isn't used any more //element.Add(new XAttribute("FolderPath", builder.FolderPaths[pageId])); element.Add(new XAttribute(AttributeNames.Depth, 1 + element.Ancestors(PageElementName).Count())); // NOTE: urlToIdLookup is obsolete, but old API needs it if (urlToIdLookup.ContainsKey(lookupUrl)) { Log.LogError(LogTitle, "Multiple pages share the same path '{0}', page ID: '{1}'. Duplicates are ignored.".FormatWith(pageUrls.PublicUrl, pageId)); continue; } urlToIdLookup.Add(lookupUrl, pageId); BuildFolderPaths(pagesData, element.Elements(), urlToIdLookup, builder); } }
public PageUrlSet BuildUrlSet(IPage page, Guid parentPageId) { Verify.ArgumentNotNull(page, "page"); Verify.ArgumentCondition(page.DataSourceId.PublicationScope == _publicationScope, "page", "Page belongs to a wrong publication scope"); Verify.ArgumentCondition(page.DataSourceId.LocaleScope.Name == _localizationScope.Name, "page", "Page belongs to a wrong localization scope"); DataScopeIdentifier dataScopeIdentifier = page.DataSourceId.DataScopeIdentifier; CultureInfo cultureInfo = page.DataSourceId.LocaleScope; string parentPath; IHostnameBinding appliedHostnameBinding = null; // Checking if it is a root-level page if (parentPageId == Guid.Empty) { parentPath = GetRootPageBaseUrl(page.Id, cultureInfo, out appliedHostnameBinding); } else { Verify.That(_folderPaths.ContainsKey(parentPageId), "Method BuildUrlInternal() should be called for parent page before running for childildren, so 'urlBuildingCache' parameter will contains parent pages data."); parentPath = _folderPaths[parentPageId]; } // Building folderPath & lookup url string lookupUrl, folderPath; if (page.UrlTitle == string.Empty || (appliedHostnameBinding != null && !appliedHostnameBinding.IncludeHomePageInUrl && appliedHostnameBinding.HomePageId == page.Id)) { // Extensionless root url lookupUrl = folderPath = (parentPath == "" ? "/" : parentPath); } else { string parentPathWithSlash = parentPath + (parentPath.EndsWith("/") ? "" : "/"); string urlTitle = page.UrlTitle; #if URLDEBUG urlTitle = UrlFormattersPluginFacade.FormatUrl(urlTitle, true); #endif folderPath = parentPathWithSlash + urlTitle; lookupUrl = folderPath + UrlSuffix; } _folderPaths.Add(page.Id, folderPath); string lookupUrlLowerCased = lookupUrl.ToLowerInvariant(); if (UrlToIdLookupLowerCased.ContainsKey(lookupUrlLowerCased)) { if (!_knownNotUniqueUrls.Contains(lookupUrlLowerCased)) { lock (_knownNotUniqueUrls) { _knownNotUniqueUrls.Add(lookupUrlLowerCased); } Log.LogError(LogTitle, "Multiple pages share the same path '{0}'. Page ID: '{1}'. Duplicates are ignored.".FormatWith(lookupUrlLowerCased, page.Id)); } return(null); } UrlToIdLookupLowerCased.Add(lookupUrlLowerCased, page.Id); UrlToIdLookup.Add(lookupUrl, page.Id); IdToUrlLookup.Add(page.Id, lookupUrl); // Building redirect folder path & url string redirectParentPath = (parentPageId == Guid.Empty) ? GetRedirectBaseUrl(cultureInfo) : _redirectFolderPaths[parentPageId]; if (redirectParentPath != null) { string redirectLookupUrl; string redirectFolderPath; if (!page.UrlTitle.IsNullOrEmpty()) { string parentPathWithTrailingSlash = redirectParentPath + (redirectParentPath.EndsWith("/") ? "" : "/"); redirectFolderPath = parentPathWithTrailingSlash + page.UrlTitle; redirectLookupUrl = redirectFolderPath + UrlSuffix; } else { redirectLookupUrl = redirectFolderPath = redirectParentPath; } if (redirectLookupUrl != lookupUrl || UrlSuffix == string.Empty) { _redirectFolderPaths.Add(page.Id, redirectFolderPath); string redirectLookupUrlLowerCased = redirectLookupUrl.ToLowerInvariant(); if (redirectLookupUrlLowerCased != lookupUrlLowerCased) { if (!RedirectUrlToIdLookupLowerCased.ContainsKey(redirectLookupUrlLowerCased)) { RedirectUrlToIdLookupLowerCased.Add(redirectLookupUrlLowerCased, page.Id); } } if (UrlSuffix == string.Empty) { string aspxExtensionRedirectUrl = redirectLookupUrlLowerCased + ".aspx"; if (!RedirectUrlToIdLookupLowerCased.ContainsKey(aspxExtensionRedirectUrl)) { RedirectUrlToIdLookupLowerCased.Add(aspxExtensionRedirectUrl, page.Id); } } } } string url = lookupUrl; if (_forceRelativeUrls) { url = UrlUtils.Combine(url, DefaultPageUrlProvider.UrlMarker_RelativeUrl); } if (dataScopeIdentifier.Name == DataScopeIdentifier.AdministratedName) { url = UrlUtils.Combine(url, DefaultPageUrlProvider.UrlMarker_Unpublished); } var pageUrls = new PageUrlSet { PublicUrl = url }; if (!string.IsNullOrEmpty(page.FriendlyUrl)) { string friendlyUrl = _friendlyUrlPrefix + MakeRelativeUrl(page.FriendlyUrl); string lowerCasedFriendlyUrl = friendlyUrl.ToLowerInvariant(); if (!FriendlyUrlToIdLookup.ContainsKey(lowerCasedFriendlyUrl)) { pageUrls.FriendlyUrl = friendlyUrl; FriendlyUrlToIdLookup.Add(lowerCasedFriendlyUrl, page.Id); } if (_friendlyUrlPrefixWithLanguageCode != null) { string alternativeFriendlyUrl = (_friendlyUrlPrefixWithLanguageCode + MakeRelativeUrl(page.FriendlyUrl)).ToLowerInvariant(); if (!FriendlyUrlToIdLookup.ContainsKey(alternativeFriendlyUrl)) { FriendlyUrlToIdLookup.Add(alternativeFriendlyUrl, page.Id); } } } return(pageUrls); }