data[2] = (byte) bis.read();
data[3] = (byte) bis.read();
if ((data[0] != 'M') || (data[1] != 'P') || (data[2] != 'X'))
{
throw new MPXJException(MPXJException.INVALID_FILE);
}
m_projectFile = new ProjectFile();
m_projectFile.addProjectListeners(m_projectListeners);
m_projectFile.setAutoTaskID(false);
m_projectFile.setAutoTaskUniqueID(false);
m_projectFile.setAutoResourceID(false);
m_projectFile.setAutoResourceUniqueID(false);
m_projectFile.setAutoOutlineLevel(false);
m_projectFile.setAutoOutlineNumber(false);
m_projectFile.setAutoWBS(false);
LocaleUtility.setLocale(m_projectFile, m_locale);
m_delimiter = (char) data[3];
m_projectFile.setDelimiter(m_delimiter);
m_taskModel = new TaskModel(m_projectFile, m_locale);
m_taskModel.setLocale(m_locale);
m_resourceModel = new ResourceModel(m_projectFile, m_locale);
m_resourceModel.setLocale(m_locale);
m_baseOutlineLevel = -1;
m_formats = new MPXJFormats(m_locale, LocaleData.getString(m_locale, LocaleData.NA), m_projectFile);
m_deferredRelationships = new LinkedList<DeferredRelationship>();
bis.reset();
//
// Read the file creation record. At this point we are reading
// directly from an input stream so no character set decoding is
// taking place. We assume that any text in this record will not
// require decoding.
//
Tokenizer tk = new InputStreamTokenizer(bis);
tk.setDelimiter(m_delimiter);
Record record;
String number;
//
// Add the header record
//
parseRecord(Integer.toString(MPXConstants.FILE_CREATION_RECORD_NUMBER), new Record(m_locale, tk, m_formats));
++line;
//
// Now process the remainder of the file in full. As we have read the
// file creation record we have access to the field which specifies the
// codepage used to encode the character set in this file. We set up
// an input stream reader using the appropriate character set, and
// create a new tokenizer to read from this Reader instance.
//
InputStreamReader reader = new InputStreamReader(bis, m_projectFile.getFileCreationRecord().getCodePage().getCharset());
tk = new ReaderTokenizer(reader);
tk.setDelimiter(m_delimiter);
//
// Read the remainder of the records
//
while (tk.getType() != Tokenizer.TT_EOF)
{
record = new Record(m_locale, tk, m_formats);
number = record.getRecordNumber();
if (number != null)
{
parseRecord(number, record);
}
++line;
}
processDeferredRelationships();
//
// Ensure that the structure is consistent
//
m_projectFile.updateStructure();
//
// Ensure that the unique ID counters are correct
//
m_projectFile.updateUniqueCounters();
m_projectFile.setAutoCalendarUniqueID(false);
return (m_projectFile);
}
catch (Exception ex)
{
throw new MPXJException(MPXJException.READ_ERROR + " (failed at line " + line + ")", ex);
}
finally
{
m_projectFile = null;