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

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


    public void initialize()
        throws Exception
    {
        rsvc.info("Resource manager initializing.");

        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


               
                //! 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
                              */

                             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 + "'");
                }                       

                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

     @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

     * 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

     * 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++)
        {
            ExtendedProperties configuration = (ExtendedProperties) sourceInitializerList.get(i);
            String loaderClass = configuration.getString("class");

            if ( loaderClass == null)
            {
                Runtime.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(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
                              */

                             if ( logWhenFound )
                             {
                                 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

     @param resourceName Name of template or content resource
     *  @return class name of loader than can provide it
     */
    public static 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

        {
            log.debug("Re-initialization of ResourceLoader attempted and ignored.");
            return;
        }

        ResourceLoader resourceLoader = null;

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

        log.trace("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"));
           

      //loaderClass=org.apache.velocity.runtime.resource.loader.FileResourceLoader
      //loaderInstance=null
      DEBUG.P("loaderClass="+loaderClass);

      //这个可以通过程序的方式设置一个以"instance"为key的ResourceLoader实现类
      ResourceLoader loaderInstance = (ResourceLoader) configuration.get("instance");

      DEBUG.P("loaderInstance="+loaderInstance);
            if (loaderInstance != null)
            {
                resourceLoader = loaderInstance;
View Full Code Here

    DEBUG.P("resourceLoaders="+resourceLoaders);

        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

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.