Skip to content
Snippets Groups Projects
DOMNodeImpl.cpp 35.1 KiB
Newer Older
void DOMNodeImpl::setTextContent(const XMLCh* textContent){
    DOMNode *thisNode = castToNode(this);
    switch (thisNode->getNodeType()) 
    {
        case DOMNode::ELEMENT_NODE:
        case DOMNode::ENTITY_NODE:
        case DOMNode::ENTITY_REFERENCE_NODE:
        case DOMNode::DOCUMENT_FRAGMENT_NODE:
            {
                if (isReadOnly())
                  throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);

                // Remove all childs
                DOMNode* current = thisNode->getFirstChild();
                while (current != NULL) 
                {
                    thisNode->removeChild(current);
                    current = thisNode->getFirstChild();
                }
                if (textContent != NULL) 
                {
                    // Add textnode containing data
                    current = ((DOMDocumentImpl*)thisNode->getOwnerDocument())->createTextNode(textContent);
                    thisNode->appendChild(current);
                }
            }
            break;

        case DOMNode::ATTRIBUTE_NODE:
        case DOMNode::TEXT_NODE:
        case DOMNode::CDATA_SECTION_NODE:
        case DOMNode::COMMENT_NODE:
        case DOMNode::PROCESSING_INSTRUCTION_NODE:
            if (isReadOnly())
                throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);

            thisNode->setNodeValue(textContent);
            break;

        case DOMNode::DOCUMENT_NODE:
        case DOMNode::DOCUMENT_TYPE_NODE:
        case DOMNode::NOTATION_NODE:
            break;

        default:
            throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, GetDOMNodeMemoryManager);
Tinny Ng's avatar
Tinny Ng committed
}


bool DOMNodeImpl::isDefaultNamespace(const XMLCh* namespaceURI) const{
	DOMNode *thisNode = castToNode(this);
    short type = thisNode->getNodeType();
    switch (type) {
    case DOMNode::ELEMENT_NODE: {
        const XMLCh *prefix = thisNode->getPrefix();
        // REVISIT: is it possible that prefix is empty string?
            return XMLString::equals(namespaceURI, thisNode->getNamespaceURI());
        if (thisNode->hasAttributes()) {
            DOMElement *elem = (DOMElement *)thisNode;
            DOMNode *attr = elem->getAttributeNodeNS(XMLUni::fgXMLNSURIName, XMLUni::fgXMLNSString);
            if (attr != 0) {
                const XMLCh *value = attr->getNodeValue();
                return XMLString::equals(namespaceURI, value);
            }
        }
        DOMNode *ancestor = getElementAncestor(thisNode);
        if (ancestor != 0) {
            return ancestor->isDefaultNamespace(namespaceURI);
        }

        return false;
    }
    case DOMNode::DOCUMENT_NODE:{
        return ((DOMDocument*)thisNode)->getDocumentElement()->isDefaultNamespace(namespaceURI);
    }

    case DOMNode::ENTITY_NODE :
    case DOMNode::NOTATION_NODE:
    case DOMNode::DOCUMENT_FRAGMENT_NODE:
    case DOMNode::DOCUMENT_TYPE_NODE:
        // type is unknown
        return false;
    case DOMNode::ATTRIBUTE_NODE:{
        if (fOwnerNode->getNodeType() == DOMNode::ELEMENT_NODE) {
            return fOwnerNode->isDefaultNamespace(namespaceURI);

        }
        return false;
    }
    default:{
        DOMNode *ancestor = getElementAncestor(thisNode);
        if (ancestor != 0) {
            return ancestor->isDefaultNamespace(namespaceURI);
        }
        return false;
    }

    }
Tinny Ng's avatar
Tinny Ng committed
}

DOMNode*         DOMNodeImpl::getInterface(const XMLCh*)      {
    throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, GetDOMNodeMemoryManager);
Tinny Ng's avatar
Tinny Ng committed
    return 0;
}


Tinny Ng's avatar
Tinny Ng committed
// non-standard extension
void DOMNodeImpl::release()
{
    // shouldn't reach here
    throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
Tinny Ng's avatar
Tinny Ng committed
XERCES_CPP_NAMESPACE_END