org.silverpeas.file
Class SilverpeasFile

java.lang.Object
  extended by java.io.File
      extended by org.silverpeas.file.SilverpeasFile
All Implemented Interfaces:
Serializable, Comparable<File>

public class SilverpeasFile
extends File

A representation of a File in Silverpeas. This class abstracts the way the files are managed in Silverpeas by extending the original JDK file with additional features. A file in Silverpeas belongs always to a component instance and is qualified by its MIME type.

Such file can be either a document referred by a publication's attachment or an image from a form.

Author:
mmoquillon
See Also:
Serialized Form

Field Summary
static SilverpeasFile NO_FILE
          A SilverpeasFile representing a non existent file.
 
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
 
Constructor Summary
protected SilverpeasFile(String componentId, String path)
          Creates a new Silverpeas file beloging to the specified component instance and located at the specified path in the Silverpeas filesystem.
protected SilverpeasFile(String componentId, String path, String mimeType)
          Creates a new Silverpeas file beloging to the specified component instance and located at the specified path in the Silverpeas filesystem.
 
Method Summary
 SilverpeasFile copyInto(String directoryPath)
          Copies this file into the specified directory.
 boolean delete()
           
 boolean exists()
           
 String getComponentInstanceId()
           
 String getMimeType()
           
 InputStream inputStream()
          Opens and returns an input stream to this file.
 boolean isArchive()
          Indicates if the current silverpeas file is of type archive.
 boolean isFileSecure()
           
 boolean isImage()
          Indicates if the current file is of type image.
 boolean isMail()
          Indicates if the current file is of type mail.
 boolean isOpenOfficeCompatible()
          Indicates if the current file is of type OpenOffice compatible.
 boolean isPdf()
          Indicates if the current file is of type PDF.
 SilverpeasFile moveInto(String directoryPath)
          Moves this file into the specified directory.
 void writeFrom(InputStream stream)
          Writes the content of the specified input stream into this file.
 
Methods inherited from class java.io.File
canExecute, canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, deleteOnExit, equals, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getFreeSpace, getName, getParent, getParentFile, getPath, getTotalSpace, getUsableSpace, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setExecutable, setExecutable, setLastModified, setReadable, setReadable, setReadOnly, setWritable, setWritable, toString, toURI, toURL
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_FILE

public static final SilverpeasFile NO_FILE
A SilverpeasFile representing a non existent file. It is better to work with it than taking into account a FileNotFoundException exception raising.

Constructor Detail

SilverpeasFile

protected SilverpeasFile(String componentId,
                         String path)
Creates a new Silverpeas file beloging to the specified component instance and located at the specified path in the Silverpeas filesystem. The MIME type of the file is detected.

Parameters:
componentId - the unique identifier of the component instance.
path - the absolute path of the file.

SilverpeasFile

protected SilverpeasFile(String componentId,
                         String path,
                         String mimeType)
Creates a new Silverpeas file beloging to the specified component instance and located at the specified path in the Silverpeas filesystem. The exact MIME type of the file is also specified.

Parameters:
componentId - the unique identifier of the component instance.
path - the absolute path of the file.
mimeType - the MIME type of the file.
Method Detail

getMimeType

public String getMimeType()

getComponentInstanceId

public String getComponentInstanceId()

exists

public boolean exists()
Overrides:
exists in class File

delete

public boolean delete()
Overrides:
delete in class File
Returns:
true if the deletion succeed, false otherwise.
See Also:

A chain of post-processors will be ran once this file deleted to perform possible additional treatments.


inputStream

public InputStream inputStream()
                        throws IOException
Opens and returns an input stream to this file.

Returns:
a buffered input stream to this file.
Throws:
IOException - if an error occurs while opening the input stream.

writeFrom

public void writeFrom(InputStream stream)
               throws IOException
Writes the content of the specified input stream into this file. If this file doesn't aleady exists, then it is created.

A chain of post-processors will be ran once the content written in this file to perform possible additional treatments.

Parameters:
stream - the input stream from which the content to write is fetched.
Throws:
IOException - if an error occurs while writing the content from the specified input stream into this file.

moveInto

public SilverpeasFile moveInto(String directoryPath)
                        throws IOException
Moves this file into the specified directory. If the directory doesn't exist, it is then created before. Once the file is moved, it is not more existing. If the file doesn't exist, then nothing is done and NO_FILE is returned.

A chain of post-processors will be ran once this file is moved to the directory to perform possible additional treatments on the the moved file.

The moving operation will create a new file in the specified directory with the content of this file and then delete this file. Consequently, a chain of post-processors will be ran against the deleted file to perform additional treatments at file deletion.

Parameters:
directoryPath - the absolute path of the directory into which this file has to be moved.
Returns:
the SilverpeasFile located at the specified directory.
Throws:
IOException - if an error occurs while moving this file into the specified directory

copyInto

public SilverpeasFile copyInto(String directoryPath)
                        throws IOException
Copies this file into the specified directory. If the directory doesn't exist, it is then created before.

A chain of post-processors will be ran once this file is copied to the directory to perform possible additional treatments on the copied file.

Parameters:
directoryPath - the absolute path of the directory into which this file has to be moved.
Throws:
IOException - if an error occurs while copying this file into the specified directory

isArchive

public boolean isArchive()
Indicates if the current silverpeas file is of type archive.

Returns:
true if it is an archive file, false otherwise.

isImage

public boolean isImage()
Indicates if the current file is of type image.

Returns:
true if it is an image file, false otherwise.

isMail

public boolean isMail()
Indicates if the current file is of type mail.

Returns:
true if it is a mail file, false otherwise.

isPdf

public boolean isPdf()
Indicates if the current file is of type PDF.

Returns:
true if it is a PDF file, false otherwise.

isOpenOfficeCompatible

public boolean isOpenOfficeCompatible()
Indicates if the current file is of type OpenOffice compatible.

Returns:
true if it is a OpenOffice compatible file, false otherwise.

isFileSecure

public boolean isFileSecure()


Copyright © 2016 Silverpeas. All Rights Reserved.