Exemplo n.º 1
0
        public void chapter()
        {
            UsxToSFM _usxToSfm = new UsxToSFM();
            const string file = "chapter";

            string input = Common.PathCombine(_inputPath, file + ".usx");
            string output = Common.PathCombine(_outputPath, file + ".sfm");
            string expected = Common.PathCombine(_expectedPath, file + ".sfm");

            _usxToSfm.ConvertUsxToSFM(input, output);

            FileAssert.AreEqual(expected, output, file + " test fails");
        }
Exemplo n.º 2
0
        public void ExportUsxRawToUsx(List<XmlDocument> usxBooksToExport)
        {
            if (MFormat != "Go Bible")
            {
                string vrsFileDest = Common.PathCombine(MOutputLocationPath, "versification.vrs");
                string ldsFileDest = Common.PathCombine(MOutputLocationPath, "English.lds");

                string paratextProjectLocation = string.Empty;
                object paraTextprojectPath;
                if (RegistryHelperLite.RegEntryExists(RegistryHelperLite.ParatextKey,
                                                      "Settings_Directory", "", out paraTextprojectPath))
                {
                    paratextProjectLocation = (string)paraTextprojectPath;
                    paratextProjectLocation = Common.PathCombine(paratextProjectLocation, _mProjectName);
                    paratextProjectLocation = Common.PathCombine(paratextProjectLocation, "gather");

                    string vrsFileName = "eng";
                    string ldsFileName = "*"; //project file name associate file.

                    if (!Directory.Exists(paratextProjectLocation))
                    {
                        paratextProjectLocation = (string)paraTextprojectPath;
                    }
                    string ssfFileName = Common.PathCombine(paratextProjectLocation, Common.databaseName + ".ssf");
                    XmlDocument xmlDoc = Common.DeclareXMLDocument(false);
                    xmlDoc.Load(ssfFileName);
                    string xPath = "//Language";
                    XmlNode list = xmlDoc.SelectSingleNode(xPath);
                    if (list != null)
                    {
                        ldsFileName = list.InnerText;
                    }

                    if (File.Exists(Common.PathCombine(paratextProjectLocation, vrsFileName + ".vrs")))
                        File.Copy(Common.PathCombine(paratextProjectLocation, vrsFileName + ".vrs"), vrsFileDest);

                    if (File.Exists(Common.PathCombine(paratextProjectLocation, ldsFileName + ".lds")))
                        File.Copy(Common.PathCombine(paratextProjectLocation, ldsFileName + ".lds"), ldsFileDest);

                }

                MOutputLocationPath = Common.PathCombine(MOutputLocationPath, "USX");
            }
            else
            {
                MOutputLocationPath = Common.PathCombine(MOutputLocationPath, "SFM");
            }


            if (!Directory.Exists(MOutputLocationPath))
                Directory.CreateDirectory(MOutputLocationPath);

            for (int iDoc = 0; iDoc < usxBooksToExport.Count; iDoc++)
            {
                XmlDocument scrBooksDoc = usxBooksToExport[iDoc];
                string usx = scrBooksDoc.InnerXml;

                var nsmgr1 = new XmlNamespaceManager(scrBooksDoc.NameTable);
                nsmgr1.AddNamespace("style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0");
                nsmgr1.AddNamespace("fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");
                nsmgr1.AddNamespace("text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0");

                string xpath = "//book";
                string bookName = string.Empty;
                XmlNodeList list = scrBooksDoc.SelectNodes(xpath, nsmgr1);

                GetBookName(list, ref bookName);

                // Create argument list
                XsltArgumentList args = new XsltArgumentList();
                foreach (string paramName in _mXslParams.Keys)
                    args.AddParam(paramName, "", _mXslParams[paramName]);

                // Step 1. Separate books into their own elements for subsequent processing.
                StringBuilder separatedBooks = new StringBuilder();
                XmlWriter htmlw1 = XmlWriter.Create(separatedBooks, _mUsxToXhtml.OutputSettings);
                _mSeparateIntoBooks.Transform(XmlReader.Create(new StringReader(usx)), null, htmlw1, null);

                // Step 2. Remove line breaks for next step (to prevent creation of empty spans).
                StringBuilder cleanUsx = new StringBuilder();
                XmlWriter htmlw2 = XmlWriter.Create(cleanUsx, _mCleanUsx.OutputSettings);
                _mCleanUsx.Transform(XmlReader.Create(new StringReader(separatedBooks.ToString())), null, htmlw2, null);

                // Step 3. Convert the SFMs to styles recognized by Pathway. Also, change the structure of the 
                //       following elements to Pathway's format: book title, chapters, figures, footnotes.
                StringBuilder html = new StringBuilder();
                XmlWriter htmlw3 = XmlWriter.Create(html, _mUsxToXhtml.OutputSettings);
                _mUsxToXhtml.Transform(XmlReader.Create(new StringReader(cleanUsx.ToString())), args, htmlw3, null);

                cleanUsx = cleanUsx.Replace("utf-16", "utf-8");
                cleanUsx = cleanUsx.Replace("<usfm>", "<USX>");
                cleanUsx = cleanUsx.Replace("</usfm>", "</USX>");

                string bookFileName = Common.PathCombine(MOutputLocationPath, bookName + ".usx");
                XmlDocument doc = new XmlDocument();
                XmlTextWriter txtWriter = new XmlTextWriter(bookFileName, null);
                txtWriter.Formatting = Formatting.Indented;
                txtWriter.WriteRaw(cleanUsx.ToString());
                doc.Save(txtWriter);
                txtWriter.Close();

                if (MFormat == "Go Bible")
                {
                    UsxToSFM usxToSfm = new UsxToSFM();
                    string targetFile = bookFileName.Replace(".usx", ".sfm");
                    usxToSfm.ConvertUsxToSFM(bookFileName, targetFile);

                    if (File.Exists(targetFile))
                    {
                        File.Delete(bookFileName);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void btnUsx2SFM_Click(object sender, EventArgs e)
        {
            if (!File.Exists(txtInputPath.Text))
            {
                MessageBox.Show("Please enter the valid USX file");
                return;
            }

            UsxToSFM usxToSfm = new UsxToSFM();
            usxToSfm.ConvertUsxToSFM(txtInputPath.Text, Path.GetDirectoryName(txtInputPath.Text) + "\\output.sfm");
        }
Exemplo n.º 4
0
        public void para()
        {
            UsxToSFM _usxToSfm = new UsxToSFM();
            const string file = "para";

            string input = Common.PathCombine(_inputPath, file + ".usx");
            string output = Common.PathCombine(_outputPath, file + ".sfm");
            string expected = Common.PathCombine(_expectedPath, file + ".sfm");
            Common.BookNameCollection.Clear();
            Common.BookNameTag = string.Empty;

            _usxToSfm.ConvertUsxToSFM(input, output);

            TextFileAssert.AreEqual(expected, output, file + " test fails");
            Assert.AreEqual(1, Common.BookNameCollection.Count);
            Assert.AreEqual("h", Common.BookNameTag);
        }
Exemplo n.º 5
0
        public void ExportUsxRawToUsx(List <XmlDocument> usxBooksToExport)
        {
            if (MFormat != "Go Bible")
            {
                string vrsFileDest = Common.PathCombine(MOutputLocationPath, "versification.vrs");
                string ldsFileDest = Common.PathCombine(MOutputLocationPath, "English.lds");

                string paratextProjectLocation = string.Empty;
                object paraTextprojectPath;
                if (RegistryHelperLite.RegEntryExists(RegistryHelperLite.ParatextKey,
                                                      "Settings_Directory", "", out paraTextprojectPath))
                {
                    paratextProjectLocation = (string)paraTextprojectPath;
                    paratextProjectLocation = Common.PathCombine(paratextProjectLocation, _mProjectName);
                    paratextProjectLocation = Common.PathCombine(paratextProjectLocation, "gather");

                    string vrsFileName = "eng";
                    string ldsFileName = "*"; //project file name associate file.

                    if (!Directory.Exists(paratextProjectLocation))
                    {
                        paratextProjectLocation = (string)paraTextprojectPath;
                    }
                    string      ssfFileName = Common.PathCombine(paratextProjectLocation, Common.databaseName + ".ssf");
                    XmlDocument xmlDoc      = Common.DeclareXMLDocument(false);
                    xmlDoc.Load(ssfFileName);
                    string  xPath = "//Language";
                    XmlNode list  = xmlDoc.SelectSingleNode(xPath);
                    if (list != null)
                    {
                        ldsFileName = list.InnerText;
                    }

                    if (File.Exists(Common.PathCombine(paratextProjectLocation, vrsFileName + ".vrs")))
                    {
                        File.Copy(Common.PathCombine(paratextProjectLocation, vrsFileName + ".vrs"), vrsFileDest);
                    }

                    if (File.Exists(Common.PathCombine(paratextProjectLocation, ldsFileName + ".lds")))
                    {
                        File.Copy(Common.PathCombine(paratextProjectLocation, ldsFileName + ".lds"), ldsFileDest);
                    }
                }

                MOutputLocationPath = Common.PathCombine(MOutputLocationPath, "USX");
            }
            else
            {
                MOutputLocationPath = Common.PathCombine(MOutputLocationPath, "SFM");
            }


            if (!Directory.Exists(MOutputLocationPath))
            {
                Directory.CreateDirectory(MOutputLocationPath);
            }

            for (int iDoc = 0; iDoc < usxBooksToExport.Count; iDoc++)
            {
                XmlDocument scrBooksDoc = usxBooksToExport[iDoc];
                string      usx         = scrBooksDoc.InnerXml;

                var nsmgr1 = new XmlNamespaceManager(scrBooksDoc.NameTable);
                nsmgr1.AddNamespace("style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0");
                nsmgr1.AddNamespace("fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");
                nsmgr1.AddNamespace("text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0");

                string      xpath    = "//book";
                string      bookName = string.Empty;
                XmlNodeList list     = scrBooksDoc.SelectNodes(xpath, nsmgr1);

                GetBookName(list, ref bookName);

                // Create argument list
                XsltArgumentList args = new XsltArgumentList();
                foreach (string paramName in _mXslParams.Keys)
                {
                    args.AddParam(paramName, "", _mXslParams[paramName]);
                }

                // Step 1. Separate books into their own elements for subsequent processing.
                StringBuilder separatedBooks = new StringBuilder();
                XmlWriter     htmlw1         = XmlWriter.Create(separatedBooks, _mUsxToXhtml.OutputSettings);
                _mSeparateIntoBooks.Transform(XmlReader.Create(new StringReader(usx)), null, htmlw1, null);

                // Step 2. Remove line breaks for next step (to prevent creation of empty spans).
                StringBuilder cleanUsx = new StringBuilder();
                XmlWriter     htmlw2   = XmlWriter.Create(cleanUsx, _mCleanUsx.OutputSettings);
                _mCleanUsx.Transform(XmlReader.Create(new StringReader(separatedBooks.ToString())), null, htmlw2, null);

                // Step 3. Convert the SFMs to styles recognized by Pathway. Also, change the structure of the
                //       following elements to Pathway's format: book title, chapters, figures, footnotes.
                StringBuilder html   = new StringBuilder();
                XmlWriter     htmlw3 = XmlWriter.Create(html, _mUsxToXhtml.OutputSettings);
                _mUsxToXhtml.Transform(XmlReader.Create(new StringReader(cleanUsx.ToString())), args, htmlw3, null);

                cleanUsx = cleanUsx.Replace("utf-16", "utf-8");
                cleanUsx = cleanUsx.Replace("<usfm>", "<USX>");
                cleanUsx = cleanUsx.Replace("</usfm>", "</USX>");

                string        bookFileName = Common.PathCombine(MOutputLocationPath, bookName + ".usx");
                XmlDocument   doc          = new XmlDocument();
                XmlTextWriter txtWriter    = new XmlTextWriter(bookFileName, null);
                txtWriter.Formatting = Formatting.Indented;
                txtWriter.WriteRaw(cleanUsx.ToString());
                doc.Save(txtWriter);
                txtWriter.Close();

                if (MFormat == "Go Bible")
                {
                    UsxToSFM usxToSfm   = new UsxToSFM();
                    string   targetFile = bookFileName.Replace(".usx", ".sfm");
                    usxToSfm.ConvertUsxToSFM(bookFileName, targetFile);

                    if (File.Exists(targetFile))
                    {
                        File.Delete(bookFileName);
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void ExportProcess(string file)
        {
            string input = FileInput(file + ".usx");
            string output = FileOutput(file + ".usx");
            string sfmOutput = FileOutput(file + ".sfm");
            File.Copy(input, output, true);
            UsxToSFM usxToSfm = new UsxToSFM();
            usxToSfm.ConvertUsxToSFM(output, sfmOutput);

        }