コード例 #1
0
 public DTDSequenceAutomata(DTDObjectModel root,
                            DTDAutomata left, DTDAutomata right)
     : base(root)
 {
     this.left  = left;
     this.right = right;
 }
コード例 #2
0
 public DTDAutomata MakeChoice(DTDAutomata other)
 {
     if (this == Root.Invalid)
     {
         return(other);
     }
     if (other == Root.Invalid)
     {
         return(this);
     }
     if (this == Root.Empty && other == Root.Empty)
     {
         return(this);
     }
     if (this == Root.Any && other == Root.Any)
     {
         return(this);
     }
     else if (other == Root.Empty)
     {
         return(Root.Factory.Choice(other, this));
     }
     else
     {
         return(Root.Factory.Choice(this, other));
     }
 }
コード例 #3
0
        private DTDAutomata CompileInternal()
        {
            if (ElementDecl.IsAny)
            {
                return(root.Any);
            }
            if (ElementDecl.IsEmpty)
            {
                return(root.Empty);
            }

            DTDAutomata basis = GetBasicContentAutomata();

            switch (Occurence)
            {
            case DTDOccurence.One:
                return(basis);

            case DTDOccurence.Optional:
                return(Choice(root.Empty, basis));

            case DTDOccurence.OneOrMore:
                return(new DTDOneOrMoreAutomata(root, basis));

            case DTDOccurence.ZeroOrMore:
                return(Choice(root.Empty, new DTDOneOrMoreAutomata(root, basis)));
            }
            throw new InvalidOperationException();
        }
コード例 #4
0
        private DTDAutomata CompileInternal()
        {
            if (this.ElementDecl.IsAny)
            {
                return(this.root.Any);
            }
            if (this.ElementDecl.IsEmpty)
            {
                return(this.root.Empty);
            }
            DTDAutomata basicContentAutomata = this.GetBasicContentAutomata();

            switch (this.Occurence)
            {
            case DTDOccurence.One:
                return(basicContentAutomata);

            case DTDOccurence.Optional:
                return(this.Choice(this.root.Empty, basicContentAutomata));

            case DTDOccurence.ZeroOrMore:
                return(this.Choice(this.root.Empty, new DTDOneOrMoreAutomata(this.root, basicContentAutomata)));

            case DTDOccurence.OneOrMore:
                return(new DTDOneOrMoreAutomata(this.root, basicContentAutomata));

            default:
                throw new InvalidOperationException();
            }
        }
コード例 #5
0
        public override DTDAutomata TryStartElement(string name)
        {
            DTDAutomata dtdautomata = this.children.TryStartElement(name);

            if (dtdautomata != base.Root.Invalid)
            {
                return(dtdautomata.MakeSequence(base.Root.Empty.MakeChoice(this)));
            }
            return(base.Root.Invalid);
        }
コード例 #6
0
ファイル: DTDAutomata.cs プロジェクト: nobled/mono
		public DTDSequenceAutomata Sequence (DTDAutomata left, DTDAutomata right)
		{
			Hashtable rightPool = sequenceTable [left] as Hashtable;
			if (rightPool == null) {
				rightPool = new Hashtable ();
				sequenceTable [left] = rightPool;
			}
			DTDSequenceAutomata result = rightPool [right] as DTDSequenceAutomata;
			if (result == null) {
				result = new DTDSequenceAutomata (root, left, right);
				rightPool [right] = result;
			}
			return result;
		}
コード例 #7
0
        public override DTDAutomata TryStartElement(string name)
        {
            DTDAutomata afterC = children.TryStartElement(name);

            if (afterC != Root.Invalid)
            {
                return(afterC.MakeSequence(
                           Root.Empty.MakeChoice(this)));
            }
            else
            {
                return(Root.Invalid);
            }
        }
コード例 #8
0
 public DTDAutomata MakeSequence(DTDAutomata other)
 {
     if (this == this.Root.Invalid || other == this.Root.Invalid)
     {
         return(this.Root.Invalid);
     }
     if (this == this.Root.Empty)
     {
         return(other);
     }
     if (other == this.Root.Empty)
     {
         return(this);
     }
     return(this.Root.Factory.Sequence(this, other));
 }
