List of usage examples for org.dom4j Document addDocType
Document addDocType(String name, String publicId, String systemId);
From source file:org.unitime.timetable.dataexchange.PointInTimeDataExport.java
License:Apache License
public void saveXml(Document document, Session session, Properties parameters) throws Exception { try {// ww w . j av a 2 s . c o m beginTransaction(); Date timestamp = new Date(); info("Data extract for Point in Time Data started at: " + timestamp.toString()); Element root = document.addElement(sRootElementName); root.addAttribute(sAcademicSessionUniqueIdAttribute, session.getUniqueId().toString()); root.addAttribute(sAcademicInitiativeAttribute, session.getAcademicInitiative()); root.addAttribute(sAcademicYearAttribute, session.getAcademicYear()); root.addAttribute(sAcademicTermAttribute, session.getAcademicTerm()); root.addAttribute(sDateFormatAttribute, sDateFormat.toPattern()); root.addAttribute(sTimeFormatAttribute, sTimeFormat.toPattern()); root.addAttribute(sCreatedAttribute, (sDateFormat.format(timestamp) + " " + sTimeFormat.format(timestamp))); root.addAttribute(sSessionBeginDateAttribute, sDateFormat.format(session.getSessionBeginDateTime())); root.addAttribute(sSessionEndDateAttribute, sDateFormat.format(session.getSessionEndDateTime())); root.addAttribute(sClassesEndDateAttribute, sDateFormat.format(session.getClassesEndDateTime())); if (session.getDefaultClassDurationType() != null) { root.addAttribute(sDurationTypeAttribute, session.getDefaultClassDurationType().getReference()); } String name = session.getAcademicInitiative() + session.getAcademicYear() + session.getAcademicTerm() + timestamp.getTime(); String note = "This is a point in time data snapshot for session: " + session.getLabel() + ", taken on: " + timestamp.toString(); root.addAttribute(sPointInTimeNameAttribute, name); root.addAttribute(sPointInTimeNoteAttribute, note); document.addDocType(sRootElementName, "-//UniTime//DTD University Course Timetabling/EN", "http://www.unitime.org/interface/PointInTimeData.dtd"); info("Loading Data..."); TreeSet<InstructionalOffering> offerings = findOfferingsWithClasses(session); info("Loaded " + offerings.size() + " Instructional Offerings"); ArrayList<AcademicArea> academicAreas = findAcademicAreas(session); info("Loaded " + academicAreas.size() + " Academic Areas"); ArrayList<StudentClassEnrollment> studentClassEnrollments = findStudentClassEnrollments(session); info("Loaded " + studentClassEnrollments.size() + " Student Class Enrollments"); ArrayList<Location> locations = findLocations(session); info("Loaded " + locations.size() + " Locations"); ArrayList<TimePattern> timePatterns = findTimePatterns(session); info("Loaded " + timePatterns.size() + " Time Patterns"); ArrayList<Object[]> eventMeetings = findClassEvents(session); info("Loaded " + eventMeetings.size() + " Class Events"); info("Default Date Pattern: " + session.getDefaultDatePatternNotNull()); timePatterns.size(); locations.size(); Date endTransTimestamp = new Date(); info("Data extract for Point in Time Data ended at: " + endTransTimestamp.toString()); info("Milliseconds elapsed = " + (endTransTimestamp.getTime() - timestamp.getTime())); departmentsElement = root.addElement(sDepartmentsElementName); roomTypesElement = root.addElement(sRoomTypesElementName); creditTypesElement = root.addElement(sCreditTypesElementName); creditUnitTypesElement = root.addElement(sCreditUnitTypesElementName); positionTypesElement = root.addElement(sPositionTypesElementName); teachingResponsibilitiesElement = root.addElement(sTeachingResponsibilitiesElementName); locationsElement = root.addElement(sLocationsElementName); studentsElement = root.addElement(sStudentsElementName); courseTypesElement = root.addElement(sCourseTypesElementName); classDurationTypesElement = root.addElement(sClassDurationTypesElementName); instructionalMethodsElement = root.addElement(sInstructionalMethodsElementName); timePatternsElement = root.addElement(sTimePatternsElementName); datePatternsElement = root.addElement(sDatePatternsElementName); academicAreasElement = root.addElement(sAcademicAreasElementName); academicClassificationsElement = root.addElement(sAcademicClassificationsElementName); majorsElement = root.addElement(sMajorsElementName); minorsElement = root.addElement(sMinorsElementName); offeringsElement = root.addElement(sOfferingsElementName); info("Exporting " + offerings.size() + " offerings ..."); for (InstructionalOffering io : offerings) { info("Exporting offering: " + io.getControllingCourseOffering().getCourseNameWithTitle()); exportInstructionalOffering(offeringsElement, io, session); } int numMeetings = eventMeetings.size(); info("Exporting student class enrollments ..."); for (StudentClassEnrollment sce : studentClassEnrollments) { exportStudentClassEnrollment(sce); } info("Exporting " + numMeetings + " class event meetings ..."); int count = 0; for (Object[] objs : eventMeetings) { count++; ClassEvent classEvent = (ClassEvent) objs[0]; Meeting meeting = (Meeting) objs[1]; Location location = (Location) objs[2]; exportClassEvent(classEvent, meeting, location); if (count % 10000 == 0) { info("Exported " + count + " of " + numMeetings + " class event meetings, " + 100 * count / numMeetings + "% complete."); } } info("Export of class event meetings complete."); Date endProcessingTimestamp = new Date(); info("XML creation for Point in Time Data ended at: " + endProcessingTimestamp.toString()); info("Milliseconds elapsed since data extract = " + (endProcessingTimestamp.getTime() - endTransTimestamp.getTime())); commitTransaction(); } catch (Exception e) { fatal("Exception: " + e.getMessage(), e); rollbackTransaction(); } }
From source file:org.unitime.timetable.dataexchange.RoomSharingExport.java
License:Open Source License
@Override public void saveXml(Document document, Session session, Properties parameters) throws Exception { try {// www . j a v a2 s . com beginTransaction(); Element root = document.addElement("roomSharing"); root.addAttribute("campus", session.getAcademicInitiative()); root.addAttribute("year", session.getAcademicYear()); root.addAttribute("term", session.getAcademicTerm()); root.addAttribute("created", new Date().toString()); root.addAttribute("timeFormat", "HHmm"); document.addDocType("roomSharing", "-//UniTime//UniTime Room Sharing DTD/EN", "http://www.unitime.org/interface/RoomSharing.dtd"); List<Location> locations = Location.findAll(session.getUniqueId()); Collections.sort(locations); for (Location location : locations) { Element locEl = root.addElement("location"); fillLocationData(location, locEl); if (location.getShareNote() != null) locEl.addAttribute("note", location.getShareNote()); Map<Long, Department> id2dept = new HashMap<Long, Department>(); for (RoomDept rd : location.getRoomDepts()) { Element deptEl = locEl.addElement("department"); fillDepartmentData(rd, deptEl); id2dept.put(rd.getDepartment().getUniqueId(), rd.getDepartment()); } RoomSharingModel model = location.getRoomSharingModel(); if (model != null && !model.allAvailable(null)) { Element sharingEl = locEl.addElement("sharing"); boolean out[][] = new boolean[model.getNrDays()][model.getNrTimes()]; for (int i = 0; i < model.getNrDays(); i++) for (int j = 0; j < model.getNrTimes(); j++) out[i][j] = false; for (int i = 0; i < model.getNrDays(); i++) for (int j = 0; j < model.getNrTimes(); j++) { if (out[i][j]) continue; out[i][j] = true; if (model.isFreeForAll(i, j)) continue; int endDay = i, endTime = j; String p = model.getPreference(i, j); while (endTime + 1 < model.getNrTimes() && !out[i][endTime + 1] && model.getPreference(i, endTime + 1).equals(p)) endTime++; while (endDay + 1 < model.getNrDays()) { boolean same = true; for (int x = j; x <= endTime; x++) if (!out[endDay + 1][x] && !model.getPreference(endDay + 1, x).equals(p)) { same = false; break; } if (!same) break; endDay++; } for (int a = i; a <= endDay; a++) for (int b = j; b <= endTime; b++) out[a][b] = true; Element el = null; Department dept = null; if (model.isNotAvailable(i, j)) { el = sharingEl.addElement("unavailable"); } else { dept = id2dept.get(model.getDepartmentId(i, j)); if (dept == null) continue; el = sharingEl.addElement("assigned"); } if (i == 0 && endDay + 1 == model.getNrDays()) { // all week } else { String day = ""; for (int a = i; a <= endDay; a++) day += Constants.DAY_NAMES_SHORT[a]; el.addAttribute("days", day); } if (j == 0 && endTime + 1 == model.getNrTimes()) { // all day } else { el.addAttribute("start", slot2time(j)); el.addAttribute("end", slot2time(endTime + 1)); } if (dept != null) fillDepartmentData(dept, el); } } } commitTransaction(); } catch (Exception e) { fatal("Exception: " + e.getMessage(), e); rollbackTransaction(); } }
From source file:org.unitime.timetable.dataexchange.StudentAdvisorsExport.java
License:Apache License
@Override public void saveXml(Document document, Session session, Properties parameters) throws Exception { try {//from w ww . j ava2 s . co m beginTransaction(); Element root = document.addElement("studentAdvisors"); root.addAttribute("campus", session.getAcademicInitiative()); root.addAttribute("year", session.getAcademicYear()); root.addAttribute("term", session.getAcademicTerm()); root.addAttribute("created", new Date().toString()); document.addDocType("studentAdvisors", "-//UniTime//UniTime Student Advisors DTD/EN", "http://www.unitime.org/interface/StudentAdvisors.dtd"); for (Advisor advisor : (List<Advisor>) getHibSession().createQuery( "from Advisor a where a.session.uniqueId = :sessionId order by a.lastName, a.firstName, a.externalUniqueId") .setLong("sessionId", session.getUniqueId()).list()) { Element advisorEl = root.addElement("studentAdvisor"); advisorEl.addAttribute("externalId", advisor.getExternalUniqueId()); if (advisor.getFirstName() != null) advisorEl.addAttribute("firstName", advisor.getFirstName()); if (advisor.getMiddleName() != null) advisorEl.addAttribute("middleName", advisor.getMiddleName()); if (advisor.getLastName() != null) advisorEl.addAttribute("lastName", advisor.getLastName()); if (advisor.getAcademicTitle() != null) advisorEl.addAttribute("acadTitle", advisor.getAcademicTitle()); if (advisor.getEmail() != null) advisorEl.addAttribute("email", advisor.getEmail()); if (advisor.getRole() != null) advisorEl.addAttribute("role", advisor.getRole().getReference()); Element updateStudentsEl = advisorEl.addElement("updateStudents"); if (advisor.getStudents() != null) for (Student student : advisor.getStudents()) if (student.getExternalUniqueId() != null) updateStudentsEl.addElement("student").addAttribute("externalId", student.getExternalUniqueId()); } commitTransaction(); } catch (Exception e) { fatal("Exception: " + e.getMessage(), e); rollbackTransaction(); } }
From source file:org.unitime.timetable.dataexchange.StudentEnrollmentExport.java
License:Open Source License
@Override public void saveXml(Document document, Session session, Properties parameters) throws Exception { try {// ww w . j a v a 2 s . c om beginTransaction(); Element root = document.addElement("studentEnrollments"); root.addAttribute("campus", session.getAcademicInitiative()); root.addAttribute("year", session.getAcademicYear()); root.addAttribute("term", session.getAcademicTerm()); document.addDocType("studentEnrollments", "-//UniTime//UniTime Student Enrollments DTD/EN", "http://www.unitime.org/interface/StudentEnrollment.dtd"); for (Student student : (List<Student>) getHibSession() .createQuery("select s from Student s where s.session.uniqueId = :sessionId") .setLong("sessionId", session.getUniqueId()).list()) { if (student.getClassEnrollments().isEmpty()) continue; Element studentEl = root.addElement("student"); studentEl.addAttribute("externalId", student.getExternalUniqueId() == null || student.getExternalUniqueId().isEmpty() ? student.getUniqueId().toString() : student.getExternalUniqueId()); for (StudentClassEnrollment enrollment : student.getClassEnrollments()) { Element classEl = studentEl.addElement("class"); Class_ clazz = enrollment.getClazz(); CourseOffering course = enrollment.getCourseOffering(); String extId = (course == null ? clazz.getExternalUniqueId() : clazz.getExternalId(course)); if (extId != null && !extId.isEmpty()) classEl.addAttribute("externalId", extId); if (course != null) { if (course.getExternalUniqueId() != null && !course.getExternalUniqueId().isEmpty()) classEl.addAttribute("courseId", course.getExternalUniqueId()); classEl.addAttribute("subject", course.getSubjectAreaAbbv()); classEl.addAttribute("courseNbr", course.getCourseNbr()); } classEl.addAttribute("type", clazz.getSchedulingSubpart().getItypeDesc().trim()); classEl.addAttribute("suffix", clazz.getSectionNumberString()); } } commitTransaction(); } catch (Exception e) { fatal("Exception: " + e.getMessage(), e); rollbackTransaction(); } }
From source file:org.unitime.timetable.dataexchange.StudentExport.java
License:Open Source License
@Override public void saveXml(Document document, Session session, Properties parameters) throws Exception { try {// w w w. j a v a2s. c om beginTransaction(); Element root = document.addElement("students"); root.addAttribute("campus", session.getAcademicInitiative()); root.addAttribute("year", session.getAcademicYear()); root.addAttribute("term", session.getAcademicTerm()); document.addDocType("students", "-//UniTime//UniTime Students DTD/EN", "http://www.unitime.org/interface/Student.dtd"); for (Student student : (List<Student>) getHibSession() .createQuery("select s from Student s where s.session.uniqueId = :sessionId") .setLong("sessionId", session.getUniqueId()).list()) { Element studentEl = root.addElement("student"); exportStudent(studentEl, student); } commitTransaction(); } catch (Exception e) { fatal("Exception: " + e.getMessage(), e); rollbackTransaction(); } }
From source file:org.unitime.timetable.dataexchange.StudentSchedulingStatusExport.java
License:Apache License
@Override public void saveXml(Document document, Session session, Properties parameters) throws Exception { try {// ww w. ja v a 2 s. c o m beginTransaction(); Element root = document.addElement("studentStatuses"); root.addAttribute("campus", session.getAcademicInitiative()); root.addAttribute("year", session.getAcademicYear()); root.addAttribute("term", session.getAcademicTerm()); root.addAttribute("created", new Date().toString()); root.addAttribute("dateFormat", sDateFormat.toPattern()); root.addAttribute("timeFormat", sTimeFormat.toPattern()); root.addAttribute("incremental", "true"); document.addDocType("studentStatuses", "-//UniTime//UniTime Student Scheduling Statuses DTD/EN", "http://www.unitime.org/interface/StudentStatuses.dtd"); for (StudentSectioningStatus status : (List<StudentSectioningStatus>) getHibSession().createQuery( "from StudentSectioningStatus where session is null or session = :sessionId order by reference") .setLong("sessionId", session.getUniqueId()).list()) { Element statusElement = root.addElement("status"); statusElement.addAttribute("reference", status.getReference()); statusElement.addAttribute("name", status.getLabel()); statusElement.addAttribute("session", status.getSession() == null ? "false" : "true"); Element permissionsEl = statusElement.addElement("permissions"); for (StudentSectioningStatus.Option option : StudentSectioningStatus.Option.values()) permissionsEl.addAttribute(getAttribute(option), status.hasOption(option) ? "true" : "false"); Element datesEl = null; if (status.getEffectiveStartDate() != null) { if (datesEl == null) datesEl = statusElement.addElement("effective-dates"); datesEl.addAttribute("startDate", sDateFormat.format(status.getEffectiveStartDate())); } if (status.getEffectiveStartPeriod() != null) { if (datesEl == null) datesEl = statusElement.addElement("effective-dates"); int hour = status.getEffectiveStartPeriod() / 12; int min = 5 * (status.getEffectiveStartPeriod() % 12); datesEl.addAttribute("startPeriod", sTwoNumbersDF.format(hour) + sTwoNumbersDF.format(min)); } if (status.getEffectiveStopDate() != null) { if (datesEl == null) datesEl = statusElement.addElement("effective-dates"); datesEl.addAttribute("stopDate", sDateFormat.format(status.getEffectiveStopDate())); } if (status.getEffectiveStopPeriod() != null) { if (datesEl == null) datesEl = statusElement.addElement("effective-dates"); int hour = status.getEffectiveStopPeriod() / 12; int min = 5 * (status.getEffectiveStopPeriod() % 12); datesEl.addAttribute("stopPeriod", sTwoNumbersDF.format(hour) + sTwoNumbersDF.format(min)); } if (status.getMessage() != null) statusElement.addElement("message").setText(status.getMessage()); for (CourseType type : status.getTypes()) statusElement.addElement("course").addAttribute("type", type.getReference()); if (status.getFallBackStatus() != null) statusElement.addElement("fallback").addAttribute("reference", status.getFallBackStatus().getReference()); } commitTransaction(); } catch (Exception e) { fatal("Exception: " + e.getMessage(), e); rollbackTransaction(); } }
From source file:org.unitime.timetable.dataexchange.TravelTimesExport.java
License:Open Source License
@Override public void saveXml(Document document, Session session, Properties parameters) throws Exception { try {//from ww w . j ava 2 s . co m beginTransaction(); Element root = document.addElement("traveltimes"); root.addAttribute("campus", session.getAcademicInitiative()); root.addAttribute("year", session.getAcademicYear()); root.addAttribute("term", session.getAcademicTerm()); root.addAttribute("created", new Date().toString()); document.addDocType("traveltimes", "-//UniTime//UniTime Travel Times DTD/EN", "http://www.unitime.org/interface/TravelTimes.dtd"); Map<Long, Map<Long, Integer>> matrix = new HashMap<Long, Map<Long, Integer>>(); for (TravelTime travel : (List<TravelTime>) getHibSession() .createQuery("from TravelTime where session.uniqueId = :sessionId") .setLong("sessionId", session.getUniqueId()).list()) { Map<Long, Integer> m = matrix.get(travel.getLocation1Id()); if (m == null) { m = new HashMap<Long, Integer>(); matrix.put(travel.getLocation1Id(), m); } m.put(travel.getLocation2Id(), travel.getDistance()); } List<Location> locations = Location.findAll(session.getUniqueId()); Collections.sort(locations); for (Location from : locations) { Map<Long, Integer> m = matrix.get(from.getUniqueId()); if (m == null || m.isEmpty()) continue; Element fromEl = root.addElement("from"); fillLocationData(from, fromEl); for (Location to : locations) { Integer distance = m.get(to.getUniqueId()); if (distance == null) continue; Element toEl = fromEl.addElement("to"); fillLocationData(to, toEl); toEl.setText(distance.toString()); } } commitTransaction(); } catch (Exception e) { fatal("Exception: " + e.getMessage(), e); rollbackTransaction(); } }
From source file:org.unitime.timetable.server.hql.HQLExportXML.java
License:Apache License
@Override public void export(ExportHelper helper) throws IOException { String s = helper.getParameter("id"); if (s == null) throw new IllegalArgumentException("No report provided, please set the id parameter."); SavedHQL report = SavedHQLDAO.getInstance().get(Long.valueOf(s)); if (report == null) throw new IllegalArgumentException("Report " + s + " does not exist."); helper.getSessionContext().checkPermission(report, Right.HQLReportEdit); helper.setup("text/xml", report.getName().replace('/', '-').replace('\\', '-').replace(':', '-') + ".xml", false);/*from w w w.ja v a 2 s. c o m*/ Document document = DocumentHelper.createDocument(); document.addDocType("report", "-//UniTime//UniTime HQL Reports DTD/EN", "http://www.unitime.org/interface/Reports.dtd"); Element reportEl = document.addElement("report"); reportEl.addAttribute("name", report.getName()); for (SavedHQL.Flag flag : SavedHQL.Flag.values()) { if (report.isSet(flag)) reportEl.addElement("flag").setText(flag.name()); } if (report.getDescription() != null) reportEl.addElement("description").add(new DOMCDATA(report.getDescription())); if (report.getQuery() != null) reportEl.addElement("query").add(new DOMCDATA(report.getQuery())); reportEl.addAttribute("created", new Date().toString()); OutputStream out = helper.getOutputStream(); new XMLWriter(out, OutputFormat.createPrettyPrint()).write(document); }