Class Convert

java.lang.Object
  extended by Convert

public class Convert
extends java.lang.Object

Class Convert to convert one Table to HTML. This class also contains various mapping functions used in the conversion as well as extracting a subtable for inclusion.

 List of Methods
 Convert() - Constructor
 cvtTable2HTML() - Process a FileTable into an output HTML file.
 cvtPrefaceTable2HTML() - Process a preface FileTable to HTML file. 
 cvtText2HTML() - convert text to an output HTML file.
 mapCellToStr() - map a cell string at [r, c] to an HTML string
 buildMapUrl() - map a cell string at [r, c] to an HTML link string
 makeOptionsListFromSemicolonList() - map ";;" delim. str to OPTION list
 testIfRowIsBlank() - test if remove trailing blank lines after first line 
 concatInputFilesWithSameFields() - create concat. tab-delim. .txt file
 shrinkStrToSmallerFont() - shrink string if text is > threshold size.
 exportBigStrToHTMLfile() - if the |str| > bigExportCellThr.
 mapHeaderNames() - try to map header names within the header table
 mapQuestionmarks() - Map cell data of the form '??{cell text}'??'
 mapDollarsigns() - map data form '$$keyword$$' to '{toString}.
 extractRowFromResourceTableAsHTML() - extract row data from resource file
 checkAndMakeIndexHtmlDirList() - make index.html files in list of dirs
 checkAndMakeIndexHtmlDir() - make index.html files in a directory.
 makeIndexHtml() - make "index.html" file in the directory.
 checkIfDir() - test if fileName is a directory
 

This code is available at the HTMLtools project on SourceForge at http://htmltools.sourceforge.org/ under the "Common Public License Version 1.0" http://www.opensource.org/licenses/cpl1.0.php.

