Class SilverpeasFile

  • All Implemented Interfaces:
    Serializable, Comparable<File>
    Direct Known Subclasses:
    DragAndDropWebEditorStore.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 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 belonging 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 belonging 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
      • 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.
      • equals

        public boolean equals​(Object o)
        Overrides:
        equals in class File
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class File