1 12 package org.displaytag.util; 13 14 import java.util.Iterator ; 15 import java.util.LinkedHashSet ; 16 import java.util.Set ; 17 18 import org.apache.commons.lang.StringUtils; 19 import org.apache.commons.lang.UnhandledException; 20 21 22 27 public class MultipleHtmlAttribute implements Cloneable 28 { 29 30 33 private Set attributeSet; 34 35 39 public MultipleHtmlAttribute(String attributeValue) 40 { 41 42 String [] attributes = StringUtils.split(attributeValue); 44 45 addAllAttributesFromArray(attributes); 46 } 47 48 52 private void addAllAttributesFromArray(String [] attributes) 53 { 54 55 int length = attributes.length; 57 58 this.attributeSet = new LinkedHashSet (length); 60 61 for (int j = 0; j < length; j++) 63 { 64 65 if (!StringUtils.isEmpty(attributes[j])) 67 { 68 this.attributeSet.add(attributes[j]); 69 } 70 71 } 72 } 73 74 78 public String toString() 79 { 80 StringBuffer buffer = new StringBuffer (); 81 82 Iterator iterator = this.attributeSet.iterator(); 83 84 while (iterator.hasNext()) 85 { 86 buffer.append(iterator.next()); 88 if (iterator.hasNext()) 89 { 90 buffer.append(' '); 92 } 93 } 94 95 return buffer.toString(); 96 } 97 98 102 public void addAttributeValue(String attributeValue) 103 { 104 if (!StringUtils.isEmpty(attributeValue)) 106 { 107 this.attributeSet.add(attributeValue); 108 } 109 110 } 111 112 115 protected Object clone() 116 { 117 MultipleHtmlAttribute clone; 118 119 try 120 { 121 clone = (MultipleHtmlAttribute) super.clone(); 122 } 123 catch (CloneNotSupportedException e) 124 { 125 throw new UnhandledException(e); 127 } 128 129 clone.addAllAttributesFromArray((String []) this.attributeSet.toArray(new String [this.attributeSet.size()])); 131 132 return clone; 133 } 134 135 } | Popular Tags |