using Microsoft.SharePoint.Utilities; using SPSolutions.Serialization; using System; using System.Collections; using System.Web; using System.Xml.Serialization; namespace SPSolutions.SharePoint.Alerts { public abstract class NotificationMessageBase { private string m_css; private string m_headerTemplate; private string m_bodyTemplate; private string m_footerTemplate; private string m_alertDetailTransform; private string m_subjectTemplate; private string m_finalizedSubject; private string m_finalizedMessage; private bool m_isDirty; public string AlertDetailTransform { get { return this.m_alertDetailTransform; } set { this.m_alertDetailTransform = value; } } [XmlElement] public string HeaderTemplate { get { return this.m_headerTemplate; } set { this.m_headerTemplate = value; this.IsDirty = true; } } public string HtmlEncodedHeaderTemplate { get { return SPHttpUtility.HtmlEncode(this.m_headerTemplate); } } [XmlElement] public string BodyTemplate { get { return this.m_bodyTemplate; } set { this.m_bodyTemplate = value; this.IsDirty = true; } } public string HtmlEncodedBodyTemplate { get { return SPHttpUtility.HtmlEncode(this.m_bodyTemplate); } } [XmlElement] public string FooterTemplate { get { return this.m_footerTemplate; } set { this.m_footerTemplate = value; this.IsDirty = true; } } public string HtmlEncodedFooterTemplate { get { return SPHttpUtility.HtmlEncode(this.m_footerTemplate); } } [XmlElement] public string Style { get { return this.m_css; } set { this.m_css = value; this.IsDirty = true; } } [XmlElement] public string AlertDetailXslt { get { return this.m_alertDetailTransform; } set { this.m_alertDetailTransform = value; this.IsDirty = true; } } public string HtmlEncodedAlertDetailXslt { get { return SPHttpUtility.HtmlEncode(this.m_alertDetailTransform); } } [XmlElement] public string SubjectTemplate { get { return this.m_subjectTemplate; } set { this.m_subjectTemplate = value; } } public bool IsDirty { get { return this.m_isDirty; } set { this.m_isDirty = value; } } public NotificationMessageBase() { } public NotificationMessageBase(bool loadDefaults) { this.LoadDefaults(); } public abstract void LoadDefaults(); public string GetFinalizedSubject(Hashtable tokens) { if (string.IsNullOrEmpty(this.m_finalizedSubject)) { this.m_finalizedSubject = StringUtil.ReplaceCurlyBraceTokens(this.SubjectTemplate, tokens); } return this.m_finalizedSubject; } public string GetFinalizedMessage(Hashtable tokens) { if (string.IsNullOrEmpty(this.m_finalizedMessage)) { tokens.Add("STYLE", this.Style); string text = SerializationUtil.GetAssemblyManifestResourceFileContent("Alerts.TrueNotificationMessageHeader.htm"); text = StringUtil.ReplaceCurlyBraceTokens(text, tokens); string text2 = SerializationUtil.GetAssemblyManifestResourceFileContent("Alerts.TrueNotificationMessageFooter.htm"); text2 = StringUtil.ReplaceCurlyBraceTokens(text2, tokens); this.m_finalizedMessage = text; this.m_finalizedMessage += StringUtil.ReplaceCurlyBraceTokens(this.HeaderTemplate, tokens); this.m_finalizedMessage += StringUtil.ReplaceCurlyBraceTokens(this.BodyTemplate, tokens); this.m_finalizedMessage += StringUtil.ReplaceCurlyBraceTokens(this.FooterTemplate, tokens); this.m_finalizedMessage += text2; } return HttpUtility.HtmlDecode(this.m_finalizedMessage); } public string GetHtmlEncodedFinalizedMessage(Hashtable tokens) { string str = null; str += SPHttpUtility.HtmlEncode(StringUtil.ReplaceCurlyBraceTokens(this.HeaderTemplate, tokens)); str += StringUtil.ReplaceCurlyBraceTokens(this.BodyTemplate, tokens); return str + SPHttpUtility.HtmlEncode(StringUtil.ReplaceCurlyBraceTokens(this.FooterTemplate, tokens)); } } }