org.mycore.datamodel.ifs
Class MCRFile

java.lang.Object
  extended by org.mycore.datamodel.ifs.MCRFilesystemNode
      extended by org.mycore.datamodel.ifs.MCRFile
All Implemented Interfaces:
MCRFileReader

public class MCRFile
extends MCRFilesystemNode
implements MCRFileReader

Represents a stored file with its metadata and content.

Version:
$Revision: 14528 $ $Date: 2008-12-09 17:45:41 +0100 (Di, 09 Dez 2008) $
Author:
Frank Lützenkirchen

Field Summary
protected  MCRAudioVideoExtender avExtender
          The optional extender for streaming audio/video files
protected  String contentTypeID
          The ID of the content type of this file
protected  boolean isNew
          Is true if this file is a new MCRFile and not retrieved from store *
protected  String md5
          The md5 checksum that was built when content was read for this file
protected  String storageID
          The ID that identifies the place where the store holds the content
protected  String storeID
          The ID of the store that holds this file's content
 
Fields inherited from class org.mycore.datamodel.ifs.MCRFilesystemNode
deleted, formatter, ID, label, lastModified, manager, name, ownerID, parentID, size
 
Constructor Summary
MCRFile(String name, MCRDirectory parent)
          Creates a new, empty MCRFile with the given filename in the parent MCRDirectory.
MCRFile(String name, MCRDirectory parent, boolean doExistCheck)
          Creates a new, empty MCRFile with the given filename in the parent MCRDirectory.
MCRFile(String name, String ownerID)
          Creates a new and empty root MCRFile with the given filename, belonging to the given ownerID.
MCRFile(String ID, String parentID, String ownerID, String name, String label, long size, GregorianCalendar date, String storeID, String storageID, String fctID, String md5)
          Internal constructor, do not use on your own.
 
Method Summary
 Document createXML()
          Build a XML representation of all technical metadata of this MCRFile and its MCRAudioVideoExtender, if present.
 void delete()
          Deletes this file and its content stored in the system.
 MCRAudioVideoExtender getAudioVideoExtender()
          Returns the AudioVideoExtender in case this file is streaming audio/video and stored in a ContentStore that supports this
 byte[] getContentAsByteArray()
          Gets the content of this file as a byte array
 InputStream getContentAsInputStream()
          Gets an InputStream to read the content of this file from the underlying store.
 Document getContentAsJDOM()
           
 String getContentAsString()
          Gets the content of this file as a string, using the default encoding of the system environment
 String getContentAsString(String encoding)
          Gets the content of this file as a string, using the given encoding
protected  MCRContentStore getContentStore()
          Returns the MCRContentStore instance that holds the content of this file
 void getContentTo(File target)
          Writes the content of this file to a file on the local filesystem
 void getContentTo(OutputStream target)
          Writes the content of this file to a target output stream.
 MCRFileContentType getContentType()
          Gets the content type of this file
 String getContentTypeID()
          Gets the ID of the content type of this file
 String getExtension()
          Returns the file extension of this file's name
static MCRFile getFile(String ID)
          Returns the MCRFile with the given ID.
 String getMD5()
          Returns the MD5 checksum for this file
static MCRFile getRootFile(String ownerID)
          Returns the root MCRFile that has no parent and is logically owned by the object with the given ID.
 String getStorageID()
          Returns the storage ID that identifies the place where the MCRContentStore has stored the content of this file
 String getStoreID()
          Returns the ID of the MCRContentStore implementation that holds the content of this file
 boolean hasAudioVideoExtender()
          Returns true, if this file is stored in a content store that provides an MCRAudioVideoExtender for audio/video streaming and additional metadata
 void setContentFrom(byte[] source)
          Reads the content of this file from a byte array and stores it in an MCRContentStore.
 void setContentFrom(Document xml)
          Sets the content of this file from a JDOM xml document.
 void setContentFrom(File source)
          Reads the content of this file from a source file in the local filesystem and stores it in an MCRContentStore.
 void setContentFrom(InputStream source)
          Reads the content of this file from the source InputStream and stores it in an MCRContentStore.
 long setContentFrom(InputStream source, boolean storeContentChange)
           
 void setContentFrom(String source)
          Reads the content of this file from a java.lang.String and stores its text as bytes, encoded in the default encoding of the platform where this is running.
 void setContentFrom(String source, String encoding)
          Reads the content of this file from a java.lang.String and stores its text as bytes, encoded in the encoding given, in an MCRContentStore.
 void storeContentChange(long sizeDiff)
           
 String toString()
           
 
