Class ProtocolHelper

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

public class ProtocolHelper extends Object
Helper class for managing and validating URL protocols in Fess crawling system. This class handles the initialization and validation of web and file protocols used by the crawler to determine which URLs can be crawled.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String[]
    Array of supported file protocols with colon suffix (e.g., "file:", "ftp:")
    protected String[]
    Array of supported web protocols with colon suffix (e.g., "http:", "https:")
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor for ProtocolHelper.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a new file protocol to the supported protocols list.
    void
    Adds a new web protocol to the supported protocols list.
    Returns the array of supported file protocols.
    Returns the array of supported web protocols.
    void
    Initializes the protocol helper by loading configured protocols from FessConfig and scanning for available protocol handlers in the classpath.
    boolean
    Checks if the given URL uses a valid file protocol.
    boolean
    Checks if the given URL uses a valid web protocol.
    protected void
    loadProtocols(String basePackage)
    Loads protocol handlers from the specified base package by scanning for Handler classes in subpackages and registering them as web or file protocols based on their PROTOCOL_TYPE field.

    Methods inherited from class java.lang.Object

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

    • webProtocols

      protected String[] webProtocols
      Array of supported web protocols with colon suffix (e.g., "http:", "https:")
    • fileProtocols

      protected String[] fileProtocols
      Array of supported file protocols with colon suffix (e.g., "file:", "ftp:")
  • Constructor Details

    • ProtocolHelper

      public ProtocolHelper()
      Default constructor for ProtocolHelper. Initializes the helper with empty protocol arrays that will be populated during init().
  • Method Details

    • init

      @PostConstruct public void init()
      Initializes the protocol helper by loading configured protocols from FessConfig and scanning for available protocol handlers in the classpath. This method is called automatically after bean construction.
    • loadProtocols

      protected void loadProtocols(String basePackage)
      Loads protocol handlers from the specified base package by scanning for Handler classes in subpackages and registering them as web or file protocols based on their PROTOCOL_TYPE field.
      Parameters:
      basePackage - the base package to scan for protocol handlers
    • getWebProtocols

      public String[] getWebProtocols()
      Returns the array of supported web protocols.
      Returns:
      array of web protocol strings with colon suffix (e.g., "http:", "https:")
    • getFileProtocols

      public String[] getFileProtocols()
      Returns the array of supported file protocols.
      Returns:
      array of file protocol strings with colon suffix (e.g., "file:", "ftp:")
    • isValidWebProtocol

      public boolean isValidWebProtocol(String url)
      Checks if the given URL uses a valid web protocol.
      Parameters:
      url - the URL to validate
      Returns:
      true if the URL starts with a supported web protocol, false otherwise
    • isValidFileProtocol

      public boolean isValidFileProtocol(String url)
      Checks if the given URL uses a valid file protocol.
      Parameters:
      url - the URL to validate
      Returns:
      true if the URL starts with a supported file protocol, false otherwise
    • addWebProtocol

      public void addWebProtocol(String protocol)
      Adds a new web protocol to the supported protocols list. If the protocol already exists, it will not be added again.
      Parameters:
      protocol - the protocol name to add (without colon suffix)
    • addFileProtocol

      public void addFileProtocol(String protocol)
      Adds a new file protocol to the supported protocols list. If the protocol already exists, it will not be added again.
      Parameters:
      protocol - the protocol name to add (without colon suffix)