uk.ac.starlink.table.formats
Class HTMLTableWriter

java.lang.Object
  extended by uk.ac.starlink.table.StreamStarTableWriter
      extended by uk.ac.starlink.table.formats.HTMLTableWriter
All Implemented Interfaces:
MultiStarTableWriter, StarTableWriter

public class HTMLTableWriter
extends StreamStarTableWriter
implements MultiStarTableWriter

A StarTableWriter that outputs text to HTML. Depending on the value of the standalone attribute, the output may either be a complete HTML document or just a <TABLE> element suitable for inserting into an existing document. The output HTML is intended to conform to HTML 3.2 or 4.01, depending on options.

See Also:
HTML 3.2, HTML 4.01

Constructor Summary
HTMLTableWriter()
          Constructs a new writer with default characteristics.
HTMLTableWriter(boolean standalone, boolean useRowGroups)
          Constructs a new writer indicating whether it will produce complete or partial HTML documents.
 
Method Summary
 java.lang.String getFormatName()
          Gives the name of the format which is written by this writer.
 java.lang.String getMimeType()
          Returns a string suitable for use as the value of a MIME Content-Type header.
static StarTableWriter[] getStarTableWriters()
          Returns a selection of useful HTMLTableWriters.
 boolean isStandalone()
          Indicates whether output tables will be complete HTML documents.
protected  boolean isUrl(java.lang.String txt)
          Determines whether a string is apparently a URL.
 boolean looksLikeFile(java.lang.String location)
          Indicates whether the destination is of a familiar form for this kind of writer.
protected  void printFooter(java.io.OutputStream ostrm)
          For standalone output, this method is invoked to output any text following the </TABLE> end tag.
protected  void printHeader(java.io.OutputStream ostrm, StarTable table)
          For standalone output, this method is invoked to output any text preceding the <TABLE> start tag.
 void setStandalone(boolean standalone)
          Sets whether output tables should be complete HTML documents.
 void writeStarTable(StarTable table, java.io.OutputStream out)
          Writes a StarTable object to a given output stream.
 void writeStarTables(TableSequence tableSeq, java.io.OutputStream out)
          Writes an array of StarTable objects to a given output stream.
 void writeStarTables(TableSequence tableSeq, java.lang.String location, StarTableOutput sto)
          Writes an array of StarTable objects to a given location.
 
Methods inherited from class uk.ac.starlink.table.StreamStarTableWriter
writeStarTable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface uk.ac.starlink.table.StarTableWriter
writeStarTable
 

Constructor Detail

HTMLTableWriter

public HTMLTableWriter()
Constructs a new writer with default characteristics.


HTMLTableWriter

public HTMLTableWriter(boolean standalone,
                       boolean useRowGroups)
Constructs a new writer indicating whether it will produce complete or partial HTML documents.

Method Detail

setStandalone

public void setStandalone(boolean standalone)
Sets whether output tables should be complete HTML documents.

Parameters:
standalone - true if the output document should be a complete HTML document

isStandalone

public boolean isStandalone()
Indicates whether output tables will be complete HTML documents.

Returns:
true if the output documents will be complete HTML docs

getFormatName

public java.lang.String getFormatName()
Description copied from interface: StarTableWriter
Gives the name of the format which is written by this writer. Matching against this string may be used by callers to identify or select this writer from a list.

Specified by:
getFormatName in interface StarTableWriter
Returns:
a short string identifying the output format of this writer

getMimeType

public java.lang.String getMimeType()
Description copied from interface: StarTableWriter
Returns a string suitable for use as the value of a MIME Content-Type header. If no suitable MIME type is available or known, one of "application/octet-stream" (for binary formats) or "text/plain" for ASCII ones) is recommended.

Specified by:
getMimeType in interface StarTableWriter
Returns:
MIME content type

looksLikeFile

public boolean looksLikeFile(java.lang.String location)
Description copied from interface: StarTableWriter
Indicates whether the destination is of a familiar form for this kind of writer. This may be used to guess what kind of format a table should be written in. Implementations should return true for values of location which look like the normal form for their output format, for instance one with the usual file extension.

Specified by:
looksLikeFile in interface StarTableWriter
Parameters:
location - the location name (probably filename)
Returns:
true iff it looks like a file this writer would normally write

writeStarTable

public void writeStarTable(StarTable table,
                           java.io.OutputStream out)
                    throws java.io.IOException
Description copied from interface: StarTableWriter
Writes a StarTable object to a given output stream. The implementation can assume that out is suitable for direct writing (for instance it should not normally wrap it in a BufferedOutputStream), and should not close it at the end of the call.

Not all table writers are capable of writing to a stream; an implementation may throw a TableFormatException to indicate that it cannot do so.

Specified by:
writeStarTable in interface StarTableWriter
Parameters:
table - the table to write
out - the output stream to which startab should be written
Throws:
TableFormatException - if this table cannot be written to a stream
java.io.IOException - if there is some I/O error

writeStarTables

public void writeStarTables(TableSequence tableSeq,
                            java.io.OutputStream out)
                     throws java.io.IOException
Description copied from interface: MultiStarTableWriter
Writes an array of StarTable objects to a given output stream. The implementation can assume that the stream is suitable for direct writing (for instance it should not normally wrap it in a BufferedOutputStream), and should not close it at the end of the call.

Specified by:
writeStarTables in interface MultiStarTableWriter
Parameters:
tableSeq - sequence of tables to write
out - destination stream
Throws:
java.io.IOException

writeStarTables

public void writeStarTables(TableSequence tableSeq,
                            java.lang.String location,
                            StarTableOutput sto)
                     throws java.io.IOException
Description copied from interface: MultiStarTableWriter
Writes an array of StarTable objects to a given location. Implementations are free to interpret the location argument in any way appropriate for them. Typically however the location will simply be used to get an output stream (for instance interpreting it as a filename). In this case the sto argument should normally be used to turn location into a stream.

Specified by:
writeStarTables in interface MultiStarTableWriter
Parameters:
tableSeq - sequence of tables to write
location - destination for tables
sto - StarTableOutput instance
Throws:
java.io.IOException

getStarTableWriters

public static StarTableWriter[] getStarTableWriters()
Returns a selection of useful HTMLTableWriters.

Returns:
array containing one standalone and one TABLE-only writer

printHeader

protected void printHeader(java.io.OutputStream ostrm,
                           StarTable table)
                    throws java.io.IOException
For standalone output, this method is invoked to output any text preceding the <TABLE> start tag. May be overridden to modify the form of output documents.

Parameters:
ostrm - output stream
table - table for which header is required; may be null for multi-table output
Throws:
java.io.IOException

printFooter

protected void printFooter(java.io.OutputStream ostrm)
                    throws java.io.IOException
For standalone output, this method is invoked to output any text following the </TABLE> end tag. May be overridden to modify the form of output documents.

Parameters:
ostrm - output stream
Throws:
java.io.IOException

isUrl

protected boolean isUrl(java.lang.String txt)
Determines whether a string is apparently a URL. If this returns true, it is appropriate to format it within an HTML "a" element.

Parameters:
txt - string to test
Returns:
true iff txt looks like a URL