org.hd.d.pg2k.svrCore.MIME
Class ExhibitMIME

java.lang.Object
  extended by org.hd.d.pg2k.svrCore.MIME.ExhibitMIME

public final class ExhibitMIME
extends java.lang.Object

Routines to establish/check exhibit MIME types. This is hard-wired into the Gallery for now; we don't allow dynamic loading of new types and handlers...

This is a rewrite and extension of the old (pre-PG2K) PG Attributes class.


Nested Class Summary
static class ExhibitMIME.ExhibitTypeParameters
          JavaBean outlining file details of one Gallery exhibit item type.
 
Field Summary
private static java.util.Hashtable<java.lang.String,ExhibitMIME.ExhibitTypeParameters> _gET_cache
          Private cache of mappings from extension to parameters.
private static ExhibitMIME.ExhibitTypeParameters[] _gFPBT_cache
          Private cache of mappings from type to parameters.
private static java.util.Hashtable<java.lang.String,ExhibitMIME.ExhibitTypeParameters> _iVIFE_cache
          Private cache of mappings from extension to parameters.
static java.lang.String DEFAULT_HANDLER_PACKAGE
          Package for default media handlers.
static int ET__max
          Maximum valid ET_XXX value (these values may be sparse).
static int ET__min
          Minimum valid ET_XXX value (these values may be sparse).
static int ET_3GP
          Type of 3GPP file.
static int ET_AU
          Type of Sun audio (usually 64kbps 8-bit u-law G.711) file.
static int ET_AVI
          Type of RealMedia file.
static int ET_BMP
          Type of BMP image file.
static int ET_GIF
          Type of GIF file.
static int ET_HTMLFRAG
          Type of HTML text fragment file.
static int ET_JP2
          Type of JPEG-2000 image file.
static int ET_JPEG
          Type of JPEG file.
static int ET_MIDI
          Type of General MIDI audio file.
static int ET_MNG
          Type of MNG (GIF-replacement) file.
static int ET_MOV
          Type of QuickTime movie file.
static int ET_MP2
          Type of MPEG-1 Layer-II audio file.
static int ET_MP3
          Type of MPEG-1 or MPEG-2 or MPEG-2.5 Layer-III audio file (8kbps and up).
static int ET_MP4
          Type of MPEG-4 audio file (2kbps and up).
static int ET_MPEG
          Type of MPEG video file.
static int ET_PDF
          Type of PDF file.
static int ET_PNG
          Type of PNG (GIF-replacement) file.
static int ET_PPT
          Type of PowerPoint presentation file.
static int ET_RM
          Type of RealMedia file.
static int ET_RTF
          Type of Windows Rich Text Format file.
static int ET_SWF
          Type of Flash file.
static int ET_TBZ2
          Type of BZIP2ed tar archive file.
static int ET_TGZ
          Type of GZIPped tar archive file.
static int ET_TIFF
          Type of TIFF image file.
static int ET_TRML
          Type of Gallery 'trail' marked-up text file.
static int ET_WAV
          Type of WAV audio file.
static int ET_WMV
          Type of Windows Movie file.
static int ET_ZIP
          Type of ZIP archive file.
private static ExhibitMIME.ExhibitTypeParameters[] inputFileTypes
          File types accepted by (and generated by) the Gallery.
private static int longestMagicBytes
          The longest known magic number in bytes of any exhibit type supported; strictly positive once computed.
 
Constructor Summary
ExhibitMIME()
           
 
Method Summary
static void checkMagicOK(ExhibitMIME.ExhibitTypeParameters etp, java.io.File file)
          Checks that file has expected magic number; throws IOException if not.
static ExhibitMIME.ExhibitTypeParameters[] getAllValidExhibitTypes()
          Returns a (private) list of all valid exhibit types, in order by type.
static ExhibitMIME.ExhibitTypeParameters getExhibitType(java.lang.String extension)
          Gets type of an exhibit given its extension.
static ExhibitMIME.ExhibitTypeParameters getInputFileType(java.lang.CharSequence name)
          Gets the type of a file from its name, or null if unrecognised here.
static int getLongestMagicBytes()
          Get longest known magic number in bytes of any exhibit type supported; strictly positive.
static java.lang.String getMIMEType(java.lang.CharSequence name)
          Get the MIME type of an exhibit (even at the end of filename or URI or URL) from its name; never null nor "".
static ExhibitMIME.ExhibitTypeParameters getParamsByType(int type)
          Given an ET_XXX type, returns the ExhibitTypeParameters.