コード例 #9
0
        public override DTDAutomata TryStartElement(string name)
        {
            DTDAutomata dtdautomata  = this.left.TryStartElement(name);
            DTDAutomata dtdautomata2 = this.right.TryStartElement(name);

            if (dtdautomata == base.Root.Invalid)
            {
                return((!this.left.Emptiable) ? dtdautomata : dtdautomata2);
            }
            DTDAutomata dtdautomata3 = dtdautomata.MakeSequence(this.right);

            if (this.left.Emptiable)
            {
                return(dtdautomata2.MakeChoice(dtdautomata3));
            }
            return(dtdautomata3);
        }
コード例 #10
0
        private DTDAutomata GetBasicContentAutomata()
        {
            if (ElementName != null)
            {
                return(new DTDElementAutomata(root, ElementName));
            }
            switch (ChildModels.Count)
            {
            case 0:
                return(root.Empty);

            case 1:
                return(ChildModels [0].GetAutomata());
            }

            DTDAutomata current    = null;
            int         childCount = ChildModels.Count;

            switch (OrderType)
            {
            case DTDContentOrderType.Seq:
                current = Sequence(
                    ChildModels [childCount - 2].GetAutomata(),
                    ChildModels [childCount - 1].GetAutomata());
                for (int i = childCount - 2; i > 0; i--)
                {
                    current = Sequence(
                        ChildModels [i - 1].GetAutomata(), current);
                }
                return(current);

            case DTDContentOrderType.Or:
                current = Choice(
                    ChildModels [childCount - 2].GetAutomata(),
                    ChildModels [childCount - 1].GetAutomata());
                for (int i = childCount - 2; i > 0; i--)
                {
                    current = Choice(
                        ChildModels [i - 1].GetAutomata(), current);
                }
                return(current);

            default:
                throw new InvalidOperationException("Invalid pattern specification");
            }
        }
コード例 #11
0
        public DTDSequenceAutomata Sequence(DTDAutomata left, DTDAutomata right)
        {
            Hashtable hashtable = this.sequenceTable[left] as Hashtable;

            if (hashtable == null)
            {
                hashtable = new Hashtable();
                this.sequenceTable[left] = hashtable;
            }
            DTDSequenceAutomata dtdsequenceAutomata = hashtable[right] as DTDSequenceAutomata;

            if (dtdsequenceAutomata == null)
            {
                dtdsequenceAutomata = new DTDSequenceAutomata(this.root, left, right);
                hashtable[right]    = dtdsequenceAutomata;
            }
            return(dtdsequenceAutomata);
        }
コード例 #12
0
        public DTDSequenceAutomata Sequence(DTDAutomata left, DTDAutomata right)
        {
            Hashtable rightPool = sequenceTable [left] as Hashtable;

            if (rightPool == null)
            {
                rightPool            = new Hashtable();
                sequenceTable [left] = rightPool;
            }
            DTDSequenceAutomata result = rightPool [right] as DTDSequenceAutomata;

            if (result == null)
            {
                result            = new DTDSequenceAutomata(root, left, right);
                rightPool [right] = result;
            }
            return(result);
        }
コード例 #13
0
        public override DTDAutomata TryStartElement(string name)
        {
            DTDAutomata afterL = left.TryStartElement(name);
            DTDAutomata afterR = right.TryStartElement(name);

            if (afterL == Root.Invalid)
            {
                return((left.Emptiable) ? afterR : afterL);
            }
            // else
            DTDAutomata whenLeftConsumed = afterL.MakeSequence(right);

            if (left.Emptiable)
            {
                return(afterR.MakeChoice(whenLeftConsumed));
            }
            else
            {
                return(whenLeftConsumed);
            }
        }
