private void ElementeAuslesen()
        {
            string     pattern    = "(?<element><!ELEMENT[\\t\\r\\n ]+[^>]+>)";
            Regex      regex      = new Regex(pattern);
            Match      match      = regex.Match(this._workingInhalt);
            SortedList sortedList = new SortedList();

            while (match.Success)
            {
                string     value      = match.Groups["element"].Value;
                DTDElement dTDElement = this.CreateElementFromQuellcode(value);
                try
                {
                    sortedList.Add(dTDElement.Name, dTDElement);
                }
                catch (ArgumentException ex)
                {
                    throw new ApplicationException(string.Format(ResReader.Reader.GetString("FehlerBeimLesenDesDTDELementes"), dTDElement.Name, ex.Message));
                }
                match = match.NextMatch();
            }
            for (int i = 0; i < sortedList.Count; i++)
            {
                this._elemente.Add((DTDElement)sortedList[sortedList.GetKey(i)]);
            }
        }
Ejemplo n.º 2
0
        private void CreateDTDAttributesForElement(DTDElement element)
        {
            element.Attribute = new List <DTDAttribut>();
            Match match1 = new Regex("(?<attributliste><!ATTLIST " + element.Name + "[\\t\\r\\n ]+(?<attribute>[^>]+?)[\\t\\r\\n ]?>)").Match(this._workingInhalt);

            if (!match1.Success)
            {
                return;
            }
            string input  = match1.Groups["attribute"].Value;
            Match  match2 = new Regex("[\\t\\r\\n ]?(?<name>[\\w-_]+)[\\t\\r\\n ]+(?<typ>CDATA|ID|IDREF|IDREFS|NMTOKEN|NMTOKENS|ENTITY|ENTITIES|NOTATION|xml:|[(][|\\w-_ \\t\\r\\n]+[)])[\\t\\r\\n ]+(?:(?<anzahl>#REQUIRED|#IMPLIED|#FIXED)[\\t\\r\\n ]+)?(?:\"(?<vorgabewert>[\\w-_]+)\")?[\\t\\r\\n ]?").Match(input);

            if (!match2.Success)
            {
                throw new ApplicationException(string.Format(ResReader.Reader.GetString("KeineAttributeInAttributListe"), (object)input));
            }
            char[] charArray = "|".ToCharArray();
            for (; match2.Success; match2 = match2.NextMatch())
            {
                DTDAttribut dtdAttribut = new DTDAttribut();
                dtdAttribut.Name         = match2.Groups["name"].Value;
                dtdAttribut.StandardWert = match2.Groups["vorgabewert"].Value;
                string str1 = match2.Groups["anzahl"].Value;
                if (!(str1 == "#REQUIRED"))
                {
                    if (!(str1 == "#IMPLIED") && (str1 == null || str1.Length != 0))
                    {
                        if (!(str1 == "#FIXED"))
                        {
                            throw new ApplicationException(string.Format(ResReader.Reader.GetString("UnbekannteAttributAnzahl"), (object)match2.Groups["anzahl"].Value, (object)match2.Value, (object)element.Name));
                        }
                        dtdAttribut.Pflicht = DTDAttribut.PflichtArten.Konstante;
                    }
                    else
                    {
                        dtdAttribut.Pflicht = DTDAttribut.PflichtArten.Optional;
                    }
                }
                else
                {
                    dtdAttribut.Pflicht = DTDAttribut.PflichtArten.Pflicht;
                }
                string str2 = match2.Groups["typ"].Value.Trim();
                if (str2.StartsWith("("))
                {
                    dtdAttribut.Typ = "";
                    foreach (string str3 in str2.Replace("(", "").Replace(")", "").Replace(")", "").Split(charArray))
                    {
                        string str4 = str3.Replace("\n", " ").Trim();
                        dtdAttribut.ErlaubteWerte.Add(str4);
                    }
                }
                else
                {
                    dtdAttribut.Typ = str2;
                }
                element.Attribute.Add(dtdAttribut);
            }
        }
Ejemplo n.º 3
0
 private string ElementName(DTDElement element)
 {
     if (element == null)
     {
         return("[null]");
     }
     return(element.Name);
 }
