summaryrefslogtreecommitdiffstats
path: root/lib/kofficecore/KoOasisStore.h
blob: e33e95266fa45dc4f83341cca54c13f1635f574f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* This file is part of the KDE project
   Copyright (C) 2005 David Faure <[email protected]>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/
#ifndef KOOASISSTORE_H
#define KOOASISSTORE_H

class TQString;
class TQDomDocument;
class KTempFile;
class KoXmlWriter;
class KoStore;
class KoStoreDevice;
class TQIODevice;

/**
 * Helper class around KoStore for writing out OASIS files.
 * This class helps solving the problem that automatic styles must be before
 * the body, but it's easier to iterate over the application's objects only
 * once. So we open a KoXmlWriter into a memory buffer, write the body into it,
 * collect automatic styles while doing that, write out automatic styles,
 * and then copy the body XML from the buffer into the real KoXmlWriter.
 *
 * The typical use of this class is therefore:
 *   - write body into bodyWriter() and collect auto styles
 *   - write auto styles into contentWriter()
 *   - call closeContentWriter()
 *   - write other files into the store (styles.xml, settings.xml etc.)
 *
 *
 * TODO: maybe we could encapsulate a bit more things, to e.g. handle
 * adding manifest entries automatically.
 *
 * @author: David Faure <[email protected]>
 */
#include <koffice_export.h>

class KOFFICECORE_EXPORT KoOasisStore
{
public:
    /// @param store recontents the property of the caller
    KoOasisStore( KoStore* store );

    ~KoOasisStore();

    KoStore* store() const { return m_store; }

    /// Open contents.xml for writing and return the KoXmlWriter
    KoXmlWriter* contentWriter();

    /// Open another KoXmlWriter for writing out the contents
    /// into a temporary file, to collect automatic styles while doing that.
    KoXmlWriter* bodyWriter();

    /// This will copy the body into the content writer,
    /// delete the bodyWriter and the contentWriter, and then
    /// close contents.xml.
    bool closeContentWriter();

    // For other files in the store, use open/addManifestEntry/KoStoreDevice/createOasisXmlWriter/close

    /// Create and return a manifest writer. It will write to a memory buffer.
    KoXmlWriter* manifestWriter( const char* mimeType );

    /// Close the manifest writer, writing its contents to manifest.xml
    bool closeManifestWriter();

    /// A completely unrelated method, for loading a file from an oasis store
    bool loadAndParse( const TQString& fileName, TQDomDocument& doc, TQString& errorMessage );

    /// Another method for loading: get mimetype from full path, using the manifest
    static TQString mimeForPath( const TQDomDocument& doc, const TQString& fullPath );

private:
    KoStore* m_store;
    KoStoreDevice* m_storeDevice;
    KoXmlWriter* m_contentWriter;
    KoXmlWriter* m_bodyWriter;
    KoXmlWriter* m_manifestWriter;
    KTempFile* m_contentTmpFile;
};

#endif /* KOOASISSTORE_H */