package queryTool;
/*
 * Created on Dec 15, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author kfosberg
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.commons.httpclient.auth.AuthPolicy;
/* logger libraries
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
import org.apache.log4j.FileAppender;
*/

public class testObject {
	public static void main(String[] args)throws IOException  {
		// create variable space for xml
		int foundFiles = 0;
		String d1 = "";
		String id = "C03999";
		String pass = "Rev218";
		HashMap inputList = new HashMap();
		// instantiate 5 file objects
		String basedir = System.getProperty("user.dir");
		String f1 = basedir + "/casequery.xml";
		File documentOne = new File(f1);

		// look for files and read into string variables
		int s1;
		if (documentOne.exists()){
			foundFiles = foundFiles + 1;
			FileReader a = new FileReader(documentOne);
			while((s1 = a.read()) != -1){
				String t = new Character((char)s1).toString();
				d1 = d1 + t;
			}
			a.close();
		}
		if(foundFiles == 0){
			System.out.println("No XML source files found in " + basedir + " switching to form mode.");
			// In a "real world" example these wold come off the form, not be hard coded.
			inputList.put("prefix","011");
			inputList.put("last_digits","5643387");
			callServer verB = new callServer();
			verB.execute("https://www7.hud.gov/clas/html/f7cfcq.cfm",inputList,id,pass);
			System.out.println(verB.resultText);
			System.out.println(verB.resultStat);
			System.out.println();
			System.runFinalization();
	        System.gc();
		} else {
				System.out.println("Posting xml to B2G interface.");
				inputList.put("idata",d1);
				// make call
				callServer verB = new callServer();
				verB.execute("https://www7.hud.gov/b2b/chums/f17cqxml.cfm",inputList,id,pass);
				System.out.println(verB.resultText);
				System.out.println(verB.resultStat);
				System.out.println();
				System.runFinalization();
		        System.gc();
		}
	}
}