public IElement CreateElement(string elementType, string props)
        {
            var      propArray = props.Split(';');
            IElement element;

            //determine element type
            switch (elementType)
            {
            case "Image":
                element = new HtmlImage(propArray[0], propArray[1], propArray[2]);
                return(element);

            case "Header":
                element = new HtmlHeader(propArray[0], propArray[1]);
                return(element);

            case "List":
                element = new HtmlList(propArray[0], propArray[1], propArray[2], propArray[3]);
                return(element);

            case "Table":
                element = new HtmlTable(propArray[0], propArray[1], propArray[2], propArray[3]);
                return(element);

            default:
                return(null);
            }
        }
Exemple #2
0
        public static List <string> GetReferenceStyleUrl(Document doc, HtmlHeader header)
        {
            List <string> UrlList = Service.DomUrlService.GetReferenceStyles(doc);

            if (header != null)
            {
                UrlList.AddRange(header.Styles);
            }
            return(UrlList);
        }
        public static HtmlHeader HeaderSet()
        {
            HtmlHeader Header = new HtmlHeader();

            Header.ContentString = HtmlBuilder.
                                   Program.ReadString("Enter Header you want to add");

            Header.SizeOfString = Convert.
                                  ToInt32(HtmlBuilder.Program.ReadString("Enter Size of heading"));

            return(Header);
        }
Exemple #4
0
        private static void WriteStyleScript(HtmlHeader header, Document dom, List <SourceUpdate> updates, ref string appendChanges)
        {
            var currentstylescript = GetScriptStyle(dom);

            foreach (var item in currentstylescript)
            {
                if (item.IsScript)
                {
                    if (header.Scripts.Contains(item.Url))
                    {
                        header.Scripts.Remove(item.Url);
                    }
                    else
                    {
                        /// remove it...
                        updates.Add(new SourceUpdate()
                        {
                            StartIndex = item.Element.location.openTokenStartIndex, EndIndex = item.Element.location.endTokenEndIndex, NewValue = null
                        });
                    }
                }
                else if (item.IsStyle)
                {
                    if (header.Styles.Contains(item.Url))
                    {
                        header.Styles.Remove(item.Url);
                    }
                    else
                    {
                        /// remove it.
                        updates.Add(new SourceUpdate()
                        {
                            StartIndex = item.Element.location.openTokenStartIndex, EndIndex = item.Element.location.endTokenEndIndex, NewValue = null
                        });
                    }
                }
            }

            foreach (var item in header.Scripts)
            {
                string tag = $"<script src=\"{ item}\"></script>";
                appendChanges += tag;
            }
            foreach (var item in header.Styles)
            {
                string tag = $"<link rel=\"stylesheet\" href=\"{item}\" />";
                appendChanges += tag;
            }
        }
Exemple #5
0
        public void Check_If_Html_Header_Returns_Correct_Html()
        {
            //arrange
            HtmlHeader head = new HtmlHeader();

            head.SizeOfString  = 1;
            head.ContentString = "header";

            //act
            string genHtml      = head.GetHtmlString();
            string expectedHtml = "<h1>header</h1>";

            //assert
            Assert.AreEqual(expectedHtml, genHtml);
        }
