Beispiel #1
0
        /**************************************************************************/

        private string ProcessCssBackImageUrl(string BackgroundImageUrl)
        {
            string LinkUrlAbs     = null;
            string LinkUrlCleaned = MacroscopeUrlUtils.CleanUrlCss(BackgroundImageUrl);

            if (LinkUrlCleaned != null)
            {
                try
                {
                    LinkUrlAbs = MacroscopeUrlUtils.MakeUrlAbsolute(
                        BaseUrl: this.DocUrl,
                        Url: LinkUrlCleaned
                        );
                }
                catch (MacroscopeUriFormatException ex)
                {
                    DebugMsg(string.Format("ProcessCssBackImageUrl: {0}", ex.Message));
                }

                DebugMsg(string.Format("ProcessCssBackImageUrl: {0}", LinkUrlCleaned));
                DebugMsg(string.Format("ProcessCssBackImageUrl: this.DocUrl: {0}", this.DocUrl));
                DebugMsg(string.Format("ProcessCssBackImageUrl: LinkUrlAbs: {0}", LinkUrlAbs));
            }

            return(LinkUrlAbs);
        }
Beispiel #2
0
        public void TestMakeUrlAbsoluteUrls()
        {
            Dictionary <string, string> UrlTable = new Dictionary <string, string> ();

            UrlTable.Add(
                @"path/to/images/picture.gif",
                @"http://www.host.com/path/to/page/path/to/images/picture.gif"
                );

            UrlTable.Add(
                @"../path/to/images/picture.gif",
                @"http://www.host.com/path/to/path/to/images/picture.gif"
                );

            UrlTable.Add(
                @"../../path/to/images/picture.gif",
                @"http://www.host.com/path/path/to/images/picture.gif"
                );

            const string BaseUrl  = "http://www.host.com/path/to/page/";
            const string Filename = "index.html";
            string       Url      = string.Join("", BaseUrl, Filename);

            foreach (string RelativeUrl in UrlTable.Keys)
            {
                string sAbsoluteUrl = MacroscopeUrlUtils.MakeUrlAbsolute(Url, RelativeUrl);
                Assert.AreEqual(UrlTable[RelativeUrl], sAbsoluteUrl, "DO NOT MATCH");
            }
        }
Beispiel #3
0
        public void TestMakeUrlAbsoluteUrlsWithBaseHref()
        {
            /*
             * List Items:
             *  Base HREF
             *  Base URL
             *  Page URL
             *  Absolute URL
             */

            List <List <string> > TestList = new List <List <string> > ();

            TestList.Add(new List <string> ());
            TestList[TestList.Count - 1].Add("http://www.host.com/BASEHREF/index.html");
            TestList[TestList.Count - 1].Add("http://www.host.com/path/to/page/");
            TestList[TestList.Count - 1].Add("http://www.host.com/path/to/page/to/pages/index.html");
            TestList[TestList.Count - 1].Add("http://www.host.com/path/to/page/to/pages/index.html");

            TestList.Add(new List <string> ());
            TestList[TestList.Count - 1].Add("http://www.host.com/BASEHREF/index.html");
            TestList[TestList.Count - 1].Add("http://www.host.com/path/to/page/");
            TestList[TestList.Count - 1].Add("path/to/pages/index.html");
            TestList[TestList.Count - 1].Add("http://www.host.com/BASEHREF/path/to/pages/index.html");

            TestList.Add(new List <string> ());
            TestList[TestList.Count - 1].Add("http://www.host.com/BASEHREF/index.html");
            TestList[TestList.Count - 1].Add("http://www.host.com/path/to/page/");
            TestList[TestList.Count - 1].Add("../path/to/pages/index.html");
            TestList[TestList.Count - 1].Add("http://www.host.com/path/to/pages/index.html");

            TestList.Add(new List <string> ());
            TestList[TestList.Count - 1].Add("http://www.host.com/BASEHREF/index.html");
            TestList[TestList.Count - 1].Add("http://www.host.com/path/to/page/");
            TestList[TestList.Count - 1].Add("../../path/to/pages/index.html");
            TestList[TestList.Count - 1].Add("http://www.host.com/path/to/pages/index.html");

            foreach (List <string> UrlSet in TestList)
            {
                string BaseHref    = UrlSet[0];
                string BaseUrl     = UrlSet[1];
                string PageUrl     = UrlSet[2];
                string AbsoluteUrl = UrlSet[3];

                string ResolvedUrl;

                ResolvedUrl = MacroscopeUrlUtils.MakeUrlAbsolute(
                    BaseHref: BaseHref,
                    BaseUrl: BaseUrl,
                    Url: PageUrl
                    );

                Assert.AreEqual(AbsoluteUrl, ResolvedUrl, "DO NOT MATCH");
            }
        }
        /**************************************************************************/

        /*
         *
         * Reference: https://www.w3.org/TR/html5/document-metadata.html#the-base-element
         *
         */

        public static string MakeUrlAbsolute(
            string BaseHref,
            string BaseUrl,
            string Url
            )
        {
            string AbsoluteBaseHref;
            string UrlFixed;

            if (!string.IsNullOrEmpty(value: BaseHref))
            {
                AbsoluteBaseHref = MacroscopeUrlUtils.MakeUrlAbsolute(
                    BaseUrl: BaseUrl,
                    Url: BaseHref
                    );

                DebugMsg(string.Format("BASEHREF: {0}", BaseHref), true);
                DebugMsg(string.Format("ABSOLUTEBASEHREF: {0}", AbsoluteBaseHref), true);

                UrlFixed = MacroscopeUrlUtils.MakeUrlAbsolute(
                    BaseUrl: AbsoluteBaseHref,
                    Url: Url
                    );

                DebugMsg(string.Format("URL: {0}", Url), true);
                DebugMsg(string.Format("URLFIXED: {0}", UrlFixed), true);
            }
            else
            {
                UrlFixed = MacroscopeUrlUtils.MakeUrlAbsolute(
                    BaseUrl: BaseUrl,
                    Url: Url
                    );
            }

            return(UrlFixed);
        }