Source code: com/dghda/kent/servlet/ReportOutputConfigurator.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.servlet;
21
22 import java.io.*;
23 import javax.servlet.*;
24 import javax.servlet.http.*;
25
26 import org.xml.sax.*;
27
28 import com.dghda.kent.*;
29
30 /**
31 A servlet which runs configures a reports transform and actions.
32 */
33 public class ReportOutputConfigurator extends ReportServlet {
34
35 public void handleReportRequest (Report report, java.util.Properties config, HttpServletRequest request, HttpServletResponse response) throws IOException {
36 com.dghda.kent.transforms.HTMLTransform htmlTransform = new com.dghda.kent.transforms.HTMLTransform (getReportEngine());
37
38 response.setContentType ("text/html");
39 PrintWriter out = response.getWriter();
40 ReportEngine engine = getReportEngine();
41 java.util.List transforms = engine.getAvailableTransforms (request.getRemoteUser());
42
43 // Output header
44 out.println ("<HTML>");
45 out.println ("<HEAD>");
46 out.print ("<TITLE>Configure output for report ");
47 out.println (report.getName());
48 out.println ("</TITLE>");
49
50 out.println ("</HEAD>");
51 out.println ("<BODY>");
52 out.print ("<H1>Configure output for report ");
53 out.println (report.getName());
54 out.println ("</H1>");
55 out.println ("<FORM NAME=\"config\" TYPE=POST ACTION=runReport>");
56
57 // Add hidden inputs for all options passed in
58 java.util.Iterator i = config.entrySet().iterator();
59 while (i.hasNext()) {
60 java.util.Map.Entry entry = (java.util.Map.Entry) i.next();
61 out.print ("<INPUT TYPE=hidden name=");
62 out.print (entry.getKey());
63 out.print (" Value=\"");
64 out.print (cleanHTMLString ((String) entry.getValue()));
65 out.println ("\">");
66 }
67
68 // Transform the configuration options to HTML & print them
69 org.omg.CORBA.IntHolder optionCount = new org.omg.CORBA.IntHolder();
70 try {
71
72 // Find the currently selected transform, if any
73 ReportTransform transform = null;
74 String selectedID = config.getProperty (KentModule.FORMAT_ID);
75 if (selectedID != null)
76 transform = getReportEngine().getTransform (selectedID, request.getRemoteUser());
77 if (transform == null)
78 transform = htmlTransform;
79
80 // Add configuration options for the selected result format
81 String xml = transform.getConfigurationOptions (config);
82 String html = htmlTransform.transformConfigurationOptions (xml, optionCount);
83 if (optionCount.value > 0) {
84 out.print (html);
85 out.println ("<BR><HR>");
86 }
87
88 // Add configuration options for additional actions
89 java.util.List actions = getActions (config, request.getRemoteUser());
90 i = actions.iterator();
91 while (i.hasNext()) {
92 org.omg.CORBA.IntHolder count = new org.omg.CORBA.IntHolder();
93
94 // Get the next action & its config options
95 ReportAction action = (ReportAction) i.next();
96 xml = action.getConfigurationOptions (config);
97 html = htmlTransform.transformConfigurationOptions (xml, count);
98
99 // Add them to the list
100 if (count.value > 0) {
101 out.print (html);
102 out.println ("<BR><HR>");
103 optionCount.value += count.value;
104 }
105 }
106 } catch (ReportTransformException exc) {
107 getServletContext().log ("An error occurred writing configuration options for " + report.getID(), exc);
108 }
109
110 // Check if there were any options at all
111 if (optionCount.value == 0) {
112 out.println ("No further configuration required<BR>");
113 }
114
115 // Write reference to run the report
116 out.println ("<BR><INPUT TYPE=submit Value=\"Run report\">");
117
118 // Output footer
119 out.println ("</FORM>");
120 out.println ("</BODY>");
121 out.println ("</HTML>");
122 }
123 }