Bloom.Api.EnhancedImageServer.ProcessCssFile C# (CSharp) Method

ProcessCssFile() private method

private ProcessCssFile ( IRequestInfo info, string localPath ) : bool
info IRequestInfo
localPath string
return bool
        private bool ProcessCssFile(IRequestInfo info, string localPath)
        {
            // BL-2219: "OriginalImages" means we're generating a pdf and want full images,
            // but it has nothing to do with css files and defeats the following 'if'
            localPath = localPath.Replace("OriginalImages/", "");
            // is this request the full path to a real file?
            if (RobustFile.Exists(localPath) && Path.IsPathRooted(localPath))
            {
                // Typically this will be files in the book or collection directory, since the browser
                // is supplying the path.

                // currently this only applies to settingsCollectionStyles.css, and customCollectionStyles.css
                var cssFile = Path.GetFileName(localPath);
                if ((cssFile == "settingsCollectionStyles.css") || (cssFile == "customCollectionStyles.css"))
                {
                    info.ContentType = "text/css";
                    info.ReplyWithFileContent(localPath);
                    return true;
                }
            }

            // if not a full path, try to find the correct file
            var fileName = Path.GetFileName(localPath);

            // try to find the css file in the xmatter and templates
            if (_fileLocator == null)
            {
                _fileLocator = Program.OptimizedFileLocator;
            }
            var path = _fileLocator.LocateFile(fileName);

            // if still not found, and localPath is an actual file path, use it
            if (string.IsNullOrEmpty(path) && RobustFile.Exists(localPath)) path = localPath;

            if (string.IsNullOrEmpty(path))
            {
                // it's just possible we need to add BloomBrowserUI to the path (in the case of the AddPage dialog)
                var lastTry = FileLocator.GetFileDistributedWithApplication(true, BloomFileLocator.BrowserRoot, localPath);
                if(RobustFile.Exists(lastTry)) path = lastTry;
            }

            // return false if the file was not found
            if (string.IsNullOrEmpty(path)) return false;

            info.ContentType = "text/css";
            info.ReplyWithFileContent(path);
            return true;
        }