Exemple #1
0
        private List <DTDTestmuster> GetAlleTestmuster(XMLCursorPos cursorPos)
        {
            List <DTDTestmuster> alleMuster = new List <DTDTestmuster>();

            if (cursorPos.AktNode == null)
            {
                throw new ApplicationException("GetAlleTestmuster: cursorPos.AktNode=NULL!");
            }
            switch (cursorPos.PosAmNode)
            {
            case XMLCursorPositionen.CursorVorDemNode:
            case XMLCursorPositionen.CursorAufNodeSelbstVorderesTag:
            case XMLCursorPositionen.CursorAufNodeSelbstHinteresTag:
            case XMLCursorPositionen.CursorInDemLeeremNode:
            case XMLCursorPositionen.CursorInnerhalbDesTextNodes:
            case XMLCursorPositionen.CursorHinterDemNode:
                if (!(cursorPos.AktNode is XmlComment))
                {
                    StringCollection stringCollection;
                    if (cursorPos.PosAmNode == XMLCursorPositionen.CursorInDemLeeremNode)
                    {
                        DTDElement dtdElement = this._dtd.DTDElementByName(cursorPos.AktNode.Name, false);
                        stringCollection = dtdElement != null ? dtdElement.AlleElementNamenWelcheAlsDirektesChildZulaessigSind : new StringCollection();
                    }
                    else if (cursorPos.AktNode.OwnerDocument == null)
                    {
                        stringCollection = new StringCollection();
                    }
                    else if (cursorPos.AktNode == cursorPos.AktNode.OwnerDocument.DocumentElement)
                    {
                        stringCollection = new StringCollection();
                    }
                    else
                    {
                        DTDElement dtdElement = this._dtd.DTDElementByName(cursorPos.AktNode.ParentNode.Name, false);
                        stringCollection = dtdElement != null ? dtdElement.AlleElementNamenWelcheAlsDirektesChildZulaessigSind : new StringCollection();
                    }
                    foreach (string elementName in stringCollection)
                    {
                        DTDTestmuster testMuster = this.CreateTestMuster(elementName, cursorPos);
                        alleMuster.Add(testMuster);
                    }
                }
                if (!de.springwald.toolbox.Debugger.WORKAROUND)
                {
                    this.PruefeAlleTestmuster(alleMuster, cursorPos);
                }
                return(alleMuster);

            default:
                throw new ApplicationException(string.Format("unknown cursorPos.StartPos.PosAmNode '{0}' detected.", (object)cursorPos.PosAmNode));
            }
        }
Exemple #2
0
        private void PruefeAlleTestmuster(List <DTDTestmuster> alleMuster, XMLCursorPos cursorPos)
        {
            XmlNode    aktNode = cursorPos.AktNode;
            DTDElement element;

            if (cursorPos.PosAmNode == XMLCursorPositionen.CursorInDemLeeremNode)
            {
                element = this._dtd.DTDElementByName(DTD.GetElementNameFromNode(aktNode), false);
            }
            else
            {
                if (aktNode.OwnerDocument == null || aktNode.OwnerDocument.DocumentElement == null)
                {
                    return;
                }
                if (aktNode == aktNode.OwnerDocument.DocumentElement)
                {
                    using (List <DTDTestmuster> .Enumerator enumerator = alleMuster.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            DTDTestmuster current = enumerator.Current;
                            if (current.ElementName == aktNode.Name)
                            {
                                current.Erfolgreich = true;
                            }
                        }
                        return;
                    }
                }
                else
                {
                    element = this._dtd.DTDElementByName(DTD.GetElementNameFromNode(aktNode.ParentNode), false);
                }
            }
            foreach (DTDTestmuster muster in alleMuster)
            {
                if (element == null)
                {
                    muster.Erfolgreich = false;
                }
                else if (!muster.Erfolgreich)
                {
                    muster.Erfolgreich = this.PasstMusterInElement(muster, element);
                }
            }
        }
