package eu.ydp.empiria.player.client.controller.data;

import com.google.gwt.dom.client.Document;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.Node;
import com.google.gwt.xml.client.NodeList;

import eu.ydp.empiria.player.client.util.XMLUtils;

/**
 * Responsible for putting meta nodes into HTML Document.
 * 
 * @author Rafal Rybacki
 */
public class MetaDescriptionManager {

	public void processDocument(Element documentElement){
		Element metaDescriptionNode = XMLUtils.getFirstElementWithTagName(documentElement, "metaDescription");
		NodeList metaNodes = metaDescriptionNode.getElementsByTagName("meta");
		com.google.gwt.dom.client.Element htmlHeadNode = Document.get().getElementsByTagName("head").getItem(0);
		for (int n = 0 ; n < metaNodes.getLength() ; n ++){
			com.google.gwt.dom.client.Element currElement = convertToDomElement((Element)metaNodes.item(n));
			htmlHeadNode.appendChild(currElement);
		}
	}
	
	private com.google.gwt.dom.client.Element convertToDomElement(Element xmlElement){
		com.google.gwt.dom.client.Element domElement = Document.get().createElement(xmlElement.getNodeName());
		for (int a = 0 ; a < xmlElement.getAttributes().getLength() ; a ++){
			Node currAttr = xmlElement.getAttributes().item(a);
			domElement.setAttribute(currAttr.getNodeName(), currAttr.getNodeValue());			
		}
		return domElement;
	}
}

@@ -580,16 +580,54 @@
 ion%22);%0D%0A
+%09%09if (metaDescriptionNode != null)%7B%0D%0A%09
 %09%09NodeLi
@@ -692,16 +692,17 @@
 eta%22);%0D%0A
+%09
 %09%09com.go
@@ -799,24 +799,25 @@
 Item(0);%0D%0A%09%09
+%09
 for (int n =
@@ -857,16 +857,17 @@
 n ++)%7B%0D%0A
+%09
 %09%09%09com.g
@@ -959,16 +959,17 @@
 m(n));%0D%0A
+%09
 %09%09%09htmlH
@@ -1003,16 +1003,22 @@
 ment);%0D%0A
+%09%09%09%7D%0D%0A
 %09%09%7D%0D%0A%09%7D%0D

fix npe bug 67082