/**
 * Recipe.java
 *
 *
 * @author 
 * @version 1.00 2007/11/22
 */


import java.io.*;
import java.util.*; 

class Recipe {
	final private static String startTag = "<recipe>";  
	final private static String endTag = "</recipe>";
	final private static String recipeNameStartTag = "<recipe name>";
	final private static String recipeNameEndTag = "</recipe name>"; 
	final private static String ratingStartTag = "<rating>";  
	final private static String ratingEndTag = "</rating>";
	final private static String contributorStartTag = "<contributor>";  
	final private static String contributorEndTag = "</contributor>";
	final private static String sourceStartTag = "<source>";  
	final private static String sourceEndTag = "</source>";
	final private static String categoryStartTag = "<category>";  
	final private static String categoryEndTag = "</category>";
	final private static String descriptionStartTag = "<description>";  
	final private static String descriptionEndTag = "</description>";
	final private static String spicesStartTag = "<spices>";  
	final private static String spicesEndTag = "</spices>";
	final private static String ingredientsStartTag = "<ingredients>";  
	final private static String ingredientsEndTag = "</ingredients>";
	final private static String directionsStartTag = "<directions>";  
	final private static String directionsEndTag = "</directions>";
	
	private String name;
	private String rating;
	private String contributor;
	private String spices;
	private String source;
	private String category;
	private String description;
	private String ingredients;
	private String directions;
	
	public static String getStartTag(){return startTag;}
	public static String getEndTag(){return endTag;}
	public String getRating() {return rating.trim();}
	public String getName() {return name.trim();}
	public String getContributor() {return contributor.trim();}
	public String getSpice() {return spices.trim();}
	public String getIngredients() {return ingredients.trim();}
	public String getDirections() {return directions.trim();}
	public String getDescription() {return description.trim();}
	public String toString(){return getName();}
	
	public void setName(String newName) {name = newName;}
	public void setRating(String newRating) {rating = newRating;}
	public void setContributor(String newContributor) {contributor = newContributor;}
	public void setSpice(String newSpice) {spices = newSpice;}
	public void setIngredients(String newIngredients) {ingredients = newIngredients;}
	public void setDirections(String newDirections) {directions = newDirections;}
	public void setDescription(String newDescription) {description = newDescription;}
	
	public Recipe(){}
	
	public Recipe(String aName, String aRating, String aContributor, String someSpices, String aSource, String aCategory,
		String aDescription, String someIngredients, String someDirections){
			
		name = aName;
		rating = aRating;
		contributor = aContributor;
		spices = someSpices;
		source = aSource;
		category = aCategory;
		description = aDescription;
		ingredients = someIngredients;
		directions = someDirections;
	}
	
	public void printXMLOn(String initialIndent, PrintWriter out) {
		String indent = initialIndent;
		String tab = "   ";
		
		out.println(indent + startTag);
		
		indent = indent + tab;
		
		out.println(indent + recipeNameStartTag);      
		out.println(indent + name.trim());
		out.println(indent + recipeNameEndTag);
		
		
		out.println(indent + ratingStartTag);
		out.println(indent + rating.trim());
		out.println(indent + ratingEndTag);
		
		out.println(indent + contributorStartTag);
		out.println(indent + contributor.trim());
		out.println(indent + contributorEndTag);
		
		out.println(indent + spicesStartTag);
		out.println(indent + spices.trim());
		out.println(indent + spicesEndTag);
		
		out.println(indent + sourceStartTag);
		out.println(indent + source.trim());
		out.println(indent + sourceEndTag);
		
		out.println(indent + categoryStartTag);
		out.println(indent + category.trim());
		out.println(indent + categoryEndTag);
		
		out.println(indent + descriptionStartTag);
		out.println(indent + description.trim());
		out.println(indent + descriptionEndTag);
		
		out.println(indent + ingredientsStartTag);
		out.println(indent + ingredients.trim());
		out.println(indent + ingredientsEndTag);
		
		out.println(indent + directionsStartTag);
		out.println(indent + directions.trim());
		out.println(indent + directionsEndTag);
		
		indent = initialIndent;
		out.println(indent + endTag);
	}
	
	public void setXMLField(String xmlField, StringBuffer text) {
		String input = xmlField.trim();
		if(input.startsWith(recipeNameStartTag)) name = text.toString();
		if(input.startsWith(ratingStartTag)) rating = text.toString();
		if(input.startsWith(contributorStartTag)) contributor = text.toString();
		if(input.startsWith(spicesStartTag)) spices = text.toString();
		if(input.startsWith(sourceStartTag)) source = text.toString();
		if(input.startsWith(categoryStartTag)) category = text.toString();
		if(input.startsWith(descriptionStartTag)) description = text.toString();
		if(input.startsWith(ingredientsStartTag)) ingredients = text.toString();
		if(input.startsWith(directionsStartTag)) directions = text.toString();
	}
	
	public static boolean isXMLStartTag(String aTagString){
		String input = aTagString;
		
		if(input.equals(startTag)) return true;      
		if(input.equals(recipeNameStartTag)) return true;
		if(input.equals(ratingStartTag)) return true;
		if(input.equals(contributorStartTag)) return true;
		if(input.equals(spicesStartTag)) return true;
		if(input.equals(sourceStartTag)) return true;
		if(input.equals(categoryStartTag)) return true;
		if(input.equals(descriptionStartTag)) return true;
		if(input.equals(ingredientsStartTag)) return true;
		if(input.equals(directionsStartTag)) return true;
		
		return false;
	}
	
	public static boolean isXMLEndTag(String aTagString){
		String input = aTagString;
		
		if(input.equals(endTag)) return true;
		if(input.equals(recipeNameEndTag)) return true;
		if(input.equals(ratingEndTag)) return true;
		if(input.equals(contributorEndTag)) return true;
		if(input.equals(spicesEndTag)) return true;
		if(input.equals(sourceEndTag)) return true;
		if(input.equals(categoryEndTag)) return true;
		if(input.equals(descriptionEndTag)) return true;
		if(input.equals(ingredientsEndTag)) return true;
		if(input.equals(directionsEndTag)) return true;
		
		return false;
	}
	
	public static boolean isXMLTag(String aTagString){
		return isXMLStartTag(aTagString) || isXMLEndTag(aTagString);
	}
}

