//author Emily Ecoff //December 9, 2008 import java.io.*; import java.net.*; import java.util.*; import java.util.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.lang.Object; import java.io.File; import java.io.FileReader; import java.io.BufferedReader; public class PluginComponent { public static String filename; public static String [] keyword = new String[10]; public static String Course; public static boolean keywordset = false; public static int keylength; public static Hashtable hash = new Hashtable(10,10); public static void main(String []args) throws Exception { if (args.length < 1) { System.out.println("Too few arguments."); System.out.println("Run it like this: java PluginComponent UniversalInterface_IP"); System.exit(0); } Socket universal = new Socket(args[0], 7999); MsgEncoder mEncoder = new MsgEncoder(); final MsgDecoder mDecoder = new MsgDecoder(universal.getInputStream()); /* receiving thread*/ Thread t = new Thread (new Runnable() { public void run() { KeyValueList kvInput; try { while(true) { DateFormat dateformat = new SimpleDateFormat("yyyy_MM_dd"); DateFormat dateformat2 = new SimpleDateFormat("HH:mm:ss"); java.util.Date date = new java.util.Date(); boolean append = true; kvInput = mDecoder.getMsg(); System.out.println("**************Recieved Msg**************"); int MsgID = Integer.parseInt(kvInput.getValue("MsgID")); if(MsgID == 1004){ //MsgID needs changed to appropriate ID //this is a class roster message Course = kvInput.getValue("CourseNo"); filename = Course + "_" + dateformat.format(date) + ".txt"; File file = new File(filename); boolean exists = file.exists(); System.out.println(exists); FileWriter fw = new FileWriter(filename,append); if(!exists){ fw.write("Attendance\r\n"); fw.write(Course + "\r\n"); fw.write("Teacher name: " + kvInput.getValue("TeacherFirst") + " " + kvInput.getValue("TeacherLast") + "\r\n"); fw.write("Current Date: " + dateformat.format(date) + "\r\n\r\n"); } int StudentCount = Integer.parseInt(kvInput.getValue("StudentCount")); int i = 0; for(i = 0; i