Beispiel #1
0
 private void TextZwischenZweiNodesEinfuegen(XmlNode nodeVorher, XmlNode nodeNachher, string text, XMLRegelwerk regelwerk)
 {
     if (ToolboxXML.IstTextOderKommentarNode(nodeVorher))
     {
         nodeVorher.InnerText += text;
         this.CursorSetzen(nodeVorher, XMLCursorPositionen.CursorInnerhalbDesTextNodes, nodeVorher.InnerText.Length);
     }
     else if (ToolboxXML.IstTextOderKommentarNode(nodeNachher))
     {
         nodeNachher.InnerText = text + nodeNachher.InnerText;
         this.CursorSetzen(nodeNachher, XMLCursorPositionen.CursorInnerhalbDesTextNodes, text.Length);
     }
     else if (regelwerk.IstDiesesTagAnDieserStelleErlaubt("#PCDATA", this))
     {
         XmlText node = this.AktNode.OwnerDocument.CreateTextNode(text);
         this.InsertXMLNode(node, regelwerk, false);
     }
 }
Beispiel #2
0
        public bool MoveRight(XmlNode rootnode, XMLRegelwerk regelwerk)
        {
            XmlNode aktNode = this.AktNode;

            switch (this.PosAmNode)
            {
            case XMLCursorPositionen.CursorAufNodeSelbstVorderesTag:
            case XMLCursorPositionen.CursorAufNodeSelbstHinteresTag:
                this.CursorSetzen(this.AktNode, XMLCursorPositionen.CursorHinterDemNode);
                goto IL_0208;

            case XMLCursorPositionen.CursorHinterDemNode:
                if (aktNode.NextSibling != null)
                {
                    this.CursorSetzen(aktNode.NextSibling, XMLCursorPositionen.CursorVorDemNode);
                    this.MoveRight(rootnode, regelwerk);
                    goto IL_0208;
                }
                if (aktNode.ParentNode != rootnode)
                {
                    this.CursorSetzen(aktNode.ParentNode, XMLCursorPositionen.CursorHinterDemNode);
                    if (!regelwerk.IstSchliessendesTagSichtbar(aktNode.ParentNode))
                    {
                        this.MoveRight(rootnode, regelwerk);
                    }
                    goto IL_0208;
                }
                return(false);

            case XMLCursorPositionen.CursorInDemLeeremNode:
                this.CursorSetzen(this.AktNode, XMLCursorPositionen.CursorHinterDemNode);
                goto IL_0208;

            case XMLCursorPositionen.CursorVorDemNode:
                if (ToolboxXML.IstTextOderKommentarNode(aktNode))
                {
                    if (ToolboxXML.TextAusTextNodeBereinigt(aktNode).Length > 1)
                    {
                        this.CursorSetzen(this.AktNode, XMLCursorPositionen.CursorInnerhalbDesTextNodes, 1);
                    }
                    else
                    {
                        this.CursorSetzen(this.AktNode, XMLCursorPositionen.CursorHinterDemNode);
                    }
                }
                else if (aktNode.ChildNodes.Count < 1)
                {
                    if (!regelwerk.IstSchliessendesTagSichtbar(aktNode))
                    {
                        this.CursorSetzen(this.AktNode, XMLCursorPositionen.CursorHinterDemNode);
                    }
                    else
                    {
                        this.CursorSetzen(this.AktNode, XMLCursorPositionen.CursorInDemLeeremNode);
                    }
                }
                else
                {
                    this.CursorSetzen(aktNode.FirstChild, XMLCursorPositionen.CursorVorDemNode);
                }
                goto IL_0208;

            case XMLCursorPositionen.CursorInnerhalbDesTextNodes:
                if (ToolboxXML.IstTextOderKommentarNode(aktNode))
                {
                    if (ToolboxXML.TextAusTextNodeBereinigt(aktNode).Length > this.PosImTextnode + 1)
                    {
                        this.CursorSetzen(this.AktNode, this.PosAmNode, this.PosImTextnode + 1);
                    }
                    else
                    {
                        this.CursorSetzen(this.AktNode, XMLCursorPositionen.CursorHinterDemNode);
                    }
                    goto IL_0208;
                }
                throw new ApplicationException(string.Format("XMLCurorPos.MoveRight: CursorPos ist XMLCursorPositionen.CursorInnerhalbDesTextNodes, es ist aber kein Textnode gewählt, sondern der Node {0}", aktNode.OuterXml));

            default:
            {
                throw new ApplicationException(string.Format("XMLCurorPos.MoveRight: Unbekannte CursorPos {0}", this.PosAmNode));
            }
IL_0208:
                return(true);
            }
        }
