/// <summary> Creates a new instance of a Lexer.</summary>
		/// <param name="connection">The url to parse.
		/// </param>
		/// <exception cref="ParserException">If an error occurs opening the connection.
		/// </exception>
		public Lexer(HttpProtocol connection):this(new Page(connection))
		{
		}
		/// <summary> Construct a parser using the provided HttpProtocol.
		/// A feedback object printing to System.Console is used.
		/// </summary>
		/// <param name="connection">HttpProtocol object.
		/// </param>
		/// <throws>  ParserException If the creation of the underlying Lexer </throws>
		/// <summary> cannot be performed.
		/// </summary>
		public Parser(HttpProtocol connection):this(connection, STDOUT)
		{
		}
Esempio n. 3
0
		/// <summary> Construct a page reading from a URL connection.</summary>
		/// <param name="connection">A fully conditioned connection. The connect()
		/// method will be called so it need not be connected yet.
		/// </param>
		/// <exception cref="ParserException">An exception object wrapping a number of
		/// possible error conditions, some of which are outlined below.
		/// <li>IOException If an i/o exception occurs creating the
		/// source.</li>
		/// <li>UnsupportedEncodingException if the character set specified in the
		/// HTTP header is not supported.</li>
		/// </exception>
		public Page(HttpProtocol connection)
		{
			if (null == connection)
			{
				throw new System.ArgumentException("HttpProtocol cannot be null");
			}
			Connection = connection;
			mBaseUrl = null;
		}
		/// <summary> Constructor for custom HTTP access.
		/// This would be used to create a parser for a URLConnection that needs
		/// a special setup or negotiation conditioning beyond what is available
		/// from the {@link #getConnectionManager ConnectionManager}.
		/// </summary>
		/// <param name="connection">A fully conditioned connection. The connect()
		/// method will be called so it need not be connected yet.
		/// </param>
		/// <param name="fb">The object to use for message communication.
		/// </param>
		/// <throws>  ParserException If the creation of the underlying Lexer </throws>
		/// <summary> cannot be performed.
		/// </summary>
		public Parser(HttpProtocol connection, IParserFeedBack fb):this(new Lexer(connection), fb)
		{
			this.m_obHttpProtocol = connection;
		}
Esempio n. 5
0
		private void GetPageContent(HttpProtocol obProtocol, bool bIsRefresh)
		{
			if(m_bHasContent && !bIsRefresh)
			{
				return;
			}

			if(obProtocol == null)
			{
				throw new ArgumentNullException("obProtocol", "Null HttpProtocol object specified");
			}

			lock(this)
			{
				ParserStream stream = null;
				System.String type = String.Empty;
				System.String charset = String.Empty;
				try
				{
					m_obProtocolOutput = obProtocol.GetProtocolOutput();
					if (m_obProtocolOutput.Status.Code == HttpProtocolStatus.SUCCESS)
					{
						m_bHasContent = true;
						this.m_HttpContentProperties = m_obProtocolOutput.Content.ContentProperties;
						type = this.ContentType;
						charset = GetCharset(type);
						stream = new ParserStream(new System.IO.MemoryStream(m_obProtocolOutput.Content.ContentData));
					}

					if (null != stream)
					{
						mSource = new InputStreamSource(stream,charset,m_obProtocolOutput.Content.ContentData.Length);
					}
				}
				catch (System.Exception e)
				{
					throw new ParserException("Failed to get page content", e);
				}

				mUrl = obProtocol.URL.ToString();
				mIndex = new PageIndex(this);
			}
		}