Coverage Report - org.codehaus.plexus.velocity.SiteResourceLoader
 
Classes in this File Line Coverage Branch Coverage Complexity
SiteResourceLoader
0 %
0/15
0 %
0/4
2,2
 
 1  
 package org.codehaus.plexus.velocity;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2016 Codehaus Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *      http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import org.apache.commons.collections.ExtendedProperties;
 20  
 import org.apache.velocity.runtime.resource.loader.FileResourceLoader;
 21  
 import org.apache.velocity.runtime.resource.loader.ResourceLoader;
 22  
 import org.apache.velocity.exception.ResourceNotFoundException;
 23  
 
 24  
 import java.io.InputStream;
 25  
 import java.io.File;
 26  
 import java.io.FileInputStream;
 27  
 import java.io.FileNotFoundException;
 28  
 
 29  
 /**
 30  
  * Allows you to dynamically add resources that you want to be processed by Velocity. For
 31  
  * example if you want to generate a site and pull in some random files to be interpolated
 32  
  * by Velocity you can use this resource loader.
 33  
  *
 34  
  * @author Jason van Zyl
 35  
  * @deprecated use {@link FileResourceLoader}
 36  
  */
 37  
 @Deprecated
 38  0
 public class SiteResourceLoader
 39  
     extends ResourceLoader
 40  
 {
 41  
     private static String resource;
 42  
 
 43  
     private static File resourceDir;
 44  
 
 45  
     public static void setResource( String staticResource )
 46  
     {
 47  0
         resource = staticResource;
 48  0
         resourceDir = new File( resource ).getParentFile();
 49  0
     }
 50  
 
 51  
     public void init( ExtendedProperties p )
 52  
     {
 53  0
     }
 54  
 
 55  
     public InputStream getResourceStream( String name )
 56  
         throws ResourceNotFoundException
 57  
     {
 58  0
         if ( resource != null )
 59  
         {
 60  
             try
 61  
             {
 62  0
                 File f = new File( resourceDir, name );
 63  0
                 if ( f.exists() )
 64  
                 {
 65  0
                     return new FileInputStream( f );
 66  
                 }
 67  
                 else
 68  
                 {
 69  0
                     return new FileInputStream( resource );
 70  
                 }
 71  
             }
 72  0
             catch ( FileNotFoundException e )
 73  
             {
 74  0
                 throw new ResourceNotFoundException( "Cannot find resource, make sure you set the right resource." );
 75  
             }
 76  
         }
 77  
 
 78  0
         return null;
 79  
     }
 80  
 
 81  
     public boolean isSourceModified( org.apache.velocity.runtime.resource.Resource resource )
 82  
     {
 83  0
         return false;  //To change body of implemented methods use File | Settings | File Templates.
 84  
     }
 85  
 
 86  
     public long getLastModified( org.apache.velocity.runtime.resource.Resource resource )
 87  
     {
 88  0
         return 0;
 89  
     }
 90  
 }
 91