2 // System.Web.Configuration.WebControlsSectionHandler
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2003 Ximian, Inc (http://www.ximian.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Configuration;
37 namespace System.Web.Configuration
39 class WebControlsConfig
41 volatile static WebControlsConfig instance;
43 string configFilePath;
44 static readonly object lockobj = new object ();
46 public WebControlsConfig (WebControlsConfig parent, object context)
48 configFilePath = context as string;
52 scriptsVDir = parent.scriptsVDir;
53 if (scriptsVDir != null)
54 configFilePath = parent.configFilePath;
57 public void SetClientScriptsLocation (string location, out string error)
60 if (location == null || location.Length == 0) {
61 error = "empty or null value for clientScriptsLocation";
65 if (location [0] != '/')
66 location = "/" + location;
68 string [] splitted = location.Split ('/');
69 int end = splitted.Length;
70 for (int i = 0; i < end; i++)
71 splitted [i] = HttpUtility.UrlEncode (splitted [i]);
73 scriptsVDir = String.Join ("/", splitted);
76 public string ScriptsPhysicalDirectory {
77 get { return Path.Combine (Path.GetDirectoryName (configFilePath), "web_scripts"); }
80 public string ScriptsVirtualDirectory {
81 get { return scriptsVDir; }
82 set { scriptsVDir = value; }
85 static public WebControlsConfig Instance {
87 //TODO: use HttpContext to get the configuration
95 instance = (WebControlsConfig) ConfigurationSettings.GetConfig ("system.web/webControls");
103 class WebControlsSectionHandler : IConfigurationSectionHandler
105 public object Create (object parent, object context, XmlNode section)
107 WebControlsConfig config = new WebControlsConfig (parent as WebControlsConfig, context);
109 if (section.Attributes == null && section.Attributes.Count == 0)
110 ThrowException ("Lack of clientScriptsLocation attribute", section);
112 string clientLocation = AttValue ("clientScriptsLocation", section, false);
113 if (section.Attributes != null && section.Attributes.Count != 0)
114 HandlersUtil.ThrowException ("Unrecognized attribute", section);
117 config.SetClientScriptsLocation (clientLocation, out error);
119 HandlersUtil.ThrowException (error, section);
124 // To save some typing...
125 static string AttValue (string name, XmlNode node, bool optional)
127 return HandlersUtil.ExtractAttributeValue (name, node, optional);
130 static void ThrowException (string message, XmlNode node)
132 HandlersUtil.ThrowException (message, node);