com.jrefinery.report.targets.table.html
Class DirectoryHtmlFilesystem

java.lang.Object
  |
  +--com.jrefinery.report.targets.table.html.DirectoryHtmlFilesystem
All Implemented Interfaces:
HtmlFilesystem

public class DirectoryHtmlFilesystem
extends java.lang.Object
implements HtmlFilesystem

Writes the generated Html-File and the supplementary data files (images and external Stylesheet definition) into a directory. The data files can be written into a separated data directory.

External referenced content can either be copied into the data directory or could be included as linked content. This behaviour is controled by the copyExternalImages flag.

Author:
Thomas Morgner

Constructor Summary
DirectoryHtmlFilesystem(java.io.File file)
          Creates a new DirectoryHtmlFilesystem, using the file as root file and the file's directory as data directory to store the generated data files.
DirectoryHtmlFilesystem(java.io.File file, java.io.File dataDirectory)
          Creates a new DirectoryHtmlFilesystem, using the file as root file and the dataDirectory to store the generated data files.
 
Method Summary
 void close()
          Close the Filesystem and write any buffered content.
 HtmlReferenceData createCSSReference(java.lang.String styleSheet)
          Creates a HtmlReference for StyleSheetData.
 HtmlReferenceData createImageReference(ImageReference reference)
          Creates a HtmlReference for ImageData.
 java.io.OutputStream getRootStream()
          The root stream is used to write the main HTML-File.
 boolean isCopyExternalImages()
          Returns true, if external content should be copied into the DataDirectory of the ZIPFile or false if the content should be included as linked content.
protected  boolean isSupportedImageFormat(java.net.URL url)
          Tests, whether the given URL points to a supported file format for common browsers.
 void setCopyExternalImages(boolean copyExternalImages)
          Defines, whether external content should be copied into the DataDirectory of the ZIPFile or should be included as linked content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DirectoryHtmlFilesystem

public DirectoryHtmlFilesystem(java.io.File file)
                        throws java.io.IOException
Creates a new DirectoryHtmlFilesystem, using the file as root file and the file's directory as data directory to store the generated data files.

Parameters:
file - the filename of the root html file.
Throws:
java.io.IOException - if an error occurs.

DirectoryHtmlFilesystem

public DirectoryHtmlFilesystem(java.io.File file,
                               java.io.File dataDirectory)
                        throws java.io.IOException
Creates a new DirectoryHtmlFilesystem, using the file as root file and the dataDirectory to store the generated data files.

Parameters:
file - the filename of the root html file.
dataDirectory - the name of the data directory, where the files should be created.
Throws:
java.io.IOException - if an error occurs.
Method Detail

isCopyExternalImages

public boolean isCopyExternalImages()
Returns true, if external content should be copied into the DataDirectory of the ZIPFile or false if the content should be included as linked content.

Linked content reduces the filesize, but the reader of the report will need access to the linked files. If you pan to use the report offline, then it is best to copy all referenced data into the zip file.

Returns:
true, if external referenced content should be copied into the ZIP file, false otherwise.

setCopyExternalImages

public void setCopyExternalImages(boolean copyExternalImages)
Defines, whether external content should be copied into the DataDirectory of the ZIPFile or should be included as linked content.

Linked content reduces the filesize, but the reader of the report will need access to the linked files. If you pan to use the report offline, then it is best to copy all referenced data into the zip file.

Parameters:
copyExternalImages - true, if external referenced content should be copied into the ZIP file, false otherwise.

getRootStream

public java.io.OutputStream getRootStream()
                                   throws java.io.IOException
The root stream is used to write the main HTML-File. Any external content is referenced from this file.

Specified by:
getRootStream in interface HtmlFilesystem
Returns:
the output stream of the main HTML file.
Throws:
java.io.IOException - if an IO error occured, while providing the root stream.

isSupportedImageFormat

protected boolean isSupportedImageFormat(java.net.URL url)
Tests, whether the given URL points to a supported file format for common browsers. Returns true if the URL references a JPEG, PNG or GIF image, false otherwise.

The checked filetypes are the ones recommended by the W3C.

Parameters:
url - the url that should be tested.
Returns:
true, if the content type is supported by the browsers, false otherwise.

createImageReference

public HtmlReferenceData createImageReference(ImageReference reference)
                                       throws java.io.IOException
Creates a HtmlReference for ImageData. If the target filesystem does not support this reference type, return an empty content reference, but never null.

Specified by:
createImageReference in interface HtmlFilesystem
Parameters:
reference - the image reference containing the data.
Returns:
the generated HtmlReference, never null.
Throws:
java.io.IOException - if IO errors occured while creating the reference.
See Also:
isSupportedImageFormat(java.net.URL)

createCSSReference

public HtmlReferenceData createCSSReference(java.lang.String styleSheet)
                                     throws java.io.IOException
Creates a HtmlReference for StyleSheetData. If the target filesystem does not support external stylesheets, return an inline stylesheet reference.

Specified by:
createCSSReference in interface HtmlFilesystem
Parameters:
styleSheet - the stylesheet data, which should be referenced.
Returns:
the generated HtmlReference, never null.
Throws:
java.io.IOException - if IO errors occured while creating the reference.

close

public void close()
           throws java.io.IOException
Close the Filesystem and write any buffered content. The filesystem will not be accessed, after close was called.

Specified by:
close in interface HtmlFilesystem
Throws:
java.io.IOException - if the close operation failed.