Manages the bidirectional conversion.(Web to Word and Word to Web)
 public WebImageAdaptorFilter(ConversionManager manager)
 {
     this.manager = manager;
     serverURL = manager.States.ServerURL;
     localFolder = manager.States.LocalFolder;
     localFilename = manager.States.LocalFileName;
 }
 /// <summary>
 /// Default constructor.
 /// </summary>
 public WebMacrosAdaptorFilterTest()
 {
     manager = ConversionManagerTestUtil.DummyConversionManager();
     initialHTML = "";
     expectedHTML = "";
     initialXmlDoc = new XmlDocument();
 }
 /// <summary>
 /// Default constructor.
 /// </summary>
 public OfficeAttributesRemoverFilterTest()
 {
     manager = ConversionManagerTestUtil.DummyConversionManager();
     initialHTML = "";
     expectedHTML = "";
     initialXmlDoc = new XmlDocument();
     expectedXmlDoc = new XmlDocument();
 }
 /// <summary>
 /// Default constructor.
 /// </summary>
 public LocalToWebStyleFilterTest()
 {
     manager = ConversionManagerTestUtil.DummyConversionManager();
     initialHTML = "";
     expectedHTML = "";
     initialXmlDoc = new XmlDocument();
     expectedXmlDoc = new XmlDocument();
 }
 /// <summary>
 /// Default constructor.
 /// </summary>
 public GrammarAndSpellingErrorsFilterTest()
 {
     manager = ConversionManagerTestUtil.DummyConversionManager();
     initialHTML = "";
     cleanedHTML = "";
     initialXmlDoc = new XmlDocument();
     cleanedXmlDoc=new XmlDocument();
 }
 public GrammarAndSpellingErrorsFilter(ConversionManager manager)
 {
     this.manager = manager;
 }
 public ParentDivAttributeRemoverFilter(ConversionManager manager)
 {
     this.manager = manager;
 }
 public LocalToWebStyleFilter(ConversionManager manager)
 {
     this.manager = manager;
     this.cssClasses = new Hashtable();
     this.counter = 0;
 }
Пример #9
0
 /// <summary>
 /// Creates a new instance of the WebToLocalHTML class.
 /// </summary>
 /// <param name="manager">The instance of the bidirectional conversion manager.</param>
 public WebToLocalHTML(ConversionManager manager)
 {
     this.manager = manager;
 }
