b311480e |
1 | // Created on: 2001-09-04 |
2 | // Created by: Julia DOROVSKIKH |
973c2be1 |
3 | // Copyright (c) 2001-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
7fd59977 |
16 | |
42cf5bc1 |
17 | #include <CDM_MessageDriver.hxx> |
18 | #include <Standard_Type.hxx> |
19 | #include <TDF_Attribute.hxx> |
7fd59977 |
20 | #include <TDF_Label.hxx> |
42cf5bc1 |
21 | #include <TDF_Tool.hxx> |
22 | #include <TDocStd_XLink.hxx> |
23 | #include <XmlMDocStd_XLinkDriver.hxx> |
24 | #include <XmlObjMgt.hxx> |
25 | #include <XmlObjMgt_Persistent.hxx> |
7fd59977 |
26 | |
92efcf78 |
27 | IMPLEMENT_STANDARD_RTTIEXT(XmlMDocStd_XLinkDriver,XmlMDF_ADriver) |
7fd59977 |
28 | IMPLEMENT_DOMSTRING (DocEntryString, "documentEntry") |
29 | |
30 | //======================================================================= |
31 | //function : XmlMDocStd_XLinkDriver |
32 | //purpose : Constructor |
33 | //======================================================================= |
34 | XmlMDocStd_XLinkDriver::XmlMDocStd_XLinkDriver |
35 | (const Handle(CDM_MessageDriver)& theMsgDriver) |
36 | : XmlMDF_ADriver (theMsgDriver, NULL) |
37 | {} |
38 | |
39 | //======================================================================= |
40 | //function : NewEmpty |
41 | //purpose : |
42 | //======================================================================= |
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 | //======================================================================= |
52 | 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 | WriteMessage ("XLink: Cannot retrieve reference string from element"); |
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 | WriteMessage (aMessage); |
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 | //======================================================================= |
96 | 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 | } |