/// <summary> /// Returns the <see cref="AtomTextConstructType"/> enumeration value that corresponds to the specified text construct type name. /// </summary> /// <param name="name">The name of the text construct type.</param> /// <returns>A <see cref="AtomTextConstructType"/> enumeration value that corresponds to the specified string, otherwise returns <b>AtomTextConstructType.None</b>.</returns> /// <remarks>This method disregards case of specified text construct type name.</remarks> /// <exception cref="ArgumentNullException">The <paramref name="name"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="name"/> is an empty string.</exception> /// <example> /// <code /// lang="cs" /// title="The following code example demonstrates the usage of the ConstructTypeByName method." /// /> /// </example> public static AtomTextConstructType ConstructTypeByName(string name) { AtomTextConstructType constructType = AtomTextConstructType.None; Guard.ArgumentNotNullOrEmptyString(name, "name"); foreach (System.Reflection.FieldInfo fieldInfo in typeof(AtomTextConstructType).GetFields()) { if (fieldInfo.FieldType == typeof(AtomTextConstructType)) { AtomTextConstructType type = (AtomTextConstructType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name); object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false); if (customAttributes != null && customAttributes.Length > 0) { EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute; if (String.Compare(name, enumerationMetadata.AlternateValue, StringComparison.OrdinalIgnoreCase) == 0) { constructType = type; break; } } } } return(constructType); }
/// <summary> /// Returns the text construct identifier for the supplied <see cref="AtomTextConstructType"/>. /// </summary> /// <param name="type">The <see cref="AtomTextConstructType"/> to get the text construct identifier for.</param> /// <returns>The text construct identifier for the supplied <paramref name="type"/>, otherwise returns an empty string.</returns> /// <example> /// <code /// lang="cs" /// title="The following code example demonstrates the usage of the ConstructTypeAsString method." /// /> /// </example> public static string ConstructTypeAsString(AtomTextConstructType type) { string name = String.Empty; foreach (System.Reflection.FieldInfo fieldInfo in typeof(AtomTextConstructType).GetFields()) { if (fieldInfo.FieldType == typeof(AtomTextConstructType)) { AtomTextConstructType constructType = (AtomTextConstructType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name); if (constructType == type) { object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false); if (customAttributes != null && customAttributes.Length > 0) { EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute; name = enumerationMetadata.AlternateValue; break; } } } } return(name); }
public void TypeTest() { AtomTextConstruct target = new AtomTextConstruct(); // TODO: Initialize to an appropriate value AtomTextConstructType expected = AtomTextConstructType.xhtml; AtomTextConstructType actual; target.Type = expected; actual = target.Type; Assert.AreEqual(expected, actual); }
/// <summary> /// Loads this <see cref="AtomTextConstruct"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="AtomTextConstruct"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomTextConstruct"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(source.NameTable); if (AtomUtility.FillCommonObjectAttributes(this, source)) { wasLoaded = true; } if (source.HasAttributes) { string typeAttribute = source.GetAttribute("type", String.Empty); if (!String.IsNullOrEmpty(typeAttribute)) { AtomTextConstructType type = AtomTextConstruct.ConstructTypeByName(typeAttribute); if (type != AtomTextConstructType.None) { this.TextType = type; wasLoaded = true; } } } if (this.TextType == AtomTextConstructType.Xhtml) { XPathNavigator xhtmlDivNavigator = source.SelectSingleNode("xhtml:div", manager); if (xhtmlDivNavigator != null && !String.IsNullOrEmpty(xhtmlDivNavigator.Value)) { this.Content = xhtmlDivNavigator.Value; wasLoaded = true; } } else if (this.TextType == AtomTextConstructType.Html && !String.IsNullOrEmpty(source.InnerXml)) { this.Content = source.InnerXml; wasLoaded = true; } else if (!String.IsNullOrEmpty(source.Value)) { this.Content = source.Value; wasLoaded = true; } return(wasLoaded); }
////////////////////////////////////////////////////////////////////// /// <summary>constructor indicating the elementtype</summary> /// <param name="elementType">holds the xml elementype</param> ////////////////////////////////////////////////////////////////////// public AtomTextConstruct(AtomTextConstructElementType elementType) { this.elementType = elementType; this.type = AtomTextConstructType.text; // set the default to text }
/// <summary> /// Loads this <see cref="AtomTextConstruct"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="AtomTextConstruct"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomTextConstruct"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Initialize XML namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(source.NameTable); //------------------------------------------------------------ // Attempt to extract common attributes information //------------------------------------------------------------ if (AtomUtility.FillCommonObjectAttributes(this, source)) { wasLoaded = true; } //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ if (source.HasAttributes) { string typeAttribute = source.GetAttribute("type", String.Empty); if (!String.IsNullOrEmpty(typeAttribute)) { AtomTextConstructType type = AtomTextConstruct.ConstructTypeByName(typeAttribute); if (type != AtomTextConstructType.None) { this.TextType = type; wasLoaded = true; } } } if(this.TextType == AtomTextConstructType.Xhtml) { XPathNavigator xhtmlDivNavigator = source.SelectSingleNode("xhtml:div", manager); if (xhtmlDivNavigator != null && !String.IsNullOrEmpty(xhtmlDivNavigator.Value)) { this.Content = xhtmlDivNavigator.Value; wasLoaded = true; } } else if (this.TextType == AtomTextConstructType.Html && !String.IsNullOrEmpty(source.InnerXml)) { this.Content = source.InnerXml; wasLoaded = true; } else if (!String.IsNullOrEmpty(source.Value)) { this.Content = source.Value; wasLoaded = true; } return wasLoaded; }
/// <summary> /// Returns the text construct identifier for the supplied <see cref="AtomTextConstructType"/>. /// </summary> /// <param name="type">The <see cref="AtomTextConstructType"/> to get the text construct identifier for.</param> /// <returns>The text construct identifier for the supplied <paramref name="type"/>, otherwise returns an empty string.</returns> /// <example> /// <code /// lang="cs" /// title="The following code example demonstrates the usage of the ConstructTypeAsString method." /// /> /// </example> public static string ConstructTypeAsString(AtomTextConstructType type) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ string name = String.Empty; //------------------------------------------------------------ // Return alternate value based on supplied protocol //------------------------------------------------------------ foreach (System.Reflection.FieldInfo fieldInfo in typeof(AtomTextConstructType).GetFields()) { if (fieldInfo.FieldType == typeof(AtomTextConstructType)) { AtomTextConstructType constructType = (AtomTextConstructType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name); if (constructType == type) { object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false); if (customAttributes != null && customAttributes.Length > 0) { EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute; name = enumerationMetadata.AlternateValue; break; } } } } return name; }
////////////////////////////////////////////////////////////////////// /// <summary>constructor indicating the elementtype</summary> /// <param name="elementType">holds the xml elementype</param> ////////////////////////////////////////////////////////////////////// public AtomTextConstruct(AtomTextConstructElementType elementType) { this.elementType = elementType; this.type = AtomTextConstructType.text; // set the default to text }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="AtomTextConstruct"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="AtomTextConstruct"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomTextConstruct"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Initialize XML namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(source.NameTable); //------------------------------------------------------------ // Attempt to extract common attributes information //------------------------------------------------------------ if (AtomUtility.FillCommonObjectAttributes(this, source)) { wasLoaded = true; } //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ if (source.HasAttributes) { string typeAttribute = source.GetAttribute("type", String.Empty); if (!String.IsNullOrEmpty(typeAttribute)) { AtomTextConstructType type = AtomTextConstruct.ConstructTypeByName(typeAttribute); if (type != AtomTextConstructType.None) { this.TextType = type; wasLoaded = true; } } } if (this.TextType == AtomTextConstructType.Xhtml) { XPathNavigator xhtmlDivNavigator = source.SelectSingleNode("xhtml:div", manager); if (xhtmlDivNavigator != null && !String.IsNullOrEmpty(xhtmlDivNavigator.Value)) { this.Content = xhtmlDivNavigator.Value; wasLoaded = true; } } else if (this.TextType == AtomTextConstructType.Html && !String.IsNullOrEmpty(source.InnerXml)) { this.Content = source.InnerXml; wasLoaded = true; } else if (!String.IsNullOrEmpty(source.Value)) { this.Content = source.Value; wasLoaded = true; } return(wasLoaded); }