View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
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 org.saxbenchmark;
17  
18  import java.io.Writer;
19  
20  import org.apache.velocity.VelocityContext;
21  import org.apache.velocity.app.VelocityEngine;
22  import org.apache.velocity.context.Context;
23  
24  /***
25   * @author JMcCrindle
26   */
27  public class VelocityResultsWriter {
28     
29      private VelocityEngine velocityEngine = null;
30      private String templateFile;
31      private String sourceDir;
32      private String outputDir;
33      
34      public void writeResults(BenchmarkResults results, Writer writer) throws Exception {
35          Context velocityContext = new VelocityContext();
36          velocityContext.put("sourceDir", sourceDir);
37          velocityContext.put("outputDir", outputDir);
38          velocityContext.put("results", results);
39          velocityContext.put("properties", System.getProperties());
40          velocityEngine.mergeTemplate(templateFile, velocityContext, writer);
41          writer.flush();
42      }
43      public String getTemplateFile() {
44          return templateFile;
45      }
46      public void setTemplateFile(String templateFile) {
47          this.templateFile = templateFile;
48      }
49      public VelocityEngine getVelocityEngine() {
50          return velocityEngine;
51      }
52      public void setVelocityEngine(VelocityEngine velocityEngine) {
53          this.velocityEngine = velocityEngine;
54      }
55      public String getOutputDir() {
56          return outputDir;
57      }
58      public void setOutputDir(String outputDir) {
59          this.outputDir = outputDir;
60      }
61      public String getSourceDir() {
62          return sourceDir;
63      }
64      public void setSourceDir(String sourceDir) {
65          this.sourceDir = sourceDir;
66      }
67  }