1 16 package org.ajaxtags.helpers; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 import java.util.Set ; 21 22 import org.apache.commons.lang.builder.ToStringBuilder; 23 24 31 class Item<T> { 32 33 39 public void setAllAttributes(Map <String , String > attributes) { 40 if (attributes != null) { 41 for (String key : attributes.keySet()) { 42 setAttributes(key, attributes.get(key)); 43 } 44 } 45 } 46 47 51 public Set <String > getAttributeKeySet() { 52 return this.attributes.keySet(); 53 } 54 55 private Map <String , String > attributes = new HashMap <String , String >(); 56 57 63 public void removeAttribute(final String name) { 64 this.attributes.remove(name); 65 } 66 67 70 public void clearAttribute() { 71 this.attributes.clear(); 72 } 73 74 82 public void setAttributes(final String name, final String value) { 83 setAttributes(name, value, false); 84 } 85 86 96 public void setAttributes(final String name, final String value, 97 boolean evenIfNull) { 98 if (value == null && !evenIfNull) { 99 return; } 101 this.attributes.put(name.toLowerCase(), value); 102 } 103 104 111 public String getAttributeValue(final String name) { 112 return this.attributes.get(name); 113 } 114 115 protected String name; 116 117 protected T value; 118 119 protected boolean asData; 120 121 124 public Item() { 125 super(); 126 } 127 128 138 public Item(String name, T value, boolean asData) { 139 super(); 140 this.name = name; 141 this.value = value; 142 this.asData = asData; 143 } 144 145 148 public String getName() { 149 return this.name; 150 } 151 152 156 public void setName(String name) { 157 this.name = name; 158 } 159 160 163 public T getValue() { 164 return this.value; 165 } 166 167 171 public void setValue(T value) { 172 this.value = value; 173 } 174 175 178 public boolean isAsCData() { 179 return this.asData; 180 } 181 182 186 public void setAsData(boolean asData) { 187 this.asData = asData; 188 } 189 190 193 @Override  194 public String toString() { 195 ToStringBuilder builder = new ToStringBuilder(this).append("name", 196 this.name).append("value", this.value).append("asData", 197 this.asData); 198 for (String key : this.attributes.keySet()) { 200 builder.append(key, this.attributes.get(key)); 201 } 202 return builder.toString(); 203 } 204 205 } | Popular Tags |