示例#1
0
        /* --------------------- DOM ---------------------------- */

        /// <seealso cref="Comzept.Genesis.Tidy.Dom.Node.insertBefore">
        /// </seealso>
        public virtual Comzept.Genesis.Tidy.Dom.Node insertBefore(Comzept.Genesis.Tidy.Dom.Node newChild, Comzept.Genesis.Tidy.Dom.Node refChild)
        {
            // TODO - handle newChild already in tree

            if (newChild == null)
            {
                return(null);
            }
            if (!(newChild is DOMNodeImpl))
            {
                throw new DOMExceptionImpl(DOMException.WRONG_DOCUMENT_ERR, "newChild not instanceof DOMNodeImpl");
            }
            DOMNodeImpl newCh = (DOMNodeImpl)newChild;

            if (this.adaptee.type == Node.RootNode)
            {
                if (newCh.adaptee.type != Node.DocTypeTag && newCh.adaptee.type != Node.ProcInsTag)
                {
                    throw new DOMExceptionImpl(DOMException.HIERARCHY_REQUEST_ERR, "newChild cannot be a child of this node");
                }
            }
            else if (this.adaptee.type == Node.StartTag)
            {
                if (newCh.adaptee.type != Node.StartTag && newCh.adaptee.type != Node.StartEndTag && newCh.adaptee.type != Node.CommentTag && newCh.adaptee.type != Node.TextNode && newCh.adaptee.type != Node.CDATATag)
                {
                    throw new DOMExceptionImpl(DOMException.HIERARCHY_REQUEST_ERR, "newChild cannot be a child of this node");
                }
            }
            if (refChild == null)
            {
                Node.insertNodeAtEnd(this.adaptee, newCh.adaptee);
                if (this.adaptee.type == Node.StartEndTag)
                {
                    this.adaptee.Type = Node.StartTag;
                }
            }
            else
            {
                Node ref_Renamed = this.adaptee.content;
                while (ref_Renamed != null)
                {
                    if (ref_Renamed.Adapter == refChild)
                    {
                        break;
                    }
                    ref_Renamed = ref_Renamed.next;
                }
                if (ref_Renamed == null)
                {
                    throw new DOMExceptionImpl(DOMException.NOT_FOUND_ERR, "refChild not found");
                }
                Node.insertNodeBeforeElement(ref_Renamed, newCh.adaptee);
            }
            return(newChild);
        }
示例#2
0
        /// <seealso cref="Comzept.Genesis.Tidy.Dom.Node.appendChild">
        /// </seealso>
        public virtual Comzept.Genesis.Tidy.Dom.Node appendChild(Comzept.Genesis.Tidy.Dom.Node newChild)
        {
            // TODO - handle newChild already in tree

            if (newChild == null)
            {
                return(null);
            }
            if (!(newChild is DOMNodeImpl))
            {
                throw new DOMExceptionImpl(DOMException.WRONG_DOCUMENT_ERR, "newChild not instanceof DOMNodeImpl");
            }
            DOMNodeImpl newCh = (DOMNodeImpl)newChild;

            if (this.adaptee.type == Node.RootNode)
            {
                if (newCh.adaptee.type != Node.DocTypeTag && newCh.adaptee.type != Node.ProcInsTag)
                {
                    throw new DOMExceptionImpl(DOMException.HIERARCHY_REQUEST_ERR, "newChild cannot be a child of this node");
                }
            }
            else if (this.adaptee.type == Node.StartTag)
            {
                if (newCh.adaptee.type != Node.StartTag && newCh.adaptee.type != Node.StartEndTag && newCh.adaptee.type != Node.CommentTag && newCh.adaptee.type != Node.TextNode && newCh.adaptee.type != Node.CDATATag)
                {
                    throw new DOMExceptionImpl(DOMException.HIERARCHY_REQUEST_ERR, "newChild cannot be a child of this node");
                }
            }
            Node.insertNodeAtEnd(this.adaptee, newCh.adaptee);

            if (this.adaptee.type == Node.StartEndTag)
            {
                this.adaptee.Type = Node.StartTag;
            }

            return(newChild);
        }
示例#3
0
        /// <seealso cref="Comzept.Genesis.Tidy.Dom.Node.replaceChild">
        /// </seealso>
        public virtual Comzept.Genesis.Tidy.Dom.Node replaceChild(Comzept.Genesis.Tidy.Dom.Node newChild, Comzept.Genesis.Tidy.Dom.Node oldChild)
        {
            // TODO - handle newChild already in tree

            if (newChild == null)
            {
                return(null);
            }
            if (!(newChild is DOMNodeImpl))
            {
                throw new DOMExceptionImpl(DOMException.WRONG_DOCUMENT_ERR, "newChild not instanceof DOMNodeImpl");
            }
            DOMNodeImpl newCh = (DOMNodeImpl)newChild;

            if (this.adaptee.type == Node.RootNode)
            {
                if (newCh.adaptee.type != Node.DocTypeTag && newCh.adaptee.type != Node.ProcInsTag)
                {
                    throw new DOMExceptionImpl(DOMException.HIERARCHY_REQUEST_ERR, "newChild cannot be a child of this node");
                }
            }
            else if (this.adaptee.type == Node.StartTag)
            {
                if (newCh.adaptee.type != Node.StartTag && newCh.adaptee.type != Node.StartEndTag && newCh.adaptee.type != Node.CommentTag && newCh.adaptee.type != Node.TextNode && newCh.adaptee.type != Node.CDATATag)
                {
                    throw new DOMExceptionImpl(DOMException.HIERARCHY_REQUEST_ERR, "newChild cannot be a child of this node");
                }
            }
            if (oldChild == null)
            {
                throw new DOMExceptionImpl(DOMException.NOT_FOUND_ERR, "oldChild not found");
            }
            else
            {
                Node n;
                Node ref_Renamed = this.adaptee.content;
                while (ref_Renamed != null)
                {
                    if (ref_Renamed.Adapter == oldChild)
                    {
                        break;
                    }
                    ref_Renamed = ref_Renamed.next;
                }
                if (ref_Renamed == null)
                {
                    throw new DOMExceptionImpl(DOMException.NOT_FOUND_ERR, "oldChild not found");
                }
                newCh.adaptee.next    = ref_Renamed.next;
                newCh.adaptee.prev    = ref_Renamed.prev;
                newCh.adaptee.last    = ref_Renamed.last;
                newCh.adaptee.parent  = ref_Renamed.parent;
                newCh.adaptee.content = ref_Renamed.content;
                if (ref_Renamed.parent != null)
                {
                    if (ref_Renamed.parent.content == ref_Renamed)
                    {
                        ref_Renamed.parent.content = newCh.adaptee;
                    }
                    if (ref_Renamed.parent.last == ref_Renamed)
                    {
                        ref_Renamed.parent.last = newCh.adaptee;
                    }
                }
                if (ref_Renamed.prev != null)
                {
                    ref_Renamed.prev.next = newCh.adaptee;
                }
                if (ref_Renamed.next != null)
                {
                    ref_Renamed.next.prev = newCh.adaptee;
                }
                for (n = ref_Renamed.content; n != null; n = n.next)
                {
                    if (n.parent == ref_Renamed)
                    {
                        n.parent = newCh.adaptee;
                    }
                }
            }
            return(oldChild);
        }