/*
 *
 * Copyright (C)  3-mar-2004 Jean-Yves Beaujean 
 * 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.,  59
 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.

 * 
 */
package jxtray.xmlconf;


import org.jdom.output.*;
import org.jdom.*;

import java.util.Enumeration;
import java.util.Properties;

import java.io.FileOutputStream;

import jxtray.Messages;

public class PropertiesWriter 
{
	
	public static void write(String filename,Properties p)
	{
			Element root = new Element("properties");
			Document doconnection = new Document(root);
			Enumeration enum = p.keys();
			String key = null;
			while ( enum.hasMoreElements())
			{
				key  = (String) enum.nextElement() ;
				System.out.println("add : "+key + " - "+p.getProperty(key));	
				Element element = new Element("property");
				element.setAttribute(new Attribute("name",key)); 
				element.setAttribute(new Attribute("value",p.getProperty(key)));
				
				root.addContent(element);
			}
			
			XMLOutputter outputter = new XMLOutputter();
			try
			{
				outputter.output(doconnection, new FileOutputStream(filename));
			}
			catch( Exception e )
			{
				Messages.error("DriverCache.writeXMLFile() :" + e);
			}
	}
}
