17 using System.Collections.Generic;
20 using erminas.SmartAPI.Exceptions;
21 using erminas.SmartAPI.Utils;
22 using erminas.SmartAPI.Utils.CachedCollections;
24 namespace erminas.SmartAPI.CMS.Project.ContentClasses
26 internal class TemplateVariants : NameIndexedRDList<ITemplateVariant>, ITemplateVariants
28 private readonly IContentClass _contentClass;
30 internal TemplateVariants(IContentClass contentClass,
Caching caching) : base(caching)
32 _contentClass = contentClass;
33 RetrieveFunc = GetTemplateVariants;
36 public IContentClass ContentClass
38 get {
return _contentClass; }
41 public void CreateTemplateVariant(TemplateVariantCreationOptions options)
45 throw new SmartAPIException(Session.ServerLogin,
"Missing Name value for template creation");
48 const string CREATE_TEMPLATE_VARIANT =
@"<TEMPLATE action=""assign"" guid=""{0}"">
49 <TEMPLATEVARIANTS action=""addnew"">
50 <TEMPLATEVARIANT name=""{1}"" description="""" code=""{2}"" fileextension=""{3}"" insertstylesheetinpage=""{4}"" nostartendmarkers=""{5}"" containerpagereference=""{6}"">{2}</TEMPLATEVARIANT>
54 var command = CREATE_TEMPLATE_VARIANT.SecureRQLFormat(ContentClass, options.Name, options.Data,
55 options.FileExtension, options.IsStylesheetIncludedInHeader, !options.ContainsAreaMarksInPage,
56 options.HasContainerPageReference);
58 Project.ExecuteRQL(command,
RqlType.SessionKeyInProject);
63 public IProject Project
65 get {
return _contentClass.Project; }
68 public ISession Session
70 get {
return _contentClass.Session; }
73 private List<ITemplateVariant> GetTemplateVariants()
75 const string LIST_CC_TEMPLATES =
76 @"<PROJECT><TEMPLATE guid=""{0}""><TEMPLATEVARIANTS action=""list"" withstylesheets=""0""/></TEMPLATE></PROJECT>";
77 var xmlDoc = Project.ExecuteRQL(LIST_CC_TEMPLATES.RQLFormat(_contentClass));
78 var variants = xmlDoc.GetElementsByTagName(
"TEMPLATEVARIANT");
80 (from XmlElement curVariant in variants
81 select (ITemplateVariant)
new TemplateVariant(_contentClass, curVariant)).ToList();
92 public string Name {
get;
set; }
93 public string FileExtension {
get;
set; }
94 public bool IsStylesheetIncludedInHeader {
get;
set; }
95 public bool HasContainerPageReference {
get;
set; }
96 public bool ContainsAreaMarksInPage {
get;
set; }
97 public bool IsValid {
get {
return Name != null; }}
98 public string Data {
get;
set; }