author | joehw |
Fri, 25 Sep 2015 16:42:19 -0700 | |
changeset 32791 | ed81078b4e7f |
parent 25868 | 686eef1e7a79 |
permissions | -rw-r--r-- |
6 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
4 |
*/ |
|
5 |
/* |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
7 |
* contributor license agreements. See the NOTICE file distributed with |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
8 |
* this work for additional information regarding copyright ownership. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
10 |
* (the "License"); you may not use this file except in compliance with |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
11 |
* the License. You may obtain a copy of the License at |
6 | 12 |
* |
13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
14 |
* |
|
15 |
* Unless required by applicable law or agreed to in writing, software |
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
18 |
* See the License for the specific language governing permissions and |
|
19 |
* limitations under the License. |
|
20 |
*/ |
|
21 |
package com.sun.org.apache.xerces.internal.dom; |
|
22 |
||
23 |
import org.w3c.dom.Attr; |
|
24 |
import org.w3c.dom.DOMException; |
|
25 |
import org.w3c.dom.Element; |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
26 |
import org.w3c.dom.ElementTraversal; |
6 | 27 |
import org.w3c.dom.NamedNodeMap; |
28 |
import org.w3c.dom.Node; |
|
29 |
import org.w3c.dom.NodeList; |
|
30 |
import org.w3c.dom.Text; |
|
31 |
import org.w3c.dom.TypeInfo; |
|
32 |
import com.sun.org.apache.xerces.internal.util.URI; |
|
33 |
||
34 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
35 |
* Elements represent most of the "markup" and structure of the document. They |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
36 |
* contain both the data for the element itself (element name and attributes), |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
37 |
* and any contained nodes, including document text (as children). |
6 | 38 |
* <P> |
39 |
* Elements may have Attributes associated with them; the API for this is |
|
40 |
* defined in Node, but the function is implemented here. In general, XML |
|
41 |
* applications should retrive Attributes as Nodes, since they may contain |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
42 |
* entity references and hence be a fairly complex sub-tree. HTML users will be |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
43 |
* dealing with simple string values, and convenience methods are provided to |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
44 |
* work in terms of Strings. |
6 | 45 |
* <P> |
46 |
* ElementImpl does not support Namespaces. ElementNSImpl, which inherits from |
|
47 |
* it, does. |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
48 |
* |
6 | 49 |
* @see ElementNSImpl |
50 |
* |
|
51 |
* @xerces.internal |
|
52 |
* |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
53 |
* @author Arnaud Le Hors, IBM |
6 | 54 |
* @author Joe Kesselman, IBM |
55 |
* @author Andy Clark, IBM |
|
56 |
* @author Ralf Pfeiffer, IBM |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
57 |
* @since PR-DOM-Level-1-19980818. |
6 | 58 |
*/ |
59 |
public class ElementImpl |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
60 |
extends ParentNode |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
61 |
implements Element, ElementTraversal, TypeInfo { |
6 | 62 |
|
63 |
// |
|
64 |
// Constants |
|
65 |
// |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
66 |
/** |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
67 |
* Serialization version. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
68 |
*/ |
6 | 69 |
static final long serialVersionUID = 3717253516652722278L; |
70 |
// |
|
71 |
// Data |
|
72 |
// |
|
73 |
||
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
74 |
/** |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
75 |
* Element name. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
76 |
*/ |
6 | 77 |
protected String name; |
78 |
||
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
79 |
/** |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
80 |
* Attributes. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
81 |
*/ |
6 | 82 |
protected AttributeMap attributes; |
83 |
||
84 |
// |
|
85 |
// Constructors |
|
86 |
// |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
87 |
/** |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
88 |
* Factory constructor. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
89 |
*/ |
6 | 90 |
public ElementImpl(CoreDocumentImpl ownerDoc, String name) { |
91 |
super(ownerDoc); |
|
92 |
this.name = name; |
|
93 |
needsSyncData(true); // synchronizeData will initialize attributes |
|
94 |
} |
|
95 |
||
96 |
// for ElementNSImpl |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
97 |
protected ElementImpl() { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
98 |
} |
6 | 99 |
|
100 |
// Support for DOM Level 3 renameNode method. |
|
101 |
// Note: This only deals with part of the pb. CoreDocumentImpl |
|
102 |
// does all the work. |
|
103 |
void rename(String name) { |
|
104 |
if (needsSyncData()) { |
|
105 |
synchronizeData(); |
|
106 |
} |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
107 |
if (ownerDocument.errorChecking) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
108 |
int colon1 = name.indexOf(':'); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
109 |
if (colon1 != -1) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
110 |
String msg |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
111 |
= DOMMessageFormatter.formatMessage( |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
112 |
DOMMessageFormatter.DOM_DOMAIN, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
113 |
"NAMESPACE_ERR", |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
114 |
null); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
115 |
throw new DOMException(DOMException.NAMESPACE_ERR, msg); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
116 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
117 |
if (!CoreDocumentImpl.isXMLName(name, ownerDocument.isXML11Version())) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
118 |
String msg = DOMMessageFormatter.formatMessage( |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
119 |
DOMMessageFormatter.DOM_DOMAIN, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
120 |
"INVALID_CHARACTER_ERR", null); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
121 |
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
122 |
msg); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
123 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
124 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
125 |
this.name = name; |
6 | 126 |
reconcileDefaultAttributes(); |
127 |
} |
|
128 |
||
129 |
// |
|
130 |
// Node methods |
|
131 |
// |
|
132 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
133 |
* A short integer indicating what type of node this is. The named constants |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
134 |
* for this value are defined in the org.w3c.dom.Node interface. |
6 | 135 |
*/ |
136 |
public short getNodeType() { |
|
137 |
return Node.ELEMENT_NODE; |
|
138 |
} |
|
139 |
||
140 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
141 |
* Returns the node name |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
142 |
* |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
143 |
* @return the node name |
6 | 144 |
*/ |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
145 |
@Override |
6 | 146 |
public String getNodeName() { |
147 |
if (needsSyncData()) { |
|
148 |
synchronizeData(); |
|
149 |
} |
|
150 |
return name; |
|
151 |
} |
|
152 |
||
153 |
/** |
|
154 |
* Retrieve all the Attributes as a set. Note that this API is inherited |
|
155 |
* from Node rather than specified on Element; in fact only Elements will |
|
156 |
* ever have Attributes, but they want to allow folks to "blindly" operate |
|
157 |
* on the tree as a set of Nodes. |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
158 |
* |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
159 |
* @return all Attributes |
6 | 160 |
*/ |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
161 |
@Override |
6 | 162 |
public NamedNodeMap getAttributes() { |
163 |
||
164 |
if (needsSyncData()) { |
|
165 |
synchronizeData(); |
|
166 |
} |
|
167 |
if (attributes == null) { |
|
168 |
attributes = new AttributeMap(this, null); |
|
169 |
} |
|
170 |
return attributes; |
|
171 |
||
172 |
} // getAttributes():NamedNodeMap |
|
173 |
||
174 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
175 |
* Return a duplicate copy of this Element. Note that its children will not |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
176 |
* be copied unless the "deep" flag is true, but Attributes are |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
177 |
* {@code always} replicated. |
6 | 178 |
* |
179 |
* @see org.w3c.dom.Node#cloneNode(boolean) |
|
180 |
*/ |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
181 |
@Override |
6 | 182 |
public Node cloneNode(boolean deep) { |
183 |
||
184 |
ElementImpl newnode = (ElementImpl) super.cloneNode(deep); |
|
185 |
// Replicate NamedNodeMap rather than sharing it. |
|
186 |
if (attributes != null) { |
|
187 |
newnode.attributes = (AttributeMap) attributes.cloneMap(newnode); |
|
188 |
} |
|
189 |
return newnode; |
|
190 |
||
191 |
} // cloneNode(boolean):Node |
|
192 |
||
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
193 |
/** |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
194 |
* DOM Level 3 WD - Experimental. Retrieve baseURI |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
195 |
* |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
196 |
* @return the baseURI |
6 | 197 |
*/ |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
198 |
@Override |
6 | 199 |
public String getBaseURI() { |
200 |
||
201 |
if (needsSyncData()) { |
|
202 |
synchronizeData(); |
|
203 |
} |
|
204 |
// Absolute base URI is computed according to |
|
205 |
// XML Base (http://www.w3.org/TR/xmlbase/#granularity) |
|
206 |
// 1. The base URI specified by an xml:base attribute on the element, |
|
207 |
// if one exists |
|
208 |
if (attributes != null) { |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
209 |
final Attr attrNode = getXMLBaseAttribute(); |
6 | 210 |
if (attrNode != null) { |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
211 |
final String uri = attrNode.getNodeValue(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
212 |
if (uri.length() != 0) {// attribute value is always empty string |
6 | 213 |
try { |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
214 |
URI _uri = new URI(uri, true); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
215 |
// If the URI is already absolute return it; otherwise it's relative and we need to resolve it. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
216 |
if (_uri.isAbsoluteURI()) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
217 |
return _uri.toString(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
218 |
} |
6 | 219 |
|
220 |
// Make any parentURI into a URI object to use with the URI(URI, String) constructor |
|
221 |
String parentBaseURI = (this.ownerNode != null) ? this.ownerNode.getBaseURI() : null; |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
222 |
if (parentBaseURI != null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
223 |
try { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
224 |
URI _parentBaseURI = new URI(parentBaseURI); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
225 |
_uri.absolutize(_parentBaseURI); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
226 |
return _uri.toString(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
227 |
} catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException ex) { |
6 | 228 |
// This should never happen: parent should have checked the URI and returned null if invalid. |
229 |
return null; |
|
230 |
} |
|
231 |
} |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
232 |
// REVISIT: what should happen in this case? |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
233 |
return null; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
234 |
} catch (com.sun.org.apache.xerces.internal.util.URI.MalformedURIException ex) { |
6 | 235 |
return null; |
236 |
} |
|
237 |
} |
|
238 |
} |
|
239 |
} |
|
240 |
||
241 |
// 2.the base URI of the element's parent element within the |
|
242 |
// document or external entity, if one exists |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
243 |
// 3. the base URI of the document entity or external entity |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
244 |
// containing the element |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
245 |
// ownerNode serves as a parent or as document |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
246 |
return (this.ownerNode != null) ? this.ownerNode.getBaseURI() : null; |
6 | 247 |
} //getBaseURI |
248 |
||
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
249 |
/** |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
250 |
* NON-DOM Returns the xml:base attribute. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
251 |
* |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
252 |
* @return the xml:base attribute |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
253 |
*/ |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
254 |
protected Attr getXMLBaseAttribute() { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
255 |
return (Attr) attributes.getNamedItem("xml:base"); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
256 |
} // getXMLBaseAttribute():Attr |
6 | 257 |
|
258 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
259 |
* NON-DOM set the ownerDocument of this node, its children, and its |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
260 |
* attributes |
6 | 261 |
*/ |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
262 |
@Override |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
263 |
protected void setOwnerDocument(CoreDocumentImpl doc) { |
6 | 264 |
super.setOwnerDocument(doc); |
265 |
if (attributes != null) { |
|
266 |
attributes.setOwnerDocument(doc); |
|
267 |
} |
|
268 |
} |
|
269 |
||
270 |
// |
|
271 |
// Element methods |
|
272 |
// |
|
273 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
274 |
* Look up a single Attribute by name. Returns the Attribute's string value, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
275 |
* or an empty string (NOT null!) to indicate that the name did not map to a |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
276 |
* currently defined attribute. |
6 | 277 |
* <p> |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
278 |
* Note: Attributes may contain complex node trees. This method returns the |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
279 |
* "flattened" string obtained from Attribute.getValue(). If you need the |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
280 |
* structure information, see getAttributeNode(). |
6 | 281 |
*/ |
282 |
public String getAttribute(String name) { |
|
283 |
||
284 |
if (needsSyncData()) { |
|
285 |
synchronizeData(); |
|
286 |
} |
|
287 |
if (attributes == null) { |
|
288 |
return ""; |
|
289 |
} |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
290 |
Attr attr = (Attr) (attributes.getNamedItem(name)); |
6 | 291 |
return (attr == null) ? "" : attr.getValue(); |
292 |
||
293 |
} // getAttribute(String):String |
|
294 |
||
295 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
296 |
* Look up a single Attribute by name. Returns the Attribute Node, so its |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
297 |
* complete child tree is available. This could be important in XML, where |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
298 |
* the string rendering may not be sufficient information. |
6 | 299 |
* <p> |
300 |
* If no matching attribute is available, returns null. |
|
301 |
*/ |
|
302 |
public Attr getAttributeNode(String name) { |
|
303 |
||
304 |
if (needsSyncData()) { |
|
305 |
synchronizeData(); |
|
306 |
} |
|
307 |
if (attributes == null) { |
|
308 |
return null; |
|
309 |
} |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
310 |
return (Attr) attributes.getNamedItem(name); |
6 | 311 |
|
312 |
} // getAttributeNode(String):Attr |
|
313 |
||
314 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
315 |
* Returns a NodeList of all descendent nodes (children, grandchildren, and |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
316 |
* so on) which are Elements and which have the specified tag name. |
6 | 317 |
* <p> |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
318 |
* Note: NodeList is a "live" view of the DOM. Its contents will change as |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
319 |
* the DOM changes, and alterations made to the NodeList will be reflected |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
320 |
* in the DOM. |
6 | 321 |
* |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
322 |
* @param tagname The type of element to gather. To obtain a list of all |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
323 |
* elements no matter what their names, use the wild-card tag name "*". |
6 | 324 |
* |
325 |
* @see DeepNodeListImpl |
|
326 |
*/ |
|
327 |
public NodeList getElementsByTagName(String tagname) { |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
328 |
return new DeepNodeListImpl(this, tagname); |
6 | 329 |
} |
330 |
||
331 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
332 |
* Returns the name of the Element. Note that Element.nodeName() is defined |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
333 |
* to also return the tag name. |
6 | 334 |
* <p> |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
335 |
* This is case-preserving in XML. HTML should uppercasify it on the way in. |
6 | 336 |
*/ |
337 |
public String getTagName() { |
|
338 |
if (needsSyncData()) { |
|
339 |
synchronizeData(); |
|
340 |
} |
|
341 |
return name; |
|
342 |
} |
|
343 |
||
344 |
/** |
|
345 |
* In "normal form" (as read from a source file), there will never be two |
|
346 |
* Text children in succession. But DOM users may create successive Text |
|
347 |
* nodes in the course of manipulating the document. Normalize walks the |
|
348 |
* sub-tree and merges adjacent Texts, as if the DOM had been written out |
|
349 |
* and read back in again. This simplifies implementation of higher-level |
|
350 |
* functions that may want to assume that the document is in standard form. |
|
351 |
* <p> |
|
352 |
* To normalize a Document, normalize its top-level Element child. |
|
353 |
* <p> |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
354 |
* As of PR-DOM-Level-1-19980818, CDATA -- despite being a subclass of Text |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
355 |
* -- is considered "markup" and will _not_ be merged either with normal |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
356 |
* Text or with other CDATASections. |
6 | 357 |
*/ |
358 |
public void normalize() { |
|
359 |
// No need to normalize if already normalized. |
|
360 |
if (isNormalized()) { |
|
361 |
return; |
|
362 |
} |
|
363 |
if (needsSyncChildren()) { |
|
364 |
synchronizeChildren(); |
|
365 |
} |
|
366 |
ChildNode kid, next; |
|
367 |
for (kid = firstChild; kid != null; kid = next) { |
|
368 |
next = kid.nextSibling; |
|
369 |
||
370 |
// If kid is a text node, we need to check for one of two |
|
371 |
// conditions: |
|
372 |
// 1) There is an adjacent text node |
|
373 |
// 2) There is no adjacent text node, but kid is |
|
374 |
// an empty text node. |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
375 |
if (kid.getNodeType() == Node.TEXT_NODE) { |
6 | 376 |
// If an adjacent text node, merge it with kid |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
377 |
if (next != null && next.getNodeType() == Node.TEXT_NODE) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
378 |
((Text) kid).appendData(next.getNodeValue()); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
379 |
removeChild(next); |
6 | 380 |
next = kid; // Don't advance; there might be another. |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
381 |
} else { |
6 | 382 |
// If kid is empty, remove it |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
383 |
if (kid.getNodeValue() == null || kid.getNodeValue().length() == 0) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
384 |
removeChild(kid); |
6 | 385 |
} |
386 |
} |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
387 |
} // Otherwise it might be an Element, which is handled recursively |
6 | 388 |
else if (kid.getNodeType() == Node.ELEMENT_NODE) { |
389 |
kid.normalize(); |
|
390 |
} |
|
391 |
} |
|
392 |
||
393 |
// We must also normalize all of the attributes |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
394 |
if (attributes != null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
395 |
for (int i = 0; i < attributes.getLength(); ++i) { |
6 | 396 |
Node attr = attributes.item(i); |
397 |
attr.normalize(); |
|
398 |
} |
|
399 |
} |
|
400 |
||
401 |
// changed() will have occurred when the removeChild() was done, |
|
402 |
// so does not have to be reissued. |
|
403 |
isNormalized(true); |
|
404 |
} // normalize() |
|
405 |
||
406 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
407 |
* Remove the named attribute from this Element. If the removed Attribute |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
408 |
* has a default value, it is immediately replaced thereby. |
6 | 409 |
* <P> |
410 |
* The default logic is actually implemented in NamedNodeMapImpl. |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
411 |
* PR-DOM-Level-1-19980818 doesn't fully address the DTD, so some of this |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
412 |
* behavior is likely to change in future versions. ????? |
6 | 413 |
* <P> |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
414 |
* Note that this call "succeeds" even if no attribute by this name existed |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
415 |
* -- unlike removeAttributeNode, which will throw a not-found exception in |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
416 |
* that case. |
6 | 417 |
* |
418 |
* @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if the node is |
|
419 |
* readonly. |
|
420 |
*/ |
|
421 |
public void removeAttribute(String name) { |
|
422 |
||
423 |
if (ownerDocument.errorChecking && isReadOnly()) { |
|
424 |
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); |
|
425 |
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg); |
|
426 |
} |
|
427 |
||
428 |
if (needsSyncData()) { |
|
429 |
synchronizeData(); |
|
430 |
} |
|
431 |
||
432 |
if (attributes == null) { |
|
433 |
return; |
|
434 |
} |
|
435 |
||
436 |
attributes.safeRemoveNamedItem(name); |
|
437 |
||
438 |
} // removeAttribute(String) |
|
439 |
||
440 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
441 |
* Remove the specified attribute/value pair. If the removed Attribute has a |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
442 |
* default value, it is immediately replaced. |
6 | 443 |
* <p> |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
444 |
* NOTE: Specifically removes THIS NODE -- not the node with this name, nor |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
445 |
* the node with these contents. If the specific Attribute object passed in |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
446 |
* is not stored in this Element, we throw a DOMException. If you really |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
447 |
* want to remove an attribute by name, use removeAttribute(). |
6 | 448 |
* |
449 |
* @return the Attribute object that was removed. |
|
450 |
* @throws DOMException(NOT_FOUND_ERR) if oldattr is not an attribute of |
|
451 |
* this Element. |
|
452 |
* @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if the node is |
|
453 |
* readonly. |
|
454 |
*/ |
|
455 |
public Attr removeAttributeNode(Attr oldAttr) |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
456 |
throws DOMException { |
6 | 457 |
|
458 |
if (ownerDocument.errorChecking && isReadOnly()) { |
|
459 |
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); |
|
460 |
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg); |
|
461 |
} |
|
462 |
||
463 |
if (needsSyncData()) { |
|
464 |
synchronizeData(); |
|
465 |
} |
|
466 |
||
467 |
if (attributes == null) { |
|
468 |
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null); |
|
469 |
throw new DOMException(DOMException.NOT_FOUND_ERR, msg); |
|
470 |
} |
|
471 |
return (Attr) attributes.removeItem(oldAttr, true); |
|
472 |
||
473 |
} // removeAttributeNode(Attr):Attr |
|
474 |
||
475 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
476 |
* Add a new name/value pair, or replace the value of the existing attribute |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
477 |
* having that name. |
6 | 478 |
* |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
479 |
* Note: this method supports only the simplest kind of Attribute, one whose |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
480 |
* value is a string contained in a single Text node. If you want to assert |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
481 |
* a more complex value (which XML permits, though HTML doesn't), see |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
482 |
* setAttributeNode(). |
6 | 483 |
* |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
484 |
* The attribute is created with specified=true, meaning it's an explicit |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
485 |
* value rather than inherited from the DTD as a default. Again, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
486 |
* setAttributeNode can be used to achieve other results. |
6 | 487 |
* |
488 |
* @throws DOMException(INVALID_NAME_ERR) if the name is not acceptable. |
|
489 |
* (Attribute factory will do that test for us.) |
|
490 |
* |
|
491 |
* @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if the node is |
|
492 |
* readonly. |
|
493 |
*/ |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
494 |
public void setAttribute(String name, String value) { |
6 | 495 |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
496 |
if (ownerDocument.errorChecking && isReadOnly()) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
497 |
String msg |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
498 |
= DOMMessageFormatter.formatMessage( |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
499 |
DOMMessageFormatter.DOM_DOMAIN, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
500 |
"NO_MODIFICATION_ALLOWED_ERR", |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
501 |
null); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
502 |
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
503 |
} |
6 | 504 |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
505 |
if (needsSyncData()) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
506 |
synchronizeData(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
507 |
} |
6 | 508 |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
509 |
Attr newAttr = getAttributeNode(name); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
510 |
if (newAttr == null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
511 |
newAttr = getOwnerDocument().createAttribute(name); |
6 | 512 |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
513 |
if (attributes == null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
514 |
attributes = new AttributeMap(this, null); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
515 |
} |
6 | 516 |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
517 |
newAttr.setNodeValue(value); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
518 |
attributes.setNamedItem(newAttr); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
519 |
} else { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
520 |
newAttr.setNodeValue(value); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
521 |
} |
6 | 522 |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
523 |
} // setAttribute(String,String) |
6 | 524 |
|
525 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
526 |
* Add a new attribute/value pair, or replace the value of the existing |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
527 |
* attribute with that name. |
6 | 528 |
* <P> |
529 |
* This method allows you to add an Attribute that has already been |
|
530 |
* constructed, and hence avoids the limitations of the simple |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
531 |
* setAttribute() call. It can handle attribute values that have arbitrarily |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
532 |
* complex tree structure -- in particular, those which had entity |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
533 |
* references mixed into their text. |
6 | 534 |
* |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
535 |
* @throws DOMException(INUSE_ATTRIBUTE_ERR) if the Attribute object has |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
536 |
* already been assigned to another Element. |
6 | 537 |
*/ |
538 |
public Attr setAttributeNode(Attr newAttr) |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
539 |
throws DOMException { |
6 | 540 |
|
541 |
if (needsSyncData()) { |
|
542 |
synchronizeData(); |
|
543 |
} |
|
544 |
||
545 |
if (ownerDocument.errorChecking) { |
|
546 |
if (isReadOnly()) { |
|
547 |
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); |
|
548 |
throw new DOMException( |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
549 |
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
550 |
msg); |
6 | 551 |
} |
552 |
||
553 |
if (newAttr.getOwnerDocument() != ownerDocument) { |
|
554 |
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null); |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
555 |
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg); |
6 | 556 |
} |
557 |
} |
|
558 |
||
559 |
if (attributes == null) { |
|
560 |
attributes = new AttributeMap(this, null); |
|
561 |
} |
|
562 |
// This will throw INUSE if necessary |
|
563 |
return (Attr) attributes.setNamedItem(newAttr); |
|
564 |
||
565 |
} // setAttributeNode(Attr):Attr |
|
566 |
||
567 |
// |
|
568 |
// DOM2: Namespace methods |
|
569 |
// |
|
570 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
571 |
* Introduced in DOM Level 2. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
572 |
* <p> |
6 | 573 |
* |
574 |
* Retrieves an attribute value by local name and namespace URI. |
|
575 |
* |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
576 |
* @param namespaceURI The namespace URI of the attribute to retrieve. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
577 |
* @param localName The local name of the attribute to retrieve. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
578 |
* @return String The Attr value as a string, or empty string if that |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
579 |
* attribute does not have a specified or default value. |
6 | 580 |
* @since WD-DOM-Level-2-19990923 |
581 |
*/ |
|
582 |
public String getAttributeNS(String namespaceURI, String localName) { |
|
583 |
||
584 |
if (needsSyncData()) { |
|
585 |
synchronizeData(); |
|
586 |
} |
|
587 |
||
588 |
if (attributes == null) { |
|
589 |
return ""; |
|
590 |
} |
|
591 |
||
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
592 |
Attr attr = (Attr) (attributes.getNamedItemNS(namespaceURI, localName)); |
6 | 593 |
return (attr == null) ? "" : attr.getValue(); |
594 |
||
595 |
} // getAttributeNS(String,String):String |
|
596 |
||
597 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
598 |
* Introduced in DOM Level 2. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
599 |
* <p> |
6 | 600 |
* |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
601 |
* Adds a new attribute. If the given namespaceURI is null or an empty |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
602 |
* string and the qualifiedName has a prefix that is "xml", the new |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
603 |
* attribute is bound to the predefined namespace |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
604 |
* "http://www.w3.org/XML/1998/namespace" [Namespaces]. If an attribute with |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
605 |
* the same local name and namespace URI is already present on the element, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
606 |
* its prefix is changed to be the prefix part of the qualifiedName, and its |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
607 |
* value is changed to be the value parameter. This value is a simple |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
608 |
* string, it is not parsed as it is being set. So any markup (such as |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
609 |
* syntax to be recognized as an entity reference) is treated as literal |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
610 |
* text, and needs to be appropriately escaped by the implementation when it |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
611 |
* is written out. In order to assign an attribute value that contains |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
612 |
* entity references, the user must create an Attr node plus any Text and |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
613 |
* EntityReference nodes, build the appropriate subtree, and use |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
614 |
* setAttributeNodeNS or setAttributeNode to assign it as the value of an |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
615 |
* attribute. |
6 | 616 |
* |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
617 |
* @param namespaceURI The namespace URI of the attribute to create or |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
618 |
* alter. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
619 |
* @param qualifiedName The qualified name of the attribute to create or |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
620 |
* alter. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
621 |
* @param value The value to set in string form. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
622 |
* @throws INVALID_CHARACTER_ERR: Raised if the specified name contains an |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
623 |
* invalid character. |
6 | 624 |
* |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
625 |
* @throws NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
626 |
* |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
627 |
* @throws NAMESPACE_ERR: Raised if the qualifiedName has a prefix that is |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
628 |
* "xml" and the namespaceURI is neither null nor an empty string nor |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
629 |
* "http://www.w3.org/XML/1998/namespace", or if the qualifiedName has a |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
630 |
* prefix that is "xmlns" but the namespaceURI is neither null nor an empty |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
631 |
* string, or if if the qualifiedName has a prefix different from "xml" and |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
632 |
* "xmlns" and the namespaceURI is null or an empty string. |
6 | 633 |
* @since WD-DOM-Level-2-19990923 |
634 |
*/ |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
635 |
public void setAttributeNS(String namespaceURI, String qualifiedName, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
636 |
String value) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
637 |
if (ownerDocument.errorChecking && isReadOnly()) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
638 |
String msg |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
639 |
= DOMMessageFormatter.formatMessage( |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
640 |
DOMMessageFormatter.DOM_DOMAIN, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
641 |
"NO_MODIFICATION_ALLOWED_ERR", |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
642 |
null); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
643 |
throw new DOMException( |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
644 |
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
645 |
msg); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
646 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
647 |
if (needsSyncData()) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
648 |
synchronizeData(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
649 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
650 |
int index = qualifiedName.indexOf(':'); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
651 |
String prefix, localName; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
652 |
if (index < 0) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
653 |
prefix = null; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
654 |
localName = qualifiedName; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
655 |
} else { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
656 |
prefix = qualifiedName.substring(0, index); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
657 |
localName = qualifiedName.substring(index + 1); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
658 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
659 |
Attr newAttr = getAttributeNodeNS(namespaceURI, localName); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
660 |
if (newAttr == null) { |
6 | 661 |
// REVISIT: this is not efficient, we are creating twice the same |
662 |
// strings for prefix and localName. |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
663 |
newAttr = getOwnerDocument().createAttributeNS( |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
664 |
namespaceURI, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
665 |
qualifiedName); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
666 |
if (attributes == null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
667 |
attributes = new AttributeMap(this, null); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
668 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
669 |
newAttr.setNodeValue(value); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
670 |
attributes.setNamedItemNS(newAttr); |
6 | 671 |
} |
672 |
else { |
|
673 |
if (newAttr instanceof AttrNSImpl){ |
|
674 |
String origNodeName = ((AttrNSImpl) newAttr).name; |
|
675 |
String newName = (prefix!=null) ? (prefix+":"+localName) : localName; |
|
676 |
||
677 |
((AttrNSImpl) newAttr).name = newName; |
|
678 |
||
679 |
if (!newName.equals(origNodeName)) { |
|
680 |
// Note: we can't just change the name of the attribute. Names have to be in sorted |
|
681 |
// order in the attributes vector because a binary search is used to locate them. |
|
682 |
// If the new name has a different prefix, the list may become unsorted. |
|
683 |
// Maybe it would be better to resort the list, but the simplest |
|
684 |
// fix seems to be to remove the old attribute and re-insert it. |
|
685 |
// -- Norman.Walsh@Sun.COM, 2 Feb 2007 |
|
686 |
newAttr = (Attr) attributes.removeItem(newAttr, false); |
|
687 |
attributes.addItem(newAttr); |
|
688 |
} |
|
689 |
} |
|
690 |
else { |
|
691 |
// This case may happen if user calls: |
|
692 |
// elem.setAttribute("name", "value"); |
|
693 |
// elem.setAttributeNS(null, "name", "value"); |
|
694 |
// This case is not defined by the DOM spec, we choose |
|
695 |
// to create a new attribute in this case and remove an old one from the tree |
|
696 |
// note this might cause events to be propagated or user data to be lost |
|
697 |
newAttr = new AttrNSImpl((CoreDocumentImpl)getOwnerDocument(), namespaceURI, qualifiedName, localName); |
|
698 |
attributes.setNamedItemNS(newAttr); |
|
699 |
} |
|
700 |
||
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
701 |
newAttr.setNodeValue(value); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
702 |
} |
6 | 703 |
|
704 |
} // setAttributeNS(String,String,String) |
|
705 |
||
706 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
707 |
* Introduced in DOM Level 2. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
708 |
* <p> |
6 | 709 |
* |
710 |
* Removes an attribute by local name and namespace URI. If the removed |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
711 |
* attribute has a default value it is immediately replaced. The replacing |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
712 |
* attribute has the same namespace URI and local name, as well as the |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
713 |
* original prefix.<p> |
6 | 714 |
* |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
715 |
* @param namespaceURI The namespace URI of the attribute to remove. |
6 | 716 |
* |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
717 |
* @param localName The local name of the attribute to remove. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
718 |
* @throws NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. |
6 | 719 |
* @since WD-DOM-Level-2-19990923 |
720 |
*/ |
|
721 |
public void removeAttributeNS(String namespaceURI, String localName) { |
|
722 |
||
723 |
if (ownerDocument.errorChecking && isReadOnly()) { |
|
724 |
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); |
|
725 |
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg); |
|
726 |
} |
|
727 |
||
728 |
if (needsSyncData()) { |
|
729 |
synchronizeData(); |
|
730 |
} |
|
731 |
||
732 |
if (attributes == null) { |
|
733 |
return; |
|
734 |
} |
|
735 |
||
736 |
attributes.safeRemoveNamedItemNS(namespaceURI, localName); |
|
737 |
||
738 |
} // removeAttributeNS(String,String) |
|
739 |
||
740 |
/** |
|
741 |
* Retrieves an Attr node by local name and namespace URI. |
|
742 |
* |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
743 |
* @param namespaceURI The namespace URI of the attribute to retrieve. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
744 |
* @param localName The local name of the attribute to retrieve. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
745 |
* @return Attr The Attr node with the specified attribute local name and |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
746 |
* namespace URI or null if there is no such attribute. |
6 | 747 |
* @since WD-DOM-Level-2-19990923 |
748 |
*/ |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
749 |
public Attr getAttributeNodeNS(String namespaceURI, String localName) { |
6 | 750 |
|
751 |
if (needsSyncData()) { |
|
752 |
synchronizeData(); |
|
753 |
} |
|
754 |
if (attributes == null) { |
|
755 |
return null; |
|
756 |
} |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
757 |
return (Attr) attributes.getNamedItemNS(namespaceURI, localName); |
6 | 758 |
|
759 |
} // getAttributeNodeNS(String,String):Attr |
|
760 |
||
761 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
762 |
* Introduced in DOM Level 2. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
763 |
* <p> |
6 | 764 |
* |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
765 |
* Adds a new attribute. If an attribute with that local name and namespace |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
766 |
* URI is already present in the element, it is replaced by the new one. |
6 | 767 |
* |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
768 |
* @param newAttr The Attr node to add to the attribute list. When the Node |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
769 |
* has no namespaceURI, this method behaves like setAttributeNode. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
770 |
* @return Attr If the newAttr attribute replaces an existing attribute with |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
771 |
* the same local name and namespace URI, the * previously existing Attr |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
772 |
* node is returned, otherwise null is returned. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
773 |
* @throws WRONG_DOCUMENT_ERR: Raised if newAttr was created from a |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
774 |
* different document than the one that created the element. |
6 | 775 |
* |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
776 |
* @throws NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. |
6 | 777 |
* |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
778 |
* @throws INUSE_ATTRIBUTE_ERR: Raised if newAttr is already an attribute of |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
779 |
* another Element object. The DOM user must explicitly clone Attr nodes to |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
780 |
* re-use them in other elements. |
6 | 781 |
* @since WD-DOM-Level-2-19990923 |
782 |
*/ |
|
783 |
public Attr setAttributeNodeNS(Attr newAttr) |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
784 |
throws DOMException { |
6 | 785 |
|
786 |
if (needsSyncData()) { |
|
787 |
synchronizeData(); |
|
788 |
} |
|
789 |
if (ownerDocument.errorChecking) { |
|
790 |
if (isReadOnly()) { |
|
791 |
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
792 |
throw new DOMException( |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
793 |
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
794 |
msg); |
6 | 795 |
} |
796 |
if (newAttr.getOwnerDocument() != ownerDocument) { |
|
797 |
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null); |
|
798 |
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg); |
|
799 |
} |
|
800 |
} |
|
801 |
||
802 |
if (attributes == null) { |
|
803 |
attributes = new AttributeMap(this, null); |
|
804 |
} |
|
805 |
// This will throw INUSE if necessary |
|
806 |
return (Attr) attributes.setNamedItemNS(newAttr); |
|
807 |
||
808 |
} // setAttributeNodeNS(Attr):Attr |
|
809 |
||
810 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
811 |
* NON-DOM: sets attribute node for this element |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
812 |
*/ |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
813 |
protected int setXercesAttributeNode(Attr attr) { |
6 | 814 |
|
815 |
if (needsSyncData()) { |
|
816 |
synchronizeData(); |
|
817 |
} |
|
818 |
||
819 |
if (attributes == null) { |
|
820 |
attributes = new AttributeMap(this, null); |
|
821 |
} |
|
822 |
return attributes.addItem(attr); |
|
823 |
||
824 |
} |
|
825 |
||
826 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
827 |
* NON-DOM: get inded of an attribute |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
828 |
*/ |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
829 |
protected int getXercesAttribute(String namespaceURI, String localName) { |
6 | 830 |
|
831 |
if (needsSyncData()) { |
|
832 |
synchronizeData(); |
|
833 |
} |
|
834 |
if (attributes == null) { |
|
835 |
return -1; |
|
836 |
} |
|
837 |
return attributes.getNamedItemIndex(namespaceURI, localName); |
|
838 |
||
839 |
} |
|
840 |
||
841 |
/** |
|
842 |
* Introduced in DOM Level 2. |
|
843 |
*/ |
|
844 |
public boolean hasAttributes() { |
|
845 |
if (needsSyncData()) { |
|
846 |
synchronizeData(); |
|
847 |
} |
|
848 |
return (attributes != null && attributes.getLength() != 0); |
|
849 |
} |
|
850 |
||
851 |
/** |
|
852 |
* Introduced in DOM Level 2. |
|
853 |
*/ |
|
854 |
public boolean hasAttribute(String name) { |
|
855 |
return getAttributeNode(name) != null; |
|
856 |
} |
|
857 |
||
858 |
/** |
|
859 |
* Introduced in DOM Level 2. |
|
860 |
*/ |
|
861 |
public boolean hasAttributeNS(String namespaceURI, String localName) { |
|
862 |
return getAttributeNodeNS(namespaceURI, localName) != null; |
|
863 |
} |
|
864 |
||
865 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
866 |
* Introduced in DOM Level 2. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
867 |
* <p> |
6 | 868 |
* |
869 |
* Returns a NodeList of all the Elements with a given local name and |
|
870 |
* namespace URI in the order in which they would be encountered in a |
|
871 |
* preorder traversal of the Document tree, starting from this node. |
|
872 |
* |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
873 |
* @param namespaceURI The namespace URI of the elements to match on. The |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
874 |
* special value "*" matches all namespaces. When it is null or an empty |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
875 |
* string, this method behaves like getElementsByTagName. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
876 |
* @param localName The local name of the elements to match on. The special |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
877 |
* value "*" matches all local names. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
878 |
* @return NodeList A new NodeList object containing all the matched |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
879 |
* Elements. |
6 | 880 |
* @since WD-DOM-Level-2-19990923 |
881 |
*/ |
|
882 |
public NodeList getElementsByTagNameNS(String namespaceURI, |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
883 |
String localName) { |
6 | 884 |
return new DeepNodeListImpl(this, namespaceURI, localName); |
885 |
} |
|
886 |
||
887 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
888 |
* DOM Level 3 WD- Experimental. Override inherited behavior from NodeImpl |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
889 |
* and ParentNode to check on attributes |
6 | 890 |
*/ |
891 |
public boolean isEqualNode(Node arg) { |
|
892 |
if (!super.isEqualNode(arg)) { |
|
893 |
return false; |
|
894 |
} |
|
895 |
boolean hasAttrs = hasAttributes(); |
|
896 |
if (hasAttrs != ((Element) arg).hasAttributes()) { |
|
897 |
return false; |
|
898 |
} |
|
899 |
if (hasAttrs) { |
|
900 |
NamedNodeMap map1 = getAttributes(); |
|
901 |
NamedNodeMap map2 = ((Element) arg).getAttributes(); |
|
902 |
int len = map1.getLength(); |
|
903 |
if (len != map2.getLength()) { |
|
904 |
return false; |
|
905 |
} |
|
906 |
for (int i = 0; i < len; i++) { |
|
907 |
Node n1 = map1.item(i); |
|
908 |
if (n1.getLocalName() == null) { // DOM Level 1 Node |
|
909 |
Node n2 = map2.getNamedItem(n1.getNodeName()); |
|
910 |
if (n2 == null || !((NodeImpl) n1).isEqualNode(n2)) { |
|
911 |
return false; |
|
912 |
} |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
913 |
} else { |
6 | 914 |
Node n2 = map2.getNamedItemNS(n1.getNamespaceURI(), |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
915 |
n1.getLocalName()); |
6 | 916 |
if (n2 == null || !((NodeImpl) n1).isEqualNode(n2)) { |
917 |
return false; |
|
918 |
} |
|
919 |
} |
|
920 |
} |
|
921 |
} |
|
922 |
return true; |
|
923 |
} |
|
924 |
||
925 |
/** |
|
926 |
* DOM Level 3: register the given attribute node as an ID attribute |
|
927 |
*/ |
|
928 |
public void setIdAttributeNode(Attr at, boolean makeId) { |
|
929 |
if (needsSyncData()) { |
|
930 |
synchronizeData(); |
|
931 |
} |
|
932 |
if (ownerDocument.errorChecking) { |
|
933 |
if (isReadOnly()) { |
|
934 |
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); |
|
935 |
throw new DOMException( |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
936 |
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
937 |
msg); |
6 | 938 |
} |
939 |
||
940 |
if (at.getOwnerElement() != this) { |
|
941 |
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null); |
|
942 |
throw new DOMException(DOMException.NOT_FOUND_ERR, msg); |
|
943 |
} |
|
944 |
} |
|
945 |
((AttrImpl) at).isIdAttribute(makeId); |
|
946 |
if (!makeId) { |
|
947 |
ownerDocument.removeIdentifier(at.getValue()); |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
948 |
} else { |
6 | 949 |
ownerDocument.putIdentifier(at.getValue(), this); |
950 |
} |
|
951 |
} |
|
952 |
||
953 |
/** |
|
954 |
* DOM Level 3: register the given attribute node as an ID attribute |
|
955 |
*/ |
|
956 |
public void setIdAttribute(String name, boolean makeId) { |
|
957 |
if (needsSyncData()) { |
|
958 |
synchronizeData(); |
|
959 |
} |
|
960 |
Attr at = getAttributeNode(name); |
|
961 |
||
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
962 |
if (at == null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
963 |
String msg = DOMMessageFormatter.formatMessage( |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
964 |
DOMMessageFormatter.DOM_DOMAIN, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
965 |
"NOT_FOUND_ERR", null); |
6 | 966 |
throw new DOMException(DOMException.NOT_FOUND_ERR, msg); |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
967 |
} |
6 | 968 |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
969 |
if (ownerDocument.errorChecking) { |
6 | 970 |
if (isReadOnly()) { |
971 |
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); |
|
972 |
throw new DOMException( |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
973 |
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
974 |
msg); |
6 | 975 |
} |
976 |
||
977 |
if (at.getOwnerElement() != this) { |
|
978 |
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null); |
|
979 |
throw new DOMException(DOMException.NOT_FOUND_ERR, msg); |
|
980 |
} |
|
981 |
} |
|
982 |
||
983 |
((AttrImpl) at).isIdAttribute(makeId); |
|
984 |
if (!makeId) { |
|
985 |
ownerDocument.removeIdentifier(at.getValue()); |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
986 |
} else { |
6 | 987 |
ownerDocument.putIdentifier(at.getValue(), this); |
988 |
} |
|
989 |
} |
|
990 |
||
991 |
/** |
|
992 |
* DOM Level 3: register the given attribute node as an ID attribute |
|
993 |
*/ |
|
994 |
public void setIdAttributeNS(String namespaceURI, String localName, |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
995 |
boolean makeId) { |
6 | 996 |
if (needsSyncData()) { |
997 |
synchronizeData(); |
|
998 |
} |
|
999 |
//if namespace uri is empty string, set it to 'null' |
|
1000 |
if (namespaceURI != null) { |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1001 |
namespaceURI = (namespaceURI.length() == 0) ? null : namespaceURI; |
6 | 1002 |
} |
1003 |
Attr at = getAttributeNodeNS(namespaceURI, localName); |
|
1004 |
||
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1005 |
if (at == null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1006 |
String msg = DOMMessageFormatter.formatMessage( |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1007 |
DOMMessageFormatter.DOM_DOMAIN, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1008 |
"NOT_FOUND_ERR", null); |
6 | 1009 |
throw new DOMException(DOMException.NOT_FOUND_ERR, msg); |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1010 |
} |
6 | 1011 |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1012 |
if (ownerDocument.errorChecking) { |
6 | 1013 |
if (isReadOnly()) { |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1014 |
String msg = DOMMessageFormatter.formatMessage( |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1015 |
DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); |
6 | 1016 |
throw new DOMException( |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1017 |
DOMException.NO_MODIFICATION_ALLOWED_ERR, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1018 |
msg); |
6 | 1019 |
} |
1020 |
||
1021 |
if (at.getOwnerElement() != this) { |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1022 |
String msg = DOMMessageFormatter.formatMessage( |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1023 |
DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null); |
6 | 1024 |
throw new DOMException(DOMException.NOT_FOUND_ERR, msg); |
1025 |
} |
|
1026 |
} |
|
1027 |
((AttrImpl) at).isIdAttribute(makeId); |
|
1028 |
if (!makeId) { |
|
1029 |
ownerDocument.removeIdentifier(at.getValue()); |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1030 |
} else { |
6 | 1031 |
ownerDocument.putIdentifier(at.getValue(), this); |
1032 |
} |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1033 |
} |
6 | 1034 |
|
1035 |
/** |
|
1036 |
* @see org.w3c.dom.TypeInfo#getTypeName() |
|
1037 |
*/ |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1038 |
public String getTypeName() { |
6 | 1039 |
return null; |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1040 |
} |
6 | 1041 |
|
1042 |
/** |
|
1043 |
* @see org.w3c.dom.TypeInfo#getTypeNamespace() |
|
1044 |
*/ |
|
1045 |
public String getTypeNamespace() { |
|
1046 |
return null; |
|
1047 |
} |
|
1048 |
||
1049 |
/** |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1050 |
* Introduced in DOM Level 3. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1051 |
* <p> |
6 | 1052 |
* Checks if a type is derived from another by restriction. See: |
1053 |
* http://www.w3.org/TR/DOM-Level-3-Core/core.html#TypeInfo-isDerivedFrom |
|
1054 |
* |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1055 |
* @param typeNamespaceArg The namspace of the ancestor type declaration |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1056 |
* @param typeNameArg The name of the ancestor type declaration |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1057 |
* @param derivationMethod The derivation method |
6 | 1058 |
* |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1059 |
* @return boolean True if the type is derived by restriction for the |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1060 |
* reference type |
6 | 1061 |
*/ |
1062 |
public boolean isDerivedFrom(String typeNamespaceArg, |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1063 |
String typeNameArg, |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1064 |
int derivationMethod) { |
6 | 1065 |
|
1066 |
return false; |
|
1067 |
} |
|
1068 |
||
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1069 |
/** |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1070 |
* Method getSchemaTypeInfo. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1071 |
* |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1072 |
* @return TypeInfo |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1073 |
*/ |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1074 |
public TypeInfo getSchemaTypeInfo() { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1075 |
if (needsSyncData()) { |
6 | 1076 |
synchronizeData(); |
1077 |
} |
|
1078 |
return this; |
|
1079 |
} |
|
1080 |
||
1081 |
// |
|
1082 |
// Public methods |
|
1083 |
// |
|
1084 |
/** |
|
1085 |
* NON-DOM: Subclassed to flip the attributes' readonly switch as well. |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1086 |
* |
6 | 1087 |
* @see NodeImpl#setReadOnly |
1088 |
*/ |
|
1089 |
public void setReadOnly(boolean readOnly, boolean deep) { |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1090 |
super.setReadOnly(readOnly, deep); |
6 | 1091 |
if (attributes != null) { |
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1092 |
attributes.setReadOnly(readOnly, true); |
6 | 1093 |
} |
1094 |
} |
|
1095 |
||
1096 |
// |
|
1097 |
// Protected methods |
|
1098 |
// |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1099 |
/** |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1100 |
* Synchronizes the data (name and value) for fast nodes. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1101 |
*/ |
6 | 1102 |
protected void synchronizeData() { |
1103 |
||
1104 |
// no need to sync in the future |
|
1105 |
needsSyncData(false); |
|
1106 |
||
1107 |
// we don't want to generate any event for this so turn them off |
|
1108 |
boolean orig = ownerDocument.getMutationEvents(); |
|
1109 |
ownerDocument.setMutationEvents(false); |
|
1110 |
||
1111 |
// attributes |
|
1112 |
setupDefaultAttributes(); |
|
1113 |
||
1114 |
// set mutation events flag back to its original value |
|
1115 |
ownerDocument.setMutationEvents(orig); |
|
1116 |
||
1117 |
} // synchronizeData() |
|
1118 |
||
1119 |
// support for DOM Level 3 renameNode method |
|
1120 |
// @param el The element from which to take the attributes |
|
1121 |
void moveSpecifiedAttributes(ElementImpl el) { |
|
1122 |
if (needsSyncData()) { |
|
1123 |
synchronizeData(); |
|
1124 |
} |
|
1125 |
if (el.hasAttributes()) { |
|
1126 |
if (attributes == null) { |
|
1127 |
attributes = new AttributeMap(this, null); |
|
1128 |
} |
|
1129 |
attributes.moveSpecifiedAttributes(el.attributes); |
|
1130 |
} |
|
1131 |
} |
|
1132 |
||
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1133 |
/** |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1134 |
* Setup the default attributes. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1135 |
*/ |
6 | 1136 |
protected void setupDefaultAttributes() { |
1137 |
NamedNodeMapImpl defaults = getDefaultAttributes(); |
|
1138 |
if (defaults != null) { |
|
1139 |
attributes = new AttributeMap(this, defaults); |
|
1140 |
} |
|
1141 |
} |
|
1142 |
||
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1143 |
/** |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1144 |
* Reconcile default attributes. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1145 |
*/ |
6 | 1146 |
protected void reconcileDefaultAttributes() { |
1147 |
if (attributes != null) { |
|
1148 |
NamedNodeMapImpl defaults = getDefaultAttributes(); |
|
1149 |
attributes.reconcileDefaults(defaults); |
|
1150 |
} |
|
1151 |
} |
|
1152 |
||
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1153 |
/** |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1154 |
* Get the default attributes. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1155 |
*/ |
6 | 1156 |
protected NamedNodeMapImpl getDefaultAttributes() { |
1157 |
||
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1158 |
DocumentTypeImpl doctype |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1159 |
= (DocumentTypeImpl) ownerDocument.getDoctype(); |
6 | 1160 |
if (doctype == null) { |
1161 |
return null; |
|
1162 |
} |
|
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1163 |
ElementDefinitionImpl eldef |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1164 |
= (ElementDefinitionImpl) doctype.getElements() |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1165 |
.getNamedItem(getNodeName()); |
6 | 1166 |
if (eldef == null) { |
1167 |
return null; |
|
1168 |
} |
|
1169 |
return (NamedNodeMapImpl) eldef.getAttributes(); |
|
1170 |
||
1171 |
} // getDefaultAttributes() |
|
1172 |
||
32791
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1173 |
// |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1174 |
// ElementTraversal methods |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1175 |
// |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1176 |
/** |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1177 |
* @see <a |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1178 |
* href="http://www.w3.org/TR/2008/REC-ElementTraversal-20081222/#attribute-childElementCount"> |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1179 |
* Element Traversal Specification</a> |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1180 |
*/ |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1181 |
@Override |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1182 |
public final int getChildElementCount() { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1183 |
int count = 0; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1184 |
Element child = getFirstElementChild(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1185 |
while (child != null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1186 |
++count; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1187 |
child = ((ElementImpl) child).getNextElementSibling(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1188 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1189 |
return count; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1190 |
} // getChildElementCount():int |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1191 |
|
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1192 |
/** |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1193 |
* @see <a |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1194 |
* href="http://www.w3.org/TR/2008/REC-ElementTraversal-20081222/#attribute-firstElementChild"> |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1195 |
* Element Traversal Specification</a> |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1196 |
*/ |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1197 |
@Override |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1198 |
public final Element getFirstElementChild() { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1199 |
Node n = getFirstChild(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1200 |
while (n != null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1201 |
switch (n.getNodeType()) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1202 |
case Node.ELEMENT_NODE: |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1203 |
return (Element) n; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1204 |
case Node.ENTITY_REFERENCE_NODE: |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1205 |
final Element e = getFirstElementChild(n); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1206 |
if (e != null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1207 |
return e; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1208 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1209 |
break; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1210 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1211 |
n = n.getNextSibling(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1212 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1213 |
return null; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1214 |
} // getFirstElementChild():Element |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1215 |
|
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1216 |
/** |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1217 |
* @see <a |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1218 |
* href="http://www.w3.org/TR/2008/REC-ElementTraversal-20081222/#attribute-lastElementChild"> |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1219 |
* Element Traversal Specification</a> |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1220 |
*/ |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1221 |
@Override |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1222 |
public final Element getLastElementChild() { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1223 |
Node n = getLastChild(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1224 |
while (n != null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1225 |
switch (n.getNodeType()) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1226 |
case Node.ELEMENT_NODE: |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1227 |
return (Element) n; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1228 |
case Node.ENTITY_REFERENCE_NODE: |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1229 |
final Element e = getLastElementChild(n); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1230 |
if (e != null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1231 |
return e; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1232 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1233 |
break; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1234 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1235 |
n = n.getPreviousSibling(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1236 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1237 |
return null; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1238 |
} // getLastElementChild():Element |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1239 |
|
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1240 |
/** |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1241 |
* @see <a |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1242 |
* href="http://www.w3.org/TR/2008/REC-ElementTraversal-20081222/#attribute-nextElementSibling"> |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1243 |
* Element Traversal Specification</a> |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1244 |
*/ |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1245 |
@Override |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1246 |
public final Element getNextElementSibling() { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1247 |
Node n = getNextLogicalSibling(this); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1248 |
while (n != null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1249 |
switch (n.getNodeType()) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1250 |
case Node.ELEMENT_NODE: |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1251 |
return (Element) n; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1252 |
case Node.ENTITY_REFERENCE_NODE: |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1253 |
final Element e = getFirstElementChild(n); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1254 |
if (e != null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1255 |
return e; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1256 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1257 |
break; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1258 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1259 |
n = getNextLogicalSibling(n); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1260 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1261 |
return null; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1262 |
} // getNextElementSibling():Element |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1263 |
|
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1264 |
/** |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1265 |
* @see <a |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1266 |
* href="http://www.w3.org/TR/2008/REC-ElementTraversal-20081222/#attribute-previousElementSibling"> |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1267 |
* Element Traversal Specification</a> |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1268 |
*/ |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1269 |
@Override |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1270 |
public final Element getPreviousElementSibling() { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1271 |
Node n = getPreviousLogicalSibling(this); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1272 |
while (n != null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1273 |
switch (n.getNodeType()) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1274 |
case Node.ELEMENT_NODE: |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1275 |
return (Element) n; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1276 |
case Node.ENTITY_REFERENCE_NODE: |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1277 |
final Element e = getLastElementChild(n); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1278 |
if (e != null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1279 |
return e; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1280 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1281 |
break; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1282 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1283 |
n = getPreviousLogicalSibling(n); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1284 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1285 |
return null; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1286 |
} // getPreviousElementSibling():Element |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1287 |
|
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1288 |
// Returns the first element node found from a |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1289 |
// non-recursive in order traversal of the given node. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1290 |
private Element getFirstElementChild(Node n) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1291 |
final Node top = n; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1292 |
while (n != null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1293 |
if (n.getNodeType() == Node.ELEMENT_NODE) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1294 |
return (Element) n; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1295 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1296 |
Node next = n.getFirstChild(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1297 |
while (next == null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1298 |
if (top == n) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1299 |
break; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1300 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1301 |
next = n.getNextSibling(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1302 |
if (next == null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1303 |
n = n.getParentNode(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1304 |
if (n == null || top == n) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1305 |
return null; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1306 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1307 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1308 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1309 |
n = next; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1310 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1311 |
return null; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1312 |
} // getFirstElementChild(Node):Element |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1313 |
|
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1314 |
// Returns the first element node found from a |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1315 |
// non-recursive reverse order traversal of the given node. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1316 |
private Element getLastElementChild(Node n) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1317 |
final Node top = n; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1318 |
while (n != null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1319 |
if (n.getNodeType() == Node.ELEMENT_NODE) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1320 |
return (Element) n; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1321 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1322 |
Node next = n.getLastChild(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1323 |
while (next == null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1324 |
if (top == n) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1325 |
break; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1326 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1327 |
next = n.getPreviousSibling(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1328 |
if (next == null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1329 |
n = n.getParentNode(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1330 |
if (n == null || top == n) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1331 |
return null; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1332 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1333 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1334 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1335 |
n = next; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1336 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1337 |
return null; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1338 |
} // getLastElementChild(Node):Element |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1339 |
|
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1340 |
// Returns the next logical sibling with respect to the given node. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1341 |
private Node getNextLogicalSibling(Node n) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1342 |
Node next = n.getNextSibling(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1343 |
// If "n" has no following sibling and its parent is an entity reference node we |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1344 |
// need to continue the search through the following siblings of the entity |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1345 |
// reference as these are logically siblings of the given node. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1346 |
if (next == null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1347 |
Node parent = n.getParentNode(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1348 |
while (parent != null && parent.getNodeType() == Node.ENTITY_REFERENCE_NODE) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1349 |
next = parent.getNextSibling(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1350 |
if (next != null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1351 |
break; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1352 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1353 |
parent = parent.getParentNode(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1354 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1355 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1356 |
return next; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1357 |
} // getNextLogicalSibling(Node):Node |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1358 |
|
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1359 |
// Returns the previous logical sibling with respect to the given node. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1360 |
private Node getPreviousLogicalSibling(Node n) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1361 |
Node prev = n.getPreviousSibling(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1362 |
// If "n" has no previous sibling and its parent is an entity reference node we |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1363 |
// need to continue the search through the previous siblings of the entity |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1364 |
// reference as these are logically siblings of the given node. |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1365 |
if (prev == null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1366 |
Node parent = n.getParentNode(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1367 |
while (parent != null && parent.getNodeType() == Node.ENTITY_REFERENCE_NODE) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1368 |
prev = parent.getPreviousSibling(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1369 |
if (prev != null) { |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1370 |
break; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1371 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1372 |
parent = parent.getParentNode(); |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1373 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1374 |
} |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1375 |
return prev; |
ed81078b4e7f
8135283: DOM API update: Element Traversal Specification
joehw
parents:
25868
diff
changeset
|
1376 |
} // getPreviousLogicalSibling(Node):Node |
6 | 1377 |
} // class ElementImpl |