Exemplo n.º 1
0
// create a real Text node as child if we don't have one yet
void AttrImpl::makeChildNode() {
    if (hasStringValue()) {
        if (value.child != null) {
            // change the address of the value field into a DOMString*
            DOMString *x = (value.str == null
                ?(value.str = new (getOwnerDocument()->getMemoryManager()) DOMString())
                :value.str
            );
            // create a Text node passing the DOMString it points to
            TextImpl *text =
              (TextImpl *) getOwnerDocument()->createTextNode(*x);
            // get the DOMString ref count to be updated by setting the value
            // field to null
            *x = null;
            delete x;
            // finally reassign the value to the node address
            value.child = text;
            text->isFirstChild(true);
            text->previousSibling = text;
            text->ownerNode = this;
            text->isOwned(true);
        }
        hasStringValue(false);
    }
}
Exemplo n.º 2
0
// initially set up the default attribute information based on doctype information
void DOMElementImpl::setupDefaultAttributes()
{
    DOMDocument *tmpdoc = getOwnerDocument();
    if ((fNode.fOwnerNode == 0) || (tmpdoc == 0) || (tmpdoc->getDoctype() == 0))
        return;

    DOMNode *eldef = ((DOMDocumentTypeImpl*)tmpdoc->getDoctype())->getElements()->getNamedItem(getNodeName());
    DOMAttrMapImpl* defAttrs = (eldef == 0) ? 0 : (DOMAttrMapImpl *)(eldef->getAttributes());

    if (defAttrs)
        fDefaultAttributes = new (getOwnerDocument()) DOMAttrMapImpl(this, defAttrs);
}
Exemplo n.º 3
0
DOMElementImpl::DOMElementImpl(DOMDocument *ownerDoc, const XMLCh *eName)
    : fNode(ownerDoc), fParent(ownerDoc), fAttributes(0), fDefaultAttributes(0), fSchemaType(0)
{
    DOMDocumentImpl *docImpl = (DOMDocumentImpl *)ownerDoc;
    fName = docImpl->getPooledString(eName);
    setupDefaultAttributes();
    if (!fDefaultAttributes) {
        fDefaultAttributes = new (getOwnerDocument()) DOMAttrMapImpl(this);
        fAttributes = new (getOwnerDocument()) DOMAttrMapImpl(this);
    }
    else {
        fAttributes = new (getOwnerDocument()) DOMAttrMapImpl(this, fDefaultAttributes);
    }
}
Exemplo n.º 4
0
void
Attr::setValue(String * newvalue)
  throw(DOMException)
{
  if (isReadOnly())
    throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR);
  if (newvalue == null) {
    if (isId())
      removeIdRef();
    while (text != null)
      removeChild(text);
    return;
  }
  if (text == null) {
    text = getOwnerDocument()->createTextNode(newvalue);
    text->isFirstChild(true);
    text->previousSibling = text;
    text->ownerNode = this;
    text->isOwned(true);
    addIdRef();
  }
  else {
    removeIdRef();
    while (text->getNextSibling() != null) {
      removeChild(text->getNextSibling());
    }
    text->setData(newvalue);
    addIdRef();
  }

  isSpecified(true);
}
Exemplo n.º 5
0
DOMString AttrImpl::getValue()
{
    if (value.child == null) {
        return 0; // return "";
    }
    if (hasStringValue()) {
        // change value into a DOMString*
        DOMString *x = (value.str == null
            ?(value.str = new (getOwnerDocument()->getMemoryManager()) DOMString())
            :value.str
        );
        // return the DOMString it points to
        return *x;
    }
    ChildNode *firstChild = value.child;
    ChildNode *node = firstChild->nextSibling;
    if (node == null) {
        return firstChild->getNodeValue().clone();
    }
    int             length = 0;
    for (node = firstChild; node != null; node = node->nextSibling)
        length += node->getNodeValue().length();

    DOMString retString;
    retString.reserve(length);
    for (node = firstChild; node != null; node = node->nextSibling)
    {
        retString.appendData(node->getNodeValue());
    };

    return retString;
};
Exemplo n.º 6
0
DOMEntityReferenceImpl::DOMEntityReferenceImpl(DOMDocument *ownerDoc,
                                         const XMLCh *entityName,
                                         bool cloneChild)
    : fNode(ownerDoc), fParent(ownerDoc), fBaseURI(0)
{
    fName = ((DOMDocumentImpl *)getOwnerDocument())->getPooledString(entityName);
    // EntityReference behaves as a read-only node, since its contents
    // reflect the Entity it refers to -- but see setNodeName().
    //retrieve the corresponding entity content

    if (ownerDoc) {
        if (ownerDoc->getDoctype()) {
            if (ownerDoc->getDoctype()->getEntities()) {
                DOMEntityImpl* entity = (DOMEntityImpl*)ownerDoc->getDoctype()->getEntities()->getNamedItem(entityName);
                if (entity) {
                    fBaseURI = entity->getBaseURI();
                    if (cloneChild) {
                        DOMEntityReference* refEntity = entity->getEntityRef();
                        if (refEntity) {
                            fParent.cloneChildren(refEntity);
                        }
                    }
                }
            }
        }
    }

    fNode.setReadOnly(true, true);
}
void DOMDocumentTypeImpl::release()
{
    if (fNode.isOwned()) {
        if (fNode.isToBeReleased()) {
            // we are calling from documnet.release() which will notify the user data handler
            if (fIsCreatedFromHeap) {
                DOMDocumentType* docType = this;
                delete docType;
            }
        }
        else
            throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
    }
    else {
        if (fIsCreatedFromHeap) {
            fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
            DOMDocumentType* docType = this;
            delete docType;
        }
        else {
            DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
            if (doc) {
                fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
                doc->release(this, DOMDocumentImpl::DOCUMENT_TYPE_OBJECT);
            }
            else {
                // shouldn't reach here
                throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
            }
        }
    }
}
Exemplo n.º 8
0
void DOMAttrImpl::setValue(const XMLCh *val)
{
    if (fNode.isReadOnly())
    {
        throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
    }

    //  If this attribute was of type ID and in the map, take it out,
    //    then put it back in with the new name.  For now, we don't worry
    //    about what happens if the new name conflicts
    //
    DOMDocumentImpl *doc = (DOMDocumentImpl *)getOwnerDocument();
    if (fNode.isIdAttr())
        doc->getNodeIDMap()->remove(this);

    DOMNode *kid;
    while ((kid = fParent.fFirstChild) != 0)         // Remove existing kids
    {
        DOMNode* node = removeChild(kid);
        if (node)
            node->release();
    }

    if (val != 0)              // Create and add the new one
        appendChild(doc->createTextNode(val));
    fNode.isSpecified(true);
    fParent.changed();

    if (fNode.isIdAttr())
        doc->getNodeIDMap()->add(this);

}
Exemplo n.º 9
0
const XMLCh* DOMTextImpl::getWholeText() const
{
    DOMDocument *doc = getOwnerDocument();
    if (!doc) {
        throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, GetDOMNodeMemoryManager);
        return 0;
    }
    DOMNode* root=doc->getDocumentElement();
    DOMTreeWalker* pWalker=doc->createTreeWalker(root!=NULL?root:(DOMNode*)this, DOMNodeFilter::SHOW_ALL, NULL, true);
    pWalker->setCurrentNode((DOMNode*)this);
    // Logically-adjacent text nodes are Text or CDATASection nodes that can be visited sequentially in document order or in
    // reversed document order without entering, exiting, or passing over Element, Comment, or ProcessingInstruction nodes.
    DOMNode* prevNode;
    while((prevNode=pWalker->previousNode())!=NULL)
    {
        if(prevNode->getNodeType()==ELEMENT_NODE || prevNode->getNodeType()==COMMENT_NODE || prevNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
            break;
    }
    XMLBuffer buff(1023, GetDOMNodeMemoryManager);
    DOMNode* nextNode;
    while((nextNode=pWalker->nextNode())!=NULL)
    {
        if(nextNode->getNodeType()==ELEMENT_NODE || nextNode->getNodeType()==COMMENT_NODE || nextNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
            break;
        if(nextNode->getNodeType()==TEXT_NODE || nextNode->getNodeType()==CDATA_SECTION_NODE)
            buff.append(nextNode->getNodeValue());
    }
    pWalker->release();

    XMLCh* wholeString = (XMLCh*)((DOMDocumentImpl*)doc)->allocate((buff.getLen()+1) * sizeof(XMLCh));
    XMLString::copyString(wholeString, buff.getRawBuffer());
    return wholeString;
}
Exemplo n.º 10
0
//
//  splitText.   revist - factor into a common function for use
//                             here and in DOMTextImpl
//
DOMText *DOMCDATASectionImpl::splitText(XMLSize_t offset)
{
    if (fNode.isReadOnly())
    {
        throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
    }
    XMLSize_t len = fCharacterData.fDataBuf->getLen();
    if (offset > len)
        throw DOMException(DOMException::INDEX_SIZE_ERR, 0, GetDOMNodeMemoryManager);

    DOMText *newText =
                getOwnerDocument()->createCDATASection(
                        this->substringData(offset, len - offset));

    DOMNode *parent = getParentNode();
    if (parent != 0)
        parent->insertBefore(newText, getNextSibling());

    fCharacterData.fDataBuf->chop(offset);

    if (this->getOwnerDocument() != 0) {
        Ranges* ranges = ((DOMDocumentImpl *)this->getOwnerDocument())->getRanges();
        if (ranges != 0) {
            XMLSize_t sz = ranges->size();
            if (sz != 0) {
                for (XMLSize_t i =0; i<sz; i++) {
                    ranges->elementAt(i)->updateSplitInfo( this, newText, offset);
                }
            }
        }
    }

    return newText;
}
Exemplo n.º 11
0
void DOMNotationImpl::setSystemId(const XMLCh *arg)
{
    if(fNode.isReadOnly())
        throw DOMException(
        DOMException::NO_MODIFICATION_ALLOWED_ERR,0, GetDOMNodeMemoryManager);

    fSystemId = ((DOMDocumentImpl *)getOwnerDocument())->cloneString(arg);
}
Exemplo n.º 12
0
void DOMNodeImpl::callUserDataHandlers(DOMUserDataHandler::DOMOperationType operation,
                                       const DOMNode* src,
                                       const DOMNode* dst) const
{
    DOMDocumentImpl* doc=(DOMDocumentImpl*)getOwnerDocument();
    if (doc)
        doc->callUserDataHandlers(this, operation, src, dst);
}
Exemplo n.º 13
0
void NodeImpl::setUserData(void * val)
{
    getOwnerDocument()->setUserData(this, val);
    if (val)
        hasUserData(true);
    else
        hasUserData(false);
};
Exemplo n.º 14
0
//Introduced in DOM Level 3
void* DOMNodeImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
{
   if (!data && !hasUserData())
       return 0;

    hasUserData(true);
    return ((DOMDocumentImpl*)getOwnerDocument())->setUserData(this, key, data, handler);
}
Exemplo n.º 15
0
void DOMEntityImpl::setBaseURI(const XMLCh* baseURI) {
    if (baseURI && *baseURI) {
        XMLCh* temp = (XMLCh*) ((DOMDocumentImpl *)getOwnerDocument())->allocate((XMLString::stringLen(baseURI) + 9)*sizeof(XMLCh));
        XMLString::fixURI(baseURI, temp);
        fBaseURI = temp;
    }
    else
        fBaseURI = 0;
}
Exemplo n.º 16
0
void DOMAttrNSImpl::setName(const XMLCh* namespaceURI, const XMLCh* qualifiedName)
{
    DOMDocumentImpl* ownerDoc = (DOMDocumentImpl *) getOwnerDocument();
    const XMLCh * xmlns = DOMNodeImpl::getXmlnsString();
    const XMLCh * xmlnsURI = DOMNodeImpl::getXmlnsURIString();
    this->fName = ownerDoc->getPooledString(qualifiedName);

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

    bool xmlnsAlone = false;	//true if attribute name is "xmlns"
    if (index == 0) {	//qualifiedName contains no ':'
        if (XMLString::equals(this->fName, xmlns)) {
            if (!XMLString::equals(namespaceURI, xmlnsURI))
                throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager);
            xmlnsAlone = true;
        }
        this -> fPrefix = 0;
        this -> fLocalName = this -> fName;
    } else {	//0 < index < this->name.length()-1
        XMLCh* newName;
        XMLCh temp[4000];
        if (index >= 3999)
            newName = (XMLCh*) ((DOMDocumentImpl *)this->getOwnerDocument())->getMemoryManager()->allocate
            (
                (XMLString::stringLen(qualifiedName) + 1) * sizeof(XMLCh)
            );//new XMLCh[XMLString::stringLen(qualifiedName)+1];
        else
            newName = temp;

        XMLString::copyNString(newName, fName, index);
        newName[index] = chNull;
        this-> fPrefix = ownerDoc->getPooledString(newName);
        this -> fLocalName = ownerDoc->getPooledString(fName+index+1);

        if (index >= 3999)
            ((DOMDocumentImpl *)this->getOwnerDocument())->getMemoryManager()->deallocate(newName);//delete[] newName;

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

    // DOM Level 3: namespace URI is never empty string.
    const XMLCh * URI = xmlnsAlone ? xmlnsURI
        : DOMNodeImpl::mapPrefix
          (
              fPrefix,
              (!namespaceURI || !*namespaceURI) ? 0 : namespaceURI,
              DOMNode::ATTRIBUTE_NODE
          );
    this -> fNamespaceURI = (URI == 0) ? 0 : ownerDoc->getPooledString(URI);
}
// cf. http://www.w3.org/TR/cssom-view/#scroll-an-element-into-view
void HTMLElementImp::scrollIntoView(bool top)
{
    if (html::Window window = getOwnerDocument().getDefaultView()) {
        if (Box* box = getBox()) {
            int x = box->getX() + box->getMarginLeft();
            int y = box->getY() + box->getMarginTop();
            if (!top)
                y += box->getBorderHeight();
            window.scroll(x, y);
        }
    }
}
Exemplo n.º 18
0
const XMLCh*     DOMNodeImpl::getTextContent() const
{
	unsigned int nBufferLength = 0;

	getTextContent(NULL, nBufferLength);
	XMLCh* pzBuffer = (XMLCh*)((DOMDocumentImpl*)getOwnerDocument())->allocate((nBufferLength+1) * sizeof(XMLCh));
	getTextContent(pzBuffer, nBufferLength);
	pzBuffer[nBufferLength] = 0;

	return pzBuffer;

}
Exemplo n.º 19
0
AttrImpl::AttrImpl(const AttrImpl &other, bool deep)
    : NodeImpl(other)
{
    name = other.name.clone();
	
    isSpecified(other.isSpecified());

    /* We must initialize the void* value to null in *all* cases. Failing to do
     * so would cause, in case of assignment to a DOMString later, its content
     * to be derefenced as a DOMString, which would lead the ref count code to
     * be called on something that is not actually a DOMString... Really bad
     * things would then happen!!!
     */
    value.child = null;
    hasStringValue(other.hasStringValue());

    if (other.isIdAttr())
    {
        isIdAttr(true);
        this->getOwnerDocument()->getNodeIDMap()->add(this);
    }

    // take care of case where there are kids
    if (!hasStringValue()) {
        cloneChildren(other);
    }
    else {
        if(other.value.str == null) 
        {
            if(value.str != null)
            {
                *(value.str) = null;
                delete value.str;
                value.str = null;
            }
       }
       else
       {
            // get the address of the value field of this as a DOMString*
            DOMString *x = (value.str == null
                ?(value.str = new (getOwnerDocument()->getMemoryManager()) DOMString())
                :value.str
            );
            // and the address of the value field of other as a DOMString*
            DOMString *y = other.value.str;
            // We can now safely do the cloning and assignement, both operands
            // being a DOMString their ref counts will be updated appropriately
            *x = y->clone();
        }
    }
};
Exemplo n.º 20
0
DOMElementImpl::DOMElementImpl(const DOMElementImpl &other, bool deep)
    : fNode(other.getOwnerDocument()),
      fParent(other.getOwnerDocument()),
      fAttributes(0),
      fDefaultAttributes(0),
      fSchemaType(other.fSchemaType)      
{
    fName = other.fName;

    if (deep)
        fParent.cloneChildren(&other);

    if (other.getAttributes())
    {
        fAttributes = ((DOMAttrMapImpl *)other.getAttributes())->cloneAttrMap(this);
    }

    if (other.getDefaultAttributes())
    {
        fDefaultAttributes = ((DOMAttrMapImpl *)other.getDefaultAttributes())->cloneAttrMap(this);
    }

    if (!fDefaultAttributes)
        setupDefaultAttributes();

    if (!fDefaultAttributes)
        fDefaultAttributes = new (getOwnerDocument()) DOMAttrMapImpl(this);

    if (!fAttributes) {
        if (!fDefaultAttributes) {
            fAttributes = new (getOwnerDocument()) DOMAttrMapImpl(this);
        }
        else {
            fAttributes = new (getOwnerDocument()) DOMAttrMapImpl(this, fDefaultAttributes);
        }
    }

}
Box* HTMLElementImp::getBox()
{
    html::Window window = getOwnerDocument().getDefaultView();
    if (!window)
        return 0;
    css::CSSStyleDeclaration style = window.getComputedStyle(this);
    if (!style)
        return 0;
    // TODO: Fix MVC violation
    CSSStyleDeclarationImp* imp = dynamic_cast<CSSStyleDeclarationImp*>(style.self());
    if (!imp)
        return 0;
    return imp->getBox();
}
Exemplo n.º 22
0
void AttrNSImpl::setPrefix(const DOMString &prefix)
{
    DOMString xml = NodeImpl::getXmlString();
    DOMString xmlURI = NodeImpl::getXmlURIString();
    DOMString xmlns = NodeImpl::getXmlnsString();
    DOMString xmlnsURI = NodeImpl::getXmlnsURIString();

    if (getOwnerDocument()->getErrorChecking()) {
        if (isReadOnly()) {
            throw DOM_DOMException(
                                 DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,
                                 null);
        }
        if (namespaceURI == null || localName.equals(xmlns)) {
            throw DOM_DOMException(DOM_DOMException::NAMESPACE_ERR, null);
        }
        if (prefix != null && !((DocumentImpl *)this->getOwnerDocument())->isXMLName(prefix)) {
            throw DOM_DOMException(DOM_DOMException::INVALID_CHARACTER_ERR,
                                   null);
        }
    }
    if (prefix == null || prefix.length() == 0) {
        name = localName;
        return;
    }
    if (getOwnerDocument()->getErrorChecking() &&
        (prefix.equals(xml) && !namespaceURI.equals(xmlURI) ||
         prefix.equals(xmlns) && !namespaceURI.equals(xmlnsURI))) {
        throw DOM_DOMException(DOM_DOMException::NAMESPACE_ERR, null);
    }
    const XMLCh *p = prefix.rawBuffer();
    for (int i = prefix.length(); --i >= 0;)
        if (*p++ == chColon)	//prefix is malformed
            throw DOM_DOMException(DOM_DOMException::NAMESPACE_ERR, null);

    name = prefix + chColon + localName; //nodeName is changed too
}
Exemplo n.º 23
0
void DOMNotationImpl::release()
{
    if (fNode.isOwned() && !fNode.isToBeReleased())
        throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);

    DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
    if (doc) {
        fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
        doc->release(this, DOMMemoryManager::NOTATION_OBJECT);
    }
    else {
        // shouldn't reach here
        throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
    }
}
Exemplo n.º 24
0
void AttrImpl::setValue(const DOMString &newvalue)
{
    if (isReadOnly())
    {
        throw DOM_DOMException
        (
            DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, null
        );
    }

    //  If this attribute was of type ID and in the map, take it out,
    //    then put it back in with the new name.  For now, we don't worry
    //    about what happens if the new name conflicts
    //
    if (isIdAttr())
        this->getOwnerDocument()->getNodeIDMap()->remove(this);

    if (!hasStringValue() && value.str != null) {
        NodeImpl *kid;
        while ((kid = value.child) != null) { // Remove existing kids
            removeChild(kid);
            if (kid->nodeRefCount == 0)
                NodeImpl::deleteIf(kid);
        }
    }

    // directly store the string as the value by changing the value field
    // into a DOMString
    DOMString *x = (value.str == null 
        ?(value.str = new (getOwnerDocument()->getMemoryManager()) DOMString())
        :value.str
    );
    if (newvalue != null) {
        *x = newvalue.clone();
    }
    else {
        *x = null;
        delete x;
        value.str = null;
    }
    hasStringValue(true);
    isSpecified(true);
    changed();

    if (isIdAttr())
        this->getOwnerDocument()->getNodeIDMap()->add(this);

};
Exemplo n.º 25
0
void DOMElementImpl::release()
{
    if (fNode.isOwned() && !fNode.isToBeReleased())
        throw DOMException(DOMException::INVALID_ACCESS_ERR,0);

    DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
    if (doc) {
        fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
        fParent.release();
        doc->release(this, DOMDocumentImpl::ELEMENT_OBJECT);
    }
    else {
        // shouldn't reach here
        throw DOMException(DOMException::INVALID_ACCESS_ERR,0);
    }
}
void DOMProcessingInstructionImpl::release()
{
    if (fNode.isOwned() && !fNode.isToBeReleased())
        throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);

    DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
    if (doc) {
        fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
        fCharacterData.releaseBuffer();
        doc->release(this, DOMMemoryManager::PROCESSING_INSTRUCTION_OBJECT);
    }
    else {
        // shouldn't reach here
        throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
    }
}
Exemplo n.º 27
0
DOMNode* DOMElementImpl::rename(const XMLCh* namespaceURI, const XMLCh* name)
{
    DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();

    if (!namespaceURI || !*namespaceURI) {
        fName = doc->getPooledString(name);
        fAttributes->reconcileDefaultAttributes(getDefaultAttributes());

        return this;
    }
    else {

        // create a new ElementNS
        DOMElementNSImpl* newElem = (DOMElementNSImpl*)doc->createElementNS(namespaceURI, name);

        // transfer the userData
        doc->transferUserData(castToNodeImpl(this), castToNodeImpl(newElem));

        // remove old node from parent if any
        DOMNode* parent = getParentNode();
        DOMNode* nextSib = getNextSibling();
        if (parent) {
            parent->removeChild(this);
        }

        // move children to new node
        DOMNode* child = getFirstChild();
        while (child) {
            removeChild(child);
            newElem->appendChild(child);
            child = getFirstChild();
        }

        // insert new node where old one was
        if (parent) {
            parent->insertBefore(newElem, nextSib);
        }

        // move specified attributes to new node
        newElem->fAttributes->moveSpecifiedAttributes(fAttributes);

        // and fire user data NODE_RENAMED event
        castToNodeImpl(newElem)->callUserDataHandlers(DOMUserDataHandler::NODE_RENAMED, this, newElem);

        return newElem;
    }
}
Exemplo n.º 28
0
  void
  SVGTextPathElement::buildBezier(svgl::Context * svglContext, svgl::GLInfo* glinfo, svgl::TextInfo* textinfo)
  {

    if(!_bezier) {
      unicode::String* ref = GETVAL(Href);
      SVGPathElement* path=0;
    
      if (ref) {
	dom::Element* de = svglContext->externalEntityManager->get(ref, getOwnerDocument());
	path = dynamic_cast<SVGPathElement*>(de);
      }
      if(!path)
	//std::cerr << "textPath " << ref << " " __FILE__ ":" << __LINE__ << std::endl;
	return;

      const SVGPathSegList& pl = path->GET_SIMPLE_VAL(PathSegList);
      if (pl.numberOfItems()<2)
	return;

      _bezier = new BezierPath;
      
      for(unsigned int i=0; i<pl.numberOfItems(); ++i) {
	const SVGPathSeg* p = pl.getItem(i);
	p->updateBezier(*_bezier);
      }
    }

    svg::SVGLength startOffsetl = GETVAL(StartOffset);

    float startOffset_ = 0;
    {
      float sav = svglContext->viewport_width;
      svglContext->viewport_width = svgl::length(*_bezier);
      startOffset_ = svglContext->computeWidthLength(startOffsetl);
      //std::cerr << DBGVAR(startOffsetl.getValueInSpecifiedUnits().getValue()) << DBGVAR(svglContext->viewport_width) << __FL__;
      svglContext->viewport_width = sav;
    }
    //std::cerr << DBGVAR(startOffset_) << __FL__;
    textinfo->distanceIterator= new svgl::BezierPathDistanceIterator(*_bezier);
    textinfo->distanceIterator->advance(startOffset_);
    textinfo->x = textinfo->distanceIterator->x /*+ textinfo->distanceIterator->dx*/;
    textinfo->y = textinfo->distanceIterator->y /*+ textinfo->distanceIterator->dy*/;

    //std::cerr << DBGVAR(startOffset_) << DBGVAR(textinfo->distanceIterator->x) << DBGVAR(textinfo->distanceIterator->y) << DBGVAR(textinfo->distanceIterator->dx) << DBGVAR(textinfo->distanceIterator->dy) << __FL__;
  }
