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
.Views
.Brail
17 using System
.Collections
;
20 using Castle
.MonoRail
.Framework
;
22 public class BrailViewComponentContext
: IViewComponentContext
26 IDictionary componentParameters
;
31 private readonly TextWriter default_writer
;
32 private BrailBase parent
;
35 /// Initializes a new instance of the <see cref="BrailViewComponentContext"/> class.
37 /// <param name="parent">The parent.</param>
38 /// <param name="body">The body.</param>
39 /// <param name="name">The name.</param>
40 /// <param name="text">The text.</param>
41 /// <param name="parameters">The parameters.</param>
42 public BrailViewComponentContext(BrailBase parent
, ICallable body
,
43 string name
, TextWriter text
, IDictionary parameters
)
48 default_writer
= text
;
49 componentParameters
= parameters
;
52 public string ComponentName
54 get { return componentName; }
57 public IDictionary ContextVars
59 get { return parent.Properties; }
62 public IDictionary ComponentParameters
64 get { return componentParameters; }
67 public string ViewToRender
69 get { return viewToRender; }
70 set { viewToRender = value; }
79 public TextWriter Writer
81 get { return default_writer; }
84 public void RenderBody()
86 RenderBody(default_writer
);
89 public void RenderBody(TextWriter writer
)
93 throw new MonoRailException("This component does not have a body content to be rendered");
95 using (parent
.SetOutputStream(writer
))
97 body
.Call(new object[] { writer }
);
104 /// <param name="name"></param>
105 /// <param name="writer"></param>
106 public void RenderView(string name
, TextWriter writer
)
108 parent
.OutputSubView(name
, writer
, new Hashtable());
111 public bool HasSection(string sectionName
)
113 return sections
!= null && sections
.Contains(sectionName
);
116 public void RenderSection(string sectionName
)
118 RenderSection(sectionName
, default_writer
);
122 /// Renders the the specified section
124 /// <param name="sectionName">Name of the section.</param>
125 /// <param name="writer">The writer.</param>
126 public void RenderSection(string sectionName
, TextWriter writer
)
128 if (HasSection(sectionName
) == false)
129 return;//matching the NVelocity behavior, but maybe should throw?
130 ICallable callable
= (ICallable
)sections
[sectionName
];
131 callable
.Call(new object[] { writer }
);
134 public IViewEngine ViewEngine
136 get { return parent.ViewEngine; }
139 public void RegisterSection(string name
, ICallable section
)
141 if (sections
== null)
143 sections
= new Hashtable(System
.StringComparer
.InvariantCultureIgnoreCase
);
145 sections
[name
] = section
;