Coverage Report

##### Coverage Report - org.webmacro.URLTemplateLoader

Classes in this File | Line Coverage | Branch Coverage | Complexity
URLTemplateLoader |
0% | 0/12
N/A | N/A
| 3.0;3

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;
24 |  |
25 |  |
     import java.net.MalformedURLException;
26 |  |
     import java.net.URL;
27 |  |
28 |  |
     import org.slf4j.Logger;
29 |  |
     import org.slf4j.LoggerFactory;
30 |  |
     import org.webmacro.resource.AbstractTemplateLoader;
31 |  |
     import org.webmacro.resource.CacheElement;
32 |  |
33 |  |
     /**
34 |  |
      * Implementation of TemplateLoader that loads templates from a given URL.
35 |  |
      * Objects of this class are responsible for searching exactly one
36 |  |
      * directory for templates. If it handles a request, it takes URL as
37 |  |
      * the base path to find the template.
38 |  |
      * @author Marc Palmer (marc@anyware.co.uk)
39 |  |
      */
40 | 0 |
     public class URLTemplateLoader extends AbstractTemplateLoader
41 |  |
     {
42 |  |
43 | 0 |
         static Logger _log =  LoggerFactory.getLogger(URLTemplateLoader.class);
44 |  |
         private URL baseURI;
45 |  |
46 |  |
         public void setConfig (String config)
47 |  |
         {
48 |  |
             try
49 |  |
             {
50 | 0 |
                 this.baseURI = new URL(config);
51 |  |
             }
52 | 0 |
             catch (MalformedURLException e)
53 |  |
             {
54 | 0 |
                 _log.error("Cannot init url template loader, bad URL", e);
55 | 0 |
             }
56 | 0 |
         }
57 |  |
58 |  |
         /**
59 |  |
          * Tries to load a template by interpreting query as
60 |  |
          * a path relative to the path set by setPath.
61 |  |
          */
62 |  |
         public final Template load (String query, CacheElement ce) throws ResourceException
63 |  |
         {
64 |  |
             try
65 |  |
             {
66 | 0 |
                 URL url = new URL(baseURI, query);
67 | 0 |
                 _log.debug("FileTemplateProvider: Found template " + url);
68 | 0 |
                 return helper.load(url, ce);
69 |  |
             }
70 | 0 |
             catch (MalformedURLException e)
71 |  |
             {
72 | 0 |
                 throw new ResourceException("Bad template URL", e);
73 |  |
             }
74 |  |
         }
75 |  |
     }