All pastes #223595 Raw Edit

Shin-Ra

public text v1 · immutable
#223595 ·published 2006-10-27 00:22 UTC
rendered paste body
using System;
using System.Collections;
using System.Configuration;
using System.Web.UI;
using BulletinX.Components;
namespace BulletinX.Controls
{
    [PersistChildren(true), ParseChildren(false)]
    public class Head : Control
    {
        public static readonly string titleKey = ConfigurationManager.AppSettings["SiteTitle"];
        public static readonly string faviconKey = ConfigurationManager.AppSettings["Favicon"];
        public static string styleFormat = "<link rel=\"stylesheet\" href=\"{0}\" type=\"text/css\" media=\"{1}\" />";
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write( "" );
            writer.Write( "<head>\n" );
            RenderTitle( writer );
            RenderFavicon( writer );
            RenderStyleSheets( writer );
            writer.Write( "</head>" );
        }
        
        protected virtual void RenderTitle(HtmlTextWriter writer)
        {
            string title = titleKey;
            if (title == null)
                throw new ApplicationException( "Site Title is blank please enter a title in the web.config" );
            writer.Write( "\t<title>{0}</title>\n", title );
        }
        
        protected virtual void RenderFavicon(HtmlTextWriter writer)
        {
            writer.Write("\t<link rel=\"shortcut icon\" type=\"image/ico\" href=\"{0}\"/>\n", faviconKey);
        }
        
        protected virtual void RenderStyleSheets(HtmlTextWriter writer)
        {
            RenderStyleSheets( writer, StyleFlags.First );
            RenderStyleSheets( writer, StyleFlags.Unknown );
            RenderStyleSheets( writer, StyleFlags.Last );
        }
        
        protected virtual void RenderStyleSheets(HtmlTextWriter writer, StyleFlags flags)
        {
            
            
            Queue queue = (Queue)styleFormat;
            if(queue != null && queue.Count > 0)
            {
                IEnumerator ie = queue.GetEnumerator( );
                while(ie.MoveNext())
                {
                    StyleQueue si = (StyleQueue)ie.Current;
                    if (si.position == flags)
                        writer.WriteLine( si.styleTag );
                }
            }
        }
        
        public static void AddStyle(string url, string media)
        {
            AddStyle( url, media, StyleFlags.Unknown );
        }
        
        public static void AddStyle(string url, string media, StyleFlags flags)
        {
            Queue styleQueue = (Queue)styleFormat;
            if(styleQueue == null)
            {
                styleQueue = new Queue( );
                styleFormat = styleQueue;
            }
            styleQueue.Enqueue( new StyleQueue( string.Format( (string)styleFormat, url, media ), flags ) );
        }
    }
}