/* * [FormatForAspSites.java] * * Summary: format CSV info on asp PADs to html. * * Copyright: (c) 2016-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 2016-05-22 initial version */ package com.mindprod.submitter; import com.mindprod.common18.BigDate; import com.mindprod.common18.EIO; import com.mindprod.common18.ST; import com.mindprod.csv.CSVReader; import com.mindprod.entities.DeEntifyStrings; import com.mindprod.entities.EntifyStrings; import com.mindprod.fastcat.FastCat; import java.io.EOFException; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import static java.lang.System.*; /** * format CSV info on asp PADs to html. *

* Use to prepare mindprod.com HTML versions of hassle, no-hassle or candidate pad submission sites. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2016-05-22 initial version * @since 2016-05-22 */ public class FormatForAspSites { private static final String USAGE = "\nFormatForAspSites.exe"; private static final String DO_NOT_EDIT = "\n"; private static void appendLongURL( final String url, final FastCat sb ) { if ( ST.isEmpty( url ) ) { sb.append( "\n" ); } else { // trim a very long submissionURL sb.append( "" ); if ( url.length() > 60 ) { String t = DeEntifyStrings.deEntifyHTML( url, ' ' ); t = t.substring( 0, 50 ); t = EntifyStrings.entifyHTML( t ); sb.append( t, "…" ); } else { sb.append( url ); } sb.append( "\n" ); } } private static void appendStatus( final String status, final FastCat sb ) { switch ( status ) { case "": sb.append( "\n" ); break; case "dead": sb.append( "\n" ); break; case "dup": sb.append( "\n" ); break; case "parked": sb.append( "\n" ); break; case "redirect": sb.append( "\n" ); break; default: sb.append( "", status, "\n" ); } } private static void emitTableHeader( final PrintWriter prw ) { prw.print( DO_NOT_EDIT + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" ); } public static void emitTableFooter( final PrintWriter prw, final int lineNumber ) { if ( lineNumber == 0 ) { prw.print( "\n" ); } // C L O S E prw.print( "
\n" + "Status of ASP PADSites\n" + "
" + "Status of ASP PADSites" + "
PadSite#StatusHomeStatusSubmitHomeRedirSubmitRedir
none
\n" ); } /** * FormatPadSites csv file to HTML, list of submission sites, either hassle or nohassle, or candidates. * * @param args source and target file names * . * * @throws IOException on trouble reading/writing files */ public static void main( String[] args ) throws IOException { if ( args.length != 0 ) { throw new IllegalArgumentException( USAGE ); } final File rfile = new File( "E:/com/mindprod/submitter/forasp.csv" ); final CSVReader r = new CSVReader( EIO.getBufferedReader( rfile, 4 * 1024, EIO.UTF8 ) ); final PrintWriter prw = EIO.getPrintWriter( new File( "E:/mindprod/jgloss/include/forasp.htmlfrag" ), 4 * 1024, EIO.UTF8 ); emitTableHeader( prw ); int lineNumber = 0; try { while ( true ) { // read url, site, image, notes final String[] fields = r.getAllFieldsInLine(); // ignore blank lines if ( fields.length == 0 ) { continue; } if ( fields.length < 3 ) { // submissionURL and status are optional err.println( "missing field(s) on line " + r.lineCount() + " of file " + rfile ); System.exit( 2 ); } final String padsiteName = fields[ 0 ]; if ( padsiteName.length() == 0 ) { err.println( "missing site name on line " + r.lineCount() + " of file " + rfile ); System.exit( 2 ); } final String statusForHome = fields[ 1 ]; final String homeURL = fields[ 2 ].replace( "&", "&" ); final String statusForSubmit = fields.length > 3 ? fields[ 3 ] : ""; final String submitURL = fields.length > 4 ? fields[ 4 ].replace( "&", "&" ) : ""; final String homeRedir = fields.length > 5 ? fields[ 5 ].replace( "&", "&" ) : ""; final String submitRedir = fields.length > 6 ? fields[ 6 ].replace( "&", "&" ) : ""; // write image, line number, link to site, notes. final FastCat sb = new FastCat( 35 ); // PadSite sb.append( "", padsiteName, "\n" ); // LineNumber sb.append( "", ++lineNumber, ".\n" ); // statusForHost appendStatus( statusForHome, sb ); // homeURL appendLongURL( homeURL, sb ); // statusForSubmit appendStatus( statusForSubmit, sb ); // submissionURL appendLongURL( submitURL, sb ); // homeRedir appendLongURL( homeRedir, sb ); // submitRedir appendLongURL( submitRedir, sb ); sb.append( "\n" ); // out.println( "used: " + sb.used() ); prw.print( sb.toString() ); } // end while } catch ( EOFException e ) { emitTableFooter( prw, lineNumber ); prw.close(); r.close(); } catch ( Exception e ) { err.println( "trouble on line " + r.lineCount() + " of file " + rfile ); err.println( e.getMessage() ); System.exit( 2 ); } } }