-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMyHandler.java
More file actions
103 lines (84 loc) · 2.97 KB
/
MyHandler.java
File metadata and controls
103 lines (84 loc) · 2.97 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package wichackathon2020;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
*
* @author notebook
*/
class MyHandler extends DefaultHandler {
// Instance variables store values across method calls
private Calendar calendar;
private Month currentMonth;
private int currentDate;
private String currentTask;
private boolean currentDone;
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
// Check for month
if (qName.equals("calendar")) {
int year = Integer.parseInt(attributes.getValue("year"));
String semester = attributes.getValue("semester");
calendar = new Calendar(semester, year);
}
if (qName.equals("month1")) {
String name = attributes.getValue("name");
currentMonth = new Month(name);
}
if (qName.equals("month2")) {
String name = attributes.getValue("name");
currentMonth = new Month(name);
}
if (qName.equals("month3")) {
String name = attributes.getValue("name");
currentMonth = new Month(name);
}
if (qName.equals("month4")) {
String name = attributes.getValue("name");
currentMonth = new Month(name);
}
if (qName.equals("month5")) {
String name = attributes.getValue("name");
currentMonth = new Month(name);
}
if (qName.equals("entry")) {
currentDate = Integer.parseInt(attributes.getValue("date"));
}
if (qName.equals("task")) {
currentTask = attributes.getValue("name");
currentDone = Boolean.parseBoolean(attributes.getValue("done"));
}
}
public void endElement(String uri, String localName, String qName)
throws SAXException {
if (qName.equals("calendar")) {
System.out.println("Calendar is set up.");
}
if (qName.equals("month1")) {
calendar.setMonth(1, currentMonth);
}
if (qName.equals("month2")) {
calendar.setMonth(2, currentMonth);
}
if (qName.equals("month3")) {
calendar.setMonth(3, currentMonth);
}
if (qName.equals("month4")) {
calendar.setMonth(4, currentMonth);
}
if (qName.equals("month5")) {
calendar.setMonth(5, currentMonth);
}
if (qName.equals("task")) {
currentMonth.addTask(currentDate, currentTask, currentDone);
}
}
public Calendar getCalendar() {
return calendar;
}
}