Ejemplo n.º 4
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));
            }
        }
        private DTDElement CreateElementFromQuellcode(string elementQuellcode)
        {
            if (elementQuellcode == "#PCDATA")
            {
                DTDElement dTDElement = new DTDElement();
                dTDElement.Name          = "#PCDATA";
                dTDElement.ChildElemente = new DTDChildElemente("");
                return(dTDElement);
            }
            if (elementQuellcode == "#COMMENT")
            {
                DTDElement dTDElement2 = new DTDElement();
                dTDElement2.Name          = "#COMMENT";
                dTDElement2.ChildElemente = new DTDChildElemente("");
                return(dTDElement2);
            }
            string pattern = "(?<element><!ELEMENT[\\t\\r\\n ]+(?<elementname>[\\w-_]+?)([\\t\\r\\n ]+(?<innerelements>[(]([\\t\\r\\n]|.)+?[)][*+]?)?)?(?<empty>[\\t\\r\\n ]+EMPTY)? *>)";
            Regex  regex   = new Regex(pattern);
            Match  match   = regex.Match(elementQuellcode);

            if (!match.Success)
            {
                throw new ApplicationException(string.Format(ResReader.Reader.GetString("NichtsImElementCodeGefunden"), elementQuellcode));
            }
            DTDElement dTDElement3 = new DTDElement();

            if (!match.Groups["elementname"].Success)
            {
                throw new ApplicationException(string.Format(ResReader.Reader.GetString("KeinNameInElementcodegefunden"), elementQuellcode));
            }
            dTDElement3.Name = match.Groups["elementname"].Value;
            this.CreateDTDAttributesForElement(dTDElement3);
            if (match.Groups["innerelements"].Success)
            {
                this.ChildElementeAuslesen(dTDElement3, match.Groups["innerelements"].Value);
            }
            else
            {
                this.ChildElementeAuslesen(dTDElement3, "");
            }
            match = match.NextMatch();
            if (match.Success)
            {
                throw new ApplicationException(string.Format(ResReader.Reader.GetString("MehrAlsEinsImElementCodeGefunden"), elementQuellcode));
            }
            return(dTDElement3);
        }
Ejemplo n.º 6
0
        private DTDElement CreateElementFromQuellcode(string elementQuellcode)
        {
            if (elementQuellcode == "#PCDATA")
            {
                return new DTDElement()
                       {
                           Name = "#PCDATA", ChildElemente = new DTDChildElemente("")
                       }
            }
            ;
            if (elementQuellcode == "#COMMENT")
            {
                return new DTDElement()
                       {
                           Name = "#COMMENT", ChildElemente = new DTDChildElemente("")
                       }
            }
            ;
            Match match = new Regex("(?<element><!ELEMENT[\\t\\r\\n ]+(?<elementname>[\\w-_]+?)([\\t\\r\\n ]+(?<innerelements>[(]([\\t\\r\\n]|.)+?[)][*+]?)?)?(?<empty>[\\t\\r\\n ]+EMPTY)? *>)").Match(elementQuellcode);

            if (!match.Success)
            {
                throw new ApplicationException(string.Format(ResReader.Reader.GetString("NichtsImElementCodeGefunden"), (object)elementQuellcode));
            }
            DTDElement element = new DTDElement();

            if (!match.Groups["elementname"].Success)
            {
                throw new ApplicationException(string.Format(ResReader.Reader.GetString("KeinNameInElementcodegefunden"), (object)elementQuellcode));
            }
            element.Name = match.Groups["elementname"].Value;
            this.CreateDTDAttributesForElement(element);
            if (match.Groups["innerelements"].Success)
            {
                this.ChildElementeAuslesen(element, match.Groups["innerelements"].Value);
            }
            else
            {
                this.ChildElementeAuslesen(element, "");
            }
            if (match.NextMatch().Success)
            {
                throw new ApplicationException(string.Format(ResReader.Reader.GetString("MehrAlsEinsImElementCodeGefunden"), (object)elementQuellcode));
            }
            return(element);
        }
Ejemplo n.º 7
0
        private void ElementeAuslesen()
        {
            Match      match      = new Regex("(?<element><!ELEMENT[\\t\\r\\n ]+[^>]+>)").Match(this._workingInhalt);
            SortedList sortedList = new SortedList();

            for (; match.Success; match = match.NextMatch())
            {
                DTDElement elementFromQuellcode = this.CreateElementFromQuellcode(match.Groups["element"].Value);
                try
                {
                    sortedList.Add((object)elementFromQuellcode.Name, (object)elementFromQuellcode);
                }
                catch (ArgumentException ex)
                {
                    throw new ApplicationException(string.Format(ResReader.Reader.GetString("FehlerBeimLesenDesDTDELementes"), (object)elementFromQuellcode.Name, (object)ex.Message));
                }
            }
            for (int index = 0; index < sortedList.Count; ++index)
            {
                this._elemente.Add((DTDElement)sortedList[sortedList.GetKey(index)]);
            }
        }
Ejemplo n.º 8
0
        public DTDElement DTDElementByNameIntern_(string elementName, bool fehlerWennNichtVorhanden)
        {
            DTDElement dTDElement = (DTDElement)this._elementeNachNamen[elementName];

            if (dTDElement != null)
            {
                return(dTDElement);
            }
            foreach (DTDElement item in this._elemente)
            {
                if (elementName == item.Name)
                {
                    this._elementeNachNamen.Add(elementName, item);
                    return(item);
                }
            }
            if (fehlerWennNichtVorhanden)
            {
                throw new XMLUnknownElementException(elementName);
            }
            return(null);
        }
