예제 #1
0
        protected virtual IEnumerable <XElement> GetContent(PrintContext printContext, XElement textFrameNode)
        {
            XAttribute xattribute = textFrameNode.Attribute((XName)"ParagraphStyle");
            string     str        = xattribute == null || string.IsNullOrEmpty(xattribute.Value) ? "NormalParagraphStyle" : xattribute.Value;

            if (!string.IsNullOrEmpty(this.InDesignContent))
            {
                return(this.FormatText(str, this.InDesignContent));
            }
            if (string.IsNullOrEmpty(this.ContentFieldName))
            {
                return((IEnumerable <XElement>)null);
            }
            try
            {
                Item dataItem = this.GetDataItem(printContext);
                if (dataItem != null)
                {
                    Field field = dataItem.Fields[this.ContentFieldName];
                    if (field == null)
                    {
                        return((IEnumerable <XElement>)null);
                    }
                    switch (field.Type)
                    {
                    case "Rich Text":
                        ParseContext context = new ParseContext(printContext.Database, printContext.Settings)
                        {
                            DefaultParagraphStyle = str,
                            ParseDefinitions      = RichTextParser.GetParseDefinitionCollection(this.RenderingItem)
                        };
                        string   htmlWithItemId = $"<!--{dataItem.ID.Guid.ToString("B")}-->" + field.Value;
                        string   xml            = RichTextParser.ConvertToXml(htmlWithItemId, context, printContext.Language);
                        XElement element        = new XElement((XName)"temp");
                        element.AddFragment(xml);
                        return(element.Elements());

                    case "Single-Line Text":
                        str = fieldStyles.ContainsKey(ContentFieldName) ? fieldStyles[ContentFieldName] : str;
                        string singleLineContent = SitecoreHelper.FetchFieldValue(dataItem, field.Name, printContext.Database, str);
                        return(this.FormatText(str, singleLineContent));

                    default:
                        string content = SitecoreHelper.FetchFieldValue(dataItem, field.Name, printContext.Database, str);
                        return(this.FormatText(str, content));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Rendering TextFrame: " + (object)this.RenderingItem.ID, ex);
            }
            return((IEnumerable <XElement>)null);
        }