package ${projBasePackage}.tapestry.commons;

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.tapestry.BaseComponent;
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.event.PageEvent;
import org.apache.tapestry.event.PageRenderListener;
import org.asyrinx.brownie.core.util.NullableFormat;
import org.asyrinx.joey.tapestry.page.CaptionablePage;

public abstract class Border extends BaseComponent implements
        PageRenderListener {

    public static final Format LOGIN_DATE_FORMAT = new NullableFormat(
            new SimpleDateFormat("yyyy/MM/dd HH:ss"));

    public Border() {
        super();
    }

    public void pageBeginRender(PageEvent pageevent) {
    }

    public String getPageName() {
        return StringUtils.defaultString(getPageCaptionHeader(), "")
                + getPageCaption()
                + StringUtils.defaultString(getPageCaptionFooter(), "");
    }

    protected String getPageCaption() {
        IPage page = getPage();
        if (page instanceof CaptionablePage) {
            CaptionablePage p = (CaptionablePage) page;
            return p.getPageCaption();
        } else {
            return page.getPageName();
        }
    }

    public void selectPage(IRequestCycle cycle) {
        Object parameters[] = cycle.getServiceParameters();
        String newPageName = (String) parameters[0];
        cycle.activate(newPageName);
    }

    public abstract boolean isShowMenu();

    public abstract String getPageCaptionHeader();

    public abstract String getPageCaptionFooter();
}
