Exemplo n.º 1
0
        /// <summary>
        /// Extarcts the references to Tridion items from the template content. It is allowed to have values in the result that are not valid Tridion references.
        /// </summary>
        /// <returns></returns>
        public override string[] PerformExtractReferences()
        {
            TemplatingLogger log = TemplatingLogger.GetLogger(this.GetType());

            string[] dwReferences = _dwHandler.PerformExtractReferences();

            RazorHandler handler = new RazorHandler(TemplateId.ToString(), WebDavUrl, Content);

            handler.Initialize();

            List <string> imports    = handler.GetImportReferences();
            List <string> references = dwReferences.ToList();

            foreach (string path in imports)
            {
                if (!path.ToLower().StartsWith("tcm:") && !path.ToLower().StartsWith("/webdav/"))
                {
                    references.Add(GetRelativeImportPath(path));
                }
                else
                {
                    if (path.StartsWith("/webdav/"))
                    {
                        string[] pathParts   = path.Split('/');
                        string[] webDavParts = WebDavUrl.Split('/');

                        if (pathParts[2] != webDavParts[2])
                        {
                            pathParts[2] = webDavParts[2];
                        }

                        references.Add(String.Join("/", pathParts));
                    }
                    else if (TcmUri.IsValid(path))
                    {
                        TcmUri uri = new TcmUri(path);
                        if (uri.PublicationId != TemplateId.PublicationId)
                        {
                            uri = new TcmUri(uri.ItemId, uri.ItemType, TemplateId.PublicationId);
                        }
                        references.Add(uri.ToString());
                    }
                }
            }

            return(references.ToArray());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the relative import path of an import.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public string GetRelativeImportPath(string path)
        {
            List <string> templatePathParts = WebDavUrl.Split('/').ToList();

            if (WebDavUrl.Contains(".cshtml"))
            {
                templatePathParts.RemoveAt(templatePathParts.Count - 1);
            }

            string[] pathParts = path.Split('/');

            if (pathParts.Length == 1)
            {
                // If there's no directory separator, path is in the same directory as this template.
                templatePathParts.Add(path);
            }
            else
            {
                foreach (string part in pathParts)
                {
                    if (part.Trim().Length == 0 || part.Equals("."))
                    {
                        // Ignore?
                    }
                    else if (part.Equals(".."))
                    {
                        templatePathParts.RemoveAt(templatePathParts.Count - 1);
                    }
                    else
                    {
                        templatePathParts.Add(part);
                    }
                }
            }

            return(String.Join("/", templatePathParts));
        }