Ejemplo n.º 9
0
        public DTDElement DTDElementByNameIntern_(
            string elementName,
            bool fehlerWennNichtVorhanden)
        {
            DTDElement dtdElement1 = (DTDElement)this._elementeNachNamen[(object)elementName];

            if (dtdElement1 != null)
            {
                return(dtdElement1);
            }
            foreach (DTDElement dtdElement2 in this._elemente)
            {
                if (elementName == dtdElement2.Name)
                {
                    this._elementeNachNamen.Add((object)elementName, (object)dtdElement2);
                    return(dtdElement2);
                }
            }
            if (fehlerWennNichtVorhanden)
            {
                throw new DTD.XMLUnknownElementException(elementName);
            }
            return((DTDElement)null);
        }
        private void CreateDTDAttributesForElement(DTDElement element)
        {
            element.Attribute = new List <DTDAttribut>();
            string pattern = "(?<attributliste><!ATTLIST " + element.Name + "[\\t\\r\\n ]+(?<attribute>[^>]+?)[\\t\\r\\n ]?>)";
            Regex  regex   = new Regex(pattern);
            Match  match   = regex.Match(this._workingInhalt);

            if (!match.Success)
            {
                return;
            }
            string value    = match.Groups["attribute"].Value;
            string pattern2 = "[\\t\\r\\n ]?(?<name>[\\w-_]+)[\\t\\r\\n ]+(?<typ>CDATA|ID|IDREF|IDREFS|NMTOKEN|NMTOKENS|ENTITY|ENTITIES|NOTATION|xml:|[(][|\\w-_ \\t\\r\\n]+[)])[\\t\\r\\n ]+(?:(?<anzahl>#REQUIRED|#IMPLIED|#FIXED)[\\t\\r\\n ]+)?(?:\"(?<vorgabewert>[\\w-_]+)\")?[\\t\\r\\n ]?";
            Regex  regex2   = new Regex(pattern2);

            match = regex2.Match(value);
            if (match.Success)
            {
                string text      = "|";
                char[] separator = text.ToCharArray();
                while (match.Success)
                {
                    DTDAttribut dTDAttribut = new DTDAttribut();
                    dTDAttribut.Name         = match.Groups["name"].Value;
                    dTDAttribut.StandardWert = match.Groups["vorgabewert"].Value;
                    string value2 = match.Groups["anzahl"].Value;
                    switch (value2)
                    {
                    default:
                        if (value2.Length != 0)
                        {
                            goto case null;
                        }
                        goto case "#IMPLIED";

                    case null:
                        if (value2 == "#FIXED")
                        {
                            dTDAttribut.Pflicht = DTDAttribut.PflichtArten.Konstante;
                            break;
                        }
                        throw new ApplicationException(string.Format(ResReader.Reader.GetString("UnbekannteAttributAnzahl"), match.Groups["anzahl"].Value, match.Value, element.Name));

                    case "#REQUIRED":
                        dTDAttribut.Pflicht = DTDAttribut.PflichtArten.Pflicht;
                        break;

                    case "#IMPLIED":
                        dTDAttribut.Pflicht = DTDAttribut.PflichtArten.Optional;
                        break;
                    }
                    string value3 = match.Groups["typ"].Value;
                    value3 = value3.Trim();
                    if (value3.StartsWith("("))
                    {
                        dTDAttribut.Typ = "";
                        value3          = value3.Replace("(", "");
                        value3          = value3.Replace(")", "");
                        value3          = value3.Replace(")", "");
                        string[] array  = value3.Split(separator);
                        string[] array2 = array;
                        foreach (string text2 in array2)
                        {
                            string text3 = text2.Replace("\n", " ");
                            text3 = text3.Trim();
                            dTDAttribut.ErlaubteWerte.Add(text3);
                        }
                    }
                    else
                    {
                        dTDAttribut.Typ = value3;
                    }
                    element.Attribute.Add(dTDAttribut);
                    match = match.NextMatch();
                }
                return;
            }
            throw new ApplicationException(string.Format(ResReader.Reader.GetString("KeineAttributeInAttributListe"), value));
        }
 private void ChildElementeAuslesen(DTDElement element, string childElementeQuellcode)
 {
     element.ChildElemente = new DTDChildElemente(childElementeQuellcode);
 }
Ejemplo n.º 12
0
 private bool PasstMusterInElement(DTDTestmuster muster, DTDElement element)
 {
     return(element.ChildrenRegExObjekt.Match(muster.VergleichStringFuerRegEx).Success);
 }
Ejemplo n.º 13
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);
            }
        }