1 17 18 19 package org.apache.commons.digester.substitution; 20 21 import org.xml.sax.Attributes ; 22 23 import java.util.ArrayList ; 24 25 26 34 35 public class VariableAttributes implements Attributes { 36 37 private ArrayList values = new ArrayList (10); 39 40 private Attributes attrs; 41 private VariableExpander expander; 42 43 45 48 public void init(Attributes attrs, VariableExpander expander) { 49 this.attrs = attrs; 50 this.expander = expander; 51 52 values.clear(); 55 } 56 57 public String getValue(int index) { 58 if (index >= values.size()) { 59 values.ensureCapacity(index+1); 65 for(int i = values.size(); i<= index; ++i) { 66 values.add(null); 67 } 68 } 69 70 String s = (String ) values.get(index); 71 72 if (s == null) { 73 s = attrs.getValue(index); 77 if (s != null) { 78 s = expander.expand(s); 79 values.set(index, s); 80 } 81 } 82 83 return s; 84 } 85 86 public String getValue(String qname) { 87 int index = attrs.getIndex(qname); 88 if (index == -1) { 89 return null; 90 } 91 return getValue(index); 92 } 93 94 public String getValue(String uri, String localname) { 95 int index = attrs.getIndex(uri, localname); 96 if (index == -1) { 97 return null; 98 } 99 return getValue(index); 100 } 101 102 public int getIndex(String qname) { 104 return attrs.getIndex(qname); 105 } 106 107 public int getIndex(String uri, String localpart) { 108 return attrs.getIndex(uri, localpart); 109 } 110 111 public int getLength() { 112 return attrs.getLength(); 113 } 114 115 public String getLocalName(int index) { 116 return attrs.getLocalName(index); 117 } 118 119 public String getQName(int index) { 120 return attrs.getQName(index); 121 } 122 123 public String getType(int index) { 124 return attrs.getType(index); 125 } 126 127 public String getType(String qname) { 128 return attrs.getType(qname); 129 } 130 131 public String getType(String uri, String localname) { 132 return attrs.getType(uri, localname); 133 } 134 135 public String getURI(int index) { 136 return attrs.getURI(index); 137 } 138 139 } 140 | Popular Tags |