Project

General

Profile

« Previous | Next » 

Revision 4895

omit studentId values from normal resultset
strip the html tags from the qti elements for both return formats

View differences:

lib/style/skins/first/download.jsp
55 55
		return params;
56 56
	}
57 57
%><%!
58
	private List processResultsSet(ResultSet rs, int omitColumn) throws SQLException {
59
		List retTable = new ArrayList();
60
		int colCount = rs.getMetaData().getColumnCount();
61
		List columnHeaders = new ArrayList();
62
		int recordCount = 1;
63
		OrderedMap uniqueIds = new OrderedMap();
64
		
65
		while (rs.next()) {
66
			List row = new ArrayList();
67
			//get the values for this row
68
			for (int i = 1; i <= colCount; i++) {
69
				if (recordCount == 1) {
70
					String colName = rs.getMetaData().getColumnName(i);
71
					columnHeaders.add(colName);
72
				}
73
				
74
				String value = rs.getString(i);
75
					
76
				//clean up the value
77
				value = cleanUp(value);
78
				
79
				//hide the ids
80
				if (i == omitColumn) {
81
					String lookupValue = (String) uniqueIds.get(value);
82
					if (lookupValue == null) {
83
						lookupValue = recordCount + "";
84
					}
85
					uniqueIds.put(value, lookupValue);
86
					value = lookupValue;
87
				}
88
				
89
				row.add(value);
90
			}
91
			retTable.add(row.toArray(new String[0]));
92
			recordCount++;
93
		}
94
		retTable.add(0, columnHeaders.toArray(new String[0]));
95
		return retTable;
96
	}
97
%><%!
58 98
	private List transpose(ResultSet rs, int idCol, int pivotCol, List pivotAttributes, boolean omitIdValues) throws SQLException {
59 99
		//map keyed by id column - data
60 100
		OrderedMap table = new OrderedMap();
......
97 137
				if (i != pivotCol) {
98 138
					String colName = rs.getMetaData().getColumnName(i);
99 139
					String value = rs.getString(i);
140
					
100 141
					//clean up the value
101
					if (value != null) {
102
						value = value.replaceAll("\n", " ");
103
						value = value.replaceAll("\\s+", " ");
104
						value = value.replaceAll("<html>", " ");
105
						value = value.replaceAll("</html>", " ");
106
						value = value.replaceAll("<head>", " ");
107
						value = value.replaceAll("</head>", " ");
108
						value = value.replaceAll("<body>", " ");
109
						value = value.replaceAll("</body>", " ");
110
					}
142
					value = cleanUp(value);
143
					
111 144
					//do we include this column in the pivot?
112 145
					if (pivotAttributes.contains(colName)) {
113 146
						//annotate the column name with the pivot column value if not the id column
......
303 336
		return retTable;
304 337
	}
305 338
%><%!
339
	private String cleanUp(String value) {
340
		if (value != null) {
341
			value = value.replaceAll("\n", " ");
342
			value = value.replaceAll("\\s+", " ");
343
			value = value.replaceAll("<html>", " ");
344
			value = value.replaceAll("</html>", " ");
345
			value = value.replaceAll("<head>", " ");
346
			value = value.replaceAll("</head>", " ");
347
			value = value.replaceAll("<body>", " ");
348
			value = value.replaceAll("</body>", " ");
349
		}
350
		return value;
351
	}
352
%><%!
306 353
	private void handleDataquery(
307 354
			Hashtable<String, String[]> params,
308 355
	        HttpServletResponse response,
......
369 416
					List transposedTable = transpose(rs, observation, pivot, pivotCols, true);
370 417
					csv.writeAll(transposedTable);
371 418
				} else {
372
					csv.writeAll(rs, true);
419
					List processedTable = processResultsSet(rs, 3);
420
					csv.writeAll(processedTable);
373 421
				}
374 422
				
375 423
				csv.flush();

Also available in: Unified diff