Kawai Wiki

Rev

Rev 137 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.kawai.tag;

import java.util.Locale;

import javax.servlet.jsp.JspException;

import org.kawai.model.Language;
import org.kawai.model.Page;
import org.kawai.model.User;
import org.mentawai.i18n.LocaleManager;
import org.mentawai.tag.util.PrintTag;

/**
 * PrintTag class EditTooltip.
 *
 * @author Sergio Oliveira
 *
 */

public class EditTooltip extends PrintTag {

    /** Attribute name of EditTooltip. */
    private String name;

    public void setName(String name) {
        this.name = name;
    }

    /**
     * {@inheritDoc}.
     */

    @Override
    public String getStringToPrint() throws JspException {

        Locale loc = Language.getDefault().getLocale();

        Page page = (Page) pageContext.findAttribute(name);
        if (page == null) {
            throw new JspException("Cannot find page with name: " + name);
        }
        User modifier = page.getModifiedBy();
        if (modifier != null) {
            return "Last modified by " + modifier.getUsername() + " on " + LocaleManager.formatDateTime(loc, page.getModifiedOn());
        } else {
            User creator = page.getCreatedBy();
            if (creator == null) {
                throw new IllegalStateException("Page without creator: " + page);
            } else {
                return "Created by " + creator.getUsername() + " on " + LocaleManager.formatDateTime(loc, page.getCreatedOn());
            }
        }
    }
}