Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework / Configuration / MonoRailConfiguration.cs
blob2dacf3b0c726d1eb62deb9bef8caea16e80a14dc
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework.Configuration
17 using System;
18 using System.Configuration;
19 using System.Xml;
20 using Castle.Core.Configuration;
21 using Castle.Core.Configuration.Xml;
22 using Castle.MonoRail.Framework.Helpers.ValidationStrategy;
23 using Castle.MonoRail.Framework.JSGeneration.Prototype;
24 using JSGeneration;
26 /// <summary>
27 /// Represents the MonoRail external configuration
28 /// </summary>
29 public class MonoRailConfiguration : IMonoRailConfiguration, ISerializedConfig
31 private static readonly String SectionName = "monorail";
32 private static readonly String AlternativeSectionName = "monoRail";
34 private bool matchHostNameAndPath, excludeAppPath;
35 private Type customFilterFactory;
36 private IConfiguration configurationSection;
38 private SmtpConfig smtpConfig;
39 private ViewEngineConfig viewEngineConfig;
40 private ControllersConfig controllersConfig;
41 private ViewComponentsConfig viewComponentsConfig;
42 private ScaffoldConfig scaffoldConfig;
43 private UrlConfig urlConfig;
44 private JSGeneratorConfiguration jsGeneratorConfig;
45 private RoutingRuleCollection routingRules;
46 private ExtensionEntryCollection extensions;
47 private DefaultUrlCollection defaultUrls;
48 private IConfiguration servicesConfig = new MutableConfiguration("services");
50 /// <summary>
51 /// Initializes a new instance of the <see cref="MonoRailConfiguration"/> class.
52 /// </summary>
53 public MonoRailConfiguration()
55 smtpConfig = new SmtpConfig();
56 viewEngineConfig = new ViewEngineConfig();
57 controllersConfig = new ControllersConfig();
58 viewComponentsConfig = new ViewComponentsConfig();
59 scaffoldConfig = new ScaffoldConfig();
60 urlConfig = new UrlConfig();
61 routingRules = new RoutingRuleCollection();
62 extensions = new ExtensionEntryCollection();
63 defaultUrls = new DefaultUrlCollection();
64 jsGeneratorConfig = new JSGeneratorConfiguration();
66 jsGeneratorConfig.AddLibrary("prototype-1.5.1", typeof(PrototypeGenerator))
67 .AddExtension(typeof(CommonJSExtension))
68 .AddExtension(typeof(ScriptaculousExtension))
69 .AddExtension(typeof(BehaviourExtension))
70 .BrowserValidatorIs(typeof(PrototypeWebValidator))
71 .SetAsDefault();
73 // old routing support related
74 matchHostNameAndPath = false;
75 excludeAppPath = false;
78 /// <summary>
79 /// Pendent
80 /// </summary>
81 /// <param name="section"></param>
82 public MonoRailConfiguration(XmlNode section) : this()
84 configurationSection = XmlConfigurationDeserializer.GetDeserializedNode(section);
87 /// <summary>
88 /// Gets the config.
89 /// </summary>
90 /// <returns></returns>
91 public static MonoRailConfiguration GetConfig()
93 MonoRailConfiguration config =
94 ConfigurationManager.GetSection(SectionName) as MonoRailConfiguration;
96 if (config == null)
98 config = ConfigurationManager.GetSection(AlternativeSectionName) as MonoRailConfiguration;
101 return config;
104 #region ISerializedConfig implementation
106 /// <summary>
107 /// Deserializes the specified node.
108 /// </summary>
109 /// <param name="node">The node.</param>
110 public void Deserialize(XmlNode node)
112 viewEngineConfig.Deserialize(node);
113 smtpConfig.Deserialize(node);
114 controllersConfig.Deserialize(node);
115 viewComponentsConfig.Deserialize(node);
116 scaffoldConfig.Deserialize(node);
117 urlConfig.Deserialize(node);
119 extensions.Deserialize(node);
120 routingRules.Deserialize(node);
121 defaultUrls.Deserialize(node);
123 ProcessFilterFactoryNode(node.SelectSingleNode("customFilterFactory"));
124 ProcessMatchHostNameAndPath(node.SelectSingleNode("routing"));
125 ProcessExcludeAppPath(node.SelectSingleNode("routing"));
127 XmlNode services = node.SelectSingleNode("services");
129 if (services != null)
131 servicesConfig = XmlConfigurationDeserializer.GetDeserializedNode(services);
135 #endregion
137 /// <summary>
138 /// Gets the SMTP config.
139 /// </summary>
140 /// <value>The SMTP config.</value>
141 public SmtpConfig SmtpConfig
143 get { return smtpConfig; }
146 /// <summary>
147 /// Gets the view engine config.
148 /// </summary>
149 /// <value>The view engine config.</value>
150 public ViewEngineConfig ViewEngineConfig
152 get { return viewEngineConfig; }
155 /// <summary>
156 /// Gets the controllers config.
157 /// </summary>
158 /// <value>The controllers config.</value>
159 public ControllersConfig ControllersConfig
161 get { return controllersConfig; }
162 set { controllersConfig = value; }
165 /// <summary>
166 /// Gets the view components config.
167 /// </summary>
168 /// <value>The view components config.</value>
169 public ViewComponentsConfig ViewComponentsConfig
171 get { return viewComponentsConfig; }
172 set { viewComponentsConfig = value; }
175 /// <summary>
176 /// Gets the routing rules.
177 /// </summary>
178 /// <value>The routing rules.</value>
179 public RoutingRuleCollection RoutingRules
181 get { return routingRules; }
182 set { routingRules = value; }
185 /// <summary>
186 /// Gets the extension entries.
187 /// </summary>
188 /// <value>The extension entries.</value>
189 public ExtensionEntryCollection ExtensionEntries
191 get { return extensions; }
194 /// <summary>
195 /// Gets the custom filter factory.
196 /// </summary>
197 /// <value>The custom filter factory.</value>
198 public Type CustomFilterFactory
200 get { return customFilterFactory; }
201 set { customFilterFactory = value; }
204 /// <summary>
205 /// Gets the scaffold config.
206 /// </summary>
207 /// <value>The scaffold config.</value>
208 public ScaffoldConfig ScaffoldConfig
210 get { return scaffoldConfig; }
211 set { scaffoldConfig = value; }
214 /// <summary>
215 /// Gets the url config.
216 /// </summary>
217 /// <value>The url config.</value>
218 public UrlConfig UrlConfig
220 get { return urlConfig; }
221 set { urlConfig = value; }
224 /// <summary>
225 /// Gets or sets the JS generator configuration.
226 /// </summary>
227 /// <value>The JS generator configuration.</value>
228 public JSGeneratorConfiguration JSGeneratorConfiguration
230 get { return jsGeneratorConfig; }
231 set { jsGeneratorConfig = value; }
234 /// <summary>
235 /// Gets a value indicating whether match host name and path should be used on
236 /// MonoRail routing.
237 /// </summary>
238 /// <value>
239 /// <c>true</c> if it should match host name and path; otherwise, <c>false</c>.
240 /// </value>
241 public bool MatchHostNameAndPath
243 get { return matchHostNameAndPath; }
244 set { matchHostNameAndPath = value; }
247 /// <summary>
248 /// Gets a value indicating whether routing should exclude app path.
249 /// </summary>
250 /// <value><c>true</c> if exclude app path; otherwise, <c>false</c>.</value>
251 public bool ExcludeAppPath
253 get { return excludeAppPath; }
254 set { excludeAppPath = value; }
257 /// <summary>
258 /// Gets the configuration section.
259 /// </summary>
260 /// <value>The configuration section.</value>
261 public IConfiguration ConfigurationSection
263 get { return configurationSection; }
264 set { configurationSection = value; }
267 /// <summary>
268 /// Gets the default urls.
269 /// </summary>
270 /// <value>The default urls.</value>
271 public DefaultUrlCollection DefaultUrls
273 get { return defaultUrls; }
276 /// <summary>
277 /// Gets or sets the services config.
278 /// </summary>
279 /// <value>The services config.</value>
280 public IConfiguration ServicesConfig
282 get { return servicesConfig; }
283 set { servicesConfig = value; }
286 private void ProcessFilterFactoryNode(XmlNode node)
288 if (node == null) return;
290 XmlAttribute type = node.Attributes["type"];
292 if (type == null)
294 String message = "The custom filter factory node must specify a 'type' attribute";
295 throw new ConfigurationErrorsException(message);
298 customFilterFactory = TypeLoadUtil.GetType(type.Value);
301 private void ProcessMatchHostNameAndPath(XmlNode node)
303 if (node == null) return;
305 XmlAttribute matchHostNameAndPathAtt = node.Attributes["matchHostNameAndPath"];
307 if (matchHostNameAndPathAtt != null && matchHostNameAndPathAtt.Value != String.Empty)
309 matchHostNameAndPath = String.Compare(matchHostNameAndPathAtt.Value, "true", true) == 0;
313 private void ProcessExcludeAppPath(XmlNode node)
315 if (node == null) return;
317 // maybe a check to make sure both matchHostNameAndPathAtt & includeAppPath
318 // are not both set as that wouldn't make sense?
319 XmlAttribute excludeAppPathAtt = node.Attributes["excludeAppPath"];
321 if (excludeAppPathAtt != null && excludeAppPathAtt.Value != String.Empty)
323 excludeAppPath = String.Compare(excludeAppPathAtt.Value, "true", true) == 0;