KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > driver > velocity > Driver


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package scriptella.driver.velocity;
17
18 import org.apache.velocity.runtime.RuntimeServices;
19 import org.apache.velocity.runtime.log.LogSystem;
20 import scriptella.spi.AbstractScriptellaDriver;
21 import scriptella.spi.Connection;
22 import scriptella.spi.ConnectionParameters;
23 import scriptella.spi.DialectIdentifier;
24
25 import java.util.logging.Level JavaDoc;
26 import java.util.logging.Logger JavaDoc;
27
28 /**
29  * Scriptella Driver for <a HREF="http://jakarta.apache.org/velocity">Velocity</a> template engine.
30  *
31  * @author Fyodor Kupolov
32  * @version 1.0
33  */

34 public class Driver extends AbstractScriptellaDriver {
35     static final DialectIdentifier DIALECT = new DialectIdentifier("Velocity", "1.4");
36     private static final Logger JavaDoc LOG = Logger.getLogger(Driver.class.getName());
37     static final LogSystem LOG_SYSTEM = new LogSystem() {
38         public void init(RuntimeServices rs) {
39         }
40
41         public void logVelocityMessage(int level, String JavaDoc message) {
42             if (level < 0) {
43                 return;
44             }
45             Level JavaDoc lev; //converting velocity level to JUL
46
switch (level) {
47                 case DEBUG_ID:
48                     lev = Level.FINE;
49                     break;
50                 case INFO_ID: //Velocity INFO is too verbose
51
lev = Level.CONFIG;
52                     break;
53                 case WARN_ID:
54                     lev = Level.INFO;
55                     break;
56                 case ERROR_ID:
57                     lev = Level.WARNING;
58                     break;
59                 default:
60                     lev = Level.INFO;
61             }
62             if (LOG.isLoggable(lev)) {
63                 LOG.log(lev, "Engine: " + message);
64             }
65         }
66     };
67
68     /**
69      * Implementor should create a new connection based on specified parameters.
70      *
71      * @param connectionParameters connection parameters defined in &lt;connection&gt; element.
72      * @return new connection.
73      */

74     public Connection connect(ConnectionParameters connectionParameters) {
75         return new VelocityConnection(connectionParameters);
76     }
77
78
79 }
80
Popular Tags