1 // Created on: 2017-02-14
2 // Created by: Sergey NIKONOV
3 // Copyright (c) 2008-2017 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 #include <Message_Messenger.hxx>
17 #include <Standard_Type.hxx>
18 #include <XCAFDoc_NoteBinData.hxx>
19 #include <XmlObjMgt.hxx>
20 #include <XmlMXCAFDoc_NoteBinDataDriver.hxx>
21 #include <XmlObjMgt_Persistent.hxx>
22 #include <LDOM_OSStream.hxx>
24 IMPLEMENT_STANDARD_RTTIEXT(XmlMXCAFDoc_NoteBinDataDriver, XmlMXCAFDoc_NoteDriver)
25 IMPLEMENT_DOMSTRING(Title, "title")
26 IMPLEMENT_DOMSTRING(MIMEtype, "mime_type")
27 IMPLEMENT_DOMSTRING(Size, "size")
29 //=======================================================================
32 //=======================================================================
33 XmlMXCAFDoc_NoteBinDataDriver::XmlMXCAFDoc_NoteBinDataDriver(const Handle(Message_Messenger)& theMsgDriver)
34 : XmlMXCAFDoc_NoteDriver(theMsgDriver, STANDARD_TYPE(XCAFDoc_NoteBinData)->Name())
38 //=======================================================================
41 //=======================================================================
42 Handle(TDF_Attribute) XmlMXCAFDoc_NoteBinDataDriver::NewEmpty() const
44 return new XCAFDoc_NoteBinData();
47 //=======================================================================
50 //=======================================================================
51 Standard_Boolean XmlMXCAFDoc_NoteBinDataDriver::Paste(const XmlObjMgt_Persistent& theSource,
52 const Handle(TDF_Attribute)& theTarget,
53 XmlObjMgt_RRelocationTable& theRelocTable) const
55 XmlMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable);
57 const XmlObjMgt_Element& anElement = theSource;
59 XmlObjMgt_DOMString aTitle = anElement.getAttribute(::Title());
60 XmlObjMgt_DOMString aMIMEtype = anElement.getAttribute(::MIMEtype());
61 XmlObjMgt_DOMString aSize = anElement.getAttribute(::Size());
62 if (aTitle == NULL || aMIMEtype == NULL || aSize == NULL)
63 return Standard_False;
65 Handle(XCAFDoc_NoteBinData) aNote = Handle(XCAFDoc_NoteBinData)::DownCast(theTarget);
67 return Standard_False;
69 Standard_Integer nbSize = 0;
70 if (!aSize.GetInteger(nbSize))
71 return Standard_False;
73 XmlObjMgt_DOMString aDataStr = XmlObjMgt::GetStringValue(theSource);
74 Standard_SStream anSS(aDataStr.GetString());
76 Handle(TColStd_HArray1OfByte) aData = new TColStd_HArray1OfByte(1, nbSize);
77 for (Standard_Integer i = 1; i <= nbSize; ++i)
81 aData->ChangeValue(i) = aValue;
84 aNote->Set(aTitle.GetString(), aMIMEtype.GetString(), aData);
89 //=======================================================================
92 //=======================================================================
93 void XmlMXCAFDoc_NoteBinDataDriver::Paste(const Handle(TDF_Attribute)& theSource,
94 XmlObjMgt_Persistent& theTarget,
95 XmlObjMgt_SRelocationTable& theRelocTable) const
97 XmlMXCAFDoc_NoteDriver::Paste(theSource, theTarget, theRelocTable);
99 Handle(XCAFDoc_NoteBinData) aNote = Handle(XCAFDoc_NoteBinData)::DownCast(theSource);
101 XmlObjMgt_DOMString aTitle(TCollection_AsciiString(aNote->Title()).ToCString());
102 XmlObjMgt_DOMString aMIMEtype(aNote->MIMEtype().ToCString());
104 theTarget.Element().setAttribute(::Title(), aTitle);
105 theTarget.Element().setAttribute(::MIMEtype(), aMIMEtype);
106 theTarget.Element().setAttribute(::Size(), aNote->Size());
108 if (aNote->Size() > 0)
110 const Handle(TColStd_HArray1OfByte)& aData = aNote->Data();
111 LDOM_OSStream anOSS(aNote->Size());
112 for (Standard_Integer i = aData->Lower(); i <= aData->Upper(); ++i)
114 anOSS << std::hex << aData->Value(i);
116 Standard_Character* dump = (Standard_Character*)anOSS.str(); // copying! Don't forget to delete it.
117 XmlObjMgt::SetStringValue(theTarget, dump, Standard_True);