/// <summary> /// Parses shared personalization for the given virtual path to obtain the applied content scriptlet /// </summary> /// <param name="virtualPath">The virtual path to check for personalization data</param> /// <returns>The name of the content scriptlet applied in personalization data, or string.Empty /// if the value could not be determined</returns> private static string GetContentScriptletFromPersonalization(SharedPersonalization sp, string themeName) { // LOOK FOR SHARED PERSONALIZATION SET ON THE GIVEN VIRTUAL PATH if (sp != null) { // DECODE THE PERSONALIZATION BLOB Dictionary <string, PersonalizationInfo> props = sp.DecodePageSettings(); // LOOP THE KEYS FOR THE PERSONALIZED PROPERTIES foreach (string key in props.Keys) { // SEE IF THIS PERSONALIZATION DATA APPLIES TO SCRIPTLETPART PersonalizationInfo pinfo = props[key]; if (pinfo.ControlType.Name == "ScriptletPart") { // SEE IF THERE IS A VALUE SET FOR THE CONTENT SCRIPTLET if (pinfo.Properties.ContainsKey("Content")) { // TRY TO LOAD THE SPECIFIED CONTENT SCRIPTLET string contentScriptlet = pinfo.Properties["Content"].ToString(); //Scriptlet s = ScriptletDataSource.Load(contentScriptlet, ScriptletType.Content); Scriptlet s = ScriptletDataSource.Load(themeName, contentScriptlet, ScriptletType.Content); if (s != null) { return(s.Identifier); } } } } } // EITHER SHARED PERSONALIZATION WAS NOT SET, CONTENT SCRIPTLET SETTING IS UNAVAILABLE, // OR THE SPECIFIED CONTENT SCRIPTLET IS INVALID return(string.Empty); }
public void AddScriptlet(Scriptlet scriptlet) { Debug.Assert(scriptlet != null); if (_scriptlets == null) { _scriptlets = new List<Scriptlet>(); } _scriptlets.Add(scriptlet); }
private string GetMergedTemplate() { Scriptlet layout = ScriptletDataSource.Load(this.Page.Theme, this.Layout, ScriptletType.Layout, true); //IF THE DESIRED LAYOUT IS NOT FOUND, RETURN DEFAULT THREE COLUMN LAYOUT if (layout == null) { return("<table width=100%><tr><td colspan=3>[[layout:header]]</td></tr><tr><td></td><td>[[layout:leftsidebar]]</td><td>[[layout:content]]</td><td>[[layout:rightsidebar]]</td></tr><tr><td colspan=3>[[layout:footer]]</td></tr></table>"); } //CHECK FOR HEADER OPTIONS if (!string.IsNullOrEmpty(layout.HeaderData)) { this.Page.Header.Controls.Add(new LiteralControl(layout.HeaderData)); } string mergedTemplate = layout.ScriptletData; MatchCollection nestedScriptlets = Regex.Matches(mergedTemplate, "\\[\\[(header|footer|sidebar|sidebar2|leftsidebar|rightsidebar|content):([^\\]]+)\\]\\]", RegexOptions.IgnoreCase); if (nestedScriptlets.Count > 0) { StringBuilder mergedTemplateBuilder = new StringBuilder(); int currentIndex = 0; foreach (Match match in nestedScriptlets) { //output the literal content up to the match index if (currentIndex < match.Index) { mergedTemplateBuilder.Append(mergedTemplate.Substring(currentIndex, (match.Index - currentIndex))); currentIndex = match.Index; } //include the nested scriptlet ScriptletType nestedType = (ScriptletType)Enum.Parse(typeof(ScriptletType), match.Groups[1].Value); string nestedIdentifier = match.Groups[2].Value.Trim(); Scriptlet nestedScriptlet = ScriptletDataSource.Load(this.Page.Theme, nestedIdentifier, nestedType, true); if (nestedScriptlet != null) { if (!string.IsNullOrEmpty(nestedScriptlet.HeaderData)) { this.Page.Header.Controls.Add(new LiteralControl(nestedScriptlet.HeaderData)); } mergedTemplateBuilder.Append(nestedScriptlet.ScriptletData); } //advance the current index currentIndex += match.Length; } //output any remaining literal content if (currentIndex < mergedTemplate.Length) { mergedTemplateBuilder.Append(mergedTemplate.Substring(currentIndex)); } mergedTemplate = mergedTemplateBuilder.ToString(); } return(mergedTemplate); }
/// <summary> /// Scans a content scriptlet to determine if it contains reference to a OnePageCheckout control /// </summary> /// <param name="identifier">The identifier of the content scriptlet</param> /// <returns>True if the one page checkout control is discovered in the specified scriptlet</returns> private static bool IsOnePageCheckoutSetInScriptlet(string themeName, string identifier) { // TRY TO LOAD THE SPECIFIED SCRIPTLET Scriptlet s = ScriptletDataSource.Load(themeName, identifier, ScriptletType.Content); if (s != null) { // SEE IF SCRIPTLET CONTAINS A REFERENCE TO ONE PAGE CHECKOUT CONTROL // IF IT HAS ONE PAGE CHECKOUT, RETURN 1 (TRUE) ELSE 0 (FALSE) return(s.ScriptletData.Contains("[[ConLib:OnePageCheckout")); } else { // THE SCRIPTLET COULD NOT BE LOADED, ONE PAGE CHECKOUT IDENTIFIER NOT PRESENT return(false); } }
private void HandleEdit(DropDownList choices, ScriptletType scriptletType) { Control c = RecursiveFindControl(this.Page, "EditScriptlet"); if (c != null) { Scriptlet s = ScriptletDataSource.Load(this.Page.Theme, choices.SelectedValue, scriptletType); if (s != null) { System.Reflection.PropertyInfo i = c.GetType().GetProperty("Identifier"); i.SetValue(c, s.Identifier, null); System.Reflection.PropertyInfo t = c.GetType().GetProperty("ScriptletType"); t.SetValue(c, s.ScriptletType, null); //we do not want the edit-mode section to disappear when user clicked on //the edit icon without selecting any valid scriptlet in the dropdown c = RecursiveFindControl(this.Page, "phEditor"); if (c != null) { c.Visible = false; } } } }
protected override void CreateChildControls() { bool created = false; Scriptlet Identifier = ScriptletDataSource.Load(this.Page.Theme, this.Identifier, (ScriptletType)Enum.Parse(typeof(ScriptletType), this.ScriptletType), true); string IdentifierScriptletData = string.Empty; if (Identifier != null) { if (!string.IsNullOrEmpty(Identifier.HeaderData)) { this.Page.Header.Controls.Add(new LiteralControl(Identifier.HeaderData)); } IdentifierScriptletData = Identifier.ScriptletData; } string template = IdentifierScriptletData; //PROCESS THE MERGED NVELOCITY TEMPLATE System.Collections.Hashtable parameters = new System.Collections.Hashtable(); object store = Token.Instance.Store; object customer = Token.Instance.User; parameters.Add("store", store); parameters.Add("customer", customer); //TODO: OBSOLETE PARAMETERS, REMOVE FOR AC7.1 parameters.Add("Store", store); parameters.Add("User", customer); //CHECK FOR CATEGORY int categoryId = GetCategoryId(); Category category = CategoryDataSource.Load(categoryId); if (category != null) { parameters.Add("Category", category); } //CHECK FOR PRODUCT int productId = GetProductId(); Product product = ProductDataSource.Load(productId); if (product != null) { parameters.Add("Product", product); } //CHECK FOR WEBPAGE int webpageId = GetWebpageId(); Webpage webpage = WebpageDataSource.Load(webpageId); if (webpage != null) { parameters.Add("Webpage", webpage); } //CHECK FOR LINK int linkId = GetLinkId(); Link link = LinkDataSource.Load(linkId); if (link != null) { parameters.Add("Link", link); } string result = NVelocityEngine.Instance.Process(parameters, template); if (this.Page != null) { string baseUrl = this.Page.ResolveUrl("~"); result = result.Replace("href=\"~/", "href=\"" + baseUrl); result = result.Replace("src=\"~/", "src=\"" + baseUrl); //DISABLE THE ABILITY TO REFER TO ANY USER CONTROL //MatchCollection userControls = Regex.Matches(result, "\\[\\[(ConLib|UserControl):([^\\]]+)\\]\\]", RegexOptions.IgnoreCase); MatchCollection userControls = Regex.Matches(result, "\\[\\[(ConLib):([^\\]]+)\\]\\]", RegexOptions.IgnoreCase); if (userControls.Count > 0) { int currentIndex = 0; foreach (Match match in userControls) { //output the literal content up to the match index if (currentIndex < match.Index) { this.Controls.Add(new LiteralControl(result.Substring(currentIndex, (match.Index - currentIndex)))); currentIndex = match.Index; } string controlPath; Dictionary <string, string> attributes; ParseControlPath(match.Groups[2].Value.Trim(), out controlPath, out attributes); if (match.Groups[1].Value.ToLowerInvariant() == "conlib") { controlPath = "~/ConLib/" + controlPath + ".ascx"; } //LOAD AND OUTPUT THE CONTROL try { Control control = this.Page.LoadControl(controlPath); if (control != null) { //TRY TO SET PARAMS foreach (string propName in attributes.Keys) { //CHECK WHETHER PROPERTY EXISTS System.Reflection.PropertyInfo pi = control.GetType().GetProperty(propName); if (pi != null) { //SET THE PROPERTY WITH THE GIVEN VALUE object value = Convert.ChangeType(attributes[propName], pi.PropertyType); pi.SetValue(control, value, null); } } //ADD CONTROL TO THE COLLECTION this.Controls.Add(control); } } catch (Exception ex) { this.Controls.Add(new LiteralControl(match.Value + " " + ex.Message)); } //advance the current index currentIndex += match.Length; } //output any remaining literal content if (currentIndex < result.Length) { this.Controls.Add(new LiteralControl(result.Substring(currentIndex))); } created = true; } } if (!created) { this.Controls.Add(new LiteralControl(result)); } }