Package uk.ac.starlink.table.formats
Class HTMLTableWriter
java.lang.Object
uk.ac.starlink.table.formats.DocumentedStreamStarTableWriter
uk.ac.starlink.table.formats.HTMLTableWriter
- All Implemented Interfaces:
Documented
,DocumentedIOHandler
,MultiStarTableWriter
,StarTableWriter
public class HTMLTableWriter
extends DocumentedStreamStarTableWriter
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.- Author:
- Mark Taylor (Starlink)
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs 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
Modifier and TypeMethodDescriptionboolean
Indicates whether the serialization of some (short) example table should be added to the user documentation for this handler.Gives the name of the format which is written by this writer.int
Returns the maximum output width in characters for a single cell.Returns a string suitable for use as the value of a MIME Content-Type header.static StarTableWriter[]
Returns a selection of useful HTMLTableWriters.Returns user-directed documentation in XML format.boolean
Indicates whether output tables will be complete HTML documents.protected boolean
Determines whether a string is apparently a URL.protected void
printFooter
(OutputStream ostrm) For standalone output, this method is invoked to output any text following the </TABLE> end tag.protected void
printHeader
(OutputStream ostrm, StarTable table) For standalone output, this method is invoked to output any text preceding the <TABLE> start tag.void
setMaxWidth
(int maxWidth) Sets the maximum output width in characters for a single cell.void
setStandalone
(boolean standalone) Sets whether output tables should be complete HTML documents.void
writeStarTable
(StarTable table, OutputStream out) Writes a StarTable object to a given output stream.void
writeStarTables
(TableSequence tableSeq, OutputStream out) Writes an array of StarTable objects to a given output stream.void
writeStarTables
(TableSequence tableSeq, String location, StarTableOutput sto) Writes an array of StarTable objects to a given location.Methods inherited from class uk.ac.starlink.table.formats.DocumentedStreamStarTableWriter
getExtensions, looksLikeFile, 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.formats.DocumentedIOHandler
readText
Methods inherited from interface uk.ac.starlink.table.StarTableWriter
looksLikeFile, writeStarTable
-
Constructor Details
-
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 Details
-
setStandalone
@ConfigMethod(property="standalone", doc="If true, the output is a freestanding HTML document complete with HTML, HEAD and BODY tags. If false, the output is just a TABLE element.") 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
-
setMaxWidth
@ConfigMethod(property="maxCell", doc="Maximum width in characters of an output table cell. Cells longer than this will be truncated.") public void setMaxWidth(int maxWidth) Sets the maximum output width in characters for a single cell.- Parameters:
maxWidth
- new maximum cell width
-
getMaxWidth
public int getMaxWidth()Returns the maximum output width in characters for a single cell.- Returns:
- maximum cell width
-
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 interfaceStarTableWriter
- Returns:
- a short string identifying the output format of this writer
-
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 interfaceStarTableWriter
- Returns:
- MIME content type
-
docIncludesExample
public boolean docIncludesExample()Description copied from interface:DocumentedIOHandler
Indicates whether the serialization of some (short) example table should be added to the user documentation for this handler. Binary formats, or instances for which theDocumented.getXmlDescription()
method already includes some example output, should return false.- Specified by:
docIncludesExample
in interfaceDocumentedIOHandler
- Returns:
- true if the user documentation would benefit from the addition of an example serialization
-
getXmlDescription
Description copied from interface:Documented
Returns user-directed documentation in XML format.The output should be a sequence of one or more <P> elements, using XHTML-like XML. Since rendering may be done in a number of contexts however, use of the full range of XHTML elements is discouraged. Where possible, the content should stick to simple markup such as the elements P, A, UL, OL, LI, DL, DT, DD EM, STRONG, I, B, CODE, TT, PRE.
- Specified by:
getXmlDescription
in interfaceDocumented
- Returns:
- XML description of this object
-
writeStarTable
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 aBufferedOutputStream
), 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 interfaceStarTableWriter
- Parameters:
table
- the table to writeout
- the output stream to which startab should be written- Throws:
IOException
- if there is some I/O error
-
writeStarTables
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 aBufferedOutputStream
), and should not close it at the end of the call.- Specified by:
writeStarTables
in interfaceMultiStarTableWriter
- Parameters:
tableSeq
- sequence of tables to writeout
- destination stream- Throws:
IOException
-
writeStarTables
public void writeStarTables(TableSequence tableSeq, String location, StarTableOutput sto) throws 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 interfaceMultiStarTableWriter
- Parameters:
tableSeq
- sequence of tables to writelocation
- destination for tablessto
- StarTableOutput instance- Throws:
IOException
-
getStarTableWriters
Returns a selection of useful HTMLTableWriters.- Returns:
- array containing one standalone and one TABLE-only writer
-
printHeader
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 streamtable
- table for which header is required; may be null for multi-table output- Throws:
IOException
-
isUrl
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
-