Minor changes to improve testability of helpers
[castle.git] / MonoRail / Castle.MonoRail.Framework / Configuration / RoutingRuleCollection.cs
blob459bb3af587c986a1f3b376694113f410cf692e8
1 // Copyright 2004-2007 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.Collections;
19 using System.Configuration;
20 using System.Xml;
22 /// <summary>
23 /// Represents a set of url routing rules.
24 /// </summary>
25 public class RoutingRuleCollection : CollectionBase, ISerializedConfig
27 #region ISerializedConfig implementation
29 /// <summary>
30 /// Deserializes the specified section.
31 /// </summary>
32 /// <param name="section">The section.</param>
33 public void Deserialize(XmlNode section)
35 XmlNodeList services = section.SelectNodes("routing/rule");
37 foreach(XmlNode node in services)
39 XmlNode patternNode = node.SelectSingleNode("pattern");
40 XmlNode replaceNode = node.SelectSingleNode("replace");
42 if (patternNode == null || patternNode.ChildNodes.Count == 0 || patternNode.ChildNodes[0] == null)
44 String message = "A rule node must have a pattern (child) " +
45 "node denoting the regular expression to be matched";
46 throw new ConfigurationErrorsException(message);
48 if (replaceNode == null || replaceNode.ChildNodes.Count == 0 || replaceNode.ChildNodes[0] == null)
50 String message = "A rule node must have a replace (child) " +
51 "node denoting the string to be replaced";
52 throw new ConfigurationErrorsException(message);
55 String pattern = patternNode.ChildNodes[0].Value;
56 String replace = replaceNode.ChildNodes[0].Value;
58 RoutingRule rule = new RoutingRule(pattern.Trim(), replace.Trim());
60 InnerList.Add(rule);
64 #endregion
66 /// <summary>
67 /// Gets the <see cref="Castle.MonoRail.Framework.Configuration.RoutingRule"/> at the specified index.
68 /// </summary>
69 /// <value></value>
70 public RoutingRule this[int index]
72 get { return InnerList[index] as RoutingRule; }