Пример #10
0
        /// <summary>
        /// Starts editing a new wiki page. The page will not be created in the wiki until the fisrt save.
        /// </summary>
        /// <param name="spaceName">The name of the wiki space.</param>
        /// <param name="pageName">The name of page.</param>
        /// <param name="pageTitle">The title of the page.</param>
        /// <param name="sender">
        /// The instance of the form that started the action.
        /// This form need to be closed before swithing the Active Word Document.
        /// </param>
        public void AddNewPage(string spaceName, string pageName, string pageTitle, Form sender)
        {
            //Any modal dialog nust be closed before opening or closing active documents.
            if (sender != null)
            {
                //hide the form before closing to prevent reactivation and focus request.
                sender.Hide();
                sender.Close();
                Application.DoEvents();
            }
            try
            {
                if (!this.Client.LoggedIn)
                {
                    Client.Login(addin.Username, addin.Password);
                }
                String pageFullName = spaceName + "." + pageName;
                String localFileName = pageFullName.Replace(".", "-");
                String folder = addin.PagesRepository + "TempPages";
                new FolderAttributesCleaner(folder).Perform();
                //content = new WebToLocalHTML(addin.serverURL, folder, localFileName).AdaptSource(content);
                ConversionManager pageConverter = new ConversionManager(addin.ServerURL, folder, pageFullName, localFileName, addin.Client);
                localFileName = folder + "\\" + localFileName + ".html";
                addin.CurrentLocalFilePath = localFileName;
                //Save the file
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
                String pageContent = "<h1>" + pageTitle + "</h1>" + Environment.NewLine;
                pageContent = pageContent + newPageText;
                FileStream stream = new FileStream(localFileName, FileMode.Create);
                //byte[] buffer = UTF8Encoding.UTF8.GetBytes(pageContent.ToString());
                Encoding iso = Client.ServerEncoding;
                byte[] buffer = iso.GetBytes(pageContent);
                stream.Write(buffer, 0, buffer.Length);
                stream.Close();
                addin.CurrentPageFullName = pageFullName;
                //Since it's a new page, it's not published
                addin.CurrentPagePublished = false;
                addin.PublishedStatus.Add(pageFullName, false);

                addin.EditedPages.Add(localFileName, pageFullName);

                //Open the file with Word
                HTMLDocumentOpener htmlDocOpener = new HTMLDocumentOpener(addin, localFileName);
                htmlDocOpener.Perform();
                Word.Document doc = htmlDocOpener.GetResults();
                doc.Activate();
                newDoc = doc;

                //If it's a new space, add it to the wiki structure and mark it as unpublished
                List<Space> spaces = Globals.XWord2003AddIn.Wiki.spaces;
                Space space = null;
                foreach (Space sp in spaces)
                {
                    if (sp.name == spaceName)
                    {
                        space = sp;

                        //Add the new page to the wiki structure and mark it as unpublished
                        XWikiDocument xwdoc = new XWikiDocument();
                        xwdoc.name = pageName;
                        xwdoc.published = false;
                        xwdoc.space = spaceName;
                        space.documents.Add(xwdoc);
                        break;
                    }
                }

                if (space == null)
                {
                    space = new Space();
                    space.name = spaceName;
                    space.published = false;
                    Globals.XWord2003AddIn.Wiki.spaces.Add(space);

                    //Add the new page to the wiki structure and mark it as unpublished
                    XWikiDocument xwdoc = new XWikiDocument();
                    xwdoc.name = pageName;
                    xwdoc.published = false;
                    xwdoc.space = spaceName;
                    space.documents.Add(xwdoc);
                }
            }
            catch (IOException ex)
            {
                UserNotifier.Error(ex.Message);
            }
        }
 public LocalMacrosAdaptorFilter(ConversionManager manager)
 {
     this.manager = manager;
 }
 public EmptyNestedElementsFilter(ConversionManager manager)
 {
     this.manager = manager;
 }
Пример #13
0
        /// <summary>
        /// Edits a wiki page.
        /// </summary>
        /// <param name="_pageFullName">The full name of the wiki page that is being opened for editing.</param>
        private void GetPage(Object _pageFullName)
        {
            try
            {
                if (!this.Client.LoggedIn)
                {
                    Client.Login(addin.username, addin.password);
                }
                String pageFullName = (String)_pageFullName;
                //Read from server
                String content = Client.GetRenderedPageContent(pageFullName);

                //TODO: Add versioniong info to the xmlrpc Page model
                IndexPageHistory(pageFullName);

                String localFileName = pageFullName.Replace(".", "-");
                String folder = addin.AddinSettings.PagesRepository + "TempPages";
                ConvertToNormalFolder(folder);
                //content = new WebToLocalHTML(addin.serverURL, folder, localFileName).AdaptSource(content);
                ConversionManager pageConverter;
                if (pageConverters.ContainsKey(pageFullName))
                {
                    pageConverter = pageConverters[pageFullName];
                }
                else
                {
                    pageConverter = new ConversionManager(addin.AddinSettings, addin.serverURL, folder, pageFullName, localFileName, addin.Client);
                    pageConverters.Add(pageFullName, pageConverter);
                }
                content = pageConverter.ConvertFromWebToWord(content);
                localFileName = folder + "\\" + localFileName + ".html";
                addin.currentLocalFilePath = localFileName;
                StringBuilder pageContent = new StringBuilder(content);
                //Process the content
                pageContent.Insert(0, startDocument);
                pageContent.Append(endDocument);
                //Save the file
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }

                StreamWriter writer = new StreamWriter(localFileName, false, Encoding.UTF8);
                writer.Write(pageContent.ToString());
                writer.Close();

                #region OpenLocalDocument
                //Register new local filename as a wiki page.
                addin.EditedPages.Add(localFileName, pageFullName);
                addin.currentPageFullName = pageFullName;
                //Open the file with Word
                Word.Document doc = OpenHTMLDocument(localFileName);
                #endregion//Open local document

                //Mark just-opened document as saved. This prevents a silly confirmation box that
                //warns about unsaved changes when closing an unchanged document.
                doc.Saved = true;

                //The opened doc becomes the newest doc used for window reactivation.
                newDoc = doc;
                if (addin.ActiveDocumentInstance != doc)
                {
                    doc.Activate();
                }
            }
            catch (IOException ex)
            {
                UserNotifier.Error(ex.Message);
            }
        }
