Kawai Wiki

Rev

Rev 157 | 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.mentawai.i18n.LocaleManager;
import org.mentawai.tag.i18n.RewriteWithLoc;
import org.mentawai.tag.util.PrintTag;

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

public class ListFlags extends PrintTag {

    /**
     * {@inheritDoc}.
     */

    @Override
    public String getStringToPrint() throws JspException {

        /*
        <mtw:isLocale value="pt">
            <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>
            <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>
        </mtw:isLocale>
        <mtw:isLocale value="en">
            <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>
            <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>
        </mtw:isLocale>
        */


        if (Language.all().size() == 1) return "";

        LocaleManager.decideLocale(req, res); // force the locale to be chosen from param or cookie...
        Locale selectedLocale = LocaleManager.getLocale(req, false);

        String cp = req.getContextPath();

        StringBuilder sb = new StringBuilder(1024);

        for(Language lang : Language.all()) {
            Locale loc = lang.getLocale();
            boolean selected = lang.getLocale().equals(selectedLocale);

            RewriteWithLoc tag = new RewriteWithLoc();
            tag.setPageContext(pageContext);
            tag.setLoc(loc.toString());
            tag.setTagsToExclude("revision");
            tag.doStartTag();
            String href = tag.getStringToPrint();

            sb.append("<a href=\"").append(href).append("\">");
            sb.append("<img src=\"").append(cp).append("/uploads/images/").append(lang.getImageFile()).append("\" border=\"0\" width=\"20\" height=\"13\" style=\"border: 3px solid ");
            if (selected) sb.append("#ccc");
            else sb.append("#fff");
            sb.append("; \" /></a>\n");
        }
        return sb.toString();
    }
}