Changed to use Authenticate asp.net event instead of Authorize
[castle.git] / MonoRail / Castle.MonoRail.Framework.Views.NVelocity / CustomDirectives / SubSectionDirective.cs
blobe3a5391c0a3f9806554f100bea40e7bda7d48b49
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 using Directive = NVelocity.Runtime.Directive.Directive;
16 using DirectiveType = NVelocity.Runtime.Directive.DirectiveType;
17 using IInternalContextAdapter = NVelocity.Context.IInternalContextAdapter;
18 using INode = NVelocity.Runtime.Parser.Node.INode;
19 using IRuntimeServices = NVelocity.Runtime.IRuntimeServices;
21 namespace Castle.MonoRail.Framework.Views.NVelocity.CustomDirectives
23 using System;
24 using System.Collections;
25 using System.IO;
27 public class SubSectionDirective : Directive
29 private readonly string name;
30 private NVelocityViewContextAdapter contextAdapter;
31 private INode savedNode;
33 public SubSectionDirective(String name)
35 this.name = name;
38 /// <summary>
39 /// Return the name of this directive
40 /// </summary>
41 public override String Name
43 get { return name; }
44 set { throw new NotImplementedException(); }
47 /// <summary>
48 /// Get the directive type BLOCK/LINE
49 /// </summary>
50 public override DirectiveType Type
52 get { return DirectiveType.BLOCK; }
55 public override bool AcceptParams
57 get { return false; }
60 /// <summary>
61 /// How this directive is to be initialized.
62 /// </summary>
63 public override void Init(IRuntimeServices rs, IInternalContextAdapter context, INode node)
65 base.Init(rs, context, node);
67 savedNode = node;
70 /// <summary>
71 /// How this directive is to be rendered
72 /// </summary>
73 public override bool Render(IInternalContextAdapter context, TextWriter writer, INode node)
75 if (context == null)
77 throw new RailsException("context is null");
80 if (contextAdapter == null)
82 throw new RailsException("contextAdapter is null");
85 if (contextAdapter.ContextVars == null)
87 throw new RailsException("contextAdapter.ContextVars is null");
90 foreach(DictionaryEntry entry in contextAdapter.ContextVars)
92 context.Put(entry.Key.ToString(), entry.Value);
95 for(int i=0; i < savedNode.ChildrenCount; i++)
97 INode childNode = savedNode.GetChild(i);
98 childNode.Render(context, writer);
101 return true;
104 internal NVelocityViewContextAdapter ContextAdapter
106 set { contextAdapter = value; }