Пример #14
0
 public LocalToWebHTML(ConversionManager manager)
 {
     this.manager = manager;
 }
 public StyleRemoverFilter(ConversionManager manager)
 {
     this.manager = manager;
 }
 public OfficeAttributesRemoverFilter(ConversionManager manager)
 {
     this.manager = manager;
 }
Пример #17
0
        /// <summary>
        /// Builds a <code>SSXManager</code> for a remote wiki page.
        /// </summary>
        /// <param name="pageConverter">An instance of the <code>ConversionManager</code> for this page.</param>
        /// <returns>An instance of a <code>SSXManager</code>.</returns>
        public static SSXManager BuildFromServerPage(ConversionManager pageConverter)
        {
            SSXManager ssxManager = new SSXManager();
            ssxManager.pageFullName = pageConverter.States.PageFullName;
            ssxManager.pageConverter = pageConverter;

            List<XWikiObject> ssxObjects = ssxManager.RetrieveStyleSheetExtensions();

            ssxManager.pageStyleSheetExtensions = ssxObjects;
            StringBuilder sb = new StringBuilder();
            foreach (XWikiObject ssxObject in ssxObjects)
            {
                sb.Append(ssxObject.objectDictionary["code"]);
                sb.Append(Environment.NewLine);
            }
            ssxManager.pageCSSContent = sb.ToString();

            return ssxManager;
        }
Пример #18
0
        /// <summary>
        /// Creates a <code>SSXManager</code> from the cleaned HTML of a local editing page.
        /// </summary>
        /// <param name="pageConverter">An instance of the <code>ConversionManager</code> for this page.</param>
        /// <param name="cleanHTML">Cleaned HTML of the local page.</param>
        /// <returns>An instance of a <code>SSXManager</code>.</returns>
        public static SSXManager BuildFromLocalHTML(ConversionManager pageConverter, string cleanHTML)
        {
            SSXManager ssxManager = new SSXManager();
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(cleanHTML);
            XmlNodeList styleNodes = xmlDoc.GetElementsByTagName("style");
            string pageCSSContent = "";

            foreach (XmlNode styleNode in styleNodes)
            {
                pageCSSContent += styleNode.InnerText;
            }

            XmlRpcStruct dictionary = new XmlRpcStruct();
            dictionary.Add("code", pageCSSContent);
            dictionary.Add("name", "XOfficeStyle");
            dictionary.Add("use", "currentPage");
            dictionary.Add("parse", "0");
            dictionary.Add("cache", "forbid");

            XWikiObject ssxObject = new XWikiObject();
            ssxObject.className = SSX_CLASS_NAME;
            ssxObject.pageId = pageConverter.States.PageFullName;
            ssxObject.objectDictionary = dictionary;

            ssxManager.pageFullName = pageConverter.States.PageFullName;
            ssxManager.pageCSSContent = pageCSSContent;
            ssxManager.pageStyleSheetExtensions = new List<XWikiObject>();
            ssxManager.pageStyleSheetExtensions.Add(ssxObject);
            ssxManager.pageConverter = pageConverter;
            return ssxManager;
        }
