PageRenderTime 40ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 1ms

/Web/Components/ContentPage.cs

#
C# | 473 lines | 372 code | 85 blank | 16 comment | 97 complexity | 9e2e0318332bc8201ab0ee7c5045e056 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause, CPL-1.0, CC-BY-SA-3.0, GPL-2.0
  1. // Author: Joe Audette
  2. // Created: 2007-08-07
  3. // Last Modified: 2011-03-24
  4. //
  5. // The use and distribution terms for this software are covered by the
  6. // Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
  7. // which can be found in the file CPL.TXT at the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by
  9. // the terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. // 2011-03-03 implemented better support for page hierarchy in initial content by implementing a childPages node in the xml and a ChildPagesCollection
  13. using System;
  14. using System.Collections.ObjectModel;
  15. using System.Web;
  16. using System.Xml;
  17. using log4net;
  18. namespace mojoPortal.Web
  19. {
  20. /// <summary>
  21. ///
  22. /// </summary>
  23. public class ContentPage
  24. {
  25. private ContentPage()
  26. { }
  27. //private static readonly ILog log = LogManager.GetLogger(typeof(ContentPage));
  28. private string resourceFile = string.Empty;
  29. private string name = string.Empty;
  30. private string title = string.Empty;
  31. private string url = string.Empty;
  32. private string menuImage = string.Empty;
  33. private int pageOrder = 1;
  34. private bool requireSSL = false;
  35. private bool showBreadcrumbs = false;
  36. private string visibleToRoles = "All Users;";
  37. private string editRoles = string.Empty;
  38. private string draftEditRoles = string.Empty;
  39. private string createChildPageRoles = string.Empty;
  40. private string pageMetaKeyWords = string.Empty;
  41. private string pageMetaDescription = string.Empty;
  42. private string bodyCssClass = string.Empty;
  43. private string menuCssClass = string.Empty;
  44. private bool includeInMenu = true;
  45. private bool isClickable = true;
  46. private bool includeInSiteMap = true;
  47. private bool includeInChildPagesSiteMap = true;
  48. private bool allowBrowserCaching = true;
  49. private bool showChildPageBreadcrumbs = false;
  50. private bool showHomeCrumb = false;
  51. private bool showChildPagesSiteMap = false;
  52. private bool hideFromAuthenticated = false;
  53. private bool enableComments = false;
  54. private Collection<ContentPageItem> pageItems = new Collection<ContentPageItem>();
  55. private Collection<ContentPage> childPages = new Collection<ContentPage>();
  56. public string ResourceFile
  57. {
  58. get { return resourceFile; }
  59. }
  60. public string Name
  61. {
  62. get { return name; }
  63. }
  64. public string Title
  65. {
  66. get { return title; }
  67. }
  68. public string Url
  69. {
  70. get { return url; }
  71. }
  72. public int PageOrder
  73. {
  74. get { return pageOrder; }
  75. }
  76. public string MenuImage
  77. {
  78. get { return menuImage; }
  79. }
  80. public bool RequireSsl
  81. {
  82. get { return requireSSL; }
  83. }
  84. public bool ShowBreadcrumbs
  85. {
  86. get { return showBreadcrumbs; }
  87. }
  88. public string VisibleToRoles
  89. {
  90. get { return visibleToRoles; }
  91. }
  92. public string EditRoles
  93. {
  94. get { return editRoles; }
  95. }
  96. public string DraftEditRoles
  97. {
  98. get { return draftEditRoles; }
  99. }
  100. public string CreateChildPageRoles
  101. {
  102. get { return createChildPageRoles; }
  103. }
  104. public string PageMetaKeyWords
  105. {
  106. get { return pageMetaKeyWords; }
  107. }
  108. public string PageMetaDescription
  109. {
  110. get { return pageMetaDescription; }
  111. }
  112. public string BodyCssClass
  113. {
  114. get { return bodyCssClass; }
  115. }
  116. public string MenuCssClass
  117. {
  118. get { return menuCssClass; }
  119. }
  120. public bool IncludeInMenu
  121. {
  122. get { return includeInMenu; }
  123. }
  124. public bool IsClickable
  125. {
  126. get { return isClickable; }
  127. }
  128. public bool IncludeInSiteMap
  129. {
  130. get { return includeInSiteMap; }
  131. }
  132. public bool IncludeInChildPagesSiteMap
  133. {
  134. get { return includeInChildPagesSiteMap; }
  135. }
  136. public bool AllowBrowserCaching
  137. {
  138. get { return allowBrowserCaching; }
  139. }
  140. public bool ShowChildPageBreadcrumbs
  141. {
  142. get { return showChildPageBreadcrumbs; }
  143. }
  144. public bool ShowHomeCrumb
  145. {
  146. get { return showHomeCrumb; }
  147. }
  148. public bool ShowChildPagesSiteMap
  149. {
  150. get { return showChildPagesSiteMap; }
  151. }
  152. public bool HideFromAuthenticated
  153. {
  154. get { return hideFromAuthenticated; }
  155. }
  156. public bool EnableComments
  157. {
  158. get { return enableComments; }
  159. }
  160. public Collection<ContentPage> ChildPages
  161. {
  162. get
  163. {
  164. return childPages;
  165. }
  166. }
  167. public Collection<ContentPageItem> PageItems
  168. {
  169. get
  170. {
  171. return pageItems;
  172. }
  173. }
  174. public static void LoadPages(
  175. ContentPageConfiguration contentPageConfig,
  176. XmlNode documentElement)
  177. {
  178. if (HttpContext.Current == null) return;
  179. if (documentElement.Name != "siteContent") return;
  180. XmlNode pagesNode = null;
  181. foreach (XmlNode node in documentElement.ChildNodes)
  182. {
  183. if (node.Name == "pages")
  184. {
  185. pagesNode = node;
  186. break;
  187. }
  188. }
  189. if(pagesNode == null) return;
  190. foreach (XmlNode node in pagesNode.ChildNodes)
  191. {
  192. if (node.Name == "page")
  193. {
  194. LoadPage(contentPageConfig, node, null);
  195. }
  196. }
  197. }
  198. public static void LoadPage(
  199. ContentPageConfiguration contentPageConfig,
  200. XmlNode node,
  201. ContentPage parentPage)
  202. {
  203. ContentPage contentPage = new ContentPage();
  204. XmlAttributeCollection attributeCollection = node.Attributes;
  205. if (attributeCollection["resourceFile"] != null)
  206. {
  207. contentPage.resourceFile = attributeCollection["resourceFile"].Value;
  208. }
  209. if (attributeCollection["name"] != null)
  210. {
  211. contentPage.name = attributeCollection["name"].Value;
  212. }
  213. if (attributeCollection["title"] != null)
  214. {
  215. contentPage.title = attributeCollection["title"].Value;
  216. }
  217. if (attributeCollection["url"] != null)
  218. {
  219. contentPage.url = attributeCollection["url"].Value;
  220. }
  221. if (attributeCollection["menuImage"] != null)
  222. {
  223. contentPage.menuImage = attributeCollection["menuImage"].Value;
  224. }
  225. if (attributeCollection["pageOrder"] != null)
  226. {
  227. int sort = 1;
  228. if (int.TryParse(attributeCollection["pageOrder"].Value,
  229. out sort))
  230. {
  231. contentPage.pageOrder = sort;
  232. }
  233. }
  234. if (attributeCollection["visibleToRoles"] != null)
  235. {
  236. contentPage.visibleToRoles = attributeCollection["visibleToRoles"].Value;
  237. }
  238. if (attributeCollection["editRoles"] != null)
  239. {
  240. contentPage.editRoles = attributeCollection["editRoles"].Value;
  241. }
  242. if (attributeCollection["draftEditRoles"] != null)
  243. {
  244. contentPage.draftEditRoles = attributeCollection["draftEditRoles"].Value;
  245. }
  246. if (attributeCollection["createChildPageRoles"] != null)
  247. {
  248. contentPage.createChildPageRoles = attributeCollection["createChildPageRoles"].Value;
  249. }
  250. if (attributeCollection["pageMetaKeyWords"] != null)
  251. {
  252. contentPage.pageMetaKeyWords = attributeCollection["pageMetaKeyWords"].Value;
  253. }
  254. if (attributeCollection["pageMetaDescription"] != null)
  255. {
  256. contentPage.pageMetaDescription = attributeCollection["pageMetaDescription"].Value;
  257. }
  258. if (
  259. (attributeCollection["requireSSL"] != null)
  260. && (attributeCollection["requireSSL"].Value.ToLower() == "true")
  261. )
  262. {
  263. contentPage.requireSSL = true;
  264. }
  265. if (
  266. (attributeCollection["showBreadcrumbs"] != null)
  267. && (attributeCollection["showBreadcrumbs"].Value.ToLower() == "true")
  268. )
  269. {
  270. contentPage.showBreadcrumbs = true;
  271. }
  272. if (
  273. (attributeCollection["includeInMenu"] != null)
  274. && (attributeCollection["includeInMenu"].Value.ToLower() == "false")
  275. )
  276. {
  277. contentPage.includeInMenu = false;
  278. }
  279. if (
  280. (attributeCollection["isClickable"] != null)
  281. && (attributeCollection["isClickable"].Value.ToLower() == "false")
  282. )
  283. {
  284. contentPage.isClickable = false;
  285. }
  286. if (
  287. (attributeCollection["includeInSiteMap"] != null)
  288. && (attributeCollection["includeInSiteMap"].Value.ToLower() == "false")
  289. )
  290. {
  291. contentPage.includeInSiteMap = false;
  292. }
  293. if (
  294. (attributeCollection["includeInChildPagesSiteMap"] != null)
  295. && (attributeCollection["includeInChildPagesSiteMap"].Value.ToLower() == "false")
  296. )
  297. {
  298. contentPage.includeInChildPagesSiteMap = false;
  299. }
  300. if (
  301. (attributeCollection["allowBrowserCaching"] != null)
  302. && (attributeCollection["allowBrowserCaching"].Value.ToLower() == "false")
  303. )
  304. {
  305. contentPage.allowBrowserCaching = false;
  306. }
  307. if (
  308. (attributeCollection["showChildPageBreadcrumbs"] != null)
  309. && (attributeCollection["showChildPageBreadcrumbs"].Value.ToLower() == "true")
  310. )
  311. {
  312. contentPage.showChildPageBreadcrumbs = true;
  313. }
  314. if (
  315. (attributeCollection["showHomeCrumb"] != null)
  316. && (attributeCollection["showHomeCrumb"].Value.ToLower() == "true")
  317. )
  318. {
  319. contentPage.showHomeCrumb = true;
  320. }
  321. if (
  322. (attributeCollection["showChildPagesSiteMap"] != null)
  323. && (attributeCollection["showChildPagesSiteMap"].Value.ToLower() == "true")
  324. )
  325. {
  326. contentPage.showChildPagesSiteMap = true;
  327. }
  328. if (
  329. (attributeCollection["hideFromAuthenticated"] != null)
  330. && (attributeCollection["hideFromAuthenticated"].Value.ToLower() == "true")
  331. )
  332. {
  333. contentPage.hideFromAuthenticated = true;
  334. }
  335. if (
  336. (attributeCollection["enableComments"] != null)
  337. && (attributeCollection["enableComments"].Value.ToLower() == "true")
  338. )
  339. {
  340. contentPage.enableComments = true;
  341. }
  342. if (attributeCollection["bodyCssClass"] != null)
  343. {
  344. contentPage.bodyCssClass = attributeCollection["bodyCssClass"].Value;
  345. }
  346. if (attributeCollection["menuCssClass"] != null)
  347. {
  348. contentPage.menuCssClass = attributeCollection["menuCssClass"].Value;
  349. }
  350. foreach (XmlNode contentFeatureNode in node.ChildNodes)
  351. {
  352. if (contentFeatureNode.Name == "contentFeature")
  353. {
  354. ContentPageItem.LoadPageItem(
  355. contentPage,
  356. contentFeatureNode);
  357. }
  358. }
  359. XmlNode childPagesNode = null;
  360. foreach (XmlNode n in node.ChildNodes)
  361. {
  362. if (n.Name == "childPages")
  363. {
  364. childPagesNode = n;
  365. break;
  366. }
  367. }
  368. if (parentPage == null)
  369. {
  370. contentPageConfig.ContentPages.Add(contentPage);
  371. }
  372. else
  373. {
  374. parentPage.ChildPages.Add(contentPage);
  375. }
  376. if (childPagesNode != null)
  377. {
  378. foreach (XmlNode c in childPagesNode.ChildNodes)
  379. {
  380. if (c.Name == "page")
  381. {
  382. LoadPage(contentPageConfig, c, contentPage);
  383. }
  384. }
  385. }
  386. }
  387. }
  388. }