package org.jivesoftware.smack.initializer;

import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.SmackInitialization;
import org.jivesoftware.smack.provider.ProviderFileLoader;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.util.FileUtils;

public abstract class UrlInitializer implements SmackInitializer {
   private static final Logger LOGGER = Logger.getLogger(UrlInitializer.class.getName());

   public List<Exception> initialize() {
      ClassLoader classLoader = this.getClass().getClassLoader();
      List<Exception> exceptions = new LinkedList();
      String providerUrl = this.getProvidersUrl();
      InputStream is;
      if (providerUrl != null) {
         try {
            is = FileUtils.getStreamForUrl(providerUrl, classLoader);
            if (is != null) {
               LOGGER.log(Level.FINE, "Loading providers for providerUrl [" + providerUrl + "]");
               ProviderFileLoader pfl = new ProviderFileLoader(is, classLoader);
               ProviderManager.addLoader(pfl);
               exceptions.addAll(pfl.getLoadingExceptions());
            } else {
               LOGGER.log(Level.WARNING, "No input stream created for " + providerUrl);
               exceptions.add(new IOException("No input stream created for " + providerUrl));
            }
         } catch (Exception var8) {
            LOGGER.log(Level.SEVERE, "Error trying to load provider file " + providerUrl, var8);
            exceptions.add(var8);
         }
      }

      String configUrl = this.getConfigUrl();
      if (configUrl != null) {
         try {
            is = FileUtils.getStreamForUrl(configUrl, classLoader);
            SmackInitialization.processConfigFile(is, exceptions, classLoader);
         } catch (Exception var7) {
            exceptions.add(var7);
         }
      }

      return exceptions;
   }

   protected String getProvidersUrl() {
      return null;
   }

   protected String getConfigUrl() {
      return null;
   }
}
