package kr.co.kihyun.beans.totsys.menu;

import java.io.IOException;
import java.net.URL;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

import kr.co.kihyun.moumi.MoumiConfig;

public class TrailMenuTag extends TagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public int doStartTag() throws JspException {
		HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
		JspWriter out = pageContext.getOut();
                DefaultMenu menu = new DefaultMenu(req);
		URL url;
		StringBuilder sb = new StringBuilder();
		try {
			url = new URL(req.getRequestURL().toString());
			for (MenuBean menuBean : menu.getPath(url)) {
				if (sb.toString().length() != 0) {
					sb.append(" > ");
				}
	//			sb.append("<a href=\"");
	//			sb.append(menuBean.getUrl());
	//			sb.append("\">");
                                //sb.append("<font size='3' face='굴림'>");
				sb.append(menuBean.getMenuName());
                                //sb.append("</font>");
	//			sb.append("</a>");
			}
			if (!menu.getDocName().equals("")) {
				//sb.append("<font size='2' face='굴림'>");
                             	sb.append("  / " + MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc") + MoumiConfig.getMessageBundle().getString("moumi.message.tot_doc.name")
						+" :"+ menu.getDocName());
				//sb.append("</font>");
			}
 			out.print(sb.toString());
		} catch (IOException ioe) {
			throw new JspException("I/O Error : " + ioe.getMessage());
		}
		return Tag.SKIP_BODY;
	}

}