static ExhibitMIME.ExhibitTypeParameters guessTypeFromMagic(java.io.InputStream is)
          Guesses the type of a file/exhibit from its magic number, or null if unrecognisable.
static ExhibitMIME.ExhibitTypeParameters isValidInputExhibitNameExtension(java.lang.CharSequence extension)
          Checks if the extension of the (putative) exhibit name is a recognised input extension.
static boolean magicOK(ExhibitMIME.ExhibitTypeParameters etp, java.io.InputStream exhibitByteStream)
          Verifies the magic number for a given exhibit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_HANDLER_PACKAGE

public static final java.lang.String DEFAULT_HANDLER_PACKAGE
Package for default media handlers.

See Also:
Constant Field Values

ET_GIF

public static final int ET_GIF
Type of GIF file.

See Also:
Constant Field Values

ET_JPEG

public static final int ET_JPEG
Type of JPEG file.

See Also:
Constant Field Values

ET_AU

public static final int ET_AU
Type of Sun audio (usually 64kbps 8-bit u-law G.711) file.

See Also:
Constant Field Values

ET_MP2

public static final int ET_MP2
Type of MPEG-1 Layer-II audio file.

See Also:
Constant Field Values

ET_MP3

public static final int ET_MP3
Type of MPEG-1 or MPEG-2 or MPEG-2.5 Layer-III audio file (8kbps and up).

See Also:
Constant Field Values

ET_MP4

public static final int ET_MP4
Type of MPEG-4 audio file (2kbps and up).

See Also:
Constant Field Values

ET_MIDI

public static final int ET_MIDI
Type of General MIDI audio file.

See Also:
Constant Field Values

ET_WAV

public static final int ET_WAV
Type of WAV audio file.

See Also:
Constant Field Values

ET_HTMLFRAG

public static final int ET_HTMLFRAG
Type of HTML text fragment file.

See Also:
Constant Field Values

ET_MPEG

public static final int ET_MPEG
Type of MPEG video file.

See Also:
Constant Field Values

ET_TIFF

public static final int ET_TIFF
Type of TIFF image file.

See Also:
Constant Field Values

ET_BMP

public static final int ET_BMP
Type of BMP image file.

See Also:
Constant Field Values

ET_PPT

public static final int ET_PPT
Type of PowerPoint presentation file.

See Also:
Constant Field Values

ET_RM

public static final int ET_RM
Type of RealMedia file.

See Also:
Constant Field Values

ET_AVI

public static final int ET_AVI
Type of RealMedia file.

See Also:
Constant Field Values

ET_PNG

public static final int ET_PNG
Type of PNG (GIF-replacement) file.

See Also:
Constant Field Values

ET_MNG

public static final int ET_MNG
Type of MNG (GIF-replacement) file.

See Also:
Constant Field Values

ET_JP2

public static final int ET_JP2
Type of JPEG-2000 image file.

See Also:
Constant Field Values

ET_SWF

public static final int ET_SWF
Type of Flash file.

See Also:
Constant Field Values

ET_PDF

public static final int ET_PDF
Type of PDF file.

See Also:
Constant Field Values

ET_3GP

public static final int ET_3GP
Type of 3GPP file.

See Also:
Constant Field Values

ET_WMV

public static final int ET_WMV
Type of Windows Movie file.

See Also:
Constant Field Values

ET_RTF

public static final int ET_RTF
Type of Windows Rich Text Format file.

See Also:
Constant Field Values

ET_TRML

public static final int ET_TRML
Type of Gallery 'trail' marked-up text file.

See Also:
Constant Field Values

ET_ZIP

public static final int ET_ZIP
Type of ZIP archive file.

See Also:
Constant Field Values

ET_TGZ

public static final int ET_TGZ
Type of GZIPped tar archive file.

See Also:
Constant Field Values

ET_TBZ2

public static final int ET_TBZ2
Type of BZIP2ed tar archive file.

See Also:
Constant Field Values

ET_MOV

public static final int ET_MOV
Type of QuickTime movie file.

See Also:
Constant Field Values

ET__min

public static final int ET__min
Minimum valid ET_XXX value (these values may be sparse). Guaranteed strictly positive.

See Also:
Constant Field Values

ET__max

public static final int ET__max
Maximum valid ET_XXX value (these values may be sparse). Guaranteed to be no less than ET__min.

See Also:
Constant Field Values

inputFileTypes

private static final ExhibitMIME.ExhibitTypeParameters[] inputFileTypes
File types accepted by (and generated by) the Gallery. Not to be handed outside the gallery in this raw state. Not necessarily in numeric order at construction here, but sorted as part of the static initialiser.


_iVIFE_cache

