Source code: com/dghda/kent/reports/FixedTemplateReport.java
1 /* Copyright (C) 2001 Duane Griffin <duanegriffin@users.sourceforge.net>
2 This file is part of Kent.
3
4 Kent is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 Kent is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with Kent; see the file COPYING. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18 */
19
20 package com.dghda.kent.reports;
21
22 import java.io.*;
23
24 import com.dghda.kent.*;
25 import com.dghda.module.*;
26
27 /**
28 A base class to simplify writing reports which use load a template.
29 */
30 public abstract class FixedTemplateReport extends BaseKentModule implements Report {
31
32 /**
33 Creates a new report object loaded by the given report engine.
34 @param id The unique ID of the module.
35 @param shortName The name of the module.
36 @param description A description of the module.
37 @param version The module's version information.
38 @param engine The report engine the module runs under.
39 @param input The stream to load the report template from.
40 */
41 public FixedTemplateReport (String id, String shortName, String description,
42 Module.ModuleVersion version, ReportEngine engine,
43 InputStream input) throws IOException {
44 super (id, shortName, description, version, engine);
45 load (input);
46 }
47
48 /**
49 Returns the loaded report template.
50 @see com.dghda.kent.ReportTemplate ReportTemplate
51 @param config The configuration to use when running the report.
52 @returns An XML document containing the results of the report.
53 */
54 public String getReportTemplate (java.util.Properties config) {
55 return m_Template;
56 }
57
58 /** Copies the contents of the given stream into a string. */
59 protected void load (InputStream input) throws IOException {
60 BufferedReader reader = new BufferedReader (new InputStreamReader (input));
61 StringWriter writer = new StringWriter();
62 for (int ch = reader.read(); ch != -1; ch = reader.read())
63 writer.write (ch);
64 writer.flush();
65 m_Template = writer.toString();
66 }
67
68 private String m_Template;
69 }