1 // Created on: 2001-09-04
2 // Created by: Julia DOROVSKIKH
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 //AGV 150202: Changed prototype XmlObjMgt::SetStringValue()
18 #include <XmlMDF_ReferenceDriver.ixx>
19 #include <XmlObjMgt.hxx>
21 #include <TDF_Reference.hxx>
22 #include <TDF_Tool.hxx>
24 //=======================================================================
25 //function : XmlMDF_ReferenceDriver
26 //purpose : Constructor
27 //=======================================================================
28 XmlMDF_ReferenceDriver::XmlMDF_ReferenceDriver
29 (const Handle(CDM_MessageDriver)& theMsgDriver)
30 : XmlMDF_ADriver (theMsgDriver, NULL)
33 //=======================================================================
36 //=======================================================================
37 Handle(TDF_Attribute) XmlMDF_ReferenceDriver::NewEmpty() const
39 return (new TDF_Reference());
42 //=======================================================================
44 //purpose : persistent -> transient (retrieve)
45 //=======================================================================
46 Standard_Boolean XmlMDF_ReferenceDriver::Paste
47 (const XmlObjMgt_Persistent& theSource,
48 const Handle(TDF_Attribute)& theTarget,
49 XmlObjMgt_RRelocationTable& ) const
51 XmlObjMgt_DOMString anXPath = XmlObjMgt::GetStringValue(theSource);
55 WriteMessage ("Cannot retrieve reference string from element");
56 return Standard_False;
59 TCollection_AsciiString anEntry;
60 if (XmlObjMgt::GetTagEntryString (anXPath, anEntry) == Standard_False)
62 TCollection_ExtendedString aMessage =
63 TCollection_ExtendedString ("Cannot retrieve reference from \"")
65 WriteMessage (aMessage);
66 return Standard_False;
69 Handle(TDF_Reference) aRef = Handle(TDF_Reference)::DownCast(theTarget);
71 // find label by entry
72 TDF_Label tLab; // Null label.
73 if (anEntry.Length() > 0)
75 TDF_Tool::Label(aRef->Label().Data(), anEntry, tLab, Standard_True);
78 // set referenced label
84 //=======================================================================
86 //purpose : transient -> persistent (store)
87 // <label tag='1'> <This is label entry 0:4:1>
89 // <label tag='8'> <This is label entry 0:4:1:8>
91 // <TDF_Reference id="621"> /document/label/label[@tag="4"]/label[@tag="1"]
92 // </TDF_Reference> <This is reference to label 0:4:1>
93 //=======================================================================
94 void XmlMDF_ReferenceDriver::Paste (const Handle(TDF_Attribute)& theSource,
95 XmlObjMgt_Persistent& theTarget,
96 XmlObjMgt_SRelocationTable& ) const
98 Handle(TDF_Reference) aRef = Handle(TDF_Reference)::DownCast(theSource);
101 const TDF_Label& lab = aRef->Label();
102 const TDF_Label& refLab = aRef->Get();
103 if (!lab.IsNull() && !refLab.IsNull())
105 if (lab.IsDescendant(refLab.Root()))
107 // Internal reference
108 TCollection_AsciiString anEntry;
109 TDF_Tool::Entry(refLab, anEntry);
111 XmlObjMgt_DOMString aDOMString;
112 XmlObjMgt::SetTagEntryString (aDOMString, anEntry);
113 // No occurrence of '&', '<' and other irregular XML characters
114 XmlObjMgt::SetStringValue (theTarget, aDOMString, Standard_True);