Ejemplo n.º 1
0
        private static List <string> GetExtractUrl(ExtractUrlTypes UrlType)
        {
            List <string> aPattern = new List <string>();

            if ((UrlType & ExtractUrlTypes.UrlFromImgTag) == ExtractUrlTypes.UrlFromImgTag)
            {
                aPattern.Add(CRegex.Pattern.ExtractUrlFromImgTag);
            }
            if ((UrlType & ExtractUrlTypes.SwfUrlFromParamTag) == ExtractUrlTypes.SwfUrlFromParamTag)
            {
                aPattern.Add(CRegex.Pattern.ExtractSwfUrlFromParamTag);
            }
            if ((UrlType & ExtractUrlTypes.UrlFromBackground) == ExtractUrlTypes.UrlFromBackground)
            {
                aPattern.Add(CRegex.Pattern.ExtractUrlFromBackground);
            }
            if ((UrlType & ExtractUrlTypes.UrlFromStyleBackground) == ExtractUrlTypes.UrlFromStyleBackground)
            {
                aPattern.Add(CRegex.Pattern.ExtractUrlFromStyleBackground);
            }
            if ((UrlType & ExtractUrlTypes.UrlFromATag) == ExtractUrlTypes.UrlFromATag)
            {
                aPattern.Add(CRegex.Pattern.ExtractUrlFromATag);
            }
            if ((UrlType & ExtractUrlTypes.UrlFromNewUri) == ExtractUrlTypes.UrlFromNewUri)
            {
                aPattern.Add(CRegex.Pattern.ExtractUrlFromNewUri);
            }

            return(aPattern);
        }
Ejemplo n.º 2
0
        public static List <string> ExtractUrl(string Value, ExtractUrlTypes UrlType, IEnumerable <string> eStartingUrl)
        {
            List <string> aPattern      = GetExtractUrl(UrlType);
            List <string> aUrlExtracted = new List <string>();

            for (int i = 0; i < aPattern.Count; i++)
            {
                Regex r = new Regex(aPattern[i], RegexOptions.IgnoreCase);
                for (Match m = r.Match(Value); m.Success; m = m.NextMatch())
                {
                    string UrlExtracted = m.Groups["Url"].Value;

                    if (eStartingUrl == null)
                    {
                        aUrlExtracted.Add(UrlExtracted);
                    }
                    else
                    {
                        foreach (string UrlCur in eStartingUrl)
                        {
                            if (!UrlExtracted.StartsWith(UrlCur))
                            {
                                continue;
                            }

                            aUrlExtracted.Add(UrlExtracted);
                        }
                    }
                }
            }

            return(aUrlExtracted);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// HTML 코드에서 사용된 URL이 dicUrlReplace의 Key로 시작한다면 URL의 dicUrlReplace의 Key 부분을 dicUrlReplace의 Value로 변경함.
        /// </summary>
        /// <param name="dicStartingUrlReplace"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        /// <example>
        /// <![CDATA[
        /// string Html = @"
        /// <td><img src=""images/title.gif"" alt="""" /></td>
        /// <td style=""width:6px;""></td>
        /// <td style=""background-image:url('images/bg_version_left.gif'); width:4px;""></td>
        /// <td class=""version"" style=""background-image:url('images/bg_version_center.gif'); background-repeat:repeat-x; padding: 0px 2px 0px 2px;"">
        /// v <span id=""spnVersion"">1.10.20.1624</span>
        /// </td>
        /// <td style=""background-image:url('images/bg_version_right.gif'); width:4px;""></td>";
        ///
        /// Dictionary<string, string> dicUrlReplace = new Dictionary<string,string>();
        /// dicUrlReplace.Add("images/", "question/");
        ///
        /// string HtmlNew = ReplaceStartingUrl(Html, dicUrlReplace);
        /// ]]>
        /// </example>
        public static string ReplaceStartingUrl(string Value, ExtractUrlTypes UrlType, Dictionary <string, string> dicStartingUrlReplace,
                                                out List <Tuple <string, string> > aFromToIs)
        {
            aFromToIs = new List <Tuple <string, string> >();
            List <Tuple <string, string> > aFromTo = new List <Tuple <string, string> >();

            List <string> aPattern = GetExtractUrl(UrlType);

            for (int i = 0; i < aPattern.Count; i++)
            {
                Regex r = new Regex(aPattern[i], RegexOptions.IgnoreCase);
                Value = r.Replace(Value, new MatchEvaluator(delegate(Match m)
                {
                    foreach (KeyValuePair <string, string> kv in dicStartingUrlReplace)
                    {
                        if (!m.Groups["Url"].Value.StartsWith(kv.Key))
                        {
                            continue;
                        }

                        int IndexFrom = m.Groups["Url"].Index - m.Index;
                        int IndexTo   = IndexFrom + kv.Key.Length - 1;

                        string From = m.Groups["Url"].Value;
                        string To   = From.Replace(kv.Key, kv.Value);
                        aFromTo.Add(new Tuple <string, string>(From, To));

                        return(m.Value.Substring(0, IndexFrom) + kv.Value + m.Value.Substring(IndexTo + 1));
                    }

                    return(m.Value);
                }));
            }

            aFromToIs = aFromTo;

            return(Value);
        }
Ejemplo n.º 4
0
 public static List <string> ExtractUrl(string Value, ExtractUrlTypes UrlType)
 {
     return(ExtractUrl(Value, UrlType, null));
 }
Ejemplo n.º 5
0
        public static string ReplaceStartingUrl(string Value, ExtractUrlTypes UrlType, Dictionary <string, string> dicStartingUrlReplace)
        {
            List <Tuple <string, string> > aFromToIs = new List <Tuple <string, string> >();

            return(ReplaceStartingUrl(Value, UrlType, dicStartingUrlReplace, out aFromToIs));
        }