|
using System;
using System.Web.UI.WebControls;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
namespace BasePageFramework.Configuration
{
/// <summary>
/// Summary description for BasePageConfiguration.
/// </summary>
public class BasePageConfiguration
{
private string _pageName = string.Empty;
private NameValueCollection _bodyAttributes = new NameValueCollection();
private HorizontalAlign _alignment = HorizontalAlign.NotSet;
private string _defaultTitle = string.Empty;
private NameValueCollection _scriptFiles = new NameValueCollection();
private NameValueCollection _cssFiles = new NameValueCollection();
private NameValueCollection _metaTags = new NameValueCollection();
public BasePageConfiguration(XmlNode xml)
{
//parse the xml passed to us and set the configuration state
//first get the name of this page
System.Xml.XmlAttribute pageName = (XmlAttribute)xml.Attributes.GetNamedItem("name");
System.Xml.XmlAttribute defaultTitle = (XmlAttribute)xml.Attributes.GetNamedItem("defaultTitle");
if(defaultTitle != null)
_defaultTitle = defaultTitle.Value;
else
_defaultTitle = string.Empty;
if(pageName != null)
_pageName = pageName.Value;
else
throw new System.Configuration.ConfigurationException("The name attribute is required on all basepage configuration entries.");
//get the body tag attributes
System.Xml.XmlNodeList bodyAttrib = xml.SelectNodes("body/attribute");
foreach(XmlNode attr in bodyAttrib)
{
XmlAttribute name = (XmlAttribute)attr.Attributes.GetNamedItem("name");
XmlAttribute val = (XmlAttribute)attr.Attributes.GetNamedItem("value");
if(name != null && val != null)
{
_bodyAttributes.Add(name.Value,val.Value);
}
}
//get the site settings
System.Xml.XmlNode title = xml.SelectSingleNode("site/title");
if(title != null)
{
XmlAttribute val = (XmlAttribute)title.Attributes.GetNamedItem("value");
if(val != null)
_defaultTitle = val.Value;
}
//get the main page links
System.Xml.XmlNodeList cssFiles = xml.SelectNodes("links/css");
foreach(XmlNode css in cssFiles)
{
XmlAttribute file = (XmlAttribute)css.Attributes.GetNamedItem("file");
XmlAttribute path = (XmlAttribute)css.Attributes.GetNamedItem("path");
if(file != null && path != null)
_cssFiles.Add(file.Value,path.Value);
}
System.Xml.XmlNodeList scriptFiles = xml.SelectNodes("links/script");
foreach(XmlNode script in scriptFiles)
{
XmlAttribute file = (XmlAttribute)script.Attributes.GetNamedItem("file");
XmlAttribute path = (XmlAttribute)script.Attributes.GetNamedItem("path");
if(file != null && path != null)
_scriptFiles.Add(file.Value,path.Value);
}
//get the place holder settings so we can see what user controls to load into our base page placeholders
System.Xml.XmlNodeList metaTags = xml.SelectNodes("metatags/meta");
foreach(XmlNode tag in metaTags)
{
XmlAttribute name = (XmlAttribute)tag.Attributes.GetNamedItem("name");
XmlAttribute content = (XmlAttribute)tag.Attributes.GetNamedItem("Content");
this._metaTags.Add(name.Value,content.Value);
}
}
//do not allow outside access to the individual values of the configuration
public NameValueCollection BodyAttributes
{get{return _bodyAttributes;}}
public HorizontalAlign SiteAlignment
{get{return _alignment;}}
public string DefaultTitle
{get{return _defaultTitle;}}
public NameValueCollection Scripts
{get{return _scriptFiles;}}
public NameValueCollection StyleSheets
{get{return _cssFiles;}}
public string Name
{get{return _pageName;}}
public NameValueCollection MetaTags
{get{return _metaTags;}}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.