/*
 * $Id: FrameTag.java,v 1.1 2006/10/04 03:10:57 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: FrameTag.java,v $
 * Revision 1.1  2006/10/04 03:10:57  marbobo
 * + Initiale Version
 *
 *
 */
package vkc.view.tag;

import javax.servlet.jsp.JspException;

import org.apache.struts.util.ResponseUtils;

public class FrameTag extends LinkTag {
    /**
     * The frameborder attribute that should be rendered (1, 0).
     */
    protected String frameborder = null;

    public String getFrameborder() {
        return (this.frameborder);
    }

    public void setFrameborder(String frameborder) {
        this.frameborder = frameborder;
    }


    /**
     * The <code>name</code> attribute that should be rendered for this frame.
     */
    protected String frameName = null;

    public String getFrameName() {
        return this.frameName;
    }

    public void setFrameName(String frameName) {
        this.frameName = frameName;
    }


    /**
     * URI of a long description of this frame (complements title).
     */
    protected String longdesc = null;

    public String getLongdesc() {
        return this.longdesc;
    }

    public void setLongdesc(String longdesc) {
        this.longdesc = longdesc;
    }


    /**
     * The margin height in pixels, or zero for no setting.
     */
    protected int marginheight = 0;

    public int getMarginheight() {
        return this.marginheight;
    }

    public void setMarginheight(int marginheight) {
        this.marginheight = marginheight;
    }


    /**
     * The margin width in pixels, or zero for no setting.
     */
    protected int marginwidth = 0;

    public int getMarginwidth() {
        return this.marginwidth;
    }

    public void setMarginwidth(int marginwidth) {
        this.marginwidth = marginwidth;
    }


    /**
     * Should users be disallowed to resize the frame?
     */
    protected boolean noresize = false;

    public boolean getNoresize() {
        return this.noresize;
    }

    public void setNoresize(boolean noresize) {
        this.noresize = noresize;
    }


    /**
     * What type of scrolling should be supported (yes, no, auto)?
     */
    protected String scrolling = null;

    public String getScrolling() {
        return this.scrolling;
    }

    public void setScrolling(String scrolling) {
        this.scrolling = scrolling;
    }

    /**
     * Render the appropriately encoded URI.
     *
     * @exception JspException if a JSP exception has occurred
     */
    public int doStartTag() throws JspException {

    // Print this element to our output writer
        StringBuffer results = new StringBuffer("<frame ");
        results.append("src=\"");
        results.append(calculateURL());
        results.append("\"");
        
        if (frameName != null) {
            results.append(" name=\"");
            results.append(frameName);
            results.append("\"");
        }
        
        if (noresize) {
            results.append(" noresize=\"noresize\"");
        }
        
        if (scrolling != null) {
            results.append(" scrolling=\"");
            results.append(scrolling);
            results.append("\"");
        }
        
        if (marginheight > 0) {
            results.append(" marginheight=\"");
            results.append(marginheight);
            results.append("\"");
        }
        
        if (marginwidth > 0) {
            results.append(" marginwidth=\"");
            results.append(marginwidth);
            results.append("\"");
        }
        
        if (frameborder != null) {
            results.append(" frameborder=\"");
            results.append(frameborder);
            results.append("\"");
        }
        
        if (longdesc != null) {
            results.append(" longdesc=\"");
            results.append(longdesc);
            results.append("\"");
        }
        
        results.append(prepareStyles());
        results.append(getElementClose());
        ResponseUtils.write(pageContext,results.toString());

	    // Skip the body of this tag
	    return SKIP_BODY;
    }


    /**
     * Ignore the end of this tag.
     *
     * @exception JspException if a JSP exception has occurred
     */
    public int doEndTag() throws JspException {
        return EVAL_PAGE;
    }


    /**
     * Release any acquired resources.
     */
    public void release() {
        super.release();

        frameborder = null;
        frameName = null;
        longdesc = null;
        marginheight = 0;
        marginwidth = 0;
        noresize = false;
        scrolling = null;
    }
}
