1 package org.apache.commons.digester3.substitution;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.xml.sax.Attributes;
23
24 import java.util.ArrayList;
25
26
27
28
29
30
31
32
33 public class VariableAttributes
34 implements Attributes
35 {
36
37
38 private ArrayList<String> values = new ArrayList<String>( 10 );
39
40 private Attributes attrs;
41
42 private VariableExpander expander;
43
44
45
46
47
48
49
50
51
52 public void init( Attributes attrs, VariableExpander expander )
53 {
54 this.attrs = attrs;
55 this.expander = expander;
56
57
58
59 values.clear();
60 }
61
62
63
64
65 public String getValue( int index )
66 {
67 if ( index >= values.size() )
68 {
69
70
71
72
73
74 values.ensureCapacity( index + 1 );
75 for ( int i = values.size(); i <= index; ++i )
76 {
77 values.add( null );
78 }
79 }
80
81 String s = values.get( index );
82
83 if ( s == null )
84 {
85
86
87
88 s = attrs.getValue( index );
89 if ( s != null )
90 {
91 s = expander.expand( s );
92 values.set( index, s );
93 }
94 }
95
96 return s;
97 }
98
99
100
101
102 public String getValue( String qname )
103 {
104 int index = attrs.getIndex( qname );
105 if ( index == -1 )
106 {
107 return null;
108 }
109 return getValue( index );
110 }
111
112
113
114
115 public String getValue( String uri, String localname )
116 {
117 int index = attrs.getIndex( uri, localname );
118 if ( index == -1 )
119 {
120 return null;
121 }
122 return getValue( index );
123 }
124
125
126
127
128
129 public int getIndex( String qname )
130 {
131 return attrs.getIndex( qname );
132 }
133
134
135
136
137 public int getIndex( String uri, String localpart )
138 {
139 return attrs.getIndex( uri, localpart );
140 }
141
142
143
144
145 public int getLength()
146 {
147 return attrs.getLength();
148 }
149
150
151
152
153 public String getLocalName( int index )
154 {
155 return attrs.getLocalName( index );
156 }
157
158
159
160
161 public String getQName( int index )
162 {
163 return attrs.getQName( index );
164 }
165
166
167
168
169 public String getType( int index )
170 {
171 return attrs.getType( index );
172 }
173
174
175
176
177 public String getType( String qname )
178 {
179 return attrs.getType( qname );
180 }
181
182
183
184
185 public String getType( String uri, String localname )
186 {
187 return attrs.getType( uri, localname );
188 }
189
190
191
192
193 public String getURI( int index )
194 {
195 return attrs.getURI( index );
196 }
197
198 }