All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.xmlform.util.I18NTexts Maven / Gradle / Ivy

package net.sf.xmlform.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

/**
 * @author Liu Zhikun
 */

public class I18NTexts implements Cloneable {
	private Map texts=new HashMap(2);
	public void put(I18NText text){
		texts.put(text.getLocale(),text);
	}
	public I18NText get(Locale language){
		if(!texts.containsKey(language))
			return null;
		return (I18NText)texts.get(language);
	}
	public void clear(){
		texts.clear();
	}
	public int size(){
		return texts.size();
	}
	public void putAll(I18NTexts texts){
		this.texts.putAll(texts.texts);
	}
	public boolean contains(Locale language){
		return texts.containsKey(language);
	}
	public I18NText remove(Locale language){
		I18NText text=get(language);
		texts.remove(language);
		return text;
	}
	public Set getLocales(){
		return texts.keySet();
	}
	public String getText(Locale locale){
		if(texts.size()==0)
    		return null;
    	if(locale==null)
    		locale=Locale.ENGLISH;
    	if(texts.size()==1)
    		return ((I18NText)texts.get((Locale)texts.keySet().iterator().next())).getText();
    	I18NText res=findI18NText(FormUtils.parseLocaleLevel(locale));
    	if(res!=null){
    		return res.getText();
    	}
    	res=findI18NText(FormUtils.parseLocaleLevel(FormUtils.parseLocale(null)));
    	return res==null?null:res.getText();
    }
    private I18NText findI18NText(List list){
    	for(int i=0;i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy