Created
June 2, 2011 08:56
-
-
Save anonymous/1004136 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class LocationData { | |
| private String term = ""; | |
| private String startDate = ""; | |
| private String endDate = ""; | |
| private String locationTitle = ""; | |
| private String weekdays = ""; | |
| private String weekdaysTime = ""; | |
| private String weekend = ""; | |
| private String weekendTime = ""; | |
| private String publicHoliday = ""; | |
| private String publicHolidayTime = ""; | |
| public String getTerm() { | |
| return term; | |
| } | |
| public void setTerm(String term) { | |
| this.term = term; | |
| } | |
| public String getStartDate() { | |
| return startDate; | |
| } | |
| public void setStartDate(String startDate) { | |
| this.startDate = startDate; | |
| } | |
| public String getEndDate() { | |
| return endDate; | |
| } | |
| public void setEndDate(String endDate) { | |
| this.endDate = endDate; | |
| } | |
| public String getLocationTitle() { | |
| return locationTitle; | |
| } | |
| public void setLocationTitle(String locationTitle) { | |
| this.locationTitle = locationTitle; | |
| } | |
| public String getWeekdays() { | |
| return weekdays; | |
| } | |
| public void setWeekdays(String weekdays) { | |
| this.weekdays = weekdays; | |
| } | |
| public String getWeekdaysTime() { | |
| return weekdaysTime; | |
| } | |
| public void setWeekdaysTime(String weekdaysTime) { | |
| this.weekdaysTime = weekdaysTime; | |
| } | |
| public String getWeekend() { | |
| return weekend; | |
| } | |
| public void setWeekEnd(String weekend) { | |
| this.weekend = weekend; | |
| } | |
| public String getWeekendTime() { | |
| return weekendTime; | |
| } | |
| public void setWeekendTime(String weekendTime) { | |
| this.weekendTime = weekendTime; | |
| } | |
| public String getPublicHoliday() { | |
| return publicHoliday; | |
| } | |
| public void setPublicHoliday(String publicHoliday) { | |
| this.publicHoliday = publicHoliday; | |
| } | |
| public String getPublicHolidayTime() { | |
| return publicHolidayTime; | |
| } | |
| public void setPublicHolidayTime(String publicHolidayTime) { | |
| this.publicHolidayTime = publicHolidayTime; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList; | |
| public class LocationList { | |
| LocationData locationData; | |
| private ArrayList<LocationData> locationList = new ArrayList<LocationData>(); | |
| public ArrayList<LocationData> getLocationList() { | |
| return locationList; | |
| } | |
| public void addLocationData(LocationData locationData) { | |
| this.locationList.add(locationData); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList; | |
| public class OHList { | |
| SemesterList semList; | |
| private ArrayList<SemesterList> OHList = new ArrayList<SemesterList>(); | |
| public ArrayList<SemesterList> getOHList() { | |
| return OHList; | |
| } | |
| public void addSemList(SemesterList semList) { | |
| this.OHList.add(semList); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList; | |
| public class SemesterList { | |
| TermsList termsList; | |
| private ArrayList<TermsList> semesterList = new ArrayList<TermsList>(); | |
| public ArrayList<TermsList> getSemesterList() { | |
| return semesterList; | |
| } | |
| public void addTermsList(TermsList termsList) { | |
| this.semesterList.add(termsList); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList; | |
| public class TermsList { | |
| LocationList locationList; | |
| private ArrayList<LocationList> termsList = new ArrayList<LocationList>(); | |
| public ArrayList<LocationList> getTermsList() { | |
| return termsList; | |
| } | |
| public void addLocationList(LocationList locationList) { | |
| this.termsList.add(locationList); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.TPLibrary.OpeningHours.*; | |
| public class OpeningHoursXMLHandler extends DefaultHandler{ | |
| public OHList ohList; | |
| LocationData locationData; | |
| LocationList locationList; | |
| TermsList termsList; | |
| SemesterList semList; | |
| private Boolean in_category = false; | |
| private Boolean in_category_title= false; | |
| private Boolean in_subcategory_term = false; | |
| private Boolean in_subcategory_location = false; | |
| private Boolean in_subcategory_string = false; | |
| private Boolean in_subcategory_weekday = false; | |
| private Boolean in_subcategory_weekend = false; | |
| private Boolean in_subcategory_publicholiday = false; | |
| private String term = ""; | |
| private String start_term_date = ""; | |
| private String end_term_date = ""; | |
| private String title = ""; | |
| private String startToEnd_Weekdays = ""; | |
| private String startToEndTime_Weekdays = ""; | |
| private String startToEnd_Weekends = ""; | |
| private String startToEndTime_Weekends = ""; | |
| private String startToEnd_PH = ""; | |
| private String startToEndTime_PH; | |
| private String stringValue = ""; | |
| private String originalString = ""; | |
| private int term_duration_count; | |
| private int count; | |
| @Override | |
| public void startDocument() throws SAXException { | |
| // Nothing to do | |
| } | |
| @Override | |
| public void endDocument() throws SAXException { | |
| // Nothing to do | |
| } | |
| @Override | |
| public void startElement(String uri, String localName, String qName, | |
| Attributes attributes) throws SAXException { | |
| //if-else for openinghours details | |
| if (localName.equalsIgnoreCase("array")) { | |
| if (attributes.getValue("id").equalsIgnoreCase("openinghours")) { | |
| ohList = new OHList(); | |
| semList = new SemesterList(); | |
| termsList = new TermsList(); | |
| locationList = new LocationList(); | |
| locationData = new LocationData(); | |
| this.in_category = true; | |
| } | |
| else if (attributes.getValue("id").equalsIgnoreCase("Semester")) { | |
| this.in_category_title= true; | |
| } | |
| else if (attributes.getValue("id").equalsIgnoreCase("term")) { | |
| term_duration_count = 0; | |
| this.in_subcategory_term = true; | |
| } | |
| else if (attributes.getValue("id").equalsIgnoreCase("location")) { | |
| count = 0; | |
| in_subcategory_location = true; | |
| } | |
| else if (attributes.getValue("id").equalsIgnoreCase("wkday")) { | |
| this.in_subcategory_weekday = true; | |
| } | |
| else if (attributes.getValue("id").equalsIgnoreCase("wkend")) { | |
| this.in_subcategory_weekend = true; | |
| } | |
| else if (attributes.getValue("id").equalsIgnoreCase("ph")) { | |
| this.in_subcategory_publicholiday = true; | |
| } | |
| } | |
| else if (localName.equalsIgnoreCase("string")) { | |
| term_duration_count++; | |
| if (term_duration_count >= 4) | |
| count++; | |
| this.in_subcategory_string = true; | |
| } | |
| } | |
| public void characters(char[] ch, int start, int length) | |
| throws SAXException { | |
| StringBuffer sb = new StringBuffer(); | |
| String finalString = ""; | |
| String chars = new String(ch, start, length); | |
| chars = chars.trim(); | |
| if (this.in_subcategory_string) { | |
| if (!(chars.equals(""))) { | |
| sb.append(chars); | |
| finalString = sb.toString(); | |
| if (finalString.contains("&")) { | |
| originalString = this.stringValue + " " + finalString; | |
| this.stringValue = originalString; | |
| } | |
| else { | |
| originalString = this.stringValue + " " + finalString; | |
| this.stringValue = finalString; | |
| } | |
| } | |
| } | |
| } | |
| @Override | |
| public void endElement(String uri, String localName, String qName) | |
| throws SAXException { | |
| //if-else for openinghours details | |
| if (localName.equalsIgnoreCase("array")) { | |
| ohList.addSemList(semList); | |
| semList.addTermsList(termsList); | |
| termsList.addLocationList(locationList); | |
| locationList.addLocationData(locationData); | |
| this.in_category = false; | |
| } | |
| else if (this.in_subcategory_string) { | |
| if (term_duration_count == 1) { | |
| term = stringValue; | |
| locationData.setTerm(term); | |
| } | |
| if (term_duration_count == 2) { | |
| start_term_date = stringValue; | |
| locationData.setStartDate(start_term_date); | |
| } | |
| if (term_duration_count == 3) { | |
| end_term_date = stringValue; | |
| locationData.setEndDate(end_term_date); | |
| } | |
| if (count == 1) { | |
| title = stringValue; | |
| locationData.setLocationTitle(title); | |
| } | |
| if (count == 2) { | |
| startToEnd_Weekdays = stringValue; | |
| locationData.setWeekdays(startToEnd_Weekdays); | |
| } | |
| if (count == 3) { | |
| startToEndTime_Weekdays = stringValue; | |
| locationData.setWeekdaysTime(startToEndTime_Weekdays); | |
| } | |
| if (count == 4) { | |
| startToEnd_Weekends = stringValue; | |
| locationData.setWeekEnd(startToEnd_Weekends); | |
| } | |
| if (count == 5) { | |
| startToEndTime_Weekends = stringValue; | |
| locationData.setWeekendTime(startToEndTime_Weekends); | |
| } | |
| if (count == 6) { | |
| /** | |
| * Special Case: | |
| * Due to this entire string from the xml contains character "&" we have to do a sort of work-around | |
| * instead of setting startToEnd_PH string with stringValue | |
| * set it with originalString as this contains the entire string WITH "&" | |
| * stringValue contains only the text after the char "&" | |
| * if you dun understand, debug ^^ | |
| */ | |
| startToEnd_PH = originalString; | |
| locationData.setPublicHoliday(startToEnd_PH); | |
| } | |
| if (count == 7) { | |
| startToEndTime_PH = stringValue; | |
| locationData.setPublicHolidayTime(startToEndTime_PH); | |
| } | |
| this.in_subcategory_string = false; | |
| } | |
| else if (this.in_category_title) { | |
| this.in_category_title = false; | |
| } | |
| else if (this.in_subcategory_location) { | |
| this.in_subcategory_location = false; | |
| } | |
| else if (this.in_subcategory_term) { | |
| this.in_subcategory_term = false; | |
| } | |
| else if (this.in_subcategory_weekday) { | |
| this.in_subcategory_weekday = false; | |
| } | |
| else if (this.in_subcategory_weekend) { | |
| this.in_subcategory_weekend = false; | |
| } | |
| else if (this.in_subcategory_publicholiday) { | |
| this.in_subcategory_publicholiday = false; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment