/**
   * Initialize this plugin. This method only called when the plugin is instantiated.
   *
   * @param servletConfig Servlet config object for the plugin to retrieve any initialization
   *     parameters
   * @param blojsomConfiguration {@link org.blojsom.blog.BlojsomConfiguration} information
   * @throws org.blojsom.plugin.BlojsomPluginException If there is an error initializing the plugin
   */
  public void init(ServletConfig servletConfig, BlojsomConfiguration blojsomConfiguration)
      throws BlojsomPluginException {
    super.init(servletConfig, blojsomConfiguration);

    _servletConfig = servletConfig;
    _blojsomConfiguration = blojsomConfiguration;
    _flavorConfiguration = servletConfig.getInitParameter(BLOJSOM_FLAVOR_CONFIGURATION_IP);
    _pluginConfiguration = servletConfig.getInitParameter(BLOJSOM_PLUGIN_CONFIGURATION_IP);
    _authorizationConfiguration = servletConfig.getInitParameter(BLOG_AUTHORIZATION_IP);

    try {
      Properties configurationProperties =
          BlojsomUtils.loadProperties(servletConfig, PLUGIN_ADMIN_EDIT_USERS_IP, true);

      _bootstrapDirectory = configurationProperties.getProperty(BOOTSTRAP_DIRECTORY_IP);
      if (BlojsomUtils.checkNullOrBlank(_bootstrapDirectory)) {
        _bootstrapDirectory = DEFAULT_BOOTSTRAP_DIRECTORY;
      }

      _blogHomeBaseDirectory = configurationProperties.getProperty(BLOG_HOME_BASE_DIRECTORY_IP);
      if (BlojsomUtils.checkNullOrBlank(_blogHomeBaseDirectory)) {
        _blogHomeBaseDirectory = _blojsomConfiguration.getGlobalBlogHome();
        if (BlojsomUtils.checkNullOrBlank(_blogHomeBaseDirectory)) {
          throw new BlojsomPluginException("No blog base home directory specified.");
        }
      } else {
        if (!_blogHomeBaseDirectory.endsWith("/")) {
          _blogHomeBaseDirectory += "/";
        }
      }

      String administratorProperty = configurationProperties.getProperty(ADMINISTRATORS_IP);
      String[] administrators = BlojsomUtils.parseCommaList(administratorProperty);
      _administrators = BlojsomUtils.arrayOfStringsToMap(administrators);
    } catch (BlojsomException e) {
      _logger.error(e);
      throw new BlojsomPluginException(e);
    }
  }
  /**
   * Initialize this plugin. This method only called when the plugin is instantiated.
   *
   * @param servletConfig Servlet config object for the plugin to retrieve any initialization
   *     parameters
   * @param blojsomConfiguration {@link BlojsomConfiguration} information
   * @throws org.blojsom.plugin.BlojsomPluginException If there is an error initializing the plugin
   */
  public void init(ServletConfig servletConfig, BlojsomConfiguration blojsomConfiguration)
      throws BlojsomPluginException {
    super.init(servletConfig, blojsomConfiguration);

    String fetcherClassName = blojsomConfiguration.getFetcherClass();
    try {
      Class fetcherClass = Class.forName(fetcherClassName);
      _fetcher = (BlojsomFetcher) fetcherClass.newInstance();
      _fetcher.init(servletConfig, blojsomConfiguration);
      _logger.info("Added blojsom fetcher: " + fetcherClassName);
    } catch (ClassNotFoundException e) {
      _logger.error(e);
      throw new BlojsomPluginException(e);
    } catch (InstantiationException e) {
      _logger.error(e);
      throw new BlojsomPluginException(e);
    } catch (IllegalAccessException e) {
      _logger.error(e);
      throw new BlojsomPluginException(e);
    } catch (BlojsomFetcherException e) {
      _logger.error(e);
      throw new BlojsomPluginException(e);
    }
  }
  /**
   * Initialize this plugin. This method only called when the plugin is instantiated.
   *
   * @param servletConfig Servlet config object for the plugin to retrieve any initialization
   *     parameters
   * @param blojsomConfiguration {@link org.blojsom.blog.BlojsomConfiguration} information
   * @throws org.blojsom.plugin.BlojsomPluginException If there is an error initializing the plugin
   */
  public void init(ServletConfig servletConfig, BlojsomConfiguration blojsomConfiguration)
      throws BlojsomPluginException {
    super.init(servletConfig, blojsomConfiguration);

    try {
      Properties configurationProperties =
          BlojsomUtils.loadProperties(servletConfig, PLUGIN_ADMIN_UPLOAD_IP, true);
      _temporaryDirectory = configurationProperties.getProperty(TEMPORARY_DIRECTORY_IP);
      if (BlojsomUtils.checkNullOrBlank(_temporaryDirectory)) {
        _temporaryDirectory = DEFAULT_TEMPORARY_DIRECTORY;
      }
      _logger.debug("Using temporary directory: " + _temporaryDirectory);

      try {
        _maximumUploadSize =
            Long.parseLong(configurationProperties.getProperty(MAXIMUM_UPLOAD_SIZE_IP));
      } catch (NumberFormatException e) {
        _maximumUploadSize = DEFAULT_MAXIMUM_UPLOAD_SIZE;
      }
      _logger.debug("Using maximum upload size: " + _maximumUploadSize);

      try {
        _maximumMemorySize =
            Integer.parseInt(configurationProperties.getProperty(MAXIMUM_MEMORY_SIZE_IP));
      } catch (NumberFormatException e) {
        _maximumMemorySize = DEFAULT_MAXIMUM_MEMORY_SIZE;
      }
      _logger.debug("Using maximum memory size: " + _maximumMemorySize);

      String acceptedFileTypes = configurationProperties.getProperty(ACCEPTED_FILE_TYPES_IP);
      String[] parsedListOfTypes;
      if (BlojsomUtils.checkNullOrBlank(acceptedFileTypes)) {
        parsedListOfTypes = DEFAULT_ACCEPTED_FILE_TYPES;
      } else {
        parsedListOfTypes = BlojsomUtils.parseCommaList(acceptedFileTypes);
      }
      _acceptedFileTypes = new HashMap(parsedListOfTypes.length);
      for (int i = 0; i < parsedListOfTypes.length; i++) {
        String type = parsedListOfTypes[i];
        _acceptedFileTypes.put(type, type);
      }
      _logger.debug(
          "Using accepted file types: " + BlojsomUtils.arrayOfStringsToString(parsedListOfTypes));

      _resourcesDirectory = _blojsomConfiguration.getResourceDirectory();
      if (BlojsomUtils.checkNullOrBlank(_resourcesDirectory)) {
        _resourcesDirectory = DEFAULT_RESOURCES_DIRECTORY;
      }

      _resourcesDirectory = BlojsomUtils.checkStartingAndEndingSlash(_resourcesDirectory);
      _logger.debug("Using resources directory: " + _resourcesDirectory);

      String invalidFileExtensionsProperty =
          configurationProperties.getProperty(INVALID_FILE_EXTENSIONS_IP);
      if (BlojsomUtils.checkNullOrBlank(invalidFileExtensionsProperty)) {
        _invalidFileExtensions = DEFAULT_INVALID_FILE_EXTENSIONS;
      } else {
        _invalidFileExtensions = BlojsomUtils.parseCommaList(invalidFileExtensionsProperty);
      }
      _logger.debug("Using invalid file extensions: " + invalidFileExtensionsProperty);
    } catch (BlojsomException e) {
      _logger.error(e);
      throw new BlojsomPluginException(e);
    }
  }