package dataWarehousingTools;

public class XmlElement
{
    private int    indent;
	private String tag;
	private String attributes;
	private String content;

	
	public XmlElement(int indent, String tag, String attributes, String value)
	{
		this.indent = indent;
		this.tag = tag;
		this.attributes = attributes;
		this.content = value;
	}
	
	private String xmlEscape(String value)
	{
		String ampersand;
		String quote;
		String lessThan;
		String greaterThan;
		
		ampersand = new String(value.replace("&", "&amp;"));
		quote = new String(ampersand.replace("\"", "&quot;"));
		lessThan = new String(quote.replace("<", "&lt;"));
		greaterThan = new String(lessThan.replace(">", "&gt;"));
		
		return greaterThan;
	}
	
	public String getXmlElement()
	{
		StringBuffer sb;
		int i;
		
		sb = new StringBuffer();
		
		for (i = 0; i < indent; i++)
			sb.append(" ");
		
		sb.append("<" +	tag);
		
		if (!attributes.equals(""))
			sb.append(" " + attributes);
		
		sb.append
		(
			">" +
			xmlEscape(content) +
			"</" +
			tag +
			">"			
		);
		
		return sb.toString();
	}
}
