Esempio n. 1
0
        /// <summary>
        /// 创建视图对象
        /// </summary>
        /// <param name="path">相对路径,如:/abc/cyq/a.html</param>
        public static XHtmlAction Create(string path)
        {
            string fullPath = AppConfig.WebRootPath + path.TrimStart('/');//.Replace("/", "\\");
            bool   isExists = File.Exists(fullPath);

            if (!isExists)
            {
                fullPath = AppConfig.WebRootPath + path.TrimStart('/').ToLower();
                isExists = File.Exists(fullPath);
            }
            // System.Web.HttpContext.Current.Response.Write(path);
            if (isExists)
            {
                //System.Web.HttpContext.Current.Response.Write("path ok");
                XHtmlAction view = new XHtmlAction(true, false);

                if (view.Load(fullPath, XmlCacheLevel.Hour, true))
                {
                    // System.Web.HttpContext.Current.Response.Write("load ok");
                    //处理Shared目录下的节点替换。
                    ReplaceItemRef(view, view.GetList("*", "itemref"), false, 0);
                }
                //System.Web.HttpContext.Current.Response.Write(view.OutXml);
                return(view);
            }
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// 创建视图对象
        /// </summary>
        /// <param name="path">相对路径,如:/abc/cyq/a.html</param>
        public static XHtmlAction Create(string path)
        {
            path = AppConfig.WebRootPath + path.TrimStart('/').Replace("/", "\\");
            if (File.Exists(path))
            {
                XHtmlAction view = new XHtmlAction(true, false);

                if (view.Load(path, XmlCacheLevel.Hour, true))
                {
                    //处理Shared目录下的节点替换。
                    ReplaceItemRef(view, view.GetList("*", "itemref"), false, 0);
                }
                return(view);
            }
            return(null);
        }
Esempio n. 3
0
        private static void ReplaceItemRef(XHtmlAction view, XmlNodeList list, bool isBreak, int loopCount)
        {
            //处理Shared目录下的节点替换。
            if (list != null && list.Count > 0)
            {
                if (loopCount > 50)
                {
                    throw new Exception("Reference loop : " + list[0].InnerXml);
                }
                string itemref = "itemref";
                for (int i = 0; i < list.Count; i++)
                {
                    string itemValue = list[i].Attributes[itemref].Value;
                    if (!string.IsNullOrEmpty(itemValue))
                    {
                        bool     isOK  = false;
                        string[] items = itemValue.Split('.');
                        if (items.Length == 1)// 只一个节点,从当前节点寻找。
                        {
                            XmlNode xNode = view.Get(items[0]);
                            if (xNode != null)
                            {
                                view.ReplaceNode(xNode, list[i]);
                                view.Remove(xNode);//从自己拿节点的,需要移除
                                isOK = true;
                            }
                        }
                        else
                        {
                            XHtmlAction sharedView = GetSharedView(items[0], view.FileName);//找到masterView
                            if (sharedView != null)
                            {
                                XmlNode xNode = sharedView.Get(items[1]);//找到被替换的节点


                                if (xNode != null)
                                {
                                    view.InsertAfter(xNode, list[i]);                                            //先插入节点。
                                    XmlNodeList childNodeList = view.GetList("*", itemref, list[i].NextSibling); //检测内部是否有引用指向外部。
                                    if (childNodeList != null && childNodeList.Count > 0)
                                    {
                                        loopCount++;
                                        ReplaceItemRef(view, childNodeList, true, loopCount); //下次跳出,避免死循环。
                                    }
                                    view.Remove(list[i]);                                     //移除节点
                                    isOK = true;
                                }
                            }
                        }
                        if (!isOK)
                        {
                            view.Remove(list[i]);//移除没有引用的节点
                            // view.RemoveAttr(list[i], itemref);
                        }
                    }
                }
                loopCount++;
                if (!isBreak)//避免死循环。
                {
                    ReplaceItemRef(view, view.GetList("*", itemref), isBreak, loopCount);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 查询网站正文设定标志列表(xml文件)
        /// </summary>
        /// <returns></returns>
        public List <SiteSign> GetSiteSignList()
        {
            var         list = new List <SiteSign>();
            XHtmlAction xml  = new XHtmlAction();

            if (xml.Load(@"SiteSign.xml"))
            {
                var nodeList = xml.GetList("SiteSign");
                foreach (XmlNode item in nodeList)
                {
                    var sign = new SiteSign();
                    foreach (XmlNode node in item.ChildNodes)
                    {
                        string value = node.InnerXml
                                       .Replace("&amp;", "&")
                                       .Replace("&lt;", "<")
                                       .Replace("&gt;", ">")
                                       .Replace("&quot;", "\"")
                                       .Replace("&apos;", "\'");

                        #region 赋值

                        switch (node.Name)
                        {
                        case "name":
                            sign.name = value;
                            break;

                        case "url":
                            sign.url = value;
                            break;

                        case "ListStart":
                            sign.ListStart = value;
                            break;

                        case "ListEnd":
                            sign.ListEnd = value;
                            break;

                        case "ContentStart":
                            sign.ContentStart = value;
                            break;

                        case "ContentEnd":
                            sign.ContentEnd = value;
                            break;

                        case "NeedDelStr":
                            sign.NeedDelStr = value;
                            break;

                        case "VolumeStart":
                            sign.VolumeStart = value;
                            break;

                        case "VolumeEnd":
                            sign.VolumeEnd = value;
                            break;

                        case "BriefUrlStart":
                            sign.BriefUrlStart = value;
                            break;

                        case "BriefUrlEnd":
                            sign.BriefUrlEnd = value;
                            break;

                        case "AuthorStart":
                            sign.AuthorStart = value;
                            break;

                        case "AuthorEnd":
                            sign.AuthorEnd = value;
                            break;

                        case "BriefStart":
                            sign.BriefStart = value;
                            break;

                        case "BriefEnd":
                            sign.BriefEnd = value;
                            break;

                        case "BookImgUrlStart":
                            sign.BookImgUrlStart = value;
                            break;

                        case "BookImgUrlEnd":
                            sign.BookImgUrlEnd = value;
                            break;

                        default:
                            break;
                        }
                        #endregion
                    }
                    list.Add(sign);
                }
            }
            ;
            return(list);
        }