Package org.codelibs.fess.thumbnail.impl
Class CommandGenerator
java.lang.Object
org.codelibs.fess.thumbnail.impl.BaseThumbnailGenerator
org.codelibs.fess.thumbnail.impl.CommandGenerator
- All Implemented Interfaces:
ThumbnailGenerator
Command-based thumbnail generator that executes external commands to create thumbnails.
Uses external tools through command execution to generate thumbnail images from documents.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classTimer task for destroying processes that exceed their timeout. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FileBase directory for command execution.protected longTimeout for destroying processes in milliseconds.List of command strings to execute for thumbnail generation.protected longTimeout for command execution in milliseconds.Fields inherited from class org.codelibs.fess.thumbnail.impl.BaseThumbnailGenerator
available, conditionMap, directoryNameLength, filePathMap, generatorList, maxRedirectCount, name -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Destroys the command generator and cleanup resources.protected intexecuteCommand(String thumbnailId, List<String> cmdList) Executes a command to generate a thumbnail using the specified command list.booleanGenerates a thumbnail for the given ID and saves it to the output file.protected StringgetExtensionFromMimeType(String mimeType) Gets file extension from MIME type for creating temp files with proper extensions.voidinit()Initializes the command generator after construction.voidsetBaseDir(File baseDir) Sets the base directory for command execution.voidsetCommandDestroyTimeout(long commandDestroyTimeout) Sets the timeout for destroying processes.voidsetCommandList(List<String> commandList) Sets the list of commands to execute for thumbnail generation.voidsetCommandTimeout(long commandTimeout) Sets the command execution timeout.protected voidUpdates timeout properties from system configuration.Methods inherited from class org.codelibs.fess.thumbnail.impl.BaseThumbnailGenerator
addCondition, createTask, expandPath, getName, isAvailable, isTarget, process, process, register, setDirectoryNameLength, setGeneratorList, setMaxRedirectCount, setName, updateThumbnailField
-
Field Details
-
commandList
List of command strings to execute for thumbnail generation. -
commandTimeout
protected long commandTimeoutTimeout for command execution in milliseconds. -
commandDestroyTimeout
protected long commandDestroyTimeoutTimeout for destroying processes in milliseconds. -
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
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
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 generatedcmdList- 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
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
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
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.
-