Example #1
0
        private void ParseLoadedContent(HTMLLinkType type, string content, string path, PDFContextBase context)
        {
            switch (type)
            {
            case (HTMLLinkType.CSS):
                StyleCollection col = this.CreateInnerStyles(content, context);
                this._content = new LinkContentCSS(col, path);
                break;

            case (HTMLLinkType.Html):

                Dictionary <string, string> ns = new Dictionary <string, string>();
                foreach (var map in this.Document.NamespaceDeclarations)
                {
                    ns.Add(map.Prefix, map.NamespaceURI);
                }
                Scryber.Data.ParsableTemplateGenerator gen = new Data.ParsableTemplateGenerator(content, ns);
                this._content = new LinkContentHtml(gen, path);
                break;

            default:
                if (context.Conformance == ParserConformanceMode.Strict)
                {
                    throw new System.IO.FileLoadException("The link with href " + this.Href + " could not be loaded from path '" + path + "' as it does not have a known rel type - stylesheet or include");
                }
                else
                {
                    context.TraceLog.Add(TraceLevel.Error, "HTML", "The link with href " + this.Href + " could not be loaded from path '" + path + "'  as it does not have a known rel type - stylesheet or include");
                }

                break;
            }
        }
Example #2
0
 protected void ClearInnerContent()
 {
     if (null != this._content)
     {
         this._content.ClearContent(this.Document);
         this._content = null;
     }
 }
Example #3
0
        protected virtual void DoLoadReference(PDFContextBase context)
        {
            if (String.IsNullOrEmpty(this.Href))
            {
                if (context.TraceLog.ShouldLog(TraceLevel.Verbose))
                {
                    context.TraceLog.Add(TraceLevel.Verbose, "HTML", "No href value on the html link tag " + this.UniqueID);
                }
                return;
            }

            if (null == this.Document)
            {
                return;
            }

            if (this.IsContentLoaded)
            {
                return;
            }

            HTMLLinkType type;

            if (this.ShouldAddContent(context.OutputFormat, out type) == false)
            {
                if (context.TraceLog.ShouldLog(TraceLevel.Verbose))
                {
                    context.TraceLog.Add(TraceLevel.Verbose, "HTML", "Link " + this.UniqueID + " is not a stylesheet or include, or print reference (@rel), so ignoring");
                }
                return;
            }

            bool   isFile;
            string content = string.Empty;

            var path = this.MapPath(this.Href, out isFile);

            if (context.TraceLog.ShouldLog(TraceLevel.Verbose))
            {
                context.TraceLog.Add(TraceLevel.Verbose, "HTML", "href for link " + this.UniqueID + " mapped to path '" + path + "'");
            }

            if (!isFile && Uri.IsWellFormedUriString(path, UriKind.Absolute))
            {
                using (var measure = context.PerformanceMonitor.Record(PerformanceMonitorType.Parse_Files, path))
                {
                    if (context.TraceLog.ShouldLog(TraceLevel.Verbose))
                    {
                        context.TraceLog.Add(TraceLevel.Message, "HTML", "Initiating the load of remote href file " + path + " for link " + this.UniqueID);
                    }

                    content = DoLoadRemoteReference(path, context);

                    if (context.TraceLog.ShouldLog(TraceLevel.Verbose))
                    {
                        context.TraceLog.Add(TraceLevel.Message, "HTML", "Completed the load of remote href file " + path + " for link " + this.UniqueID);
                    }

                    else if (context.TraceLog.ShouldLog(TraceLevel.Message))
                    {
                        context.TraceLog.Add(TraceLevel.Message, "HTML", "Loaded remote href file " + path + " for link " + this.UniqueID);
                    }
                }
            }
            else if (isFile && System.IO.File.Exists(path))
            {
                using (var measure = context.PerformanceMonitor.Record(PerformanceMonitorType.Parse_Files, path))
                {
                    if (context.TraceLog.ShouldLog(TraceLevel.Message))
                    {
                        context.TraceLog.Add(TraceLevel.Message, "HTML", "Initiating the load of local href file " + path + " for link " + this.UniqueID);
                    }


                    content = System.IO.File.ReadAllText(path);

                    if (context.TraceLog.ShouldLog(TraceLevel.Verbose))
                    {
                        context.TraceLog.Add(TraceLevel.Message, "HTML", "Completed the load of local file " + path + " for link " + this.UniqueID);
                    }

                    else if (context.TraceLog.ShouldLog(TraceLevel.Message))
                    {
                        context.TraceLog.Add(TraceLevel.Message, "HTML", "Loaded local file " + path + " for link " + this.UniqueID);
                    }
                }
            }
            else if (context.Conformance == ParserConformanceMode.Strict)
            {
                throw new System.IO.FileLoadException("The link with href " + this.Href + " could not be loaded from path '" + path + "'");
            }
            else
            {
                context.TraceLog.Add(TraceLevel.Error, "HTML", "The link with href " + this.Href + " could not be loaded from path '" + path + "'");
            }

            switch (type)
            {
            case (HTMLLinkType.CSS):
                StyleCollection col = this.CreateInnerStyles(content, context);
                this._content = new LinkContentCSS(col, path);
                break;

            case (HTMLLinkType.Html):

                Dictionary <string, string> ns = new Dictionary <string, string>();
                foreach (var map in this.Document.NamespaceDeclarations)
                {
                    ns.Add(map.Prefix, map.NamespaceURI);
                }
                Scryber.Data.ParsableTemplateGenerator gen = new Data.ParsableTemplateGenerator(content, ns);
                this._content = new LinkContentHtml(gen, path);
                break;

            default:
                if (context.Conformance == ParserConformanceMode.Strict)
                {
                    throw new System.IO.FileLoadException("The link with href " + this.Href + " could not be loaded from path '" + path + "' as it does not have a known rel type - stylesheet or include");
                }
                else
                {
                    context.TraceLog.Add(TraceLevel.Error, "HTML", "The link with href " + this.Href + " could not be loaded from path '" + path + "'  as it does not have a known rel type - stylesheet or include");
                }

                break;
            }
        }