View Javadoc
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 java.io.InputStream;
20  
21  import org.apache.velocity.runtime.resource.Resource;
22  import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
23  import org.apache.velocity.runtime.resource.loader.ResourceLoader;
24  import org.apache.velocity.exception.ResourceNotFoundException;
25  
26  import org.apache.commons.collections.ExtendedProperties;
27  
28  /**
29   *
30   * @deprecated use {@link ClasspathResourceLoader}
31   *
32   */
33  @Deprecated
34  public class ContextClassLoaderResourceLoader
35      extends ResourceLoader
36  {
37      public void init( ExtendedProperties configuration)
38      {
39      }
40  
41      public synchronized InputStream getResourceStream( String name )
42          throws ResourceNotFoundException
43      {
44          InputStream result = null;
45  
46          if (name == null || name.length() == 0)
47          {
48              throw new ResourceNotFoundException ("No template name provided");
49          }
50  
51          try
52          {
53              ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
54  
55              if ( name.startsWith( "/" ) )
56              {
57                  name = name.substring( 1 );
58              }
59  
60              result = classLoader.getResourceAsStream( name );
61          }
62          catch( Exception fnfe )
63          {
64              throw new ResourceNotFoundException( fnfe.getMessage() );
65          }
66  
67          return result;
68      }
69  
70      public boolean isSourceModified(Resource resource)
71      {
72          return false;
73      }
74  
75      public long getLastModified(Resource resource)
76      {
77          return 0;
78      }
79  }
80