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
|
if (rs == null) {
|
31
|
return;
|
32
|
}
|
33
|
|
34
|
//get the results as csv file
|
35
|
if (qformat != null && qformat.equalsIgnoreCase("csv")) {
|
36
|
response.setContentType("text/csv");
|
37
|
//response.setContentType("application/csv");
|
38
|
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
|
39
|
|
40
|
Writer writer = new OutputStreamWriter(response.getOutputStream());
|
41
|
CSVWriter csv = new CSVWriter(writer, CSVWriter.DEFAULT_SEPARATOR, CSVWriter.NO_QUOTE_CHARACTER);
|
42
|
csv.writeAll(rs, true);
|
43
|
|
44
|
response.flushBuffer();
|
45
|
|
46
|
rs.close();
|
47
|
return;
|
48
|
}
|
49
|
|
50
|
int numColumns = rs.getMetaData().getColumnCount();
|
51
|
%>
|
52
|
|
53
|
<!-- <h3><%=tableTitle %></h3> -->
|
54
|
|
55
|
<table>
|
56
|
<!--
|
57
|
<tr>
|
58
|
<th colspan="<%=numColumns %>"><%=tableTitle %></th>
|
59
|
</tr>
|
60
|
-->
|
61
|
<tr>
|
62
|
<% for (int i=1; i<=numColumns; i++) { %>
|
63
|
<th><%=rs.getMetaData().getColumnName(i) %></th>
|
64
|
<% } %>
|
65
|
</tr>
|
66
|
<%
|
67
|
while (rs.next()) {
|
68
|
//System.out.println("rs:" + rs.getInt(1));
|
69
|
%>
|
70
|
<tr>
|
71
|
<% for (int i=1; i<=numColumns; i++) { %>
|
72
|
<td><%=rs.getString(i) %></td>
|
73
|
<% } %>
|
74
|
</tr>
|
75
|
<%
|
76
|
}
|
77
|
%>
|
78
|
</table>
|
79
|
<%
|
80
|
//clean up
|
81
|
if (rs != null) {
|
82
|
rs.close();
|
83
|
}
|
84
|
}//end if docids
|
85
|
else {
|
86
|
%>
|
87
|
No items selected
|
88
|
<%}%>
|