Exemple #6
0
        internal static List <SourceUpdate> GetUpdates(HtmlHeader header, Document dom, string OnlyEnableCulture)
        {
            List <SourceUpdate> result;

            if (DomService.HasHeadTag(dom))
            {
                result = GetUpdateWithDomHeader(header, dom, OnlyEnableCulture);
            }
            else
            {
                result = GetUpdateWithOutDomHeader(header, dom, OnlyEnableCulture);
            }


            return(result);
        }
        private static void Testing()
        {
            HtmlImage img = new HtmlImage();

            img.ImageSrc = "https://en.wikipedia.org/wiki/File:C_Sharp_wordmark.svg";
            img.Alt      = "Logo";

            HtmlPara pr = new HtmlPara();

            pr.Text = "My paragraph";

            HtmlLink lnk = new HtmlLink();

            lnk.LinkSrc  = "https://in.yahoo.com/";
            lnk.LinkText = "Yahooo!!";

            HtmlHeader head = new HtmlHeader();

            head.ContentString = "Heading";
            head.SizeOfString  = 1;

            HtmlTable table = new HtmlTable();

            table.Rows    = 3;
            table.Columns = 3;

            try
            {
                table.FillData("A", "B", "C", "D", "E", "F");
            }
            catch (Exception iie)
            {
                P(iie.Message.ToString());
            }
            HtmlPage page = new HtmlPage();

            page.Title     = "My fabulous page";
            page.BodyColor = "yellow";
            page.Elements.Add(head);
            page.Elements.Add(img);
            page.Elements.Add(pr);
            page.Elements.Add(lnk);
            page.Elements.Add(table);

            var html = page.GetPageHtml();
        }
Exemple #8
0
        public static string SetHeaderToHtml(string htmlsource, HtmlHeader header, string OnlyEnableCulture = null)
        {
            if (!header.HasValue())
            {
                return(htmlsource);
            }
            var dom = Kooboo.Dom.DomParser.CreateDom(htmlsource);

            string result = string.Empty;

            List <SourceUpdate> updates = GetUpdates(header, dom, OnlyEnableCulture);

            if (updates.Count > 0)
            {
                return(Service.DomService.UpdateSource(htmlsource, updates));
            }
            else
            {
                return(htmlsource);
            }
        }
Exemple #9
0
        private static void AppendScriptStyle(Document dom, HtmlHeader header)
        {
            var resources = GetScriptStyle(dom);

            foreach (var item in resources)
            {
                if (item.IsScript)
                {
                    if (!header.Scripts.Contains(item.Url))
                    {
                        header.Scripts.Add(item.Url);
                    }
                }
                else if (item.IsStyle)
                {
                    if (!header.Styles.Contains(item.Url))
                    {
                        header.Styles.Add(item.Url);
                    }
                }
            }
        }
Exemple #10
0
        internal static List <SourceUpdate> GetUpdateWithOutDomHeader(HtmlHeader header, Document dom, string OnlyEnableCulture)
        {
            List <SourceUpdate> updates = new List <SourceUpdate>();

            string appendChanges = string.Empty;

            var titlevalue = GetOnlyOrDefault(header.Titles, OnlyEnableCulture);

            if (!string.IsNullOrEmpty(titlevalue))
            {
                appendChanges += $"<Title>{titlevalue}</Title>";
            }


            foreach (var item in header.Metas)
            {
                var checkresult = MetaCheck(item, OnlyEnableCulture);

                if (checkresult.ShouldAppendToDom)
                {
                    appendChanges = appendChanges + "\r\n" + GenerateMetaTag(item, checkresult.ContentValue);
                }
            }

            WriteStyleScript(header, dom, updates, ref appendChanges);

            if (!string.IsNullOrEmpty(appendChanges))
            {
                appendChanges = "<head>\r\n" + appendChanges + "\r\n</head>";
                var afterHtmlLocation = dom.documentElement.location.openTokenEndIndex + 1;

                updates.Add(new SourceUpdate()
                {
                    StartIndex = afterHtmlLocation, EndIndex = -1, NewValue = appendChanges
                });
            }
            return(updates);
        }
Exemple #11
0
        //extract header information from html source...
        public static HtmlHeader AppendSourceToHeader(string htmlsource, HtmlHeader currentHeader)
        {
            var dom = Dom.DomParser.CreateDom(htmlsource);

            string htmltitle = GetTitle(dom);

            var currenttitle = currentHeader.GetTitle();

            if (string.IsNullOrEmpty(currenttitle))
            {
                currentHeader.SetTitle(htmltitle);
            }

            var metas = dom.head.getElementsByTagName("meta");

            foreach (var item in metas.item)
            {
                AppendMeta(item, currentHeader.Metas);
            }

            AppendScriptStyle(dom, currentHeader);

            return(currentHeader);
        }
