1 17 package org.alfresco.web.config; 18 19 import java.util.ArrayList ; 20 import java.util.HashMap ; 21 import java.util.List ; 22 import java.util.Map ; 23 24 import org.alfresco.config.ConfigElement; 25 import org.alfresco.config.ConfigException; 26 import org.alfresco.config.element.ConfigElementAdapter; 27 28 33 public class LanguagesConfigElement extends ConfigElementAdapter 34 { 35 public static final String CONFIG_ELEMENT_ID = "languages"; 36 37 private Map <String , String > localeMap = new HashMap <String , String >(); 38 private List <String > languages = new ArrayList <String >(8); 39 40 43 public LanguagesConfigElement() 44 { 45 super(CONFIG_ELEMENT_ID); 46 } 47 48 53 public LanguagesConfigElement(String name) 54 { 55 super(name); 56 } 57 58 61 @Override 62 public List <ConfigElement> getChildren() 63 { 64 throw new ConfigException("Reading the languages config via the generic interfaces is not supported"); 65 } 66 67 70 public ConfigElement combine(ConfigElement configElement) 71 { 72 LanguagesConfigElement existingElement = (LanguagesConfigElement)configElement; 73 LanguagesConfigElement newElement = new LanguagesConfigElement(); 74 75 for (String locale : this.languages) 77 { 78 newElement.addLanguage(locale, this.localeMap.get(locale)); 79 } 80 81 List <String > languages = existingElement.getLanguages(); 84 for (String locale : languages) 85 { 86 if (newElement.getLabelForLanguage(locale) == null) 87 { 88 String label = existingElement.getLabelForLanguage(locale); 89 newElement.addLanguage(locale, label); 90 } 91 } 92 93 return newElement; 94 } 95 96 102 void addLanguage(String locale, String label) 103 { 104 this.localeMap.put(locale, label); 105 this.languages.add(locale); 106 } 107 108 111 public List <String > getLanguages() 112 { 113 return this.languages; 114 } 115 116 121 public String getLabelForLanguage(String locale) 122 { 123 return this.localeMap.get(locale); 124 } 125 } 126 | Popular Tags |