DirectoryEntry calDir = (DirectoryEntry) m_projectDir.getEntry("TBkndCal");
FixFix calendarFixedData = new FixFix(36, new DocumentInputStream(((DocumentEntry) calDir.getEntry("FixFix 0"))));
FixDeferFix calendarVarData = new FixDeferFix(new DocumentInputStream(((DocumentEntry) calDir.getEntry("FixDeferFix 0"))));
ProjectCalendar cal;
ProjectCalendarHours hours;
ProjectCalendarException exception;
String name;
byte[] baseData;
byte[] extData;
int periodCount;
int index;
int offset;
int defaultFlag;
Date start;
long duration;
int exceptionCount;
//
// Configure default time ranges
//
SimpleDateFormat df = new SimpleDateFormat("HH:mm");
Date defaultStart1;
Date defaultEnd1;
Date defaultStart2;
Date defaultEnd2;
try
{
defaultStart1 = df.parse("08:00");
defaultEnd1 = df.parse("12:00");
defaultStart2 = df.parse("13:00");
defaultEnd2 = df.parse("17:00");
}
catch (ParseException ex)
{
throw new MPXJException(MPXJException.INVALID_FORMAT, ex);
}
int calendars = calendarFixedData.getItemCount();
int calendarID;
int baseCalendarID;
int periodIndex;
Day day;
List<Pair<ProjectCalendar, Integer>> baseCalendars = new LinkedList<Pair<ProjectCalendar, Integer>>();
for (int loop = 0; loop < calendars; loop++)
{
baseData = calendarFixedData.getByteArrayValue(loop);
calendarID = MPPUtility.getInt(baseData, 0);
baseCalendarID = MPPUtility.getInt(baseData, 4);
name = calendarVarData.getUnicodeString(getOffset(baseData, 20));
//
// Uncommenting the call to this method is useful when trying
// to determine the function of unknown task data.
//
//dumpUnknownData (name + " " + MPPUtility.getInt(baseData), UNKNOWN_CALENDAR_DATA, baseData);
//
// Skip calendars with negative ID values
//
if (calendarID < 0)
{
continue;
}
//
// Populate the basic calendar
//
ExtendedData ed = new ExtendedData(calendarVarData, getOffset(baseData, 32));
offset = -1 - ed.getInt(Integer.valueOf(8));
if (offset == -1)
{
if (baseCalendarID > 0)
{
cal = m_file.getDefaultResourceCalendar();
baseCalendars.add(new Pair<ProjectCalendar, Integer>(cal, Integer.valueOf(baseCalendarID)));
}
else
{
cal = m_file.addDefaultBaseCalendar();
cal.setName(name);
}
cal.setUniqueID(Integer.valueOf(calendarID));
}
else
{
if (baseCalendarID > 0)
{
cal = m_file.addResourceCalendar();
baseCalendars.add(new Pair<ProjectCalendar, Integer>(cal, Integer.valueOf(baseCalendarID)));
}
else
{
cal = m_file.addBaseCalendar();
cal.setName(name);
}
cal.setUniqueID(Integer.valueOf(calendarID));
extData = calendarVarData.getByteArray(offset);
for (index = 0; index < 7; index++)
{
offset = 4 + (40 * index);
defaultFlag = MPPUtility.getShort(extData, offset);
day = Day.getInstance(index + 1);
if (defaultFlag == 1)
{
cal.setWorkingDay(day, DEFAULT_WORKING_WEEK[index]);
if (cal.isWorkingDay(day) == true)
{
hours = cal.addCalendarHours(net.sf.mpxj.Day.getInstance(index + 1));
hours.addRange(new DateRange(defaultStart1, defaultEnd1));
hours.addRange(new DateRange(defaultStart2, defaultEnd2));
}
}
else
{
periodCount = MPPUtility.getShort(extData, offset + 2);
if (periodCount == 0)
{
cal.setWorkingDay(day, false);
}
else
{
cal.setWorkingDay(day, true);
hours = cal.addCalendarHours(Day.getInstance(index + 1));
for (periodIndex = 0; periodIndex < periodCount; periodIndex++)
{
start = MPPUtility.getTime(extData, offset + 8 + (periodIndex * 2));
duration = MPPUtility.getDuration(extData, offset + 16 + (periodIndex * 4));
hours.addRange(new DateRange(start, new Date(start.getTime() + duration)));
}
}
}
}