Пример #1
0
        public void UpdateStyleSheetLinkPaths(IFileLocator fileLocator, string folderPath, IProgress log)
        {
            foreach (XmlElement linkNode in SafeSelectNodes("/html/head/link"))
            {
                var href = linkNode.GetAttribute("href");
                if (href == null)
                {
                    continue;
                }

                //TODO: see long comment on ProjectContextGetFileLocations() about linking to the right version of a css

                //TODO: what cause this to get encoded this way? Saw it happen when creating wall calendar
                href = href.Replace("%5C", "/");

                var fileName = FileUtils.NormalizePath(Path.GetFileName(href));
                if (!fileName.StartsWith("xx"))
                //I use xx  as a convenience to temporarily turn off stylesheets during development
                {
                    var path = fileLocator.LocateOptionalFile(fileName);

                    //we want these stylesheets to come from the book folder
                    if (string.IsNullOrEmpty(path) || path.Contains("languageDisplay.css"))
                    {
                        //look in the same directory as the book
                        var local = Path.Combine(folderPath, fileName);
                        if (File.Exists(local))
                        {
                            path = local;
                        }
                    }
                    //we want these stylesheets to come from the user's collection folder, not ones found in the templates directories
                    else if (path.Contains("CollectionStyles.css"))                     //settingsCollectionStyles & custonCollectionStyles
                    {
                        //look in the parent directory of the book
                        var pathInCollection = Path.Combine(Path.GetDirectoryName(folderPath), fileName);
                        if (File.Exists(pathInCollection))
                        {
                            path = pathInCollection;
                        }
                    }
                    if (!string.IsNullOrEmpty(path))
                    {
                        //this is here for geckofx 11... probably can remove it when we move up to modern gecko, as FF22 doesn't like it.
                        //linkNode.SetAttribute("href", "file://" + path);
                        linkNode.SetAttribute("href", path.ToLocalhost());
                    }
                    else
                    {
                        throw new ApplicationException(
                                  string.Format("Bloom could not find the stylesheet '{0}', which is used in {1}", fileName,
                                                folderPath));
                    }
                }
            }
        }
Пример #2
0
        //        /// <summary>
        //        /// Creates a relative path from one file or folder to another.
        //        /// </summary>
        //        /// <param name="fromPath">Contains the directory that defines the start of the relative path.</param>
        //        /// <param name="toPath">Contains the path that defines the endpoint of the relative path.</param>
        //        /// <param name="dontEscape">Boolean indicating whether to add uri safe escapes to the relative path</param>
        //        /// <returns>The relative path from the start directory to the end path.</returns>
        //        /// <exception cref="ArgumentNullException"></exception>
        //        public static String MakeRelativePath(String fromPath, String toPath)
        //        {
        //            if (String.IsNullOrEmpty(fromPath)) throw new ArgumentNullException("fromPath");
        //            if (String.IsNullOrEmpty(toPath)) throw new ArgumentNullException("toPath");
        //
        //            //the stuff later on needs to see directory names trailed by a "/" or "\".
        //            fromPath = fromPath.Trim();
        //            if (!fromPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
        //            {
        //                if (Directory.Exists(fromPath))
        //                {
        //                    fromPath = fromPath + Path.DirectorySeparatorChar;
        //                }
        //            }
        //            Uri fromUri = new Uri(fromPath);
        //            Uri toUri = new Uri(toPath);
        //
        //            Uri relativeUri = fromUri.MakeRelativeUri(toUri);
        //            String relativePath = Uri.UnescapeDataString(relativeUri.ToString());
        //
        //            return relativePath.Replace('/', Path.DirectorySeparatorChar);
        //        }
        private void UpdateStyleSheetLinkPaths(HtmlDom dom, IFileLocator fileLocator, IProgress log)
        {
            foreach (XmlElement linkNode in dom.SafeSelectNodes("/html/head/link"))
            {
                var href = linkNode.GetAttribute("href");
                if (href == null)
                {
                    continue;
                }

                //TODO: see long comment on ProjectContextGetFileLocations() about linking to the right version of a css

                //TODO: what cause this to get encoded this way? Saw it happen when creating wall calendar
                href = href.Replace("%5C", "/");

                var fileName = Path.GetFileName(href);
                if (!fileName.StartsWith("xx")) //I use xx  as a convenience to temporarily turn off stylesheets during development
                {
                    var path = fileLocator.LocateOptionalFile(fileName);

                    //we want these stylesheets to come from the book folder
                    if (string.IsNullOrEmpty(path)|| path.Contains("languageDisplay.css"))
                    {
                        //look in the same directory as the book
                        var local = Path.Combine(_folderPath, fileName);
                        if (File.Exists(local))
                            path = local;
                    }
                    //we want these stylesheets to come from the user's collection folder, not ones found in the templates directories
                    else if (path.Contains("CollectionStyles.css")) //settingsCollectionStyles & custonCollectionStyles
                    {
                        //look in the parent directory of the book
                        var pathInCollection = Path.Combine(Path.GetDirectoryName(_folderPath), fileName);
                        if (File.Exists(pathInCollection))
                            path = pathInCollection;
                    }
                    if (!string.IsNullOrEmpty(path))
                    {
                        //this is here for geckofx 11... probably can remove it when we move up to modern gecko, as FF22 doesn't like it.
                        linkNode.SetAttribute("href", "file://" + path);
                    }
                    else
                    {
                        throw new ApplicationException(string.Format("Bloom could not find the stylesheet '{0}', which is used in {1}", fileName, _folderPath));
                    }
                }
            }
        }