Methods inherited from class org.mycore.datamodel.ifs.MCRFilesystemNode
checkName, ensureNotDeleted, getAbsolutePath, getAdditionalData, getAllAdditionalData, getID, getLabel, getLastModified, getName, getNode, getOwnerID, getParent, getParentID, getPath, getRootDirectory, getRootNode, getSize, getSizeFormatted, getSizeFormatted, hasParent, removeAdditionalData, removeAllAdditionalData, setAdditionalData, setLabel, setName, storeNew
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mycore.datamodel.ifs.MCRFileReader
getID, getPath, getSize
 

Field Detail

storeID

protected String storeID
The ID of the store that holds this file's content


storageID

protected String storageID
The ID that identifies the place where the store holds the content


contentTypeID

protected String contentTypeID
The ID of the content type of this file


md5

protected String md5
The md5 checksum that was built when content was read for this file


avExtender

protected MCRAudioVideoExtender avExtender
The optional extender for streaming audio/video files


isNew

protected boolean isNew
Is true if this file is a new MCRFile and not retrieved from store *

Constructor Detail

MCRFile

public MCRFile(String name,
               String ownerID)
Creates a new and empty root MCRFile with the given filename, belonging to the given ownerID. The file is assumed to be a standalone "root file" that has no parent directory.

Parameters:
name - the filename of the new MCRFile
ownerID - any ID String of the logical owner of this file

MCRFile

public MCRFile(String name,
               MCRDirectory parent)
Creates a new, empty MCRFile with the given filename in the parent MCRDirectory.

Parameters:
name - the filename of the new MCRFile
parent - the parent directory that will contain the new child
Throws:
MCRUsageException - if that directory already contains a child with that name

MCRFile

public MCRFile(String name,
               MCRDirectory parent,
               boolean doExistCheck)
Creates a new, empty MCRFile with the given filename in the parent MCRDirectory.

Parameters:
name - the filename of the new MCRFile
parent - the parent directory that will contain the new child
doExistCheck - checks if file with that Name already exists
Throws:
MCRUsageException - if that directory already contains a child with that name

MCRFile

MCRFile(String ID,
        String parentID,
        String ownerID,
        String name,
        String label,
        long size,
        GregorianCalendar date,
        String storeID,
        String storageID,
        String fctID,
        String md5)
Internal constructor, do not use on your own.

Method Detail

getFile

public static MCRFile getFile(String ID)
Returns the MCRFile with the given ID.

Parameters:
ID - the unique ID of the MCRFile to return
Returns:
the MCRFile with the given ID, or null if no such file exists

getRootFile

public static MCRFile getRootFile(String ownerID)
Returns the root MCRFile that has no parent and is logically owned by the object with the given ID.

Parameters:
ownerID - the ID of the logical owner of that file
Returns:
the root MCRFile stored for that owner ID, or null if no such file exists

getExtension

public String getExtension()
Returns the file extension of this file's name

Specified by:
getExtension in interface MCRFileReader
Returns:
the file extension, or an empty string if the file has no extension

getMD5

public String getMD5()
Returns the MD5 checksum for this file


getStoreID

public String getStoreID()
Returns the ID of the MCRContentStore implementation that holds the content of this file

Specified by:
getStoreID in interface MCRFileReader

getStorageID

public String getStorageID()
Returns the storage ID that identifies the place where the MCRContentStore has stored the content of this file

Specified by:
getStorageID in interface MCRFileReader

getContentStore

protected MCRContentStore getContentStore()
Returns the MCRContentStore instance that holds the content of this file

Returns:
the MCRContentStore instance that holds the content of this file, or null if no content is stored

setContentFrom

public void setContentFrom(String source)
                    throws MCRPersistenceException
Reads the content of this file from a java.lang.String and stores its text as bytes, encoded in the default encoding of the platform where this is running.

Parameters:
source - the String that is the file's content
Throws:
MCRPersistenceException

setContentFrom

public void setContentFrom(String source,
                           String encoding)
                    throws MCRPersistenceException,
                           UnsupportedEncodingException
