Exemple #1
0
        private string GetXslPath(PartBookmark bookmark, bool isIf = false, string bizName = null, Relations relations = null)
        {
            List <string> tables = GetSelectedTables(bookmark);

            relations = relations ?? GetRelations(bookmark);

            bizName = bizName == null ? bookmark.BizName : bizName;

            string path = GetXslPath(bookmark, bizName, isIf, tables, relations);

            return(path);
        }
Exemple #2
0
        private PartBookmark ParseToPartBookmark(IHTMLElement htmlElement)
        {
            PartBookmark bookmark = null;

            IHTMLAnchorElement anchor = htmlElement as IHTMLAnchorElement;

            if (anchor != null && !string.IsNullOrEmpty(anchor.name))
            {
                bookmark = new PartBookmark(anchor.name, _ibm);
            }

            return(bookmark);
        }
Exemple #3
0
        private void ProcessStartForeachBookmark(PartBookmark bookmark, ref Relations relations)
        {
            int index        = _bookmarks.FindIndex(b => b.Key.Equals(bookmark.Key, System.StringComparison.OrdinalIgnoreCase));
            int foreachIndex = _foreach.Count + 1;

            //TODO:CHECK
            string variant = Core.MarkupConstant.XslVariableImage + index.ToString();

            InternalBookmarkDomain ibmDomain = _ibm.GetInternalBookmarkDomainByItemKey(bookmark.Key);

            relations = GetRelations(bookmark);

            ForeachItem foreachItem = new ForeachItem(index, _bookmarks, relations, ibmDomain.SelectedTables, foreachIndex, variant, string.Empty);

            _foreach.Add(foreachItem);
        }
Exemple #4
0
        private string GenerateXslForBookmark(PartBookmark bookmark)
        {
            string result  = null;
            string bizName = null;

            if (!bookmark.IsDelete)
            {
                bool      isIf      = bookmark.Type == BookmarkType.StartIf;
                Relations relations = null;

                switch (bookmark.Type)
                {
                case BookmarkType.StartForeach:
                    ProcessStartForeachBookmark(bookmark, ref relations);
                    bizName = string.Empty;
                    goto case BookmarkType.Select;

                case BookmarkType.StartIf:
                case BookmarkType.Select:
                case BookmarkType.Image:
                case BookmarkType.PdeTag:
                case BookmarkType.PdeChart:
                    string path = GetXslPath(bookmark, isIf, bizName);
                    result = string.Format(bookmark.XslString, path);
                    break;

                case BookmarkType.EndForeach:
                    if (_foreach.Count > 0)
                    {
                        _foreach.RemoveAt(_foreach.Count - 1);
                    }
                    goto case BookmarkType.EndIf;

                case BookmarkType.EndIf:
                    result = bookmark.XslString;
                    break;

                default:
                    break;
                }
            }

            return(result);
        }
Exemple #5
0
        private bool IsRedundantSpaceNode(IHTMLDOMNode node)
        {
            bool result = false;

            if (node.nodeType == 3 && string.IsNullOrWhiteSpace(node.nodeValue))
            {
                IHTMLDOMNode sibling = node.nextSibling;

                if (sibling != null && sibling is IHTMLAnchorElement)
                {
                    PartBookmark bookmark = ParseToPartBookmark(sibling as IHTMLElement);

                    if (bookmark != null && bookmark.IsControlBookmark)
                    {
                        result = true;
                    }
                }
            }

            return(result);
        }
Exemple #6
0
        private void MatchingControlBookmarks(Stack <KeyValuePair <IHTMLDOMNode, PartBookmark> > controlMarkupStack, IHTMLDOMNode htmlNode)
        {
            IHTMLElement2          htmlElement = htmlNode as IHTMLElement2;
            IHTMLElementCollection anchors     = htmlElement.getElementsByTagName("A");

            foreach (IHTMLElement anchor in anchors)
            {
                PartBookmark bookmark = ParseToPartBookmark(anchor);

                if (bookmark != null && bookmark.IsControlBookmark)
                {
                    IHTMLDOMNode node = anchor as IHTMLDOMNode;

                    if (controlMarkupStack.Count == 0)
                    {
                        controlMarkupStack.Push(new KeyValuePair <IHTMLDOMNode, PartBookmark>(node, bookmark));
                    }
                    else
                    {
                        KeyValuePair <IHTMLDOMNode, PartBookmark> previous = controlMarkupStack.Peek();

                        bool isMatch = (previous.Value.Type == BookmarkType.StartForeach && bookmark.Type == BookmarkType.EndForeach) ||
                                       (previous.Value.Type == BookmarkType.StartIf && bookmark.Type == BookmarkType.EndIf);

                        isMatch = isMatch && previous.Key.parentNode == node.parentNode;

                        if (isMatch)
                        {
                            controlMarkupStack.Pop();
                        }
                        else
                        {
                            controlMarkupStack.Push(new KeyValuePair <IHTMLDOMNode, PartBookmark>(node, bookmark));
                        }
                    }
                }
            }
        }
