0,0 → 1,50 |
// based on jakarta struts taglib |
package ak.hostadmiral.core.taglib; |
|
import java.util.Locale; |
import javax.servlet.jsp.JspException; |
|
import org.apache.struts.taglib.html.Constants; |
import org.apache.struts.taglib.html.SelectTag; |
import org.apache.struts.taglib.html.OptionsTag; |
import org.apache.struts.util.MessageResources; |
import org.apache.struts.util.ResponseUtils; |
|
import ak.hostadmiral.core.Locales; |
import ak.hostadmiral.core.model.User; |
import ak.hostadmiral.core.servlet.SessionKeys; |
|
public class LocaleOptionsTag extends OptionsTag |
{ |
protected static MessageResources pageMessages = |
MessageResources.getMessageResources("ak.hostadmiral.core.resources.PageMessages"); |
|
public int doEndTag() throws JspException |
{ |
SelectTag selectTag = (SelectTag) pageContext.getAttribute(Constants.SELECT_KEY); |
if (selectTag == null) { |
throw new JspException(messages.getMessage("optionsTag.select")); |
} |
|
User user = (User)pageContext.getSession().getAttribute(SessionKeys.USER); |
if(user == null) throw new JspException("no user found"); |
Locale userLocale = user.getLocale(); |
|
StringBuffer sb = new StringBuffer(); |
Locale[] locales = Locales.getLocales(); |
for(int i = 0; i < locales.length; i++) { |
Locale locale = locales[i]; |
String stringValue = locale.toString(); |
String label = locale.getDisplayLanguage(userLocale); |
String country = locale.getDisplayCountry(userLocale); |
|
if(country != null && !country.equals("")) |
label += " / " + country; // FIXME: move the slash to JSP? |
|
addOption(sb, stringValue, label, selectTag.isMatched(stringValue)); |
} |
|
ResponseUtils.write(pageContext, sb.toString()); |
return EVAL_PAGE; |
} |
} |