Beispiel #3
0
        public bool SelektionLoeschen(out XMLCursorPos neueCursorPosNachLoeschen)
        {
            if (!this.IstEtwasSelektiert)
            {
                neueCursorPosNachLoeschen = this.StartPos.Clone();
                return(false);
            }
            if (this.StartPos.AktNode == this.EndPos.AktNode)
            {
                switch (this.StartPos.PosAmNode)
                {
                case XMLCursorPositionen.CursorVorDemNode:
                    if (ToolboxXML.IstTextOderKommentarNode(this.StartPos.AktNode))
                    {
                        this.StartPos.CursorSetzen(this.StartPos.AktNode, XMLCursorPositionen.CursorInnerhalbDesTextNodes, 0);
                        return(this.SelektionLoeschen(out neueCursorPosNachLoeschen));
                    }
                    this.BeideCursorPosSetzen(this.StartPos.AktNode, XMLCursorPositionen.CursorAufNodeSelbstVorderesTag);
                    return(this.SelektionLoeschen(out neueCursorPosNachLoeschen));

                case XMLCursorPositionen.CursorAufNodeSelbstVorderesTag:
                case XMLCursorPositionen.CursorAufNodeSelbstHinteresTag:
                    XmlNode aktNode         = this.StartPos.AktNode;
                    XmlNode previousSibling = aktNode.PreviousSibling;
                    XmlNode nextSibling     = aktNode.NextSibling;
                    neueCursorPosNachLoeschen = new XMLCursorPos();
                    if (previousSibling != null && nextSibling != null && (previousSibling is XmlText && nextSibling is XmlText))
                    {
                        neueCursorPosNachLoeschen.CursorSetzen(previousSibling, XMLCursorPositionen.CursorInnerhalbDesTextNodes, previousSibling.InnerText.Length);
                        previousSibling.InnerText += nextSibling.InnerText;
                        aktNode.ParentNode.RemoveChild(aktNode);
                        nextSibling.ParentNode.RemoveChild(nextSibling);
                        return(true);
                    }
                    if (previousSibling != null)
                    {
                        neueCursorPosNachLoeschen.CursorSetzen(previousSibling, XMLCursorPositionen.CursorHinterDemNode);
                    }
                    else if (nextSibling != null)
                    {
                        neueCursorPosNachLoeschen.CursorSetzen(nextSibling, XMLCursorPositionen.CursorVorDemNode);
                    }
                    else
                    {
                        neueCursorPosNachLoeschen.CursorSetzen(aktNode.ParentNode, XMLCursorPositionen.CursorInDemLeeremNode);
                    }
                    aktNode.ParentNode.RemoveChild(aktNode);
                    return(true);

                case XMLCursorPositionen.CursorInDemLeeremNode:
                    if (this.EndPos.PosAmNode != XMLCursorPositionen.CursorHinterDemNode && this.EndPos.PosAmNode != XMLCursorPositionen.CursorVorDemNode)
                    {
                        throw new ApplicationException("AuswahlLoeschen:#6363S undefined Endpos " + (object)this.EndPos.PosAmNode + "!");
                    }
                    XMLCursor xmlCursor1 = new XMLCursor();
                    xmlCursor1.BeideCursorPosSetzen(this.StartPos.AktNode, XMLCursorPositionen.CursorAufNodeSelbstVorderesTag, 0);
                    return(xmlCursor1.SelektionLoeschen(out neueCursorPosNachLoeschen));

                case XMLCursorPositionen.CursorInnerhalbDesTextNodes:
                    int posImTextnode = this.StartPos.PosImTextnode;
                    int num           = this.EndPos.PosImTextnode;
                    if (this.EndPos.PosAmNode == XMLCursorPositionen.CursorHinterDemNode)
                    {
                        num = this.StartPos.AktNode.InnerText.Length;
                    }
                    if (posImTextnode == 0 && num >= this.StartPos.AktNode.InnerText.Length)
                    {
                        XMLCursor xmlCursor2 = new XMLCursor();
                        xmlCursor2.BeideCursorPosSetzen(this.StartPos.AktNode, XMLCursorPositionen.CursorAufNodeSelbstVorderesTag);
                        return(xmlCursor2.SelektionLoeschen(out neueCursorPosNachLoeschen));
                    }
                    this.StartPos.AktNode.InnerText = this.StartPos.AktNode.InnerText.Remove(posImTextnode, num - posImTextnode);
                    neueCursorPosNachLoeschen       = new XMLCursorPos();
                    if (posImTextnode == 0)
                    {
                        neueCursorPosNachLoeschen.CursorSetzen(this.StartPos.AktNode, XMLCursorPositionen.CursorVorDemNode);
                    }
                    else
                    {
                        neueCursorPosNachLoeschen.CursorSetzen(this.StartPos.AktNode, XMLCursorPositionen.CursorInnerhalbDesTextNodes, posImTextnode);
                    }
                    return(true);

                case XMLCursorPositionen.CursorHinterDemNode:
                    if (ToolboxXML.IstTextOderKommentarNode(this.StartPos.AktNode))
                    {
                        this.StartPos.CursorSetzen(this.StartPos.AktNode, XMLCursorPositionen.CursorInnerhalbDesTextNodes, this.StartPos.AktNode.InnerText.Length);
                        return(this.SelektionLoeschen(out neueCursorPosNachLoeschen));
                    }
                    this.BeideCursorPosSetzen(this.StartPos.AktNode, XMLCursorPositionen.CursorAufNodeSelbstVorderesTag);
                    return(this.SelektionLoeschen(out neueCursorPosNachLoeschen));

                default:
                    throw new ApplicationException("AuswahlLoeschen:#63346 StartPos.PosAmNode " + (object)this.StartPos.PosAmNode + " not allowed!");
                }
            }
            else
            {
                while (this.StartPos.AktNode.NextSibling != this.EndPos.AktNode)
                {
                    this.StartPos.AktNode.ParentNode.RemoveChild(this.StartPos.AktNode.NextSibling);
                }
                XMLCursor xmlCursor2 = this.Clone();
                xmlCursor2.StartPos.CursorSetzen(this.EndPos.AktNode, XMLCursorPositionen.CursorVorDemNode);
                XMLCursorPos neueCursorPosNachLoeschen1;
                xmlCursor2.SelektionLoeschen(out neueCursorPosNachLoeschen1);
                this.EndPos.CursorSetzen(this.StartPos.AktNode, XMLCursorPositionen.CursorHinterDemNode);
                return(this.SelektionLoeschen(out neueCursorPosNachLoeschen));
            }
        }
