210 |
*/ |
*/ |
211 |
public Element getElementById(String id) |
public Element getElementById(String id) |
212 |
{ |
{ |
213 |
DomDoctype doctype = (DomDoctype) getDoctype(); |
if (id == null || id.length() == 0) |
|
|
|
|
if (doctype == null || !doctype.hasIds() |
|
|
|| id == null || id.length() == 0) |
|
214 |
{ |
{ |
215 |
return null; |
return null; |
216 |
} |
} |
217 |
|
DomDoctype doctype = (DomDoctype) getDoctype(); |
218 |
|
if (doctype != null && !doctype.hasIds()) |
219 |
|
{ |
220 |
|
doctype = null; |
221 |
|
} |
222 |
|
|
223 |
// yes, this is linear in size of document. |
// yes, this is linear in size of document. |
224 |
// it'd be easy enough to maintain a hashtable. |
// it'd be easy enough to maintain a hashtable. |
235 |
if (current.getNodeType() == ELEMENT_NODE) |
if (current.getNodeType() == ELEMENT_NODE) |
236 |
{ |
{ |
237 |
DomElement element = (DomElement) current; |
DomElement element = (DomElement) current; |
238 |
DTDElementTypeInfo info = |
if (doctype != null) |
|
doctype.getElementTypeInfo(current.getNodeName()); |
|
|
if (info != null && |
|
|
id.equals(element.getAttribute(info.idAttrName))) |
|
|
{ |
|
|
return element; |
|
|
} |
|
|
else if (element.userIdAttrs != null) |
|
239 |
{ |
{ |
240 |
for (Iterator i = element.userIdAttrs.iterator(); |
DTDElementTypeInfo info = |
241 |
i.hasNext(); ) |
doctype.getElementTypeInfo(current.getNodeName()); |
242 |
|
if (info != null && |
243 |
|
id.equals(element.getAttribute(info.idAttrName))) |
244 |
{ |
{ |
245 |
Node idAttr = (Node) i.next(); |
return element; |
246 |
if (id.equals(idAttr.getNodeValue())) |
} |
247 |
|
else if (element.userIdAttrs != null) |
248 |
|
{ |
249 |
|
for (Iterator i = element.userIdAttrs.iterator(); |
250 |
|
i.hasNext(); ) |
251 |
{ |
{ |
252 |
return element; |
Node idAttr = (Node) i.next(); |
253 |
|
if (id.equals(idAttr.getNodeValue())) |
254 |
|
{ |
255 |
|
return element; |
256 |
|
} |
257 |
} |
} |
258 |
} |
} |
259 |
} |
} |
260 |
|
// xml:id |
261 |
|
String xmlId = element.getAttribute("xml:id"); |
262 |
|
if (xmlId == null) |
263 |
|
{ |
264 |
|
xmlId = element.getAttributeNS(XMLConstants.XML_NS_URI, |
265 |
|
"id"); |
266 |
|
} |
267 |
|
if (id.equals(xmlId)) |
268 |
|
{ |
269 |
|
return element; |
270 |
|
} |
271 |
} |
} |
272 |
|
|
273 |
// descend? |
// descend? |