1 30 31 34 package com.nightlabs.i18n; 35 36 import java.util.HashMap ; 37 import java.util.Iterator ; 38 import java.util.Map ; 39 import java.util.Map.Entry; 40 41 51 public class I18nTextBuffer extends I18nText 52 { 53 57 private Map texts = new HashMap (); 58 59 62 protected Map getI18nMap() 63 { 64 return texts; 65 } 66 67 private String text; 68 69 72 protected void setText(String localizedValue) 73 { 74 text = localizedValue; 75 } 76 77 80 public String getText() 81 { 82 return text; 83 } 84 85 88 protected String getFallBackValue(String languageID) 89 { 90 return languageID; 91 } 92 93 101 public void store(I18nText other) 102 { 103 Map otherI18nMap = other.getI18nMap(); 104 otherI18nMap.clear(); 105 for (Iterator it = texts.entrySet().iterator(); it.hasNext(); ) { 106 Map.Entry me = (Entry) it.next(); 107 Object key = me.getKey(); 108 Object value = me.getValue(); 109 110 if (value == null) 111 continue; 112 113 otherI18nMap.put(key, value); 114 } 115 } 116 117 125 public void load(I18nText other) 126 { 127 texts.clear(); 128 for (Iterator it = other.getI18nMap().entrySet().iterator(); it.hasNext(); ) { 129 Map.Entry me = (Entry) it.next(); 130 Object key = me.getKey(); 131 Object value = me.getValue(); 132 133 if (value == null) 134 continue; 135 136 if (!(key instanceof String )) 137 throw new IllegalArgumentException ("other's i18nMap contains a key which is an instance of " + key == null ? "null" : key.getClass().getName() + "! Must be String!"); 138 if (!(value instanceof String )) 139 throw new IllegalArgumentException ("other's i18nMap contains a value which is an instance of " + value.getClass().getName() + "! Must be String!"); 140 141 texts.put(key, value); 142 } 143 } 144 } 145 | Popular Tags |