Beispiel #4
0
        public bool MoveLeft(XmlNode rootnode, XMLRegelwerk regelwerk)
        {
            XmlNode aktNode = this.AktNode;

            switch (this.PosAmNode)
            {
            case XMLCursorPositionen.CursorVorDemNode:
                if (aktNode == rootnode)
                {
                    return(false);
                }
                if (aktNode.PreviousSibling != null)
                {
                    this.CursorSetzen(aktNode.PreviousSibling, XMLCursorPositionen.CursorHinterDemNode);
                    this.MoveLeft(rootnode, regelwerk);
                    break;
                }
                this.CursorSetzen(aktNode.ParentNode, XMLCursorPositionen.CursorVorDemNode);
                break;

            case XMLCursorPositionen.CursorAufNodeSelbstVorderesTag:
            case XMLCursorPositionen.CursorAufNodeSelbstHinteresTag:
                this.CursorSetzen(this.AktNode, XMLCursorPositionen.CursorVorDemNode);
                break;

            case XMLCursorPositionen.CursorInDemLeeremNode:
                this.CursorSetzen(this.AktNode, XMLCursorPositionen.CursorVorDemNode);
                break;

            case XMLCursorPositionen.CursorInnerhalbDesTextNodes:
                if (!ToolboxXML.IstTextOderKommentarNode(aktNode))
                {
                    throw new ApplicationException(string.Format("XMLCursorPos.MoveLeft: CursorPos ist XMLCursorPositionen.CursorInnerhalbDesTextNodes, es ist aber kein Textnode gewählt, sondern der Node {0}", (object)aktNode.OuterXml));
                }
                if (this.PosImTextnode > 1)
                {
                    this.CursorSetzen(this.AktNode, this.PosAmNode, this.PosImTextnode - 1);
                    break;
                }
                this.CursorSetzen(this.AktNode, XMLCursorPositionen.CursorVorDemNode);
                break;

            case XMLCursorPositionen.CursorHinterDemNode:
                if (ToolboxXML.IstTextOderKommentarNode(aktNode))
                {
                    this.CursorSetzen(aktNode, XMLCursorPositionen.CursorInnerhalbDesTextNodes, Math.Max(0, ToolboxXML.TextAusTextNodeBereinigt(aktNode).Length - 1));
                    break;
                }
                if (aktNode.ChildNodes.Count < 1)
                {
                    if (regelwerk.IstSchliessendesTagSichtbar(aktNode))
                    {
                        this.CursorSetzen(this.AktNode, XMLCursorPositionen.CursorInDemLeeremNode);
                    }
                    else
                    {
                        this.CursorSetzen(this.AktNode, XMLCursorPositionen.CursorVorDemNode);
                    }
                }
                else
                {
                    this.CursorSetzen(aktNode.LastChild, XMLCursorPositionen.CursorHinterDemNode);
                }
                break;

            default:
                throw new ApplicationException(string.Format("XMLCursorPos.MoveLeft: Unbekannte CursorPos {0}", (object)this.PosAmNode));
            }
            return(true);
        }