コード例 #14
0
		void ReadDoctype ()
		{
			FillAttributes ();

			IHasXmlParserContext ctx = reader as IHasXmlParserContext;
			if (ctx != null)
				dtd = ctx.ParserContext.Dtd;
			if (dtd == null) {
				XmlTextReaderImpl xmlTextReader = new XmlTextReaderImpl ("", XmlNodeType.Document, null);
				xmlTextReader.XmlResolver = resolver;
				xmlTextReader.GenerateDTDObjectModel (reader.Name,
					reader ["PUBLIC"], reader ["SYSTEM"], reader.Value);
				dtd = xmlTextReader.DTD;
			}
			currentAutomata = dtd.RootAutomata;

			// Validity Constraint Check.
			for (int i = 0; i < DTD.Errors.Length; i++)
				HandleError (DTD.Errors [i].Message, XmlSeverityType.Error);

			// NData target exists.
			foreach (DTDEntityDeclaration ent in dtd.EntityDecls.Values)
				if (ent.NotationName != null && dtd.NotationDecls [ent.NotationName] == null)
					this.HandleError ("Target notation was not found for NData in entity declaration " + ent.Name + ".",
						XmlSeverityType.Error);
			// NOTATION exists for attribute default values
			foreach (DTDAttListDeclaration attListIter in dtd.AttListDecls.Values) {
				foreach (DTDAttributeDefinition def in attListIter.Definitions) {
					if (def.Datatype.TokenizedType != XmlTokenizedType.NOTATION)
						continue;
					foreach (string notation in def.EnumeratedNotations)
						if (dtd.NotationDecls [notation] == null)
							this.HandleError ("Target notation was not found for NOTATION typed attribute default " + def.Name + ".",
								XmlSeverityType.Error);
				}
			}
		}
コード例 #15
0
		private void ValidateText ()
		{
			if (currentAutomata == null)
				return;

			DTDElementDeclaration elem = null;
			if (elementStack.Count > 0)
				elem = dtd.ElementDecls [elementStack.Peek () as string];
			// Here element should have been already validated, so
			// if no matching declaration is found, simply ignore.
			if (elem != null && !elem.IsMixedContent && !elem.IsAny && !isWhitespace) {
				HandleError (String.Format ("Current element {0} does not allow character data content.", elementStack.Peek () as string),
					XmlSeverityType.Error);
				currentAutomata = previousAutomata;
			}
		}
コード例 #16
0
		private bool ReadContent ()
		{
			switch (reader.ReadState) {
			case ReadState.Closed:
			case ReadState.Error:
			case ReadState.EndOfFile:
				return false;
			}
			if (popScope) {
				nsmgr.PopScope ();
				popScope = false;
				if (elementStack.Count == 0)
				// it reached to the end of document element,
				// so reset to non-validating state.
					currentAutomata = null;
			}

			bool b = !reader.EOF;
			if (shouldResetCurrentTextValue) {
				currentTextValue = null;
				shouldResetCurrentTextValue = false;
			}
			else
				b = reader.Read ();

			if (!b) {
				if (elementStack.Count != 0)
					throw new InvalidOperationException ("Unexpected end of XmlReader.");
				return false;
			}

			return ProcessContent ();
		}
コード例 #17
0
 public DTDAutomata Compile()
 {
     this.compiledAutomata = this.CompileInternal();
     return(this.compiledAutomata);
 }
コード例 #18
0
 private DTDAutomata Choice(DTDAutomata l, DTDAutomata r)
 {
     return(l.MakeChoice(r));
 }
コード例 #19
0
 private DTDAutomata Sequence(DTDAutomata l, DTDAutomata r)
 {
     return(this.root.Factory.Sequence(l, r));
 }
コード例 #20
0
ファイル: DTDAutomata.cs プロジェクト: nobled/mono
		public DTDOneOrMoreAutomata (DTDObjectModel root,
			DTDAutomata children)
			: base (root)
		{
			this.children = children;
		}