Exemple #7
0
        private string GetXslPath(string bookmarkName)
        {
            PartBookmark bookmark = new PartBookmark(bookmarkName, _ibm);

            return(GetXslPath(bookmark, false));
        }
Exemple #8
0
        private string GenerateXslForBookmark(string bookmarkName)
        {
            PartBookmark bookmark = new PartBookmark(bookmarkName, _ibm);

            return(GenerateXslForBookmark(bookmark));
        }
Exemple #9
0
        private void CreateHtmlTemplate(XmlWriter writer, IHTMLDOMNode htmlNode, IEnumerable <ControlBase> formControls, bool analyseParagraph = true)
        {
            //Element
            if (htmlNode.nodeType == 1)
            {
#if DEBUG
                if (analyseParagraph)
                {
                    Debug.WriteLine(string.Format("Current HTML Node:{0}.", htmlNode.nodeName));
                }
                else
                {
                    Debug.WriteLine(string.Format("Current HTML Element:{0}, analysed.", htmlNode.nodeName));
                }
#endif
                if (htmlNode is IHTMLParaElement && analyseParagraph)
                {
                    ProcessParagraphTag(writer, htmlNode, formControls);

                    return;
                }

                if (htmlNode is IHTMLObjectElement)
                {
                    IHTMLElement objElement = htmlNode as IHTMLElement;

                    ControlBase formControl = formControls.Single(c => c.ObjectId.Is(objElement.id));

                    SetDataBindingsForControl(formControl);

                    //Write control template
                    formControl.WriteToXslTemplate(writer);

                    return;
                }

                if (htmlNode is IHTMLAnchorElement)
                {
                    PartBookmark bookmark = ParseToPartBookmark(htmlNode as IHTMLElement);

                    if (bookmark != null)
                    {
                        string result = GenerateXslForBookmark(bookmark);

                        writer.WriteRaw(result);

                        return;
                    }
                }

                if (htmlNode is IHTMLImgElement)
                {
                    IHTMLImgElement image = htmlNode as IHTMLImgElement;

                    if (!string.IsNullOrEmpty(image.src))
                    {
                        string[] tempArray = image.src.Split(':');

                        string src = tempArray.Length == 2 ? tempArray[1] : image.src;

                        src = string.Format(@"{0}\{1}", Path.GetDirectoryName(_htmlFileName), src.Replace('/', '\\'));

                        image.src = GetBase64ImageSrc(src);
                    }
                }

                WriteStartHTMLElement(writer, htmlNode);

                if (htmlNode is IHTMLBodyElement)
                {
                    writer.WriteStartHtmlFormElement(Form_Method, Form_Action);

                    writer.WriteXslHtmlHiddenElement(Hidden_Url_Name, Hidden_Url_Value);
                    writer.WriteXslHtmlHiddenElement(Hidden_Object_Name, Hidden_Object_Value);
                }

                if (htmlNode is IHTMLStyleElement)
                {
                    IHTMLElement element = htmlNode as IHTMLElement;
                    writer.WriteString(element.innerHTML);
                    writer.WriteString(WartermarkStyle);
                }

                //Other tags
                foreach (IHTMLDOMNode child in htmlNode.childNodes)
                {
                    CreateHtmlTemplate(writer, child, formControls);
                }

                WriteEndHTMLElement(writer, htmlNode);
            }
            else
            {
                //Text or something else

                Debug.WriteLine(string.Format("Current HTML Node:{0}.", htmlNode.nodeName));

                //Text
                if (htmlNode.nodeType == 3)
                {
                    if (!IsRedundantSpaceNode(htmlNode))
                    {
                        writer.WriteString(htmlNode.nodeValue);
                    }
                }
            }
        }