Kawai Wiki

Rev

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

Rev Author Line No. Line
140 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.mentawai.i18n.LocaleManager;
9
import org.mentawai.tag.i18n.RewriteWithLoc;
10
import org.mentawai.tag.util.PrintTag;
11
 
194 helio.frota 12
/**
13
 * PrintTag class EditTooltip.
14
 *
15
 * @author Sergio Oliveira
16
 *
17
 */
140 soliveira 18
public class ListFlags extends PrintTag {
19
 
194 helio.frota 20
    /**
21
     * {@inheritDoc}.
22
     */
23
    @Override
24
    public String getStringToPrint() throws JspException {
140 soliveira 25
 
194 helio.frota 26
        /*
27
        <mtw:isLocale value="pt">
28
            <a href="<mtw:urlWithLoc loc="pt" tagsToExclude="revision" />"><img src="images/brazil.gif" border="0" width="20" height="13" style="border: 3px solid #ccc;" /></a>
29
            <a href="<mtw:urlWithLoc loc="en" tagsToExclude="revision" />"><img src="images/usa.gif" width="20" height="13" border="0" style="border: 3px solid #fff;" /></a>
30
        </mtw:isLocale>
31
        <mtw:isLocale value="en">
32
            <a href="<mtw:urlWithLoc loc="pt" tagsToExclude="revision" />"><img src="images/brazil.gif" border="0" width="20" height="13" style="border: 3px solid #fff;" /></a>
33
            <a href="<mtw:urlWithLoc loc="en" tagsToExclude="revision" />"><img src="images/usa.gif" width="20" height="13" border="0" style="border: 3px solid #ccc;" /></a>
34
        </mtw:isLocale>
35
        */
36
 
37
        if (Language.all().size() == 1) return "";
38
 
39
        LocaleManager.decideLocale(req, res); // force the locale to be chosen from param or cookie...
40
        Locale selectedLocale = LocaleManager.getLocale(req, false);
41
 
42
        String cp = req.getContextPath();
43
 
44
        StringBuilder sb = new StringBuilder(1024);
45
 
46
        for(Language lang : Language.all()) {
47
            Locale loc = lang.getLocale();
48
            boolean selected = lang.getLocale().equals(selectedLocale);
49
 
50
            RewriteWithLoc tag = new RewriteWithLoc();
51
            tag.setPageContext(pageContext);
52
            tag.setLoc(loc.toString());
53
            tag.setTagsToExclude("revision");
54
            tag.doStartTag();
55
            String href = tag.getStringToPrint();
56
 
57
            sb.append("<a href=\"").append(href).append("\">");
58
            sb.append("<img src=\"").append(cp).append("/uploads/images/").append(lang.getImageFile()).append("\" border=\"0\" width=\"20\" height=\"13\" style=\"border: 3px solid ");
59
            if (selected) sb.append("#ccc");
60
            else sb.append("#fff");
61
            sb.append("; \" /></a>\n");
62
        }
63
        return sb.toString();
64
    }
65
}