Newer
Older
}
fCurrentParent->appendChild(elem);
fNodeStack->push(fCurrentParent);
fCurrentParent = elem;
fCurrentNode = elem;
fWithinElement = true;
// If an empty element, do end right now (no endElement() will be called)
endElement(elemDecl, urlId, isRoot, elemPrefix);
}
void AbstractDOMParser::startEntityReference(const XMLEntityDecl& entDecl)
{
const XMLCh * entName = entDecl.getName();
DOMNamedNodeMap *entities = fDocumentType->getEntities();
DOMEntityImpl* entity = (DOMEntityImpl*)entities->getNamedItem(entName);
if (entity)
entity->setActualEncoding(fScanner->getReaderMgr()->getCurrentEncodingStr());
DOMEntityReference *er = fDocument->createEntityReferenceByParser(entName);
Tinny Ng
committed
//set the readOnly flag to false before appending node, will be reset in endEntityReference
DOMEntityReferenceImpl *erImpl = (DOMEntityReferenceImpl *) er;
erImpl->setReadOnly(false, true);
Tinny Ng
committed
if (fCreateEntityReferenceNodes == true)
{
Tinny Ng
committed
fNodeStack->push(fCurrentParent);
fCurrentParent = er;
fCurrentNode = er;
// this entityRef needs to be stored in Entity map too.
// We'd decide later whether the entity nodes should be created by a
// separated method in parser or not. For now just stick it in if
// the ref nodes are created
if (entity)
entity->setEntityRef(er);
}
void AbstractDOMParser::XMLDecl(const XMLCh* const version
, const XMLCh* const encoding
, const XMLCh* const standalone
, const XMLCh* const actualEncStr)
{
fDocument->setStandalone(XMLString::equals(XMLUni::fgYesString, standalone));
fDocument->setVersion(version);
fDocument->setEncoding(encoding);
fDocument->setActualEncoding(actualEncStr);
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
}
// ---------------------------------------------------------------------------
// AbstractDOMParser: Helper methods
// ---------------------------------------------------------------------------
DOMElement* AbstractDOMParser::createElementNSNode(const XMLCh *namespaceURI,
const XMLCh *qualifiedName)
{
return fDocument->createElementNS(namespaceURI, qualifiedName);
}
// ---------------------------------------------------------------------------
// AbstractDOMParser: Deprecated methods
// ---------------------------------------------------------------------------
bool AbstractDOMParser::getDoValidation() const
{
//
// We don't want to tie the public parser classes to the enum used
// by the scanner, so we use a separate one and map.
//
// DON'T mix the new and old methods!!
//
const XMLScanner::ValSchemes scheme = fScanner->getValidationScheme();
if (scheme == XMLScanner::Val_Always)
return true;
return false;
}
void AbstractDOMParser::setDoValidation(const bool newState)
{
fScanner->setDoValidation
(
newState ? XMLScanner::Val_Always : XMLScanner::Val_Never
);
}
//doctypehandler interfaces
void AbstractDOMParser::attDef
(
const DTDElementDecl& elemDecl
, const DTDAttDef& attDef
, const bool ignoring
{
if (fDocumentType->isIntSubsetReading())
{
if (elemDecl.hasAttDefs())
{
fInternalSubset.append(attDef.getFullName());
// Get the type and display it
const XMLAttDef::AttTypes type = attDef.getType();
switch(type)
{
case XMLAttDef::CData :
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgCDATAString);
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgIDString);
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgIDRefString);
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgIDRefsString);
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgEntityString);
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgEntitiesString);
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgNmTokenString);
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgNmTokensString);
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgNotationString);
const XMLCh* enumString = attDef.getEnumeration();
int length = XMLString::stringLen(enumString);
if (length > 0) {
for(int i=0; i<length; i++) {
if (enumString[i] == chSpace)
}
break;
}
//get te default types of the attlist
const XMLAttDef::DefAttTypes def = attDef.getDefaultType();
switch(def)
{
case XMLAttDef::Required :
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgRequiredString);
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgImpliedString);
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgFixedString);
break;
}
const XMLCh* defaultValue = attDef.getValue();
if (defaultValue != 0) {
fInternalSubset.append(chSpace);
fInternalSubset.append(chDoubleQuote);
fInternalSubset.append(defaultValue);
fInternalSubset.append(chDoubleQuote);
}
}
}
}
void AbstractDOMParser::doctypeComment
(
const XMLCh* const comment
)
{
if (fDocumentType->isIntSubsetReading())
{
if (comment != 0)
{
fInternalSubset.append(XMLUni::fgCommentString);
fInternalSubset.append(chSpace);
fInternalSubset.append(comment);
fInternalSubset.append(chSpace);
fInternalSubset.append(chDash);
fInternalSubset.append(chDash);
fInternalSubset.append(chCloseAngle);
}
}
}
void AbstractDOMParser::doctypeDecl
(
const DTDElementDecl& elemDecl
, const XMLCh* const publicId
, const XMLCh* const systemId
, const bool hasIntSubset
Khaled Noaman
committed
, const bool hasExtSubset
)
{
fDocumentType = (DOMDocumentTypeImpl *) fDocument->createDocumentType(elemDecl.getFullName(), publicId, systemId);
fDocument->setDocumentType(fDocumentType);
}
void AbstractDOMParser::doctypePI
(
const XMLCh* const target
, const XMLCh* const data
)
{
if (fDocumentType->isIntSubsetReading())
Tinny Ng
committed
{
//add these chars to internalSubset variable
fInternalSubset.append(chOpenAngle);
fInternalSubset.append(chQuestion);
fInternalSubset.append(target);
fInternalSubset.append(chSpace);
fInternalSubset.append(data);
fInternalSubset.append(chQuestion);
fInternalSubset.append(chCloseAngle);
Tinny Ng
committed
}
}
void AbstractDOMParser::doctypeWhitespace
(
const XMLCh* const chars
, const unsigned int length
)
{
if (fDocumentType->isIntSubsetReading())
}
void AbstractDOMParser::elementDecl
(
const DTDElementDecl& decl
, const bool isIgnored
)
{
if (fDocumentType->isIntSubsetReading())
Tinny Ng
committed
{
fInternalSubset.append(chOpenAngle);
fInternalSubset.append(chBang);
fInternalSubset.append(XMLUni::fgElemString);
fInternalSubset.append(chSpace);
fInternalSubset.append(decl.getFullName());
//get the ContentSpec information
const XMLCh* contentModel = decl.getFormattedContentModel();
if (contentModel != 0) {
fInternalSubset.append(chSpace);
fInternalSubset.append(contentModel);
Tinny Ng
committed
}
}
void AbstractDOMParser::endAttList
(
const DTDElementDecl& elemDecl
)
{
if (fDocumentType->isIntSubsetReading())
{
//print the closing angle
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
// this section sets up default attributes.
// default attribute nodes are stored in a NamedNodeMap DocumentTypeImpl::elements
// default attribute data attached to the document is used to conform to the
// DOM spec regarding creating element nodes & removing attributes with default values
// see DocumentTypeImpl
if (elemDecl.hasAttDefs())
{
XMLAttDefList* defAttrs = &elemDecl.getAttDefList();
XMLAttDef* attr = 0;
DOMAttrImpl * insertAttr = 0;
DOMElement *elem = fDocument->createElement(elemDecl.getFullName());
DOMElementImpl *elemImpl = (DOMElementImpl *) elem;
while (defAttrs->hasMoreElements())
{
attr = &defAttrs->nextElement();
if (attr->getValue() != 0)
{
if (fScanner->getDoNamespaces())
{
// DOM Level 2 wants all namespace declaration attributes
// to be bound to "http://www.w3.org/2000/xmlns/"
// So as long as the XML parser doesn't do it, it needs to
// done here.
const XMLCh* qualifiedName = attr->getFullName();
int index = DOMDocumentImpl::indexofQualifiedName(qualifiedName);
Khaled Noaman
committed
XMLBufBid bbQName(&fBufMgr);
XMLBuffer& buf = bbQName.getBuffer();
static const XMLCh XMLNS[] = {
chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chNull};
if (index > 0) {
// there is prefix
// map to XML URI for all cases except when prefix == "xmlns"
XMLCh* prefix;
XMLCh temp[1000];
if (index > 999)
prefix = (XMLCh*) fMemoryManager->allocate
(
(index + 1) * sizeof(XMLCh)
);//new XMLCh[index+1];
else
prefix = temp;
XMLString::subString(prefix ,qualifiedName, 0, index);
if (XMLString::equals(prefix,XMLNS))
buf.append(XMLUni::fgXMLNSURIName);
else
buf.append(XMLUni::fgXMLURIName);
if (index > 999)
fMemoryManager->deallocate(prefix);//delete [] prefix;
if (XMLString::equals(qualifiedName,XMLNS))
buf.append(XMLUni::fgXMLNSURIName);
}
insertAttr = (DOMAttrImpl *) fDocument->createAttributeNS(
buf.getRawBuffer(), // NameSpaceURI
qualifiedName); // qualified name
DOMNode* remAttr = elemImpl->setAttributeNodeNS(insertAttr);
if (remAttr)
remAttr->release();
}
else
{
// Namespaces is turned off...
insertAttr = (DOMAttrImpl *) fDocument->createAttribute(attr->getFullName());
DOMNode* remAttr = elemImpl->setAttributeNode(insertAttr);
if (remAttr)
remAttr->release();
insertAttr->setValue(attr->getValue());
DOMNode* rem = fDocumentType->getElements()->setNamedItem(elemImpl);
if (rem)
rem->release();
}
}
void AbstractDOMParser::endIntSubset()
{
fDocumentType->setInternalSubset(fInternalSubset.getRawBuffer());
// the buffer shouldn't be released as it is reused in the next parse
// fBufMgr.releaseBuffer(fInternalSubset);
fDocumentType->fIntSubsetReading = false;
}
void AbstractDOMParser::endExtSubset()
{
}
void AbstractDOMParser::entityDecl
(
const DTDEntityDecl& entityDecl
, const bool isPEDecl
, const bool isIgnored
)
{
DOMEntityImpl* entity = (DOMEntityImpl *) fDocument->createEntity(entityDecl.getName());
entity->setPublicId(entityDecl.getPublicId());
entity->setSystemId(entityDecl.getSystemId());
entity->setNotationName(entityDecl.getNotationName());
entity->setBaseURI(entityDecl.getBaseURI());
DOMEntityImpl *previousDef = (DOMEntityImpl *)
fDocumentType->getEntities()->setNamedItem( entity );
if (fDocumentType->isIntSubsetReading())
{
//add thes chars to internalSubset variable
fInternalSubset.append(chOpenAngle);
fInternalSubset.append(chBang);
fInternalSubset.append(XMLUni::fgEntityString);
fInternalSubset.append(chSpace);
fInternalSubset.append(entityDecl.getName());
const XMLCh* id = entity->getPublicId();
if (id != 0) {
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgPubIDString);
fInternalSubset.append(chSpace);
fInternalSubset.append(chDoubleQuote);
fInternalSubset.append(id);
fInternalSubset.append(chDoubleQuote);
}
id = entity->getSystemId();
if (id != 0) {
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgSysIDString);
fInternalSubset.append(chSpace);
fInternalSubset.append(chDoubleQuote);
fInternalSubset.append(id);
fInternalSubset.append(chDoubleQuote);
}
id = entity->getNotationName();
if (id != 0) {
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgNDATAString);
fInternalSubset.append(chSpace);
fInternalSubset.append(id);
}
id = entityDecl.getValue();
if (id !=0) {
fInternalSubset.append(chSpace);
fInternalSubset.append(chDoubleQuote);
fInternalSubset.append(id);
fInternalSubset.append(chDoubleQuote);
}
}
void AbstractDOMParser::resetDocType()
{
fDocumentType = 0;
}
void AbstractDOMParser::notationDecl
(
const XMLNotationDecl& notDecl
, const bool isIgnored
)
{
DOMNotationImpl* notation = (DOMNotationImpl *)fDocument->createNotation(notDecl.getName());
notation->setPublicId(notDecl.getPublicId());
notation->setSystemId(notDecl.getSystemId());
notation->setBaseURI(notDecl.getBaseURI());
DOMNode* rem = fDocumentType->getNotations()->setNamedItem( notation );
if (rem)
rem->release();
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
if (fDocumentType->isIntSubsetReading())
{
//add thes chars to internalSubset variable
fInternalSubset.append(chOpenAngle);
fInternalSubset.append(chBang);
fInternalSubset.append(XMLUni::fgNotationString);
fInternalSubset.append(chSpace);
fInternalSubset.append(notDecl.getName());
const XMLCh* id = notation->getPublicId();
if (id != 0) {
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgPubIDString);
fInternalSubset.append(chSpace);
fInternalSubset.append(chDoubleQuote);
fInternalSubset.append(id);
fInternalSubset.append(chDoubleQuote);
}
id = notation->getSystemId();
if (id != 0) {
fInternalSubset.append(chSpace);
fInternalSubset.append(XMLUni::fgSysIDString);
fInternalSubset.append(chSpace);
fInternalSubset.append(chDoubleQuote);
fInternalSubset.append(id);
fInternalSubset.append(chDoubleQuote);
}
fInternalSubset.append(chCloseAngle);
}
}
void AbstractDOMParser::startAttList
(
const DTDElementDecl& elemDecl
)
{
if (fDocumentType->isIntSubsetReading())
{
fInternalSubset.append(chOpenAngle);
fInternalSubset.append(chBang);
fInternalSubset.append(XMLUni::fgAttListString);
fInternalSubset.append(chSpace);
fInternalSubset.append(elemDecl.getFullName());
}
void AbstractDOMParser::startIntSubset()
{
}
void AbstractDOMParser::startExtSubset()
{
}
void AbstractDOMParser::TextDecl
(
const XMLCh* const versionStr
, const XMLCh* const encodingStr
)
{
if (fCurrentEntity) {
fCurrentEntity->setVersion(versionStr);
fCurrentEntity->setEncoding(encodingStr);
}