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 static WebControlsConfig instance;
43 string configFilePath;
45 public WebControlsConfig (WebControlsConfig parent, object context)
47 configFilePath = context as string;
51 scriptsVDir = parent.scriptsVDir;
52 if (scriptsVDir != null)
53 configFilePath = parent.configFilePath;
56 public void SetClientScriptsLocation (string location, out string error)
59 if (location == null || location.Length == 0) {
60 error = "empty or null value for clientScriptsLocation";
64 if (location [0] != '/')
65 location = "/" + location;
67 string [] splitted = location.Split ('/');
68 int end = splitted.Length;
69 for (int i = 0; i < end; i++)
70 splitted [i] = HttpUtility.UrlEncode (splitted [i]);
72 scriptsVDir = String.Join ("/", splitted);
75 public string ScriptsPhysicalDirectory {
76 get { return Path.Combine (Path.GetDirectoryName (configFilePath), "web_scripts"); }
79 public string ScriptsVirtualDirectory {
80 get { return scriptsVDir; }
81 set { scriptsVDir = value; }
84 static public WebControlsConfig Instance {
86 //TODO: use HttpContext to get the configuration
90 lock (typeof (WebControlsConfig)) {
94 instance = (WebControlsConfig) ConfigurationSettings.GetConfig ("system.web/webControls");
102 class WebControlsSectionHandler : IConfigurationSectionHandler
104 public object Create (object parent, object context, XmlNode section)
106 WebControlsConfig config = new WebControlsConfig (parent as WebControlsConfig, context);
108 if (section.Attributes == null && section.Attributes.Count == 0)
109 ThrowException ("Lack of clientScriptsLocation attribute", section);
111 string clientLocation = AttValue ("clientScriptsLocation", section, false);
112 if (section.Attributes != null && section.Attributes.Count != 0)
113 HandlersUtil.ThrowException ("Unrecognized attribute", section);
116 config.SetClientScriptsLocation (clientLocation, out error);
118 HandlersUtil.ThrowException (error, section);
123 // To save some typing...
124 static string AttValue (string name, XmlNode node, bool optional)
126 return HandlersUtil.ExtractAttributeValue (name, node, optional);
129 static void ThrowException (string message, XmlNode node)
131 HandlersUtil.ThrowException (message, node);