/// <summary>public static string CalculateUri(string base, string inheritedBase, string local)</summary> /// <param name="localBase">the baseUri from xml:base </param> /// <param name="inheritedBase">the pushed down baseUri from an outer element</param> /// <param name="localUri">the Uri value</param> /// <returns>the absolute Uri to use... </returns> internal static string CalculateUri(AtomUri localBase, AtomUri inheritedBase, string localUri) { try { Uri uriBase = null; Uri uriSuperBase = null; Uri uriComplete = null; if (inheritedBase != null && inheritedBase.ToString() != null) { uriSuperBase = new Uri(inheritedBase.ToString()); } if (localBase != null && localBase.ToString() != null) { if (uriSuperBase != null) { uriBase = new Uri(uriSuperBase, localBase.ToString()); } else { uriBase = new Uri(localBase.ToString()); } } else { // if no local xml:base, take the passed down one uriBase = uriSuperBase; } if (localUri != null) { if (uriBase != null) { uriComplete = new Uri(uriBase, localUri.ToString()); } else { uriComplete = new Uri(localUri.ToString()); } } else { uriComplete = uriBase; } return(uriComplete != null ? uriComplete.AbsoluteUri : null); } catch (System.UriFormatException) { return("Unsupported URI format"); } }
/// <summary>helper method to encapsulate a string encoding, uses HTML encoding now</summary> /// <param name="writer">the xml writer to write to</param> /// <param name="content">the string to encode</param> protected static void WriteEncodedString(XmlWriter writer, AtomUri content) { if (writer == null) { throw new System.ArgumentNullException("writer", "No valid xmlWriter"); } if (Utilities.IsPersistable(content)) { string encoded = Utilities.EncodeString(content.ToString()); writer.WriteString(encoded); } }
/// <summary>helper method to encapsulate encoding, uses HTML encoding now</summary> /// <param name="writer">the xml writer to write to</param> /// <param name="elementName">the attribute the write</param> /// <param name="content">the string to encode</param> protected static void WriteEncodedElementString(XmlWriter writer, string elementName, AtomUri content) { if (writer == null) { throw new ArgumentNullException("writer"); } if (Utilities.IsPersistable(content)) { string encoded = Utilities.EncodeString(content.ToString()); writer.WriteElementString(elementName, BaseNameTable.NSAtom, encoded); } }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>figures out if this object should be persisted</summary> /// <returns> true, if it's worth saving</returns> ////////////////////////////////////////////////////////////////////// public override bool ShouldBePersisted() { if (!base.ShouldBePersisted()) { if (_uri != null && Utilities.IsPersistable(_uri.ToString())) { return(true); } if (Utilities.IsPersistable(_version) || Utilities.IsPersistable(_text)) { return(true); } return(false); } return(true); }
/// <summary>Little helper that checks if a string is XML persistable</summary> public static bool IsPersistable(AtomUri uriString) { return(uriString == null ? false : Utilities.IsPersistable(uriString.ToString())); }