示例#1
0
        /// <summary>
        /// Gets the text included in the external source.
        /// </summary>
        /// <param name="url">The URL of the external source.</param>
        /// <returns>The contained string.</returns>
        String GetText(String url)
        {
            if (Configuration.HasHttpRequester)
            {
                if (!Location.IsAbsolute(url))
                {
                    url = Location.MakeAbsolute(_result.Url, url);
                }

                var http     = Configuration.GetHttpRequester();
                var response = http.Request(new DefaultHttpRequest {
                    Address = new Uri(url)
                });
                var stream = new SourceManager(response.Content);
                var tok    = new DtdPlainTokenizer(_result, stream);
                var token  = tok.Get();

                if (token.Type == DtdTokenType.TextDecl)
                {
                    var pi = (DtdDeclToken)token;

                    if (!String.IsNullOrEmpty(pi.Encoding))
                    {
                        SetEncoding(stream, pi.Encoding);
                    }

                    token = tok.Get();
                }

                if (token.Type == DtdTokenType.Comment)
                {
                    return(((DtdCommentToken)token).Data);
                }
            }

            return(String.Empty);
        }
示例#2
0
        /// <summary>
        /// Gets the text included in the external source.
        /// </summary>
        /// <param name="url">The URL of the external source.</param>
        /// <returns>The contained string.</returns>
        String GetText(String url)
        {
            if (Configuration.HasHttpRequester)
            {
                if (!Location.IsAbsolute(url))
                    url = Location.MakeAbsolute(_result.Url, url);

                var http = Configuration.GetHttpRequester();
                var response = http.Request(new DefaultHttpRequest { Address = new Uri(url) });
                var stream = new SourceManager(response.Content);
                var tok = new DtdPlainTokenizer(_result, stream);
                var token = tok.Get();

                if (token.Type == DtdTokenType.TextDecl)
                {
                    var pi = (DtdDeclToken)token;

                    if (!String.IsNullOrEmpty(pi.Encoding))
                        SetEncoding(stream, pi.Encoding);

                    token = tok.Get();
                }

                if (token.Type == DtdTokenType.Comment)
                    return ((DtdCommentToken)token).Data;
            }

            return String.Empty;
        }