Reads the content of this file from a java.lang.String and stores its text as bytes, encoded in the encoding given, in an MCRContentStore.

Parameters:
source - the String that is the file's content
encoding - the character encoding to use to store the String as bytes
Throws:
MCRPersistenceException
UnsupportedEncodingException

setContentFrom

public void setContentFrom(File source)
                    throws MCRPersistenceException
Reads the content of this file from a source file in the local filesystem and stores it in an MCRContentStore.

Parameters:
source - the file in the local host's filesystem thats content should be imported
Throws:
MCRPersistenceException

setContentFrom

public void setContentFrom(byte[] source)
                    throws MCRPersistenceException
Reads the content of this file from a byte array and stores it in an MCRContentStore.

Parameters:
source - the file's content
Throws:
MCRPersistenceException

setContentFrom

public void setContentFrom(Document xml)
Sets the content of this file from a JDOM xml document.

Parameters:
xml - the JDOM xml document that should be stored as file content

setContentFrom

public void setContentFrom(InputStream source)
                    throws MCRPersistenceException
Reads the content of this file from the source InputStream and stores it in an MCRContentStore. InputStream does NOT get closed at end of process, this must be done by invoking code if required/appropriate.

Parameters:
source - the source for the file's content bytes
Throws:
MCRPersistenceException

setContentFrom

public long setContentFrom(InputStream source,
                           boolean storeContentChange)
                    throws MCRPersistenceException
Throws:
MCRPersistenceException

storeContentChange

public void storeContentChange(long sizeDiff)

delete

public void delete()
            throws MCRPersistenceException
Deletes this file and its content stored in the system. Note that after calling this method, the file object is deleted and invalid and can not be used any more.

Overrides:
delete in class MCRFilesystemNode
Throws:
MCRPersistenceException

getContentAsInputStream

public InputStream getContentAsInputStream()
                                    throws IOException
Gets an InputStream to read the content of this file from the underlying store. It is important that you close() the stream when you are finished reading content from it.

Returns:
an InputStream to read the file's content from
Throws:
IOException

getContentTo

public void getContentTo(OutputStream target)
                  throws MCRPersistenceException
Writes the content of this file to a target output stream.

Parameters:
target - the output stream to write the content to
Throws:
MCRPersistenceException

getContentTo

public void getContentTo(File target)
                  throws MCRPersistenceException,
                         IOException
Writes the content of this file to a file on the local filesystem

Parameters:
target - the local file to write the content to
Throws:
MCRPersistenceException
IOException

getContentAsByteArray

public byte[] getContentAsByteArray()
                             throws MCRPersistenceException
Gets the content of this file as a byte array

Returns:
the content of this file as a byte array
Throws:
MCRPersistenceException

getContentAsString

public String getContentAsString()
                          throws MCRPersistenceException
Gets the content of this file as a string, using the default encoding of the system environment

Returns:
the file's content as a String
Throws:
MCRPersistenceException

getContentAsString

public String getContentAsString(String encoding)
                          throws MCRPersistenceException,
                                 UnsupportedEncodingException
Gets the content of this file as a string, using the given encoding

Parameters:
encoding - the character encoding to use
Returns:
the file's content as a String
Throws:
MCRPersistenceException
UnsupportedEncodingException

getContentAsJDOM

public Document getContentAsJDOM()
                          throws MCRPersistenceException,
                                 IOException,
                                 JDOMException
Throws:
MCRPersistenceException
IOException
JDOMException

hasAudioVideoExtender

public boolean hasAudioVideoExtender()
Returns true, if this file is stored in a content store that provides an MCRAudioVideoExtender for audio/video streaming and additional metadata


getAudioVideoExtender

public MCRAudioVideoExtender getAudioVideoExtender()
Returns the AudioVideoExtender in case this file is streaming audio/video and stored in a ContentStore that supports this


getContentTypeID

public String getContentTypeID()
Gets the ID of the content type of this file

Specified by:
getContentTypeID in interface MCRFileReader

getContentType

public MCRFileContentType getContentType()
Gets the content type of this file

Specified by:
getContentType in interface MCRFileReader

toString

public String toString()
Overrides:
toString in class MCRFilesystemNode

createXML

public Document createXML()
Build a XML representation of all technical metadata of this MCRFile and its MCRAudioVideoExtender, if present. That xml can be used for indexing this data.