Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
DOMDocumentType *newdoctype = (DOMDocumentType *)
createDocumentType(srcdoctype->getNodeName(),
srcdoctype->getPublicId(),
srcdoctype->getSystemId());
// Values are on NamedNodeMaps
DOMNamedNodeMap *smap = srcdoctype->getEntities();
DOMNamedNodeMap *tmap = newdoctype->getEntities();
if(smap != 0) {
for(XMLSize_t i = 0; i < smap->getLength(); i++) {
tmap->setNamedItem(importNode(smap->item(i), true, false));
}
}
smap = srcdoctype->getNotations();
tmap = newdoctype->getNotations();
if (smap != 0) {
for(XMLSize_t i = 0; i < smap->getLength(); i++) {
tmap->setNamedItem(importNode(smap->item(i), true, false));
}
}
// NOTE: At this time, the DOM definition of DocumentType
// doesn't cover Elements and their Attributes. domimpl's
// extentions in that area will not be preserved, even if
// copying from domimpl to domimpl. We could special-case
// that here. Arguably we should. Consider. ?????
newnode = newdoctype;
}
break;
case DOMNode::DOCUMENT_FRAGMENT_NODE :
newnode = createDocumentFragment();
// No name, kids carry value
break;
case DOMNode::NOTATION_NODE :
{
DOMNotation *srcnotation=(DOMNotation *)source;
DOMNotationImpl *newnotation = (DOMNotationImpl *)createNotation(source->getNodeName());
newnotation->setPublicId(srcnotation->getPublicId());
newnotation->setSystemId(srcnotation->getSystemId());
// Kids carry additional value
newnode=newnotation;
// No name, no value
break;
}
case DOMNode::DOCUMENT_NODE : // Document can't be child of Document
default: // Unknown node type
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0);
}
// If deep, replicate and attach the kids.
if (deep)
for (DOMNode *srckid = source->getFirstChild();
srckid != 0;
srckid = srckid->getNextSibling())
{
newnode->appendChild(importNode(srckid, true, false));
}
if (newnode->getNodeType() == DOMNode::ENTITY_REFERENCE_NODE
|| newnode->getNodeType() == DOMNode::ENTITY_NODE) {
castToNodeImpl(newnode)->setReadOnly(true, true);
errorChecking = oldErrorCheckingFlag;
}
if (!cloningDoc)
fNode.callUserDataHandlers(DOMUserDataHandler::NODE_IMPORTED, source, newnode);
return newnode;
}
// user data utility
void* DOMDocumentImpl::setUserData(DOMNodeImpl* n, const XMLCh* key, void* data, DOMUserDataHandler* handler)
{
void* oldData = 0;
if (!fUserDataTable) {
// create the table on heap so that it can be cleaned in destructor
fUserDataTable = new (this) RefHashTableOf<DOMNodeUserDataTable>(29, true, new HashPtr());
}
else {
node_userDataTable = fUserDataTable->get((void*)n);
DOMUserDataRecord* oldDataRecord = 0;
if (node_userDataTable) {
oldDataRecord = node_userDataTable->get((void*)key);
if (oldDataRecord) {
oldData = oldDataRecord->getKey();
node_userDataTable->removeKey((void*)key);
}
}
}
if (data) {
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
// create on the heap and adopted by the hashtable which will delete it upon removal.
if (!node_userDataTable) {
node_userDataTable = new RefHashTableOf<DOMUserDataRecord>(29, true);
fUserDataTable->put(n, node_userDataTable);
}
// clone the key first, and create the DOMUserDataRecord
// create on the heap and adopted by the hashtable which will delete it upon removal.
node_userDataTable->put((void*)getPooledString(key), new DOMUserDataRecord(data, handler));
}
else {
if (node_userDataTable->isEmpty())
n->hasUserData(false);
}
return oldData;
}
void* DOMDocumentImpl::getUserData(const DOMNodeImpl* n, const XMLCh* key) const
{
if (fUserDataTable) {
DOMNodeUserDataTable* node_userDataTable = fUserDataTable->get((void*)n);
if (node_userDataTable) {
DOMUserDataRecord* dataRecord = node_userDataTable->get((void*)key);
if (dataRecord)
return dataRecord->getKey();
}
}
return 0;
}
void DOMDocumentImpl::callUserDataHandlers(const DOMNodeImpl* n, DOMUserDataHandler::DOMOperationType operation, const DOMNode* src, const DOMNode* dst) const
{
if (fUserDataTable) {
DOMNodeUserDataTable* node_userDataTable = fUserDataTable->get((void*)n);
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
if (node_userDataTable) {
RefHashTableOfEnumerator<DOMUserDataRecord> userDataEnum(node_userDataTable);
// walk through the entire node_userDataTable table
while (userDataEnum.hasMoreElements()) {
// get the key
XMLCh* key = (XMLCh*) userDataEnum.nextElementKey();
// get the DOMUserDataRecord
DOMUserDataRecord* userDataRecord = node_userDataTable->get((void*)key);
// get the handler
DOMUserDataHandler* handler = userDataRecord->getValue();
if (handler) {
// get the data
void* data = userDataRecord->getKey();
handler->handle(operation, key, data, src, dst);
}
}
}
}
}
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
void DOMDocumentImpl::transferUserData(DOMNodeImpl* n1, DOMNodeImpl* n2)
{
if (fUserDataTable) {
fUserDataTable->transferElement((void*)n1, (void*)n2);
n1->hasUserData(false);
n2->hasUserData(true);
}
}
DOMNode* DOMDocumentImpl::renameNode(DOMNode* n, const XMLCh* namespaceURI, const XMLCh* name)
{
if (n->getOwnerDocument() != this)
throw DOMException(DOMException::WRONG_DOCUMENT_ERR, 0);
switch (n->getNodeType()) {
case ELEMENT_NODE:
return ((DOMElementImpl*)n)->rename(namespaceURI, name);
case ATTRIBUTE_NODE:
return ((DOMAttrImpl*)n)->rename(namespaceURI, name);
default:
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0);
}
return 0;
}
void DOMDocumentImpl::release()
{
DOMDocument* doc = (DOMDocument*) this;
// release the docType as well
if (fDocType) {
castToNodeImpl(fDocType)->isToBeReleased(true);
fDocType->release();
}
// delete the document memory pool
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
delete doc;
};
void DOMDocumentImpl::release(DOMNode* object, NodeObjectType type)
{
if (!fRecycleNodePtr)
fRecycleNodePtr = new RefArrayOf<DOMNodePtr> (15);
if (!fRecycleNodePtr->operator[](type))
fRecycleNodePtr->operator[](type) = new RefStackOf<DOMNode> (15, false);
fRecycleNodePtr->operator[](type)->push(object);
}
void * DOMDocumentImpl::allocate(size_t amount, NodeObjectType type)
{
if (!fRecycleNodePtr)
return allocate(amount);
DOMNodePtr* ptr = fRecycleNodePtr->operator[](type);
if (!ptr || ptr->empty())
return allocate(amount);
return (void*) ptr->pop();
}