/*
* [Reorg.java]
*
* Summary: Reorganize an HTML table by reshaping it selecting which columns to keep in what order.
*
* Copyright: (c) 1998-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 1998-01-01 initial version
*/
package com.mindprod.reorg;
import java.io.IOException;
/**
* Reorganize an HTML table by reshaping it selecting which columns to keep in what order.
*
* command line input tells which cols you want to keep, 0 based,
* in which order, can have dups, can leave out cols to delete them.
* -1 means insert a dummy column.
* Must manually strip stuff ahead and after table.
* Must manually strip
* Must manually strip |
* no fancy etc. Just
in upper or lower case.
* It can't handle any grammatical errors in your HTML.
* Input from E:\temp\in.html
* Output to E:\temp\out.html all tags in lower case.
* command line input tells which cols you want to keep, 0 based,
* in which order, can have dups, can leave out cols to delete them.
* -1 means insert a dummy column.
* Must manually strip stuff ahead and after table.
* Must manually strip
* Must manually strip | |
* no fancy
etc. Just
in upper or lower case.
* It can't handle any grammatical errors in your HTML.
* Input from E:\temp\in.html
* Output to E:\temp\out.html all tags in lower case.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 1998-01-01 initial version
* @since 1998-01-01
*/
public final class Reorg extends Common
{
private static final int FIRST_COPYRIGHT_YEAR = 1998;
/**
* non-displaying copyright.
*/
@SuppressWarnings( { "UnusedDeclaration" } )
private static final String EMBEDDED_COPYRIGHT =
"Copyright: (c) 1998-2017 Roedy Green, Canadian Mind Products, http://mindprod.com";
/**
* when package released.
*
* @noinspection UnusedDeclaration
*/
private static final String RELEASE_DATE = "1998-01-01";
/**
* embedded version string.
*/
@SuppressWarnings( { "UnusedDeclaration" } )
private static final String VERSION_STRING = "1.0";
/**
* main
*
* @param args which cols you want in output table in order, 0-based
*
* @throws java.io.IOException if any problem reading or writing the html
*/
@SuppressWarnings( { "UnnecessaryLocalVariable" } )
public static void main( String[] args ) throws IOException
{
// convert string args to numeric format
int[] colSource = new int[ args.length ];
for ( int i = 0; i < colSource.length; i++ )
{
colSource[ i ] = Integer.parseInt( args[ i ] );
}
// get entire table into a string.
final String[][] matrix = getMatrix( IN_FILENAME );
final int rows = rows( matrix );
final int cols = cols( matrix );
displayRowAndColCounts( "input", rows, cols );
trimMatrix( matrix );
final int nrows = rows;
final int ncols = colSource.length;
displayRowAndColCounts( "reshaped output", nrows, ncols );
// create new matrix with desired new columns.
String[][] grid = new String[ nrows ][ ncols ];
// copy over just the desired columns.
for ( int col = 0; col < ncols; col++ )
{
for ( int row = 0; row < nrows; row++ )
{
// find data for this column.
int sourceCol = colSource[ col ];
grid[ row ][ col ] =
( sourceCol < 0 )
? " "
: matrix[ row ][ sourceCol ];
} // end for
} // end for
writeMatrix( grid, OUT_FILENAME );
} // end main
}
|