Exemple #3
0
        public bool IstDerNodeAnDieserStelleErlaubt(XmlNode node)
        {
            if (node.ParentNode is XmlDocument)
            {
                return(true);
            }
            XMLCursorPos cursorPos = new XMLCursorPos();

            cursorPos.CursorSetzen(node, XMLCursorPositionen.CursorAufNodeSelbstVorderesTag);
            DTDTestmuster testMuster = this.CreateTestMuster(DTD.GetElementNameFromNode(node), cursorPos);

            this.PruefeAlleTestmuster(new List <DTDTestmuster>()
            {
                testMuster
            }, cursorPos);
            return(testMuster.Erfolgreich);
        }
Exemple #4
0
        public bool IstDerNodeAnDieserStelleErlaubt(XmlNode node)
        {
            if (node.ParentNode is XmlDocument)
            {
                return(true);
            }
            XMLCursorPos xMLCursorPos = new XMLCursorPos();

            xMLCursorPos.CursorSetzen(node, XMLCursorPositionen.CursorAufNodeSelbstVorderesTag);
            string               elementNameFromNode = DTD.GetElementNameFromNode(node);
            DTDTestmuster        dTDTestmuster       = this.CreateTestMuster(elementNameFromNode, xMLCursorPos);
            List <DTDTestmuster> list = new List <DTDTestmuster>();

            list.Add(dTDTestmuster);
            this.PruefeAlleTestmuster(list, xMLCursorPos);
            if (dTDTestmuster.Erfolgreich)
            {
                return(true);
            }
            return(false);
        }
Exemple #5
0
        private DTDTestmuster CreateTestMuster(string elementName, XMLCursorPos cursorPos)
        {
            XmlNode       aktNode = cursorPos.AktNode;
            DTDTestmuster dtdTestmuster;

            if (cursorPos.PosAmNode == XMLCursorPositionen.CursorInDemLeeremNode)
            {
                dtdTestmuster = new DTDTestmuster(elementName, DTD.GetElementNameFromNode(aktNode));
                dtdTestmuster.AddElement(elementName);
            }
            else
            {
                if (aktNode.ParentNode is XmlDocument)
                {
                    throw new ApplicationException(ResReader.Reader.GetString("FuerRootElementKeinTestmuster"));
                }
                dtdTestmuster = new DTDTestmuster(elementName, DTD.GetElementNameFromNode(aktNode.ParentNode));
                for (XmlNode node = aktNode.ParentNode.FirstChild; node != null; node = node.NextSibling)
                {
                    if (!(node is XmlWhitespace))
                    {
                        if (node == aktNode)
                        {
                            if (node is XmlComment)
                            {
                                dtdTestmuster.AddElement("#COMMENT");
                            }
                            else if (this._dtd.DTDElementByName(DTD.GetElementNameFromNode(aktNode), false) != null)
                            {
                                switch (cursorPos.PosAmNode)
                                {
                                case XMLCursorPositionen.CursorVorDemNode:
                                    if (elementName == null)
                                    {
                                        throw new ApplicationException("CreateTestMuster: Löschen darf bei XMLCursorPositionen.CursorVorDemNode nicht geprüft werden!");
                                    }
                                    dtdTestmuster.AddElement(elementName);
                                    dtdTestmuster.AddElement(DTD.GetElementNameFromNode(aktNode));
                                    break;

                                case XMLCursorPositionen.CursorAufNodeSelbstVorderesTag:
                                case XMLCursorPositionen.CursorAufNodeSelbstHinteresTag:
                                    if (elementName != null)
                                    {
                                        dtdTestmuster.AddElement(elementName);
                                        break;
                                    }
                                    break;

                                case XMLCursorPositionen.CursorInDemLeeremNode:
                                    if (elementName == null)
                                    {
                                        throw new ApplicationException("CreateTestMuster: Löschen darf bei XMLCursorPositionen.CursorHinterDemNode nicht geprüft werden!");
                                    }
                                    throw new ApplicationException("CreateTestMuster: CursorInDemLeeremNode can´t be handled at this place!");

                                case XMLCursorPositionen.CursorInnerhalbDesTextNodes:
                                    if (elementName == null)
                                    {
                                        throw new ApplicationException("CreateTestMuster: Löschen darf bei XMLCursorPositionen.CursorInnerhalbDesTextNodes nicht geprüft werden!");
                                    }
                                    if (DTD.GetElementNameFromNode(aktNode) != "#PCDATA")
                                    {
                                        throw new ApplicationException("CreateTestMuster: CursorInnerhalbDesTextNodes angegeben, aber node.name=" + DTD.GetElementNameFromNode(aktNode));
                                    }
                                    dtdTestmuster.AddElement("#PCDATA");
                                    dtdTestmuster.AddElement(elementName);
                                    dtdTestmuster.AddElement("#PCDATA");
                                    break;

                                case XMLCursorPositionen.CursorHinterDemNode:
                                    if (elementName == null)
                                    {
                                        throw new ApplicationException("CreateTestMuster: Löschen darf bei XMLCursorPositionen.CursorHinterDemNode nicht geprüft werden!");
                                    }
                                    dtdTestmuster.AddElement(DTD.GetElementNameFromNode(aktNode));
                                    dtdTestmuster.AddElement(elementName);
                                    break;

                                default:
                                    throw new ApplicationException("Unknown XMLCursorPositionen value:" + (object)cursorPos.PosAmNode);
                                }
                            }
                        }
                        else
                        {
                            dtdTestmuster.AddElement(DTD.GetElementNameFromNode(node));
                        }
                    }
                }
            }
            return(dtdTestmuster);
        }