Пример #19
0
 public LocalToWebHTML(ConversionManager manager)
 {
     this.manager = manager;
 }
Пример #20
0
        /// <summary>
        /// Retrieves a page from the wiki and save it locally in order to be merged to the active document.
        /// </summary>
        /// <param name="pageFullName">The full name of the wiki page.</param>
        /// <param name="localFileName">String reference to the file path of the created document.</param>
        private void OpenForMerge(String pageFullName, out String localFileName)
        {
            String content = Client.GetRenderedPageContent(pageFullName);
            String suffix = "__LATEST";
            String folder = addin.AddinSettings.PagesRepository + "TempPages";

            localFileName = pageFullName.Replace(".", "-") + suffix;
            ConvertToNormalFolder(folder);
            ConversionManager pageConverter;
            //TODO: The converter info should be merged.
            pageConverter = new ConversionManager(addin.AddinSettings, addin.serverURL, folder, pageFullName, localFileName, addin.Client);
            //pageConverters.Add(pageFullName + suffix, pageConverter);

            content = pageConverter.ConvertFromWebToWord(content);
            localFileName = folder + "\\" + localFileName + ".html";
            addin.currentLocalFilePath = localFileName;
            StringBuilder pageContent = new StringBuilder(content);
            //Process the content
            pageContent.Insert(0, startDocument);
            pageContent.Append(endDocument);
            //Save the file
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            StreamWriter writer = new StreamWriter(localFileName, false, Encoding.UTF8);
            writer.Write(pageContent.ToString());
            writer.Close();
        }
 public LocalImageAdaptorFilter(ConversionManager manager)
 {
     this.manager = manager;
 }
 public WebListsAdaptorFilter(ConversionManager manager)
 {
     this.manager = manager;
 }
Пример #23
0
 /// <summary>
 /// Creates a new instance of the WebToLocalHTML class.
 /// </summary>
 /// <param name="manager">The instance of the bidirectional conversion manager.</param>
 public WebToLocalHTML(ConversionManager manager)
 {
     this.manager = manager;
 }
 public WebToLocalStyleFilter(ConversionManager manager)
 {
     this.manager = manager;
 }
Пример #25
0
        /// <summary>
        /// Saves the currently edited page or document to the server.
        /// </summary>
        private void SaveToXWiki()
        {
            try
            {
                String contentFilePath = "";
                addin.ReinforceApplicationOptions();
                String filePath = addin.ActiveDocumentFullName;
                String currentFileName = Path.GetDirectoryName(addin.ActiveDocumentFullName);
                currentFileName += "\\" + Path.GetFileNameWithoutExtension(addin.ActiveDocumentFullName);
                String tempExportFileName = currentFileName + "_TempExport.html";
                if (!ShadowCopyDocument(addin.ActiveDocumentInstance, tempExportFileName, addin.SaveFormat))
                {
                    UserNotifier.Error(UIMessages.ERROR_SAVING_PAGE);
                    return;
                }
                contentFilePath = tempExportFileName;
                StreamReader sr = new StreamReader(contentFilePath);
                String fileContent = sr.ReadToEnd();
                sr.Close();
                File.Delete(contentFilePath);
                String cleanHTML = "";

                cleanHTML = new CommentsRemover().Clean(fileContent);
                cleanHTML = new HeadSectionRemover().Clean(cleanHTML);

                ConversionManager pageConverter;
                if (pageConverters.ContainsKey(addin.CurrentPageFullName))
                {
                    pageConverter = pageConverters[addin.CurrentPageFullName];
                }
                else
                {
                    pageConverter = new ConversionManager(addin.ServerURL, Path.GetDirectoryName(contentFilePath),
                                                          addin.CurrentPageFullName, Path.GetFileName(contentFilePath), addin.Client);
                }
                cleanHTML = pageConverter.ConvertFromWordToWeb(cleanHTML);
                cleanHTML = new BodyContentExtractor().Clean(cleanHTML);

                if (addin.AddinStatus.Syntax == null)
                {
                    addin.AddinStatus.Syntax = addin.DefaultSyntax;
                }

                //Convert the source to the propper encoding.
                Encoding iso = Client.ServerEncoding;
                byte[] content = Encoding.Unicode.GetBytes(cleanHTML);
                byte[] wikiContent = null;
                wikiContent = Encoding.Convert(Encoding.Unicode, iso, content);
                cleanHTML = iso.GetString(wikiContent);
                SavePage(addin.CurrentPageFullName, ref cleanHTML, addin.AddinStatus.Syntax);
            }
            catch (COMException ex)
            {
                string message = "An internal Word error appeared when trying to save your file.";
                message += Environment.NewLine + ex.Message;
                Log.Exception(ex);
                UserNotifier.Error(message);
            }
        }
 /// <summary>
 /// Default constructor.
 /// </summary>
 public LocalImageAdaptorFilterTest()
 {
     manager = ConversionManagerTestUtil.DummyConversionManager();
     initialHTML = "";
     initialXmlDoc = new XmlDocument();
 }
