// Path: substratum-template-patcher/src/main/java/com/pddstudio/substratum/template/patcher/internal/LinePatcher.java
// public abstract class LinePatcher implements Patcher<String, String, String> {
// 
// 	@Override
// 	public String patch(String target, String key, String value) {
// 		return patchLine(target, key, value);
// 	}
// 
// 	public abstract String patchLine(String line, String targetKey, String replacementValue);
// }
// 
// Path: substratum-template-patcher/src/main/java/com/pddstudio/substratum/template/patcher/internal/model/JsonConfigModel.java
// public class JsonConfigModel implements Serializable, ThemeConfiguration {
// 
// 	@SerializedName("themeName")
// 	private String themeName;
// 
// 	@SerializedName("themeAuthor")
// 	private String themeAuthor;
// 
// 	@SerializedName("themeTemplates")
// 	private List<Template> templateList;
// 
// 	@Override
// 	public String getThemeName() {
// 		return themeName;
// 	}
// 
// 	@Override
// 	public String getThemeAuthor() {
// 		return themeAuthor;
// 	}
// 
// 	@Override
// 	public List<TemplateConfiguration> getThemeTemplates() {
// 		List<TemplateConfiguration> configurations = new ArrayList<>();
// 		StreamSupport.stream(templateList).filter(Objects::nonNull).forEach(configurations::add);
// 		return configurations;
// 	}
// 
// }


import android.util.Log;
import com.google.gson.Gson;
import com.pddstudio.substratum.template.patcher.internal.LinePatcher;
import com.pddstudio.substratum.template.patcher.internal.model.JsonConfigModel;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java8.util.stream.Collectors;
import java8.util.stream.StreamSupport;
		}
	}

	private void patch(TemplateConfiguration templateConfiguration, PatchingCallback callback) throws PatchingException {
		File templateFile = callback.resolveTemplateFileName(templateConfiguration.getTemplateFileName());
		if(templateFile == null ||!templateFile.exists() || templateFile.isDirectory()) {
			throw new PatchingException("Template File must not be null, empty or a directory!");
		}
		try {
			List<String> content = FileUtils.readLines(templateFile, Charset.forName("utf-8"));
			List<String> patchedContent = patchLines(content, templateConfiguration);
			if(patchedContent != null && !patchedContent.isEmpty()) {
				File newDestination = new File(templateFile.getParentFile(), FilenameUtils.removeExtension(callback.getPatchedFileName(templateConfiguration) + ".xml"));
				StreamSupport.stream(patchedContent).forEach(line -> Log.d(TAG, "PATCHED: " + line));
				FileUtils.writeLines(newDestination, patchedContent, false);
			}
		} catch (IOException e) {
			throw new PatchingException(e);
		}
	}

	public static final class Builder {

		private final List<File> targetFiles;
		private LinePatcher linePatcher = XmlPatcher.getInstance();
		private final ThemeConfiguration themeConfiguration;

		public static Builder fromJson(String jsonContent) throws PatchingException {
			Log.d("TemplatePatcher$Builder", "JSON: " + jsonContent);
			Gson gson = new Gson();
// Path: substratum-template-patcher/src/main/java/com/pddstudio/substratum/template/patcher/internal/LinePatcher.java
// public abstract class LinePatcher implements Patcher<String, String, String> {
// 
// 	@Override
// 	public String patch(String target, String key, String value) {
// 		return patchLine(target, key, value);
// 	}
// 
// 	public abstract String patchLine(String line, String targetKey, String replacementValue);
// }
// 
// Path: substratum-template-patcher/src/main/java/com/pddstudio/substratum/template/patcher/internal/model/JsonConfigModel.java
// public class JsonConfigModel implements Serializable, ThemeConfiguration {
// 
// 	@SerializedName("themeName")
// 	private String themeName;
// 
// 	@SerializedName("themeAuthor")
// 	private String themeAuthor;
// 
// 	@SerializedName("themeTemplates")
// 	private List<Template> templateList;
// 
// 	@Override
// 	public String getThemeName() {
// 		return themeName;
// 	}
// 
// 	@Override
// 	public String getThemeAuthor() {
// 		return themeAuthor;
// 	}
// 
// 	@Override
// 	public List<TemplateConfiguration> getThemeTemplates() {
// 		List<TemplateConfiguration> configurations = new ArrayList<>();
// 		StreamSupport.stream(templateList).filter(Objects::nonNull).forEach(configurations::add);
// 		return configurations;
// 	}
// 
// }


// Path: substratum-template-patcher/src/main/java/com/pddstudio/substratum/template/patcher/TemplatePatcher.java
import android.util.Log;
import com.google.gson.Gson;
import com.pddstudio.substratum.template.patcher.internal.LinePatcher;
import com.pddstudio.substratum.template.patcher.internal.model.JsonConfigModel;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java8.util.stream.Collectors;
import java8.util.stream.StreamSupport;

		}
	}

	private void patch(TemplateConfiguration templateConfiguration, PatchingCallback callback) throws PatchingException {
		File templateFile = callback.resolveTemplateFileName(templateConfiguration.getTemplateFileName());
		if(templateFile == null ||!templateFile.exists() || templateFile.isDirectory()) {
			throw new PatchingException("Template File must not be null, empty or a directory!");
		}
		try {
			List<String> content = FileUtils.readLines(templateFile, Charset.forName("utf-8"));
			List<String> patchedContent = patchLines(content, templateConfiguration);
			if(patchedContent != null && !patchedContent.isEmpty()) {
				File newDestination = new File(templateFile.getParentFile(), FilenameUtils.removeExtension(callback.getPatchedFileName(templateConfiguration) + ".xml"));
				StreamSupport.stream(patchedContent).forEach(line -> Log.d(TAG, "PATCHED: " + line));
				FileUtils.writeLines(newDestination, patchedContent, false);
			}
		} catch (IOException e) {
			throw new PatchingException(e);
		}
	}

	public static final class Builder {

		private final List<File> targetFiles;
		private LinePatcher linePatcher = XmlPatcher.getInstance();
		private final ThemeConfiguration themeConfiguration;

		public static Builder fromJson(String jsonContent) throws PatchingException {
			Log.d("TemplatePatcher$Builder", "JSON: " + jsonContent);
			Gson gson = new Gson();
			JsonConfigModel configModel = gson.fromJson(jsonContent, JsonConfigModel.class);