@SuppressWarnings("unchecked")
	public static String getText(
			GenericTreeNode<LayoutParserTreeElement> element) {

		// Daca elementul este nod frunza returneaza textul.
		if (element.getData().elementType.toString().compareTo("String") == 0) {
			return element.getData().text;
		}

		// Ia copii elementului curent.
		List<GenericTreeNode<LayoutParserTreeElement>> children = element
				.getChildren();

		// Sorteaza dupa top.
		Collections.sort(children, new ElementComparator());

		String text = "";
		for (GenericTreeNode<LayoutParserTreeElement> child : children) {
			text = text.concat(getText(child));
			if (child.getData().elementType.toString().compareTo("TextLine") == 0) {
				text = text.concat("\n");
			} else if (child.getData().elementType.toString().compareTo(
					"String") == 0) {
				text = text.concat(" ");
			}
		}

		// Remove space and new line added only after last component.
		text = text.replaceAll(" $", "");
		if (element.getData().elementType.toString().compareTo("TextBlock") == 0
				&& text.length() > 0) {
			text = text.substring(0, text.length() - 1);
		}
		return text;
	}