6
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Copyright 1999-2002,2004 The Apache Software Foundation.
|
|
7 |
*
|
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9 |
* you may not use this file except in compliance with the License.
|
|
10 |
* You may obtain a copy of the License at
|
|
11 |
*
|
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13 |
*
|
|
14 |
* Unless required by applicable law or agreed to in writing, software
|
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17 |
* See the License for the specific language governing permissions and
|
|
18 |
* limitations under the License.
|
|
19 |
*/
|
|
20 |
|
|
21 |
package com.sun.org.apache.xerces.internal.dom;
|
|
22 |
|
|
23 |
import org.w3c.dom.Node;
|
|
24 |
|
|
25 |
/**
|
|
26 |
* This class represents a Document Type <em>declaraction</em> in
|
|
27 |
* the document itself, <em>not</em> a Document Type Definition (DTD).
|
|
28 |
* An XML document may (or may not) have such a reference.
|
|
29 |
* <P>
|
|
30 |
* DocumentType is an Extended DOM feature, used in XML documents but
|
|
31 |
* not in HTML.
|
|
32 |
* <P>
|
|
33 |
* Note that Entities and Notations are no longer children of the
|
|
34 |
* DocumentType, but are parentless nodes hung only in their
|
|
35 |
* appropriate NamedNodeMaps.
|
|
36 |
* <P>
|
|
37 |
* This area is UNDERSPECIFIED IN REC-DOM-Level-1-19981001
|
|
38 |
* Most notably, absolutely no provision was made for storing
|
|
39 |
* and using Element and Attribute information. Nor was the linkage
|
|
40 |
* between Entities and Entity References nailed down solidly.
|
|
41 |
*
|
|
42 |
* @xerces.internal
|
|
43 |
*
|
|
44 |
* @since PR-DOM-Level-1-19980818.
|
|
45 |
*/
|
|
46 |
public class DeferredDocumentTypeImpl
|
|
47 |
extends DocumentTypeImpl
|
|
48 |
implements DeferredNode {
|
|
49 |
|
|
50 |
//
|
|
51 |
// Constants
|
|
52 |
//
|
|
53 |
|
|
54 |
/** Serialization version. */
|
|
55 |
static final long serialVersionUID = -2172579663227313509L;
|
|
56 |
|
|
57 |
//
|
|
58 |
// Data
|
|
59 |
//
|
|
60 |
|
|
61 |
/** Node index. */
|
|
62 |
protected transient int fNodeIndex;
|
|
63 |
|
|
64 |
//
|
|
65 |
// Constructors
|
|
66 |
//
|
|
67 |
|
|
68 |
/**
|
|
69 |
* This is the deferred constructor. Only the fNodeIndex is given here.
|
|
70 |
* All other data, can be requested from the ownerDocument via the index.
|
|
71 |
*/
|
|
72 |
DeferredDocumentTypeImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) {
|
|
73 |
super(ownerDocument, null);
|
|
74 |
|
|
75 |
fNodeIndex = nodeIndex;
|
|
76 |
needsSyncData(true);
|
|
77 |
needsSyncChildren(true);
|
|
78 |
|
|
79 |
} // <init>(DeferredDocumentImpl,int)
|
|
80 |
|
|
81 |
//
|
|
82 |
// DeferredNode methods
|
|
83 |
//
|
|
84 |
|
|
85 |
/** Returns the node index. */
|
|
86 |
public int getNodeIndex() {
|
|
87 |
return fNodeIndex;
|
|
88 |
}
|
|
89 |
|
|
90 |
//
|
|
91 |
// Protected methods
|
|
92 |
//
|
|
93 |
|
|
94 |
/** Synchronizes the data (name and value) for fast nodes. */
|
|
95 |
protected void synchronizeData() {
|
|
96 |
|
|
97 |
// no need to sync in the future
|
|
98 |
needsSyncData(false);
|
|
99 |
|
|
100 |
// fluff data
|
|
101 |
DeferredDocumentImpl ownerDocument =
|
|
102 |
(DeferredDocumentImpl)this.ownerDocument;
|
|
103 |
name = ownerDocument.getNodeName(fNodeIndex);
|
|
104 |
|
|
105 |
// public and system ids
|
|
106 |
publicID = ownerDocument.getNodeValue(fNodeIndex);
|
|
107 |
systemID = ownerDocument.getNodeURI(fNodeIndex);
|
|
108 |
int extraDataIndex = ownerDocument.getNodeExtra(fNodeIndex);
|
|
109 |
internalSubset = ownerDocument.getNodeValue(extraDataIndex);
|
|
110 |
} // synchronizeData()
|
|
111 |
|
|
112 |
/** Synchronizes the entities, notations, and elements. */
|
|
113 |
protected void synchronizeChildren() {
|
|
114 |
|
|
115 |
// we don't want to generate any event for this so turn them off
|
|
116 |
boolean orig = ownerDocument().getMutationEvents();
|
|
117 |
ownerDocument().setMutationEvents(false);
|
|
118 |
|
|
119 |
// no need to synchronize again
|
|
120 |
needsSyncChildren(false);
|
|
121 |
|
|
122 |
// create new node maps
|
|
123 |
DeferredDocumentImpl ownerDocument =
|
|
124 |
(DeferredDocumentImpl)this.ownerDocument;
|
|
125 |
|
|
126 |
entities = new NamedNodeMapImpl(this);
|
|
127 |
notations = new NamedNodeMapImpl(this);
|
|
128 |
elements = new NamedNodeMapImpl(this);
|
|
129 |
|
|
130 |
// fill node maps
|
|
131 |
DeferredNode last = null;
|
|
132 |
for (int index = ownerDocument.getLastChild(fNodeIndex);
|
|
133 |
index != -1;
|
|
134 |
index = ownerDocument.getPrevSibling(index)) {
|
|
135 |
|
|
136 |
DeferredNode node = ownerDocument.getNodeObject(index);
|
|
137 |
int type = node.getNodeType();
|
|
138 |
switch (type) {
|
|
139 |
|
|
140 |
// internal, external, and unparsed entities
|
|
141 |
case Node.ENTITY_NODE: {
|
|
142 |
entities.setNamedItem(node);
|
|
143 |
break;
|
|
144 |
}
|
|
145 |
|
|
146 |
// notations
|
|
147 |
case Node.NOTATION_NODE: {
|
|
148 |
notations.setNamedItem(node);
|
|
149 |
break;
|
|
150 |
}
|
|
151 |
|
|
152 |
// element definitions
|
|
153 |
case NodeImpl.ELEMENT_DEFINITION_NODE: {
|
|
154 |
elements.setNamedItem(node);
|
|
155 |
break;
|
|
156 |
}
|
|
157 |
|
|
158 |
// elements
|
|
159 |
case Node.ELEMENT_NODE: {
|
|
160 |
if (((DocumentImpl)getOwnerDocument()).allowGrammarAccess){
|
|
161 |
insertBefore(node, last);
|
|
162 |
last = node;
|
|
163 |
break;
|
|
164 |
}
|
|
165 |
}
|
|
166 |
|
|
167 |
// NOTE: Should never get here! -Ac
|
|
168 |
default: {
|
|
169 |
System.out.println("DeferredDocumentTypeImpl" +
|
|
170 |
"#synchronizeInfo: " +
|
|
171 |
"node.getNodeType() = " +
|
|
172 |
node.getNodeType() +
|
|
173 |
", class = " +
|
|
174 |
node.getClass().getName());
|
|
175 |
}
|
|
176 |
}
|
|
177 |
}
|
|
178 |
|
|
179 |
// set mutation events flag back to its original value
|
|
180 |
ownerDocument().setMutationEvents(orig);
|
|
181 |
|
|
182 |
// set entities and notations read_only per DOM spec
|
|
183 |
setReadOnly(true, false);
|
|
184 |
|
|
185 |
} // synchronizeChildren()
|
|
186 |
|
|
187 |
} // class DeferredDocumentTypeImpl
|