public void LoadModule_PageOptionsBoxTest() { // In this case the snippet info data is not HTML(which is often the case) // but xml data which contains rendering properties for each page option item string xmlData = @"<?xml version=""1.0"" encoding=""utf-8""?> <cde:Module_PageOptionsBox xsi:schemaLocation=""http://www.example.org/CDESchema CDESchema.xsd"" xmlns:cde=""http://www.example.org/CDESchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""> <Title>Hello</Title> <PageOptions> <PageOption key=""""> <cssClass>Class Name</cssClass> <LinkText>text</LinkText> <WebAnalyticsFunction>functionname</WebAnalyticsFunction> <OptionType>type</OptionType> </PageOption> <PageOption key=""""> <cssClass>Class Name</cssClass> <LinkText>text</LinkText> <WebAnalyticsFunction>functionname</WebAnalyticsFunction> <OptionType>type</OptionType> </PageOption> </PageOptions> </cde:Module_PageOptionsBox>"; XmlTextReader reader = new XmlTextReader(xmlData, XmlNodeType.Element, null); XmlSerializer serializer = new XmlSerializer(typeof(Module_PageOptionsBox), "cde"); Module_PageOptionsBox obj = (Module_PageOptionsBox)serializer.Deserialize(reader); Assert.IsNotNull(obj); Assert.IsNotNull(obj.Title); Assert.IsTrue(obj.PageOptions.Count > 0); }
/// <summary> /// Process the page options information in the xml and creates /// the page options items. /// </summary> /// <param name="snippetXmlData">The xml fragment which contains pageoptions information.</param> private void processPageOptionsData(string snippetXmlData) { // The snippet CDATA may contain CDATA as part of the data but percussion replaces the CDATA // close tag with Replace ']]>' with ']]ENDCDATA' this ']]ENDCDATA' should be replaced with // valid CDATA close tag ']]>' before it can be deserialized snippetXmlData = snippetXmlData.Replace("]]ENDCDATA", "]]>"); IPageAssemblyInstruction pgInstruction = PageAssemblyContext.Current.PageAssemblyInstruction; // If AlternateContentVersions information is not in the instructions then do not create // the PageOptions box. string[] acvKeys = pgInstruction.AlternateContentVersionsKeys; if (acvKeys != null) { Module_PageOptionsBox mPBO = ModuleObjectFactory <Module_PageOptionsBox> .GetModuleObject(snippetXmlData); if (mPBO != null) { // Create the Page Options box control. PageOptionsBox pageOptionsBox = new PageOptionsBox(); pageOptionsBox.BoxTitle = mPBO.Title; pageOptionsBox.CssClass = "po-box"; foreach (PageOption pgOptionItem in mPBO.PageOptions) { try { // Check if the Pageoptions are recognized in the Alternate Content Version keys string key = pgOptionItem.Key; if (!string.IsNullOrEmpty(key)) { key = key.ToLower(); } if (acvKeys.Contains <string>(key)) { NCI.Web.UI.WebControls.PageOption pgoBase = null; if (String.Compare(pgOptionItem.OptionType, PageOptionType.Link.ToString()) == 0) { pgoBase = new LinkPageOption(); ((LinkPageOption)pgoBase).OnClick = pgOptionItem.WebAnalyticsFunction; ((LinkPageOption)pgoBase).Href = pgInstruction.GetUrl(key).ToString(); } else if (String.Compare(pgOptionItem.OptionType, PageOptionType.Email.ToString()) == 0) { pgoBase = new LinkPageOption(); ((LinkPageOption)pgoBase).Href = pgInstruction.GetUrl("email").ToString(); ((LinkPageOption)pgoBase).OnClick = pgOptionItem.WebAnalyticsFunction; ((LinkPageOption)pgoBase).OnClick += " " + "dynPopWindow('" + ((LinkPageOption)pgoBase).Href.Replace("'", "%27").Replace("(", "%28").Replace(")", "%29") + "', 'emailPopUp', 'height=525,width=492'); return false;"; } else if (String.Compare(pgOptionItem.OptionType, PageOptionType.BookMarkShare.ToString()) == 0) { pgoBase = new AddThisPageOption(); ((AddThisPageOption)pgoBase).Settings.Language = pgInstruction.Language; //((AddThisPageOption)pgoBase).PageTitle = pgInstruction.GetField("long_description").ToString(); //pgInstruction.GetUrl("BookMarkShareUrl").ToString(); ((AddThisPageOption)pgoBase).PageTitle = pgInstruction.GetField("long_title").ToString(); ((AddThisPageOption)pgoBase).OnClick = pgOptionItem.WebAnalyticsFunction; } if (pgoBase != null) { pgoBase.CssClass = pgOptionItem.CssClass; pgoBase.LinkText = pgOptionItem.LinkText; pageOptionsBox.PageOptions.Add(pgoBase); } } } catch { //TODO, log exception } } if (pageOptionsBox.PageOptions.Count > 0) { this.Controls.Add(pageOptionsBox); } } } }