// Path: EclipsePlugin/plugin/src/io/leocad/dumbledroidplugin/exceptions/InvalidContentException.java
// public class InvalidContentException extends Exception {
// 
// 	private static final long serialVersionUID = 8125988022163808304L;
// 	
// 	private String mContentType;
// 	
// 	public InvalidContentException(String contentType) {
// 		mContentType = contentType;
// 	}
// 
// 	@Override
// 	public String getMessage() {
// 		
// 		return String.format("The provided '%s' is invalid or corrupted. Please validate it here: %s", mContentType, getValidationUrl());
// 	}
// 	
// 	private String getValidationUrl() {
// 		return mContentType.toLowerCase().equals("json")?
// 			"http://jsonlint.com/":
// 			"http://www.w3schools.com/xml/xml_validator.asp";
// 	}
// }
// 
// Path: EclipsePlugin/plugin/src/io/leocad/dumbledroidplugin/exceptions/InvalidUrlException.java
// public class InvalidUrlException extends Exception {
// 
// 	private static final long serialVersionUID = -309967699128351284L;
// 
// 	@Override
// 	public String getMessage() {
// 		
// 		return "The provided URL does not point to a valid address. Please double check it. If it seems to be OK, check your internet connection.";
// 	}
// }


import io.leocad.dumbledroidplugin.exceptions.InvalidContentException;
import io.leocad.dumbledroidplugin.exceptions.InvalidUrlException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Iterator;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Path;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
package io.leocad.dumbledroidplugin.core;




public class JsonReverseReflector {

	public static void parseJsonToFiles(InputStream is, String url, String urlQueryString, boolean isPojo, long cacheDuration, IFile file) throws InvalidUrlException, InvalidContentException {

		String jsonString = getJsonString(is);

		JSONObject jsonObj = null;
		JSONArray jsonArray = null;

		try {
			jsonObj = new JSONObject(jsonString);

		} catch (JSONException e) {
			//Not a JsonObject. Try an array…
			try {
				jsonArray = new JSONArray(jsonString);

			} catch (JSONException e2) {
				//Not a valid JSON.
				throw new InvalidContentException("JSON");
			}
		}

		if (jsonObj != null) {
			processJsonObjectFile(jsonObj, true, url, urlQueryString, isPojo, cacheDuration, file);
		} else {
			processJsonArrayFile(jsonArray, true, url, urlQueryString, isPojo, cacheDuration, file);
		}
	}

	private static String getJsonString(InputStream is) throws InvalidUrlException {

		StringBuilder total = new StringBuilder();

		try {
// Path: EclipsePlugin/plugin/src/io/leocad/dumbledroidplugin/exceptions/InvalidContentException.java
// public class InvalidContentException extends Exception {
// 
// 	private static final long serialVersionUID = 8125988022163808304L;
// 	
// 	private String mContentType;
// 	
// 	public InvalidContentException(String contentType) {
// 		mContentType = contentType;
// 	}
// 
// 	@Override
// 	public String getMessage() {
// 		
// 		return String.format("The provided '%s' is invalid or corrupted. Please validate it here: %s", mContentType, getValidationUrl());
// 	}
// 	
// 	private String getValidationUrl() {
// 		return mContentType.toLowerCase().equals("json")?
// 			"http://jsonlint.com/":
// 			"http://www.w3schools.com/xml/xml_validator.asp";
// 	}
// }
// 
// Path: EclipsePlugin/plugin/src/io/leocad/dumbledroidplugin/exceptions/InvalidUrlException.java
// public class InvalidUrlException extends Exception {
// 
// 	private static final long serialVersionUID = -309967699128351284L;
// 
// 	@Override
// 	public String getMessage() {
// 		
// 		return "The provided URL does not point to a valid address. Please double check it. If it seems to be OK, check your internet connection.";
// 	}
// }


// Path: EclipsePlugin/plugin/src/io/leocad/dumbledroidplugin/core/JsonReverseReflector.java
import io.leocad.dumbledroidplugin.exceptions.InvalidContentException;
import io.leocad.dumbledroidplugin.exceptions.InvalidUrlException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Iterator;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Path;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

package io.leocad.dumbledroidplugin.core;




public class JsonReverseReflector {

	public static void parseJsonToFiles(InputStream is, String url, String urlQueryString, boolean isPojo, long cacheDuration, IFile file) throws InvalidUrlException, InvalidContentException {

		String jsonString = getJsonString(is);

		JSONObject jsonObj = null;
		JSONArray jsonArray = null;

		try {
			jsonObj = new JSONObject(jsonString);

		} catch (JSONException e) {
			//Not a JsonObject. Try an array…
			try {
				jsonArray = new JSONArray(jsonString);

			} catch (JSONException e2) {
				//Not a valid JSON.
				throw new InvalidContentException("JSON");
			}
		}

		if (jsonObj != null) {
			processJsonObjectFile(jsonObj, true, url, urlQueryString, isPojo, cacheDuration, file);
		} else {
			processJsonArrayFile(jsonArray, true, url, urlQueryString, isPojo, cacheDuration, file);
		}
	}

	private static String getJsonString(InputStream is) throws InvalidUrlException {

		StringBuilder total = new StringBuilder();

		try {
			BufferedReader r = new BufferedReader(new InputStreamReader(is));