|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.nrao.sss.html.HtmlElement edu.nrao.sss.html.HtmlTable
public class HtmlTable
An HTML table.
Version Info:
$Revision: 502 $ |
$Date: 2007-04-04 11:39:33 -0600 (Wed, 04 Apr 2007) $ |
$Author: dharland $ |
Field Summary |
---|
Fields inherited from class edu.nrao.sss.html.HtmlElement |
---|
NBSP_HTML, NBSP_TEXT, NBSP_UNICODE |
Constructor Summary | |
---|---|
HtmlTable()
Creates a new empty table. |
Method Summary | |
---|---|
void |
addRow(HtmlTableRow newRow)
Adds newRow to this table. |
static List<HtmlTable> |
createFromHtml(Reader source)
Returns a list of new HTML tables created by parsing the given source. |
URL |
getParentPage()
Returns the page to which this table belongs, if any. |
List<String> |
getParsingErrors()
Returns a list of the parsing errors reported during the most recent call to readHtmlFrom(Reader, int) . |
List<HtmlTableRow> |
getRows()
Returns a copy of this table's list of rows. |
List<HtmlTableRow> |
getRows(HtmlTableRow.Type desiredType)
Returns a new list that contains the rows of this table whose type is equal to desiredType . |
List<List<HtmlTableRow>> |
getRowsInSections()
Returns the rows of this table segregated into header rows, data rows, and footer rows. |
boolean |
isSimple()
Returns false. |
void |
readHtmlFrom(Reader source,
int tableIndex)
Adds rows to this table by parsing source. |
void |
readTextFrom(Reader reader,
String columnSeparator)
Appends new rows to this table by parsing the delimited text in reader . |
int |
removeEmptyRows()
Removes all empty rows (those with no cells) from this table. |
boolean |
removeRow(HtmlTableRow unwantedRow)
Removes unwantedRow from this table. |
int |
size()
Returns the number of rows in this table. |
HtmlTable |
toCompressedTable()
Returns a new table that is an expanded form of this table. |
HtmlTable |
toExpandedTable()
Returns a new table that is an expanded form of this table. |
void |
writeTextTo(Writer device,
String rowDelimiter,
String columnDelimiter)
Writes this table as text. |
Methods inherited from class edu.nrao.sss.html.HtmlElement |
---|
addAttribute, copyAttributesOf, getAttribute, getAttributes, getAttributeValue, getTag, removeAllAttributes, removeAttribute, writeHtmlTo |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HtmlTable()
Method Detail |
---|
public boolean isSimple()
isSimple
in class HtmlElement
public URL getParentPage()
public void addRow(HtmlTableRow newRow)
newRow
to this table.
If the new row is null or already in this table, this method does nothing. Otherwise the new row is removed from its previous table, if any, and added to this one. The new cell's parent table is set to this one.
newRow
- a new row for this table.public boolean removeRow(HtmlTableRow unwantedRow)
unwantedRow
from this table.
If the unwanted row is null or not part of this table, this method does nothing. Otherwise the unwanted row is removed from this table, and its parent table is set to null.
unwantedRow
- the row to be removed from this table.
unwantedRow
was removed from this table.public int removeEmptyRows()
public List<HtmlTableRow> getRows()
While the list is a copy, the rows in the returned list are the actual rows held in this table.
public List<HtmlTableRow> getRows(HtmlTableRow.Type desiredType)
desiredType
.
desiredType
- the type of row desired.
public List<List<HtmlTableRow>> getRowsInSections()
The returned list will always have exactly three elements. The first list holds header rows, the second holds data rows, and the last holds footer rows. Each element will always hold a list -- it will never hold null. If a table has no rows of a given type, that list will be empty.
public int size()
public void writeTextTo(Writer device, String rowDelimiter, String columnDelimiter) throws IOException
rowDelimiter
. Within each row, each column is
separated by columnDelimiter
.
Handling COLSPAN and ROWSPAN
In order to make a rectangular grid of rows and columns, this method
processes the colspan and rowspan attributes of
each HtmlTableCell
. It does this by repeating a table cell's
information in the appropriate number of rows and columns of the grid.
A hole anywhere in the grid is represented by an empty string, in which
case you will see consecutive columnDelimiter
s. If a table has
been specified erroneously such that two cells overlap in the grid, this
method favors the table cells of the row with the higher index, overwriting
those from previous rows.
Given this 4x4 table:
--A-- --B-- --C-- --D-- --E-- --F-- --G--
The result of calling this method with ";" for the column delimiter and
new-line for the row delimiter is:
--A--;--B--;--B--;;
--A--;--C--;--C--;--D--;
--E--;--C--;--C--;--F--;
--G--;--G--;;--F--;
device
- where the text is written.rowDelimiter
- used to separate the rows.columnDelimiter
- used to separate columns within a row.
IOException
- if anything goes wrong while writing to the device.public static List<HtmlTable> createFromHtml(Reader source) throws IOException
Caveat: This method translates only "outer" tables -- those
not contained in the cells of other tables. Tables inside table cells
are captured as the unparsed content of
HtmlTableCells
. One way to overcome this is
to subject the unparsed content of the returned tables' cells to this
same method.
source
- a source of HTML to be parsed for tables.
IOException
- if anything goes wrong while reading the source.public void readHtmlFrom(Reader source, int tableIndex) throws IOException
tableIndex
, starting from the
current cursor position in source, is used. Indexing starts at zero and
starts with the first table open tag found. If no such tag is found,
this table is unaltered by this method.
Caveat: This method indexes and translates only "outer" tables --
those not contained in the cells of other tables. Tables inside table
cells of the parsed table are captured as the unparsed content of
HtmlTableCells
. One way to overcome this is
to subject the unparsed content of the returned tables' cells to
createFromHtml(Reader)
.
source
- a source of HTML to be parsed for tables.
IOException
- if anything goes wrong while reading the source.public List<String> getParsingErrors()
readHtmlFrom(Reader, int)
. The returned list is
not held by this table, so manipulating it will have no
effect on this object.
readHtmlFrom(Reader, int)
.public void readTextFrom(Reader reader, String columnSeparator) throws IOException
reader
. Each line presented by reader
is assumed
to be a new row.
reader
- a text source of table rows.columnSeparator
- the delimiter separating columns in a row.
IOException
public HtmlTable toExpandedTable()
By "expanded" we mean that any cells that had colspan or rowspan values greater than one have been split into multiple cells with column and row spans of one. For example, a cell in this table with a column span of three and a row span of two is present not once, but six times, in the returned table. Furthermore, the six occurrences, while equal to each other, are six distinct instances.
No cells are shared by this table and the returned table.
Example--A-- | --B-- | |
--C-- | --D-- | |
--E-- | --F-- | |
--G-- |
--A-- | --B-- | --B-- | |
--A-- | --C-- | --C-- | --D-- |
--E-- | --C-- | --C-- | --F-- |
--G-- | --G-- | --F-- |
toCompressedTable()
,
it looks like this:
--A-- | --B-- | ||
--C-- | --D-- | ||
--E-- | --F-- | ||
--G-- |
Caveat: the algorithm used for column widths is only approximate. It is possible to achieve odd-looking widths for some tables.
public HtmlTable toCompressedTable()
By "compressed" we mean that adjacent cells in this table that have equal contents attributes have been merged, to the extent possible, into one cell with a column span and/or a row span greater than one.
No cells are shared by this table and the returned table.
See the example in toExpandedTable()
; this method first calls
that method, so any problems mentioned in that method's documentation
may have an effect on the results of this method.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |