1 // Created on: 2001-09-04
2 // Created by: Julia DOROVSKIKH
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
17 #include <Message_Messenger.hxx>
18 #include <Standard_Type.hxx>
19 #include <TDF_Attribute.hxx>
20 #include <TDF_Label.hxx>
21 #include <TDF_Tool.hxx>
22 #include <TDocStd_XLink.hxx>
23 #include <XmlMDocStd_XLinkDriver.hxx>
24 #include <XmlObjMgt.hxx>
25 #include <XmlObjMgt_Persistent.hxx>
26
IMPLEMENT_STANDARD_RTTIEXT(XmlMDocStd_XLinkDriver,XmlMDF_ADriver)27 IMPLEMENT_STANDARD_RTTIEXT(XmlMDocStd_XLinkDriver,XmlMDF_ADriver)
28 IMPLEMENT_DOMSTRING (DocEntryString, "documentEntry")
29
30 //=======================================================================
31 //function : XmlMDocStd_XLinkDriver
32 //purpose : Constructor
33 //=======================================================================
34 XmlMDocStd_XLinkDriver::XmlMDocStd_XLinkDriver
35 (const Handle(Message_Messenger)& theMsgDriver)
36 : XmlMDF_ADriver (theMsgDriver, NULL)
37 {}
38
39 //=======================================================================
40 //function : NewEmpty
41 //purpose :
42 //=======================================================================
Handle(TDF_Attribute)43 Handle(TDF_Attribute) XmlMDocStd_XLinkDriver::NewEmpty() const
44 {
45 return (new TDocStd_XLink());
46 }
47
48 //=======================================================================
49 //function : Paste
50 //purpose : persistent -> transient (retrieve)
51 //=======================================================================
Paste(const XmlObjMgt_Persistent & theSource,const Handle (TDF_Attribute)& theTarget,XmlObjMgt_RRelocationTable &) const52 Standard_Boolean XmlMDocStd_XLinkDriver::Paste
53 (const XmlObjMgt_Persistent& theSource,
54 const Handle(TDF_Attribute)& theTarget,
55 XmlObjMgt_RRelocationTable& ) const
56 {
57 XmlObjMgt_DOMString anXPath = XmlObjMgt::GetStringValue (theSource);
58
59 if (anXPath == NULL)
60 {
61 myMessageDriver->Send ("XLink: Cannot retrieve reference string from element", Message_Fail);
62 return Standard_False;
63 }
64
65 TCollection_AsciiString anEntry;
66 if (XmlObjMgt::GetTagEntryString (anXPath, anEntry) == Standard_False)
67 {
68 TCollection_ExtendedString aMessage =
69 TCollection_ExtendedString ("Cannot retrieve XLink reference from \"")
70 + anXPath + '\"';
71 myMessageDriver->Send (aMessage, Message_Fail);
72 return Standard_False;
73 }
74
75 Handle(TDocStd_XLink) aRef = Handle(TDocStd_XLink)::DownCast(theTarget);
76
77 // set referenced label
78 aRef->LabelEntry(anEntry);
79
80 // document entry
81 aRef->DocumentEntry(theSource.Element().getAttribute(::DocEntryString()));
82
83 return Standard_True;
84 }
85
86 //=======================================================================
87 //function : Paste
88 //purpose : transient -> persistent (store)
89 // <label tag='1'> <This is label entry 0:4:1>
90 // ...
91 // <label tag='8'> <This is label entry 0:4:1:8>
92 //
93 // <TDocStd_XLink id="621"> /document/label/label[@tag="4"]/label[@tag="1"]
94 // </TDocStd_XLink> <This is reference to label 0:4:1>
95 //=======================================================================
Paste(const Handle (TDF_Attribute)& theSource,XmlObjMgt_Persistent & theTarget,XmlObjMgt_SRelocationTable &) const96 void XmlMDocStd_XLinkDriver::Paste (const Handle(TDF_Attribute)& theSource,
97 XmlObjMgt_Persistent& theTarget,
98 XmlObjMgt_SRelocationTable& ) const
99 {
100 Handle(TDocStd_XLink) aRef = Handle(TDocStd_XLink)::DownCast(theSource);
101 if (!aRef.IsNull())
102 {
103 // reference
104 TCollection_AsciiString anEntry = aRef->LabelEntry();
105 XmlObjMgt_DOMString aDOMString;
106 XmlObjMgt::SetTagEntryString (aDOMString, anEntry);
107 XmlObjMgt::SetStringValue (theTarget, aDOMString);
108
109 // document entry
110 theTarget.Element().setAttribute(::DocEntryString(),
111 aRef->DocumentEntry().ToCString());
112 }
113 }
114