package com.grayben.riskExtractor.htmlScorer;

import com.grayben.riskExtractor.htmlScorer.partScorers.Scorer;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.select.NodeVisitor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ScoringAndFlatteningNodeVisitor implements NodeVisitor {
	
	ScoredText flatText;
	
	int emphasisScore = 0;
	int separationScore = 0;
	List<Scorer<Element>> elementScorers;
	

	public ScoringAndFlatteningNodeVisitor(List<Scorer<Element>> elementScorers) {
		super();
		this.elementScorers = elementScorers;
		this.flatText = new ScoredText();
	}

	@Override
	public void head(Node node, int depth) {
		Element element = null;
		if(!node.getClass().equals(Element.class)){
			/* System.err.println("The node was not an " + Element.class
					+ ": " + node.toString());
					*/
			return;
		} else {
			element = (Element) node;
		}
		// if the node has emphasis, add a score to this node.
		if(/* test for attributes */ true){
			// flatStructure.element(id).incrementEmphasis();
		}
		Map<String, Integer> scores = new HashMap<String, Integer>();
		scores.put("emphasis", this.emphasisScore);
		scores.put("segmentation", this.separationScore);
		ScoredTextElement st = new ScoredTextElement(element.ownText(),
							scores);
		
		flatText.add(st);

	}

	@Override
	public void tail(Node node, int depth) {
		return;

	}
}
@@ -460,17 +460,16 @@
 corers;%0A
-%09
 %0A%0A%09publi
@@ -690,209 +690,104 @@
 ) %7B%0A
-%09%09Element element = null;%0A%09%09if(!node.getClass().equals(Element.class))%7B%0A%09%09%09/* System.err.println(%22The node was not an %22 + Element.class%0A%09%09%09%09%09+ %22: %22 + node.toString());%0A%09%09%09%09%09*/%0A%09%09%09return;%0A%09%09%7D else %7B%0A%09%09%09
+        validateInput(node, depth);%0A        if(! isElement(node))%0A            return;%0A%09%09Element 
 elem
@@ -808,19 +808,24 @@
 ) node;%0A
-%09%09%7D
+        
 %0A%09%09// if
@@ -1298,19 +1298,588 @@
 ) %7B%0A
-%09%09return;%0A%0A%09
+        validateInput(node, depth);%0A        if (! isElement(node))%0A            return;%0A        return;%0A%0A%09%7D%0A%0A    private void validateInput(Node node, int depth)%7B%0A        if (node == null)%0A            throw new NullPointerException(%0A                    %22Node was null%22%0A            );%0A        if (depth %3C 0)%0A            throw new IllegalArgumentException(%0A                    %22Depth was less than 0%22%0A            );%0A    %7D%0A%0A    private boolean isElement(Node node)%7B%0A        if (node.getClass().equals(Element.class))%0A            return true;%0A        else%0A            return false;%0A    
 %7D%0A%7D

Add input validation