Class FileTypeHelper

java.lang.Object
org.codelibs.fess.helper.FileTypeHelper

public class FileTypeHelper extends Object
Helper class for managing file type mappings based on MIME types. This class provides functionality to map MIME types to file types and retrieve appropriate file type classifications for documents during indexing. The mappings are loaded from configuration and can be dynamically modified at runtime. When a MIME type is not found in the mapping, a default value is returned.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
    Default file type value returned when MIME type is not found in mappings
    protected Map<String,String>
    Map storing MIME type to file type mappings
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor for file type helper.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String mimetype, String filetype)
    Adds or updates a MIME type to file type mapping.
    get(String mimetype)
    Retrieves the file type for a given MIME type.
    Gets the default file type value used when MIME type is not found.
    Gets all distinct file types currently configured in the mappings.
    void
    Initializes the file type mappings by loading configuration from Fess settings.
    void
    setDefaultValue(String defaultValue)
    Sets the default file type value to use when MIME type is not found.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • defaultValue

      protected String defaultValue
      Default file type value returned when MIME type is not found in mappings
    • mimetypeMap

      protected Map<String,String> mimetypeMap
      Map storing MIME type to file type mappings
  • Constructor Details

    • FileTypeHelper

      public FileTypeHelper()
      Default constructor for file type helper. Creates a new instance with default values.
  • Method Details

    • init

      @PostConstruct public void init()
      Initializes the file type mappings by loading configuration from Fess settings. This method is called automatically after dependency injection is complete. The mappings are loaded from the index filetype configuration property, where each line contains a MIME type to file type mapping in the format "mimetype=filetype".
    • add

      public void add(String mimetype, String filetype)
      Adds or updates a MIME type to file type mapping.
      Parameters:
      mimetype - the MIME type to map (e.g., "application/pdf")
      filetype - the file type classification (e.g., "pdf")
    • get

      public String get(String mimetype)
      Retrieves the file type for a given MIME type.
      Parameters:
      mimetype - the MIME type to look up
      Returns:
      the corresponding file type, or the default value if not found
    • getDefaultValue

      public String getDefaultValue()
      Gets the default file type value used when MIME type is not found.
      Returns:
      the default file type value
    • setDefaultValue

      public void setDefaultValue(String defaultValue)
      Sets the default file type value to use when MIME type is not found.
      Parameters:
      defaultValue - the new default file type value
    • getTypes

      public String[] getTypes()
      Gets all distinct file types currently configured in the mappings.
      Returns:
      an array of all unique file type values