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 // Export/import of BMessages to and from
35 // XML using the Cortex persistence library.
36 // Messages are stored in a user-readable form.
39 // - sanity-check string values (filter/escape single quotes)
42 // e.moon 1dec99 Begun.
44 #ifndef __MessageIO_H__
45 #define __MessageIO_H__
51 #include "cortex_defs.h"
52 __BEGIN_CORTEX_NAMESPACE
57 public: // *** ctor/dtor/accessor
62 // When given a message to export, this object does NOT take
63 // responsibility for deleting it. It will, however, handle
64 // deletion of an imported BMessage.
67 const BMessage
* message
);
71 // Returns 0 if no message has been set, and if no message has
74 const BMessage
* message() const { return m_message
; }
76 // Returns true if the message will be automatically deleted.
78 bool ownsMessage() const { return m_ownMessage
; }
80 public: // *** static setup method
81 // call this method to install hooks for the tags needed by
82 // MessageIO into the given document type
84 XML::DocumentType
* docType
);
86 public: // *** XML formatting
87 static const char* const s_element
;
89 public: // *** IPersistent impl.
94 ExportContext
& context
) const;
96 void xmlExportAttributes(
97 ExportContext
& context
) const;
99 void xmlExportContent(
100 ExportContext
& context
) const;
103 ExportContext
& context
) const;
108 virtual void xmlImportBegin(
109 ImportContext
& context
);
111 virtual void xmlImportAttribute(
114 ImportContext
& context
);
116 virtual void xmlImportContent(
119 ImportContext
& context
);
121 virtual void xmlImportChild(
123 ImportContext
& context
);
125 virtual void xmlImportComplete(
126 ImportContext
& context
);
128 virtual void xmlImportChildBegin(
130 ImportContext
& context
);
132 virtual void xmlImportChildAttribute(
135 ImportContext
& context
);
137 virtual void xmlImportChildContent(
140 ImportContext
& context
);
142 virtual void xmlImportChildComplete(
144 ImportContext
& context
);
146 private: // *** members
150 // name of the message (if used to import a nested BMessage)
157 bool _isValidMessageElement(
158 const char* element
) const;
160 status_t
_importField(
166 status_t
_exportField(
167 ExportContext
& context
,
174 __END_CORTEX_NAMESPACE
176 #endif /*__MessageIO_H__*/