/*
* [RebuildIndexShells.java]
*
* Summary: Rebuild skeletons of all indexes in case they are ever damaged.
*
* Copyright: (c) 2007-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
*
* Licence: This software may be copied and used freely for any purpose but military.
* http://mindprod.com/contact/nonmil.html
*
* Requires: JDK 1.8+
*
* Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
*
* Version History:
* 2.2 2007-04-27 use enum for each embellishment letter. use CSS for single icons.
*/
package com.mindprod.qf;
import com.mindprod.fastcat.FastCat;
import com.mindprod.htmlmacros.macro.Global;
import com.mindprod.htmlmacros.support.ConfigurationForMindprod;
import com.mindprod.hunkio.HunkIO;
import java.io.File;
import java.io.IOException;
import static java.lang.System.*;
/**
* Rebuild skeletons of all indexes in case they are ever damaged.
*
* @author Roedy Green, Canadian Mind Products
* @version 2.2 2007-04-27 use enum for each embellishment letter. use CSS for single icons.
* @since 2007
*/
public final class RebuildIndexShells
{
/**
* what to use for
*/
private static final String BR;
/**
* root directory of website
*/
private static final String webrootDirname;
static
{
// combine dirsWithMacros and dirsWithIncludes into dirsToProcess;
Global.installConfiguration( new ConfigurationForMindprod() );
webrootDirname = Global.configuration.getLocalWebrootWithSlashes();
BR = Global.configuration.getBr();
}
// methods
/**
* connvert a filename to a webroot relative filename
*
* @param f absolute name of file
*
* @return webroot relative name of file
*/
private static String absToPath( String f )
{
// chop lead E:/mindprod/
return f.substring( webrootDirname.length() + 1 /* to account for trail / */ );
}// /method
/**
* generate one Bgloss letter index shell, no guts
*
* @param letterCode which letter of alphabet to create index for
*
* @throws IOException if trouble writing out the index
*/
private static void createBglossIndexShell( char letterCode ) throws IOException
{
createIndexShell( letterCode, new BglossCustomiser() );
}// /method
/**
* generate one Ggloss letter index shell, no guts
*
* @param letterCode which letter of alphabet to create index for
*
* @throws IOException if trouble writing the index file
*/
private static void createGglossIndexShell( char letterCode ) throws IOException
{
createIndexShell( letterCode, new GglossCustomiser() );
}// /method
private static void createIndexShell( char letterCode, AbstractGlossCustomiser c ) throws IOException
{
final File file = new File( c.getInputDirName(), c.getFilenameForLetterCode( letterCode ) );
final char signatureLetter = c.getGlossEnum().getSignatureLetter();
final String base = c.getBaseName();
final FastCat sb = new FastCat( 15 );
sb.append( "\n" );
if ( letterCode == '~' )
{
// only for master index, on page index. JGlossLetterHad provides second menu for off page index.
// for ordinary index pages, letter menu provided by JglossLetterHead macro.
sb.append( "\n" );
}
sb.append( "\n" );
sb.append( "\n" );
HunkIO.writeEntireFile( file, sb.toString() );
}// /method
/**
* generate one Jgloss letter index shell, no guts
*
* @param letterCode which letter of alphabet to create index for
*
* @throws IOException if trouble writing the index
*/
private static void createJglossIndexShell( char letterCode ) throws IOException
{
createIndexShell( letterCode, new JglossCustomiser() );
}// /method
/**
* create the letter menu for a glossary
*/
private static void createLetterMenu( String glossary ) throws IOException
{
final FastCat sb = new FastCat( 12 );
sb.append( "page index ⇒" );
sb.append( "" );
sb.append(
"punctuation 0-9 A B "
);
sb.append(
"C D E F G "
);
sb.append(
"H I J K L "
);
sb.append(
"M N O P Q "
);
sb.append(
"R S T U V "
);
sb.append( "W X Y Z" );
sb.append( BR );
sb.append( "The following index is sorted alphabetically in columns, like a phone book." );
final File file = new File( webrootDirname + "/" + glossary + "/include/" + glossary + "/lettermenu.htmlfrag" );
HunkIO.writeEntireFile( file, sb.toString() );
}// /method
/**
* @param args not used
*
* @throws IOException if trouble writing the shells.
*/
public static void main( String[] args ) throws IOException
{
// does not fix egloss or lgloss. must do that manually.
out.println( "regenerating index shells, e.g. " + webrootDirname + "/jgloss/a.html" );
out.println( webrootDirname + "/jgloss/include/jgloss/a.guts.htmlfrag generated later by gf." );
// do master indexes
createBglossIndexShell( '~' );
createGglossIndexShell( '~' );
createJglossIndexShell( '~' );
// lgloss just gets master index uses lgloss.html, not a true master
// index.
// do punctuation
createBglossIndexShell( '*' );
createGglossIndexShell( '*' );
createJglossIndexShell( '*' );
// do digits, one page for 0-9
createBglossIndexShell( '0' );
createGglossIndexShell( '0' );
createJglossIndexShell( '0' );
// do A-Z
for ( char letter = 'A'; letter <= 'Z'; letter++ )
{
createBglossIndexShell( letter );
createGglossIndexShell( letter );
createJglossIndexShell( letter );
}
createLetterMenu( "jgloss" );
createLetterMenu( "bgloss" );
createLetterMenu( "ggloss" );
out.println( "done" );
}// /method
// /methods
}