package com.johnlpage.mongosyphon;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;

import org.bson.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.json.*;

public class JobDescription {
	private Document jobDesc;
	Logger logger;

	JobDescription(String configFile) throws FileNotFoundException {
		logger = LoggerFactory.getLogger(JobDescription.class);
		String config = "";
		try {
			config = new String(Files.readAllBytes(Paths.get(configFile)),
					StandardCharsets.UTF_8);
		} catch (IOException e) {
			logger.error(e.getMessage());

			System.exit(1);
		}
		// Better errors from this parser
		try {
			@SuppressWarnings("unused")
			JSONObject obj = new JSONObject(config);
		} catch (Exception e) {
			logger.error(e.getMessage());
			System.exit(1);
		}
		jobDesc = Document.parse(config);

	}

	public Map<String, Object> getJobDesc() {
		return jobDesc;
	}

	public Document getSection(String heading) {
		if (heading == null) {
			return jobDesc.get("start", Document.class);
		}
		return jobDesc.get(heading, Document.class);
	}

}

@@ -728,16 +728,121 @@
 1);%0A%09%09%7D%0A
+%09%09%0A%09%09// Handle %5C followed by newline as line continuation%0A%09%09config = config.replaceAll(%22%5C%5C%5C%5C%5Cn%22, %22%22);%0A%09%09%0A
 %09%09// Bet

Add support for line continuation (\ at end of line) for long SQL strings