/// <summary>
        /// During import all master styles were moved to the text document.
        /// Now we reverse the task.
        /// </summary>
        /// <remarks>This step is necessary otherwise header and footer will be corrupted.</remarks>
        private void MoveBackMasterStyles()
        {
            XmlNamespaceManager namespaceManager = _document.NamespaceManager;
            XmlDocument         stylesDoc        = ((TextDocument)_document).DocumentStyles.Styles;
            var automaticStyles = _document.XmlDoc.SelectNodes("//office:automatic-styles/style:page-layout", namespaceManager);
            var masterStyles    = _document.XmlDoc.SelectNodes("//office:master-styles", namespaceManager);

            MasterPageFactory.MoveMasterStyles(stylesDoc, automaticStyles, masterStyles, namespaceManager);
        }
Example #2
0
 /// <summary>
 /// Load the style from assmebly resource.
 /// </summary>
 public virtual void New()
 {
     try
     {
         Assembly ass = Assembly.GetExecutingAssembly();
         Stream   str = ass.GetManifestResourceStream("AODL.Resources.OD.styles.xml");
         this.Styles = new XmlDocument();
         this.Styles.Load(str);
         MasterPageFactory.FillFromXMLDocument(this.TextDocument);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Example #3
0
        /// <summary>
        /// Create a blank new document.
        /// </summary>
        public TextDocument New()
        {
            this._xmldoc = new XmlDocument();
            this.Styles  = new StyleCollection();
            this._xmldoc.LoadXml(TextDocumentHelper.GetBlankDocument());
            this.NamespaceManager = TextDocumentHelper.NameSpace(this._xmldoc.NameTable);

            this.DocumentConfigurations2 = new DocumentConfiguration2();

            this.DocumentManifest = new DocumentManifest();
            this.DocumentManifest.New();

            this.DocumentMetadata = new DocumentMetadata(this);
            this.DocumentMetadata.New();

            this.DocumentPictures = new DocumentPictureCollection();

            this.DocumentSetting = new DocumentSetting();
            this.DocumentSetting.New();

            this.DocumentStyles = new DocumentStyles();
            this.DocumentStyles.New(this);
            this.ReadCommonStyles();

            this.Forms = new ODFFormCollection();
            this._formCollection.Clearing += FormsCollection_Clear;
            this._formCollection.Removed  += FormsCollection_Removed;

            this.Fields.Clear();
            this.Content.Clear();


            this.VariableDeclarations = new VariableDeclCollection();

            this.DocumentThumbnails = new DocumentPictureCollection();

            MasterPageFactory.RenameMasterStyles(
                this.DocumentStyles.Styles,
                this.XmlDoc, this.NamespaceManager);
            // Read the moved and renamed styles
            LocalStyleProcessor lsp = new LocalStyleProcessor(this, false);

            lsp.ReReadKnownAutomaticStyles();
            new MasterPageFactory(m_dirInfo).FillFromXMLDocument(this);
            return(this);
        }
Example #4
0
        /// <summary>
        /// Create a blank new document.
        /// </summary>
        public TextDocument New()
        {
            _xmldoc = XDocument.Parse(TextDocumentHelper.GetBlankDocument());
            Styles  = new StyleCollection();

            DocumentConfigurations2 = new DocumentConfiguration2();

            DocumentManifest = new DocumentManifest();
            DocumentManifest.New();

            DocumentMetadata = new DocumentMetadata(this);
            DocumentMetadata.New();

            DocumentPictures = new DocumentPictureCollection();

            DocumentSetting = new DocumentSetting();
            DocumentSetting.New();

            DocumentStyles = new DocumentStyles();
            DocumentStyles.New(this);
            ReadCommonStyles();

            Forms = new ODFFormCollection();
            _formCollection.Clearing += FormsCollection_Clear;
            _formCollection.Removed  += FormsCollection_Removed;

            Fields.Clear();
            Content.Clear();


            VariableDeclarations = new VariableDeclCollection();

            DocumentThumbnails = new DocumentPictureCollection();

            MasterPageFactory.RenameMasterStyles(
                DocumentStyles.Styles,
                XmlDoc);
            // Read the moved and renamed styles
            LocalStyleProcessor lsp = new LocalStyleProcessor(this, false);

            lsp.ReReadKnownAutomaticStyles();
            new MasterPageFactory().FillFromXMLDocument(this);
            return(this);
        }
Example #5
0
        /// <summary>
        /// Reads the content.
        /// </summary>
        private void ReadContent()
        {
            /*
             * NOTICE:
             * Do not change this order!
             */

            // 1. load content file
            this._document.XmlDoc = new XmlDocument();
            this._document.XmlDoc.Load(Path.Combine(m_dirInfo.Dir, "content.xml"));

            // 2. Read local styles
            LocalStyleProcessor lsp = new LocalStyleProcessor(this._document, false);

            lsp.ReadStyles();

            // 3. Import common styles and read common styles
            this.ImportCommonStyles();
            lsp = new LocalStyleProcessor(this._document, true);
            lsp.ReadStyles();

            if (_document is TextDocument)
            {
                FormsProcessor fp = new FormsProcessor(this._document);
                fp.ReadFormNodes();

                TextDocument td = _document as TextDocument;
                td.VariableDeclarations.Clear();

                XmlNode nodeText = td.XmlDoc.SelectSingleNode(
                    TextDocumentHelper.OfficeTextPath, td.NamespaceManager);
                if (nodeText != null)
                {
                    XmlNode nodeVarDecls = nodeText.SelectSingleNode("text:variable-decls", td.NamespaceManager);
                    if (nodeVarDecls != null)
                    {
                        foreach (XmlNode vd in nodeVarDecls.CloneNode(true).SelectNodes("text:variable-decl", td.NamespaceManager))
                        {
                            td.VariableDeclarations.Add(new VariableDecl(td, vd));
                        }
                        nodeVarDecls.InnerXml = "";
                    }
                }
            }

            // 4. Register warnig events
            MainContentProcessor mcp = new MainContentProcessor(this._document);

            mcp.Warning += mcp_OnWarning;

            // 5. Read the content
            mcp.ReadContentNodes();

            // 6.1 load master pages and styles for TextDocument
            if (this._document is TextDocument)
            {
                MasterPageFactory.RenameMasterStyles(
                    ((TextDocument)this._document).DocumentStyles.Styles,
                    this._document.XmlDoc, this._document.NamespaceManager);
                // Read the moved and renamed styles
                lsp = new LocalStyleProcessor(this._document, false);
                lsp.ReReadKnownAutomaticStyles();
                new MasterPageFactory(m_dirInfo).FillFromXMLDocument(this._document as TextDocument);
            }
        }
        /// <summary>
        /// Reads the content.
        /// </summary>
        private void ReadContent()
        {
            /*
             * NOTICE:
             * Do not change this order!
             */

            // 1. load content file
            using (TextReader reader = new StreamReader(_packageReader.Open("content.xml")))
            {
                _document.XmlDoc = XDocument.Load(reader);
            }

            // 2. Read local styles
            LocalStyleProcessor lsp = new LocalStyleProcessor(_document, false);

            lsp.ReadStyles();

            // 3. Import common styles and read common styles
            ImportCommonStyles();
            lsp = new LocalStyleProcessor(_document, true);
            lsp.ReadStyles();

            if (_document is TextDocument)
            {
                FormsProcessor fp = new FormsProcessor(_document);
                fp.ReadFormNodes();

                TextDocument td = _document as TextDocument;
                td.VariableDeclarations.Clear();

                XElement nodeText =
                    td.XmlDoc.Elements(Ns.Office + "document-content")
                    .Elements(Ns.Office + "body")
                    .Elements(Ns.Office + "text").FirstOrDefault();
                if (nodeText != null)
                {
                    XElement nodeVarDecls = nodeText.Element(Ns.Text + "variable-decls");
                    if (nodeVarDecls != null)
                    {
                        foreach (XElement vd in new XElement(nodeVarDecls).Elements(Ns.Text + "variable-decl"))
                        {
                            td.VariableDeclarations.Add(new VariableDecl(td, vd));
                        }
                        nodeVarDecls.Value = "";
                    }
                }
            }

            // 4. Register warnig events
            MainContentProcessor mcp = new MainContentProcessor(_document);

            mcp.Warning += mcp_OnWarning;

            // 5. Read the content
            mcp.ReadContentNodes();

            // 6.1 load master pages and styles for TextDocument
            if (_document is TextDocument)
            {
                MasterPageFactory.RenameMasterStyles(
                    ((TextDocument)_document).DocumentStyles.Styles,
                    _document.XmlDoc);
                // Read the moved and renamed styles
                lsp = new LocalStyleProcessor(_document, false);
                lsp.ReReadKnownAutomaticStyles();
                new MasterPageFactory().FillFromXMLDocument(_document as TextDocument);
            }
        }