/// <summary> /// The create media object. /// </summary> /// <param name="item"> /// The current item. /// </param> /// <returns> /// Media Object class /// </returns> private MediaBaseObject CreateMediaObject(Item item) { MediaItem mediaItem = null; Data.Fields.ImageField currentImageField = null; if (this.RenderParameters != null) { this.ParseNode(this.RenderParameters); } if (item != null) { if (!string.IsNullOrEmpty(this.fieldName)) { Field innerField = item.Fields[this.fieldName]; Assert.IsNotNull(innerField, "Item {0} don't have field {1}", item.ID.ToString(), this.fieldName); if (innerField != null) { currentImageField = string.IsNullOrEmpty(this.fieldValue) ? new Data.Fields.ImageField(innerField) : new Data.Fields.ImageField(innerField, this.fieldValue); mediaItem = currentImageField.MediaItem; } this.ParseField(currentImageField); this.ParseMediaItem(mediaItem); } else if (item.Paths.IsMediaItem) { mediaItem = item; this.ParseMediaItem(mediaItem); } } if (string.IsNullOrEmpty(this.src)) { SiteContext site = Sitecore.Context.Site; if (((site != null) && (site.DisplayMode == DisplayMode.Edit)) && !Sitecore.Context.PageMode.IsPageEditorEditing) { this.src = GetDefaultImage(); } else { return(null); } } string mediaObjectExtension = mediaItem != null ? mediaItem.Extension : Path.GetExtension(this.src).Replace(".", string.Empty); MediaBaseObject mediaObject = Singleton <MediaControlsFactory> .Instance.GetMediaObject(mediaObjectExtension); if (mediaObject != null) { this.SetAtributesToAshx(); this.SetMediaObjectAtributes(mediaObject); } return(mediaObject); }
/// <summary> /// The parse field. /// </summary> /// <param name="currentImageField"> /// The current image field. /// </param> private void ParseField(Data.Fields.ImageField currentImageField) { if (!string.IsNullOrEmpty(this.database)) { currentImageField.MediaDatabase = Factory.GetDatabase(this.database); } if (!string.IsNullOrEmpty(this.language)) { currentImageField.MediaLanguage = Language.Parse(this.language); } if (!string.IsNullOrEmpty(this.version)) { currentImageField.MediaVersion = Data.Version.Parse(this.version); } this.src = StringUtil.GetString(new[] { this.src, currentImageField.Src }); this.altText = StringUtil.GetString(new[] { this.altText, currentImageField.Alt }); this.border = StringUtil.GetString(new[] { this.border, currentImageField.Border }); this.height = StringUtil.GetString(new[] { this.height, currentImageField.Height }); this.width = StringUtil.GetString(new[] { this.width, currentImageField.Width }); this.hSpace = StringUtil.GetString(new[] { this.hSpace, currentImageField.HSpace }); this.vSpace = StringUtil.GetString(new[] { this.vSpace, currentImageField.VSpace }); this.CssClass = StringUtil.GetString(new[] { this.CssClass, currentImageField.Class }); }