forked from jslee7/ICS314_Mangosteen
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtoICS.java
More file actions
73 lines (68 loc) · 2.4 KB
/
toICS.java
File metadata and controls
73 lines (68 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.TimeZone;
public class toICS
{
PrintWriter pw;
String summary, timeEnd, timeStart, priority, protection;
//takes user input and generates a .ics file for them to use in calender
public toICS(PrintWriter pw,String summary,String timeStart,String timeEnd,String priority,String protection) throws IOException
{
this.pw = pw;
this.summary = summary;
this.timeStart = timeStart;
this.timeEnd = timeEnd;
this.priority = priority;
this.protection = protection;
}
public void createEvent()
{
pw.println("BEGIN: VEVENT");
pw.println("VERSION:2.0");
pw.println("SUMMARY:"+summary);
pw.println("DTSTART;TZID=/"+getTimeZone()+":"+timeStart);
pw.println("DTSTART;TZID=/"+getTimeZone()+":"+timeEnd);
//body
pw.println("CLASS:"+protection);
pw.println("END:VEVENT");
}
public String getTimeZone()
{
TimeZone tz = TimeZone.getDefault();
String ID = tz.getID();
return ID;
}
public static void main(String[] args)
{
//random test values just to see if it generates a file
//it does and it saves it in the current d
String fileName = "",summary = "meh", timeEnd = "6", timeStart = "5",priority = "1",protection = "PRIVATE";
int check = 1;
Scanner keyboard = new Scanner(System.in);
System.out.println("This is a program that generates .ics files which can be uploaded to a calender.");
System.out.println("The .ics files will be saved to the directory that this program resides in.");
System.out.println("Please enter the name of the file you wish to write to(don't include .ics).");
fileName = keyboard.next();
PrintWriter pw;
try
{
pw = new PrintWriter(new FileWriter(fileName+".ics"));
pw.println("BEGIN:VCALENDER"); //only neccesary once, but not quite sure if we need this
while(check == 1)
{
System.out.println("Please enter a Summary of your event");
//user enters summary,timeStart,timeEnd,priority, level of protection(public,private,protected)
toICS event = new toICS(pw,summary,timeEnd,timeStart,priority,protection);
event.createEvent();
System.out.println("Would you like to enter another event?");
System.out.println("If so enter 1, if not enter 0");
check = keyboard.nextInt();
}
pw.println("END:VCALENDER"); //only neccesary once
pw.close();
}
catch (IOException e) {e.printStackTrace();}
}
}