package in.twizmwaz.cardinal.util;

import org.jdom2.Document;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;

import java.io.File;
import java.io.IOException;

public class DomUtils {

    public static Document parse(File file) throws JDOMException, IOException {
        SAXBuilder saxBuilder = new SAXBuilder();
        return saxBuilder.build(file);

    }
}

@@ -44,18 +44,70 @@
 org.
-jdom2.Docu
+bukkit.Bukkit;%0Aimport org.jdom2.Document;%0Aimport org.jdom2.Ele
 ment
@@ -212,27 +212,92 @@
 java.io.
-IOException
+FileNotFoundException;%0Aimport java.io.IOException;%0Aimport java.nio.file.Path
 ;%0A%0Apubli
@@ -458,14 +458,27 @@
     
-return
+Document original =
  sax
@@ -498,16 +498,1111 @@
 (file);%0A
+        Path repo = file.getParentFile().getParentFile().toPath();%0A        for (Element include : original.getRootElement().getChildren(%22include%22)) %7B%0A            try %7B%0A                Path included;%0A                try %7B%0A                    included = repo.resolve(include.getAttributeValue(%22src%22)).normalize();%0A                    for (Element element : parse(included.toFile()).getRootElement().getChildren()) %7B%0A                        original.getRootElement().addContent(element.detach());%0A                    %7D%0A                %7D catch (FileNotFoundException e) %7B%0A                    included = file.getParentFile().toPath().resolve(include.getAttributeValue(%22src%22)).normalize();%0A                    for (Element element : parse(included.toFile()).getRootElement().getChildren()) %7B%0A                        original.getRootElement().addContent(element.detach());%0A                        Bukkit.getLogger().info(element.getName());%0A                    %7D%0A                %7D%0A            %7D catch (Exception e) %7B%0A                e.printStackTrace();%0A            %7D%0A        %7D%0A        return original;
 %0A    %7D%0A%7D

Add includes, not working yet