/*
 *
 * 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.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;




public class PropertiesContentHandler implements ContentHandler
{

	private Locator locator;
	private Map namespaceMappings;
	private Properties inputProperties;
	
	public PropertiesContentHandler( Properties inputProps)
	{
		inputProperties = inputProps;
		this.namespaceMappings = new HashMap();
	}
	
	
	public void setDocumentLocator( Locator locator) 
	{
		this.locator = locator;
	}
	
	public void startDocument() throws SAXException 
	{
	}
	
	public void endDocument() throws SAXException 
	{
	}
	
	public void processingInstruction ( String target, String data) throws SAXException
	{
			
	}
	
	public void startPrefixMapping(String prefix, String uri) 
	{
			namespaceMappings.put(uri,prefix);
	}
	
	public void endPrefixMapping(String prefix ) 
	{
			for ( Iterator i = namespaceMappings.keySet().iterator(); i.hasNext();)
			{
					String uri = (String) i.next();
					String thisPrefix=  (String) namespaceMappings.get(uri);
					if ( prefix.equals(thisPrefix) )
					{
							namespaceMappings.remove(uri);
							break;
					}
			}
	}
	
	public void startElement ( String namespaceURI, String localName, String qName, Attributes atts) throws SAXException
	{
		if( "property".equals(localName))
			inputProperties.put(atts.getValue(0),atts.getValue(1));
		
	}
	
	public void endElement ( String namespaceURI, String localName, String qName) throws SAXException
	{
		
	}
	
	public void characters ( char[] ch, int start, int length) throws SAXException
	{	
			
	}
	
	public void ignorableWhitespace ( char[] ch, int start, int length) throws SAXException
	{	
	}
	public void skippedEntity ( String name) throws SAXException
	{	
	}	
	
	
}
