1 18 package org.apache.beehive.netui.tags.rendering; 19 20 import org.apache.beehive.netui.util.Bundle; 21 import org.apache.beehive.netui.util.logging.Logger; 22 23 import java.util.HashMap ; 24 import java.util.Map ; 25 26 abstract public class AbstractAttributeState extends AbstractTagState 27 { 28 private static final Logger logger = Logger.getInstance(AbstractAttributeState.class); 29 30 33 public static final String EMPTY_STRING = ""; 34 35 39 public static final int ATTR_GENERAL = 0; 40 41 private HashMap generalMap = null; 43 public HashMap getGeneralAttributeMap() 44 { 45 return generalMap; 46 } 47 48 57 public Map selectMap(int type, boolean createIfNull) 58 { 59 Map ret = null; 60 if (type == ATTR_GENERAL) { 61 if (generalMap == null && createIfNull) 62 generalMap = new HashMap (); 63 ret = generalMap; 64 } 65 66 return ret; 67 } 68 69 public void clear() 70 { 71 if (generalMap != null) 72 generalMap.clear(); 73 } 74 75 83 public void registerAttribute(int type, String attrName, String value, boolean ignoreEmpty) 84 { 85 assert(attrName != null); 86 87 if (value == null) 89 return; 90 if (ignoreEmpty && "".equals(value)) 91 return; 92 93 Map map = selectMap(type, true); 94 if (map == null) { 95 String s = Bundle.getString("Tags_ParameterAccessError", 96 new Object []{new Integer (type), attrName}); 97 logger.error(s); 98 return; 99 } 100 map.put(attrName, value); 101 } 102 103 public void registerAttribute(int type, String attrName, String value) 104 { 105 registerAttribute(type, attrName, value, true); 106 } 107 108 113 public void removeAttribute(int type, String attrName) 114 { 115 Map map = selectMap(type, false); 116 if (map == null) { 117 String s = Bundle.getString("Tags_ParameterAccessError", 118 new Object []{new Integer (type), attrName}); 119 logger.error(s); 120 return; 121 } 122 123 map.remove(attrName); 124 } 125 126 132 public String getAttribute(int type, String attrName) 133 { 134 Map map = selectMap(type, false); 135 if (map == null) 136 return null; 137 return (String ) map.get(attrName); 138 } 139 } 140 | Popular Tags |