1 // Created on: 2001-09-04
2 // Created by: Julia DOROVSKIKH
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
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.
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.
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.
20 //AGV 150202: Changed prototype XmlObjMgt::SetStringValue()
22 #include <XmlMDF_ReferenceDriver.ixx>
23 #include <XmlObjMgt.hxx>
25 #include <TDF_Reference.hxx>
26 #include <TDF_Tool.hxx>
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)
37 //=======================================================================
40 //=======================================================================
41 Handle(TDF_Attribute) XmlMDF_ReferenceDriver::NewEmpty() const
43 return (new TDF_Reference());
46 //=======================================================================
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
55 XmlObjMgt_DOMString anXPath = XmlObjMgt::GetStringValue(theSource);
59 WriteMessage ("Cannot retrieve reference string from element");
60 return Standard_False;
63 TCollection_AsciiString anEntry;
64 if (XmlObjMgt::GetTagEntryString (anXPath, anEntry) == Standard_False)
66 TCollection_ExtendedString aMessage =
67 TCollection_ExtendedString ("Cannot retrieve reference from \"")
69 WriteMessage (aMessage);
70 return Standard_False;
73 Handle(TDF_Reference) aRef = Handle(TDF_Reference)::DownCast(theTarget);
75 // find label by entry
76 TDF_Label tLab; // Null label.
77 if (anEntry.Length() > 0)
79 TDF_Tool::Label(aRef->Label().Data(), anEntry, tLab, Standard_True);
82 // set referenced label
88 //=======================================================================
90 //purpose : transient -> persistent (store)
91 // <label tag='1'> <This is label entry 0:4:1>
93 // <label tag='8'> <This is label entry 0:4:1:8>
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
102 Handle(TDF_Reference) aRef = Handle(TDF_Reference)::DownCast(theSource);
105 const TDF_Label& lab = aRef->Label();
106 const TDF_Label& refLab = aRef->Get();
107 if (!lab.IsNull() && !refLab.IsNull())
109 if (lab.IsDescendant(refLab.Root()))
111 // Internal reference
112 TCollection_AsciiString anEntry;
113 TDF_Tool::Entry(refLab, anEntry);
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);