コード例 #1
0
ファイル: Form1.cs プロジェクト: mwatts/haiola
        private void m_buttonOSIS_to_HTML_Click(object sender, EventArgs e)
        {
            OSIS_to_HTML converter = new OSIS_to_HTML(
                Path.Combine(m_rootDir, @"OSIS"), Path.Combine(m_rootDir, @"HTML"),
                Path.Combine(m_rootDir, @"Conc"), Path.Combine(m_rootDir, @"Sepp Options.xml"));

            converter.Run(m_filesList.CheckedItems);
        }
コード例 #2
0
        /// <summary>
        /// Run the breakdown...return null if successful, error message otherwise.
        /// </summary>
        /// <returns></returns>
        public string Run(ref string prevFile, string nextFile, OSIS_to_HTML parent)
        {
            m_parent   = parent;
            m_prevFile = m_prevMainFile = prevFile;
            if (nextFile != null)
            {
                m_nextMainFile = BuildNextFileLinkTargetName(Path.Combine(m_outputDir, nextFile));
            }
            // Read file into input
            StreamReader reader = new StreamReader(m_inputPath, Encoding.UTF8);

            m_input = reader.ReadToEnd();
            reader.Close();

            if (!GetMainElements())
            {
                return("problems parsing HTML--could not find <body> element");
            }
            BuildFootnoteMap();
            GetChapterAnchors();
            if (m_chapAnchorIndexes.Count == 0)
            {
                return("no chapters found");
            }
            if (m_parent.KeepAsSingleFile(m_inputFileName))
            {
                MakeSingleFile();
                prevFile = m_prevFile;
            }
            else
            {
                // break into chapters
                MakeChapterFiles();
                prevFile = m_prevFile;                 // Return for next book the last chaper of this (not the TOC!)
                if (m_toc != null)
                {
                    MakeTocFile();                     // Depends on info set up by MakeChapterFiles!
                }
            }
            return(null);
        }
コード例 #3
0
 public IntroRefConverter(OSIS_to_HTML parent, string baseFileName, bool hasNoChapters)
 {
     m_parent         = parent;
     m_baseFileName   = baseFileName;
     m_fHasNoChapters = hasNoChapters;
 }
コード例 #4
0
        /// <summary>
        /// Run the algorithm (on all files).
        /// </summary>
        public void Run(IList files)
        {
            Utils.EnsureDirectory(m_outputDirName);
            m_xslt.Load(Utils.GetUtilityFile("osis2ChapIndexFrag.xsl"));

            string header = "<!doctype HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n<html>\n"
                            + "<link rel=\"stylesheet\" href=\"display.css\" type=\"text/css\">"
                            + "<head>"
                            + "</head>\n<body class=\"BookChapIndex\">\n"
                            + "<p><a target=\"body\" href=\"treeMaster.htm\">" + m_options.ConcordanceLinkText + "</a></p>\n";
            string bcHeaderPath = Path.Combine(Path.GetDirectoryName(m_inputDirName), "bookChapterHeader.txt");

            if (File.Exists(bcHeaderPath))
            {
                string headerFmt = new StreamReader(bcHeaderPath, Encoding.UTF8).ReadToEnd();
                header = string.Format(headerFmt, m_options.ConcordanceLinkText);
            }
            string trailer = "</body>\n</html>\n";

            string bcFooterPath = Path.Combine(Path.GetDirectoryName(m_inputDirName), "bookChapterFooter.txt");

            if (File.Exists(bcFooterPath))
            {
                string trailerFmt = new StreamReader(bcFooterPath, Encoding.UTF8).ReadToEnd();
                trailer = string.Format(trailerFmt, m_options.ConcordanceLinkText);
            }
            string     path   = Path.Combine(m_outputDirName, "ChapterIndex.htm");
            TextWriter writer = new StreamWriter(path, false, Encoding.UTF8);

            writer.Write(header);

            Progress status = new Progress(files.Count);

            status.Show();
            int count = 0;

            foreach (string inputFile in m_options.MainFiles)
            {
                string filename = Path.GetFileName(inputFile);
                if (files.Contains(Path.ChangeExtension(filename, "xml")))
                {
                    status.File = filename;
                    string       inputFilePath = Path.Combine(m_inputDirName, inputFile);
                    MemoryStream output        = new MemoryStream();

                    TextReader inputReader = new StreamReader(inputFilePath, Encoding.UTF8);
                    XmlReader  input       = XmlReader.Create(inputReader);
                    m_xslt.Transform(input, new XsltArgumentList(), output);
                    output.Seek(0, SeekOrigin.Begin);
                    StreamReader reader   = new StreamReader(output, Encoding.UTF8);
                    string       fragment = reader.ReadToEnd();
                    string       htmlFile = Path.ChangeExtension(inputFile, "htm");
                    if (m_options.ChapterPerFile)
                    {
                        htmlFile = ChapterSplitter.BuildNextFileLinkTargetName(htmlFile);
                    }
                    fragment = fragment.Replace("$$filename$$", htmlFile);
                    fragment = fragment.Replace(" xmlns:osis=\"http://www.bibletechnologies.net/2003/OSIS/namespace\"", "");

                    // Handle introduction if any
                    string introCrossRef = "";
                    string introFile;
                    string introPath = null;
                    if (m_options.IntroFiles.TryGetValue(inputFile, out introFile))
                    {
                        introPath = Path.Combine(m_introDirName, introFile);
                        if (File.Exists(introPath))
                        {
                            File.Copy(introPath, Path.Combine(m_outputDirName, introFile), true);
                        }
                        else
                        {
                            MessageBox.Show("Introduction file not found: " + introPath, "Warning", MessageBoxButtons.OK,
                                            MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        // See if we generated one
                        introPath = Path.Combine(m_outputDirName, OSIS_to_HTML.MakeIntroFileName(filename));
                        if (File.Exists(introPath))
                        {
                            introFile = Path.GetFileName(introPath);
                        }
                        else
                        {
                            introPath = null;
                        }
                    }

                    if (introPath != null)
                    {
                        introCrossRef = "<p class=\"IndexIntroduction\"><a target=\"main\" href=\"" + introFile + "\">" +
                                        m_options.IntroductionLinkText + "</a></p>";
                    }

                    fragment = fragment.Replace("$$intro$$", introCrossRef);
                    if (m_options.ChapterPerFile)
                    {
                        fragment = FixChapterHrefs(fragment);
                    }
                    writer.WriteLine(fragment);
                    count++;
                    status.Value = count;
                }
            }
            if (m_options.ExtraFiles != null)
            {
                foreach (ExtraFileInfo efi in m_options.ExtraFiles)
                {
                    string fileName = efi.FileName;
                    string linkText = efi.HotLinkText;
                    string filePath = Path.Combine(m_extraDirName, fileName);
                    if (!File.Exists(filePath))
                    {
                        MessageBox.Show(String.Format("File {0} requested as link but not found.", filePath), "Warning");
                        continue;
                    }

                    writer.Write("<p class=\"extraLink\"><a target=\"main\" href=\""
                                 + fileName + "\">" + linkText + "</a></p>\n");
                    File.Copy(filePath, Path.Combine(m_outputDirName, fileName), true);
                }
            }
            writer.Write(trailer);
            writer.Close();

            status.Close();
        }