/*
 * Plugins.java, 5 juin 2006
 * 
 * This file is part of FilmZ.
 *
 * Copyright © 2006 Johan Cwiklinski
 *
 * File :               Plugins.java
 * Author's email :     johan@x-tnd.be
 * Author's Website :   http://www.x-tnd.be/
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 */

/**
 * 
 */
package be.xtnd.films.plugins;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 * @author Johan Cwiklinski
 * @version 1.0
 */
public class Plugins {
	static Logger logger = Logger.getLogger(Plugins.class.getName());

	/**
	 * 
	 */
	public Plugins(){
		PropertyConfigurator.configure(ClassLoader.getSystemResource("be/xtnd/films/log4j.properties"));
	}
	
	/**
	 * 
	 * @return Liste des plugins web
	 */
	public static ArrayList<String> liste(){
		//FIXME externaliser les plugins
		ArrayList<String> ar = new ArrayList<String>(3);
		
		ar.add("Allociné");
		ar.add("DVDFR");
		ar.add("CinemAsie");
		ar.add("Cinéfil");
		
		return ar;
	}
	
	/**
	 * 
	 * @param path
	 */
	public void loadExternalPlugins(String path){
		try {
			URL urlList[] = {new File(path).toURL()};

			ClassLoader loader = new URLClassLoader(urlList);

			String className = "DVDFR" ;

			RecupWeb r = (RecupWeb) Class.forName(className,true,loader).newInstance();
			
			/*for(int i = 0 ; i < urlList.length ; i++)
				System.err.println("path contains " + urlList[i]);*/
		} catch (MalformedURLException e){
			// TODO Bloc catch auto-généré
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Bloc catch auto-généré
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Bloc catch auto-généré
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Bloc catch auto-généré
			e.printStackTrace();
		} 		
	}
}
