org.liquidsite.core.content
Class ContentFile

java.lang.Object
  extended byorg.liquidsite.core.content.PersistentObject
      extended byorg.liquidsite.core.content.Content
          extended byorg.liquidsite.core.content.ContentFile

public class ContentFile
extends Content

A web site file.


Field Summary
 
Fields inherited from class org.liquidsite.core.content.Content
DOCUMENT_CATEGORY, FILE_CATEGORY, FOLDER_CATEGORY, FORUM_CATEGORY, NAME_CHARS, PAGE_CATEGORY, POST_CATEGORY, SECTION_CATEGORY, SITE_CATEGORY, TEMPLATE_CATEGORY, TOPIC_CATEGORY, TRANSLATOR_CATEGORY
 
Fields inherited from class org.liquidsite.core.content.PersistentObject
BINDERS, LOWER_CASE, NUMBERS, UPPER_CASE
 
Constructor Summary
protected ContentFile(ContentManager manager, ContentData data, DataSource src)
          Creates a new file.
  ContentFile(ContentManager manager, Content parent, java.lang.String name)
          Creates a new file with default values.
 
Method Summary
 void deleteRevision(User user)
          Deletes this content revision from the database.
protected  void doDelete(DataSource src, User user)
          Deletes the object data from the database.
protected  void doUpdate(DataSource src, User user)
          Updates the object data in the database.
protected  void doValidate()
          Validates the object data before writing to the database.
 java.io.File getFile()
          Returns the file used for storing the data content.
 java.lang.String getFileName()
          Returns the file name.
 java.lang.String getMimeType(javax.servlet.ServletContext context)
          Returns the MIME type of the file.
static java.lang.String getMimeType(javax.servlet.ServletContext context, java.lang.String fileName)
          Returns the MIME type of a file.
 java.lang.String getTextContent(javax.servlet.ServletContext context)
          Returns the text content of a file.
 void setFileName(java.lang.String name)
          Sets the file name.
 void setTextContent(java.lang.String content)
          Sets the content of the file to the specified string.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class org.liquidsite.core.content.Content
doInsert, equals, equals, getAllRevisions, getAttribute, getAttributeNames, getAuthor, getAuthorName, getCategory, getComment, getDomain, getDomainName, getId, getLock, getMaxRevisionNumber, getModifiedDate, getName, getOfflineDate, getOnlineDate, getParent, getParentId, getPermissions, getRevision, getRevisionNumber, isLatestRevision, isOnline, isPublishedRevision, setAttribute, setAuthorName, setComment, setId, setModifiedDate, setName, setOfflineDate, setOnlineDate, setParent, setParentId, setRevisionNumber
 
Methods inherited from class org.liquidsite.core.content.PersistentObject
decodeMap, delete, delete, encodeMap, getContentManager, hasAdminAccess, hasPublishAccess, hasReadAccess, hasWriteAccess, isPersistent, restore, restore, save, save, validateChars, validateSize
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ContentFile

public ContentFile(ContentManager manager,
                   Content parent,
                   java.lang.String name)
            throws ContentException
Creates a new file with default values.

Parameters:
manager - the content manager to use
parent - the parent content object
name - the file name
Throws:
ContentException - if the database couldn't be accessed properly

ContentFile

protected ContentFile(ContentManager manager,
                      ContentData data,
                      DataSource src)
               throws ContentException
Creates a new file.

Parameters:
manager - the content manager to use
data - the content data object
src - the data source to use
Throws:
ContentException - if the database couldn't be accessed properly
Method Detail

getMimeType

public static java.lang.String getMimeType(javax.servlet.ServletContext context,
                                           java.lang.String fileName)
Returns the MIME type of a file. The MIME types are configured in the servlet context.

Parameters:
context - the servlet context
fileName - the file name
Returns:
the MIME type of the file, or a default binary MIME type if unknown

toString

public java.lang.String toString()
Returns a string representation of this object.

Overrides:
toString in class Content
Returns:
a string representation of this object

getFile

public java.io.File getFile()
                     throws ContentException
Returns the file used for storing the data content. Note that this method cannot be called before writing the file content object to the database, as it requires the content id to create a unique file name.

Returns:
the file used for storing the data content
Throws:
ContentException - if the content base directory wasn't found or couldn't be created

getFileName

public java.lang.String getFileName()
Returns the file name. This is the unique file name stored in the database, and used to access the actual file in the content object directory. Note that the file name does NOT contain the path of the file.

Returns:
the file name.

setFileName

public void setFileName(java.lang.String name)
                 throws ContentException
Sets the file name. Note that the specified file name will only be used to create the new unique file name that will actually be used. Also note that an previous file will NOT be renamed, effectively making getFile() return a non-existent file. After changing the file name, the desired data must be written to the new file. This method has the same requirements as getFile().

Parameters:
name - the new file name
Throws:
ContentException - if the content base directory wasn't found or couldn't be created
See Also:
getFile()

getMimeType

public java.lang.String getMimeType(javax.servlet.ServletContext context)
Returns the MIME type of the file. The MIME types are configured in the servlet context.

Parameters:
context - the servlet context
Returns:
the MIME type of the file, or a default binary MIME type if unknown

getTextContent

public java.lang.String getTextContent(javax.servlet.ServletContext context)
                                throws ContentException
Returns the text content of a file. If the file isn't a text file or if the file size is too big, null will be returned. Also, if the text in the file isn't encoded as UTF-8, null will be returned.

Parameters:
context - the servlet context (for the MIME type)
Returns:
the text file contents, or null for non-text files
Throws:
ContentException - if the file data couldn't be read properly

setTextContent

public void setTextContent(java.lang.String content)
                    throws ContentException
Sets the content of the file to the specified string. If the file doesn't exist it will be created, otherwise overwritten.

Parameters:
content - the new file contents
Throws:
ContentException - if the file data couldn't be written properly

deleteRevision

public void deleteRevision(User user)
                    throws ContentException,
                           ContentSecurityException
Deletes this content revision from the database.

Overrides:
deleteRevision in class Content
Parameters:
user - the user performing the operation
Throws:
ContentException - if the database couldn't be accessed properly
ContentSecurityException - if the user specified didn't have write permissions

doValidate

protected void doValidate()
                   throws ContentException
Validates the object data before writing to the database.

Overrides:
doValidate in class Content
Throws:
ContentException - if the object data wasn't valid

doUpdate

protected void doUpdate(DataSource src,
                        User user)
                 throws ContentException
Updates the object data in the database.

Overrides:
doUpdate in class Content
Parameters:
src - the data source to use
user - the user performing the operation
Throws:
ContentException - if the object data didn't validate or if the database couldn't be accessed properly

doDelete

protected void doDelete(DataSource src,
                        User user)
                 throws ContentException
Deletes the object data from the database.

Overrides:
doDelete in class Content
Parameters:
src - the data source to use
user - the user performing the operation
Throws:
ContentException - if the database couldn't be accessed properly