1 7 package org.jical; 8 9 import java.io.BufferedReader ; 10 import java.io.BufferedWriter ; 11 import java.io.FileInputStream ; 12 import java.io.FileWriter ; 13 import java.io.InputStreamReader ; 14 import java.text.SimpleDateFormat ; 15 import java.util.Date ; 16 import java.util.LinkedList ; 17 18 24 public class SyslogICal { 25 26 public static void main(String [] args) { 27 28 SimpleDateFormat formatter = new SimpleDateFormat ("yyyy:MM:dd HH:mm:ss"); 29 SimpleDateFormat touchformatter = new SimpleDateFormat ("yyyyMMddHHmm.ss"); 30 SimpleDateFormat syslogformatter = new SimpleDateFormat ("yyyy MMM dd HH:mm:ss"); 31 32 39 ICalendar iCal = new ICalendar(); 40 iCal.icalEventCollection = new LinkedList (); 41 iCal.setProdId("JICAL"); 42 iCal.setVersion("2.0"); 43 int iCtr = 0; 44 45 try 46 { 47 FileInputStream fin = new FileInputStream (args[0]); 48 BufferedReader myInput = null; 49 50 myInput = new BufferedReader (new InputStreamReader (fin)); 51 String buildLine = null; 52 String thisLine = ""; 53 Date startDate = null; 54 Date endDate = null; 55 57 while((thisLine = myInput.readLine()) != null) 58 { 59 if (thisLine.indexOf(args[2]) != -1) 62 { 63 startDate = syslogformatter.parse("2004 "+thisLine.substring(0,15)); 64 System.out.println(thisLine); 65 } 66 67 if (thisLine.indexOf(args[3]) != -1 68 && startDate != null) 69 { 70 endDate = syslogformatter.parse("2004 "+thisLine.substring(0,15)); 71 System.out.println(thisLine); 72 ICalendarVEvent vevent = new ICalendarVEvent(); 73 74 Date workDate = new Date (); 75 76 vevent.setDateStart(startDate); 77 vevent.setDateEnd(endDate); 78 vevent.setSummary(args[4]); 79 vevent.setDescription(""); 80 vevent.setSequence(0); 81 vevent.setEventClass("PUBLIC"); 82 vevent.setTransparency("OPAQUE"); 83 vevent.setDateStamp(workDate); 84 vevent.setCreated(workDate); 85 vevent.setLastModified(workDate); 86 vevent.setOrganizer("MAILTO:sfg@eurekait.com"); 88 iCtr++; 89 vevent.setUid("jical-"+touchformatter.format(workDate)+"-"+iCtr); 91 vevent.setPriority(3); 92 93 95 iCal.icalEventCollection.add(vevent); 96 startDate = null; 97 } 98 99 } 100 } 101 catch(Exception e) 102 { 103 e.printStackTrace(); 104 System.err.println("SomethingBad Happened:"+e); 105 } 106 107 108 try{ 109 110 113 BufferedWriter out = new BufferedWriter (new FileWriter (args[1])); 114 out.write(iCal.getVCalendar()); 115 out.close(); 116 117 } 118 catch (Exception e) 119 { 120 e.printStackTrace(); 121 System.err.println("SomethingBad Happened:"+e); 122 } 123 124 126 } 127 } 128 | Popular Tags |