1 18 package org.apache.batik.dom.svg; 19 20 import org.apache.batik.dom.util.DoublyIndexedTable; 21 22 28 public class AttributeInitializer { 29 30 33 protected String [] keys; 34 35 38 protected int length; 39 40 43 protected DoublyIndexedTable values = new DoublyIndexedTable(); 44 45 48 public AttributeInitializer(int capacity) { 49 keys = new String [capacity * 3]; 50 } 51 52 59 public void addAttribute(String ns, String prefix, String ln, String val) { 60 int len = keys.length; 61 if (length == len) { 62 String [] t = new String [len * 2]; 63 for (int i = len - 1; i >= 0; --i) { 64 t[i] = keys[i]; 65 } 66 keys = t; 67 } 68 keys[length++] = ns; 69 keys[length++] = prefix; 70 keys[length++] = ln; 71 values.put(ns, ln, val); 72 } 73 74 77 public void initializeAttributes(AbstractElement elt) { 78 for (int i = length - 1; i >= 2; i -= 3) { 79 resetAttribute(elt, keys[i - 2], keys[i - 1], keys[i]); 80 } 81 } 82 83 92 public boolean resetAttribute(AbstractElement elt, 93 String ns, String prefix, String ln) { 94 String val = (String )values.get(ns, ln); 95 if (val == null) { 96 return false; 97 } 98 if (prefix != null) { 99 StringBuffer sb = new StringBuffer (prefix.length() + ln.length() + 1); 100 sb.append(prefix).append(':').append(ln); 101 ln = sb.toString(); 102 } 103 elt.setUnspecifiedAttribute(ns, ln, val); 104 return true; 105 } 106 } 107 | Popular Tags |