Exemple #12
0
        public static void Compute(SiteObjectEvent SiteEvent)
        {
            if (SiteEvent == null || SiteEvent.Value == null)
            {
                return;
            }

            if (SiteEvent.Value is Style)
            {
                ComputeStyle(SiteEvent);
                return;
            }

            if (SiteEvent.Value is IDataMethodSetting)
            {
                if (SiteEvent.ChangeType == ChangeType.Delete)
                {
                    DataMethodRelation.Clean(SiteEvent.SiteDb, SiteEvent.Value.Id);
                }
                else
                {
                    DataMethodRelation.Compute(SiteEvent.Value as IDataMethodSetting, SiteEvent.SiteDb);
                }
            }

            if (SiteEvent.Value is ResourceGroup)
            {
                if (SiteEvent.ChangeType == ChangeType.Delete)
                {
                    SiteEvent.SiteDb.Relations.CleanObjectRelation(SiteEvent.Value.Id);
                }
                else
                {
                    GroupRelation.Compute(SiteEvent.Value as ResourceGroup, SiteEvent.SiteDb);
                }
            }

            Type ModelType = SiteEvent.Value.GetType();

            //only below needs to compute relation.
            if (SiteEvent.Value is IDomObject || ModelType == typeof(CmsCssRule))
            {
                string     basurl = null;
                HtmlHeader header = null;
                Document   Dom    = null;


                if (Attributes.AttributeHelper.IsRoutable(ModelType))
                {
                    basurl = Service.ObjectService.GetObjectRelativeUrl(SiteEvent.SiteDb, SiteEvent.Value.Id, SiteEvent.Value.ConstType);
                }

                if (ModelType == typeof(Page))
                {
                    var page = SiteEvent.Value as Page;
                    header = page.Headers;
                }

                if (!ShouldCheck(ModelType, SiteEvent))
                {
                    return;
                }

                Dom = GetDom(ModelType, SiteEvent);

                if (SiteEvent.ChangeType == ChangeType.Delete)
                {
                    var siteobject = SiteEvent.Value as SiteObject;
                    if (siteobject != null)
                    {
                        RelationManager.Clean(SiteEvent.SiteDb, siteobject);
                    }
                }
                else
                {
                    if (Dom != null || SiteEvent.Value is IDomObject)
                    {
                        DomRelation.Compute(SiteEvent.SiteDb, Dom, SiteEvent.Value.Id, SiteEvent.Value.ConstType, basurl, header);
                    }
                }
            }
        }
Exemple #13
0
        internal static List <SourceUpdate> GetUpdateWithDomHeader(HtmlHeader header, Document dom, string OnlyEnableCulture)
        {
            List <SourceUpdate> updates = new List <SourceUpdate>();

            string appendChanges = string.Empty;

            var titlevalue = GetOnlyOrDefault(header.Titles, OnlyEnableCulture);

            if (!string.IsNullOrEmpty(titlevalue))
            {
                var    titletag    = DomService.GetTitleElement(dom);
                string newtitletag = $"<Title>{titlevalue}</Title>\r\n";
                if (titletag == null)
                {
                    appendChanges += newtitletag;
                }
                else
                {
                    if (titletag.InnerHtml != titlevalue)
                    {
                        updates.Add(new SourceUpdate()
                        {
                            StartIndex = titletag.location.openTokenStartIndex, EndIndex = titletag.location.endTokenEndIndex, NewValue = newtitletag
                        });
                    }
                }
            }

            foreach (var item in header.Metas)
            {
                var checkresult = MetaCheck(item, OnlyEnableCulture);

                var sametags = GetSameMetaTags(dom, item);

                string metatag = GenerateMetaTag(item, checkresult.ContentValue);

                if (sametags != null && sametags.Count() > 0)
                {
                    var tag = sametags[0];
                    if (!IsSameMeta(tag, item, checkresult.ContentValue))
                    {
                        updates.Add(new SourceUpdate()
                        {
                            StartIndex = tag.location.openTokenStartIndex, EndIndex = tag.location.endTokenEndIndex, NewValue = metatag
                        });
                    }

                    if (sametags.Count() > 1)
                    {
                        int len = sametags.Count();
                        for (int i = 1; i < len; i++)
                        {
                            updates.Add(new SourceUpdate()
                            {
                                StartIndex = sametags[i].location.openTokenStartIndex, EndIndex = sametags[i].location.endTokenEndIndex, NewValue = null
                            });
                        }
                    }
                }
                else
                {
                    appendChanges += metatag;
                }
            }

            WriteStyleScript(header, dom, updates, ref appendChanges);

            if (!string.IsNullOrEmpty(appendChanges))
            {
                var afterheaderlocation = dom.head.location.openTokenEndIndex + 1;

                updates.Add(new SourceUpdate()
                {
                    StartIndex = afterheaderlocation, EndIndex = -1, NewValue = appendChanges
                });
            }
            return(updates);
        }
