Class CommandGenerator

java.lang.Object
org.codelibs.fess.thumbnail.impl.BaseThumbnailGenerator
org.codelibs.fess.thumbnail.impl.CommandGenerator
All Implemented Interfaces:
ThumbnailGenerator

public class CommandGenerator extends BaseThumbnailGenerator
Command-based thumbnail generator that executes external commands to create thumbnails. Uses external tools through command execution to generate thumbnail images from documents.
  • Field Details

    • commandList

      protected List<String> commandList
      List of command strings to execute for thumbnail generation.
    • commandTimeout

      protected long commandTimeout
      Timeout for command execution in milliseconds.
    • commandDestroyTimeout

      protected long commandDestroyTimeout
      Timeout for destroying processes in milliseconds.
    • baseDir

      protected File baseDir
      Base directory for command execution.
  • Constructor Details

    • CommandGenerator

      public CommandGenerator()
      Default constructor for CommandGenerator.
  • Method Details

    • init

      @PostConstruct public void init()
      Initializes the command generator after construction.
    • updateProperties

      protected void updateProperties()
      Updates timeout properties from system configuration.
    • destroy

      public void destroy()
      Destroys the command generator and cleanup resources.
    • generate

      public boolean generate(String thumbnailId, File outputFile)
      Generates a thumbnail for the given ID and saves it to the output file.
      Parameters:
      thumbnailId - The ID of the thumbnail to generate.
      outputFile - The file where the thumbnail will be saved.
      Returns:
      True if thumbnail generation was successful, false otherwise.
    • executeCommand

      protected int executeCommand(String thumbnailId, List<String> cmdList)
      Executes a command to generate a thumbnail using the specified command list.

      This method starts a process with the given command list, manages its execution, handles timeouts, and logs relevant information. It ensures the process is destroyed if it exceeds the allowed execution time or becomes unresponsive. The method also captures and logs the process output for debugging purposes.

      Parameters:
      thumbnailId - the identifier for the thumbnail being generated
      cmdList - the list of command arguments to execute
      Returns:
      the exit code of the process if it finishes normally; -1 if the process fails or is terminated
    • setCommandList

      public void setCommandList(List<String> commandList)
      Sets the list of commands to execute for thumbnail generation.
      Parameters:
      commandList - The command list.
    • setCommandTimeout

      public void setCommandTimeout(long commandTimeout)
      Sets the command execution timeout.
      Parameters:
      commandTimeout - The timeout in milliseconds.
    • setBaseDir

      public void setBaseDir(File baseDir)
      Sets the base directory for command execution.
      Parameters:
      baseDir - The base directory.
    • setCommandDestroyTimeout

      public void setCommandDestroyTimeout(long commandDestroyTimeout)
      Sets the timeout for destroying processes.
      Parameters:
      commandDestroyTimeout - The destroy timeout in milliseconds.
    • getExtensionFromMimeType

      protected String getExtensionFromMimeType(String mimeType)
      Gets file extension from MIME type for creating temp files with proper extensions. This helps ImageMagick correctly identify file formats.
      Parameters:
      mimeType - The MIME type of the content.
      Returns:
      The file extension including the dot (e.g., ".gif"), or empty string if unknown.