ccc.domain
Class FileEntity

java.lang.Object
  extended by ccc.domain.Entity
      extended by ccc.domain.ResourceEntity
          extended by ccc.domain.HistoricalResource<U,T>
              extended by ccc.domain.WorkingCopySupport<FileRevision,File,FileWorkingCopy>
                  extended by ccc.domain.FileEntity
All Implemented Interfaces:
Lockable, SnapshotSupport<Resource>, WCAware<File>, Jsonable, java.io.Serializable

public class FileEntity
extends WorkingCopySupport<FileRevision,File,FileWorkingCopy>

A file resource. This class encapsulates all file metadata. The raw file data is stored separately and can be accessed using the token stored in this class' #fileData() field.

Author:
Civic Computing Ltd.
See Also:
Serialized Form

Constructor Summary
protected FileEntity()
          Constructor: for persistence only.
  FileEntity(ResourceName name, java.lang.String title, java.lang.String description, Data data, long size, MimeType mimeType, java.util.Map<java.lang.String,java.lang.String> properties, RevisionMetadata metadata)
          Constructor.
  FileEntity(ResourceName name, java.lang.String title, java.lang.String description, Data data, long size, RevisionMetadata metadata)
          Constructor.
 
Method Summary
protected  FileWorkingCopy createWorkingCopy(File delta)
          Create a working copy from a delta.
 File deltaFile()
          Create a delta for a file.
 File forCurrentRevision()
          Create a snapshot for the current revision.
 File forSpecificRevision(int revNo)
          Create a snapshot for the specified revision.
 File forWorkingCopy()
          Create a snapshot for the working copy.
 java.lang.String getCharset()
          Accessor for text charset.
 Data getData()
          Accessor for the data field.
 java.lang.String getHeight()
          Accessor for image height.
 MimeType getMimeType()
          Accessor for mime type.
 java.util.Map<java.lang.String,java.lang.String> getProperties()
          Accessor for the properties field.
 ResourceType getType()
          Query the type of this resource.
 java.lang.String getWidth()
          Accessor for image width.
 boolean isExecutable()
          Determine if a file can be executed.
 boolean isImage()
          Query if this file is an image.
 boolean isText()
          Query if this file is a text file.
 File mapFile()
          Create a summary of a file.
static java.util.List<File> mapFiles(java.util.Collection<FileEntity> files)
          Create summaries for a collection of files.
 File mapTextFile(DataRepository dataRepo)
          Create a summary of a text file.
static java.lang.String read(DataRepository dm, File file)
          Helper method that reads a file's contents into a string.
static java.lang.String read(DataRepository dm, FileEntity file)
          Helper method that reads a file's contents into a string.
 long size()
          Accessor for size.
protected  void update(File delta, RevisionMetadata metadata)
          Update the resource from the specified delta.
 
Methods inherited from class ccc.domain.WorkingCopySupport
applyWorkingCopy, clearWorkingCopy, getOrCreateWorkingCopy, getWorkingCopy, hasWorkingCopy, setOrUpdateWorkingCopy, setWorkingCopy, setWorkingCopyFromRevision
 
Methods inherited from class ccc.domain.HistoricalResource
addRevision, currentRevision, currentRevisionNo, revision, revisions, toJson
 
Methods inherited from class ccc.domain.ResourceEntity
addGroupPermission, addMetadata, addMetadatum, addUserPermission, as, canUnlock, clearGroupAcl, clearMetadata, clearMetadatum, clearUserAcl, computeCache, computeMetadata, computeTemplate, confirmLock, delete, getAbsolutePath, getAcl, getCacheDuration, getChangedBy, getCreatedBy, getDateChanged, getDateCreated, getDescription, getGroupAcl, getIndex, getLockedBy, getMetadata, getMetadatum, getName, getParent, getPublishedBy, getRoot, getTags, getTemplate, getTitle, getUserAcl, isDeleted, isIncludedInMainMenu, isIndexable, isLocked, isPublished, isReadableBy, isSecure, isVisible, isWriteableBy, lock, mapResource, mapResources, publish, setCacheDuration, setDateChanged, setDateCreated, setDescription, setDtoProps, setIncludedInMainMenu, setIndexPosition, setName, setTags, setTemplate, setTitle, undelete, unlock, unpublish
 
Methods inherited from class ccc.domain.Entity
equals, getId, getVersion, hashCode, setId, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileEntity

