Coverage Report - org.apache.tiles.request.freemarker.servlet.WebappClassTemplateLoader
 
Classes in this File Line Coverage Branch Coverage Complexity
WebappClassTemplateLoader
91%
11/12
50%
1/2
1.2
 
 1  
 /*
 2  
  * $Id: WebappClassTemplateLoader.java 1306435 2012-03-28 15:39:11Z nlebas $
 3  
  *
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  * http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 package org.apache.tiles.request.freemarker.servlet;
 23  
 
 24  
 import java.io.IOException;
 25  
 import java.io.Reader;
 26  
 
 27  
 import javax.servlet.ServletContext;
 28  
 
 29  
 import freemarker.cache.ClassTemplateLoader;
 30  
 import freemarker.cache.TemplateLoader;
 31  
 import freemarker.cache.WebappTemplateLoader;
 32  
 
 33  
 /**
 34  
  * Delegates loading templates using a {@link WebappTemplateLoader} and, if not
 35  
  * found, a {@link ClassTemplateLoader}. The resources are loaded from the
 36  
  * webapp root and from the classpath root.
 37  
  *
 38  
  * @version $Rev: 1306435 $ $Date: 2012-03-29 02:39:11 +1100 (Thu, 29 Mar 2012) $
 39  
  */
 40  
 public class WebappClassTemplateLoader implements TemplateLoader {
 41  
 
 42  
     /**
 43  
      * The webapp template loader.
 44  
      */
 45  
     private WebappTemplateLoader webappTemplateLoader;
 46  
 
 47  
     /**
 48  
      * The webapp template loader.
 49  
      */
 50  
     private ClassTemplateLoader classTemplateLoader;
 51  
 
 52  
     /**
 53  
      * Constructor.
 54  
      *
 55  
      * @param servletContext The servlet context.
 56  
      */
 57  5
     public WebappClassTemplateLoader(ServletContext servletContext) {
 58  5
         webappTemplateLoader = new WebappTemplateLoader(servletContext);
 59  5
         classTemplateLoader = new ClassTemplateLoader(getClass(), "/");
 60  5
     }
 61  
 
 62  
     /** {@inheritDoc} */
 63  
     public Object findTemplateSource(String name) throws IOException {
 64  1
         Object retValue = webappTemplateLoader.findTemplateSource(name);
 65  1
         if (retValue == null) {
 66  0
             retValue = classTemplateLoader.findTemplateSource(name);
 67  
         }
 68  1
         return retValue;
 69  
     }
 70  
 
 71  
     /** {@inheritDoc} */
 72  
     public void closeTemplateSource(Object templateSource) throws IOException {
 73  1
         webappTemplateLoader.closeTemplateSource(templateSource);
 74  1
     }
 75  
 
 76  
     /** {@inheritDoc} */
 77  
     public long getLastModified(Object templateSource) {
 78  1
         return webappTemplateLoader.getLastModified(templateSource);
 79  
     }
 80  
 
 81  
     /** {@inheritDoc} */
 82  
     public Reader getReader(Object templateSource, String encoding)
 83  
             throws IOException {
 84  1
         return webappTemplateLoader.getReader(templateSource, encoding);
 85  
     }
 86  
 }