1 17 package org.alfresco.web.config; 18 19 import java.util.Iterator ; 20 21 import org.alfresco.config.ConfigElement; 22 import org.alfresco.config.ConfigException; 23 import org.alfresco.config.xml.elementreader.ConfigElementReader; 24 import org.dom4j.Element; 25 26 31 public class LanguagesElementReader implements ConfigElementReader 32 { 33 public static final String ELEMENT_LANGUAGE = "language"; 34 public static final String ATTRIBUTE_LOCALE = "locale"; 35 36 39 @SuppressWarnings ("unchecked") 40 public ConfigElement parse(Element element) 41 { 42 LanguagesConfigElement configElement = null; 43 44 if (element != null) 45 { 46 String name = element.getName(); 47 if (name.equals(LanguagesConfigElement.CONFIG_ELEMENT_ID) == false) 48 { 49 throw new ConfigException("LanguagesElementReader can only parse " + 50 LanguagesConfigElement.CONFIG_ELEMENT_ID + " elements, the element passed was '" + 51 name + "'"); 52 } 53 54 configElement = new LanguagesConfigElement(); 55 56 Iterator <Element> langsItr = element.elementIterator(ELEMENT_LANGUAGE); 57 while (langsItr.hasNext()) 58 { 59 Element language = langsItr.next(); 60 String localeCode = language.attributeValue(ATTRIBUTE_LOCALE); 61 String label = language.getTextTrim(); 62 63 if (localeCode != null && localeCode.length() != 0 && 64 label != null && label.length() != 0) 65 { 66 configElement.addLanguage(localeCode, label); 68 } 69 } 70 } 71 72 return configElement; 73 } 74 } 75 | Popular Tags |