/* * [Common.java] * * Summary: methods common to all the table reorganising utilitise. * * 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-07-29 holds methods common to all utilities. */ package com.mindprod.reorg; import com.mindprod.common18.EIO; import com.mindprod.hunkio.HunkIO; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.StringTokenizer; import static java.lang.System.*; /** * methods common to all the table reorganising utilitise. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2008-07-29 holds methods common to all utilities. * @since 2008-07-29 */ abstract class Common { /** * where input HTML comes from */ static final String IN_FILENAME = "E:/temp/in.html"; /** * where other input HTML comes from */ static final String OTHER_IN_FILENAME = "E:/temp/other.html"; /** * where output HTML goes. */ static final String OUT_FILENAME = "E:/temp/out.html"; /** * get number of cols in matrix * * @param matrix html table, * * @return rows in table */ static int cols( String[][] matrix ) { return matrix.length == 0 ? 0 : matrix[ 0 ].length; } /** * Count how many rows and cols in the table * * @param tableString HTML for the table as a string. including lead ", true /* return delims */ ); boolean copy = false; // true = inside data, copy to matrix boolean bypass = false;// bypass next token String token = null; while ( st.hasMoreTokens() ) { // bypass any left over > if ( bypass ) { while ( st.hasMoreTokens() && !st.nextToken().equals( ">" ) ) { } bypass = false; } if ( !st.hasMoreTokens() ) { throw new IllegalArgumentException( "HTML syntax error near 0-based table row " + row + " col " + col + " token " + token ); } token = st.nextToken(); if ( token.equals( "<" ) ) { token = st.nextToken(); if ( token.equalsIgnoreCase( "tr" ) ) { // saw
" ); if ( aMatrix[ col ] != null ) { pw.print( aMatrix[ col ] ); } pw.print( " | " ); } // end col loop pw.println( "