View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  package org.apache.creadur.tentacles;
18  
19  import java.util.Properties;
20  
21  import org.apache.velocity.app.VelocityEngine;
22  import org.apache.velocity.runtime.log.CommonsLogLogChute;
23  
24  public final class Templates {
25  
26      private final IOSystem ioSystem;
27      private final VelocityEngine engine;
28      private final TentaclesResources tentaclesResources;
29  
30      public Templates(final Platform platform) {
31          this.ioSystem = platform.getIoSystem();
32          this.tentaclesResources = platform.getTentaclesResources();
33          final Properties properties = new Properties();
34          properties.setProperty("file.resource.loader.cache", "true");
35          properties.setProperty("resource.loader", "file, class");
36          properties.setProperty("class.resource.loader.description",
37                  "Velocity Classpath Resource Loader");
38          properties
39                  .setProperty("class.resource.loader.class",
40                          "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
41          properties.setProperty("runtime.log.logsystem.class",
42                  CommonsLogLogChute.class.getName());
43          properties.setProperty("runtime.log.logsystem.commons.logging.name",
44                  Templates.class.getName());
45  
46          this.engine = new VelocityEngine();
47          this.engine.init(properties);
48      }
49  
50      public TemplateBuilder template(final String name) {
51          return new TemplateBuilder(name, this.ioSystem, this.engine,
52                  this.tentaclesResources);
53      }
54  }