1 16 17 18 package org.apache.webapp.admin; 19 20 21 import java.util.ArrayList ; 22 import java.util.List ; 23 import java.util.Locale ; 24 import java.util.ResourceBundle ; 25 import org.apache.struts.Globals; 26 import org.apache.struts.action.ActionServlet; 27 import org.apache.struts.util.MessageResources; 28 29 30 37 38 public final class ApplicationLocales { 39 40 41 43 44 49 public ApplicationLocales(ActionServlet servlet) { 50 51 super(); 52 Locale list[] = Locale.getAvailableLocales(); 53 MessageResources resources = (MessageResources) 54 servlet.getServletContext().getAttribute(Globals.MESSAGES_KEY); 55 if (resources == null) 56 return; 57 String config = resources.getConfig(); 58 if (config == null) 59 return; 60 61 for (int i = 0; i < list.length; i++) { 62 try { 63 ResourceBundle bundle = 64 ResourceBundle.getBundle(config, list[i]); 65 if (bundle == null) 66 continue; 67 if (list[i].equals(bundle.getLocale())) { 68 localeLabels.add(list[i].getDisplayName()); 69 localeValues.add(list[i].toString()); 70 supportedLocales.add(list[i]); 71 } 72 } catch( Exception ex ) { 73 servlet.log("Missing locale " + list[i] ); 74 continue; 75 } 76 } 77 78 } 79 80 81 83 84 87 protected ArrayList localeLabels = new ArrayList (); 88 89 90 93 protected ArrayList localeValues = new ArrayList (); 94 95 96 99 protected ArrayList supportedLocales = new ArrayList (); 100 101 102 104 105 108 public List getLocaleLabels() { 109 110 return (localeLabels); 111 112 } 113 114 115 118 public List getLocaleValues() { 119 120 return (localeValues); 121 122 } 123 124 125 128 public List getSupportedLocales() { 129 130 return (supportedLocales); 131 132 } 133 134 135 } 136 | Popular Tags |