/*
 * $Id: HorizontalLineTag.java,v 1.5 2005/02/14 14:01:48 bigmac Exp $
 * 
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 * 
 * $Log: HorizontalLineTag.java,v $
 * Revision 1.5  2005/02/14 14:01:48  bigmac
 * Applikationsweites CSS konfigurierbar gemacht + Refactorings
 * Revision 1.4 2004/11/26 15:40:25 koppy +
 * alt=""
 * 
 * Revision 1.3 2004/07/20 08:56:55 jonyp added copyright info + cvs log
 * 
 *  
 */

package vkc.view.tag;

import java.io.IOException;

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

import vkc.util.StringUtils;

public final class HorizontalLineTag extends TagSupport {

	private int topSpace = 0;
	private int bottomSpace = 0;
	private int colspan = 1;
	private int lineHeight = 1;
	private String lineColor = "#000000";
	private String lineClass = "";
	private String topSpaceClass = "";
	private String bottomSpaceClass = "";

	public int doEndTag() throws JspException {

		JspWriter writer = pageContext.getOut();
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

		try {

			writer.print( "<tr><td width='100%' colspan='" );
			writer.print( colspan );
			writer.print( "'><table width='100%' cellSpacing='0' cellPadding='0' border='0'>\n");

			if ( topSpace > 0 ) {
				writer.print("<tr><td" );
				if ( !StringUtils.isEmpty( topSpaceClass ) ) {
					writer.print( " class=\"" + topSpaceClass + "\"" );
				}
				writer.print( "><img src='" + request.getContextPath()
						+ "/common/images/void.gif' alt='' height='" + topSpace
						+ "' width='1'></td></tr>\n");
			}

			writer.print("  <tr><td");

			if (lineColor.length() > 0) {
				writer.print(" bgcolor='" + lineColor + "'");
			}

			if (lineClass.length() > 0) {
				writer.print(" class='" + lineClass + "'");
			}

			writer.print("><img src='" + request.getContextPath()
					+ "/common/images/void.gif' alt='' height='" + lineHeight
					+ "' width='1'></td></tr>\n");

			if (bottomSpace > 0) {

				writer.print("<tr><td" );
				if ( !StringUtils.isEmpty( bottomSpaceClass ) ) {
					writer.print( " class=\"" + bottomSpaceClass + "\"" );
				}
				writer.print("><img src='" + request.getContextPath()
						+ "/common/images/void.gif' alt='' height='"
						+ bottomSpace + "' width='1'></td></tr>\n");
			}

			writer.print("  </table></td></tr>");

		} catch (IOException ioex) {
			throw new JspException(ioex);
		}

		return EVAL_PAGE;
	}

	public int doStartTag() throws JspException {
		return SKIP_BODY;
	}

	public void setBottomSpace(int i) {
		bottomSpace = i;

		if (bottomSpace < 0) {
			bottomSpace = 0;
		}
	}

	public void setColspan(int i) {
		colspan = i;

		if (colspan < 1) {
			colspan = 1;
		}
	}

	public void setLineColor(String string) {
		lineColor = string;
	}

	public void setLineHeight(int i) {
		lineHeight = i;

		if (lineHeight < 1) {
			lineHeight = 1;
		}
	}

	public void setTopSpace(int i) {
		topSpace = i;

		if (topSpace < 0) {
			topSpace = 0;
		}
	}

	public void setLineClass(String string) {
		lineClass = string;
	}

	public void release() {
		super.release();
		topSpace = 0;
		bottomSpace = 0;
		colspan = 1;
		lineHeight = 1;
		lineColor = "#000000";
		lineClass = "";
		bottomSpaceClass = "";
		topSpaceClass = "";
	}

	public String getBottomSpaceClass() {
		return bottomSpaceClass;
	}

	public void setBottomSpaceClass(String bottomRowClass) {
		this.bottomSpaceClass = bottomRowClass;
	}

	public String getTopSpaceClass() {
		return topSpaceClass;
	}

	public void setTopSpaceClass(String topRowClass) {
		this.topSpaceClass = topRowClass;
	}
}