예제 #1
0
        public string Render(PlaceHolder placeHolder, PageEntry pageEntry, XmlDocument content, Stack <string> placeHolderStack, out bool containsCacheableContent)
        {
            containsCacheableContent = false;
            String[] arr = placeHolder.Expression.Split('|');
            if (arr.Length != 2)
            {
                return("[EmbedSecure requires expression: loggedInPageCode|loggedOutPageCode (use relevant page code values, or blank for none)]");
            }

            string pagecode = (WebAuthentication.Instance.IsLoggedIn ? arr[0] : arr[1]).Trim();

            if (pagecode == "")
            {
                return("");
            }

            PageEntry page = PageRegistry.Pages.FromPageCode(pagecode);

            if (page == null)
            {
                return("[No page found with PageCode \"" + pagecode + "\"]");
            }

            bool discard;

            return(page.Render(placeHolderStack, out discard));
        }
        public string Render(PlaceHolder placeHolder, PageEntry pageEntry, XmlDocument content, Stack <string> placeHolderStack, out bool containsCacheableContent)
        {
            PageEntry page = PageRegistry.Pages.FromPageCode(placeHolder.Expression);

            if (page == null)
            {
                containsCacheableContent = false;
                return("[No page found with PageCode \"" + placeHolder.Expression + "\"]");
            }
            return(page.Render(placeHolderStack, out containsCacheableContent));
        }
        void OnLoadRequestedPath(HttpApplication app, string sprocketPath, string[] pathSections, HandleFlag handled)
        {
            if (handled.Handled)
            {
                return;
            }

            if (!File.Exists(WebUtility.MapPath(PageRegistry.XmlFilePath)))
            {
                return;
            }

            switch (sprocketPath)
            {
            case "$reset":
                PageRegistry.UpdateValues();
                TemplateRegistry.Reload();
                ListRegistry.Reload();
                OutputFormatRegistry.Reload();
                GeneralRegistry.Reload();
                ContentCache.ClearCache();
                WebUtility.Redirect("");
                break;

            default:
                PageRegistry.CheckDate();

                PageEntry page = PageRegistry.Pages.FromPath(sprocketPath);
                if (page == null)
                {
                    return;
                }
                if (OnBeforeRenderPage != null)
                {
                    OnBeforeRenderPage(page, sprocketPath, pathSections);
                }
                string output = page.Render();
                if (output == null)
                {
                    return;
                }
                Response.Write(output);
                break;
            }

            handled.Set();
        }
        public string Render(string xpath, PageEntry pageEntry, XmlDocument content, Stack <string> placeHolderStack, out bool containsCacheableContent)
        {
            string      text = "";
            XmlNodeList nodes;

            try
            {
                nodes = content.SelectNodes(xpath);
            }
            catch
            {
                containsCacheableContent = false;
                return("[Cannot render placeholder; invalid XPath expression]");
            }
            if (nodes.Count == 0)
            {
                containsCacheableContent = false;
                return(null);
            }
            bool cacheable = true;

            foreach (XmlElement node in nodes)
            {
                if (node != null)
                {
                    if (node.HasAttribute("Embed"))
                    {
                        PageEntry embedPageEntry = PageRegistry.Pages.FromPageCode(node.GetAttribute("Embed"));
                        if (embedPageEntry == null)
                        {
                            text += "[Embed failed. Page code \"" + node.GetAttribute("Embed") + "\" not found]";
                        }
                        else
                        {
                            bool   returnValueCached;
                            string embed = embedPageEntry.Render(placeHolderStack, out returnValueCached);
                            cacheable = cacheable && returnValueCached;
                            if (embed == null)
                            {
                                text += "[Content not found for embedded page " + pageEntry.PageCode + "]";
                            }
                            else
                            {
                                text += embed;
                            }
                        }
                    }
                    else
                    {
                        if (node.FirstChild != null)
                        {
                            bool   cache;
                            string str = node.FirstChild.Value;
                            foreach (PlaceHolder ph in PlaceHolder.Extract(str))
                            {
                                str       = str.Replace(ph.RawText, ph.Render(pageEntry, content, placeHolderStack, out cache));
                                cacheable = cacheable && cache;
                            }
                            text += str;
                        }
                    }
                }
                else
                {
                    text += "[Content not found for node " + xpath + "]";
                }
            }
            containsCacheableContent = cacheable;
            return(text);
        }