private Project . Calendars . Calendar writeCalendar ( ProjectCalendar bc ) { // // Create a calendar // Project . Calendars . Calendar calendar = m_factory . createProjectCalendarsCalendar ( ) ; calendar . setUID ( NumberHelper . getBigInteger ( bc . getUniqueID ( ) ) ) ; calendar . setIsBaseCalendar ( Boolean . valueOf ( ! bc . isDerived ( ) ) ) ; ProjectCalendar base = bc . getParent ( ) ; // SF-329: null default required to keep Powerproject happy when importing MSPDI files calendar . setBaseCalendarUID ( base == null ? NULL_CALENDAR_ID : NumberHelper . getBigInteger ( base . getUniqueID ( ) ) ) ; calendar . setName ( bc . getName ( ) ) ; // // Create a list of normal days // Project . Calendars . Calendar . WeekDays days = m_factory . createProjectCalendarsCalendarWeekDays ( ) ; Project . Calendars . Calendar . WeekDays . WeekDay . WorkingTimes . WorkingTime time ; ProjectCalendarHours bch ; List < Project . Calendars . Calendar . WeekDays . WeekDay > dayList = days . getWeekDay ( ) ; for ( int loop = 1 ; loop < 8 ; loop ++ ) { DayType workingFlag = bc . getWorkingDay ( Day . getInstance ( loop ) ) ; if ( workingFlag != DayType . DEFAULT ) { Project . Calendars . Calendar . WeekDays . WeekDay day = m_factory . createProjectCalendarsCalendarWeekDaysWeekDay ( ) ; dayList . add ( day ) ; day . setDayType ( BigInteger . valueOf ( loop ) ) ; day . setDayWorking ( Boolean . valueOf ( workingFlag == DayType . WORKING ) ) ; if ( workingFlag == DayType . WORKING ) { Project . Calendars . Calendar . WeekDays . WeekDay . WorkingTimes times = m_factory . createProjectCalendarsCalendarWeekDaysWeekDayWorkingTimes ( ) ; day . setWorkingTimes ( times ) ; List < Project . Calendars . Calendar . WeekDays . WeekDay . WorkingTimes . WorkingTime > timesList = times . getWorkingTime ( ) ; bch = bc . getCalendarHours ( Day . getInstance ( loop ) ) ; if ( bch != null ) { for ( DateRange range : bch ) { if ( range != null ) { time = m_factory . createProjectCalendarsCalendarWeekDaysWeekDayWorkingTimesWorkingTime ( ) ; timesList . add ( time ) ; time . setFromTime ( range . getStart ( ) ) ; time . setToTime ( range . getEnd ( ) ) ; } } } } } } // // Create a list of exceptions // // A quirk of MS Project is that these exceptions must be // in date order in the file, otherwise they are ignored // List < ProjectCalendarException > exceptions = new ArrayList < ProjectCalendarException > ( bc . getCalendarExceptions ( ) ) ; if ( ! exceptions . isEmpty ( ) ) { Collections . sort ( exceptions ) ; writeExceptions ( calendar , dayList , exceptions ) ; } // // Do not add a weekdays tag to the calendar unless it // has valid entries. // Fixes SourceForge bug 1854747: MPXJ and MSP 2007 XML formats // if ( ! dayList . isEmpty ( ) ) { calendar . setWeekDays ( days ) ; } writeWorkWeeks ( calendar , bc ) ; m_eventManager . fireCalendarWrittenEvent ( bc ) ; return ( calendar ) ; }
This method writes data for a single calendar to an MSPDI file .