-// File: XmlLDrivers_DocumentRetrievalDriver.cxx
-// Created: Mon Jul 9 12:29:49 MSK DST 2001
-// Author: Julia DOROVSKIKH
-// Copyright: Open Cascade 2001
-
-#include <XmlLDrivers_DocumentRetrievalDriver.ixx>
-
-#include <XmlLDrivers.hxx>
-#include <XmlMDF.hxx>
-#include <XmlObjMgt_RRelocationTable.hxx>
-#include <XmlObjMgt_Document.hxx>
-#include <XmlObjMgt.hxx>
-#include <XmlMDataStd.hxx>
-#include <LDOM_LDOMImplementation.hxx>
+// Created on: 2001-07-09
+// Created by: Julia DOROVSKIKH
+// Copyright (c) 2001-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+
+#include <CDM_Application.hxx>
+#include <CDM_Document.hxx>
+#include <CDM_MessageDriver.hxx>
+#include <CDM_MetaData.hxx>
#include <LDOM_DocumentType.hxx>
+#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>
#include <TDF_Data.hxx>
-#include <TDocStd_Owner.hxx>
#include <TDocStd_Document.hxx>
-#include <CDM_MessageDriver.hxx>
-#include <CDM_MetaData.hxx>
-#include <TCollection_AsciiString.hxx>
+#include <TDocStd_Owner.hxx>
#include <UTL.hxx>
-#include <OSD_Path.hxx>
+#include <XmlLDrivers.hxx>
+#include <XmlLDrivers_DocumentRetrievalDriver.hxx>
+#include <XmlMDataStd.hxx>
+#include <XmlMDF.hxx>
+#include <XmlMDF_ADriver.hxx>
+#include <XmlMDF_ADriverTable.hxx>
+#include <XmlObjMgt.hxx>
+#include <XmlObjMgt_Document.hxx>
+#include <XmlObjMgt_RRelocationTable.hxx>
+
+IMPLEMENT_STANDARD_RTTIEXT(XmlLDrivers_DocumentRetrievalDriver,PCDM_RetrievalDriver)
-#ifdef WNT
+#ifdef _MSC_VER
# include <tchar.h>
-#endif // WNT
+#endif // _MSC_VER
#include <locale.h>
#include <Standard_Failure.hxx>
#define START_REF "START_REF"
#define END_REF "END_REF"
-#define REFERENCE_COUNTER "REFERENCE_COUNTER"
-static Standard_Integer myDocumentVersion = 0;
+#define MODIFICATION_COUNTER "MODIFICATION_COUNTER: "
+#define REFERENCE_COUNTER "REFERENCE_COUNTER: "
//#define TAKE_TIMES
static void take_time (const Standard_Integer, const char *,
Standard_Integer i, j, len ;
len = aString.Length() ;
-#ifdef WNT
+#ifdef _WIN32
// Case of network path, such as \\MACHINE\dir
for (i = j = 2 ; j <= len ; i++,j++) {
#else
TCollection_AsciiString theCFile=UTL::CString(aFileName);
TCollection_AsciiString theDirectory;
Standard_Integer i=theCFile.SearchFromEnd("/");
-#ifdef WNT
+#ifdef _WIN32
// if(i==-1) i=theCFile.SearchFromEnd("\\");
if(theCFile.SearchFromEnd("\\") > i)
i=theCFile.SearchFromEnd("\\");
const TCollection_AsciiString& aRelFilePath)
{
TCollection_AsciiString EmptyString = "" ;
-#ifdef WNT
+#ifdef _WIN32
if (aRelFilePath.Search(":") == 2 ||
(aRelFilePath.Search("\\") == 1 && aRelFilePath.Value(2) == '\\'))
#else
TCollection_AsciiString DirPath = aDirPath, RelFilePath = aRelFilePath ;
Standard_Integer i,len ;
-#ifdef WNT
+#ifdef _WIN32
if(DirPath.Search(":") != 2 &&
(DirPath.Search("\\") != 1 || DirPath.Value(2) != '\\'))
#else
#endif
return EmptyString ;
-#ifdef WNT
+#ifdef _WIN32
DirPath.ChangeAll('\\','/') ;
RelFilePath.ChangeAll('\\','/') ;
#endif
while (RelFilePath.Search("../") == 1) {
if (len == 3)
- return EmptyString ;
+ return EmptyString ;
RelFilePath = RelFilePath.SubString(4,len) ;
len -= 3 ;
if (DirPath.IsEmpty())
- return EmptyString ;
+ return EmptyString ;
i = DirPath.SearchFromEnd("/") ;
if (i < 0)
return EmptyString ;
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;
- const TCollection_AsciiString anOldNumLocale =
- (Standard_CString) setlocale (LC_NUMERIC, NULL);
- setlocale(LC_NUMERIC, "C");
-
+
+ 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;
::take_time (0, " +++++ Fin parsing XML : ", aMessageDriver);
ReadFromDomDocument (anElement, theNewDocument, theApplication);
-
- setlocale(LC_NUMERIC, (char *) anOldNumLocale.ToCString()) ;
}
//=======================================================================
aCurDocVersion = 2;
else if (!aDocVerStr.GetInteger(aCurDocVersion)) {
TCollection_ExtendedString aMsg =
- TCollection_ExtendedString ("Cannot retrieve the current Document version"
+ TCollection_ExtendedString ("Cannot retrieve the current Document version"
" attribute as \"") + aDocVerStr + "\"";
if(!aMsgDriver.IsNull())
- aMsgDriver->Write(aMsg.ToExtString());
+ aMsgDriver->Write(aMsg.ToExtString());
}
- if(aCurDocVersion < 2) aCurDocVersion = 2;
+
+ // 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() )
+ {
+ TCollection_ExtendedString aMsg =
+ TCollection_ExtendedString ("error: wrong file version: ") +
+ aDocVerStr + " while current is " +
+ XmlLDrivers::StorageVersion();
+ myReaderStatus = PCDM_RS_NoVersion;
+ if(!aMsgDriver.IsNull())
+ aMsgDriver->Write(aMsg.ToExtString());
+ return;
+ }
+
+ if( aCurDocVersion < 2) aCurDocVersion = 2;
PropagateDocumentVersion(aCurDocVersion);
if (aNode.getNodeType() == LDOM_Node::ELEMENT_NODE) {
if (XmlObjMgt::GetExtendedString ((LDOM_Element&)aNode, anInfo)) {
- // Read ref counter
- if(anInfo.Search(REFERENCE_COUNTER) != -1) {
- try {
- OCC_CATCH_SIGNALS
- TCollection_AsciiString anInf(anInfo,'?');
- Standard_Integer aRefCounter = anInf.Token(" ",2).IntegerValue();
- //theNewDocument->SetReferenceCounter(aRefCounter);
- }
- catch (Standard_Failure) {
- // cout << "warning: could not read the reference counter in " << aFileName << endl;
- TCollection_ExtendedString aMsg("Warning: ");
- aMsg = aMsg.Cat("could not read the reference counter").Cat("\0");
- if(!aMsgDriver.IsNull())
- aMsgDriver->Write(aMsg.ToExtString());
- }
- }
-
- if(anInfo == END_REF)
- isRef = Standard_False;
- if(isRef) { // Process References
-
- Standard_Integer pos=anInfo.Search(" ");
- if(pos != -1) {
- // Parce RefId, DocumentVersion and FileName
- Standard_Integer aRefId;
- TCollection_ExtendedString aFileName;
- Standard_Integer aDocumentVersion;
-
-
- TCollection_ExtendedString aRest=anInfo.Split(pos);
- aRefId = UTL::IntegerValue(anInfo);
-
- Standard_Integer pos2 = aRest.Search(" ");
-
- aFileName = aRest.Split(pos2);
- aDocumentVersion = UTL::IntegerValue(aRest);
-
- TCollection_AsciiString aPath = UTL::CString(aFileName);
- TCollection_AsciiString anAbsolutePath;
- if(!anAbsoluteDirectory.IsEmpty()) {
- anAbsolutePath = AbsolutePath(anAbsoluteDirectory,aPath);
- if(!anAbsolutePath.IsEmpty()) aPath=anAbsolutePath;
- }
- if(!aMsgDriver.IsNull()) {
- // cout << "reference found; ReferenceIdentifier: " << theReferenceIdentifier << "; File:" << thePath << ", version:" << theDocumentVersion;
- TCollection_ExtendedString aMsg("Warning: ");
- aMsg = aMsg.Cat("reference found; ReferenceIdentifier: ").Cat(aRefId).Cat("; File:").Cat(aPath).Cat(", version:").Cat(aDocumentVersion).Cat("\0");
- aMsgDriver->Write(aMsg.ToExtString());
- }
- // Add new ref!
- /////////////
- TCollection_ExtendedString theFolder,theName;
- //TCollection_ExtendedString theFile=myReferences(myIterator).FileName();
- TCollection_ExtendedString f(aPath);
-#ifndef WNT
-
- Standard_Integer i= f.SearchFromEnd("/");
- TCollection_ExtendedString n = f.Split(i);
- f.Trunc(f.Length()-1);
- theFolder = f;
- theName = n;
+ // Read ref counter
+ if(anInfo.Search(REFERENCE_COUNTER) != -1) {
+ try {
+ OCC_CATCH_SIGNALS
+ TCollection_AsciiString anInf(anInfo,'?');
+ Standard_Integer aRefCounter = anInf.Token(" ",2).IntegerValue();
+ theNewDocument->SetReferenceCounter(aRefCounter);
+ }
+ catch (Standard_Failure) {
+ // cout << "warning: could not read the reference counter in " << aFileName << endl;
+ TCollection_ExtendedString aMsg("Warning: ");
+ aMsg = aMsg.Cat("could not read the reference counter").Cat("\0");
+ if(!aMsgDriver.IsNull())
+ 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;
+ if(isRef) { // Process References
+
+ Standard_Integer pos=anInfo.Search(" ");
+ if(pos != -1) {
+ // Parce RefId, DocumentVersion and FileName
+ Standard_Integer aRefId;
+ TCollection_ExtendedString aFileName;
+ Standard_Integer aDocumentVersion;
+
+
+ TCollection_ExtendedString aRest=anInfo.Split(pos);
+ aRefId = UTL::IntegerValue(anInfo);
+
+ Standard_Integer pos2 = aRest.Search(" ");
+
+ aFileName = aRest.Split(pos2);
+ aDocumentVersion = UTL::IntegerValue(aRest);
+
+ TCollection_AsciiString aPath = UTL::CString(aFileName);
+ TCollection_AsciiString anAbsolutePath;
+ if(!anAbsoluteDirectory.IsEmpty()) {
+ anAbsolutePath = AbsolutePath(anAbsoluteDirectory,aPath);
+ if(!anAbsolutePath.IsEmpty()) aPath=anAbsolutePath;
+ }
+ if(!aMsgDriver.IsNull()) {
+ // cout << "reference found; ReferenceIdentifier: " << theReferenceIdentifier << "; File:" << thePath << ", version:" << theDocumentVersion;
+ TCollection_ExtendedString aMsg("Warning: ");
+ aMsg = aMsg.Cat("reference found; ReferenceIdentifier: ").Cat(aRefId).Cat("; File:").Cat(aPath).Cat(", version:").Cat(aDocumentVersion).Cat("\0");
+ aMsgDriver->Write(aMsg.ToExtString());
+ }
+ // Add new ref!
+ /////////////
+ TCollection_ExtendedString theFolder,theName;
+ //TCollection_ExtendedString theFile=myReferences(myIterator).FileName();
+ TCollection_ExtendedString f(aPath);
+#ifndef _WIN32
+
+ Standard_Integer i= f.SearchFromEnd("/");
+ TCollection_ExtendedString n = f.Split(i);
+ f.Trunc(f.Length()-1);
+ theFolder = f;
+ theName = n;
#else
- OSD_Path p = UTL::Path(f);
- Standard_ExtCharacter chr;
- TCollection_ExtendedString dir, dirRet, name;
-
- dir = UTL::Disk(p);
- dir += UTL::Trek(p);
-
- for ( int i = 1; i <= dir.Length (); ++i ) {
-
- chr = dir.Value ( i );
-
- switch ( chr ) {
-
- case _TEXT( '|' ):
- dirRet += _TEXT( "/" );
- break;
+ OSD_Path p = UTL::Path(f);
+ Standard_ExtCharacter chr;
+ TCollection_ExtendedString dir, dirRet, name;
+
+ dir = UTL::Disk(p);
+ dir += UTL::Trek(p);
+
+ for ( int i = 1; i <= dir.Length (); ++i ) {
+
+ chr = dir.Value ( i );
+
+ switch ( chr ) {
+
+ case '|':
+ dirRet += "/";
+ break;
+
+ case '^':
+
+ dirRet += "..";
+ break;
+
+ default:
+ dirRet += chr;
- case _TEXT( '^' ):
-
- dirRet += _TEXT( ".." );
- break;
-
- default:
- dirRet += chr;
-
- }
- }
- theFolder = dirRet;
- theName = UTL::Name(p); theName+= UTL::Extension(p);
-#endif // WNT
-
- Handle(CDM_MetaData) aMetaData = CDM_MetaData::LookUp(theFolder,theName,aPath,aPath,UTL::IsReadOnly(aFileName));
+ }
+ }
+ theFolder = dirRet;
+ theName = UTL::Name(p); theName+= UTL::Extension(p);
+#endif // _WIN32
+
+ Handle(CDM_MetaData) aMetaData = CDM_MetaData::LookUp(theFolder,theName,aPath,aPath,UTL::IsReadOnly(aFileName));
////////////
- theNewDocument->CreateReference(aMetaData,aRefId,
- theApplication,aDocumentVersion,Standard_False);
+ theNewDocument->CreateReference(aMetaData,aRefId,
+ theApplication,aDocumentVersion,Standard_False);
-
- }
+
+ }
-
- }
- if(anInfo == START_REF)
- isRef = Standard_True;
+
+ }
+ if(anInfo == START_REF)
+ isRef = Standard_True;
}
}
}
try
{
OCC_CATCH_SIGNALS
-#if defined(DEB) && !defined(TAKE_TIMES)
+#ifdef OCCT_DEBUG
TCollection_ExtendedString aMessage ("PasteDocument");
aMsgDriver -> Write (aMessage.ToExtString());
#endif
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());
}
#include <sys/timeb.h>
#include <sys/types.h>
#include <stdio.h>
-#ifndef WNT
+#ifndef _WIN32
extern "C" int ftime (struct timeb *tp);
#endif
extern struct timeb tmbuf0;
if (isReset) tmbuf0 = tmbuf;
else {
char take_tm_buf [64];
- sprintf (take_tm_buf, "%9.2f s ++++",
+ Sprintf (take_tm_buf, "%9.2f s ++++",
double(tmbuf.time - tmbuf0.time) +
double(tmbuf.millitm - tmbuf0.millitm)/1000.);
aMessage += take_tm_buf;
void XmlLDrivers_DocumentRetrievalDriver::PropagateDocumentVersion(
const Standard_Integer theDocVersion )
{
-#ifdef DEB
-// cout << "DocCurVersion =" << theDocVersion <<endl;
-#endif
XmlMDataStd::SetDocumentVersion(theDocVersion);
}
//=======================================================================
Handle(XmlMDF_ADriver) XmlLDrivers_DocumentRetrievalDriver::ReadShapeSection(
const XmlObjMgt_Element& /*theElement*/,
- const Handle(CDM_MessageDriver)& /*aMsgDriver*/)
+ const Handle(CDM_MessageDriver)& /*aMsgDriver*/)
{
Handle(XmlMDF_ADriver) aDriver;
//empty; to be redefined
//purpose : definition of ShapeSetCleaning
//=======================================================================
void XmlLDrivers_DocumentRetrievalDriver::ShapeSetCleaning(
- const Handle(XmlMDF_ADriver)& /*theDriver*/)
+ const Handle(XmlMDF_ADriver)& /*theDriver*/)
{}