Kawai Wiki

Rev

Rev 194 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
26 soliveira 1
package org.kawai.tag;
2
 
3
import java.util.Locale;
4
 
5
import javax.servlet.jsp.JspException;
6
 
7
import org.kawai.model.Language;
8
import org.kawai.model.Page;
9
import org.kawai.model.User;
10
import org.mentawai.i18n.LocaleManager;
11
import org.mentawai.tag.util.PrintTag;
12
 
194 helio.frota 13
/**
14
 * PrintTag class EditTooltip.
15
 *
16
 * @author Sergio Oliveira
17
 *
18
 */
26 soliveira 19
public class EditTooltip extends PrintTag {
194 helio.frota 20
 
21
    /** Attribute name of EditTooltip. */
22
    private String name;
23
 
195 helio.frota 24
    /**
25
     * Sets the name attribute of EditTooltip.
26
     * @param name String
27
     */
194 helio.frota 28
    public void setName(String name) {
29
        this.name = name;
30
    }
31
 
32
    /**
33
     * {@inheritDoc}.
34
     */
35
    @Override
36
    public String getStringToPrint() throws JspException {
37
 
38
        Locale loc = Language.getDefault().getLocale();
39
 
40
        Page page = (Page) pageContext.findAttribute(name);
41
        if (page == null) {
42
            throw new JspException("Cannot find page with name: " + name);
43
        }
44
        User modifier = page.getModifiedBy();
45
        if (modifier != null) {
46
            return "Last modified by " + modifier.getUsername() + " on " + LocaleManager.formatDateTime(loc, page.getModifiedOn());
47
        } else {
48
            User creator = page.getCreatedBy();
49
            if (creator == null) {
50
                throw new IllegalStateException("Page without creator: " + page);
51
            } else {
52
                return "Created by " + creator.getUsername() + " on " + LocaleManager.formatDateTime(loc, page.getCreatedOn());
53
            }
54
        }
55
    }
56
}