1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0027077: OCAF: Implementation of streaming save/load (OCC26229) is incomplete/incorrect

XmlOcaf reading is non-seekable

// 1. Read method of XmlLDrivers_DocumentRetrievalDriver extended to read complete document (with "document" tag) in compatible mode (when reading is performed from file)
// 2. the empty statement removed
// 3. the description of LDOMPARSER::parse method extended
This commit is contained in:
ibs
2016-01-14 19:17:00 +03:00
committed by bugmaster
parent 3f8122493a
commit 5fce160515
8 changed files with 102 additions and 44 deletions

View File

@@ -93,19 +93,10 @@ PCDM_TypeOfFileDriver PCDM::FileDriverType (Standard_IStream& theIStream, PCDM_B
{
TCollection_AsciiString aReadMagicNumber;
// read magic number from the file
if (theIStream.good())
{
streampos aDocumentPos = theIStream.tellg();
// read magic number from the file
aReadMagicNumber = Storage_BaseDriver::ReadMagicNumber (theIStream);
if (!theIStream.good())
{
theIStream.clear();
}
theIStream.seekg(aDocumentPos);
}
if(aReadMagicNumber == FSD_CmpFile::MagicNumber())
@@ -123,6 +114,17 @@ PCDM_TypeOfFileDriver PCDM::FileDriverType (Standard_IStream& theIStream, PCDM_B
theBaseDriver = new FSD_BinaryFile;
return PCDM_TOFD_File;
}
else if (aReadMagicNumber.Search ("<?xml") != -1)
{
// skip xml declaration
char aChar = ' ';
while (theIStream.good() && !theIStream.eof() && aChar != '>')
{
theIStream.get(aChar);
}
return PCDM_TOFD_XmlFile;
}
theBaseDriver = NULL;
return PCDM_TOFD_Unknown;

View File

@@ -167,15 +167,11 @@ TCollection_ExtendedString PCDM_ReadWriter::FileFormat (Standard_IStream& theISt
TCollection_ExtendedString aFormat;
Storage_BaseDriver* aFileDriver;
if (PCDM::FileDriverType (theIStream, aFileDriver) == PCDM_TOFD_Unknown)
if (PCDM::FileDriverType (theIStream, aFileDriver) == PCDM_TOFD_XmlFile)
{
return ::TryXmlDriverType (theIStream);
}
// the stream starts with a magic number, FileDriverType has read
// them already but returned the stream pos to initial state,
// thus we should read them before reading of info section
aFileDriver->ReadMagicNumber(theIStream);
aFileDriver->ReadCompleteInfo (theIStream, theData);
@@ -230,23 +226,14 @@ static TCollection_ExtendedString TryXmlDriverType (Standard_IStream& theIStream
if (theIStream.good())
{
streampos aDocumentPos = theIStream.tellg();
// Parse the file; if there is no error or an error appears before retrieval
// of the DocumentElement, the XML format cannot be defined
if (aParser.parse (theIStream))
if (aParser.parse (theIStream, Standard_True))
{
LDOM_Element anElement = aParser.GetElement();
if (anElement.getTagName().equals (LDOMString(aDocumentElementName)))
theFormat = anElement.getAttribute ("format");
}
if (!theIStream.good())
{
theIStream.clear();
}
theIStream.seekg(aDocumentPos);
}
return theFormat;

View File

@@ -22,6 +22,7 @@ enum PCDM_TypeOfFileDriver
{
PCDM_TOFD_File,
PCDM_TOFD_CmpFile,
PCDM_TOFD_XmlFile,
PCDM_TOFD_Unknown
};