public Index GenerarIndice( int NivelMaximoIndice )
 {
     Index index = new Index();
     foreach( NodoArbol hijo in Raiz.Hijos )
         GenerarIndice( index , hijo , NivelMaximoIndice , 1 );
     return index;
 }
        public void GenerarIndice( Index index , NodoArbol nodo , int NivelMaximoIndice , int nivel )
        {
            if( NivelMaximoIndice != 0 && nivel > NivelMaximoIndice )
                return;

            index.AddNode( nodo );
            //writer.WriteLine( nodo.EntradaArbolContenidos );
            foreach( NodoArbol hijo in nodo.Hijos )
                GenerarIndice( index , /*writer ,*/ hijo , NivelMaximoIndice , nivel + 1 );
        }
        /// <summary>
        /// Generated the help web site 
        /// </summary>
        /// <param name="archivosGenerados">List of all files of the help content.</param>
        /// <param name="index">Index help information</param>
        /// <param name="cssFile">File that contains extracted CSS styles</param>
        private void GenerateWebSite( ArrayList archivosGenerados, Index index, string cssFile )
        {
            try
            {
                // Crear el directorio web y copiar archivos adicionales:
                string dirWeb;
                //if( DirectorioWeb.Equals("") )
                if (Project.WebDirectory.Equals(""))
                    dirWeb = Project.HelpProjectDirectory + Path.DirectorySeparatorChar + "web";
                else
                    dirWeb = Project.WebDirectory;
                GenerarDirDestino(dirWeb);

                // Copy the css file if was generated:
                if (cssFile != null)
                    File.Copy(cssFile, dirWeb + Path.DirectorySeparatorChar + Path.GetFileName(cssFile));

                // Check if we can copy the generated files or we must to regenerate with other header
                // Copy generated chapter files:
                //if (ArchivoCabecera.Equals(HtmlHeaderFile) && ArchivoPie.Equals(HtmlFooterFile) && !Configuration.FullTextSearch )
                if (Project.ChmHeaderFile.Equals(Project.WebHeaderFile) && Project.ChmFooterFile.Equals(Project.WebFooterFile) && !Project.FullTextSearch)
                {
                    // Copy files generated for the CHM help
                    foreach (string file in archivosGenerados)
                    {
                        string archivoDst = dirWeb + Path.DirectorySeparatorChar + Path.GetFileName(file);
                        File.Copy(file, archivoDst);
                    }
                }
                else
                {
                    // Prepare the indexing database:
                    WebIndex indexer = null;
                    try
                    {
                        if (Project.FullTextSearch)
                        {
                            indexer = new WebIndex();
                            string dbFile = dirWeb + Path.DirectorySeparatorChar + "fullsearchdb.db3";
                            string dirTextFiles = dirWeb + Path.DirectorySeparatorChar + "textFiles";
                            indexer.Connect(dbFile);
                            indexer.CreateDatabase(System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "searchdb.sql", dirTextFiles);
                            indexer.StoreConfiguration(Project.WebLanguage);
                        }

                        // Create new files for the web help:
                        GuardarDocumentos(dirWeb, HtmlHeaderCode, HtmlFooterCode, indexer);
                    }
                    finally
                    {
                        if (indexer != null)
                            indexer.Disconnect();
                    }
                }

                // Copy base files for web help:
                string keywordsMeta = "", descriptionMeta = "";
                //if( !WebKeywords.Trim().Equals( "" ) )
                if (!Project.WebKeywords.Trim().Equals(""))
                    //keywordsMeta = "<meta name=\"keywords\" content=\"" + WebKeywords + "\" >";
                    keywordsMeta = "<meta name=\"keywords\" content=\"" + Project.WebKeywords + "\" >";
                //if( !WebDescription.Trim().Equals( "" ) )
                if (!Project.WebDescription.Trim().Equals(""))
                    //descriptionMeta = "<meta name=\"description\" content=\"" + WebDescription + "\" >";
                    descriptionMeta = "<meta name=\"description\" content=\"" + Project.WebDescription + "\" >";

                // Convert title to windows-1252 enconding:
                string title = HtmlEncode(Project.HelpTitle);

                // Generate search form HTML code:
                string textSearch = "";
                if (Project.FullTextSearch)
                {
                    textSearch = "<form name=\"searchform\" method=\"post\" action=\"search.aspx\" id=\"searchform\" onsubmit=\"doFullTextSearch();return false;\" >\n";
                    textSearch += "<p><img src=\"system-search.png\" align=middle alt=\"Search image\" /> <b>%Search Text%:</b><br /><input type=\"text\" id=\"searchText\" style=\"width:80%;\" name=\"searchText\"/>\n";
                    textSearch += "<input type=\"button\" value=\"%Search%\" onclick=\"doFullTextSearch();\" id=\"Button1\" name=\"Button1\"/></p>\n";
                }
                else
                {
                    textSearch = "<form name=\"searchform\" method=\"post\" action=\"search.aspx\" id=\"searchform\" onsubmit=\"doSearch();return false;\" >\n";
                    textSearch += "<p><img src=\"system-search.png\" align=middle alt=\"Search image\" /> <b>%Search Text%:</b><br /><input type=\"text\" id=\"searchText\" style=\"width:80%;\" name=\"searchText\"/><br/>\n";
                    textSearch += "<input type=\"button\" value=\"%Search%\" onclick=\"doSearch();\" id=\"Button1\" name=\"Button1\"/></p>\n";
                    textSearch += "<select id=\"searchResult\" style=\"width:100%;\" size=\"20\" name=\"searchResult\">\n";
                    textSearch += "<option></option>\n";
                    textSearch += "</select>\n";
                }
                textSearch += "</form>\n";

                string[] variables = { "%TEXTSEARCH%" , "%TITLE%", "%TREE%", "%TOPICS%", "%FIRSTPAGECONTENT%",
                    "%WEBDESCRIPTION%", "%KEYWORDS%" , "%HEADER%" , "%FOOTER%" };
                //string[] newValues = { textSearch , title, arbol.GenerarArbolHtml(NivelMaximoTOC, "contentsTree",
                string[] newValues = { textSearch , title, tree.GenerarArbolHtml(Project.MaxHeaderContentTree, "contentsTree",
                    "contentTree"), index.GenerateWebIndex(), FirstChapterContent, descriptionMeta,
                    keywordsMeta , HtmlHeaderCode , HtmlFooterCode };
                string baseDir = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "webFiles";
                string[] extensions = { ".htm", ".html" };
                Replacements replacements = new Replacements(variables, newValues);
                string translationFile = System.Windows.Forms.Application.StartupPath +
                    Path.DirectorySeparatorChar + "webTranslations" + Path.DirectorySeparatorChar +
                    Project.WebLanguage + ".txt";
                try
                {
                    replacements.AddReplacementsFromFile(translationFile);
                }
                catch (Exception ex)
                {
                    log("Error opening web translations file" + translationFile + ": " + ex.Message, 1);
                    log(ex);
                }

                replacements.CopyDirectoryReplaced(baseDir, dirWeb, extensions, AppSettings.UseTidyOverOutput, UI);
                if (Project.FullTextSearch)
                {
                    // Copy full text serch files:
                    string[] aspxExtensions = { ".aspx" };
                    string dirSearchFiles = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "searchFiles";
                    replacements.CopyDirectoryReplaced(dirSearchFiles, dirWeb, aspxExtensions, false, UI);
                }

                if (Project.GenerateSitemap)
                    // Generate site map for web indexers (google).
                    GeneateSitemap(dirWeb);

                //return dirWeb + Path.DirectorySeparatorChar + "index.html";
            }
            catch (Exception ex)
            {
                log(ex);
            }
        }
 /// <summary>
 /// Generates the help.hs help set xml file for java help
 /// </summary>
 /// <param name="dirJavaHelp">Directory where to generate the help.hs file</param>
 /// <param name="index">Index of topics of the document</param>
 void GenerateJavaHelpSetFile(String dirJavaHelp, Index index)
 {
     StreamWriter writer = new StreamWriter( dirJavaHelp + Path.DirectorySeparatorChar + "help.hs" ,
         false, Encoding.UTF8 );
     writer.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
     writer.WriteLine("<!DOCTYPE helpset\n" +
         "PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 2.0//EN\"\n" +
         "\"http://java.sun.com/products/javahelp/helpset_2_0.dtd\">");
     writer.WriteLine("<helpset version=\"2.0\">");
     writer.WriteLine("<title>" + Project.HelpTitle + "</title>");
     writer.WriteLine("<maps><homeID>" + index.FirstTopicTarget + "</homeID><mapref location=\"map.jhm\"/></maps>");
     writer.WriteLine("<view><name>TOC</name><label>Table Of Contents</label><type>javax.help.TOCView</type><data>toc.xml</data></view>");
     writer.WriteLine("<view><name>Index</name><label>Index</label><type>javax.help.IndexView</type><data>index.xml</data></view>");
     writer.WriteLine("<view><name>Search</name><label>Search</label><type>javax.help.SearchView</type><data engine=\"com.sun.java.help.search.DefaultSearchEngine\">JavaHelpSearch</data></view>");
     writer.WriteLine("</helpset>");
     writer.Close();
 }
        /// <summary>
        /// Generates a JAR with the java help of the document.
        /// <param name="generatedFiles">List of chapter html files generated for the help</param>
        /// <param name="index">List of topics of the document.</param>
        /// <param name="cssFile">CSS file of the document, if it was generated.</param>
        /// </summary>
        private void GenerateJavaHelp(ArrayList generatedFiles, Index index, string cssFile)
        {
            // Create a temporal directy to generate the javahelp files:
            String dirJavaHelp = Path.GetTempPath() + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(MainSourceFile) + "-javahelp";
            log("Copiying files to directory " + dirJavaHelp , 2 );
            GenerarDirDestino(dirJavaHelp);

            // Copy the css file if was generated:
            if (cssFile != null)
                File.Copy(cssFile, dirJavaHelp + Path.DirectorySeparatorChar + Path.GetFileName(cssFile));

            // Copy files generated for the CHM help
            foreach (string file in generatedFiles )
            {
                string dstFile = dirJavaHelp + Path.DirectorySeparatorChar + Path.GetFileName(file);
                File.Copy(file, dstFile);
            }

            log("Generating java help xml files" , 2 );
            // Generate the java help xml files:
            GenerateJavaHelpSetFile(dirJavaHelp, index);
            index.GenerateJavaHelpIndex(dirJavaHelp + Path.DirectorySeparatorChar + "index.xml");
            index.GenerateJavaHelpMapFile(dirJavaHelp + Path.DirectorySeparatorChar + "map.jhm");
            tree.GenerateJavaHelpTOC(dirJavaHelp + Path.DirectorySeparatorChar + "toc.xml", Project.MaxHeaderContentTree);

            log("Building the search index" , 2 );
            log(AppSettings.JavaHelpIndexerPath + " .", 2 );
            ExecuteCommandLine(AppSettings.JavaHelpIndexerPath, ".", dirJavaHelp);

            // Build a JAR with the help.
            //java -jar E:\dev\java\javahelp\javahelp2.0\demos\bin\hsviewer.jar -helpset help.jar
            string commandLine = " cvf \"" + Project.JavaHelpPath + "\" .";
            string jarPath = AppSettings.JarPath;
            log("Building jar:", 2 );
            log(jarPath + " " + commandLine, 2 );
            ExecuteCommandLine(jarPath, commandLine, dirJavaHelp);

            Directory.Delete(dirJavaHelp, true);
        }
        /// <summary>
        /// Generated the help web site 
        /// </summary>
        /// <param name="archivosGenerados">List of all files of the help content.</param>
        /// <param name="index">Index help information</param>
        /// <param name="cssFile">File that contains extracted CSS styles</param>
        private void GenerateWebSite( ArrayList archivosGenerados, Index index, string cssFile )
        {
            try
            {
                // Crear el directorio web y copiar archivos adicionales:
                string dirWeb;
                //if( DirectorioWeb.Equals("") )
                if (Project.WebDirectory.Equals(""))
                    dirWeb = Project.HelpProjectDirectory + Path.DirectorySeparatorChar + "web";
                else
                    dirWeb = Project.WebDirectory;
                GenerarDirDestino(dirWeb);

                // Copy the css file if was generated:
                if (cssFile != null)
                    File.Copy(cssFile, dirWeb + Path.DirectorySeparatorChar + Path.GetFileName(cssFile));

                // Prepare the indexing database:
                WebIndex indexer = null;
                try
                {
                    if (Project.FullTextSearch)
                    {
                        indexer = new WebIndex();
                        string dbFile = dirWeb + Path.DirectorySeparatorChar + "fullsearchdb.db3";
                        string dirTextFiles = dirWeb + Path.DirectorySeparatorChar + "textFiles";
                        indexer.Connect(dbFile);
                        indexer.CreateDatabase(System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "searchdb.sql", dirTextFiles);
                        indexer.StoreConfiguration(Project.WebLanguage);
                    }

                    // Create new files for the web help:
                    GuardarDocumentos(dirWeb, webDecorator, indexer);
                }
                finally
                {
                    if (indexer != null)
                        indexer.Disconnect();
                }

                // HTML save version of the title:
                string htmlTitle = HtmlEncode(Project.HelpTitle);

                // Generate search form HTML code:
                string textSearch = "";
                if (Project.FullTextSearch)
                {
                    textSearch = "<form name=\"searchform\" method=\"post\" action=\"search.aspx\" id=\"searchform\" onsubmit=\"doFullTextSearch();return false;\" >\n";
                    textSearch += "<p><img src=\"system-search.png\" align=middle alt=\"Search image\" /> <b>%Search Text%:</b><br /><input type=\"text\" id=\"searchText\" style=\"width:80%;\" name=\"searchText\"/>\n";
                    textSearch += "<input type=\"button\" value=\"%Search%\" onclick=\"doFullTextSearch();\" id=\"Button1\" name=\"Button1\"/></p>\n";
                }
                else
                {
                    textSearch = "<form name=\"searchform\" method=\"post\" action=\"search.aspx\" id=\"searchform\" onsubmit=\"doSearch();return false;\" >\n";
                    textSearch += "<p><img src=\"system-search.png\" align=middle alt=\"Search image\" /> <b>%Search Text%:</b><br /><input type=\"text\" id=\"searchText\" style=\"width:80%;\" name=\"searchText\"/><br/>\n";
                    textSearch += "<input type=\"button\" value=\"%Search%\" onclick=\"doSearch();\" id=\"Button1\" name=\"Button1\"/></p>\n";
                    textSearch += "<select id=\"searchResult\" style=\"width:100%;\" size=\"20\" name=\"searchResult\">\n";
                    textSearch += "<option></option>\n";
                    textSearch += "</select>\n";
                }
                textSearch += "</form>\n";

                // The text placements for web files:
                string[] variables = { "%TEXTSEARCH%" , "%TITLE%", "%TREE%", "%TOPICS%", "%FIRSTPAGECONTENT%",
                    "%WEBDESCRIPTION%", "%KEYWORDS%" , "%HEADER%" , "%FOOTER%" , "%HEADINCLUDE%" };
                string[] newValues = { textSearch , htmlTitle, tree.GenerarArbolHtml(Project.MaxHeaderContentTree, "contentsTree",
                    "contentTree"), index.GenerateWebIndex(), FirstChapterContent,
                    webDecorator.MetaDescriptionTag , webDecorator.MetaKeywordsTag ,
                    webDecorator.HeaderHtmlCode , webDecorator.FooterHtmlCode , webDecorator.HeadIncludeHtmlCode };

                Replacements replacements = new Replacements(variables, newValues);

                // Load translation files.
                string translationFile = System.Windows.Forms.Application.StartupPath +
                    Path.DirectorySeparatorChar + "webTranslations" + Path.DirectorySeparatorChar +
                    Project.WebLanguage + ".txt";
                try
                {
                    replacements.AddReplacementsFromFile(translationFile);
                }
                catch (Exception ex)
                {
                    log("Error opening web translations file" + translationFile + ": " + ex.Message, ConsoleUserInterface.ERRORWARNING);
                    log(ex);
                }

                // Copy web files replacing text
                string baseDir = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "webFiles";
                replacements.CopyDirectoryReplaced(baseDir, dirWeb, MSWord.HTMLEXTENSIONS, AppSettings.UseTidyOverOutput, UI, webDecorator.OutputEncoding);

                // Copy full text search files replacing text:
                if (Project.FullTextSearch)
                {
                    // Copy full text serch files:
                    string dirSearchFiles = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "searchFiles";
                    replacements.CopyDirectoryReplaced(dirSearchFiles, dirWeb, MSWord.ASPXEXTENSIONS, false, UI, webDecorator.OutputEncoding);
                }

                if (Project.GenerateSitemap)
                    // Generate site map for web indexers (google).
                    GeneateSitemap(dirWeb);

            }
            catch (Exception ex)
            {
                log(ex);
            }
        }