Imports System Imports System.Collections Imports System.Configuration Imports System.Web Imports System.Web.UI Imports BulletinX.Components Namespace BulletinX.Controls _ Public Class Head Inherits Control ''' ''' The value of the title in the web.config. ''' ''' ''' ''' Public Shared ReadOnly titleKey As String = ConfigurationManager.AppSettings("SiteTitle") ''' ''' The value of the location of the Favicon. ''' ''' ''' ''' Public Shared ReadOnly faviconKey As String = ConfigurationManager.AppSettings("Favicon") ''' ''' The string format of the style to create each time a style is added to the head. ''' ''' ''' The style format that is created each time. Href and Media are string inputs. ''' Public Shared styleFormat As String = "" ''' ''' Overrides the default Render method. ''' ''' ''' HtmlTextWriter to create the Rendering process. ''' ''' ''' Need to write the output to the browser. ''' Protected Overrides Sub Render(ByVal writer As HtmlTextWriter) writer.Write("") writer.WriteLine("") RenderTitle(writer) RenderFavicon(writer) RenderStyleSheets(writer) writer.WriteLine("") End Sub ''' ''' Render the html title tags. ''' ''' ''' HtmlTextWriter to write the title tags. ''' ''' ''' Creates the title tags by the control. ''' Protected Overridable Sub RenderTitle(ByVal writer As HtmlTextWriter) Dim title As String = titleKey If title Is Nothing Then '' '' TODO: Change this '' Throw New ApplicationException("SiteTitle is empty, please enter a title in the web.config.") End If writer.WriteLine("{0}", title) End Sub ''' ''' Render the favicon tag. ''' ''' ''' HtmlTextWriter to write by the favicon tags. ''' ''' ''' Creates the favicon tags by the control. ''' Protected Overridable Sub RenderFavicon(ByVal writer As HtmlTextWriter) writer.WriteLine("", faviconKey) End Sub ''' ''' Render the stylesheets tags. ''' ''' ''' HtmlTextWriter to write by the stylesheet tags. ''' ''' ''' Creates the stylesheet tags by the control. ''' Protected Overridable Sub RenderStyleSheets(ByVal writer As HtmlTextWriter) RenderStyleSheets(writer, StyleFlags.First) RenderStyleSheets(writer, StyleFlags.Last) RenderStyleSheets(writer, StyleFlags.Unknown) End Sub ''' ''' Render the stylesheets tags. ''' ''' ''' HtmlTextWriter to write by the stylesheet tags. ''' ''' ''' Position of the way the stylesheets are created. ''' ''' ''' Creates the stylesheet tags by the control. ''' Protected Overridable Sub RenderStyleSheets(ByVal writer As HtmlTextWriter, ByVal flags As StyleFlags) Dim q As Queue = CType(Context.Items(styleFormat), Queue) If q IsNot Nothing AndAlso q.Count > 0 Then Dim ie As IEnumerator = q.GetEnumerator() While (ie.MoveNext()) Dim si As StyleQueue = CType(ie.Current, StyleQueue) If si._position = flags Then writer.WriteLine(si._styleTag) End If End While End If End Sub ''' ''' Gets values from the child controls. ''' ''' ''' Url of the stylesheet location. ''' ''' ''' Media type for the stylesheet. ''' ''' ''' Gets the values from the child control of Style. ''' Public Shared Sub AddStyle(ByVal url As String, ByVal media As String) AddStyle(url, StyleFlags.Unknown) End Sub ''' ''' Gets values from the child controls. ''' ''' ''' Url of the stylesheet location. ''' ''' ''' Media type for the stylesheet. ''' ''' ''' Position of the stylesheet. ''' ''' ''' Gets the values from the child control of Style. ''' Public Shared Sub AddStyle(ByVal url As String, ByVal media As String, ByVal flags As StyleFlags) Dim context As HttpContext = HttpContext.Current Dim styleQueue As Queue = CType(context.Items(styleFormat), Queue) If styleQueue Is Nothing Then styleQueue = New Queue context.Items(styleFormat) = styleQueue End If styleQueue.Enqueue(New StyleQueue(String.Format(styleFormat, url, media), flags)) End Sub End Class End Namespace