NVelocity.Runtime.Resource.ResourceManagerImpl.LoadResource C# (CSharp) Method

LoadResource() protected method

Loads a resource from the current set of resource loaders
protected LoadResource ( String resourceName, ResourceType resourceType, String encoding ) : Resource
resourceName String The name of the resource to retrieve.
resourceType ResourceType The type of resource (Template, /// Content, etc.). ///
encoding String The character encoding to use.
return Resource
        protected internal Resource LoadResource(String resourceName, ResourceType resourceType, String encoding)
        {
            Resource resource = ResourceFactory.GetResource(resourceName, resourceType);

            resource.RuntimeServices = runtimeServices;

            resource.Name = resourceName;
            resource.Encoding = encoding;

            /*
            * Now we have to try to find the appropriate
            * loader for this resource. We have to cycle through
            * the list of available resource loaders and see
            * which one gives us a stream that we can use to
            * make a resource with.
            */

            long howOldItWas = 0; // Initialize to avoid warnings

            ResourceLoader resourceLoader = null;

            for(int i = 0; i < resourceLoaders.Count; i++)
            {
                resourceLoader = (ResourceLoader) resourceLoaders[i];
                resource.ResourceLoader = resourceLoader;

                /*
            *  catch the ResourceNotFound exception
            *  as that is ok in our new multi-loader environment
            */

                try
                {
                    if (resource.Process())
                    {
                        /*
            *  FIXME  (gmj)
            *  moved in here - technically still
            *  a problem - but the resource needs to be
            *  processed before the loader can figure
            *  it out due to to the new
            *  multi-path support - will revisit and fix
            */

                        if (logWhenFound)
                        {
                            runtimeServices.Info(
                                string.Format("ResourceManager : found {0} with loader {1}", resourceName, resourceLoader.ClassName));
                        }

                        howOldItWas = resourceLoader.GetLastModified(resource);
                        break;
                    }
                }
                catch(ResourceNotFoundException)
                {
                    /*
                    *  that's ok - it's possible to fail in
                    *  multi-loader environment
                    */
                }
            }

            /*
            * Return null if we can't find a resource.
            */
            if (resource.Data == null)
            {
                throw new ResourceNotFoundException(string.Format("Unable to find resource '{0}'", resourceName));
            }

            /*
            *  some final cleanup
            */

            resource.LastModified = howOldItWas;

            resource.ModificationCheckInterval = resourceLoader.ModificationCheckInterval;

            resource.Touch();

            return resource;
        }