Пример #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);
        }
Пример #2
0
        private IEnumerable <XElement> GetItemParagraphs(PrintContext printContext)
        {
            var dataItem      = GetDataItem(printContext);
            var dataItemField = RenderingItem[Templates.DataReference.Fields.ItemField];

            if (dataItem == null || string.IsNullOrEmpty(dataItemField))
            {
                return(Enumerable.Empty <XElement>());
            }

            // Fetch the value for the field point in the ParagraphStyle element and add it as a CDATA
            var field   = dataItem.Fields[dataItemField];
            var context = new ParseContext(printContext.Database, printContext.Settings)
            {
                ParseDefinitions = RichTextParser.GetParseDefinitionCollection(RenderingItem)
            };
            var content  = RichTextParser.ConvertToXml(field.Value, context, printContext.Language);
            var xElement = new XElement("temp");

            xElement.AddFragment(content);
            return(xElement.Elements());
        }