Exemple #14
0
        public static List <string> ComputeReferenceScript(Document doc, SiteDb sitedb, Guid objectId, byte constType, string baseUrl = "", HtmlHeader header = null)
        {
            List <string> UrlList = Service.DomUrlService.GetReferenceScripts(doc);

            if (header != null)
            {
                UrlList.AddRange(header.Scripts);
            }
            DomUrlService.MakeAllUrlRelative(UrlList, baseUrl);

            List <string> scripturls = new List <string>();
            List <string> groupurls  = new List <string>();

            foreach (var item in UrlList)
            {
                if (Kooboo.Sites.Service.GroupService.IsGroupUrl(item))
                {
                    groupurls.Add(item);
                }
                else
                {
                    scripturls.Add(item);
                }
            }

            ComputeUrlRelation(sitedb, objectId, constType, scripturls, ConstObjectType.Script);

            return(groupurls);
        }
Exemple #15
0
        public static void Compute(SiteDb SiteDb, Document dom, Guid OwnerObjectId, byte OwnerConstType, string baseUrl = "", HtmlHeader header = null)
        {
            List <string> ResourceGroupUrl = ComputeReferenceStyle(dom, SiteDb, OwnerObjectId, OwnerConstType, baseUrl, header);

            var scriptgroup = ComputeReferenceScript(dom, SiteDb, OwnerObjectId, OwnerConstType, baseUrl, header);

            ResourceGroupUrl.AddRange(scriptgroup);

            ComputeUrlRelation(SiteDb, OwnerObjectId, OwnerConstType, ResourceGroupUrl, ConstObjectType.ResourceGroup);

            if (dom != null)
            {
                if (!string.IsNullOrEmpty(baseUrl))
                {
                    dom.URL = baseUrl;
                }
                ComputeImage(dom, SiteDb, OwnerObjectId, OwnerConstType, baseUrl);

                ComputeEmbeddedStyle(dom, SiteDb, OwnerObjectId, OwnerConstType);

                ComputeEmbeddedForms(dom, SiteDb, OwnerObjectId, OwnerConstType);

                ComputeEmbeddedScript(dom, SiteDb, OwnerObjectId, OwnerConstType);

                ComputeEmbeddedKKScript(dom, SiteDb, OwnerObjectId, OwnerConstType);

                ComputeInlineCss(dom, SiteDb, OwnerObjectId, OwnerConstType, baseUrl);

                ComputeEmbededImage(dom, SiteDb, OwnerObjectId, OwnerConstType);

                ComputeLinks(dom, SiteDb, OwnerObjectId, OwnerConstType);

                computeLabel(dom, SiteDb, OwnerObjectId, OwnerConstType);

                computekConfig(dom, SiteDb, OwnerObjectId, OwnerConstType);

                ComputeComponent(dom, SiteDb, OwnerObjectId, OwnerConstType);

                computeLayout(dom, SiteDb, OwnerObjectId, OwnerConstType);
            }
        }