public IEnumerable <ChromeLanguageInfo> GetLanguageInfo(PageData page)
        {
            List <ChromeLanguageInfo> languages     = new List <ChromeLanguageInfo>();
            ReadOnlyStringList        pageLanguages = page.PageLanguages;
            string currentLanguage = page.LanguageBranch;

            foreach (string language in pageLanguages)
            {
                LanguageBranch languageBranch = _languageBranchRepository.ListEnabled().FirstOrDefault(l => l.LanguageID.Equals(language, StringComparison.InvariantCultureIgnoreCase));
                if (languageBranch != null)
                {
                    languages.Add(new ChromeLanguageInfo()
                    {
                        DisplayName = languageBranch.Name,
                        IconUrl     = languageBranch.ResolvedIconPath, //"/Content/Images/flags/" + language + ".png",
                        // We use this to enable language switching inside edit mode too
                        Url      = languageBranch.CurrentUrlSegment,
                        EditUrl  = PageEditing.GetEditUrlForLanguage(page.ContentLink, languageBranch.LanguageID),
                        Selected = string.Compare(language, currentLanguage, StringComparison.InvariantCultureIgnoreCase) == 0
                    });
                }
            }

            return(languages);
        }
		public virtual void Save(LanguageBranch languageBranch)
		{
			if(languageBranch == null)
				throw new ArgumentNullException("languageBranch");

			languageBranch.Save();
		}
