r4895 - trunk/lib/style/skins/first

leinfelder at ecoinformatics.org leinfelder at ecoinformatics.org
Thu Apr 2 17:00:01 PDT 2009


Author: leinfelder
Date: 2009-04-02 17:00:00 -0700 (Thu, 02 Apr 2009)
New Revision: 4895

Modified:
   trunk/lib/style/skins/first/download.jsp
Log:
omit studentId values from normal resultset
strip the html tags from the qti elements for both return formats

Modified: trunk/lib/style/skins/first/download.jsp
===================================================================
--- trunk/lib/style/skins/first/download.jsp	2009-04-02 23:27:58 UTC (rev 4894)
+++ trunk/lib/style/skins/first/download.jsp	2009-04-03 00:00:00 UTC (rev 4895)
@@ -55,6 +55,46 @@
 		return params;
 	}
 %><%!
+	private List processResultsSet(ResultSet rs, int omitColumn) throws SQLException {
+		List retTable = new ArrayList();
+		int colCount = rs.getMetaData().getColumnCount();
+		List columnHeaders = new ArrayList();
+		int recordCount = 1;
+		OrderedMap uniqueIds = new OrderedMap();
+		
+		while (rs.next()) {
+			List row = new ArrayList();
+			//get the values for this row
+			for (int i = 1; i <= colCount; i++) {
+				if (recordCount == 1) {
+					String colName = rs.getMetaData().getColumnName(i);
+					columnHeaders.add(colName);
+				}
+				
+				String value = rs.getString(i);
+					
+				//clean up the value
+				value = cleanUp(value);
+				
+				//hide the ids
+				if (i == omitColumn) {
+					String lookupValue = (String) uniqueIds.get(value);
+					if (lookupValue == null) {
+						lookupValue = recordCount + "";
+					}
+					uniqueIds.put(value, lookupValue);
+					value = lookupValue;
+				}
+				
+				row.add(value);
+			}
+			retTable.add(row.toArray(new String[0]));
+			recordCount++;
+		}
+		retTable.add(0, columnHeaders.toArray(new String[0]));
+		return retTable;
+	}
+%><%!
 	private List transpose(ResultSet rs, int idCol, int pivotCol, List pivotAttributes, boolean omitIdValues) throws SQLException {
 		//map keyed by id column - data
 		OrderedMap table = new OrderedMap();
@@ -97,17 +137,10 @@
 				if (i != pivotCol) {
 					String colName = rs.getMetaData().getColumnName(i);
 					String value = rs.getString(i);
+					
 					//clean up the value
-					if (value != null) {
-						value = value.replaceAll("\n", " ");
-						value = value.replaceAll("\\s+", " ");
-						value = value.replaceAll("<html>", " ");
-						value = value.replaceAll("</html>", " ");
-						value = value.replaceAll("<head>", " ");
-						value = value.replaceAll("</head>", " ");
-						value = value.replaceAll("<body>", " ");
-						value = value.replaceAll("</body>", " ");
-					}
+					value = cleanUp(value);
+					
 					//do we include this column in the pivot?
 					if (pivotAttributes.contains(colName)) {
 						//annotate the column name with the pivot column value if not the id column
@@ -303,6 +336,20 @@
 		return retTable;
 	}
 %><%!
+	private String cleanUp(String value) {
+		if (value != null) {
+			value = value.replaceAll("\n", " ");
+			value = value.replaceAll("\\s+", " ");
+			value = value.replaceAll("<html>", " ");
+			value = value.replaceAll("</html>", " ");
+			value = value.replaceAll("<head>", " ");
+			value = value.replaceAll("</head>", " ");
+			value = value.replaceAll("<body>", " ");
+			value = value.replaceAll("</body>", " ");
+		}
+		return value;
+	}
+%><%!
 	private void handleDataquery(
 			Hashtable<String, String[]> params,
 	        HttpServletResponse response,
@@ -369,7 +416,8 @@
 					List transposedTable = transpose(rs, observation, pivot, pivotCols, true);
 					csv.writeAll(transposedTable);
 				} else {
-					csv.writeAll(rs, true);
+					List processedTable = processResultsSet(rs, 3);
+					csv.writeAll(processedTable);
 				}
 				
 				csv.flush();



More information about the Metacat-cvs mailing list