protected FileEntity()
Constructor: for persistence only.


FileEntity

public FileEntity(ResourceName name,
                  java.lang.String title,
                  java.lang.String description,
                  Data data,
                  long size,
                  RevisionMetadata metadata)
Constructor. Assumes a mime type of "application/octet-stream".

Parameters:
name - The name of the file.
title - The title of the file.
description - The description of the file.
data - A token representing the binary content of the file.
size - The size of the file in bytes.
metadata - The metadata for the revision.

FileEntity

public FileEntity(ResourceName name,
                  java.lang.String title,
                  java.lang.String description,
                  Data data,
                  long size,
                  MimeType mimeType,
                  java.util.Map<java.lang.String,java.lang.String> properties,
                  RevisionMetadata metadata)
Constructor.

Parameters:
name - The name of the file.
title - The title of the file.
description - The description of the file.
data - A token representing the binary content of the file.
size - The size of the file in bytes.
mimeType - The mime type for the file.
properties - The properties of the file..
metadata - The metadata for the revision.
Method Detail

getType

public ResourceType getType()
Query the type of this resource.

Specified by:
getType in class ResourceEntity
Returns:
The ResourceType that describes this resource.

size

public long size()
Accessor for size.

Returns:
The size of the file in bytes, as a long.

getMimeType

public MimeType getMimeType()
Accessor for mime type. TODO: Make defensive copy?

Returns:
The mime type.

getData

public Data getData()
Accessor for the data field.

Returns:
The Data instance for this file.

getProperties

public java.util.Map<java.lang.String,java.lang.String> getProperties()
Accessor for the properties field.

Returns:
The Data instance for this file.

getCharset

public java.lang.String getCharset()
Accessor for text charset.

Returns:
Property value for charset.

getWidth

public java.lang.String getWidth()
Accessor for image width.

Returns:
Property value for width.

getHeight

public java.lang.String getHeight()
Accessor for image height.

Returns:
Property value for height.

isImage

public boolean isImage()
Query if this file is an image.

Returns:
True if the file is an image, false otherwise.

isText

public boolean isText()
Query if this file is a text file.

Returns:
True if the file is a text file, false otherwise.

isExecutable

public boolean isExecutable()
Determine if a file can be executed.

Returns:
True if the file can be executed, false otherwise.

update

protected void update(File delta,
                      RevisionMetadata metadata)
Update the resource from the specified delta.

Specified by:
update in class WorkingCopySupport<FileRevision,File,FileWorkingCopy>
Parameters:
delta - The delta to apply.
metadata - The metadata for the update.

createWorkingCopy

protected FileWorkingCopy createWorkingCopy(File delta)
Create a working copy from a delta.

Specified by:
createWorkingCopy in class WorkingCopySupport<FileRevision,File,FileWorkingCopy>
Parameters:
delta - The delta for the working copy.
Returns:
The new working copy.

forWorkingCopy

public final File forWorkingCopy()
Create a snapshot for the working copy.

Returns:
A read-only snapshot of the resource.

forCurrentRevision

public final File forCurrentRevision()
Create a snapshot for the current revision.

Returns:
A read-only snapshot of the resource.

forSpecificRevision

public final File forSpecificRevision(int revNo)
Create a snapshot for the specified revision.

Parameters:
revNo - The revision to create a snapshot for.
Returns:
A read-only snapshot of the resource.

mapFile

public File mapFile()
Create a summary of a file.

Returns:
The summary of the file.

mapTextFile

public File mapTextFile(DataRepository dataRepo)
Create a summary of a text file.

Parameters:
dataRepo - The repository used to read the file's data.
Returns:
The summary of the file.

mapFiles

public static java.util.List<File> mapFiles(java.util.Collection<FileEntity> files)
Create summaries for a collection of files.

Parameters:
files - The files.
Returns:
The corresponding summaries.

deltaFile

public File deltaFile()
Create a delta for a file.

Returns:
A corresponding delta.

read

public static java.lang.String read(DataRepository dm,
                                    FileEntity file)
Helper method that reads a file's contents into a string.

Parameters:
dm - The file repository.
file - The file to read.
Returns:
The file's contents as a string.

read

public static java.lang.String read(DataRepository dm,
                                    File file)
Helper method that reads a file's contents into a string. TODO: Move to the File class?

Parameters:
dm - The file repository.
file - The file to read.
Returns:
The file's contents as a string.


Copyright © 2010. All Rights Reserved.