Package org.apache.velocity.runtime.resource.loader

Examples of org.apache.velocity.runtime.resource.loader.ResourceLoader


        resource.touch();

        /* check whether this can now be found in a higher priority
         * resource loader.  if so, pass the request off to loadResource.
         */
        ResourceLoader loader = resource.getResourceLoader();
        if (resourceLoaders.size() > 0 && resourceLoaders.indexOf(loader) > 0)
        {
            String name = resource.getName();
            if (loader != getLoaderForResource(name))
            {
                return loadResource(name, resource.getType(), encoding);
            }
        }

        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 (!org.apache.commons.lang.StringUtils.equals(resource.getEncoding(), encoding))
            {
                log.warn("Declared encoding for template '" +
                             resource.getName() +
                             "' is different on reload. Old = '" +
                             resource.getEncoding() + "' New = '" + encoding);

                resource.setEncoding(encoding);
            }

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

            String resourceKey = resource.getType() + resource.getName();

            /*
             * we create a copy to avoid partially overwriting a
             * template which may be in use in another thread
             */

            Resource newResource =
                ResourceFactory.getResource(resource.getName(), resource.getType());

            newResource.setRuntimeServices(rsvc);
            newResource.setName(resource.getName());
            newResource.setEncoding(resource.getEncoding());
            newResource.setResourceLoader(loader);
            newResource.setModificationCheckInterval(loader.getModificationCheckInterval());

            newResource.process();
            newResource.setLastModified(howOldItWas);
            resource = newResource;

View Full Code Here


     *
     * @return  class name of loader than can provide it
     */
    public String getLoaderNameForResource(String resourceName)
    {
        ResourceLoader loader = getLoaderForResource(resourceName);
        if (loader == null)
        {
            return null;
        }
        return loader.getClass().toString();
    }
