19 using erminas.SmartAPI.Exceptions;
20 using erminas.SmartAPI.Utils;
22 namespace erminas.SmartAPI.CMS.Project.Keywords
42 void DeleteForcibly();
62 void Rename(
string newCategoryName);
65 internal class ArbitraryCategory : ICategory
67 public static readonly ArbitraryCategory INSTANCE =
new ArbitraryCategory();
69 private ArbitraryCategory()
75 throw new NotImplementedException();
78 public void DeleteForcibly()
80 throw new NotImplementedException();
83 public void EnsureInitialization()
85 throw new NotImplementedException();
90 get {
return Guid.Empty; }
93 public CategoryKeywords Keywords
95 get {
throw new NotImplementedException(); }
98 public ILanguageVariant LanguageVariant
100 get {
throw new NotImplementedException(); }
105 get {
throw new NotImplementedException(); }
108 public IProject Project
110 get {
throw new NotImplementedException(); }
113 public void Refresh()
115 throw new NotImplementedException();
118 public void Rename(
string newCategoryName)
120 throw new NotImplementedException();
123 public ISession Session
125 get {
throw new NotImplementedException(); }
128 void ICategory.Delete()
130 throw new NotImplementedException();
133 void IDeletable.Delete()
135 throw new NotImplementedException();
142 internal class Category : PartialRedDotProjectObject, ICategory
144 private ILanguageVariant _languageVariant;
146 internal Category(IProject project, XmlElement xmlElement) : base(project, xmlElement)
148 Keywords =
new CategoryKeywords(
this);
152 public Category(IProject project, Guid guid) : base(project, guid)
154 Keywords =
new CategoryKeywords(
this);
162 const string SAVE_CATEGORY =
@"<PROJECT><CATEGORY action=""save"" guid=""{0}"" value=""{1}""/></PROJECT>";
163 string htmlEncodedName = HttpUtility.HtmlEncode(Name);
164 var xmlDoc = Project.ExecuteRQL(
string.Format(SAVE_CATEGORY, Guid.ToRQLString(), htmlEncodedName));
166 const string CATEGORY_XPATH_TEMPLATE =
"/IODATA/CATEGORY[@value='{0}' and @guid='{1}']";
167 string categoryXPath = CATEGORY_XPATH_TEMPLATE.RQLFormat(htmlEncodedName,
this);
168 var category = xmlDoc.SelectSingleNode(categoryXPath);
169 if (category == null)
172 string.Format(
"Could not rename category to '{0}'", Name));
182 const string DELETE_CATEGORY =
@"<CATEGORY action=""delete"" guid=""{0}"" force=""0""/>";
184 var xmlDoc = Project.ExecuteRQL(DELETE_CATEGORY.RQLFormat(
this),
RqlType.SessionKeyInProject);
185 var category = (XmlElement) xmlDoc.SelectSingleNode(
"/IODATA/CATEGORY");
187 if (category == null)
189 throw new SmartAPIException(Session.ServerLogin,
string.Format(
"Could not delete category {0}",
this));
192 if (IsCategoryStillUsed(category))
196 "Could not delete category {0}, because a keyword is still assigned to a page",
200 Project.Categories.InvalidateCache();
208 public void DeleteForcibly()
210 const string DELETE_KEYWORD =
@"<CATEGORY action=""delete"" guid=""{0}"" force=""1"" password=""{1}"" />";
213 Project.ExecuteRQL(DELETE_KEYWORD.RQLFormat(
this, Project.Session.ServerLogin.AuthData.Password),
215 var category = (XmlElement) xmlDoc.SelectSingleNode(
"/IODATA/CATEGORY");
217 if (category == null)
219 throw new SmartAPIException(Session.ServerLogin,
string.Format(
"Could not delete keyword {0}",
this));
222 Project.Categories.InvalidateCache();
228 public CategoryKeywords Keywords {
get;
private set; }
233 public ILanguageVariant LanguageVariant
235 get {
return LazyLoad(ref _languageVariant); }
249 public void Rename(
string newCategoryName)
251 Name = newCategoryName;
255 protected override void LoadWholeObject()
260 protected override XmlElement RetrieveWholeObject()
262 const string LOAD_CATEGORY =
@"<PROJECT><CATEGORY action=""load"" guid=""{0}""/></PROJECT>";
265 Project.ExecuteRQL(
string.Format(LOAD_CATEGORY, Guid.ToRQLString())).GetElementsByTagName(
"CATEGORY")[0];
268 private static bool IsCategoryStillUsed(XmlElement category)
270 return category.GetIntAttributeValue(
"countkeywordonpag") > 0 ||
271 category.GetIntAttributeValue(
"countkeywordonpge") > 0 ||
272 category.GetIntAttributeValue(
"countkeywordonpgeandpag") > 0;
275 private void LoadXml()
277 EnsuredInit(ref _name,
"value", HttpUtility.HtmlDecode);
278 InitIfPresent(ref _languageVariant,
"languagevariantid", x => Project.LanguageVariants[x]);