package br.unisinos.lab2.mindmap;

public class MindMapWriter<E> {
	private StringBuffer xml;
	private int currentStringIndex = 0;
	
	public void write(MindMap<E> mindMap) {
		DNode<E> root = mindMap.getRoot();
		String out = "<?xml version=\"1.0\"?>\n";
		out += makeInnerXML(root, 0);
		System.out.println(out);
		//TODO: MAKE WRITE THE XML STRING TO FILE
	}
	
	private String makeInnerXML(DNode <E> node, int tabNumber) {
		tabNumber += 1;
		String sNode = "<node>\n";
		E elem = node.getElement();
		sNode += "<"+elem.getClass().getSimpleName() +">\n"+elem.toString()+"\n</"+elem.getClass().getSimpleName()+">\n";
		
        DNode<E> nextSon = node.getSon();
        DNode<E> nextBrother = node.getBro();
        
        if (nextSon != null) {
        	sNode += sNode + makeInnerXML(nextSon, tabNumber) + "</node>\n";
        	if (nextBrother != null) {
        		return sNode + "</node>\n" + makeInnerXML(nextBrother, tabNumber);
        	} else {
        		return sNode + "</node>\n";
        	}
        } else {
        	if (nextBrother != null) {
        		return sNode + "</node>\n" + makeInnerXML(nextBrother, tabNumber); 
        	} else {
        		return sNode + "</node>\n";
        	}
        }
	}
}

@@ -759,24 +759,16 @@
 sNode +=
- sNode +
  makeInn
@@ -964,34 +964,32 @@
 sNode + %22%3C/node%3E
-%5Cn
 %22;%0A        %09%7D%0A  
@@ -1157,30 +1157,16 @@
 rn sNode
- + %22%3C/node%3E%5Cn%22
 ;%0A      

fix bug in writer