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

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


     * 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


               
                //! Bug this is being run more then once!
               
                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
                              */
                             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 )
View Full Code Here

  {
      log.warn("Re-initialization of ResourceLoader attempted!");
      return;
  }
 
        ResourceLoader resourceLoader = null;

        this.rsvc = rsvc;
        log = rsvc.getLog();

        log.debug("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();
            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 && log.isDebugEnabled())
                    {
                        log.debug("ResourceManager : found " + resourceName +
                                  " with loader " +
                                  resourceLoader.getClassName());
                    }

                    howOldItWas = resourceLoader.getLastModified(resource);

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

        /*
         *  loop through our loaders...
         */
        for (Iterator it = resourceLoaders.iterator(); it.hasNext(); )
        {
            ResourceLoader resourceLoader = (ResourceLoader) it.next();

            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 rnfe)
            {
                /*
 
View Full Code Here

    public void setUp()
            throws Exception
    {

        ResourceLoader rl = new FileResourceLoader();

        // pass in an instance to Velocity
        Velocity.addProperty( "resource.loader", "testrl" );
        Velocity.setProperty( "testrl.resource.loader.instance", rl );
        Velocity.setProperty( "testrl.resource.loader.path", FILE_RESOURCE_LOADER_PATH );
View Full Code Here

        rsvc = rs;
        log = rsvc.getLog();
       
        log.debug("Default ResourceManager initializing. (" + this.getClass() + ")");

        ResourceLoader resourceLoader;
       
        assembleResourceLoaderInitializers();
       
        for (int i = 0; i < sourceInitializerList.size(); i++)
        {
            /**
             * Resource loader can be loaded either via class name or be passed
             * in as an instance.
             */
            ExtendedProperties configuration =
                (ExtendedProperties) sourceInitializerList.get(i);
            String loaderClass = StringUtils.nullTrim(configuration.getString("class"));
            ResourceLoader loaderInstance =
                (ResourceLoader) configuration.get("instance");

            if ( (loaderClass == null) && (loaderInstance == null) )
            {
                log.error("Unable to find '"
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 && log.isDebugEnabled())
                     {
                         log.debug("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

    {
        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

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.