private string ProcessHtmlNodes(Hashtable State, XmlDocument doc, string page_name, XmlNode fields_node, HtmlNodeCollection childNodes) { try { XmlNode field_node = null; HttpServerUtility Server = (HttpServerUtility) HttpRuntime.Cache["Server"]; Util util = new Util(); ArrayList sortedNodeList = new ArrayList(); foreach (HtmlNode node in childNodes) { Hashtable dict = new Hashtable(); Hashtable attribute_list = new Hashtable(); foreach (HtmlAttribute attribute in node.Attributes) { attribute_list[attribute.Name.ToLower()] = attribute.Value.Replace("&", "&"); } HtmlNode child = node.FirstChild; if (child != null) { foreach (HtmlAttribute attribute in child.Attributes) { if (attribute.Name.ToLower() == "src") attribute_list[attribute.Name.ToLower()] = attribute.Value; } } dict["node"] = node; dict["attribute_list"] = attribute_list; //just get z-index for now string style_string = attribute_list["style"].ToString(); if (style_string.Contains("z-index")) { int start = style_string.IndexOf("z-index:"); start += 8; int end = style_string.IndexOf(";", start); string s_zindex = style_string.Substring(start, end - start); dict["z-index"] = Convert.ToInt32(s_zindex.Trim()); } else dict["z-index"] = 0; sortedNodeList.Add(dict); } sortedNodeList.Sort(new mySortClass());//sort by z-index to get overlapping fields foreach (Hashtable dict in sortedNodeList) { HtmlNode node = (HtmlNode)dict["node"]; string text = node.InnerText; Hashtable attribute_list = (Hashtable)dict["attribute_list"]; switch (attribute_list["title"].ToString()) { case "MobiFlex Button": field_node = CreateNode(doc, fields_node, "button"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); if (attribute_list["src"] != null) CreateNode(doc, field_node, "image_source", attribute_list["src"].ToString()); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); //there are 2 coding schemes here: //1 css type coding //2 xml type coding - the new one //maintain backward comptibility if (attribute_list["submit"] != null) { string submit = attribute_list["submit"].ToString().Replace("_this_page", page_name).Replace(";;", ";"); XmlNode submit_node = null; if (submit.Contains("compute:")) { XmlNode compute_node = CreateNode(doc, field_node, "compute"); if (!EncodeCompute(State, doc, compute_node, submit.Substring(submit.IndexOf("compute:")))) { return "There is an error in the compute field: " + submit.Substring(submit.IndexOf("compute:")); } string submit_part = submit.Substring(0, submit.IndexOf("compute:")); if (submit_part != ";") //it needs to be more than just a ';' submit_node = CreateNode(doc, field_node, "submit", submit_part); } else submit_node = CreateNode(doc, field_node, "submit", submit); if (submit_node != null) { EncodeSubmit(State, doc, submit_node); CheckCreatePage(State, doc, submit_node); //ensure backward compatiblity FilterSubmitBackwards(submit_node); } } string button_text = node.InnerText.Replace("\r", "").Replace("\n", "").Trim(); CreateNode(doc, field_node, "text", button_text); break; case "MobiFlex Label": field_node = CreateNode(doc, fields_node, "label"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); string label_text2 = node.InnerText.Replace("\r", "").Replace("\n", ""); CreateNode(doc, field_node, "text", label_text2); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); break; case "MobiFlex TextField": field_node = CreateNode(doc, fields_node, "text_field"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); CreateNode(doc, field_node, "type", attribute_list["type"].ToString()); if (attribute_list["text"] != null) { CreateNode(doc, field_node, "text", DecodeStudioHtml(attribute_list["text"].ToString())); } if (attribute_list["alt"] != null) { string[] parts = attribute_list["alt"].ToString().Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 1) { CreateNode(doc, field_node, "keyboard", attribute_list["alt"].ToString()); CreateNode(doc, field_node, "validation", "none"); } else if(parts.Length == 2) { string[] sub_parts = parts[0].Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if(sub_parts.Length ==2) CreateNode(doc, field_node, "keyboard", sub_parts[1]); sub_parts = parts[1].Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (sub_parts.Length == 2) CreateNode(doc, field_node, "validation", sub_parts[1]); } } else { CreateNode(doc, field_node, "keyboard", "default"); CreateNode(doc, field_node, "validation", "none"); } AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); break; case "MobiFlex TextArea": field_node = CreateNode(doc, fields_node, "text_area"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); if(attribute_list["type"] != null) CreateNode(doc, field_node, "edit_type", attribute_list["type"].ToString()); else CreateNode(doc, field_node, "edit_type", "non_editable"); if (attribute_list["text"] != null) CreateNode(doc, field_node, "text", DecodeStudioHtml(attribute_list["text"].ToString())); else CreateNode(doc, field_node, "text", ""); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); break; case "MobiFlex HtmlPanel": field_node = CreateNode(doc, fields_node, "html_panel"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); CreateNode(doc, field_node, "html", HttpUtility.HtmlEncode(node.InnerHtml)); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); break; case "MobiFlex ImageButton": field_node = CreateNode(doc, fields_node, "image_button"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); CreateNode(doc, field_node, "image_source", attribute_list["src"].ToString()); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); //there are 2 coding schemes here: //1 css type coding //2 xml type coding - the new one //maintain backward comptibility if (attribute_list["submit"] != null) { string ImageButton_submit = attribute_list["submit"].ToString().Replace("_this_page", page_name).Replace(";;", ";"); XmlNode submit_node = null; if (ImageButton_submit.Contains("compute:")) { XmlNode compute_node = CreateNode(doc, field_node, "compute"); if (!EncodeCompute(State, doc, compute_node, ImageButton_submit.Substring(ImageButton_submit.IndexOf("compute:")))) { return "There is an error in the compute field: " + ImageButton_submit.Substring(ImageButton_submit.IndexOf("compute:")); } string ImageButton_submit_part = ImageButton_submit.Substring(0, ImageButton_submit.IndexOf("compute:")); if (ImageButton_submit_part != ";") //it needs to be more than just a ';' submit_node = CreateNode(doc, field_node, "submit", ImageButton_submit_part); } else submit_node = CreateNode(doc, field_node, "submit", ImageButton_submit); if (submit_node != null) { EncodeSubmit(State, doc, submit_node); CheckCreatePage(State, doc, submit_node); //ensure backward compatiblity FilterSubmitBackwards(submit_node); } } break; case "MobiFlex Image": field_node = CreateNode(doc, fields_node, "image"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); CreateNode(doc, field_node, "image_source", attribute_list["src"].ToString()); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); break; case "MobiFlex Audio": field_node = CreateNode(doc, fields_node, "audio"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); CreateNode(doc, field_node, "audio_source", attribute_list["source"].ToString()); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); break; case "MobiFlex Table": field_node = CreateNode(doc, fields_node, "table"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); if (attribute_list["name"] == null) CreateNode(doc, field_node, "display_name", attribute_list["id"].ToString()); else CreateNode(doc, field_node, "display_name", attribute_list["name"].ToString()); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); //get table type and fields string fields_value = attribute_list["fields"].ToString(); string[] parts2 = fields_value.Split(":".ToCharArray()); string[] format = parts2[0].Split("|".ToCharArray()); if (format.Length != 2) { return attribute_list["id"].ToString() + " table format is wrong. Re-insert the table."; } CreateNode(doc, field_node, "table_type", format[0]); XmlNode table_fields = CreateNode(doc, field_node, "table_fields"); string[] field_types = format[1].Split(",".ToCharArray()); string[] field_names = parts2[1].Split(",".ToCharArray()); int i_field = 0; //prepare options if they exist string[] option_sections = null; if (attribute_list.ContainsKey("options")) { string options = attribute_list["options"].ToString(); if (options.Length > 0) { option_sections = options.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (option_sections.Length > 0 && option_sections.Length != field_names.Length) return "The number of table fields (" + field_names.Length + ") does not equal the number of option section(s) (" + option_sections.Length + ")"; } } int i_section = 0; foreach (string field_name in field_names) { XmlNode table_field = CreateNode(doc, table_fields, "table_field"); CreateNode(doc, table_field, "name", field_name.Trim()); CreateNode(doc, table_field, "type", field_types[i_field]); if (attribute_list.ContainsKey("options") && option_sections != null && option_sections.Length > 0) CreateNode(doc, table_field, "options", DecodeStudioHtml(option_sections[i_section++])); i_field++; } //there are 2 coding schemes here: //1 css type coding //2 xml type coding - the new one //maintain backward comptibility if (attribute_list.ContainsKey("submit")) { string table_submit = attribute_list["submit"].ToString().Replace("_this_page", page_name).Replace(";;", ";"); XmlNode submit_node = null; if (table_submit.Contains("compute:")) { XmlNode compute_node = CreateNode(doc, field_node, "compute"); if (!EncodeCompute(State, doc, compute_node, table_submit.Substring(table_submit.IndexOf("compute:")))) { return "There is an error in the compute field: " + table_submit.Substring(table_submit.IndexOf("compute:")); } string table_submit_part = table_submit.Substring(0, table_submit.IndexOf("compute:")); if (table_submit_part != ";") //it needs to be more than just a ';' submit_node = CreateNode(doc, field_node, "submit", table_submit_part); } else submit_node = CreateNode(doc, field_node, "submit", table_submit); if (submit_node != null) { EncodeSubmit(State, doc, submit_node); CheckCreatePage(State, doc, submit_node); //ensure backward compatiblity FilterSubmitBackwards(submit_node); } } break; case "MobiFlex Slider": field_node = CreateNode(doc, fields_node, "slider"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); CreateNode(doc, field_node, "type", "horizontal"); string value = attribute_list["value"].ToString(); string[] values = value.Split(":".ToCharArray()); CreateNode(doc, field_node, "min_value", values[0]); CreateNode(doc, field_node, "max_value", values[1]); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); break; case "MobiFlex Picker": field_node = CreateNode(doc, fields_node, "picker"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); //get picker fields string type_value = attribute_list["type"].ToString(); string[] picker_parts = type_value.Split(":".ToCharArray()); string picker_type = picker_parts[0].Trim(); CreateNode(doc, field_node, "picker_type", picker_type); bool pickerHasOptions = true; if (picker_type == "date" || picker_type == "time") pickerHasOptions = false; string picker_options = null; string[] picker_option_sections = null; if (pickerHasOptions) { if (attribute_list.ContainsKey("options")) { picker_options = attribute_list["options"].ToString(); picker_option_sections = picker_options.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); } else { return "Options are missing for picker " + attribute_list["id"].ToString(); } } if (picker_type != "date" && picker_type != "time") { XmlNode picker_fields = CreateNode(doc, field_node, "picker_fields"); string[] picker_field_names = picker_parts[1].Split(",".ToCharArray()); int i_picker_section = 0; foreach (string picker_field_name in picker_field_names) { XmlNode picker_field = CreateNode(doc, picker_fields, "picker_field"); CreateNode(doc, picker_field, "name", picker_field_name.Trim()); if (pickerHasOptions && picker_option_sections != null && picker_option_sections.Length > i_picker_section) CreateNode(doc, picker_field, "options", DecodeStudioHtml(picker_option_sections[i_picker_section++])); } } AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); break; case "MobiFlex WebView": field_node = CreateNode(doc, fields_node, "web_view"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); if (attribute_list.ContainsKey("url") && attribute_list["url"].ToString().Length > 0) CreateNode(doc, field_node, "url", attribute_list["url"].ToString()); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); break; case "MobiFlex Alert": field_node = CreateNode(doc, fields_node, "alert"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); break; case "MobiFlex Switch": field_node = CreateNode(doc, fields_node, "switch"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); CreateNode(doc, field_node, "default_value", attribute_list["value"].ToString()); CreateNode(doc, field_node, "type", attribute_list["type"].ToString()); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); //there are 2 coding schemes here: //1 css type coding //2 xml type coding - the new one //maintain backward comptibility if (attribute_list["submit"] != null) { string switch_submit = attribute_list["submit"].ToString().Replace("_this_page", page_name).Replace(";;", ";"); XmlNode submit_node = null; if (switch_submit.Contains("compute:")) { XmlNode compute_node = CreateNode(doc, field_node, "compute"); if (!EncodeCompute(State, doc, compute_node, switch_submit.Substring(switch_submit.IndexOf("compute:")))) { return "There is an error in the compute field: " + switch_submit.Substring(switch_submit.IndexOf("compute:")); } string switch_submit_part = switch_submit.Substring(0, switch_submit.IndexOf("compute:")); if (switch_submit_part != ";") //it needs to be more than just a ';' submit_node = CreateNode(doc, field_node, "submit", switch_submit_part); } else submit_node = CreateNode(doc, field_node, "submit", switch_submit); if (submit_node != null) { EncodeSubmit(State, doc, submit_node); CheckCreatePage(State, doc, submit_node); //ensure backward compatiblity FilterSubmitBackwards(submit_node); } } break; case "MobiFlex CheckBox": field_node = CreateNode(doc, fields_node, "checkbox"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); CreateNode(doc, field_node, "default_value", attribute_list["value"].ToString()); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); //there are 2 coding schemes here: //1 css type coding //2 xml type coding - the new one //maintain backward comptibility if (attribute_list["submit"] != null) { string checkbox_submit = attribute_list["submit"].ToString().Replace("_this_page", page_name).Replace(";;", ";"); XmlNode submit_node = null; if (checkbox_submit.Contains("compute:")) { XmlNode compute_node = CreateNode(doc, field_node, "compute"); if (!EncodeCompute(State, doc, compute_node, checkbox_submit.Substring(checkbox_submit.IndexOf("compute:")))) { return "There is an error in the compute field: " + checkbox_submit.Substring(checkbox_submit.IndexOf("compute:")); } string switch_submit_part = checkbox_submit.Substring(0, checkbox_submit.IndexOf("compute:")); if (switch_submit_part != ";") //it needs to be more than just a ';' submit_node = CreateNode(doc, field_node, "submit", switch_submit_part); } else submit_node = CreateNode(doc, field_node, "submit", checkbox_submit); if (submit_node != null) { EncodeSubmit(State, doc, submit_node); CheckCreatePage(State, doc, submit_node); //ensure backward compatiblity FilterSubmitBackwards(submit_node); } } break; case "MobiFlex HiddenField": field_node = CreateNode(doc, fields_node, "hidden_field"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); if(attribute_list["value"].ToString().Length > 0) CreateNode(doc, field_node, "value", DecodeStudioHtml(attribute_list["value"].ToString())); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); break; case "MobiFlex AudioRecorder": field_node = CreateNode(doc, fields_node, "audio_recorder"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); break; case "MobiFlex Photo": field_node = CreateNode(doc, fields_node, "photo"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); CreateNode(doc, field_node, "compression", attribute_list["compression"].ToString()); if (attribute_list["icon_field"] != null && attribute_list["icon_field"].ToString().Length > 0) { string[] parse_list = attribute_list["icon_field"].ToString().Split(";".ToCharArray(),StringSplitOptions.RemoveEmptyEntries); foreach (string parse in parse_list) { string[] icon_parts = parse.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); switch (icon_parts[0]) { case "field": CreateNode(doc, field_node, "icon_field", icon_parts[1]); break; case "width": CreateNode(doc, field_node, "icon_width", icon_parts[1]); break; case "height": CreateNode(doc, field_node, "icon_height", icon_parts[1]); break; } } } AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); break; case "MobiFlex GPS": field_node = CreateNode(doc, fields_node, "gps"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); string names = attribute_list["alt"].ToString(); string[] gps_parts = names.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); CreateNode(doc, field_node, "latitude", gps_parts[0]); CreateNode(doc, field_node, "longitude", gps_parts[1]); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); break; case "MobiFlex Map": field_node = CreateNode(doc, fields_node, "map"); CreateNode(doc, field_node, "id", attribute_list["id"].ToString()); CreateNode(doc, field_node, "url", attribute_list["url"].ToString()); AddStyleNodes(doc, field_node, util.AddToStyleAttribute(new Hashtable(), attribute_list["style"].ToString())); break; } } return "OK"; } catch (Exception ex) { Util util = new Util(); util.LogError(State, ex); throw new Exception(ex.Message + ": " + ex.StackTrace); } }