/SobekCM_Core/UI_Configuration/Citation/CitationElement.cs

http://github.com/MarkVSullivan/SobekCM-Web-Application · C# · 193 lines · 115 code · 26 blank · 52 comment · 10 complexity · fde56d72362c9db900f61bde8b105730 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.Serialization;
  4. using System.Xml.Serialization;
  5. using ProtoBuf;
  6. using SobekCM.Core.Configuration.Localization;
  7. using SobekCM.Tools;
  8. namespace SobekCM.Core.UI_Configuration.Citation
  9. {
  10. /// <summary> Enumeration used to indicate when the basic citation
  11. /// section writer should override the display term and use some other
  12. /// value from within the individual item metadata </summary>
  13. public enum CitationElement_OverrideDispayTerm_Enum : byte
  14. {
  15. /// <summary> Do not override the dispay term </summary>
  16. NONE = 0,
  17. /// <summary> Use any provided subterm as the display term, if one exists </summary>
  18. subterm = 1
  19. }
  20. /// <summary> Information about a single citation element to be displayed within
  21. /// a citation set </summary>
  22. [Serializable, DataContract, ProtoContract]
  23. [XmlRoot("CitationElement")]
  24. public class CitationElement
  25. {
  26. /// <summary> Metadata term this citation element displays (or a unique value) </summary>
  27. /// <remarks> This field also uniquely defines this citation element </remarks>
  28. [DataMember(Name = "term")]
  29. [XmlAttribute("term")]
  30. [ProtoMember(1)]
  31. public string MetadataTerm { get; set; }
  32. /// <summary> Default display term for this citation element </summary>
  33. [DataMember(Name = "display", EmitDefaultValue = false)]
  34. [XmlAttribute("display")]
  35. [ProtoMember(2)]
  36. public string DisplayTerm { get; set; }
  37. /// <summary> SobekCM search code, if this element should be clickable
  38. /// to initiate a search within SobekCM </summary>
  39. [DataMember(Name = "searchCode", EmitDefaultValue = false)]
  40. [XmlAttribute("searchCode")]
  41. [ProtoMember(3)]
  42. public string SearchCode { get; set; }
  43. /// <summary> Schema.org microdata tag to include for this element </summary>
  44. [DataMember(Name = "itemProp", EmitDefaultValue = false)]
  45. [XmlAttribute("itemProp")]
  46. [ProtoMember(4)]
  47. public string ItemProp { get; set; }
  48. /// <summary> Flag indicatse if the basic citation section writer should override
  49. /// the display term and use some other value from within the individual item metadata </summary>
  50. [DataMember(Name = "overrideDisplayTerm")]
  51. [XmlAttribute("overrideDisplayTerm")]
  52. [ProtoMember(5)]
  53. public CitationElement_OverrideDispayTerm_Enum OverrideDisplayTerm { get; set; }
  54. /// <summary> Custom section writer information, if a non-standard citation section
  55. /// writer should be used for this element </summary>
  56. [DataMember(Name = "sectionWriter", EmitDefaultValue = false)]
  57. [XmlElement("sectionWriter")]
  58. [ProtoMember(6)]
  59. public SectionWriter SectionWriter { get; set; }
  60. /// <summary> Any additional options for the citation section writer </summary>
  61. [DataMember(Name = "options", EmitDefaultValue = false)]
  62. [XmlArray("options")]
  63. [XmlArrayItem("option", typeof(StringKeyValuePair))]
  64. [ProtoMember(7)]
  65. public List<StringKeyValuePair> Options { get; set; }
  66. /// <summary> Provided translations for the display term </summary>
  67. [DataMember(Name = "translations", EmitDefaultValue = false)]
  68. [XmlArray("translations")]
  69. [XmlArrayItem("translation", typeof(Web_Language_Translation_Value))]
  70. [ProtoMember(8)]
  71. public List<Web_Language_Translation_Value> Translations { get; set; }
  72. /// <summary> Flag indicates if each field should be individually labeled, or if they
  73. /// can all be run together in one large block </summary>
  74. [DataMember(Name = "individualFields")]
  75. [XmlAttribute("individualFields")]
  76. [ProtoMember(9)]
  77. public bool IndividualFields { get; set; }
  78. /// <summary> Constructor for a new instance of the <see cref="CitationElement"/> class </summary>
  79. public CitationElement()
  80. {
  81. OverrideDisplayTerm = CitationElement_OverrideDispayTerm_Enum.NONE;
  82. IndividualFields = false;
  83. }
  84. /// <summary> Constructor for a new instance of the <see cref="CitationElement"/> class </summary>
  85. /// <param name="MetadataTerm"> Metadata term this citation element displays (or a unique value) </param>
  86. /// <param name="DisplayTerm"> Default display term for this citation element </param>
  87. /// <param name="SearchCode"> SobekCM search code, if this element should be clickable
  88. /// to initiate a search within SobekCM </param>
  89. /// <param name="ItemProp"> Schema.org microdata tag to include for this element </param>
  90. public CitationElement(string MetadataTerm, string DisplayTerm, string SearchCode, string ItemProp)
  91. {
  92. this.MetadataTerm = MetadataTerm;
  93. this.DisplayTerm = DisplayTerm;
  94. this.SearchCode = SearchCode;
  95. this.ItemProp = ItemProp;
  96. OverrideDisplayTerm = CitationElement_OverrideDispayTerm_Enum.NONE;
  97. IndividualFields = false;
  98. }
  99. /// <summary> Constructor for a new instance of the <see cref="CitationElement"/> class </summary>
  100. /// <param name="MetadataTerm"> Metadata term this citation element displays (or a unique value) </param>
  101. /// <param name="DisplayTerm"> Default display term for this citation element </param>
  102. /// <param name="SearchCode"> SobekCM search code, if this element should be clickable
  103. /// to initiate a search within SobekCM </param>
  104. /// <param name="ItemProp"> Schema.org microdata tag to include for this element </param>
  105. /// <param name="OverrideDisplayTerm"> Flag indicatse if the basic citation section writer should override
  106. /// the display term and use some other value from within the individual item metadata </param>
  107. public CitationElement(string MetadataTerm, string DisplayTerm, string SearchCode, string ItemProp, CitationElement_OverrideDispayTerm_Enum OverrideDisplayTerm )
  108. {
  109. this.MetadataTerm = MetadataTerm;
  110. this.DisplayTerm = DisplayTerm;
  111. this.SearchCode = SearchCode;
  112. this.ItemProp = ItemProp;
  113. this.OverrideDisplayTerm = OverrideDisplayTerm;
  114. IndividualFields = (OverrideDisplayTerm == CitationElement_OverrideDispayTerm_Enum.subterm);
  115. }
  116. #region Methods that controls XML serialization
  117. /// <summary> Method suppresses XML Serialization of the OverrideDisplayTerm property if it is empty </summary>
  118. /// <returns> TRUE if the property should be serialized, otherwise FALSE </returns>
  119. public bool ShouldSerializeOverrideDisplayTerm()
  120. {
  121. return (OverrideDisplayTerm != CitationElement_OverrideDispayTerm_Enum.NONE);
  122. }
  123. /// <summary> Method suppresses XML Serialization of the SearchCode property if it is empty </summary>
  124. /// <returns> TRUE if the property should be serialized, otherwise FALSE </returns>
  125. public bool ShouldSerializeSearchCode()
  126. {
  127. return (!String.IsNullOrEmpty(SearchCode));
  128. }
  129. /// <summary> Method suppresses XML Serialization of the ItemProp property if it is empty </summary>
  130. /// <returns> TRUE if the property should be serialized, otherwise FALSE </returns>
  131. public bool ShouldSerializeItemProp()
  132. {
  133. return (!String.IsNullOrEmpty(ItemProp));
  134. }
  135. /// <summary> Method suppresses XML Serialization of the Options property if it is empty </summary>
  136. /// <returns> TRUE if the property should be serialized, otherwise FALSE </returns>
  137. public bool ShouldSerializeOptions()
  138. {
  139. return ((Options != null) && (Options.Count > 0));
  140. }
  141. /// <summary> Method suppresses XML Serialization of the Translations property if it is empty </summary>
  142. /// <returns> TRUE if the property should be serialized, otherwise FALSE </returns>
  143. public bool ShouldSerializeTranslations()
  144. {
  145. return ((Translations != null) && (Translations.Count > 0));
  146. }
  147. #endregion
  148. /// <summary> Add a new option to this citation element configuration </summary>
  149. /// <param name="Key"> Key for this key/value pair </param>
  150. /// <param name="Value"> Value for this key/value pair </param>
  151. public void Add_Option(string Key, string Value)
  152. {
  153. if (Options == null)
  154. Options = new List<StringKeyValuePair>();
  155. Options.Add(new StringKeyValuePair(Key, Value));
  156. }
  157. /// <summary> Add a new translation for the display term </summary>
  158. /// <param name="Language"> Language in which this value is represented </param>
  159. /// <param name="Value"> Value in provided language </param>
  160. public void Add_Translation(Web_Language_Enum Language, string Value)
  161. {
  162. if (Translations == null)
  163. Translations = new List<Web_Language_Translation_Value>();
  164. Translations.Add(new Web_Language_Translation_Value(Language, Value));
  165. }
  166. }
  167. }