Пример #27
0
        /// <summary>
        /// Saves the currently edited page or document to the server.
        /// </summary>
        private void SaveToXwiki()
        {
            try
            {
                addin.AnnotationMaintainer.ClearComments();
                String contentFilePath = "";
                addin.ReinforceApplicationOptions();
                String filePath = addin.ActiveDocumentFullName;
                String currentFileName = Path.GetDirectoryName(addin.ActiveDocumentFullName);
                currentFileName += "\\" + Path.GetFileNameWithoutExtension(addin.ActiveDocumentFullName);
                String tempExportFileName = currentFileName + "_TempExport.html";
                if (!ShadowCopyDocument(addin.ActiveDocumentInstance, tempExportFileName, addin.SaveFormat))
                {
                    ReportSaveProblem();
                    return;
                }
                contentFilePath = tempExportFileName;
                StreamReader sr = new StreamReader(contentFilePath, Client.ServerEncoding);
                String fileContent = sr.ReadToEnd();
                sr.Close();
                File.Delete(contentFilePath);
                String cleanHTML = "";

                cleanHTML = new CommentsRemover().Clean(fileContent);
                cleanHTML = new HeadSectionRemover().Clean(cleanHTML);

                ConversionManager pageConverter;
                if (pageConverters.ContainsKey(addin.currentPageFullName))
                {
                    pageConverter = pageConverters[addin.currentPageFullName];
                }
                else
                {
                    pageConverter = new ConversionManager(addin.AddinSettings, addin.serverURL, Path.GetDirectoryName(contentFilePath),
                                                          addin.currentPageFullName, Path.GetFileName(contentFilePath), addin.Client);
                }
                cleanHTML = pageConverter.ConvertFromWordToWeb(cleanHTML);

                SSXManager ssxManager = SSXManager.BuildFromLocalHTML(pageConverter, cleanHTML);

                cleanHTML = new BodyContentExtractor().Clean(cleanHTML);

                //openHTMLDocument(addin.currentLocalFilePath);
                if (addin.AddinStatus.Syntax == null)
                {
                    addin.AddinStatus.Syntax = addin.DefaultSyntax;
                }

                if (SavePage(addin.currentPageFullName, ref cleanHTML, addin.AddinStatus.Syntax))
                {
                    ssxManager.UploadStyleSheetExtensions();
                    pageConverter.UploadAttachments();
                    addin.AnnotationMaintainer.UpdateAnnotations();
                }
            }
            catch (COMException ex)
            {
                string message = "An internal Word error appeared when trying to save your file.";
                message += Environment.NewLine + ex.Message;
                Log.Exception(ex);
                UserNotifier.Error(message);
            }
        }
 public EmptySpanRemoverFilter(ConversionManager manager)
 {
     this.manager = manager;
 }