2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // Efficient export/import of BMessages to and from
35 // XML using the Cortex persistence library.
36 // Messages are stored in flattened form.
38 // e.moon 6jul99 Begun.
43 // encoding = 'base64'>
44 // nKJNFBlkn3lknbxlkfnbLKN/lknlknlDSLKn3lkn3l2k35234ljk234
45 // lkdsg23823nlknsdlkbNDSLKBNlkn3lk23n4kl23n423lknLKENL+==
48 #ifndef __FlatMessageIO_H__
49 #define __FlatMessageIO_H__
55 #include "cortex_defs.h"
56 __BEGIN_CORTEX_NAMESPACE
61 public: // *** ctor/dtor/accessor
62 virtual ~FlatMessageIO();
66 // When given a message to export, this object does NOT take
67 // responsibility for deleting it. It will, however, handle
68 // deletion of an imported BMessage.
70 FlatMessageIO(const BMessage
* message
);
71 void setMessage(BMessage
* message
);
73 // Returns 0 if no message has been set, and if no message has
76 const BMessage
* message() const { return m_message
; }
78 // Returns true if the message will be automatically deleted.
80 bool ownsMessage() const { return m_ownMessage
; }
82 public: // *** static setup method
83 // call this method to install hooks for the tags needed by
84 // FlatMessageIO into the given document type
85 static void AddTo(XML::DocumentType
* pDocType
);
87 public: // *** XML formatting
88 static const char* const s_element
;
89 static const uint16 s_encodeToMax
= 72;
90 static const uint16 s_encodeToMin
= 24;
92 public: // *** IPersistent impl.
94 // virtual void xmlExport(
96 // ExportContext& context) const;
101 ExportContext
& context
) const;
103 void xmlExportAttributes(
104 ExportContext
& context
) const;
106 void xmlExportContent(
107 ExportContext
& context
) const;
110 ExportContext
& context
) const;
115 virtual void xmlImportBegin(
116 ImportContext
& context
);
118 virtual void xmlImportAttribute(
121 ImportContext
& context
);
123 virtual void xmlImportContent(
126 ImportContext
& context
);
128 virtual void xmlImportChild(
130 ImportContext
& context
);
132 virtual void xmlImportComplete(
133 ImportContext
& context
);
135 private: // *** members
139 // encoded data is cached here during the import process
140 BString m_base64Data
;
143 __END_CORTEX_NAMESPACE
145 #endif /*__FlatMessageIO_H__*/