static void InflateKeywords(ItemFields fields, XmlElement element)
        {
            var ns = new XmlNamespaceManager(element.OwnerDocument.NameTable);

            ns.AddNamespace("ns", element.NamespaceURI);

            fields
            .OfType <KeywordField>()
            .ToList()
            .ForEach(keywordField =>
                     element.SelectNodes("./ns:" + keywordField.Name, ns)
                     .OfType <XmlElement>()
                     .ToList()
                     .ForEach(kwelement =>
            {
                kwelement.SetAttribute("href", "http://www.w3.org/1999/xlink", keywordField.Values.First(v => v.Title.Equals(kwelement.InnerText)).Id);
                kwelement.SetAttribute("type", "http://www.w3.org/1999/xlink", "simple");
                kwelement.SetAttribute("title", "http://www.w3.org/1999/xlink", kwelement.InnerText);
            })
                     );

            fields
            .OfType <EmbeddedSchemaField>()
            .ToList()
            .ForEach(embedField =>
                     element.SelectNodes("./ns:" + embedField.Name, ns)
                     .OfType <XmlElement>()
                     .Select((embedElement, i) => new { Fields = embedField.Values[i], Element = embedElement })
                     .ToList()
                     .ForEach(a => InflateKeywords(a.Fields, a.Element))
                     );
        }
        private string GetBannerImageTcmId()
        {
            var    page       = GetPage();
            string imageTcmId = null;

            foreach (var cp in page.ComponentPresentations)
            {
                //ImageGallery
                var fields = new ItemFields(cp.Component.Content, cp.Component.Schema);

                var images = fields.OfType <MultimediaLinkField>();

                if (images == null || images.Count() == 0)
                {
                    //Logger.Info("No Multimedia Link Fields in the context.");
                    continue;
                }

                var multimediaLink = images.FirstOrDefault(img => img.Name.ToLowerInvariant().Equals("imagegallery"));

                if (multimediaLink != null && multimediaLink.Value != null && multimediaLink.Value.ComponentType == ComponentType.Multimedia)
                {
                    imageTcmId = multimediaLink.Value.Id;
                    break;
                }
            }

            return(imageTcmId);
        }
Esempio n. 3
0
        private void ExtractDataAttributes(ItemFields fields, StringBuilder dataAttributesBuilder)
        {
            if (fields == null)
            {
                return;
            }

            foreach (string fieldname in _dataFieldNames.Where(fn => fields.Contains(fn)))
            {
                string dataAttribute = string.Format(" data-{0}=\"{1}\"", fieldname, System.Net.WebUtility.HtmlEncode(fields.GetSingleFieldValue(fieldname)));
                dataAttributesBuilder.Append(dataAttribute);
            }

            // Flatten embedded fields
            foreach (EmbeddedSchemaField embeddedSchemaField in fields.OfType <EmbeddedSchemaField>())
            {
                ExtractDataAttributes(embeddedSchemaField.Value, dataAttributesBuilder);
            }
        }
        private void ExtractDataAttributes(ItemFields fields, StringBuilder dataAttributesBuilder)
        {
            if (fields == null)
            {
                return;
            }

            foreach (string fieldname in _dataFieldNames.Where(fn => fields.Contains(fn)))
            {
                string dataAttribute = string.Format(" data-{0}=\"{1}\"", fieldname, System.Net.WebUtility.HtmlEncode(fields.GetSingleFieldValue(fieldname)));
                dataAttributesBuilder.Append(dataAttribute);
            }

            // Flatten embedded fields
            foreach (EmbeddedSchemaField embeddedSchemaField in fields.OfType<EmbeddedSchemaField>())
            {
                ExtractDataAttributes(embeddedSchemaField.Value, dataAttributesBuilder);
            }
        }