Exemple #6
0
 private bool PasstMusterInElement(DTDTestmuster muster, DTDElement element)
 {
     return(element.ChildrenRegExObjekt.Match(muster.VergleichStringFuerRegEx).Success);
 }
Exemple #7
0
        private List <DTDTestmuster> GetAlleTestmuster(XMLCursorPos cursorPos)
        {
            List <DTDTestmuster> list = new List <DTDTestmuster>();

            if (cursorPos.AktNode == null)
            {
                throw new ApplicationException("GetAlleTestmuster: cursorPos.AktNode=NULL!");
            }
            switch (cursorPos.PosAmNode)
            {
            default:
                throw new ApplicationException(string.Format("unknown cursorPos.StartPos.PosAmNode '{0}' detected.", cursorPos.PosAmNode));

            case XMLCursorPositionen.CursorVorDemNode:
            case XMLCursorPositionen.CursorAufNodeSelbstVorderesTag:
            case XMLCursorPositionen.CursorAufNodeSelbstHinteresTag:
            case XMLCursorPositionen.CursorInDemLeeremNode:
            case XMLCursorPositionen.CursorInnerhalbDesTextNodes:
            case XMLCursorPositionen.CursorHinterDemNode:
                if (!(cursorPos.AktNode is XmlComment))
                {
                    StringCollection stringCollection;
                    if (cursorPos.PosAmNode == XMLCursorPositionen.CursorInDemLeeremNode)
                    {
                        DTDElement dTDElement = this._dtd.DTDElementByName(cursorPos.AktNode.Name, false);
                        stringCollection = ((dTDElement != null) ? dTDElement.AlleElementNamenWelcheAlsDirektesChildZulaessigSind : new StringCollection());
                    }
                    else if (cursorPos.AktNode.OwnerDocument == null)
                    {
                        stringCollection = new StringCollection();
                    }
                    else if (cursorPos.AktNode == cursorPos.AktNode.OwnerDocument.DocumentElement)
                    {
                        stringCollection = new StringCollection();
                    }
                    else
                    {
                        DTDElement dTDElement2 = this._dtd.DTDElementByName(cursorPos.AktNode.ParentNode.Name, false);
                        stringCollection = ((dTDElement2 != null) ? dTDElement2.AlleElementNamenWelcheAlsDirektesChildZulaessigSind : new StringCollection());
                    }
                    StringEnumerator enumerator = stringCollection.GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            string        current = enumerator.Current;
                            DTDTestmuster item    = this.CreateTestMuster(current, cursorPos);
                            list.Add(item);
                        }
                    }
                    finally
                    {
                        IDisposable disposable = enumerator as IDisposable;
                        if (disposable != null)
                        {
                            disposable.Dispose();
                        }
                    }
                }
                this.PruefeAlleTestmuster(list, cursorPos);
                return(list);
            }
        }