Example #1
0
        //对“翻页项容器”(stl:pageItems)元素进行解析,此元素在生成页面时单独解析,不包含在ParseStlElement方法中。
        public static async Task <string> ParseAsync(IParseManager parseManager, string stlElement, int channelId, int contentId, int currentPageIndex, int pageCount, int totalNum, ParseType contextType)
        {
            var pageInfo = parseManager.PageInfo;

            await pageInfo.AddPageHeadCodeIfNotExistsAsync(ParsePage.Const.Jquery);

            string parsedContent;

            try
            {
                var stlElementInfo = StlParserUtility.ParseStlElement(stlElement);
                if (stlElementInfo.Attributes[Context] != null)
                {
                    contextType = TranslateUtils.ToEnum(stlElementInfo.Attributes[Context], ParseType.Undefined);
                }

                if (pageCount <= 1)
                {
                    return(string.Empty);
                }

                bool isXmlContent;
                var  index  = stlElement.IndexOf(">", StringComparison.Ordinal) + 1;
                var  length = stlElement.LastIndexOf("<", StringComparison.Ordinal) - index;
                if (index <= 0 || length <= 0)
                {
                    stlElement   = stlElementInfo.InnerHtml;
                    isXmlContent = true;
                }
                else
                {
                    stlElement   = stlElement.Substring(index, length);
                    isXmlContent = false;
                }

                parsedContent = await parseManager.ParseStlPageItemsAsync(stlElement, channelId, contentId, currentPageIndex, pageCount, totalNum, isXmlContent, contextType);

                var innerBuilder = new StringBuilder(parsedContent);
                await parseManager.ParseInnerContentAsync(innerBuilder);

                parsedContent = innerBuilder.ToString();
            }
            catch (Exception ex)
            {
                parsedContent =
                    await parseManager.AddStlErrorLogAsync(ElementName, stlElement, ex);
            }

            return(parsedContent);
        }