package in.twizmwaz.cardinal.util;

import com.google.common.collect.Lists;
import org.bukkit.Bukkit;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;

public class DomUtils {

    public static Document parse(File file) throws JDOMException, IOException {
        SAXBuilder saxBuilder = new SAXBuilder();
        Document original = saxBuilder.build(file);
        List<String> toInclude = Lists.newArrayList();
        for (Element include : original.getRootElement().getChildren("include"))
            toInclude.add(include.getAttributeValue("src"));
        for (String include : toInclude) {
            boolean found = false;
            File path = file.getParentFile();
            File including = new File(path, include);
            if (including.exists()) {
                found = true;
                try {
                    for (Element element : parse(including).getRootElement().getChildren()) {
                        original.getRootElement().addContent(element.clone().detach());
                    }
                } catch (JDOMException | IOException ignored) {}
            } else {
                while (include.startsWith("../")) {
                    include = include.replace("../", "");
                }
                including = new File(path, include);
                if (including.exists()) {
                    found = true;
                    try {
                        for (Element element : parse(including).getRootElement().getChildren()) {
                            original.getRootElement().addContent(element.clone().detach());
                        }
                    } catch (JDOMException | IOException ignored) {
                    }
                }
                including = new File(path.getParentFile(), include);
                if (including.exists()) {
                    found = true;
                    try {
                        for (Element element : parse(including).getRootElement().getChildren()) {
                            original.getRootElement().addContent(element.clone().detach());
                        }
                    } catch (JDOMException | IOException ignored) {
                    }
                }
            }
            if (!found) Bukkit.getLogger().log(Level.WARNING, "File '" + including.getName() + "' was not found nor included!");
        }
        return original;
    }

}
@@ -33,48 +33,8 @@
 l;%0A%0A
-import com.google.common.collect.Lists;%0A
 impo
@@ -229,31 +229,8 @@
 on;%0A
-import java.util.List;%0A
 impo
@@ -469,63 +469,8 @@
 e);%0A
-        List%3CString%3E toInclude = Lists.newArrayList();%0A
     
@@ -549,110 +549,8 @@
 e%22))
-%0A            toInclude.add(include.getAttributeValue(%22src%22));%0A        for (String include : toInclude)
  %7B%0A 
@@ -625,24 +625,86 @@
 rentFile();%0A
+            String source = include.getAttributeValue(%22src%22);%0A
             
@@ -727,38 +727,37 @@
  new File(path, 
-includ
+sourc
 e);%0A            
@@ -1147,22 +1147,21 @@
  while (
-includ
+sourc
 e.starts
@@ -1199,24 +1199,22 @@
     
-include = includ
+source = sourc
 e.re
@@ -1292,22 +1292,21 @@
 e(path, 
-includ
+sourc
 e);%0A    
@@ -1786,22 +1786,21 @@
 File(), 
-includ
+sourc
 e);%0A    
@@ -2405,10 +2405,9 @@
 ;%0A    %7D%0A
-%0A
 %7D

Revert 1174348