package com.peetz.kontor.data;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.peetz.tradingcards.service.SportService;
import com.peetz.tradingcards.service.TradingcardService;

public class ImportTradingCards
{
	public void parseNode(Node xmlNode)
	{
		NodeList childNodes = xmlNode.getChildNodes();
		for (int i=0; i<childNodes.getLength(); i++)
		{
			Node node = childNodes.item(i);
			if (node.getNodeName().equals("sport")) parseSport(node);
			if (node.getNodeName().equals("manufacturer")) parseManufacturer(node);
		}
	}
	
	public void parseSport(Node node)
	{
		NamedNodeMap attr = node.getAttributes();
		
		Node nameNode = attr.getNamedItem("name");
		String name = nameNode.getNodeValue();
		
		getSportService().addSport(name);
	}

	public void parseManufacturer(Node node)
	{
		NamedNodeMap attr = node.getAttributes();
		
		Node nameNode = attr.getNamedItem("name");
		String name = nameNode.getNodeValue();

		getCardService().addManufacturer(name);
	}

	private SportService getSportService()
	{
		return null;
	}
	
	private TradingcardService getCardService()
	{
		return null;
	}
}
