1
|
<%@page
|
2
|
import="java.sql.ResultSet"%><%@page
|
3
|
import="edu.ucsb.nceas.first.metacat.client.AssessmentQuery"%><%@page
|
4
|
import="au.com.bytecode.opencsv.CSVWriter"%><%@page
|
5
|
import="java.util.*"%><%@page
|
6
|
import="java.io.*"%><%
|
7
|
|
8
|
String[] docids = request.getParameterValues("docids");
|
9
|
String qformat = request.getParameter("qformat");
|
10
|
|
11
|
if (docids != null && docids.length > 0) {
|
12
|
|
13
|
List assessmentDocIds = Arrays.asList(docids);
|
14
|
|
15
|
//make a title
|
16
|
String tableTitle = "Showing data for ";
|
17
|
String fileName = "results-";
|
18
|
for (int i=0; i<docids.length; i++) {
|
19
|
tableTitle += docids[i];
|
20
|
tableTitle +=", ";
|
21
|
|
22
|
fileName += docids[i];
|
23
|
}
|
24
|
tableTitle = tableTitle.substring(0, tableTitle.length()-2);
|
25
|
fileName += ".csv";
|
26
|
|
27
|
//AssessmentQuery.testEcogrid("edml.4.5");
|
28
|
ResultSet rs = AssessmentQuery.selectResponseData(assessmentDocIds);
|
29
|
|
30
|
//get the results as csv file
|
31
|
if (qformat != null && qformat.equalsIgnoreCase("csv")) {
|
32
|
response.setContentType("text/csv");
|
33
|
//response.setContentType("application/csv");
|
34
|
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
|
35
|
|
36
|
Writer writer = new OutputStreamWriter(response.getOutputStream());
|
37
|
CSVWriter csv = new CSVWriter(writer, CSVWriter.DEFAULT_SEPARATOR, CSVWriter.NO_QUOTE_CHARACTER);
|
38
|
csv.writeAll(rs, true);
|
39
|
|
40
|
response.flushBuffer();
|
41
|
|
42
|
rs.close();
|
43
|
return;
|
44
|
}
|
45
|
|
46
|
int numColumns = rs.getMetaData().getColumnCount();
|
47
|
%>
|
48
|
|
49
|
<!-- <h3><%=tableTitle %></h3> -->
|
50
|
|
51
|
<table>
|
52
|
<!--
|
53
|
<tr>
|
54
|
<th colspan="<%=numColumns %>"><%=tableTitle %></th>
|
55
|
</tr>
|
56
|
-->
|
57
|
<tr>
|
58
|
<% for (int i=1; i<=numColumns; i++) { %>
|
59
|
<th><%=rs.getMetaData().getColumnName(i) %></th>
|
60
|
<% } %>
|
61
|
</tr>
|
62
|
<%
|
63
|
while (rs.next()) {
|
64
|
//System.out.println("rs:" + rs.getInt(1));
|
65
|
%>
|
66
|
<tr>
|
67
|
<% for (int i=1; i<=numColumns; i++) { %>
|
68
|
<td><%=rs.getInt(i) %></td>
|
69
|
<% } %>
|
70
|
</tr>
|
71
|
<%
|
72
|
}
|
73
|
%>
|
74
|
</table>
|
75
|
<%
|
76
|
//clean up
|
77
|
if (rs != null) {
|
78
|
rs.close();
|
79
|
}
|
80
|
}//end if docids
|
81
|
else {
|
82
|
%>
|
83
|
No items selected
|
84
|
<%}%>
|