1 |
3551
|
leinfelder
|
<%@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 |
3542
|
leinfelder
|
|
8 |
|
|
String[] docids = request.getParameterValues("docids");
|
9 |
3551
|
leinfelder
|
String qformat = request.getParameter("qformat");
|
10 |
3542
|
leinfelder
|
|
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 |
3551
|
leinfelder
|
String fileName = "results-";
|
18 |
3542
|
leinfelder
|
for (int i=0; i<docids.length; i++) {
|
19 |
|
|
tableTitle += docids[i];
|
20 |
|
|
tableTitle +=", ";
|
21 |
3551
|
leinfelder
|
|
22 |
|
|
fileName += docids[i];
|
23 |
3542
|
leinfelder
|
}
|
24 |
|
|
tableTitle = tableTitle.substring(0, tableTitle.length()-2);
|
25 |
3551
|
leinfelder
|
fileName += ".csv";
|
26 |
3542
|
leinfelder
|
|
27 |
|
|
//AssessmentQuery.testEcogrid("edml.4.5");
|
28 |
|
|
ResultSet rs = AssessmentQuery.selectResponseData(assessmentDocIds);
|
29 |
3551
|
leinfelder
|
|
30 |
3563
|
leinfelder
|
if (rs == null) {
|
31 |
|
|
return;
|
32 |
|
|
}
|
33 |
|
|
|
34 |
3551
|
leinfelder
|
//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 |
3542
|
leinfelder
|
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 |
3563
|
leinfelder
|
<td><%=rs.getString(i) %></td>
|
73 |
3542
|
leinfelder
|
<% } %>
|
74 |
|
|
</tr>
|
75 |
|
|
<%
|
76 |
|
|
}
|
77 |
|
|
%>
|
78 |
|
|
</table>
|
79 |
3551
|
leinfelder
|
<%
|
80 |
|
|
//clean up
|
81 |
|
|
if (rs != null) {
|
82 |
|
|
rs.close();
|
83 |
|
|
}
|
84 |
|
|
}//end if docids
|
85 |
|
|
else {
|
86 |
|
|
%>
|
87 |
|
|
No items selected
|
88 |
|
|
<%}%>
|