src/org/ohmage/domain/campaign/Campaign.java
private static Message processMessage(
			final String containerId,
			final Node message, 
			final int index,
			final List<SurveyItem> alreadyProcessedItemsInSurveyItemGroup) 
			throws DomainException {
		
		Nodes ids = message.query(XML_MESSAGE_ID);  //required
		if(ids.size() == 0) {
			throw new DomainException(
					"The message ID is missing: " + containerId);
		}
		else if(ids.size() > 1) {
			throw new DomainException(
					"Multiple message IDs were found: " + containerId);
		}
		String id = ids.get(0).getValue().trim();
		if(id.length() == 0) {
			throw new DomainException(
					"The message's ID cannot be only whitespace in the survey item container: " +
						containerId);
		}
		if(! VALID_CHARACTERS_PATTERN.matcher(id).matches()) {
			throw new DomainException(
					"The message's ID contains illegal characters: " + id);
		}
		
		String condition = null;
		Nodes conditions = message.query(XML_MESSAGE_CONDITION);  // optional
		if(conditions.size() > 1) {
			throw new DomainException(
					"Multiple message conditions were found: " + id);
		}
		else if(conditions.size() == 1) {
			condition = conditions.get(0).getValue().trim();
			
			condition = validateCondition(
					condition, 
					id, 
					containerId, 
					alreadyProcessedItemsInSurveyItemGroup);
		}
		
		Nodes texts = message.query(XML_MESSAGE_TEXT);  // required
		if(texts.size() == 0) {
			throw new DomainException(
					"The message text is missing: " + id);
		}
		else if(texts.size() > 1) {
			throw new DomainException(
					"Multiple message texts were found: " + id);
		}
		String text = texts.get(0).getValue().trim();
		if(text.length() == 0) {
			throw new DomainException(
					"The text cannot be only whitespace: " +
						id);
		}
		
		return new Message(id, condition, index, text);
	}
/**
	 * Creates a Message object from the message Node from the XML.
	 * 
	 * @param containerId The unique identifier for the container that contains
	 * 					  this message.
	 * 
	 * @param message The message Node from the XML.
	 * 
	 * @param index The index of this message in its list of survey items.
	 * 
	 * @return A Message object representing the message defined in the XML.
	 * 
	 * @throws DomainException The message was malformed.
	 */
Creates a Message object from the message Node from the XML.

@param containerId The unique identifier for the container that contains
this message.

@param message The message Node from the XML.

@param index The index of this message in its list of survey items.

@return A Message object representing the message defined in the XML.

@throws DomainException The message was malformed.
Creates a Message object from the message Node from the XML . @param containerId The unique identifier for the container that contains this message . @param message The message Node from the XML . @param index The index of this message in its list of survey items . @return A Message object representing the message defined in the XML . @throws DomainException The message was malformed .
private static Message processMessage(
			final String containerId,
			final Node message, 
			final int index,
			final List<SurveyItem> alreadyProcessedItemsInSurveyItemGroup) 
			throws DomainException {
		Nodes ids = message.query(XML_MESSAGE_ID);  
		if(ids.size() == 0) {
			throw new DomainException(
					"The message ID is missing: " + containerId);
		}
		else if(ids.size() > 1) {
			throw new DomainException(
					"Multiple message IDs were found: " + containerId);
		}
		String id = ids.get(0).getValue().trim();
		if(id.length() == 0) {
			throw new DomainException(
					"The message's ID cannot be only whitespace in the survey item container: " +
						containerId);
		}
		if(! VALID_CHARACTERS_PATTERN.matcher(id).matches()) {
			throw new DomainException(
					"The message's ID contains illegal characters: " + id);
		}
		String condition = null;
		Nodes conditions = message.query(XML_MESSAGE_CONDITION);  
		if(conditions.size() > 1) {
			throw new DomainException(
					"Multiple message conditions were found: " + id);
		}
		else if(conditions.size() == 1) {
			condition = conditions.get(0).getValue().trim();
			condition = validateCondition(
					condition, 
					id, 
					containerId, 
					alreadyProcessedItemsInSurveyItemGroup);
		}
		Nodes texts = message.query(XML_MESSAGE_TEXT);  
		if(texts.size() == 0) {
			throw new DomainException(
					"The message text is missing: " + id);
		}
		else if(texts.size() > 1) {
			throw new DomainException(
					"Multiple message texts were found: " + id);
		}
		String text = texts.get(0).getValue().trim();
		if(text.length() == 0) {
			throw new DomainException(
					"The text cannot be only whitespace: " +
						id);
		}
		return new Message(id, condition, index, text);
	}
private static Message processMessage ( final String containerId , final Node message , final int index , final List < SurveyItem > alreadyProcessedItemsInSurveyItemGroup ) throws DomainException { Nodes ids = message . query ( XML_MESSAGE_ID ) ; if ( ids . size ( ) == 0 ) { throw new DomainException ( "The message ID is missing: " + containerId ) ; } else if ( ids . size ( ) > 1 ) { throw new DomainException ( "Multiple message IDs were found: " + containerId ) ; } String id = ids . get ( 0 ) . getValue ( ) . trim ( ) ; if ( id . length ( ) == 0 ) { throw new DomainException ( "The message's ID cannot be only whitespace in the survey item container: " + containerId ) ; } if ( ! VALID_CHARACTERS_PATTERN . matcher ( id ) . matches ( ) ) { throw new DomainException ( "The message's ID contains illegal characters: " + id ) ; } String condition = null ; Nodes conditions = message . query ( XML_MESSAGE_CONDITION ) ; if ( conditions . size ( ) > 1 ) { throw new DomainException ( "Multiple message conditions were found: " + id ) ; } else if ( conditions . size ( ) == 1 ) { condition = conditions . get ( 0 ) . getValue ( ) . trim ( ) ; condition = validateCondition ( condition , id , containerId , alreadyProcessedItemsInSurveyItemGroup ) ; } Nodes texts = message . query ( XML_MESSAGE_TEXT ) ; if ( texts . size ( ) == 0 ) { throw new DomainException ( "The message text is missing: " + id ) ; } else if ( texts . size ( ) > 1 ) { throw new DomainException ( "Multiple message texts were found: " + id ) ; } String text = texts . get ( 0 ) . getValue ( ) . trim ( ) ; if ( text . length ( ) == 0 ) { throw new DomainException ( "The text cannot be only whitespace: " + id ) ; } return new Message ( id , condition , index , text ) ; }
Creates a Message object from the message Node from the XML.
Creates a Message object from the message Node from the XML .
//required // optional // required