/*
 * Created on Mar 13, 2005 by Sergei Vasilevsky
 * Part of CLCA project
 */
package edu.uiuc.webcoord;

import java.util.Vector;
import com.thoughtworks.xstream.XStream;

public class HTMLDocument implements java.io.Serializable {
	private String htmlString;
	private Vector webElementVec;
	
	public HTMLDocument() {
		webElementVec = new Vector();
	}
	
	public HTMLDocument(String urlString) {
		htmlString = FetchHTML.getHTMLString(urlString);
		webElementVec = new Vector();
	}
	
	public void addWebElement(WebElement we) {
		webElementVec.addElement(we);
	}
	
	public WebElement[] getWebElements() {
		return (WebElement[])(this.webElementVec.toArray(new WebElement[0]));
	}
	
	public WEText[] getTextElements() {

		Vector textVector = new Vector();
		for (int i = 0; i < this.webElementVec.size(); i++) {
			if (this.webElementVec.elementAt(i).getClass()==WEText.class) {
				textVector.addElement(this.webElementVec.elementAt(i));
			}
		}
		
		return (WEText[])(textVector.toArray(new WEText[0]));
	}
	
	public WETextBox[] getTextBoxElements() {
		
		Vector textVector = new Vector();
		for (int i = 0; i < this.webElementVec.size(); i++) {
			if (this.webElementVec.elementAt(i).getClass()==WETextBox.class) {
				textVector.addElement(this.webElementVec.elementAt(i));
			}
		}
		
		return (WETextBox[])(textVector.toArray(new WETextBox[0]));
	}
	
	public WEImage[] getImageElements() {

		Vector textVector = new Vector();
		for (int i = 0; i < this.webElementVec.size(); i++) {
			if (this.webElementVec.elementAt(i).getClass()==WEImage.class) {
				textVector.addElement(this.webElementVec.elementAt(i));
			}
		}

		return (WEImage[])(textVector.toArray(new WEImage[0]));
	}
	
	public WEButton[] getButtonElements() {

		Vector textVector = new Vector();
		for (int i = 0; i < this.webElementVec.size(); i++) {
			if (this.webElementVec.elementAt(i).getClass()==WEButton.class) {
				textVector.addElement(this.webElementVec.elementAt(i));
			}
		}
		
		return (WEButton[])(textVector.toArray(new WEButton[0]));
	}
	
	public HTMLDocument toIntCoords() {
		CoordConverter CC = new CoordConverter();
		return CC.toIntCoords(this);
	}
	
	public String toXMLString() {
		XStream xStream = new XStream();
		return(xStream.toXML(this));
	}
}
