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

RefreshResource() protected method

Takes an existing resource, and 'refreshes' it. This generally means that the source of the resource is checked for changes according to some cache/check algorithm and if the resource changed, then the resource data is reloaded and re-parsed. *
protected RefreshResource ( Resource resource, String encoding ) : void
resource Resource resource to refresh /// * /// @throws ResourceNotFoundException if template not found /// from current source for this Resource /// @throws ParseErrorException if template cannot be parsed due /// to syntax (or other) error. /// @throws Exception if a problem in parse /// ///
encoding String
return void
        protected internal void RefreshResource(Resource resource, String encoding)
        {
            /*
            * The resource knows whether it needs to be checked
            * or not, and the resource's loader can check to
            * see if the source has been modified. If both
            * these conditions are true then we must reload
            * the input stream and parse it to make a new
            * AST for the resource.
            */
            if (resource.RequiresChecking())
            {
                /*
            *  touch() the resource to reset the counters
            */

                resource.Touch();

                if (resource.IsSourceModified())
                {
                    /*
            *  now check encoding info.  It's possible that the newly declared
            *  encoding is different than the encoding already in the resource
            *  this strikes me as bad...
            */

                    if (!resource.Encoding.Equals(encoding))
                    {
                        runtimeServices.Error(
                            string.Format("Declared encoding for template '{0}' is different on reload.  Old = '{1}'  New = '{2}",
                                          resource.Name, resource.Encoding, encoding));

                        resource.Encoding = encoding;
                    }

                    /*
            *  read how old the resource is _before_
            *  processing (=>reading) it
            */
                    long howOldItWas = resource.ResourceLoader.GetLastModified(resource);

                    /*
            *  read in the fresh stream and parse
            */

                    resource.Process();

                    /*
            *  now set the modification info and reset
            *  the modification check counters
            */

                    resource.LastModified = howOldItWas;
                }
            }
        }