Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework.Views.NVelocity / ResourceLoaderAdapter.cs
blob77cff91a96d456dd28fd705181d26401aa0f42b7
1 // Copyright 2004-2008 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 Resource = NVelocity.Runtime.Resource.Resource;
16 using ResourceLoader = NVelocity.Runtime.Resource.Loader.ResourceLoader;
17 using ResourceNotFoundException = NVelocity.Exception.ResourceNotFoundException;
19 namespace Castle.MonoRail.Framework.Views.NVelocity
21 using System;
22 using System.IO;
24 using Commons.Collections;
26 public class ResourceLoaderAdapter : ResourceLoader
28 private readonly IViewSourceLoader sourceLoader;
30 public ResourceLoaderAdapter(IViewSourceLoader sourceLoader)
32 this.sourceLoader = sourceLoader;
35 internal IViewSource GetViewSource(String templateName)
37 if (sourceLoader.HasSource(templateName))
39 return sourceLoader.GetViewSource(templateName);
42 return null;
45 public override void Init(ExtendedProperties configuration)
49 public override Stream GetResourceStream(string source)
51 IViewSource viewSource = GetViewSource(source);
53 if (viewSource == null)
55 throw new ResourceNotFoundException(String.Format("Resource could not be located {0}", source));
58 return viewSource.OpenViewStream();
61 public override bool IsSourceModified(Resource resource)
63 CustomTemplate template = resource as CustomTemplate;
65 if (template != null)
67 return template.IsModified;
70 return false;
73 public override long GetLastModified(Resource resource)
75 return resource.LastModified;