/*
 * $Id$
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log$
 * Revision 1.1  2006/03/09 01:35:11  marbobo
 * + Initiale Version
 *
 */

package vkc.view.tag;

import javax.servlet.jsp.JspException;

import org.apache.struts.util.RequestUtils;

import vkc.util.VKCStringUtils;

public class SubmitTag extends org.apache.struts.taglib.html.SubmitTag {
    /**
     * Filter the rendered output for characters that are sensitive in HTML?
     */
    protected boolean filter = true;

    public boolean getFilter() {
        return filter;
    }

    public void setFilter(boolean filter) {
        this.filter = filter;
    }

    /**
    * Return the text specified by the literal value or the message resources
    * key, if any; otherwise return <code>null</code>.
    *
    * @param literal Literal text value or <code>null</code>
    * @param key Message resources key or <code>null</code>
    *
    * @exception JspException if both arguments are non-null
    */
	protected String message(String literal, String key) throws JspException {
	   if (literal != null) {
	       if (key != null) {
	           JspException e = new JspException(messages.getMessage("common.both"));
	           RequestUtils.saveException(pageContext, e);
	           throw e;
	       }

	       if (filter) {
	    	   return VKCStringUtils.filterUnicodeChars(literal);
	       }
	       
	       return literal;
	   } 

	   if (key != null) {
           if (filter) {
    		   return VKCStringUtils.filterUnicodeChars(RequestUtils.message(pageContext, getBundle(), getLocale(), key));
           }
           
		   return RequestUtils.message(pageContext, getBundle(), getLocale(), key);
       } 

       return null;
	}

    /**
     * Release any acquired resources.
     */
    public void release() {
        super.release();
        filter = true;
    }
}