src/org/ohmage/request/clazz/ClassRosterReadRequest.java
@Override
	public void respond(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
		LOGGER.info("Writing the class roster read response.");
		
		// Creates the writer that will write the response, success or fail.
		Writer writer;
		try {
			writer = new BufferedWriter(new OutputStreamWriter(getOutputStream(httpRequest, httpResponse)));
		}
		catch(IOException e) {
			LOGGER.error("Unable to create writer object. Aborting.", e);
			return;
		}
		
		// Sets the HTTP headers to disable caching
		expireResponse(httpResponse);
		
		// Write an error message or the roster depending on if it failed or 
		// not.
		String responseText = "";
		if(isFailed()) {
			httpResponse.setContentType("text/html");
			
			// Use the annotator's message to build the response.
			responseText = getFailureMessage();
		}
		else {
			// Set the type and force the browser to download it as the 
			// last step before beginning to stream the response.
			httpResponse.setContentType("ohmage/roster");
			httpResponse.setHeader("Content-Disposition", "attachment; filename=roster.csv");
			
			// If available, set the token.
			if(getUser() != null) {
				final String token = getUser().getToken(); 
				if(token != null) {
					CookieUtils.setCookieValue(httpResponse, InputKeys.AUTH_TOKEN, token);
				}
			}

			// Build the class roster as a CSV file.
			StringBuilder resultBuilder = new StringBuilder();
			for(String classId : roster.keySet()) {
				Map<String, Clazz.Role> userAndClassRoles =
						roster.get(classId);
				
				for(String username : userAndClassRoles.keySet()) {
					Clazz.Role role = userAndClassRoles.get(username);
					
					resultBuilder
						.append(classId)
						.append(",")
						.append(username)
						.append(",")
						.append((role == null) ? "" : role.toString())
						.append("\n");
				}
			}
			
			responseText = resultBuilder.toString();
		}
			
		// Write the error response.
		try {
			writer.write(responseText); 
		}
		catch(IOException e) {
			LOGGER.warn("Unable to write failed response message. Aborting.", e);
		}
		
		// Close it.
		try {
			writer.close();
		}
		catch(IOException e) {
			LOGGER.warn("Unable to close the writer.", e);
		}
	}
/**
	 * Generates the class roster and returns it to the user as an attachment
	 * unless it fails in which case a JSON message will be returned not as an
	 * attachment.
	 */
Generates the class roster and returns it to the user as an attachment
unless it fails in which case a JSON message will be returned not as an
attachment.
Generates the class roster and returns it to the user as an attachment unless it fails in which case a JSON message will be returned not as an attachment .
@Override
	public void respond(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
		LOGGER.info("Writing the class roster read response.");
		Writer writer;
		try {
			writer = new BufferedWriter(new OutputStreamWriter(getOutputStream(httpRequest, httpResponse)));
		}
		catch(IOException e) {
			LOGGER.error("Unable to create writer object. Aborting.", e);
			return;
		}
		expireResponse(httpResponse);
		String responseText = "";
		if(isFailed()) {
			httpResponse.setContentType("text/html");
			responseText = getFailureMessage();
		}
		else {
			httpResponse.setContentType("ohmage/roster");
			httpResponse.setHeader("Content-Disposition", "attachment; filename=roster.csv");
			if(getUser() != null) {
				final String token = getUser().getToken(); 
				if(token != null) {
					CookieUtils.setCookieValue(httpResponse, InputKeys.AUTH_TOKEN, token);
				}
			}
			StringBuilder resultBuilder = new StringBuilder();
			for(String classId : roster.keySet()) {
				Map<String, Clazz.Role> userAndClassRoles =
						roster.get(classId);
				for(String username : userAndClassRoles.keySet()) {
					Clazz.Role role = userAndClassRoles.get(username);
					resultBuilder
						.append(classId)
						.append(",")
						.append(username)
						.append(",")
						.append((role == null) ? "" : role.toString())
						.append("\n");
				}
			}
			responseText = resultBuilder.toString();
		}
		try {
			writer.write(responseText); 
		}
		catch(IOException e) {
			LOGGER.warn("Unable to write failed response message. Aborting.", e);
		}
		try {
			writer.close();
		}
		catch(IOException e) {
			LOGGER.warn("Unable to close the writer.", e);
		}
	}
@ Override public void respond ( HttpServletRequest httpRequest , HttpServletResponse httpResponse ) { LOGGER . info ( "Writing the class roster read response." ) ; Writer writer ; try { writer = new BufferedWriter ( new OutputStreamWriter ( getOutputStream ( httpRequest , httpResponse ) ) ) ; } catch ( IOException e ) { LOGGER . error ( "Unable to create writer object. Aborting." , e ) ; return ; } expireResponse ( httpResponse ) ; String responseText = "" ; if ( isFailed ( ) ) { httpResponse . setContentType ( "text/html" ) ; responseText = getFailureMessage ( ) ; } else { httpResponse . setContentType ( "ohmage/roster" ) ; httpResponse . setHeader ( "Content-Disposition" , "attachment; filename=roster.csv" ) ; if ( getUser ( ) != null ) { final String token = getUser ( ) . getToken ( ) ; if ( token != null ) { CookieUtils . setCookieValue ( httpResponse , InputKeys . AUTH_TOKEN , token ) ; } } StringBuilder resultBuilder = new StringBuilder ( ) ; for ( String classId : roster . keySet ( ) ) { Map < String , Clazz . Role > userAndClassRoles = roster . get ( classId ) ; for ( String username : userAndClassRoles . keySet ( ) ) { Clazz . Role role = userAndClassRoles . get ( username ) ; resultBuilder . append ( classId ) . append ( "," ) . append ( username ) . append ( "," ) . append ( ( role == null ) ? "" : role . toString ( ) ) . append ( "\n" ) ; } } responseText = resultBuilder . toString ( ) ; } try { writer . write ( responseText ) ; } catch ( IOException e ) { LOGGER . warn ( "Unable to write failed response message. Aborting." , e ) ; } try { writer . close ( ) ; } catch ( IOException e ) { LOGGER . warn ( "Unable to close the writer." , e ) ; } }
Generates the class roster and returns it to the user as an attachment
 unless it fails in which case a JSON message will be returned not as an
 attachment.
Generates the class roster and returns it to the user as an attachment unless it fails in which case a JSON message will be returned not as an attachment .
// Creates the writer that will write the response, success or fail. // Sets the HTTP headers to disable caching // Write an error message or the roster depending on if it failed or  // not. // Use the annotator's message to build the response. // Set the type and force the browser to download it as the  // last step before beginning to stream the response. // If available, set the token. // Build the class roster as a CSV file. // Write the error response. // Close it.