Ejemplo n.º 1
0
        private void AddApplicationBeforeDocument(int lineIndex)
        {
            // find end of tag
            int    index = lineIndex;
            string line  = _htmlPart.Lines[lineIndex];

            while (!string.IsNullOrEmpty(line) && !line.EndsWith(Mime.EndTag))
            {
                index++;
                line = _htmlPart.Lines[index];
            }

            // add before document
            line = line + XslContent.XslValueOfTag(ProntoDoc.Framework.CoreObject.FrameworkConstants.PdwApplication + "/"
                                                   + ProntoDoc.Framework.CoreObject.FrameworkConstants.PdwBeforeDocumet);

            // add multi-section
            if (_isAddSection)
            {
                line = line + XslContent.XslStartForeachTag(GetSectionPath(),
                                                            Core.MarkupConstant.XslVariableSection, Core.MarkupConstant.XslPosition);
            }

            // update line
            _htmlPart.Lines[lineIndex] = line;
        }
Ejemplo n.º 2
0
        private void UpdateImagePart(string imageFilePath, PartBookmark bookmark, string variant)
        {
            // 1. find image part
            foreach (Part imgPart in _imageParts)
            {
                if (imgPart.Content.Location.Trim().EndsWith(imageFilePath))
                {
                    // replace
                    for (int lineIndex = 0; lineIndex < imgPart.Lines.Count; lineIndex++)
                    {
                        string line = imgPart.Lines[lineIndex];
                        if (string.IsNullOrEmpty(line) || line.StartsWith(Mime.StartPart) ||
                            line.StartsWith(PartContent.ContentTransferEncoding) || line.StartsWith(PartContent.ContentType))
                        {
                            continue;
                        }

                        if (line.StartsWith(PartContent.ContentLocation))
                        {
                            int lastDotIndex = line.LastIndexOf(Mime.Dot);
                            line = line.Insert(lastDotIndex, variant);
                            imgPart.Lines[lineIndex] = line;

                            continue;
                        }

                        imgPart.RemoveLine(lineIndex);
                    }

                    // insert for-each tag
                    string startLine = string.Empty;
                    string endLine   = string.Empty;
                    if (_isAddSection)
                    {
                        startLine = XslContent.XslStartForeachTag(GetSectionPath(),
                                                                  Core.MarkupConstant.XslVariableSection, Core.MarkupConstant.XslPosition);
                        endLine = XslContent.XslFormat.XslEndForeach;
                    }

                    foreach (ForeachItem fItem in _foreach)
                    {
                        startLine = startLine + fItem.XslString;
                        endLine   = endLine + XslContent.XslFormat.XslEndForeach;
                    }

                    if (!string.IsNullOrEmpty(startLine))
                    {
                        imgPart.Lines.Insert(0, XslContent.InsertBreakLine(startLine, true));
                    }
                    imgPart.Lines.Add(bookmark.XslString);
                    if (!string.IsNullOrEmpty(endLine))
                    {
                        imgPart.Lines.Add(XslContent.InsertBreakLine(endLine, false));
                    }

                    return;
                }
            }
        }
Ejemplo n.º 3
0
        private void UpdateImageBookmark(PartBookmark bookmark)
        {
            //1. Find src=3D" attribute
            int    index = bookmark.StartLineIndex;
            string line  = _htmlPart.Lines[index];

            while (index < _htmlPart.Lines.Count && !line.Contains(Mime.SourceImage))
            {
                index++;
                line = _htmlPart.Lines[index];
            }
            if (index >= _htmlPart.Lines.Count)
            {
                return;
            }

            //2. Find end of src3D attribute (Char: '"'), last position of Dot ('.')
            int    dotLineIndex = index;
            int    dotCharIndex = line.LastIndexOf(Mime.Dot);
            string imagePath    = string.Empty;

            line = line.Substring(line.IndexOf(Mime.SourceImage) + Mime.SourceImage.Length);
            while (index < _htmlPart.Lines.Count && !string.IsNullOrEmpty(line) && !line.Contains(Mime.EndAttribute))
            {
                imagePath += line.TrimEnd(new char[] { Mime.Equal });
                index++;
                line = _htmlPart.Lines[index];

                if (line.Contains(Mime.Dot))
                {
                    dotLineIndex = index;
                    dotCharIndex = line.LastIndexOf(Mime.Dot);
                }
            }
            if (index >= _htmlPart.Lines.Count)
            {
                return;
            }

            //3. Insert xsl string and get result
            string variant = string.Empty;

            if (_foreach.Count > 0)
            {
                variant = _foreach[_foreach.Count - 1].VariantName;
            }
            if (!string.IsNullOrEmpty(variant))
            {
                variant = XslContent.XslValueOfTag(variant, false, true);
            }
            if (_isAddSection)
            {
                variant = XslContent.XslValueOfTag(Core.MarkupConstant.XslVariableSection, false) + variant;
            }
            _htmlPart.Lines[dotLineIndex] = _htmlPart.Lines[dotLineIndex].Insert(dotCharIndex, variant);
            imagePath += line.Substring(0, line.IndexOf(Mime.EndAttribute));
            UpdateImagePart(imagePath, bookmark, variant);
        }