private static final java.util.Hashtable<java.lang.String,ExhibitMIME.ExhibitTypeParameters> _iVIFE_cache
Private cache of mappings from extension to parameters. Used by isValidInputExhibitNameExtension(), and filled in under protection of its own lock on first use if zero-sized.

Fixed small size.


_gET_cache

private static final java.util.Hashtable<java.lang.String,ExhibitMIME.ExhibitTypeParameters> _gET_cache
Private cache of mappings from extension to parameters. Used by isValidInputExhibitNameExtension(), and filled in under protection of its own lock on first use if zero-sized.

Fixed small size.


longestMagicBytes

private static volatile int longestMagicBytes
The longest known magic number in bytes of any exhibit type supported; strictly positive once computed. Volatile to allow access without a lock.

Computed on first use.


_gFPBT_cache

private static ExhibitMIME.ExhibitTypeParameters[] _gFPBT_cache
Private cache of mappings from type to parameters. Constructed on first use by getParamsByType().

Fixed small size.

Constructor Detail

ExhibitMIME

public ExhibitMIME()
Method Detail

getAllValidExhibitTypes

public static ExhibitMIME.ExhibitTypeParameters[] getAllValidExhibitTypes()
Returns a (private) list of all valid exhibit types, in order by type.


isValidInputExhibitNameExtension

public static ExhibitMIME.ExhibitTypeParameters isValidInputExhibitNameExtension(java.lang.CharSequence extension)
Checks if the extension of the (putative) exhibit name is a recognised input extension. The string should not be null, nor start with a dot. (A null input gives a null return.)

This returns null if the extension is not recognised, else the (immutable) ExhibitTypeParameters describing it.


getExhibitType

public static ExhibitMIME.ExhibitTypeParameters getExhibitType(java.lang.String extension)
Gets type of an exhibit given its extension. The string passed must not be null, nor start with a dot.

This returns null if the extension is not recognised, else the (immutable) ExhibitTypeParameters describing the exhibit type.

This checks first by the primary suffix for each exhibit type, but if that fails may check by secondary suffix.


magicOK

public static boolean magicOK(ExhibitMIME.ExhibitTypeParameters etp,
                              java.io.InputStream exhibitByteStream)
Verifies the magic number for a given exhibit. This will try to read enough data to check the magic number.

Returns false if the magic number check fails.

If the file type specified has no unique magic number to be checked this always succeeds.

This function does not close the input stream.

Parameters:
etp - is the exhibit type (must not be null)
exhibitByteStream - is a stream of bytes from the start of the exhibit at least long enough to contain the magic number

checkMagicOK

public static void checkMagicOK(ExhibitMIME.ExhibitTypeParameters etp,
                                java.io.File file)
                         throws java.io.IOException,
                                java.io.InvalidObjectException
Checks that file has expected magic number; throws IOException if not.

Throws:
java.io.InvalidObjectException - if given file does not have a correct magic number
java.io.IOException - in case of difficulty reading the file

getLongestMagicBytes

public static int getLongestMagicBytes()
Get longest known magic number in bytes of any exhibit type supported; strictly positive.


guessTypeFromMagic

public static ExhibitMIME.ExhibitTypeParameters guessTypeFromMagic(java.io.InputStream is)
                                                            throws java.io.IOException
Guesses the type of a file/exhibit from its magic number, or null if unrecognisable. This may only be able to check for files that have a unique magic number.

The stream may need to be markable to allow various possibilities to be tested.

Throws:
java.io.IOException

getInputFileType

public static ExhibitMIME.ExhibitTypeParameters getInputFileType(java.lang.CharSequence name)
Gets the type of a file from its name, or null if unrecognised here. The string passed must not be null, nor start with a dot.

This returns null if the extension is not recognised for an exhibit, else returns the (immutable) ExhibitTypeParameters describing it.

The extension should be for an exhibit input, though this can be called to quickly check if a filename or URI might be for an exhibit, returning null if not.

Parameters:
name - name of file or URL/URI

getParamsByType

public static ExhibitMIME.ExhibitTypeParameters getParamsByType(int type)
Given an ET_XXX type, returns the ExhibitTypeParameters. Throws IllegalArgumentException for an illegal type.


getMIMEType

public static java.lang.String getMIMEType(java.lang.CharSequence name)
                                    throws java.io.IOException
Get the MIME type of an exhibit (even at the end of filename or URI or URL) from its name; never null nor "".

Throws:
java.io.IOException

DHD Multimedia Gallery V1.57.21

Copyright (c) 1996-2011, Damon Hart-Davis. All rights reserved.