SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
IPublicationFolder.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.Web;
18 using System.Xml;
19 using erminas.SmartAPI.Exceptions;
20 using erminas.SmartAPI.Utils;
21 
22 namespace erminas.SmartAPI.CMS.Project.Publication
23 {
28  {
29  void Commit();
30  string ContentGroup { get; set; }
31  PublicationFolderContentType ContentTypeValue { get; set; }
32  PublicationFolderContextInfoPreparationType ContextInfoPreparation { get; set; }
33  string ContextTags { get; set; }
34  void CreateInProject(IProject project, Guid parentFolderGuid);
35  bool DoCreateLog { get; set; }
36  bool DoIndexForFulltextSearch { get; set; }
37  bool DoReleaseAfterImport { get; set; }
38  bool DoReplaceExistingContent { get; set; }
39  bool DoReplaceGroupAssignment { get; set; }
40  bool IsPublishedPagesFolder { get; }
41  string RealName { get; set; }
42  string RealVirtualName { get; set; }
43  PublicationFolderType Type { get; set; }
44  string VirtualName { get; set; }
45  }
46 
47  internal class PublicationFolder : PartialRedDotProjectObject, IPublicationFolder
48  {
49  public static readonly Guid ROOT_LEVEL_GUID = Guid.Parse("9BBF210F7923406291BE7AE47B4CA571");
50  public static readonly Guid PUBLISHED_PAGES_GUID;
51  private static readonly XmlElement PUBLISHED_PAGES_NODE;
52  private string _contentgroup;
53  private PublicationFolderContentType _contenttype;
54  private PublicationFolderContextInfoPreparationType _contextInfoPreparationType;
55  private string _contexttags;
56  private bool _doArchivePreviousVersion;
57  private bool _doCreateLog;
58  private bool _doIgnoreMetadata;
59  private bool _doIndexing;
60  private bool _doOverwriteContent;
61  private bool _doOverwriteGroupAssignment;
62  private bool _doReleasePublishedFiles;
63  private string _inlineFunctionName;
64  private string _prefix;
65  private string _realName;
66  private string _realVirtualName;
67  private string _script;
68  private PublicationFolderType _type;
69  private bool _usePrefix;
70  private string _virtualName;
71 
72  static PublicationFolder()
73  {
74  var doc = new XmlDocument();
75  PUBLISHED_PAGES_NODE = doc.CreateElement("EXPORTFOLDER");
76  const string PUBLISHED_PAGES_GUID_STRING = "00000000000000000000000000000100";
77  PUBLISHED_PAGES_GUID = Guid.Parse(PUBLISHED_PAGES_GUID_STRING);
78  PUBLISHED_PAGES_NODE.SetAttributeValue("name", "Published pages");
79  PUBLISHED_PAGES_NODE.SetAttributeValue("guid", PUBLISHED_PAGES_GUID_STRING);
80  }
81 
82  public PublicationFolder(string name, PublicationFolderType type) : base(null)
83  {
84  _contextInfoPreparationType = PublicationFolderContextInfoPreparationType.None;
85  Name = name;
86  _type = type;
87  }
88 
89  public PublicationFolder(IProject project, Guid guid) : base(project, guid)
90  {
91  _contextInfoPreparationType = PublicationFolderContextInfoPreparationType.None;
92  }
93 
94  public void Commit()
95  {
96  const string SAVE_STRING =
97  @"<PROJECT><EXPORTFOLDER action=""save"" guid=""{0}"" type=""{1}"" name=""{2}"" {3} /></PROJECT>";
98 
99  XmlDocument reply =
100  Project.ExecuteRQL(string.Format(SAVE_STRING, Guid.ToRQLString(), ((int) _type), Name, SaveParameters()));
101 
102  if (reply.GetElementsByTagName("EXPORTFOLDER").Count != 1)
103  {
104  throw new SmartAPIException(Session.ServerLogin,
105  string.Format("Could not save publication folder {0}", this));
106  }
107  }
108 
109  public string ContentGroup
110  {
111  get { return LazyLoad(ref _contentgroup); }
112  set { _contentgroup = value; }
113  }
114 
115  public PublicationFolderContentType ContentTypeValue
116  {
117  get { return LazyLoad(ref _contenttype); }
118  set { _contenttype = value; }
119  }
120 
121  public PublicationFolderContextInfoPreparationType ContextInfoPreparation
122  {
123  get { return LazyLoad(ref _contextInfoPreparationType); }
124  set { _contextInfoPreparationType = value; }
125  }
126 
127  public string ContextTags
128  {
129  get { return LazyLoad(ref _contexttags); }
130  set { _contexttags = value; }
131  }
132 
133  public void CreateInProject(IProject project, Guid parentFolderGuid)
134  {
135  const string CREATE_STRING =
136  @"<PROJECT><EXPORTFOLDER action=""assign"" guid=""{0}""><EXPORTFOLDER action=""addnew"" name=""{1}"" type=""{2}"" {3} /></EXPORTFOLDER></PROJECT>";
137 
138  XmlDocument reply =
139  project.ExecuteRQL(string.Format(CREATE_STRING, parentFolderGuid.ToRQLString(), Name, ((int) _type),
140  SaveParameters()));
141 
142  reply.GetElementsByTagName("EXPORTFOLDER");
143  }
144 
145  public void Delete()
146  {
147  const string DELETE = @"<PROJECT><EXPORTFOLDER action=""delete"" guid=""{0}""/> </PROJECT>";
148  Project.ExecuteRQL(string.Format(DELETE, Guid.ToRQLString()));
149  //TODO check result
150  }
151 
152  public bool DoCreateLog
153  {
154  get { return LazyLoad(ref _doCreateLog); }
155  set { _doCreateLog = value; }
156  }
157 
158  public bool DoIndexForFulltextSearch
159  {
160  get { return LazyLoad(ref _doIndexing); }
161  set { _doIndexing = value; }
162  }
163 
164  public bool DoReleaseAfterImport
165  {
166  get { return LazyLoad(ref _doReleasePublishedFiles); }
167  set { _doReleasePublishedFiles = value; }
168  }
169 
170  public bool DoReplaceExistingContent
171  {
172  get { return LazyLoad(ref _doOverwriteContent); }
173  set { _doOverwriteContent = value; }
174  }
175 
176  public bool DoReplaceGroupAssignment
177  {
178  get { return LazyLoad(ref _doOverwriteGroupAssignment); }
179  set { _doOverwriteGroupAssignment = value; }
180  }
181 
182  public bool IsPublishedPagesFolder
183  {
184  get { return Guid == PUBLISHED_PAGES_GUID; }
185  }
186 
187  public string RealName
188  {
189  get { return LazyLoad(ref _realName); }
190  set { _realName = value; }
191  }
192 
193  public string RealVirtualName
194  {
195  get { return LazyLoad(ref _realVirtualName); }
196  set { _realVirtualName = value; }
197  }
198 
199  public override ISession Session
200  {
201  get { return Project != null ? Project.Session : null; }
202  }
203 
204  public PublicationFolderType Type
205  {
206  get { return LazyLoad(ref _type); }
207  set { _type = value; }
208  }
209 
210  public string VirtualName
211  {
212  get { return LazyLoad(ref _virtualName); }
213  set { _virtualName = value; }
214  }
215 
216  protected override void LoadWholeObject()
217  {
218  LoadXml();
219  }
220 
221  protected override XmlElement RetrieveWholeObject()
222  {
223  if (Guid != PUBLISHED_PAGES_GUID)
224  {
225  const string LOAD_PUBLICATION_FOLDER =
226  @"<PROJECT><EXPORTFOLDER action=""load"" guid=""{0}""/></PROJECT>";
227 
228  return
229  (XmlElement)
230  Project.ExecuteRQL(string.Format(LOAD_PUBLICATION_FOLDER, Guid.ToRQLString()))
231  .GetElementsByTagName("EXPORTFOLDER")[0];
232  }
233 
234  return PUBLISHED_PAGES_NODE;
235  }
236 
237  private static string BoolToString(bool value)
238  {
239  return value ? "1" : "0";
240  }
241 
242  private void LoadXml()
243  {
244  if (Guid == PUBLISHED_PAGES_GUID)
245  {
246  return;
247  }
248  EnsuredInit(ref _realName, "realname", x => x ?? "");
249  EnsuredInit(ref _type, "type", x => (PublicationFolderType) int.Parse(x));
250 
251  InitIfPresent(ref _realVirtualName, "realvirtualname", x => x ?? "");
252  InitIfPresent(ref _virtualName, "virtualname", x => x ?? "");
253  if (_type == PublicationFolderType.DeliveryServer)
254  {
255  InitIfPresent(ref _contentgroup, "contentgroup", x => x);
256  EnsuredInit(ref _contenttype, "contenttype",
257  x => (PublicationFolderContentType) Enum.Parse(typeof (PublicationFolderContentType), x));
258  InitIfPresent(ref _contexttags, "contexttags", x => x);
259  InitIfPresent(ref _contextInfoPreparationType, "contextinfo",
260  x =>
262  Enum.Parse(typeof (PublicationFolderContextInfoPreparationType), x));
263  EnsuredInit(ref _doArchivePreviousVersion, "flag_archive_prev_version", BoolConvert);
264  InitIfPresent(ref _doCreateLog, "flag_create_log", BoolConvert);
265  InitIfPresent(ref _doIndexing, "flag_indexing", BoolConvert);
266  InitIfPresent(ref _doOverwriteContent, "flag_overwrite_content", BoolConvert);
267  InitIfPresent(ref _doOverwriteGroupAssignment, "flag_overwrite_group_assignment", BoolConvert);
268  InitIfPresent(ref _doReleasePublishedFiles, "flag_set_final", BoolConvert);
269  InitIfPresent(ref _doIgnoreMetadata, "ignore_metadata", BoolConvert);
270  InitIfPresent(ref _inlineFunctionName, "inlinefunctionname", x => x);
271  InitIfPresent(ref _prefix, "prefix", x => x);
272  InitIfPresent(ref _script, "script", x => x);
273  InitIfPresent(ref _usePrefix, "useprefix", BoolConvert);
274  }
275  }
276 
277  private string SaveParameters()
278  {
279  string optionalParameters = String.IsNullOrEmpty(_virtualName)
280  ? ""
281  : "virtualname=\"" + HttpUtility.HtmlEncode(_virtualName) + "\" ";
282  if (Type == PublicationFolderType.DeliveryServer)
283  {
284  if (!String.IsNullOrEmpty(_contentgroup))
285  {
286  optionalParameters += "contentgroup=\"" + HttpUtility.HtmlEncode(_contentgroup) + "\" ";
287  }
288  optionalParameters += "contenttype=\"" + _contenttype + "\" ";
289 
290  if (!String.IsNullOrEmpty(_contexttags))
291  {
292  optionalParameters += "contexttags=\"" + HttpUtility.HtmlEncode(_contexttags) + "\" ";
293  }
294 
295  if (_contextInfoPreparationType != PublicationFolderContextInfoPreparationType.None)
296  {
297  optionalParameters += "contextinfo=\"" + HttpUtility.HtmlEncode(_contextInfoPreparationType) + "\" ";
298  }
299 
300  if (_doArchivePreviousVersion)
301  {
302  optionalParameters += "flag_archive_prev_version=\"1\" ";
303  }
304 
305  if (_doCreateLog)
306  {
307  optionalParameters += "flag_create_log=\"1\" ";
308  }
309 
310  if (_doIndexing)
311  {
312  optionalParameters += "flag_indexing=\"1\" ";
313  }
314 
315  if (_doOverwriteContent)
316  {
317  optionalParameters += "flag_overwrite_content=\"1\" ";
318  }
319 
320  if (_doOverwriteGroupAssignment)
321  {
322  optionalParameters += "flag_overwrite_group_assignment=\"1\" ";
323  }
324 
325  if (_doReleasePublishedFiles)
326  {
327  optionalParameters += "flag_set_final=\"1\" ";
328  }
329 
330  optionalParameters += "ignore_metadata=\"" + BoolToString(_doIgnoreMetadata) + "\" ";
331 
332  if (!String.IsNullOrEmpty(_inlineFunctionName))
333  {
334  optionalParameters += "inlinefunctionname=\"" + HttpUtility.HtmlEncode(_inlineFunctionName) + "\" ";
335  }
336 
337  if (!String.IsNullOrEmpty(_prefix))
338  {
339  optionalParameters += "prefix=\"" + HttpUtility.HtmlEncode(_prefix) + "\" ";
340  }
341 
342  if (!String.IsNullOrEmpty(_script))
343  {
344  optionalParameters += "script=\"" + HttpUtility.HtmlEncode(_script) + "\" ";
345  }
346 
347  if (_usePrefix)
348  {
349  optionalParameters += "useprefix=\"1\" ";
350  }
351  }
352  return optionalParameters;
353  }
354  }
355 
357  {
358  FtpUncLocal = 0,
359  DeliveryServer = 1
360  }
361 
363  {
364  None = -1,
365  DoNotPrepare = 0,
366  BeginningOfText = 1,
367  TextForHighlighting = 2,
368  ContextTags = 3
369  }
370 
372  {
373  HTML,
374  XML,
375  XSL,
376  SCRIPT,
377  BLOB
378  }
379 }