Ejemplo n.º 4
0
        private void AddApplicationHeader(int lineIndex)
        {
            string line = _htmlPart.Lines[lineIndex];

            line = XslContent.XslValueOfTag(ProntoDoc.Framework.CoreObject.FrameworkConstants.PdwApplication + "/"
                                            + ProntoDoc.Framework.CoreObject.FrameworkConstants.PdwHeader) + line;

            _htmlPart.Lines[lineIndex] = line;
        }
Ejemplo n.º 5
0
        private string GetXslString()
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(XslContent.XslHeader());

            foreach (Part part in _parts)
            {
                builder.AppendLine(part.ToString());
            }

            builder.Append(XslContent.XslFooter());
            return(builder.ToString());
        }
Ejemplo n.º 6
0
        private void AddApplicationAfterDocument(int lineIndex)
        {
            string line = _htmlPart.Lines[lineIndex];

            // add after document
            line = XslContent.XslValueOfTag(ProntoDoc.Framework.CoreObject.FrameworkConstants.PdwApplication + "/"
                                            + ProntoDoc.Framework.CoreObject.FrameworkConstants.PdwAfterDocument) + line;

            // add multi-section
            if (_isAddSection)
            {
                line = XslContent.XslFormat.XslEndForeach + line;
            }

            // update line
            _htmlPart.Lines[lineIndex] = line;
        }
Ejemplo n.º 7
0
        private void ReplaceBookmarkTag()
        {
            _foreach = new List <ForeachItem>();
            for (int index = 0; index < _bookmarks.Count; index++)
            {
                PartBookmark  bookmark      = _bookmarks[index];
                List <string> selectedTable = GetSelectedTables(bookmark);
                Relations     relations     = GetRelations(bookmark);
                if (!bookmark.IsDelete)
                {
                    string xslPath = string.Empty;
                    switch (bookmark.Type)
                    {
                    case Core.BookmarkType.EndForeach:
                        bookmark.XslString = XslContent.XslFormat.XslEndForeach;
                        if (_foreach.Count > 0)
                        {
                            _foreach.RemoveAt(_foreach.Count - 1);
                        }
                        UpdateBookmarkPart(bookmark, index);
                        break;

                    case Core.BookmarkType.EndIf:
                        bookmark.XslString = XslContent.XslFormat.XslEndIf;
                        UpdateBookmarkPart(bookmark, index);
                        break;

                    case Core.BookmarkType.Image:
                        xslPath            = GetXslPath(bookmark, bookmark.BizName, false, selectedTable, relations);
                        bookmark.XslString = XslContent.XslValueOfTag(xslPath);
                        UpdateImageBookmark(bookmark);
                        break;

                    case Core.BookmarkType.Select:
                        xslPath            = GetXslPath(bookmark, bookmark.BizName, false, selectedTable, relations);
                        bookmark.XslString = XslContent.XslValueOfTag(xslPath,
                                                                      bookmark.BizName == ProntoDoc.Framework.CoreObject.FrameworkConstants.PdwWatermark ? false : true);
                        UpdateBookmarkPart(bookmark, index);
                        break;

                    case Core.BookmarkType.StartIf:
                        xslPath            = GetXslPath(bookmark, bookmark.BizName, true, selectedTable, relations);
                        bookmark.XslString = XslContent.XslStartIfTag(xslPath);
                        UpdateBookmarkPart(bookmark, index);
                        break;

                    case Core.BookmarkType.StartForeach:
                        int    indexForeach = _foreach.Count + 1;
                        string variant      = Core.MarkupConstant.XslVariableImage + index.ToString();
                        InternalBookmarkDomain ibmDomain = _ibm.GetInternalBookmarkDomainByItemKey(bookmark.Key);
                        ForeachItem            fItem     = new ForeachItem(index, _bookmarks.Cast <Base.BaseBookmark>(),
                                                                           relations, ibmDomain.SelectedTables, indexForeach, variant, string.Empty);
                        _foreach.Add(fItem);

                        xslPath = GetXslPath(bookmark, string.Empty, false, selectedTable, relations);
                        InternalBookmarkItem ibmItem = _ibm.GetInternalBookmarkItem(bookmark.Key);
                        string sort = GetSortXsl(bookmark.BizName, ibmItem.DomainName, selectedTable, relations, true);
                        bookmark.XslString = XslContent.XslStartForeachTag(xslPath,
                                                                           variant, Core.MarkupConstant.XslMultiPosition, sort);
                        fItem.XslString = bookmark.XslString;

                        UpdateBookmarkPart(bookmark, index);
                        break;

                    default:
                        break;
                    }
                }
            }
        }