SmartAPI
Open Source .NET RQL library for RedDot CMS / OpenText WSM Management Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
AbstractLinkElement.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.Collections.Generic;
18 using System.Linq;
19 using System.Xml;
20 using erminas.SmartAPI.Utils;
21 using erminas.SmartAPI.Utils.CachedCollections;
22 
23 namespace erminas.SmartAPI.CMS.Project.Pages.Elements
24 {
25  internal abstract class AbstractLinkElement : PageElement, ILinkElement
26  {
27  private LinkType _linkType;
28 
29  protected AbstractLinkElement(IProject project, Guid guid, ILanguageVariant languageVariant)
30  : base(project, guid, languageVariant)
31  {
32  Connections = new LinkConnections(this, Caching.Enabled);
33  ReferencedFrom = new RDList<ILinkElement>(GetReferencingLinks, Caching.Enabled);
34  }
35 
36  protected AbstractLinkElement(IProject project, XmlElement xmlElement) : base(project, xmlElement)
37  {
38  Connections = new LinkConnections(this, Caching.Enabled);
39  ReferencedFrom = new RDList<ILinkElement>(GetReferencingLinks, Caching.Enabled);
40  LoadXml();
41  }
42 
43  public ILinkConnections Connections { get; protected set; }
44 
45  public LinkType LinkType
46  {
47  get { return LazyLoad(ref _linkType); }
48  }
49 
50  public IRDList<ILinkElement> ReferencedFrom { get; private set; }
51 
52  protected abstract void LoadWholeLinkElement();
53 
54  protected override sealed void LoadWholePageElement()
55  {
56  LoadXml();
57  LoadWholeLinkElement();
58  }
59 
60  private List<ILinkElement> GetReferencingLinks()
61  {
62  const string LIST_REFERENCES = @"<REFERENCE action=""list"" guid=""{0}"" />";
63  XmlDocument xmlDoc = Project.ExecuteRQL(LIST_REFERENCES.RQLFormat(this), RqlType.SessionKeyInProject);
64 
65  //theoretically through an anchor the language variant of the target could be changed, but this is also not considered in the SmartTree,
66  //so we ignore it, to be consistent with the SmartTree.
67  return (from XmlElement curLink in xmlDoc.GetElementsByTagName("LINK")
68  select (ILinkElement) CreateElement(Project, curLink.GetGuid(), LanguageVariant)).ToList();
69  }
70 
71  private void LoadXml()
72  {
73  InitIfPresent(ref _linkType, "islink", x => (LinkType) int.Parse(x));
74  }
75  }
76 }