1 // FlatMessageIO.h 2 // * PURPOSE 3 // Efficient export/import of BMessages to and from 4 // XML using the Cortex persistence library. 5 // Messages are stored in flattened form. 6 // * HISTORY 7 // e.moon 6jul99 Begun. 8 // 9 // Example: 10 // 11 // <flat-BMessage 12 // encoding = 'base64'> 13 // nKJNFBlkn3lknbxlkfnbLKN/lknlknlDSLKn3lkn3l2k35234ljk234 14 // lkdsg23823nlknsdlkbNDSLKBNlkn3lk23n4kl23n423lknLKENL+== 15 // </flat-BMessage> 16 17 #ifndef __FlatMessageIO_H__ 18 #define __FlatMessageIO_H__ 19 20 #include <Message.h> 21 #include <String.h> 22 #include "XML.h" 23 24 #include "cortex_defs.h" 25 __BEGIN_CORTEX_NAMESPACE 26 27 class FlatMessageIO : 28 public IPersistent { 29 30 public: // *** ctor/dtor/accessor 31 virtual ~FlatMessageIO(); 32 33 FlatMessageIO(); 34 35 // When given a message to export, this object does NOT take 36 // responsibility for deleting it. It will, however, handle 37 // deletion of an imported BMessage. 38 39 FlatMessageIO(const BMessage* message); 40 void setMessage(BMessage* message); 41 42 // Returns 0 if no message has been set, and if no message has 43 // been imported. 44 45 const BMessage* message() const { return m_message; } 46 47 // Returns true if the message will be automatically deleted. 48 49 bool ownsMessage() const { return m_ownMessage; } 50 51 public: // *** static setup method 52 // call this method to install hooks for the tags needed by 53 // FlatMessageIO into the given document type 54 static void AddTo(XML::DocumentType* pDocType); 55 56 public: // *** XML formatting 57 static const char* const s_element; 58 static const uint16 s_encodeToMax = 72; 59 static const uint16 s_encodeToMin = 24; 60 61 public: // *** IPersistent impl. 62 63 // virtual void xmlExport( 64 // ostream& stream, 65 // ExportContext& context) const; 66 67 // EXPORT: 68 69 void xmlExportBegin( 70 ExportContext& context) const; 71 72 void xmlExportAttributes( 73 ExportContext& context) const; 74 75 void xmlExportContent( 76 ExportContext& context) const; 77 78 void xmlExportEnd( 79 ExportContext& context) const; 80 81 82 // IMPORT: 83 84 virtual void xmlImportBegin( 85 ImportContext& context); 86 87 virtual void xmlImportAttribute( 88 const char* key, 89 const char* value, 90 ImportContext& context); 91 92 virtual void xmlImportContent( 93 const char* data, 94 uint32 length, 95 ImportContext& context); 96 97 virtual void xmlImportChild( 98 IPersistent* child, 99 ImportContext& context); 100 101 virtual void xmlImportComplete( 102 ImportContext& context); 103 104 private: // *** members 105 bool m_ownMessage; 106 BMessage* m_message; 107 108 // encoded data is cached here during the import process 109 BString m_base64Data; 110 }; 111 112 __END_CORTEX_NAMESPACE 113 114 #endif /*__FlatMessageIO_H__*/ 115