/// <summary> /// Gets the hyper link. /// </summary> /// <param name="index">The index.</param> /// <param name="match">The match.</param> /// <param name="linkURL">The link URL.</param> /// <returns>bool - success/fail</returns> public bool GetHyperLink(int index, string match, ref HTTPRequest linkURL) { string regex = "<(a |[^>]*onclick)[^>]*" + match + "[^>]*>"; //"<a .*? href=[^>]*" .ToLowerInvariant() string result = SearchRegex(index, regex, true, false); if (result == null) { return(false); } bool linkFound = false; string strLinkURL = string.Empty; int start = -1; char delim = '>'; if (result.ToLowerInvariant().IndexOf("href=") != -1) { start += result.ToLowerInvariant().IndexOf("href=") + 5; } if (result.ToLowerInvariant().IndexOf("onclick=") != -1) { start += result.ToLowerInvariant().IndexOf("onclick=") + 8; } if (result[start + 1] == '\"' || result[start + 1] == '\'') { start++; delim = result[start]; } int end = -1; //if (delim != '>') //{ // start = -1; // start = result.IndexOf(delim); //} if (start != -1) { end = result.IndexOf(delim, ++start); } if (end != -1) { strLinkURL = result.Substring(start, end - start); linkFound = true; } if ((start = strLinkURL.IndexOf("=")) != -1) { for (int i = 0; i < strLinkURL.Length - start; i++) { if (strLinkURL[start + i] == '\"' || strLinkURL[start + i] == '\'') { delim = strLinkURL[start + i]; start = start + i; break; } } end = -1; if (start != -1) { end = strLinkURL.IndexOf(delim, ++start); } if (end != -1) { strLinkURL = strLinkURL.Substring(start, end - start); } } string[] param = GetJavaSubLinkParams(result); //strLinkURL); if (param != null) { if (!linkURL.HasTag("[1]")) { linkURL = linkURL.Add(HtmlString.ToAscii(param[0])); } else { for (int i = 0; i < param.Length; i++) { linkURL.ReplaceTag("[" + (i + 1).ToString() + "]", HtmlString.ToAscii(param[i])); } } } else { linkURL = linkURL.Add(HtmlString.ToAscii(strLinkURL.Trim())); } //} return(linkFound); }
/// <summary> /// Gets the sections. /// </summary> /// <param name="source">The source.</param> /// <returns></returns> private Sections GetSections(string source) { source = StripTags(source); Sections data = new Sections(); data.dataFields = new ArrayList(); data.minFields = 0; data.optionalData = false; data.dataTags = 0; MatchTagCollection tags = HtmlString.TagList(source); bool isOptionalTag = false; bool zTag = false; for (int i = 0; i < tags.Count; i++) { MatchTag tag = tags[i]; // check if tag + data is optional / regex zTag = false; if (char.ToUpper(tag.TagName[0]) == 'Z') { zTag = true; isOptionalTag = true; if (tag.IsClose) { isOptionalTag = false; } //i++; //if (i < tags.Count) // tag = tags[i]; //else // break; } // Check if tag is one of interest if (_template.Tags.IndexOf(char.ToUpper(tag.TagName[0])) != -1) { DataField section; if (!zTag) { // Add tag to array of fields section = new DataField(); section.optional = isOptionalTag; section.htmlTag = tag; section.hasData = false; section.source = tag.FullTag; if (section.source.IndexOf("<#") != -1 || section.source.IndexOf("<*") != -1) { section.hasData = true; if (isOptionalTag) { data.optionalData = true; } section.dataElements = GetElements(section.source); data.dataTags += section.dataElements.Count; } data.dataFields.Add(section); if (!isOptionalTag) { data.minFields++; } } // Add data between this tag and the next to field array int start = tag.Index + tag.Length; int end; if (i + 1 < tags.Count) { tag = tags[i + 1]; zTag = false; if (char.ToUpper(tag.TagName[0]) == 'Z') { zTag = true; isOptionalTag = true; if (tag.IsClose) { isOptionalTag = false; } } // start = tag.Index + tag.Length; // i++; // if (i + 1 < tags.Count) // tag = tags[i + 1]; // else // break; //} end = tag.Index; } else { end = source.Length; } if (!zTag) { section = new DataField(); section.optional = isOptionalTag; section.htmlTag = null; section.source = HtmlString.Decode(source.Substring(start, end - start)); section.hasData = false; if (section.source.IndexOf("<#") != -1 || section.source.IndexOf("<*") != -1) { section.hasData = true; if (isOptionalTag) { data.optionalData = true; } section.dataElements = GetElements(section.source); data.dataTags += section.dataElements.Count; } data.dataFields.Add(section); if (!isOptionalTag) { data.minFields++; } } } } return(data); }