예제 #1
0
파일: DTDReader.cs 프로젝트: runefs/Marvin
		private void PushParserInput (string url)
		{
			Uri baseUri = null;
			try {
				if (DTD.BaseURI != null && DTD.BaseURI.Length > 0)
					baseUri = new Uri (DTD.BaseURI);
			} catch (UriFormatException) {
			}

			Uri absUri = url != null && url.Length > 0 ?
				DTD.Resolver.ResolveUri (baseUri, url) : baseUri;
			string absPath = absUri != null ? absUri.ToString () : String.Empty;

			foreach (XmlParserInput i in parserInputStack.ToArray ()) {
				if (i.BaseURI == absPath)
					throw NotWFError ("Nested inclusion is not allowed: " + url);
			}
			parserInputStack.Push (currentInput);
			Stream s = null;
			MemoryStream ms = new MemoryStream ();
			try {
				s = DTD.Resolver.GetEntity (absUri, null, typeof (Stream)) as Stream;
				int size;
				byte [] buf = new byte [4096];
				do {
					size = s.Read (buf, 0, buf.Length);
					ms.Write (buf, 0, size);
				} while (size > 0);
				s.Close ();
				ms.Position = 0;
				currentInput = new XmlParserInput (new XmlStreamReader (ms), absPath);
			} catch (Exception ex) { // FIXME: (wishlist) Bad exception catch ;-(
				if (s != null)
					s.Close ();
				int line = currentInput == null ? 0 : currentInput.LineNumber;
				int col = currentInput == null ? 0 : currentInput.LinePosition;
				string bu = (currentInput == null) ? String.Empty : currentInput.BaseURI;
				HandleError (new XmlSchemaException ("Specified external entity not found. Target URL is " + url + " .",
					line, col, null, bu, ex));
				currentInput = new XmlParserInput (new StringReader (String.Empty), absPath);
			}
		}
예제 #2
0
파일: DTDReader.cs 프로젝트: runefs/Marvin
		private void PopParserInput ()
		{
			currentInput.Close ();
			currentInput = parserInputStack.Pop () as XmlParserInput;
		}
예제 #3
0
파일: DTDReader.cs 프로젝트: runefs/Marvin
		internal DTDObjectModel GenerateDTDObjectModel ()
		{
			// now compile DTD
			int originalParserDepth = parserInputStack.Count;
			bool more;
			if (DTD.InternalSubset != null && DTD.InternalSubset.Length > 0) {
				this.processingInternalSubset = true;
				XmlParserInput original = currentInput;

				currentInput = new XmlParserInput (
					new StringReader (DTD.InternalSubset),
					DTD.BaseURI,
					currentLinkedNodeLineNumber,
					currentLinkedNodeLinePosition);
				currentInput.AllowTextDecl = false;
				do {
					more = ProcessDTDSubset ();
					if (PeekChar () == -1 && parserInputStack.Count > 0)
						PopParserInput ();
				} while (more || parserInputStack.Count > originalParserDepth);
				if (dtdIncludeSect != 0)
					throw NotWFError ("INCLUDE section is not ended correctly.");

				currentInput = original;
				this.processingInternalSubset = false;
			}
			if (DTD.SystemId != null && DTD.SystemId != String.Empty && DTD.Resolver != null) {
				PushParserInput (DTD.SystemId);
				do {
					more = ProcessDTDSubset ();
					if (PeekChar () == -1 && parserInputStack.Count > 1)
						PopParserInput ();
				} while (more || parserInputStack.Count > originalParserDepth + 1);
				if (dtdIncludeSect != 0)
					throw NotWFError ("INCLUDE section is not ended correctly.");

				PopParserInput ();
			}
			ArrayList sc = new ArrayList ();

			// Entity recursion check.
			foreach (DTDEntityDeclaration ent in DTD.EntityDecls.Values) {
				if (ent.NotationName != null) {
					ent.ScanEntityValue (sc);
					sc.Clear ();
				}
			}
			// release unnecessary memory usage
			DTD.ExternalResources.Clear ();

			return DTD;
		}