View Full Code Here

     */
    private ResourceLoader getLoaderForResource(String resourceName)
    {
        for (Iterator i = resourceLoaders.iterator(); i.hasNext(); )
        {
            ResourceLoader loader = (ResourceLoader)i.next();
            if (loader.resourceExists(resourceName))
            {
                return loader;
            }
        }
        return null;
View Full Code Here

     * that assembleSourceInitializers() has been
     * called before this is run.
     */
    public static void initialize() throws Exception
    {
        ResourceLoader resourceLoader;
       
        assembleResourceLoaderInitializers();
       
        for (int i = 0; i < sourceInitializerList.size(); i++)
        {
            Configuration configuration = (Configuration) sourceInitializerList.get(i);
            String loaderClass = configuration.getString("class");

            resourceLoader = ResourceLoaderFactory.getLoader(loaderClass);
            resourceLoader.commonInit(configuration);
            resourceLoader.init(configuration);
            resourceLoaders.add(resourceLoader);

        }
    }
View Full Code Here

     */
    public static Resource getResource(String resourceName, int resourceType)
        throws ResourceNotFoundException, ParseErrorException, Exception
    {
        Resource resource = null;
        ResourceLoader resourceLoader = null;
       
        /*
         * 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.
         */
       
        if (globalCache.containsKey(resourceName))
        {
            resource = (Resource) globalCache.get(resourceName);

            /*
             * 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();

                ifresource.isSourceModified() )
                {
                    try
                    {
                        /*
                         *  read how old the resource is _before_
                         *  processing (=>reading) it
                         */
                        long howOldItWas = resourceLoader.getLastModified( resource );

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

                        resource.process();

                        /*
                         *  now set the modification info and reset
                         *  the modification check counters
                         */
                       
                        resource.setLastModified( howOldItWas );
                    }
                    catch( ResourceNotFoundException rnfe )
                    {
                        Runtime.error("ResourceManager.getResource() exception: " + rnfe);
                        throw rnfe;
                    }
                    catch( ParseErrorException pee )
                    {
                        Runtime.error("ResourceManager.getResource() exception: " + pee);
                        throw pee;
                    }
                    catch( Exception eee )
                    {
                        Runtime.error("ResourceManager.getResource() exception: " + eee);
                        throw eee;
                    }
                }
            }

            return resource;
        }
        else
        {
            /*
             *  it's not in the cache
             */

            try
            {
                resource = ResourceFactory.getResource(resourceName, resourceType);
                resource.setName(resourceName);
               
                /*
                 * 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.
                 */
               
                //! Bug this is being run more then once!
               
                long howOldItWas = 0// Initialize to avoid warnings

                for (int i = 0; i < resourceLoaders.size(); i++)
                {
                    resourceLoader = (ResourceLoader) resourceLoaders.get(i);
                    resource.setResourceLoader(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
                              */
                             Runtime.info("ResourceManager : found " + resourceName +
                                          " with loader " + resourceLoader.getClassName());
          
                             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.getData() == null)
                    throw new ResourceNotFoundException("Unable to find resource '" + resourceName + "'");

                resource.setLastModified( howOldItWas );
                
                resource.setModificationCheckInterval(
                    resourceLoader.getModificationCheckInterval());
               
                resource.touch();
               
                /*
                 * Place the resource in the cache if the resource
                 * loader says to.
                 */
               
                if (resourceLoader.isCachingOn())
                    globalCache.put(resourceName, resource);
            }
            catch( ResourceNotFoundException rnfe2 )
            {
                Runtime.error("ResourceManager : unable to find resource '" + resourceName + "' in any resource loader.");
View Full Code Here

    {
        rsvc = rs;
       
        rsvc.info("Default ResourceManager initializing. (" + this.getClass() + ")");

        ResourceLoader resourceLoader;
       
        assembleResourceLoaderInitializers();
       
        for (int i = 0; i < sourceInitializerList.size(); i++)
        {
            ExtendedProperties configuration = (ExtendedProperties) sourceInitializerList.get(i);
            String loaderClass = configuration.getString("class");

            if ( loaderClass == null)
            {
                rsvc.error"Unable to find '"
                                + configuration.getString(RESOURCE_LOADER_IDENTIFIER)
                                + ".resource.loader.class' specification in configuation."
                                + " This is a critical value.  Please adjust configuration.");
                continue;
            }

            resourceLoader = ResourceLoaderFactory.getLoader( rsvc, loaderClass);
            resourceLoader.commonInit( rsvc, configuration);
            resourceLoader.init(configuration);
            resourceLoaders.add(resourceLoader);

        }

        /*
 
View Full Code Here

         * make a resource with.
         */

        long howOldItWas = 0// Initialize to avoid warnings

        ResourceLoader resourceLoader = null;

        for (int i = 0; i < resourceLoaders.size(); i++)
        {
            resourceLoader = (ResourceLoader) resourceLoaders.get(i);
            resource.setResourceLoader(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.getClassName() );
                     }
  
                     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.getData() == null)
        {
            throw new ResourceNotFoundException(
                "Unable to find resource '" + resourceName + "'");
        }

        /*
         *  some final cleanup
         */
        
        resource.setLastModified( howOldItWas );
        
        resource.setModificationCheckInterval(
            resourceLoader.getModificationCheckInterval());
       
        resource.touch();
   
        return resource;           
    }
View Full Code Here

     @param resourceName Name of template or content resource
     *  @return class name of loader than can provide it
     */
    public String getLoaderNameForResource(String resourceName )
    {
        ResourceLoader resourceLoader = null;
      
        /*
         *  loop through our loaders...
         */
        for (int i = 0; i < resourceLoaders.size(); i++)
        {
            resourceLoader = (ResourceLoader) resourceLoaders.get(i);

            InputStream is = null;

            /*
             *  if we find one that can provide the resource,
             *  return the name of the loaders's Class
             */
            try
            {
                is=resourceLoader.getResourceStream( resourceName );
              
                if( is != null)
                {
                    return resourceLoader.getClass().toString();
                }
            }
            catch( ResourceNotFoundException e)
            {
                /*
 
View Full Code Here

        {
            Logger.debug(this,"Re-initialization of ResourceLoader attempted and ignored.");
            return;
        }
 
        ResourceLoader resourceLoader = null;

        this.rsvc = rsvc;
       
        Logger.debug(this,"Default ResourceManager initializing. (" + this.getClass() + ")");

        assembleResourceLoaderInitializers();

        for (Iterator it = sourceInitializerList.iterator(); it.hasNext();)
        {
            /**
             * Resource loader can be loaded either via class name or be passed
             * in as an instance.
             */
            ExtendedProperties configuration = (ExtendedProperties) it.next();

            String loaderClass = StringUtils.nullTrim(configuration.getString("class"));
            ResourceLoader loaderInstance = (ResourceLoader) configuration.get("instance");

            if (loaderInstance != null)
            {
                resourceLoader = loaderInstance;
            }
View Full Code Here

        long howOldItWas = 0;

        for (Iterator it = resourceLoaders.iterator(); it.hasNext();)
        {
            ResourceLoader resourceLoader = (ResourceLoader) it.next();

            /*
             *  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 && Logger.isDebugEnabled(this.getClass()))
                    {
                        Logger.debug(this,"ResourceManager : found " + resourceName +
                                  " with loader " +
                                  resourceLoader.getClassName());
                    }

                    howOldItWas = resourceLoader.getLastModified(resource);

                    break;
                }
            }
            catch (ResourceNotFoundException rnfe)
View Full Code Here

TOP

Related Classes of org.apache.velocity.runtime.resource.loader.ResourceLoader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.