Coverage Report - org.webmacro.resource.TemplatePathTemplateLoader
 
Classes in this File Line Coverage Branch Coverage Complexity
TemplatePathTemplateLoader
0%
0/20
0%
0/10
4
 
 1  
 /*
 2  
  * Copyright (C) 1998-2000 Semiotek Inc.  All Rights Reserved.
 3  
  *
 4  
  * Redistribution and use in source and binary forms, with or without
 5  
  * modification, are permitted under the terms of either of the following
 6  
  * Open Source licenses:
 7  
  *
 8  
  * The GNU General Public License, version 2, or any later version, as
 9  
  * published by the Free Software Foundation
 10  
  * (http://www.fsf.org/copyleft/gpl.html);
 11  
  *
 12  
  *  or
 13  
  *
 14  
  * The Semiotek Public License (http://webmacro.org/LICENSE.)
 15  
  *
 16  
  * This software is provided "as is", with NO WARRANTY, not even the
 17  
  * implied warranties of fitness to purpose, or merchantability. You
 18  
  * assume all risks and liabilities associated with its use.
 19  
  *
 20  
  * See www.webmacro.org for more information on the WebMacro project.
 21  
  */
 22  
 
 23  
 package org.webmacro.resource;
 24  
 
 25  
 import org.slf4j.Logger;
 26  
 import org.slf4j.LoggerFactory;
 27  
 import org.webmacro.InitException;
 28  
 import org.webmacro.ResourceException;
 29  
 import org.webmacro.Template;
 30  
 import org.webmacro.util.Settings;
 31  
 
 32  
 import java.io.File;
 33  
 import java.util.StringTokenizer;
 34  
 
 35  
 /**
 36  
  * Implementation of TemplateLoader that loads templates from a list of
 37  
  * paths specified in the TemplatePath setting. This template loader
 38  
  * is for compatability with old WebMacro.properties configurations, that
 39  
  * still use a TemplatePath setting.
 40  
  * @author Sebastian Kanthak (sebastian.kanthak@muehlheim.de)
 41  
  */
 42  0
 public class TemplatePathTemplateLoader extends AbstractTemplateLoader
 43  
 {
 44  
 
 45  0
     static Logger _log =  LoggerFactory.getLogger(TemplatePathTemplateLoader.class);
 46  
     
 47  
     private TemplateLoader[] loaders;
 48  
 
 49  
     public void setConfig (String config) throws InitException
 50  
     {
 51  
         // ignore parameter
 52  0
         Settings settings = broker.getSettings();
 53  0
         String templatePath = settings.getSetting("TemplatePath", "");
 54  0
         _log.info("Using legacy template path " + templatePath);
 55  0
         if (templatePath.length() != 0)
 56  
         {
 57  0
             StringTokenizer st = new StringTokenizer(templatePath, File.pathSeparator);
 58  0
             loaders = new TemplateLoader[st.countTokens()];
 59  0
             for (int i = 0; i < loaders.length; i++)
 60  
             {
 61  0
                 TemplateLoader loader = new FileTemplateLoader();
 62  0
                 loader.init(broker, settings);
 63  0
                 loader.setConfig(st.nextToken());
 64  0
                 loaders[i] = loader;
 65  
             }
 66  
         }
 67  0
     }
 68  
 
 69  
     public final Template load (String query, CacheElement ce) throws ResourceException
 70  
     {
 71  0
         if (loaders != null)
 72  
         {
 73  0
             for (int i = 0; i < loaders.length; i++)
 74  
             {
 75  0
                 Template t = loaders[i].load(query, ce);
 76  0
                 if (t != null)
 77  0
                     return t;
 78  
             }
 79  
         }
 80  0
         return null;
 81  
     }
 82  
 
 83  
 }