src/org/ohmage/service/CampaignServices.java
public void ensurePromptExistsInCampaign(final String campaignId, 
			final String promptId) throws ServiceException {
		
		// Get the XML.
		String xml;
		try {
			xml = campaignQueries.getXml(campaignId);
		}
		catch(DataAccessException e) {
			throw new ServiceException(e);
		}
		if(xml == null) {
			throw new ServiceException(
					ErrorCode.CAMPAIGN_INVALID_ID, 
					"There is no such campaign with the campaign ID: " + 
						campaignId);
		}
		
		// Now use XOM to retrieve a Document and a root node for further processing. XOM is used because it has a 
		// very simple XPath API	
		Builder builder = new Builder();
		Document document;
		try {
			document = builder.build(new StringReader(xml));
		} catch (IOException e) {
			// The XML should already have been validated, so this should
			// never happen.
			throw new ServiceException("Unable to read XML.", e);
		} catch (ValidityException e) {
			// The XML should already have been validated, so this should
			// never happen.
			throw new ServiceException("Invalid XML.", e);
		} catch (ParsingException e) {
			// The XML should already have been validated, so this should
			// never happen.
			throw new ServiceException("XML cannot be parsed.", e);
		}
		
		// Find all the prompt IDs with the parameterized promptId.
		Element root = document.getRootElement();
		Nodes nodes = root.query("/campaign/surveys/survey/contentList/prompt[id='" + promptId + "']");
		if(nodes.size() == 0) {
			throw new ServiceException(
					ErrorCode.SURVEY_INVALID_PROMPT_ID, 
					"The following prompt ID is not part of the campaign's XML: " + 
						promptId);
		}
	}
/**
	 * Ensures that the prompt ID exists in the campaign XML of the campaign.
	 * 
	 * @param campaignId The unique identifier for the campaign whose XML is 
	 * 					 being checked.
	 * 
	 * @param promptId A prompt ID that is unique to the campaign's XML and is
	 * 				   being checked for existance.
	 * 
	 * @throws ServiceException Throws a 
	 * 							{@value org.ohmage.annotator.ErrorCodes#CAMPAIGN_NOT_FOUND}
	 * 							if the campaign doesn't exist or a
	 * 							{@value org.ohmage.annotator.ErrorCodes##CAMPAIGN_UNKNOWN_PROMPT_ID}
	 * 							if the prompt ID doesn't exist in the 
	 * 							campaign's XML. Also, thrown if there is an 
	 * 							error.
	 */
Ensures that the prompt ID exists in the campaign XML of the campaign.

@param campaignId The unique identifier for the campaign whose XML is
being checked.

@param promptId A prompt ID that is unique to the campaign's XML and is
being checked for existance.

@throws ServiceException Throws a
org.ohmage.annotator.ErrorCodes#CAMPAIGN_NOT_FOUND
if the campaign doesn't exist or a
org.ohmage.annotator.ErrorCodes##CAMPAIGN_UNKNOWN_PROMPT_ID
if the prompt ID doesn't exist in the
campaign's XML. Also, thrown if there is an
error.
Ensures that the prompt ID exists in the campaign XML of the campaign . @param campaignId The unique identifier for the campaign whose XML is being checked . @param promptId A prompt ID that is unique to the campaign ' s XML and is being checked for existance . @throws ServiceException Throws a org . ohmage . annotator . ErrorCodes#CAMPAIGN_NOT_FOUND if the campaign doesn ' t exist or a org . ohmage . annotator . ErrorCodes##CAMPAIGN_UNKNOWN_PROMPT_ID if the prompt ID doesn ' t exist in the campaign ' s XML . Also thrown if there is an error .
public void ensurePromptExistsInCampaign(final String campaignId, 
			final String promptId) throws ServiceException {
		String xml;
		try {
			xml = campaignQueries.getXml(campaignId);
		}
		catch(DataAccessException e) {
			throw new ServiceException(e);
		}
		if(xml == null) {
			throw new ServiceException(
					ErrorCode.CAMPAIGN_INVALID_ID, 
					"There is no such campaign with the campaign ID: " + 
						campaignId);
		}
		Builder builder = new Builder();
		Document document;
		try {
			document = builder.build(new StringReader(xml));
		} catch (IOException e) {
			throw new ServiceException("Unable to read XML.", e);
		} catch (ValidityException e) {
			throw new ServiceException("Invalid XML.", e);
		} catch (ParsingException e) {
			throw new ServiceException("XML cannot be parsed.", e);
		}
		Element root = document.getRootElement();
		Nodes nodes = root.query("/campaign/surveys/survey/contentList/prompt[id='" + promptId + "']");
		if(nodes.size() == 0) {
			throw new ServiceException(
					ErrorCode.SURVEY_INVALID_PROMPT_ID, 
					"The following prompt ID is not part of the campaign's XML: " + 
						promptId);
		}
	}
public void ensurePromptExistsInCampaign ( final String campaignId , final String promptId ) throws ServiceException { String xml ; try { xml = campaignQueries . getXml ( campaignId ) ; } catch ( DataAccessException e ) { throw new ServiceException ( e ) ; } if ( xml == null ) { throw new ServiceException ( ErrorCode . CAMPAIGN_INVALID_ID , "There is no such campaign with the campaign ID: " + campaignId ) ; } Builder builder = new Builder ( ) ; Document document ; try { document = builder . build ( new StringReader ( xml ) ) ; } catch ( IOException e ) { throw new ServiceException ( "Unable to read XML." , e ) ; } catch ( ValidityException e ) { throw new ServiceException ( "Invalid XML." , e ) ; } catch ( ParsingException e ) { throw new ServiceException ( "XML cannot be parsed." , e ) ; } Element root = document . getRootElement ( ) ; Nodes nodes = root . query ( "/campaign/surveys/survey/contentList/prompt[id='" + promptId + "']" ) ; if ( nodes . size ( ) == 0 ) { throw new ServiceException ( ErrorCode . SURVEY_INVALID_PROMPT_ID , "The following prompt ID is not part of the campaign's XML: " + promptId ) ; } }
Ensures that the prompt ID exists in the campaign XML of the campaign.
Ensures that the prompt ID exists in the campaign XML of the campaign .
// Get the XML. // Now use XOM to retrieve a Document and a root node for further processing. XOM is used because it has a  // very simple XPath API	 // The XML should already have been validated, so this should // never happen. // The XML should already have been validated, so this should // never happen. // The XML should already have been validated, so this should // never happen. // Find all the prompt IDs with the parameterized promptId.