/**
 * Licensed under the MICE s.r.l.
 * End User License Agreement
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.micegroup.it/voila/license.html
 */
package it.mice.voila.runtime.displaytag.basedec;

import javax.servlet.jsp.PageContext;

import org.displaytag.decorator.ColumnDecorator;
import org.displaytag.decorator.ColumnDecoratorHandler;
import org.displaytag.exception.DecoratorException;

/**
 * Display Column Decorator per la trasformazione delle date anche con l'ora.
 *
 */
public class SiNoDecorator implements ColumnDecorator, ColumnDecoratorHandler {
	protected PageContext pageContext = null;

    public SiNoDecorator() {
        super();
    }

	/**
	 * Called after the object has been retrieved from the bean contained in the list and
	 * before the decorate method will executed.
	 * 
	 * @param pageContext
	 *            Column instance object that allow you to surf the entire model of
	 *            displaytag
	 */
	public void setPageContext(PageContext pageContext) {
		this.pageContext = pageContext;
	}

	public String decorate(Object columnValue) throws DecoratorException {
		if ("S".equalsIgnoreCase(nullSafeValue(columnValue)) || "Y".equalsIgnoreCase(nullSafeValue(columnValue))) {
			return "Si";
		}
		if ("N".equalsIgnoreCase(nullSafeValue(columnValue))) {
			return "No";
		}
		return nullSafeValue(columnValue);
	}

	private String nullSafeValue(Object columnValue) {
		return columnValue == null ? null : columnValue.toString();
	}

}
