/* * [Repair.java] * * Summary: Repair Miscellaneous blockquotes problems in Mindprod website. * * Copyright: (c) 2008-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: * 1.0 2008-06-08 initial version * 1.1 2009-01-04 add SortQuotes */ package com.mindprod.repair; import com.mindprod.commandline.CommandLine; import com.mindprod.filter.AllButSVNDirectoriesFilter; import com.mindprod.filter.ExtensionListFilter; import com.mindprod.hunkio.HunkIO; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; import static java.lang.System.*; /** * Repair Miscellaneous blockquotes problems in Mindprod website. * * @author Roedy Green, Canadian Mind Products * @version 1.1 2009-01-04 add SortQuotes * @since 2008 */ public class Repair { private static final int FIRST_COPYRIGHT_YEAR = 2008; /** * what we look for surrounding text of interest */ private static final String CLOSE_TAG = ""; /** * undisplayed copyright notice */ @SuppressWarnings( { "UnusedDeclaration" } ) private static final String EMBEDDED_COPYRIGHT = "Copyright: (c) 2008-2017 Roedy Green, Canadian Mind Products, http://mindprod.com"; /** * what we look for surrounding text of interest */ private static final String OPEN_TAG = "(.+) * * @return tidied up blockquote */ private static String processDoneBlockQuote( String rawBlockQuote ) { final Matcher m = DONE.matcher( rawBlockQuote ); if ( m.matches() && m.groupCount() == 1 ) { // if was already done. out.println( "ok: " + m.group( 1 ) ); return rawBlockQuote; } else { out.print( "." ); // add marker to let us know in needs to be fixed. return rawBlockQuote + ""; } } @SuppressWarnings( { "ResultOfMethodCallIgnored" } ) public static void main( String[] args ) { // get files to process from command line. out.println( "Gathering html files to repair non-standard
s..." ); CommandLine wantedFiles = new CommandLine( args, new AllButSVNDirectoriesFilter(), new ExtensionListFilter( "html" ) ); for ( File fileBeingProcessed : wantedFiles ) { try { final String big = HunkIO.readEntireFile( fileBeingProcessed ); final StringBuilder modified = new StringBuilder( big.length() + 100 ); int start0 = 0; int start1; while ( ( start1 = big.indexOf( OPEN_TAG, start0 ) ) >= 0 ) { final int start2 = start1 + OPEN_TAG.length(); final int end1 = big.indexOf( CLOSE_TAG, start2 ); if ( end1 < 0 ) { throw new IllegalArgumentException( " missing
" ); } final int end2 = end1 + CLOSE_TAG.length(); final String rawBlockQuote = big.substring( start1, end2 ); // process text
final String modifiedBlockQuote = processDoneBlockQuote( rawBlockQuote ); // copy text prior to
modified.append( big.substring( start0 ) ); final String modifiedBig = modified.toString(); if ( !modifiedBig.equals( big ) ) { final File tempFile = HunkIO.createTempFile( "temp_", ".tmp", fileBeingProcessed ); FileWriter emit = new FileWriter( tempFile ); emit.write( modifiedBig ); emit.close(); // successfully created output in same directory as input, HunkIO.deleteAndRename( tempFile, fileBeingProcessed ); } } catch ( IOException e ) { e.printStackTrace( err ); err.println(); } } // end for to process each file out.println( "done" ); } }