Exemplo n.º 29
0
void DOMElementNSImpl::setName(const XMLCh *namespaceURI,
                               const XMLCh *qualifiedName)
{
    DOMDocumentImpl* ownerDoc = (DOMDocumentImpl *) getOwnerDocument();
    this->fName = ownerDoc->getPooledString(qualifiedName);

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

    if (index == 0) {	//qualifiedName contains no ':'
        this -> fPrefix = 0;
        this -> fLocalName = this -> fName;
    } else {	//0 < index < this->name.length()-1
        XMLCh* newName;
        XMLCh temp[4000];
        if (index >= 3999)
            newName = (XMLCh*) ownerDoc->getMemoryManager()->allocate
            (
                (XMLString::stringLen(qualifiedName) + 1) * sizeof(XMLCh)
            );//new XMLCh[XMLString::stringLen(qualifiedName)+1];
        else
            newName = temp;

        XMLString::copyNString(newName, fName, index);
        newName[index] = chNull;
        this-> fPrefix = ownerDoc->getPooledString(newName);
        this -> fLocalName = ownerDoc->getPooledString(fName+index+1);

        if (index >= 3999)
            ownerDoc->getMemoryManager()->deallocate(newName);//delete[] newName;

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

    // DOM Level 3: namespace URI is never empty string.
    const XMLCh * URI = DOMNodeImpl::mapPrefix
        (
            fPrefix,
            (!namespaceURI || !*namespaceURI) ? 0 : namespaceURI,
            DOMNode::ELEMENT_NODE
        );
    this -> fNamespaceURI = (URI == 0) ? 0 : ownerDoc->getPooledString(URI);
}
Exemplo n.º 30
0
  void
  SVGGElement::pickTraverse(svgl::Context * svglContext, svgl::GLInfo* glinfo)
  {
    glPushMatrix();
    SVGTransformable::glTraverse(svglContext, glinfo);

    svg::SVGClipPathElement *clippath_element=0;

    clippath_element = getSVGClipPathElement(svglContext->externalEntityManager, getOwnerDocument());
    if(clippath_element)
      clippath_element->pickTraverse(svglContext, glinfo);

    glinfo->pushPickInfo(this);
    pickTraverseChildren(svglContext, glinfo);
    glinfo->popPickInfo();

    glPopMatrix();

  }