コード例 #21
0
		void ProcessStartElement ()
		{
			nsmgr.PushScope ();
			popScope = reader.IsEmptyElement;
			elementStack.Push (reader.Name);

			currentElement = Name;

			// If no DTD, skip validation.
			if (currentAutomata == null) {
				ValidateAttributes (null, false);
				if (reader.IsEmptyElement)
					ProcessEndElement ();
				return;
			}

			// StartElementDeriv

			previousAutomata = currentAutomata;
			currentAutomata = currentAutomata.TryStartElement (reader.Name);
			if (currentAutomata == DTD.Invalid) {
				HandleError (String.Format ("Invalid start element found: {0}", reader.Name),
					XmlSeverityType.Error);
				currentAutomata = previousAutomata;
			}

			DTDElementDeclaration elem =
				DTD.ElementDecls [reader.Name];
			if (elem == null) {
				HandleError (String.Format ("Element {0} is not declared.", reader.Name),
					XmlSeverityType.Error);
				currentAutomata = previousAutomata;
			}

			automataStack.Push (currentAutomata);
			if (elem != null)	// i.e. not invalid
				currentAutomata = elem.ContentModel.GetAutomata ();

			DTDAttListDeclaration attList = dtd.AttListDecls [currentElement];
			if (attList != null) {
				// check attributes
				ValidateAttributes (attList, true);
				currentAttribute = -1;
			} else {
				if (reader.HasAttributes) {
					HandleError (String.Format (
						"Attributes are found on element {0} while it has no attribute definitions.", currentElement),
						XmlSeverityType.Error);
				}
				// SetupValidityIgnorantAttributes ();
				ValidateAttributes (null, false);
			}
			// If it is empty element then directly check end element.
			if (reader.IsEmptyElement)
				ProcessEndElement ();
		}
コード例 #22
0
 public DTDAutomata Compile()
 {
     compiledAutomata = CompileInternal();
     return(compiledAutomata);
 }
コード例 #23
0
ファイル: DTDAutomata.cs プロジェクト: nobled/mono
		public DTDAutomata MakeSequence (DTDAutomata other)
		{
			if (this == Root.Invalid || other == Root.Invalid)
				return Root.Invalid;
			if (this == Root.Empty)
				return other;
			if (other == Root.Empty)
				return this;
			else
				return Root.Factory.Sequence (this, other);
		}
コード例 #24
0
 public DTDOneOrMoreAutomata(DTDObjectModel root,
                             DTDAutomata children)
     : base(root)
 {
     this.children = children;
 }
コード例 #25
0
ファイル: DTDAutomata.cs プロジェクト: nobled/mono
		public DTDSequenceAutomata (DTDObjectModel root,
			DTDAutomata left, DTDAutomata right)
			: base (root)
		{
			this.left = left;
			this.right = right;
		}
コード例 #26
0
		void ProcessEndElement ()
		{
			popScope = true;
			elementStack.Pop ();

			// If no schema specification, then skip validation.
			if (currentAutomata == null)
				return;

			// EndElementDeriv
			DTDElementDeclaration elem =
				DTD.ElementDecls [reader.Name];
			if (elem == null) {
				HandleError (String.Format ("Element {0} is not declared.", reader.Name),
					XmlSeverityType.Error);
			}

			previousAutomata = currentAutomata;
			// Don't let currentAutomata
			DTDAutomata tmpAutomata = currentAutomata.TryEndElement ();
			if (tmpAutomata == DTD.Invalid) {
				HandleError (String.Format ("Invalid end element found: {0}", reader.Name),
					XmlSeverityType.Error);
				currentAutomata = previousAutomata;
			}

			currentAutomata = automataStack.Pop () as DTDAutomata;
		}
コード例 #27
0
ファイル: DTDAutomata.cs プロジェクト: nobled/mono
		public DTDAutomata MakeChoice (DTDAutomata other)
		{
			if (this == Root.Invalid)
				return other;
			if (other == Root.Invalid)
				return this;
			if (this == Root.Empty && other == Root.Empty)
				return this;
			if (this == Root.Any && other == Root.Any)
				return this;
			else if (other == Root.Empty)
				return Root.Factory.Choice (other, this);
			else
				return Root.Factory.Choice (this, other);
		}