#include <LDOM_LDOMImplementation.hxx>
#include <LDOMParser.hxx>
#include <OSD_Path.hxx>
+#include <OSD_OpenFile.hxx>
#include <PCDM_Document.hxx>
+#include <PCDM_DOMHeaderParser.hxx>
#include <Standard_Type.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
#define START_REF "START_REF"
#define END_REF "END_REF"
-#define REFERENCE_COUNTER "REFERENCE_COUNTER"
+
+#define MODIFICATION_COUNTER "MODIFICATION_COUNTER: "
+#define REFERENCE_COUNTER "REFERENCE_COUNTER: "
//#define TAKE_TIMES
static void take_time (const Standard_Integer, const char *,
return new TDocStd_Document(PCDM_RetrievalDriver::GetFormat());
}
-//=======================================================================
-//function : SchemaName
-//purpose : pure virtual method definition
-//=======================================================================
-TCollection_ExtendedString XmlLDrivers_DocumentRetrievalDriver::SchemaName() const
-{
- TCollection_ExtendedString schemaname;
- return schemaname;
-}
-
-//=======================================================================
-//function : Make
-//purpose : pure virtual method definition
-//=======================================================================
-void XmlLDrivers_DocumentRetrievalDriver::Make (const Handle(PCDM_Document)&,
- const Handle(CDM_Document)&)
-{
-}
-
//=======================================================================
//function : Read
//purpose :
{
myReaderStatus = PCDM_RS_DriverFailure;
myFileName = theFileName;
+
+ std::ifstream aFileStream;
+ OSD_OpenStream (aFileStream, myFileName, std::ios::in);
+
+ if (aFileStream.is_open() && aFileStream.good())
+ {
+ Read (aFileStream, NULL, theNewDocument, theApplication);
+ }
+ else
+ {
+ myReaderStatus = PCDM_RS_OpenError;
+
+ TCollection_ExtendedString aMsg = TCollection_ExtendedString("Error: the file ") +
+ theFileName + " cannot be opened for reading";
+
+ theApplication->MessageDriver()->Write (aMsg.ToExtString());
+ throw Standard_Failure("File cannot be opened for reading");
+ }
+}
+
+//=======================================================================
+//function : Read
+//purpose :
+//=======================================================================
+void XmlLDrivers_DocumentRetrievalDriver::Read (Standard_IStream& theIStream,
+ const Handle(Storage_Data)& /*theStorageData*/,
+ const Handle(CDM_Document)& theNewDocument,
+ const Handle(CDM_Application)& theApplication)
+{
Handle(CDM_MessageDriver) aMessageDriver = theApplication -> MessageDriver();
::take_time (~0, " +++++ Start RETRIEVE procedures ++++++", aMessageDriver);
// 1. Read DOM_Document from file
LDOMParser aParser;
- TCollection_AsciiString aName (theFileName,'?');
- if (aParser.parse(aName.ToCString()))
+
+ // if myFileName is not empty, "document" tag is required to be read
+ // from the received document
+ Standard_Boolean aWithoutRoot = myFileName.IsEmpty();
+
+ if (aParser.parse(theIStream, Standard_False, aWithoutRoot))
{
TCollection_AsciiString aData;
cout << aParser.GetError(aData) << ": " << aData << endl;
// oan: OCC22305 - check a document verison and if it's greater than
// current version of storage driver set an error status and return
- if( aCurDocVersion > XmlLDrivers::StorageVersion().IntegerValue() )
+ if( aCurDocVersion > XmlLDrivers::StorageVersion() )
{
TCollection_ExtendedString aMsg =
TCollection_ExtendedString ("error: wrong file version: ") +
try {
OCC_CATCH_SIGNALS
TCollection_AsciiString anInf(anInfo,'?');
- //Standard_Integer aRefCounter = anInf.Token(" ",2).IntegerValue();
- //theNewDocument->SetReferenceCounter(aRefCounter);
+ Standard_Integer aRefCounter = anInf.Token(" ",2).IntegerValue();
+ theNewDocument->SetReferenceCounter(aRefCounter);
}
catch (Standard_Failure) {
// cout << "warning: could not read the reference counter in " << aFileName << endl;
aMsgDriver->Write(aMsg.ToExtString());
}
}
+ else if (anInfo.Search(MODIFICATION_COUNTER) != -1) {
+ try {
+ OCC_CATCH_SIGNALS
+
+ TCollection_AsciiString anInf(anInfo,'?');
+ Standard_Integer aModCounter = anInf.Token(" ",2).IntegerValue();
+ theNewDocument->SetModifications (aModCounter);
+ }
+ catch (Standard_Failure) {
+ TCollection_ExtendedString aMsg("Warning: could not read the modification counter\0");
+ if(!aMsgDriver.IsNull())
+ aMsgDriver->Write(aMsg.ToExtString());
+ }
+ }
if(anInfo == END_REF)
isRef = Standard_False;
chr = dir.Value ( i );
switch ( chr ) {
-
- case _TEXT( '|' ):
- dirRet += _TEXT( "/" );
+
+ case '|':
+ dirRet += "/";
break;
-
- case _TEXT( '^' ):
-
- dirRet += _TEXT( ".." );
+
+ case '^':
+
+ dirRet += "..";
break;
default:
else
myReaderStatus = PCDM_RS_OK;
}
- catch (Standard_Failure)
+ catch (Standard_Failure const& anException)
{
- TCollection_ExtendedString anErrorString (Standard_Failure::Caught()->GetMessageString());
+ TCollection_ExtendedString anErrorString (anException.GetMessageString());
aMsgDriver -> Write (anErrorString.ToExtString());
}