2 // System.Web.Configuration.WebControlsSectionHandler
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2003 Ximian, Inc (http://www.ximian.com)
11 using System.Configuration;
16 namespace System.Web.Configuration
18 class WebControlsConfig
20 static WebControlsConfig instance;
22 string configFilePath;
24 public WebControlsConfig (WebControlsConfig parent, object context)
26 configFilePath = context as string;
30 scriptsVDir = parent.scriptsVDir;
31 if (scriptsVDir != null)
32 configFilePath = parent.configFilePath;
35 public void SetClientScriptsLocation (string location, out string error)
38 if (location == null || location.Length == 0) {
39 error = "empty or null value for clientScriptsLocation";
43 if (location [0] != '/')
44 location = "/" + location;
46 string [] splitted = location.Split ('/');
47 int end = splitted.Length;
48 for (int i = 0; i < end; i++)
49 splitted [i] = HttpUtility.UrlEncode (splitted [i]);
51 scriptsVDir = String.Join ("/", splitted);
54 public string ScriptsPhysicalDirectory {
55 get { return Path.Combine (Path.GetDirectoryName (configFilePath), "web_scripts"); }
58 public string ScriptsVirtualDirectory {
59 get { return scriptsVDir; }
60 set { scriptsVDir = value; }
63 static public WebControlsConfig Instance {
65 //TODO: use HttpContext to get the configuration
69 lock (typeof (WebControlsConfig)) {
73 instance = (WebControlsConfig) ConfigurationSettings.GetConfig ("system.web/webControls");
81 class WebControlsSectionHandler : IConfigurationSectionHandler
83 public object Create (object parent, object context, XmlNode section)
85 WebControlsConfig config = new WebControlsConfig (parent as WebControlsConfig, context);
87 if (section.Attributes == null && section.Attributes.Count == 0)
88 ThrowException ("Lack of clientScriptsLocation attribute", section);
90 string clientLocation = AttValue ("clientScriptsLocation", section, false);
91 if (section.Attributes != null && section.Attributes.Count != 0)
92 HandlersUtil.ThrowException ("Unrecognized attribute", section);
95 config.SetClientScriptsLocation (clientLocation, out error);
97 HandlersUtil.ThrowException (error, section);
102 // To save some typing...
103 static string AttValue (string name, XmlNode node, bool optional)
105 return HandlersUtil.ExtractAttributeValue (name, node, optional);
108 static string AttValue (string name, XmlNode node)
110 return HandlersUtil.ExtractAttributeValue (name, node, true);
113 static void ThrowException (string message, XmlNode node)
115 HandlersUtil.ThrowException (message, node);