Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 960 → Rev 961

/hostadmiral/trunk/src/ak/hostadmiral/core/taglib/LocaleOptionsTag.java
0,0 → 1,49
// 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;
 
public class LocaleOptionsTag extends OptionsTag
{
protected static MessageResources coreMessages =
MessageResources.getMessageResources("ak.hostadmiral.core.CoreResources");
 
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("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;
}
}