/// <summary>
        /// Retrieves the UrlContext for the item in context
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private UrlContext GetContext(CommandContext context)
        {
            //start retrieval process
            UrlContext urlContext = new UrlContext();
            urlContext.Parameters = context.Parameters;

            foreach (XmlNode node in Factory.GetConfigNodes("itemUrlHelper/processUrl/child::node()"))
            {
                if (node.Name != "processor")
                {
                    continue;
                }

                IProcessUrl processUrl = ProcessUrlFactory.GetProcessUrl(node, urlContext);
                if (processUrl == null)
                {
                    continue;
                }

                processUrl.Process();
                urlContext = processUrl.UrlContext;
            }

            return urlContext;
        }
        public static IProcessUrl GetProcessUrl(XmlNode node, UrlContext context)
        {
            if (node.Name != "processor")
            {
                return null;
            }

            if (node.Attributes["type"] != null && !string.IsNullOrEmpty(node.Attributes["type"].Value))
            {
                return GetItem_FromReflection(node, context);
            }

            return null;
        }
        /// <summary>
        /// Sends reponse to client
        /// </summary>
        /// <param name="url"></param>
        private void SendResponse(UrlContext urlContext)
        {
            //close context menu
            Sitecore.Context.ClientPage.ClientResponse.ClosePopups(true);

            //check for messages
            if (urlContext.Messages.Count > 0)
            {
                string messages = string.Empty;
                foreach(string s in urlContext.Messages)
                {
                    string message = s.Trim();
                    if(!s.Contains("."))
                    {
                        message += s;
                    }

                    messages += message + " ";
                }

                Sitecore.Context.ClientPage.ClientResponse.Alert(messages.Trim());
            }
            //verify there is a url
            else if (string.IsNullOrEmpty(urlContext.Url))
            {
                Sitecore.Context.ClientPage.ClientResponse.Alert("The selected item does not have presentation settings.");
            }
            //return url to front end
            else
            {
                string clientResponseText = "The Url for the selected item is: " + urlContext.Url;

                //if we are on IE we can copy to the clipboard
                if (UIUtil.IsIE())
                {
                    //set clipboard
                    Sitecore.Context.ClientPage.ClientResponse.Eval(string.Format("window.clipboardData.setData('Text','{0}')", urlContext.Url));
                    clientResponseText = "The Url for the selected item has been copied: " + urlContext.Url;
                }
                else if (UIUtil.IsFirefox() || UIUtil.IsWebkit())
                {
                    Sitecore.Context.ClientPage.ClientResponse.Eval(string.Format("window.prompt('Copy to clipboard: Ctrl+C, Enter','{0}')", urlContext.Url));
                    return;
                }

                Sitecore.Context.ClientPage.ClientResponse.Alert(clientResponseText);
            }
        }
        /// <summary>
        /// Return item from reflection
        /// </summary>
        /// <param name="node"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        private static IProcessUrl GetItem_FromReflection(XmlNode node, UrlContext context)
        {
            try
            {
                //verify we can break up the type string into a namespace and assembly name
                string[] split = node.Attributes["type"].Value.Split(',');
                if (split.Length == 0)
                {
                    return null;
                }

                string Namespace = split[0];
                string AssemblyName = split[1];

                // load the assemly
                Assembly assembly = GetAssembly(AssemblyName);

                // Walk through each type in the assembly looking for our class
                Type type = assembly.GetType(Namespace);
                if (type == null || !type.IsClass)
                {
                    return null;
                }

                object[] parameters = new object[1];
                parameters[0] = context;

                //cast to process url class
                IProcessUrl processUrl = (IProcessUrl)Activator.CreateInstance(type, parameters);

                return processUrl;
            }
            catch (Exception e)
            {
                Sitecore.Diagnostics.Log.Error("Item Url Helper: Could not instantiate ICleanUrl object.", e, typeof(ProcessUrlFactory));
            }

            return null;
        }
Exemplo n.º 5
0
 public CleanUrl(UrlContext urlContext)
     : base(urlContext)
 {
 }
Exemplo n.º 6
0
 public GetDevice(UrlContext urlContext)
     : base(urlContext)
 {
 }
Exemplo n.º 7
0
 public GetMediaUrl(UrlContext urlContext)
     : base(urlContext)
 {
 }
Exemplo n.º 8
0
 public GetUrl(UrlContext urlContext)
     : base(urlContext)
 {
 }
Exemplo n.º 9
0
 public GetItem(UrlContext urlContext)
     : base(urlContext)
 {
 }
Exemplo n.º 10
0
 public AProcessUrl(UrlContext urlContext)
 {
     UrlContext = urlContext;
 }