From: Dion O. <dol...@us...> - 2005-12-08 11:34:08
|
Update of /cvsroot/magicajax/magicajax/Core/UI/Controls In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20209/magicajax/Core/UI/Controls Modified Files: AjaxPanel.cs Log Message: Small regex fix for <select> tag Index: AjaxPanel.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/Controls/AjaxPanel.cs,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** AjaxPanel.cs 8 Dec 2005 01:43:11 -0000 1.30 --- AjaxPanel.cs 8 Dec 2005 11:33:50 -0000 1.31 *************** *** 498,510 **** // Check <select> tags // ! regEx = new System.Text.RegularExpressions.Regex("<select\\s.*?name=\"(?<name>[-\\w]+)\".*?(?<multiple>multiple=\"multiple\")?.*>.*?</select>", options); ! Regex regExOpt = new System.Text.RegularExpressions.Regex("<option\\s.*?(?<selected>selected=\"selected\")?.*?value=\"(?<value>.*?)\".*?>.*?</option>", options); ! matches = regEx.Matches(html); for (int i=0; i<matches.Count; i++) { ! Match match = matches[i]; ! string name = match.Groups["name"].Value; ! bool multiple = match.Groups["multiple"].Success; if (name != null) --- 498,519 ---- // Check <select> tags // ! Regex regExSelect = new System.Text.RegularExpressions.Regex("<select\\s((?<attrname>[-\\w]+)=\"(?<attrvalue>.*?)\"\\s?)*\\s*>(?<options>.*?)</select>", options); ! Regex regExOption = new System.Text.RegularExpressions.Regex("<option\\s((?<attrname>[-\\w]+)=\"(?<attrvalue>.*?)\"\\s?)*\\s*>.*?</option>", options); ! matches = regExSelect.Matches(html); for (int i=0; i<matches.Count; i++) { ! Match matchSelect = matches[i]; ! CaptureCollection attrnamesSelect = matchSelect.Groups["attrname"].Captures; ! CaptureCollection attrvaluesSelect = matchSelect.Groups["attrvalue"].Captures; ! Hashtable attrNameValuesSelect = new Hashtable(); ! for (int j = 0; j < attrnamesSelect.Count; j++) ! { ! attrNameValuesSelect.Add(attrnamesSelect[j].Value.ToLower(), attrvaluesSelect[j].Value); ! } ! ! string name = (string)attrNameValuesSelect["name"]; ! bool multiple = attrNameValuesSelect.ContainsKey("multiple"); ! bool isDropDown = !attrNameValuesSelect.ContainsKey("size"); if (name != null) *************** *** 512,529 **** string serverValue = null; ! //now match the options within this <select> tag ! MatchCollection matchesOpt = regExOpt.Matches(match.Value); ! for (int j = 0; j < matchesOpt.Count; j++) { ! Match matchOpt = matchesOpt[j]; ! string optValue = matchOpt.Groups["value"].Value; //TODO: check value encodings etc. ! bool optSelected = matchOpt.Groups["selected"].Success; ! if (optSelected) { ! serverValue += (serverValue == null ? string.Empty : ",") + optValue; ! if (!multiple) break; } } --- 521,555 ---- string serverValue = null; ! //now match the <option>s within this <select> tag ! MatchCollection matchesOption = regExOption.Matches(matchSelect.Groups["options"].Value); ! for (int j = 0; j < matchesOption.Count; j++) { ! Match matchOption = matchesOption[j]; ! CaptureCollection attrnamesOption = matchOption.Groups["attrname"].Captures; ! CaptureCollection attrvaluesOption = matchOption.Groups["attrvalue"].Captures; ! Hashtable attrNameValuesOption = new Hashtable(); ! for (int k = 0; k < attrnamesOption.Count; k++) ! { ! attrNameValuesOption.Add(attrnamesOption[k].Value.ToLower(), attrvaluesOption[k].Value); ! } ! ! string optValue = (string)attrNameValuesOption["value"]; //TODO: check value encodings etc. ! bool optSelected = attrNameValuesOption.ContainsKey("selected"); ! if (!multiple) { ! //for dropdowns: start with picking first item ! if (isDropDown && serverValue == null) ! serverValue = optValue; ! if (optSelected) ! { ! serverValue = optValue; break; + } + } + else if (optSelected) + { + serverValue += (serverValue == null ? string.Empty : ",") + optValue; } } |