1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using System
.Collections
;
19 using System
.Configuration
;
23 /// Represents a set of url routing rules.
25 public class RoutingRuleCollection
: CollectionBase
, ISerializedConfig
27 #region ISerializedConfig implementation
30 /// Deserializes the specified section.
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());
67 /// Gets the <see cref="Castle.MonoRail.Framework.Configuration.RoutingRule"/> at the specified index.
70 public RoutingRule
this[int index
]
72 get { return InnerList[index] as RoutingRule; }