<%@ page language="java" import="java.util.*,java.net.*,java.io.*,javax.servlet.*" %>
<%!
public void jspInit()
{
	ServletConfig servletConfig = getServletConfig();
	String basePath = servletConfig.getServletContext().getRealPath("/") + "WEB-INF" + File.separator + "CopyOnStartup.properties";
	File cosFile = new File(basePath);
	if (cosFile.exists() == false)
		return;
	Properties copyOnStartup = new Properties();
	try
	{
		FileInputStream cosFIS = new FileInputStream(cosFile);
		copyOnStartup.load(cosFIS);
		cosFIS.close();
		
	}
	catch (FileNotFoundException e)
	{
		e.printStackTrace();
	}
	catch (IOException e)
	{
		e.printStackTrace();
	}
	Enumeration keys = copyOnStartup.keys();
	while (keys.hasMoreElements())
	{
		String from = (String) keys.nextElement();
		String to = (String) copyOnStartup.get(from);
		File fFrom = new File(from);
		File fTo = new File(to);
		if (!fFrom.exists())
			continue;
	    if (fTo.exists())
	    	fTo.delete();
	    fTo.getParentFile().mkdirs();
		try
		{
		    FileInputStream fis = new FileInputStream(fFrom);
		    FileOutputStream fos = new FileOutputStream(fTo);
		    byte[] data = new byte[1024];
		    int read = fis.read(data);
		    while (read > 0)
		    {
		        fos.write(data, 0, read);
		        read = fis.read(data);
		    }
		    fis.close();
		    fos.close();
		    fFrom.delete();
		}
		catch (FileNotFoundException e)
		{
		    e.printStackTrace();
		}
		catch (IOException e)
		{
		    e.printStackTrace();
		}
	}
	cosFile.delete();
}

%>
