SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IContentClassEditableAreaSettings.cs
Go to the documentation of this file.
1 // SmartAPI - .Net programmatic access to RedDot servers
2 //
3 // Copyright (C) 2013 erminas GbR
4 //
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free Software Foundation,
7 // either version 3 of the License, or (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 // See the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program.
14 // If not, see <http://www.gnu.org/licenses/>.
15 
16 using System;
17 using System.Runtime.CompilerServices;
18 using System.Xml;
19 using erminas.SmartAPI.Exceptions;
20 using erminas.SmartAPI.Utils;
21 using erminas.SmartAPI.Utils.CachedCollections;
22 
23 namespace erminas.SmartAPI.CMS.Project.ContentClasses
24 {
26  {
27  string BorderColor { get; set; }
28 
29  string BorderStyle { get; set; }
30 
31  string BorderWidth { get; set; }
32 
33  void Commit();
34 
35  bool IsUsingBorderDefinitionFromProjectSetting { get; set; }
36 
37  bool IsUsingBordersToHighlightPages { get; set; }
38  }
39 
43  internal class CCEditableAreaSettings : AbstractAttributeContainer, IContentClassEditableAreaSettings
44  {
45  private readonly IContentClass _parent;
46 
47  internal CCEditableAreaSettings(IContentClass parent) : base(parent.Session)
48  {
49  _parent = parent;
50  }
51 
52  [RedDot("bordercolor")]
53  public string BorderColor
54  {
55  get { return GetAttributeValue<string>(); }
56  set { SetAttributeValue(value); }
57  }
58 
59  [RedDot("borderstyle")]
60  public string BorderStyle
61  {
62  get
63  {
64  EnsureInitialization();
65  return GetAttributeValue<string>();
66  }
67  set { SetAttributeValue(value); }
68  }
69 
70  [RedDot("borderwidth")]
71  public string BorderWidth
72  {
73  get
74  {
75  EnsureInitialization();
76  return GetAttributeValue<string>();
77  }
78  set
79  {
80  EnsureInitialization();
81  SetAttributeValue(value);
82  }
83  }
84 
85  public void Commit()
86  {
87  EnsureInitialization();
88  const string SAVE_CC_SETTINGS = @"<TEMPLATE guid=""{0}"">{1}</TEMPLATE>";
89  var query = SAVE_CC_SETTINGS.RQLFormat(_parent, RedDotObject.GetSaveString(_readWriteWrapper.MergedElement));
90 
91  var result = _parent.Project.ExecuteRQL(query, RqlType.SessionKeyInProject);
92 
93  if (result.GetElementsByTagName("SETTINGS").Count != 1)
94  {
95  throw new SmartAPIException(Session.ServerLogin,
96  String.Format("Could not save settings for content class {0}", _parent));
97  }
98  }
99 
100  public void InvalidateCache()
101  {
102  XmlElement = null;
103  }
104 
105  [RedDot("usedefaultrangesettings")]
106  public bool IsUsingBorderDefinitionFromProjectSetting
107  {
108  get { return GetAttributeValue<bool>(); }
109  set { SetAttributeValue(value); }
110  }
111 
112  [RedDot("showpagerange")]
113  public bool IsUsingBordersToHighlightPages
114  {
115  get { return GetAttributeValue<bool>(); }
116  set { SetAttributeValue(value); }
117  }
118 
119  public IProject Project
120  {
121  get { return _parent.Project; }
122  }
123 
124  public void Refresh()
125  {
126  InvalidateCache();
127  XmlElement = RetrieveWholeObject();
128  }
129 
130  public override XmlElement XmlElement
131  {
132  get { return base.XmlElement ?? (XmlElement = RetrieveWholeObject()); }
133  protected internal set { base.XmlElement = value; }
134  }
135 
136  protected override T GetAttributeValue<T>([CallerMemberName] string callerName = "")
137  {
138  EnsureInitialization();
139  return base.GetAttributeValue<T>(callerName);
140  }
141 
142  protected override void SetAttributeValue<T>(T value, [CallerMemberName] string callerName = "")
143  {
144  EnsureInitialization();
145  base.SetAttributeValue(value, callerName);
146  }
147 
148  private void EnsureInitialization()
149  {
150  if (_readWriteWrapper == null)
151  {
152  Refresh();
153  }
154  }
155 
156  private XmlElement RetrieveWholeObject()
157  {
158  const string LOAD_CC_SETTINGS = @"<TEMPLATE guid=""{0}""><SETTINGS action=""load""/></TEMPLATE>";
159  var xmlDoc = _parent.Project.ExecuteRQL(LOAD_CC_SETTINGS.RQLFormat(_parent));
160  var node = xmlDoc.GetSingleElement("SETTINGS");
161  if (node == null)
162  {
163  throw new SmartAPIException(_parent.Session.ServerLogin,
164  String.Format("Could not load settings for content class {0}", _parent));
165  }
166 
167  return node;
168  }
169  }
170 }