Exemplo n.º 3
0
 private IEnumerable <SelectListItem> PopulateLanguageBranchItems(string selectedItem)
 {
     return(LanguageBranch.ListEnabled().Select(language =>
                                                new SelectListItem {
         Text = language.Culture.Name, Value = language.Culture.Name, Selected = selectedItem.Equals(language.Culture.Name)
     }));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes the language link.
        /// Checks the number of available and enabled languages. If more than two,
        /// populates a dropdown-menu with the available and enabled languages.
        /// Otherwise sets the link to the not currently active language.
        /// </summary>
        private void SetLanguage()
        {
            PageDataCollection languageBranches = DataFactory.Instance.GetLanguageBranches(CurrentPage.PageLink);

            if (languageBranches == null)
            {
                return;
            }

            if (languageBranches.Count > 2)
            {
                LanguageList.Visible = LanguageListLabel.Visible = LanguageButton.Visible = LanguageList.Parent.Visible = true;

                foreach (PageData languageBranch in languageBranches)
                {
                    if (languageBranch.LanguageID != CurrentPage.LanguageID && LanguageBranch.Load(languageBranch.LanguageID).Enabled)
                    {
                        LanguageList.Items.Add(new System.Web.UI.WebControls.ListItem(new CultureInfo(languageBranch.LanguageID).NativeName, languageBranch.LanguageID));
                    }
                }
            }
            else
            {
                foreach (PageData languageBranch in languageBranches)
                {
                    if (languageBranch.LanguageID != CurrentPage.LanguageID && LanguageBranch.Load(languageBranch.LanguageID).Enabled)
                    {
                        Language.Visible     = Language.Parent.Visible = true;
                        Language.NavigateUrl = EPiServer.UriSupport.AddLanguageSelection(languageBranch.LinkURL, languageBranch.LanguageID);
                        Language.Text        = Translate(new CultureInfo(languageBranch.LanguageID).NativeName);
                        break;
                    }
                }
            }
        }
Exemplo n.º 5
0
        private static void UpdateLanguageBranches(IImportStatus status)
        {
            var languageBranchRepository = ServiceLocator.Current.GetInstance <ILanguageBranchRepository>();

            if (status.ContentLanguages == null)
            {
                return;
            }

            foreach (var languageId in status.ContentLanguages)
            {
                var languageBranch = languageBranchRepository.Load(languageId);

                if (languageBranch == null)
                {
                    languageBranch = new LanguageBranch(languageId);
                    languageBranchRepository.Save(languageBranch);
                }
                else if (!languageBranch.Enabled)
                {
                    languageBranch         = languageBranch.CreateWritableClone();
                    languageBranch.Enabled = true;
                    languageBranchRepository.Save(languageBranch);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// The get sitemap items.
        /// </summary>
        /// <param name="root">
        /// The root.
        /// </param>
        /// <param name="language">
        /// The language.
        /// </param>
        /// <returns>
        /// The <see cref="IList"/>.
        /// </returns>
        private List <PageData> GetSitemapItems(SiteDefinition root, LanguageBranch language)
        {
            var thisLanguage = language.Culture.DisplayName;

            var repository  = ServiceLocator.Current.GetInstance <IContentLoader>();
            var contentRoot = repository.Get <PageData>(root.StartPage);

            // Get all published pages which are visible and have not been excluded from the site map
            var descendants = new List <PageData>();

            PageDataHelper.GetChildrenRecursive(contentRoot.ContentLink, descendants);
            descendants = FilterForVisitor.Filter(descendants).OfType <PageData>().Where(x => x.Status == VersionStatus.Published &&
                                                                                         x.IsVisibleOnSite()).ToList();

            // TODO: Change current user to search for pages as in sitecore.
            var sitemapItems = descendants;

            // Limit the sitemap items to only those descendants that have a version in default language set in the site node configuration
            sitemapItems = sitemapItems.Where(x => x.ExistingLanguages.Any(l => l.DisplayName == thisLanguage)).ToList();

            // Add root
            sitemapItems.Insert(0, contentRoot);

            // Filter types which are not allowed
            var selected = from itm in sitemapItems
                           where this.IsRestricted(itm) == false
                           select itm;

            return(selected.ToList());
        }
Exemplo n.º 7
0
        private static ListItem CreateLanguageListItem(LanguageBranch language)
        {
            if (language.Name == language.Culture.DisplayName)
            {
                return(new ListItem(language.Name, language.Culture.Name));
            }

            return(new ListItem(language.Name + " (" + language.Culture.DisplayName + ")", language.Culture.Name));
        }
Exemplo n.º 8
0
        private static bool TryResolveCurrentForNonPage(string rewrittenPageUrl, LanguageBranch languageBranch)
        {
            Url rewrittenUrl = new Url(rewrittenPageUrl);

            //Get the current url from our request
            Url currentUrl = new Url(HttpContext.Current.Request.Url);

            //Are any of the segments equal, then assume the menu item is selected
            return(currentUrl.Segments.Any(segment => rewrittenUrl.Segments.Contains(segment) && !segment.Equals("/") && !segment.Equals(String.Format("{0}/", languageBranch.CurrentUrlSegment))));
        }
        /// <summary>
        /// Load the content for a <see cref="ContentReference"/>.
        /// </summary>
        /// <param name="contentLink">
        /// The content link.
        /// </param>
        /// <param name="languageSelector">
        /// The language selector.
        /// </param>
        /// <returns>
        /// The <see cref="IContent"/>.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// contentLink
        /// </exception>
        /// <exception cref="System.NotSupportedException">
        /// Only cloning of pages is supported
        /// </exception>
        protected override IContent LoadContent(ContentReference contentLink, ILanguageSelector languageSelector)
        {
            if (ContentReference.IsNullOrEmpty(contentLink) || contentLink.ID == 0)
            {
                throw new ArgumentNullException("contentLink");
            }

            if (languageSelector == null)
            {
                languageSelector = LanguageSelector.AutoDetect();
            }

            if (contentLink.WorkID > 0)
            {
                return(this.ContentStore.LoadVersion(contentLink, -1));
            }

            ILanguageBranchRepository languageBranchRepository =
                ServiceLocator.Current.GetInstance <ILanguageBranchRepository>();

            LanguageSelectorContext context = new LanguageSelectorContext(
                contentLink, languageBranchRepository, this.Load);

            if (contentLink.GetPublishedOrLatest)
            {
                languageSelector.SelectPageLanguage(context);

                LanguageBranch langBr = null;

                if (context.SelectedLanguage != null)
                {
                    langBr = languageBranchRepository.Load(context.SelectedLanguage);
                }

                return(this.ContentStore.LoadVersion(contentLink, langBr != null ? langBr.ID : -1));
            }

            languageSelector.SetInitializedLanguageBranch(context);

            // Get published version of Content
            IContent originalContent = this.ContentStore.Load(
                contentLink, context.SelectedLanguageBranch != null ? context.SelectedLanguageBranch.ID : -1);

            PageData page = originalContent as PageData;

            if (page == null)
            {
                throw new NotSupportedException("Only cloning of pages is supported");
            }

            return(this.ClonePage(page));
        }
        public void Execute()
        {
            var branch = _repository.Load(Culture);

            if (branch != null)
            {
                branch = branch.CreateWritableClone();

                branch.Enabled = Enabled;
                _repository.Save(branch);
            }
            else
            {
                branch         = new LanguageBranch(Culture);
                branch.Enabled = Enabled;
                _repository.Save(branch);
            }
        }
        protected override IContent LoadContent(ContentReference contentLink, ILanguageSelector languageSelector)
        {
            if (ContentReference.IsNullOrEmpty(contentLink) || contentLink.ID == 0)
            {
                throw new ArgumentNullException("contentLink");
            }

            if (contentLink.WorkID > 0)
            {
                return(_contentStore.LoadVersion(contentLink, -1));
            }

            var languageBranchRepository = DependencyHelper.LanguageBranchRepository;

            LanguageBranch langBr = null;

            if (languageSelector.Language != null)
            {
                langBr = languageBranchRepository.Load(languageSelector.Language);
            }

            if (contentLink.GetPublishedOrLatest)
            {
                return(_contentStore.LoadVersion(contentLink, langBr != null ? langBr.ID : -1));
            }

            // Get published version of Content
            var originalContent = _contentStore.Load(contentLink, langBr != null ? langBr.ID : -1);

            var page = originalContent as PageData;

            if (page == null)
            {
                throw new NotSupportedException("Only cloning of pages is supported");
            }

            return(ClonePage(page));
        }
		public void Delete_ShouldCallLoadAndDeleteOfTheWrappedLanguageBranch()
		{
			using(ShimsContext.Create())
			{
				bool loadIsCalled = false;
				bool deleteIsCalled = false;
				int? loadLanguageBranchIdValue = null;
				LanguageBranch loadedLanguageBranchValue = new LanguageBranch();
				LanguageBranch deleteLanguageBranchValue = null;

				ShimLanguageBranch.LoadInt32 = delegate(int languageBranchId)
				{
					loadLanguageBranchIdValue = languageBranchId;
					loadIsCalled = true;
					return loadedLanguageBranchValue;
				};

				ShimLanguageBranch.AllInstances.Delete = delegate(LanguageBranch languageBranch)
				{
					deleteLanguageBranchValue = languageBranch;
					deleteIsCalled = true;
				};

				int languageBranchIdParameter = DateTime.Now.Second;

				Assert.IsFalse(loadIsCalled);
				Assert.IsFalse(deleteIsCalled);

				new LanguageBranchWrapper().Delete(languageBranchIdParameter);

				Assert.IsTrue(loadIsCalled);
				Assert.IsTrue(deleteIsCalled);

				Assert.AreEqual(loadLanguageBranchIdValue.Value, languageBranchIdParameter);
				Assert.AreEqual(loadedLanguageBranchValue, deleteLanguageBranchValue);
			}
		}
Exemplo n.º 13
0
        /// <summary>
        /// The generate site maps.
        /// </summary>
        /// <param name="currentDataBase">
        /// The current data base.
        /// </param>
        public void GenerateSiteMaps(SitemapConfigurationDataStore currentDataBase = null)
        {
            LogHelper.Information("START: SitemapManager.SitemapManager", typeof(SitemapGenerator));

            this.dataFromBase = currentDataBase ?? this.sitemapManagerConfigurator.GetFirstData() ?? new SitemapConfigurationDataStore();

            this.sites                         = SitemapManagerConfiguration.GetSites(this.dataFromBase);
            this.maxUrls                       = int.Parse(ConfigurationManager.AppSettings["SiteMap_MAX_URLS"]);
            this.showLocalizedUrls             = bool.Parse(ConfigurationManager.AppSettings["Show_Localized_URLS"]);
            this.displayLocalizedUrlsSeparated = bool.Parse(ConfigurationManager.AppSettings["Display_Localized_URLS_Separated"]);
            this.showTrailingSlash             = bool.Parse(ConfigurationManager.AppSettings["Show_Trailing_Slash"]);

            var languageRep = ServiceLocator.Current.GetInstance <ILanguageBranchRepository>();

            this.defaultLanguage = languageRep.LoadFirstEnabledBranch();

            LogHelper.Information("SitemapManager.SitemapManager: # Sites: " + this.sites.Count, typeof(SitemapGenerator));
            foreach (DictionaryEntry site in this.sites)
            {
                this.BuildSiteMap(site.Key.ToString(), site.Value.ToString());
            }

            LogHelper.Information("END: SitemapManager.SitemapManager", typeof(SitemapGenerator));
        }
 public virtual void Delete(LanguageBranch languageBranch)
 {
     languageBranch.Delete();
 }
        private void UpdateLanguageBranches(DataImporter importer)
        {
            // Enable all language branches in the import package
            LanguageBranch languageBranch;
            foreach (string languageID in importer.ContentLanguages)
            {
                languageBranch = _languageBranchRepository.Load(languageID);

                if (languageBranch == null)
                {
                    languageBranch = new LanguageBranch(languageID, null);
                    _languageBranchRepository.Save(languageBranch);
                }
                else if (!languageBranch.Enabled)
                {
                    languageBranch = new LanguageBranch(languageBranch.ID, languageBranch.LanguageID, languageBranch.Name, languageBranch.SortIndex, languageBranch.RawIconPath, languageBranch.URLSegment, true);
                    _languageBranchRepository.Save(languageBranch);
                }
            }
        }
		public void LoadFirstEnabledBranch_ShouldCallLoadFirstEnabledBranchOfTheWrappedLanguageBranch()
		{
			using(ShimsContext.Create())
			{
				bool loadFirstEnabledBranchIsCalled = false;
				LanguageBranch loadFirstEnabledBranchValue = new LanguageBranch();

				ShimLanguageBranch.LoadFirstEnabledBranch = delegate
				{
					loadFirstEnabledBranchIsCalled = true;
					return loadFirstEnabledBranchValue;
				};

				Assert.IsFalse(loadFirstEnabledBranchIsCalled);
				Assert.AreEqual(loadFirstEnabledBranchValue, new LanguageBranchWrapper().LoadFirstEnabledBranch());
				Assert.IsTrue(loadFirstEnabledBranchIsCalled);
			}
		}
		public void Load_WithCultureInfoParameter_ShouldCallLoadWithCultureInfoParameterOfTheWrappedLanguageBranch()
		{
			using(ShimsContext.Create())
			{
				bool loadIsCalled = false;
				LanguageBranch loadedLanguageBranch = new LanguageBranch();
				CultureInfo cultureValue = null;

				ShimLanguageBranch.LoadCultureInfo = delegate(CultureInfo culture)
				{
					loadIsCalled = true;
					cultureValue = culture;
					return loadedLanguageBranch;
				};

				CultureInfo cultureParameter = CultureInfo.InvariantCulture;

				Assert.IsFalse(loadIsCalled);
				Assert.AreEqual(loadedLanguageBranch, new LanguageBranchWrapper().Load(cultureParameter));
				Assert.IsTrue(loadIsCalled);
				Assert.AreEqual(cultureValue, cultureParameter);
			}
		}
		public void Load_WithIntegerParameter_ShouldCallLoadWithIntegerParameterOfTheWrappedLanguageBranch()
		{
			using(ShimsContext.Create())
			{
				bool loadIsCalled = false;
				LanguageBranch loadedLanguageBranch = new LanguageBranch();
				int? idValue = null;

				ShimLanguageBranch.LoadInt32 = delegate(int id)
				{
					loadIsCalled = true;
					idValue = id;
					return loadedLanguageBranch;
				};

				int idParameter = DateTime.Now.Second;

				Assert.IsFalse(loadIsCalled);
				Assert.AreEqual(loadedLanguageBranch, new LanguageBranchWrapper().Load(idParameter));
				Assert.IsTrue(loadIsCalled);
				Assert.AreEqual(idValue.Value, idParameter);
			}
		}
Exemplo n.º 19
0
        /// <summary>
        /// Initializes the language link.
        /// Checks the number of available and enabled languages. If more than two,
        /// populates a dropdown-menu with the available and enabled languages.
        /// Otherwise sets the link to the not currently active language.
        /// </summary>
        private void SetLanguage()
        {
            PageDataCollection languageBranches = DataFactory.Instance.GetLanguageBranches(CurrentPage.PageLink);

            //Filter so pages with Replacement language is filtered away.
            new FilterReplacementLanguage().Filter(languageBranches);

            if (languageBranches.Count > 2)
            {
                LanguageList.Visible = LanguageListLabel.Visible = LanguageButton.Visible = LanguageList.Parent.Visible = true;
                foreach (PageData languageBranch in languageBranches.Where(p => p.LanguageID != CurrentPage.LanguageID && LanguageBranch.Load(p.LanguageID).Enabled))
                {
                    LanguageList.Items.Add(new System.Web.UI.WebControls.ListItem(new CultureInfo(languageBranch.LanguageID).NativeName, languageBranch.LanguageID));
                }
            }
            else
            {
                foreach (PageData languageBranch in languageBranches.Where(p => p.LanguageID != CurrentPage.LanguageID && LanguageBranch.Load(p.LanguageID).Enabled))
                {
                    Language.Visible     = Language.Parent.Visible = true;
                    Language.NavigateUrl = EPiServer.UriSupport.AddLanguageSelection(languageBranch.LinkURL, languageBranch.LanguageID);
                    Language.Text        = Translate(new CultureInfo(languageBranch.LanguageID).NativeName);
                    break;
                }
            }
        }
		public void Save_ShouldCallSaveOfTheLanguageBranchParameter()
		{
			using(ShimsContext.Create())
			{
				bool saveIsCalled = false;
				LanguageBranch languageBranchValue = null;
				LanguageBranch languageBranchParameter = new LanguageBranch();

				// ReSharper disable ObjectCreationAsStatement

				new ShimLanguageBranch(languageBranchParameter)
					{
						Save = delegate
						{
							saveIsCalled = true;
							languageBranchValue = languageBranchParameter;
						}
					};

				// ReSharper restore ObjectCreationAsStatement

				Assert.IsFalse(saveIsCalled);
				new LanguageBranchWrapper().Save(languageBranchParameter);
				Assert.IsTrue(saveIsCalled);
				Assert.AreEqual(languageBranchParameter, languageBranchValue);
			}
		}
Exemplo n.º 21
0
 private bool CheckAccessRightOnLanguageBranch(LanguageBranch languageBranch)
 {
     return(languageBranch.QueryEditAccessRights(PrincipalInfo.CurrentPrincipal));
 }
 public virtual void Save(LanguageBranch languageBranch)
 {
     languageBranch.Save();
 }