0023024: Update headers of OCCT files
[occt.git] / src / XmlMDF / XmlMDF_ReferenceDriver.cxx
1 // Created on: 2001-09-04
2 // Created by: Julia DOROVSKIKH
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20 //AGV 150202: Changed prototype XmlObjMgt::SetStringValue()
21
22 #include <XmlMDF_ReferenceDriver.ixx>
23 #include <XmlObjMgt.hxx>
24
25 #include <TDF_Reference.hxx>
26 #include <TDF_Tool.hxx>
27
28 //=======================================================================
29 //function : XmlMDF_ReferenceDriver
30 //purpose  : Constructor
31 //=======================================================================
32 XmlMDF_ReferenceDriver::XmlMDF_ReferenceDriver
33                         (const Handle(CDM_MessageDriver)& theMsgDriver)
34       : XmlMDF_ADriver (theMsgDriver, NULL)
35 {}
36
37 //=======================================================================
38 //function : NewEmpty
39 //purpose  : 
40 //=======================================================================
41 Handle(TDF_Attribute) XmlMDF_ReferenceDriver::NewEmpty() const
42 {
43   return (new TDF_Reference());
44 }
45
46 //=======================================================================
47 //function : Paste
48 //purpose  : persistent -> transient (retrieve)
49 //=======================================================================
50 Standard_Boolean XmlMDF_ReferenceDriver::Paste
51                 (const XmlObjMgt_Persistent&   theSource,
52                  const Handle(TDF_Attribute)&  theTarget,
53                  XmlObjMgt_RRelocationTable&   ) const
54 {
55   XmlObjMgt_DOMString anXPath = XmlObjMgt::GetStringValue(theSource);
56
57   if (anXPath == NULL)
58   {
59     WriteMessage ("Cannot retrieve reference string from element");
60     return Standard_False;
61   }
62
63   TCollection_AsciiString anEntry;
64   if (XmlObjMgt::GetTagEntryString (anXPath, anEntry) == Standard_False)
65   {
66     TCollection_ExtendedString aMessage =
67       TCollection_ExtendedString ("Cannot retrieve reference from \"")
68         + anXPath + '\"';
69     WriteMessage (aMessage);
70     return Standard_False;
71   }
72
73   Handle(TDF_Reference) aRef = Handle(TDF_Reference)::DownCast(theTarget);
74
75   // find label by entry
76   TDF_Label tLab; // Null label.
77   if (anEntry.Length() > 0)
78   {
79     TDF_Tool::Label(aRef->Label().Data(), anEntry, tLab, Standard_True);
80   }
81
82   // set referenced label
83   aRef->Set(tLab);
84
85   return Standard_True;
86 }
87
88 //=======================================================================
89 //function : Paste
90 //purpose  : transient -> persistent (store)
91 //           <label tag='1'>     <This is label entry 0:4:1>
92 //           ...
93 //           <label tag='8'>     <This is label entry 0:4:1:8>
94 //
95 //           <TDF_Reference id="621"> /document/label/label[@tag="4"]/label[@tag="1"]
96 //           </TDF_Reference>    <This is reference to label 0:4:1>
97 //=======================================================================
98 void XmlMDF_ReferenceDriver::Paste (const Handle(TDF_Attribute)&  theSource,
99                                     XmlObjMgt_Persistent&         theTarget,
100                                     XmlObjMgt_SRelocationTable&   ) const
101 {
102   Handle(TDF_Reference) aRef = Handle(TDF_Reference)::DownCast(theSource);
103   if (!aRef.IsNull())
104   {
105     const TDF_Label& lab = aRef->Label();
106     const TDF_Label& refLab = aRef->Get();
107     if (!lab.IsNull() && !refLab.IsNull())
108     {
109       if (lab.IsDescendant(refLab.Root()))
110       {
111         // Internal reference
112         TCollection_AsciiString anEntry;
113         TDF_Tool::Entry(refLab, anEntry);
114
115         XmlObjMgt_DOMString aDOMString;
116         XmlObjMgt::SetTagEntryString (aDOMString, anEntry);
117         // No occurrence of '&', '<' and other irregular XML characters
118         XmlObjMgt::SetStringValue (theTarget, aDOMString, Standard_True);
119       }
120     }
121   }
122 }