/**
 *  Copyright © 2026, Luis Andrés Lange <https://javacomm.net>
 *
 *  This Source Code Form is subject to the terms of the Mozilla Public
 *  License, v. 2.0. If a copy of the MPL was not distributed with this
 *  file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 *  ----------------------------------------------------------------------------
 *
 *  Exhibit B - "Incompatible With Secondary Licenses" Notice
 *
 *  This Source Code Form is "Incompatible With Secondary Licenses",
 *  as defined by the Mozilla Public License, v. 2.0.
 *
 */
package net.javacomm.client.environment;

import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
// API-Klassen
import org.apache.logging.log4j.core.LoggerContext;
// Core-Konfigurations-Klassen
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.xml.XmlConfiguration;



public class ImageLoggingFactory extends ConfigurationFactory {

  @Override
  protected String[] getSupportedTypes() {
    return new String[] {".xml"};
  }



  @Override
  public Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) {
    if (source != null && source != ConfigurationSource.NULL_SOURCE) {
      return new XmlConfiguration(loggerContext, source);
    }

    try {
      URL configUrl = Path.of("etc/log4j2.xml").toUri().toURL();
      ConfigurationSource customSource = new ConfigurationSource(configUrl.openStream(), configUrl);
      return new XmlConfiguration(loggerContext, customSource);
    }
    catch (IOException e) {
      return null;
    }
  }



  @Override
  public Configuration getConfiguration(LoggerContext loggerContext, String name, URI configLocation) {
    return getConfiguration(loggerContext, null);
  }
}