1 13 package info.magnolia.module.admininterface.dialogs; 14 15 import info.magnolia.cms.core.Content; 16 import info.magnolia.cms.gui.control.SelectOption; 17 import info.magnolia.cms.gui.dialog.DialogSelect; 18 import info.magnolia.cms.i18n.MessagesManager; 19 import info.magnolia.context.MgnlContext; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.Collections ; 24 import java.util.Comparator ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Locale ; 28 29 import javax.jcr.RepositoryException; 30 import javax.servlet.http.HttpServletRequest ; 31 import javax.servlet.http.HttpServletResponse ; 32 33 import org.apache.commons.lang.StringUtils; 34 35 36 41 public class LanguageSelect extends DialogSelect { 42 43 47 public void init(HttpServletRequest request, HttpServletResponse response, Content websiteNode, Content configNode) 48 throws RepositoryException { 49 super.init(request, response, websiteNode, configNode); 50 51 List options = new ArrayList (); 52 53 Collection col = MessagesManager.getAvailableLocales(); 54 55 for (Iterator iter = col.iterator(); iter.hasNext();) { 56 Locale locale = (Locale ) iter.next(); 57 String code = locale.getLanguage(); 58 if (StringUtils.isNotEmpty(locale.getCountry())) { 59 code += "_" + locale.getCountry(); } 61 String name = locale.getDisplayName(MgnlContext.getLocale()); 62 SelectOption option = new SelectOption(name, code); 63 options.add(option); 64 } 65 66 Collections.sort(options, new Comparator () { 68 69 public int compare(Object arg0, Object arg1) { 70 try { 71 String name0 = ((SelectOption) arg0).getLabel(); 72 String name1 = ((SelectOption) arg1).getLabel(); 73 return name0.compareTo(name1); 74 } 75 catch (Exception e) { 76 return 0; 77 } 78 } 79 }); 80 81 this.setOptions(options); 82 } 83 } 84 | Popular Tags |