src/org/ohmage/validator/SurveyResponseValidators.java
public static Map<UUID, Image> validateImages(
			final String value) 
			throws ValidationException {
		
		if(StringUtils.isEmptyOrWhitespaceOnly(value)) {
			return null;
		}
		
		JSONObject imagesJson;
		try {
			imagesJson = new JSONObject(value);
		}
		catch(JSONException e) {
			throw new ValidationException(
				ErrorCode.SURVEY_INVALID_IMAGES_VALUE,
				"The images parameter was not valid JSON: " + value,
				e);
		}

		Map<UUID, Image> results = new HashMap<UUID, Image>();
		
		Iterator<?> imageIds = imagesJson.keys();
		int numImageIds = imagesJson.length();
		for(int i = 0; i < numImageIds; i++) {
			UUID imageUuid;
			String imageId = (String) imageIds.next();
			
			try {
				imageUuid = UUID.fromString(imageId);
			}
			catch(IllegalArgumentException e) {
				throw new ValidationException(
					ErrorCode.SURVEY_INVALID_IMAGES_VALUE,
					"An image's ID is not a valid UUID: " + imageId,
					e);
			}
			
			Image image;
			try {
				image = 
					ImageValidators.validateImageContents(
						imageUuid,
						DatatypeConverter.parseBase64Binary(
							imagesJson.getString(imageId)));
			}
			catch(JSONException e) {
				throw new ValidationException(
					ErrorCode.SURVEY_INVALID_IMAGES_VALUE,
					"The image's contents in the JSON was not a string.",
					e);
			}
			catch(IllegalArgumentException e) {
				throw new ValidationException(
					ErrorCode.SURVEY_INVALID_IMAGES_VALUE,
					"The image's contents were not BASE64.",
					e);
			}
			
			results.put(imageUuid, image);
		}
		
		return results;
	}
/**
	 * Validates that a "images" value was a valid JSON object whose keys were
	 * the image IDs (UUIDs) and values were BASE64-encoded images. It then 
	 * returns the map of the IDs to BufferedImages.
	 * 
	 * @param value The value to be validated.
	 * 
	 * @return The map of image IDs to Images.
	 * 
	 * @throws ValidationException The value was not valid JSON, an image's ID
	 * 							   was not a valid UUID, or an image's contents
	 * 							   was not a valid BASE64-encoded image.
	 */
Validates that a "images" value was a valid JSON object whose keys were
the image IDs (UUIDs) and values were BASE64-encoded images. It then
returns the map of the IDs to BufferedImages.

@param value The value to be validated.

@return The map of image IDs to Images.

@throws ValidationException The value was not valid JSON, an image's ID
was not a valid UUID, or an image's contents
was not a valid BASE64-encoded image.
Validates that a " images " value was a valid JSON object whose keys were the image IDs ( UUIDs ) and values were BASE64 - encoded images . It then returns the map of the IDs to BufferedImages . @param value The value to be validated . @return The map of image IDs to Images . @throws ValidationException The value was not valid JSON an image ' s ID was not a valid UUID or an image ' s contents was not a valid BASE64 - encoded image .
public static Map<UUID, Image> validateImages(
			final String value) 
			throws ValidationException {
		if(StringUtils.isEmptyOrWhitespaceOnly(value)) {
			return null;
		}
		JSONObject imagesJson;
		try {
			imagesJson = new JSONObject(value);
		}
		catch(JSONException e) {
			throw new ValidationException(
				ErrorCode.SURVEY_INVALID_IMAGES_VALUE,
				"The images parameter was not valid JSON: " + value,
				e);
		}
		Map<UUID, Image> results = new HashMap<UUID, Image>();
		Iterator<?> imageIds = imagesJson.keys();
		int numImageIds = imagesJson.length();
		for(int i = 0; i < numImageIds; i++) {
			UUID imageUuid;
			String imageId = (String) imageIds.next();
			try {
				imageUuid = UUID.fromString(imageId);
			}
			catch(IllegalArgumentException e) {
				throw new ValidationException(
					ErrorCode.SURVEY_INVALID_IMAGES_VALUE,
					"An image's ID is not a valid UUID: " + imageId,
					e);
			}
			Image image;
			try {
				image = 
					ImageValidators.validateImageContents(
						imageUuid,
						DatatypeConverter.parseBase64Binary(
							imagesJson.getString(imageId)));
			}
			catch(JSONException e) {
				throw new ValidationException(
					ErrorCode.SURVEY_INVALID_IMAGES_VALUE,
					"The image's contents in the JSON was not a string.",
					e);
			}
			catch(IllegalArgumentException e) {
				throw new ValidationException(
					ErrorCode.SURVEY_INVALID_IMAGES_VALUE,
					"The image's contents were not BASE64.",
					e);
			}
			results.put(imageUuid, image);
		}
		return results;
	}
public static Map < UUID , Image > validateImages ( final String value ) throws ValidationException { if ( StringUtils . isEmptyOrWhitespaceOnly ( value ) ) { return null ; } JSONObject imagesJson ; try { imagesJson = new JSONObject ( value ) ; } catch ( JSONException e ) { throw new ValidationException ( ErrorCode . SURVEY_INVALID_IMAGES_VALUE , "The images parameter was not valid JSON: " + value , e ) ; } Map < UUID , Image > results = new HashMap < UUID , Image > ( ) ; Iterator < ? > imageIds = imagesJson . keys ( ) ; int numImageIds = imagesJson . length ( ) ; for ( int i = 0 ; i < numImageIds ; i ++ ) { UUID imageUuid ; String imageId = ( String ) imageIds . next ( ) ; try { imageUuid = UUID . fromString ( imageId ) ; } catch ( IllegalArgumentException e ) { throw new ValidationException ( ErrorCode . SURVEY_INVALID_IMAGES_VALUE , "An image's ID is not a valid UUID: " + imageId , e ) ; } Image image ; try { image = ImageValidators . validateImageContents ( imageUuid , DatatypeConverter . parseBase64Binary ( imagesJson . getString ( imageId ) ) ) ; } catch ( JSONException e ) { throw new ValidationException ( ErrorCode . SURVEY_INVALID_IMAGES_VALUE , "The image's contents in the JSON was not a string." , e ) ; } catch ( IllegalArgumentException e ) { throw new ValidationException ( ErrorCode . SURVEY_INVALID_IMAGES_VALUE , "The image's contents were not BASE64." , e ) ; } results . put ( imageUuid , image ) ; } return results ; }
Validates that a "images" value was a valid JSON object whose keys were
 the image IDs (UUIDs) and values were BASE64-encoded images.
Validates that a " images " value was a valid JSON object whose keys were the image IDs ( UUIDs ) and values were BASE64 - encoded images .