Пример #1
0
void DOMElementNSImpl::setPrefix(const XMLCh *prefix)
{
    if (fNode.isReadOnly())
        throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
    if (fNamespaceURI == 0 || fNamespaceURI[0] == chNull)
        throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager);

    if (prefix == 0 || *prefix == 0) {
        fPrefix = 0;
        fName = fLocalName;
        return;
    }

    DOMDocumentImpl* doc = (DOMDocumentImpl*) fParent.fOwnerDocument;

    if(!doc->isXMLName(prefix))
        throw DOMException(DOMException::INVALID_CHARACTER_ERR,0, GetDOMNodeMemoryManager);

    const XMLCh * xml      = DOMNodeImpl::getXmlString();
    const XMLCh * xmlURI   = DOMNodeImpl::getXmlURIString();

    if (XMLString::equals(prefix, xml) &&
        !XMLString::equals(fNamespaceURI, xmlURI))
        throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager);


    if (XMLString::indexOf(prefix, chColon) != -1) {
        throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager);
    }

    this-> fPrefix = doc->getPooledString(prefix);

    XMLSize_t prefixLen = XMLString::stringLen(prefix);
    XMLSize_t newQualifiedNameLen = prefixLen+1+XMLString::stringLen(fLocalName);

    XMLCh *newName;
    XMLCh temp[256];
    if (newQualifiedNameLen >= 255)
      newName = (XMLCh*) doc->getMemoryManager()->allocate
        (
            newQualifiedNameLen * sizeof(XMLCh)
        );//new XMLCh[newQualifiedNameLen];
    else
        newName = temp;

    // newName = prefix + chColon + fLocalName;
    XMLString::copyString(newName, prefix);
    newName[prefixLen] = chColon;
    XMLString::copyString(&newName[prefixLen+1], fLocalName);

    fName = doc->getPooledString(newName);

    if (newQualifiedNameLen >= 255)
        doc->getMemoryManager()->deallocate(newName);//delete[] newName;

}
Пример #2
0
void DOMElementNSImpl::setName(const XMLCh *namespaceURI,
                               const XMLCh *qualifiedName)
{
    DOMDocumentImpl* ownerDoc = (DOMDocumentImpl *) fParent.fOwnerDocument;
    this->fName = ownerDoc->getPooledString(qualifiedName);

    int index = DOMDocumentImpl::indexofQualifiedName(qualifiedName);
    if (index < 0)
        throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager);

    if (index == 0)
    {
        //qualifiedName contains no ':'
        //
        fPrefix = 0;
        fLocalName = fName;
    }
    else
    {	//0 < index < this->name.length()-1
        //
        fPrefix = ownerDoc->getPooledNString(qualifiedName, index);
        fLocalName = ownerDoc->getPooledString(fName+index+1);

        // Before we carry on, we should check if the prefix or localName are valid XMLName
        if (!ownerDoc->isXMLName(fPrefix) || !ownerDoc->isXMLName(fLocalName))
          throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager);
    }

    // DOM Level 3: namespace URI is never empty string.
    //
    const XMLCh * URI = DOMNodeImpl::mapPrefix (
      fPrefix,
      (!namespaceURI || !*namespaceURI) ? 0 : namespaceURI,
      DOMNode::ELEMENT_NODE);

    fNamespaceURI = (URI == 0) ? 0 : ownerDoc->getPooledString(URI);
}