Class FileManager

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
it.rol.manager.FileManager
All Implemented Interfaces:
Constants, Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class FileManager extends javax.servlet.http.HttpServlet implements Constants

FileManager è la classe che si occupa della gestione dei files caricati dall'utente, della generazione di link per il download, l'impostazione dei privilegi, secondo eventuali policy, dell'aggiornamento e di quant'altro occorra alle funzioni di gestione allegati della web-application Rol.

Author:
Giovanroberto Torre
See Also:
  • Field Details

    • STD_SPACER

      public static final char STD_SPACER
      Talking const for the preferred, standard separator between entity names and attribute names.
      See Also:
    • FORBIDDEN_EXTENSIONS

      public static final String[] FORBIDDEN_EXTENSIONS
      Carica la lista con le estensioni vietate
  • Constructor Details

    • FileManager

      public FileManager()
  • Method Details

    • init

      public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException

      Inizializza, staticamente, alcune variabili globali.

      Specified by:
      init in interface javax.servlet.Servlet
      Overrides:
      init in class javax.servlet.GenericServlet
      Parameters:
      config - la configurazione usata dal servlet container per passare informazioni alla servlet durante l'inizializzazione
      Throws:
      javax.servlet.ServletException - una eccezione che puo' essere sollevata quando la servlet incontra difficolta'
    • doGet

      protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws javax.servlet.ServletException, IOException

      La chiamata diretta della Servlet con il metodo GET produce il logout.

      Overrides:
      doGet in class javax.servlet.http.HttpServlet
      Parameters:
      req - la HttpServletRequest contenente la richiesta del client
      res - la HttpServletResponse contenente la risposta del server
      Throws:
      javax.servlet.ServletException - eccezione che viene sollevata se si verifica un problema nell'inoltro (forward) della richiesta/risposta
      IOException - eccezione che viene sollevata se si verifica un problema nell'inoltro (forward) della richiesta/risposta
      See Also:
      • HttpServlet.doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
    • doPost

      protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws javax.servlet.ServletException, IOException

      Handles file upload.

      Utilizza un approccio di programmazione difensiva per garantire la correttezza dell'input.

      Overrides:
      doPost in class javax.servlet.http.HttpServlet
      Parameters:
      req - la HttpServletRequest contenente la richiesta del client
      res - la HttpServletResponse contenente la risposta del server
      Throws:
      javax.servlet.ServletException - eccezione che viene sollevata se si verifica un problema nell'inoltro (forward) della richiesta/risposta
      IOException - eccezione che viene sollevata se si verifica un problema nell'inoltro (forward) della richiesta/risposta
    • getAllowedUploadCommand

      public static LinkedList<String> getAllowedUploadCommand()
      Getter su variabile di classe
      Returns:
      LinkedList<String> - Elenco delle Command abilitate a caricare files in upload
    • checkPrime

      public static String checkPrime(String toCheck)

      Returns a String replacing all the sequence of characters matching regex and replacement String.

      Parameters:
      toCheck - the String to check
      Returns:
      String - the String replaced
    • getFileSizeBytes

      public static long getFileSizeBytes(File file)

      Restituisce il peso in bytes di un file che accetta come argomento.

      Parameters:
      file - File di cui bisogna restituire il peso in B
      Returns:
      long - il peso del file in B
    • getFileSizeKiloBytes

      public static double getFileSizeKiloBytes(File file)

      Restituisce il peso in KiloBytes di un file che accetta come argomento.

      Parameters:
      file - File di cui bisogna restituire il peso in KB
      Returns:
      double - il peso del file in Kappa
    • getFileSizeMegaBytes

      public static double getFileSizeMegaBytes(File file)

      Restituisce il peso in MegaBytes di un file che accetta come argomento.

      Parameters:
      file - File di cui bisogna restituire il peso in MB
      Returns:
      double - il peso del file in Mega
    • getContent

      public static String getContent(String path) throws NotFoundException, CommandException
      Legge un file (di configurazione)
      Parameters:
      path -
      Returns:
      Throws:
      NotFoundException
      CommandException