It was derived and refactored from the open source MAExplorer (http://maexplorer.sourceforge.org/), and Open2Dprot (http://Open2Dprot.sourceforge.net/) Table modules.

$Date: 2009/11/21 11:45:56 $ $Revision: 1.37 $
Copyright 2008, 2009 by Peter Lemkin E-Mail: lemkin@users.sourceforge.net http://lemkingroup.com/


Field Summary
 HTMLtools cvt
           
 FileTable fio
          Global fileTable instance
private static int STYLE_DL
           
private static int STYLE_OL
           
private static int STYLE_TABLE
           
private static int STYLE_UL
           
 
Constructor Summary
Convert(HTMLtools cvt)
          Convert() - Constructor
 
Method Summary
 java.lang.String buildMapUrl(java.lang.String cell, int c, int hrefIdx)
          buildMapUrl() - map a cell string at [r, c] to an HTML link string by adding the HREF if hrefIdx==c using the cvt.urlBaseLink For the 1:1 mapping, it adds the cell value {} to the base urlBaseLink value {}.
 boolean checkAndMakeIndexHtml(int nLevel, int subLevelNbr, java.lang.String parentDir, java.lang.String dirToCheck, boolean overrideFlag)
          checkAndMakeIndexHtmlDir() - make index.html files in a directory.
 boolean checkAndMakeIndexHtmlDirList(int nDirIndexHtml, java.lang.String parentDir, java.lang.String[] dirIndexHtml, boolean[] dirIndexHtmlOverrideFlag)
          checkAndMakeIndexHtmlDirList() - make index.html files in list of dirs.
 boolean checkIfDir(java.lang.String dirName, java.lang.String fileName)
          checkIfDir() - test if fileName is a directory
 boolean concatInputFilesWithSameFields(int fileNbr, FileTable ft)
          concatInputFilesWithSameFields() - to create a new concatenated tab-delimited .txt output file from the set of input text files IFF they have exactly the same column header names.
 java.lang.String cvtPrefaceTable2HTML(FileTable ft, java.lang.String fileName, java.lang.String sName, java.lang.String sProlog, java.lang.String sEpilogue)
          cvtPrefaceTable2HTML() - Process a preface FileTable into an output HTML file.
 java.lang.String cvtTable2HTML(FileTable ft, java.lang.String iFileName, int fileNbr, java.lang.String sName, java.lang.String sProlog, java.lang.String sEpilogue, java.lang.String oPrefaceFile, java.lang.String limitedRows)
          cvtTable2HTML() - Process a FileTable into an output HTML file.
 java.lang.String cvtText2HTML(java.lang.String sText, java.lang.String sName, java.lang.String sProlog, java.lang.String sEpilogue)
          cvtText2HTML() - convert text to an output HTML file.
 java.lang.String exportBigStrToHTMLfile(java.lang.String str, java.lang.String oDir, java.lang.String oFileName, int r, int c, int maxChars)
          exportBigStrToHTMLfile() - if the |str| > bigExportCellThr.
 java.lang.String extractRowFromResourceTableAsHTML(FileTable ft, java.lang.String extractColName, int extractRowNbr, java.lang.String extractResTblFile, java.lang.String extractHtmlStyle)
          extractRowFromResourceTableAsHTML() - to get and lookup a keyword in the table being processed at (colName,rowNbr) and then to search a resourceTblFile for that keyword.
 java.lang.String makeColorMapScaleHTML()
          makeColorMapScaleHTML() - make colormap data scale TABLE HTML mapping the cvt.heatMapColors[] to positive numeric value in range of [cvt.glbMinRowVal, cvt.glbMaxRowVal]
 boolean makeIndexHtml(java.io.File fd, java.lang.String dirName, java.lang.String[] dirList)
          makeIndexHtml() - make "index.html" file in the directory.
 java.lang.String makeOptionsListFromSemicolonList(java.lang.String cell)
          makeOptionsListFromSemicolonList() - map a ";;" delimited cell string to an < OPTION > list.
 java.lang.String mapCellToStr(java.lang.String cell, int r, int c, java.lang.String tHD, int hrefIdx, java.lang.String oFileBaseName)
          mapCellToStr() - map a cell string at [r, c] to an HTML string adding the HREF if hrefIdx==c using the cvt.urlBaseLink.
 java.lang.String mapDataToCellBGcolor(java.lang.String sVal, java.lang.String defaultBGcolor)
          mapDataToCellBGcolor() - map data cell number to cell background color the colors are in cvt.heatMapColors[].
 java.lang.String mapDollarsigns(java.lang.String str)
          mapDollarsigns() - map data form '$$keyword$$' to '{toString}.
 int mapHeaderNames(FileTable ft)
          mapHeaderNames() - try to map header names within the header table in the tFields[] and tHeader[last][] arrays.
 java.lang.String mapQuestionmarks(java.lang.String str)
          mapQuestionmarks() - map cell data of the form '??{cell text}'??' to bold and red, keeping 1 questionmark so can process the string recursively.
 java.lang.String shrinkStrToSmallerFont(java.lang.String str)
          shrinkStrToSmallerFont() - if the useHTMLfontSize or the |str| > bigShrinkCellThr.
 boolean testIfRowIsBlank(java.lang.String[] tRowData, int tCols)
          testIfRowIsBlank() - test if remove trailing blank lines after first line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cvt

public HTMLtools cvt

fio

public FileTable fio
Global fileTable instance


STYLE_DL

private static final int STYLE_DL
See Also:
Constant Field Values

STYLE_OL

private static final int STYLE_OL
See Also:
Constant Field Values

STYLE_UL

private static final int STYLE_UL
See Also:
Constant Field Values

STYLE_TABLE

private static final int STYLE_TABLE
See Also:
Constant Field Values
Constructor Detail

Convert

public Convert(HTMLtools cvt)
Convert() - Constructor

Parameters:
cvt - is instance of HTMLtools
Method Detail

cvtTable2HTML

public java.lang.String cvtTable2HTML(FileTable ft,
                                      java.lang.String iFileName,
                                      int fileNbr,
                                      java.lang.String sName,
                                      java.lang.String sProlog,
                                      java.lang.String sEpilogue,
                                      java.lang.String oPrefaceFile,
                                      java.lang.String limitedRows)
cvtTable2HTML() - Process a FileTable into an output HTML file.

Parameters:
ft - is FileTable containing the data to convert
iFileName - full path of input file name
fileNbr - number of the input file (special processing for 1st)
sName - name for the prolog HTML header if not null
sProlog - prolog string if not null
sEpilogue - epilogue string it not null
oPrefaceFile - name of preface file to generate if not null.
limitedRows - if limited length of rows in table.
Returns:
true if succeed, then return the output HTML web page string, else null.
See Also:
mapCellToStr(java.lang.String, int, int, java.lang.String, int, java.lang.String), testIfRowIsBlank(java.lang.String[], int)

cvtPrefaceTable2HTML

public java.lang.String cvtPrefaceTable2HTML(FileTable ft,
                                             java.lang.String fileName,
                                             java.lang.String sName,
                                             java.lang.String sProlog,
                                             java.lang.String sEpilogue)
cvtPrefaceTable2HTML() - Process a preface FileTable into an output HTML file.

Parameters:
ft - is FileTable containing the data to convert
fileName - full path of input file name
sName - name for the prolog HTML header if not null
sProlog - prolog string if not null
sEpilogue - epilogue string it not null
Returns:
true if succeed, then return the
output HTML web page string, else null.
See Also:
mapCellToStr(java.lang.String, int, int, java.lang.String, int, java.lang.String)

cvtText2HTML

public java.lang.String cvtText2HTML(java.lang.String sText,
                                     java.lang.String sName,
                                     java.lang.String sProlog,
                                     java.lang.String sEpilogue)
cvtText2HTML() - convert text to an output HTML file. This is used for prefacing text from the input file or additional preface table.

Parameters:
sText - is the string to convert to HTML
sName - name for the prolog HTML header if not null
sProlog - prolog string if not null
sEpilogue - epilogue string it not null
Returns:
true if succeed, then return HTML string

mapCellToStr

public java.lang.String mapCellToStr(java.lang.String cell,
                                     int r,
                                     int c,
                                     java.lang.String tHD,
                                     int hrefIdx,
                                     java.lang.String oFileBaseName)
mapCellToStr() - map a cell string at [r, c] to an HTML string adding the HREF if hrefIdx==c using the cvt.urlBaseLink. It generates "< TH >{sCell}< /TH >" or "< TD >{sCell}< /TD >" and then {sCell} is inside of "< FONT fontSize={useHTMLfontSize} > sCell < /FONT >" and hCell is < A HREF="{urlBaseLink}+cell" > cell < /A >"

Parameters:
cell - data to convert
r - is row of the cell
c - is col of the cell
tHD - is either "TH" or "TD" depending on whether it's a header cell.
hrefIdx - is the hypertext map index if not -1
oFileBaseName - is the output File base name
Returns:
converted HTML string or the original string if not converted.
See Also:
mapQuestionmarks(java.lang.String), makeOptionsListFromSemicolonList(java.lang.String), exportBigStrToHTMLfile(java.lang.String, java.lang.String, java.lang.String, int, int, int), shrinkStrToSmallerFont(java.lang.String)

buildMapUrl

public java.lang.String buildMapUrl(java.lang.String cell,
                                    int c,
                                    int hrefIdx)
buildMapUrl() - map a cell string at [r, c] to an HTML link string by adding the HREF if hrefIdx==c using the cvt.urlBaseLink For the 1:1 mapping, it adds the cell value {} to the base urlBaseLink value {}. e.g., < A HREF="{urlBaseLink}+{cell}" > {cell} < /A >"

If the mapTokenInUrl exists, then substitute the cell for cvt.mapTokenInUrl[hrefIdx] in the cvt.urlBaseLink[hrefIdx].

[TODO] more complex cases require breaking up the cell value and inserting the pieces into the different parts of the urlBaseLink.

[MAYBE] add special cases here. Would be nice to automate it better.

Parameters:
cell - data to convert
c - is col of the cell
hrefIdx - is the hypertext map index if not -1
Returns:
converted HTML string or the original string if not converted.
See Also:
UtilCM.replaceSubstrInString(java.lang.String, java.lang.String, java.lang.String)

makeOptionsListFromSemicolonList

public java.lang.String makeOptionsListFromSemicolonList(java.lang.String cell)
makeOptionsListFromSemicolonList() - map a ";;" delimited cell string to an < OPTION > list. This is triggered by makeOptionsListFromSemicolonListFlag.

Parameters:
cell - data to convert
Returns:
converted HTML string or the original string if not converted.

testIfRowIsBlank

public boolean testIfRowIsBlank(java.lang.String[] tRowData,
                                int tCols)
testIfRowIsBlank() - test if remove trailing blank lines after first line. Note the trailing line could be short so check for that as well. If tRowData.length != tCols, then ill-formed Table data.

Parameters:
tRowData - is row of tData to test if blank.
tCols - is the number of columns to test.
Returns:
true if the line is blank

concatInputFilesWithSameFields

public boolean concatInputFilesWithSameFields(int fileNbr,
                                              FileTable ft)
concatInputFilesWithSameFields() - to create a new concatenated tab-delimited .txt output file from the set of input text files IFF they have exactly the same column header names. The -outputDir switch specifies where the file is saved. Default is not to concatenate the input files. Data is appended into concatStr. The '-concatTables:{outputConcatenateFile.txt}' switch enables this option by setting the concatInputFilesWithSameFieldsFlag switch.

Parameters:
fileNbr - - is the order of the file in the list of files starting with 0.
ft - is the instance of the FileTable to be concatenated
Returns:
true if succeed.

shrinkStrToSmallerFont

public java.lang.String shrinkStrToSmallerFont(java.lang.String str)
shrinkStrToSmallerFont() - if the useHTMLfontSize or the |str| > bigShrinkCellThr. Then shrink the string by decreasing the font size.

Parameters:
str - to shrink
Returns:
shrunken string.

exportBigStrToHTMLfile

public java.lang.String exportBigStrToHTMLfile(java.lang.String str,
                                               java.lang.String oDir,
                                               java.lang.String oFileName,
                                               int r,
                                               int c,
                                               int maxChars)
exportBigStrToHTMLfile() - if the |str| > bigExportCellThr. Then export the entire string and replace it with a leading string of maxChars. Create the file in oDir. Create a file "big-R"+r+"C"+c+oFileName in oDir.

[TODO] add javascript focus option instead of separate files.

Parameters:
str - to export to a file
oDir - is output directory to write the file
ofileName - is name of .html file with .html extension
r - row of cell
c - column of cell
maxChars - to use in HREF
Returns:
shrunken string.
See Also:
FileIO.writeStringToFile(java.lang.String, java.lang.String)

mapHeaderNames

public int mapHeaderNames(FileTable ft)
mapHeaderNames() - try to map header names within the header table in the tFields[] and tHeader[last][] arrays. This uses the cvt.nLong2ShortHdrNamesMap names in cvt.fromLongHdrNamesMap[] and cvt.toShortHdrNamesMap[] set by the "-mapHdrNames:{mapFile,fromHdrName,toHdrName}" switch.

Parameters:
ft - is FileTable to map.
Returns:
the number mapped if succeed, also make a list of this.unmapped names that are not in the names map.

mapQuestionmarks

public java.lang.String mapQuestionmarks(java.lang.String str)
mapQuestionmarks() - map cell data of the form '??{cell text}'??' to bold and red, keeping 1 questionmark so can process the string recursively.

Parameters:
str - input string containing possible ?? mapping.
Returns:
true if succeed

mapDollarsigns

public java.lang.String mapDollarsigns(java.lang.String str)
mapDollarsigns() - map data form '$$keyword$$' to '{toString}. Do this for all instances in the mapDollarsign mapping list. It can process the string recursively.

Parameters:
str - input string containing possible $$ mapping.
Returns:
true if succeed

extractRowFromResourceTableAsHTML

public java.lang.String extractRowFromResourceTableAsHTML(FileTable ft,
                                                          java.lang.String extractColName,
                                                          int extractRowNbr,
                                                          java.lang.String extractResTblFile,
                                                          java.lang.String extractHtmlStyle)
extractRowFromResourceTableAsHTML() - to get and lookup a keyword in the table being processed at (colName,rowNbr) and then to search a resourceTblFile for that keyword. If it found, then it will extract the header row and the data row from the resource file and create HTML of htmlStyle. This string could, for example, be inserted into the front of the epilogue. The htmlStyles may be DL, OL, UL and TABLE. Default is no row extraction.

The args are specified with the '-extractRow:{colName,rowNbr,resourceTblFile,htmlStyle}' switch.

Parameters:
ft - is the FileTable being processed
extractColName - - column common to both this ft table and the reference database file
extractRowNbr - - row to pick up examplar to search with
extractResTblFile - - reference database file to extract data
extractHtmlStyle - - string DL, OL, UL or TABLE
Returns:
extracted string from the resource table converted to HTML if successful, else null.
See Also:
UtilCM.logMsg(java.lang.String), FileIO.readFileAsString(java.lang.String), FileTable#readFileAsTable, FileTable.setDuplicateFieldsFlag(boolean), FileTable.setNbrTableHdrLines(int), FileTable.setRmvTrailingBlankLinesFlag(boolean), FileTable.setRmvTrailingEmptyColumnsFlag(boolean), FileTable.setHasEmptyLineBeforeTableFlag(boolean), FileTable.lookupFieldIdx(java.lang.String)

checkAndMakeIndexHtmlDirList

public boolean checkAndMakeIndexHtmlDirList(int nDirIndexHtml,
                                            java.lang.String parentDir,
                                            java.lang.String[] dirIndexHtml,
                                            boolean[] dirIndexHtmlOverrideFlag)
checkAndMakeIndexHtmlDirList() - make index.html files in list of dirs. in the dirIndexHtml[0:nDirIndexHtml-1] without them. If '-dirIndexHtml:{dir,'O'verride}' switches are set, then make an index.html file of all of the files in the specified directories in each directory in the list of directories dirIndexHtml[0:nDirIndexHtml-1]. In addition, if the corresponding dirIndexHtmlOverrideFlag[0:nDirIndexHtml-1] flag is set to 'Override', then override "index.html" files. Call subdirectories recursively.

Parameters:
nDirIndexHtml - - number of directories specified
dirIndexHtml - - list of relative directories to check
dirIndexHtmlOverrideFlag - - list of 'Override' "index.html" flags
Returns:
true if successful

checkAndMakeIndexHtml

public boolean checkAndMakeIndexHtml(int nLevel,
                                     int subLevelNbr,
                                     java.lang.String parentDir,
                                     java.lang.String dirToCheck,
                                     boolean overrideFlag)
checkAndMakeIndexHtmlDir() - make index.html files in a directory. If the overrideFlag is set, override "index.html" generation in each directory and subdirectory. Call the tree recursively.

Parameters:
nLevel - - dir number on main list.
subLevelNbr - - subdirectory level in tree from dir.
parentDir - - parent directory relative to top level.
dirToCheck - - relative directory to check
overrideFlag - - override "index.html" generation in each dir and subdirectory
Returns:
true if successful

makeIndexHtml

public boolean makeIndexHtml(java.io.File fd,
                             java.lang.String dirName,
                             java.lang.String[] dirList)
makeIndexHtml() - make "index.html" file in the directory.

Parameters:
fd - - file descriptor for the directory
dirName - - is name of the directory
dirList - - files in the directory
Returns:

checkIfDir

public boolean checkIfDir(java.lang.String dirName,
                          java.lang.String fileName)
checkIfDir() - test if fileName is a directory

Parameters:
fileName - to test
Returns:
true if directory

mapDataToCellBGcolor

public java.lang.String mapDataToCellBGcolor(java.lang.String sVal,
                                             java.lang.String defaultBGcolor)
mapDataToCellBGcolor() - map data cell number to cell background color the colors are in cvt.heatMapColors[].

Parameters:
sVal - is positive numeric value in range of [cvt.glbMinRowVal, cvt.glbMaxRowVal]
defaultBGcolor - is the default background color.
Returns:
background color from cvt.heatMapColors in corresponding quantile.

makeColorMapScaleHTML

public java.lang.String makeColorMapScaleHTML()
makeColorMapScaleHTML() - make colormap data scale TABLE HTML mapping the cvt.heatMapColors[] to positive numeric value in range of [cvt.glbMinRowVal, cvt.glbMaxRowVal]

Returns:
background color from cvt.heatMapColors in corresponding quantile.