<commit_before>// Copyright 2004-2007 Castle Project - http://www.castleproject.org/
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Directive = NVelocity.Runtime.Directive.Directive;
using DirectiveType = NVelocity.Runtime.Directive.DirectiveType;
using IInternalContextAdapter = NVelocity.Context.IInternalContextAdapter;
using INode = NVelocity.Runtime.Parser.Node.INode;
using IRuntimeServices = NVelocity.Runtime.IRuntimeServices;

namespace Castle.MonoRail.Framework.Views.NVelocity.CustomDirectives
{
	using System;
	using System.Collections;
	using System.IO;

	public class SubSectionDirective : Directive
	{
		private readonly string name;
		private NVelocityViewContextAdapter contextAdapter;
		private INode savedNode;

		public SubSectionDirective(String name)
		{
			this.name = name;
		}

		/// <summary>
		/// Return the name of this directive
		/// </summary>
		public override String Name
		{
			get { return name; }
			set { throw new NotImplementedException(); }
		}

		/// <summary>
		/// Get the directive type BLOCK/LINE
		/// </summary>
		public override DirectiveType Type
		{
			get { return DirectiveType.BLOCK; }
		}

		public override bool AcceptParams
		{
			get { return false; }
		}

		/// <summary>
		/// How this directive is to be initialized.
		/// </summary>
		public override void Init(IRuntimeServices rs, IInternalContextAdapter context, INode node)
		{
			base.Init(rs, context, node);

			savedNode = node;
		}

		/// <summary>
		/// How this directive is to be rendered
		/// </summary>
		public override bool Render(IInternalContextAdapter context, TextWriter writer, INode node)
		{
			if (context == null)
			{
				throw new MonoRailException("context is null");
			}

			if (contextAdapter == null)
			{
				throw new MonoRailException("contextAdapter is null");
			}

			if (contextAdapter.ContextVars == null)
			{
				throw new MonoRailException("contextAdapter.ContextVars is null");
			}

			foreach(DictionaryEntry entry in contextAdapter.ContextVars)
			{
				context.Put(entry.Key.ToString(), entry.Value);
			}

			for(int i=0; i < savedNode.ChildrenCount; i++)
			{<commit_msg>Fixed nasty sife effect of ViewComponent cache misuse on directive implementation<commit_after>// Copyright 2004-2007 Castle Project - http://www.castleproject.org/
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Directive = NVelocity.Runtime.Directive.Directive;
using DirectiveType = NVelocity.Runtime.Directive.DirectiveType;
using IInternalContextAdapter = NVelocity.Context.IInternalContextAdapter;
using INode = NVelocity.Runtime.Parser.Node.INode;
using IRuntimeServices = NVelocity.Runtime.IRuntimeServices;

namespace Castle.MonoRail.Framework.Views.NVelocity.CustomDirectives
{
	using System;
	using System.Collections;
	using System.IO;

	public class SubSectionDirective : Directive
	{
		private readonly string name;
		private NVelocityViewContextAdapter contextAdapter;
		private INode savedNode;

		public SubSectionDirective(String name)
		{
			this.name = name;
		}

		/// <summary>
		/// Return the name of this directive
		/// </summary>
		public override String Name
		{
			get { return name; }
			set { throw new NotImplementedException(); }
		}

		/// <summary>
		/// Get the directive type BLOCK/LINE
		/// </summary>
		public override DirectiveType Type
		{
			get { return DirectiveType.BLOCK; }
		}

		public override bool AcceptParams
		{
			get { return false; }
		}

		/// <summary>
		/// How this directive is to be initialized.
		/// </summary>
		public override void Init(IRuntimeServices rs, IInternalContextAdapter context, INode node)
		{
			base.Init(rs, context, node);

			savedNode = node;
		}

		/// <summary>
		/// How this directive is to be rendered
		/// </summary>
		public override bool Render(IInternalContextAdapter context, TextWriter writer, INode node)
		{
			if (context == null)
			{
				throw new MonoRailException("context is null");
			}

			if (contextAdapter == null)
			{
				throw new MonoRailException("contextAdapter is null");
			}

			if (contextAdapter.ContextVars == null)
			{
				throw new MonoRailException("contextAdapter.ContextVars is null");
			}

//			foreach(DictionaryEntry entry in contextAdapter.ContextVars)
//			{
//				context.Put(entry.Key.ToString(), entry.Value);
//			}

			for(int i=0; i < savedNode.ChildrenCount; i++)
			{
{'fraction_non_alphanumeric': 0.10029717682020803, 'fraction_numerical': 0.0048291233283803865, 'mean_word_length': 3.4467382328654006, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1378273', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1507, 'n_words': 494}