package com.udapsoft.modular.web.tags;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class AttrTag extends TemplateBasedRequestContextAwareTag {

	public static final String ATTR_MODEL_KEY = "modular:attr_model";
	private String key;
	private String value;

	public String getKey() {
		return this.key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getValue() {
		return this.value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	protected int doBuildModelForStartTag(Map model) throws Exception {
		Object attrModel = this.pageContext.getAttribute("modular:attr_model");
		List attrList = null;
		if (attrModel == null) {
			attrList = new ArrayList<Object>();
			this.pageContext.setAttribute("modular:attr_model", attrList);
		} else {
			attrList = (List<?>) attrModel;
		}
		attrList.add("{key:\"" + this.key + "\", value:\"" + this.value + "\"}");

		return 0;
	}

}
