/// <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 do render.
        /// </summary>
        /// <param name="output">
        /// The output.
        /// </param>
        protected override void DoRender(HtmlTextWriter output)
        {
            // Item item = this.GetItem();
            MediaBaseObject mediaObject = this.CreateMediaObject(this.Item);

            if (mediaObject != null)
            {
                mediaObject.RenderControl(output);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Gets the media object.
        /// </summary>
        /// <param name="extension">
        /// The files extension.
        /// </param>
        /// <returns>
        /// Return media object for the extension. If object doesn't exit and useDefaultObject set to true, return default media object.
        /// </returns>
        public MediaBaseObject GetMediaObject(string extension)
        {
            string mediaObjectType;

            if (this.mediaObjectExtensions.TryGetValue(extension.ToLower(), out mediaObjectType))
            {
                MediaBaseObject mediaBaseObject = ReflectionUtil.CreateObject(mediaObjectType) as MediaBaseObject;
                return(mediaBaseObject);
            }

            return(null);
        }
        /// <summary>
        /// The set media object atributes.
        /// </summary>
        /// <param name="mediaObject">
        /// The media object.
        /// </param>
        private void SetMediaObjectAtributes(MediaBaseObject mediaObject)
        {
            mediaObject.AddObjectAttribute("src", this.src);
            mediaObject.AddObjectAttribute("border", this.border);
            mediaObject.AddObjectAttribute("alt", this.altText);
            mediaObject.AddObjectAttribute("vspace", this.vSpace);
            mediaObject.AddObjectAttribute("hspace", this.hSpace);
            mediaObject.CssClass = this.CssClass;

            string currentWidth;
            string currentHeight;

            this.GetMinValues(this.maxWidth, this.maxHeight, this.width, this.height, out currentWidth, out currentHeight);
            mediaObject.Width  = new Unit(StringUtil.GetString(currentWidth));
            mediaObject.Height = new Unit(StringUtil.GetString(currentHeight));
        }