16 using System.Collections.Generic;
19 using erminas.SmartAPI.Exceptions;
20 using erminas.SmartAPI.Utils;
21 using erminas.SmartAPI.Utils.CachedCollections;
23 namespace erminas.SmartAPI.CMS.Project
31 internal class LanguageVariants : IndexedRDList<string, ILanguageVariant>, ILanguageVariants
33 private readonly IProject _project;
34 private ILanguageVariant _currentLanguageVariant;
36 internal LanguageVariants(IProject project,
Caching caching) : base(variant => variant.Abbreviation, caching)
39 RetrieveFunc = GetLanguageVariants;
45 public ILanguageVariant Current
50 return _currentLanguageVariant;
54 if (_currentLanguageVariant == value)
58 const string SELECT_LANGUAGE =
@"<LANGUAGEVARIANT action=""setactive"" guid=""{0}""/>";
59 XmlDocument xmlDoc = _project.ExecuteRQL(SELECT_LANGUAGE.RQLFormat(value.Guid.ToRQLString()),
61 if (!xmlDoc.IsContainingOk())
64 string.Format(
"Could not load language variant '{0}' for project {1}",
65 value.Abbreviation,
this));
67 if (_currentLanguageVariant != null)
69 ((LanguageVariant) _currentLanguageVariant).IsCurrentLanguageVariant =
false;
71 ((LanguageVariant) value).IsCurrentLanguageVariant =
true;
72 _currentLanguageVariant = value;
76 public ILanguageVariant Main
78 get {
return this.First(variant => variant.IsMainLanguage); }
81 public IProject Project
83 get {
return _project; }
86 public ISession Session
88 get {
return _project.Session; }
91 private List<ILanguageVariant> GetLanguageVariants()
93 const string LIST_LANGUAGE_VARIANTS =
94 @"<PROJECT projectguid=""{0}""><LANGUAGEVARIANTS action=""list""/></PROJECT>";
95 XmlDocument xmlDoc = Project.ExecuteRQL(LIST_LANGUAGE_VARIANTS.RQLFormat(Project));
96 XmlNodeList xmlNodes = xmlDoc.GetElementsByTagName(
"LANGUAGEVARIANT");
97 var languageVariants =
new List<ILanguageVariant>();
99 foreach (XmlElement curNode
in xmlNodes)
101 var variant =
new LanguageVariant(Project, curNode);
102 languageVariants.Add(variant);
103 if (variant.IsCurrentLanguageVariant)
105 _currentLanguageVariant = variant;
109 return languageVariants;