package com.mindprod.stomp;
import com.mindprod.filter.ExtensionListFilter;
import com.mindprod.hunkio.HunkIO;
import java.io.File;
import java.io.IOException;
import static java.lang.System.err;
/**
* fixes syntax errors in HTML in current directory created by PADGen.
*
* Presumes F:\Program Files\PADGen\PADGen.tml has been replaced with a corrected template.
* See http://mindprod.com/jgloss/padgen.html
*
* @author Roedy Green, Canadian Mind Products
* @since 2009
* @version 1.2 2009-01-02
*/
public class FixPADGen
{
/**
* encoding of the generated html file.
*/
private static final String ENCODING = "UTF-8";
/**
* fix syntax bugs in Pad.html files, created by PadGen,
* Presumes F:\Program Files\PADGen\PADGen.tml has been replaced with a corrected template.
* See http://mindprod.com/jgloss/padgen.html
*
* @param padHTMLFile HTML pad summary file
*/
static void tidyPadHtml( final File padHTMLFile )
{
try
{
String text = HunkIO.readEntireFile( padHTMLFile, ENCODING );
boolean changed = false;
if ( text.startsWith( "<!doctype html public" ) )
{
text = "<!DOCTYPE HTML PUBLIC" + text.substring( "<!doctype html public".length() );
changed = true;
}
int place;
while ( ( place = text.indexOf( "<a class=\"offsite\" href=\"\"></a><br>" ) ) >= 0 )
{
text = text.substring( 0, place ) +
text.substring( place + "<a class=\"offsite\" href=\"\"></a><br>".length() );
changed = true;
}
if ( changed )
{
HunkIO.writeEntireFile( padHTMLFile, text, ENCODING );
}
}
catch ( IOException e )
{
err.println( "Unable to access " + padHTMLFile.toString() );
}
}
/**
* Tidy all PADGen HTML files in the current directory.
*
* @param args ignored
*/
public static void main( String[] args )
{
final File thisDir = new File( "." );
final String[] filenames = thisDir.list( new ExtensionListFilter( "html" ) );
for ( String filename : filenames )
{
tidyPadHtml( new File( thisDir, filename ) );
}
}
}