public virtual Resource put(System.Object key, Resource value_Renamed) { Object o = cache[key]; cache[key] = value_Renamed; return (Resource) o; }
public Resource put(Object key, Resource value) { Object o = cache[key]; cache[key] = value; return (Resource) o; }
/// <summary> 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. /// * /// </summary> /// <param name="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 /// /// </param> protected internal virtual void refreshResource(Resource resource, System.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)) { rsvc.error("Declared encoding for template '" + resource.Name + "' is different on reload. Old = '" + resource.Encoding + "' New = '" + 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; } } }
public override long GetLastModified(Resource resource) { return resource.LastModified; }
private void InitializeResource(Resource resource, string resourceName, string encoding) { resource.RuntimeServices = runtimeServices; resource.Name = resourceName; resource.Encoding = encoding; }
public override bool IsSourceModified(Resource resource) { return false; }
/* (non-Javadoc) * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#getLastModified(org.apache.velocity.runtime.resource.Resource) */ public override long getLastModified(Resource resource) { return (DateTime.Now.Ticks - 621355968000000000) / 10000; }
/// <summary> /// Loads a resource from the current set of resource loaders /// </summary> /// <param name="resourceName">The name of the resource to retrieve.</param> /// <param name="resourceType">The type of resource (<code>RESOURCE_TEMPLATE</code>, /// <code>RESOURCE_CONTENT</code>, etc.). /// </param> /// <param name="encoding"> The character encoding to use.</param> /// <returns>Resource with the template parsed and ready. /// @throws ResourceNotFoundException if template not found /// from any available source. /// @throws ParseErrorException if template cannot be parsed due /// to syntax (or other) error. /// @throws Exception if a problem in parse /// </returns> protected internal virtual Resource loadResource(System.String resourceName, int resourceType, System.String encoding) { Resource resource = ResourceFactory.getResource(resourceName, resourceType); resource.RuntimeServices = rsvc; 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) { rsvc.info("ResourceManager : found " + resourceName + " with loader " + resourceLoader.ClassName); } howOldItWas = resourceLoader.getLastModified(resource); break; } } catch (ResourceNotFoundException rnfe) { /* * 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("Unable to find resource '" + resourceName + "'"); } /* * some final cleanup */ resource.LastModified = howOldItWas; resource.ModificationCheckInterval = resourceLoader.ModificationCheckInterval; resource.Touch(); return(resource); }
/// <summary> Gets the named resource. Returned class type corresponds to specified type /// (i.e. <code>Template</code> to <code>RESOURCE_TEMPLATE</code>). /// * /// </summary> /// <param name="resourceName">The name of the resource to retrieve. /// </param> /// <param name="resourceType">The type of resource (<code>RESOURCE_TEMPLATE</code>, /// <code>RESOURCE_CONTENT</code>, etc.). /// </param> /// <param name="encoding"> The character encoding to use. /// </param> /// <returns>Resource with the template parsed and ready. /// @throws ResourceNotFoundException if template not found /// from any available source. /// @throws ParseErrorException if template cannot be parsed due /// to syntax (or other) error. /// @throws Exception if a problem in parse /// /// </returns> public virtual Resource getResource(System.String resourceName, int resourceType, System.String encoding) { /* * Check to see if the resource was placed in the cache. * If it was placed in the cache then we will use * the cached version of the resource. If not we * will load it. */ Resource resource = globalCache.get(resourceName); if (resource != null) { /* * refresh the resource */ try { refreshResource(resource, encoding); } catch (ResourceNotFoundException rnfe) { /* * something exceptional happened to that resource * this could be on purpose, * so clear the cache and try again */ globalCache.remove(resourceName); return(getResource(resourceName, resourceType, encoding)); } catch (ParseErrorException pee) { rsvc.error("ResourceManager.getResource() exception: " + pee); throw pee; } catch (System.Exception eee) { rsvc.error("ResourceManager.getResource() exception: " + eee); throw eee; } } else { try { /* * it's not in the cache, so load it. */ resource = loadResource(resourceName, resourceType, encoding); if (resource.ResourceLoader.isCachingOn()) { globalCache.put(resourceName, resource); } } catch (ResourceNotFoundException rnfe2) { rsvc.error("ResourceManager : unable to find resource '" + resourceName + "' in any resource loader."); throw rnfe2; } catch (ParseErrorException pee) { rsvc.error("ResourceManager.getResource() parse exception: " + pee); throw pee; } catch (System.Exception ee) { rsvc.error("ResourceManager.getResource() exception new: " + ee); throw ee; } } return(resource); }
private void ProcessResourceWithSensibleExceptionWrapping(string resourceName, Resource resource) { try { resource.Process(); } catch(Exception e) { throw new ResourceProcessingException(resourceName, e); } }