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

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

public class ZIPHtmlFilesystem
extends java.lang.Object
implements HtmlFilesystem

Similiar to the DirectoryHtmlFilesystem, the generated Html-File and the supplementary data files (images and external Stylesheet definition) into a directory in a ZIP-File. The data files can be written into a separated data directory within the ZIP-File.

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
ZIPHtmlFilesystem(java.io.OutputStream out, java.lang.String dataDirectory)
          Creates a new ZIPHtmlFilesystem.
 
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

ZIPHtmlFilesystem

public ZIPHtmlFilesystem(java.io.OutputStream out,
                         java.lang.String dataDirectory)
                  throws java.io.IOException
Creates a new ZIPHtmlFilesystem. The given output stream is used to write a generated Zip-File. The given data directory must denote a relative directory within the ZIP file.

Parameters:
out - the target output stream.
dataDirectory - the data directory, relative within the ZIP file.
Throws:
java.io.IOException - if an IO error occurs.
Method Detail

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.

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.

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.

If the image was generated during the report processing or is not in a commonly supported format, then the image is recoded as PNG and the recoded image is included in the data directory.

If external referenced data should be copied into the data directory, then the Image content is read and copied into the data directory.

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.