19#include "KoOasisStore.h"
21#include "KoDocument.h"
25#include <KoStoreDevice.h>
26#include <KoXmlWriter.h>
28#include <tdetempfile.h>
41 m_manifestWriter( 0 ),
46KoOasisStore::~KoOasisStore()
50 Q_ASSERT( !m_contentWriter );
51 delete m_contentWriter;
52 Q_ASSERT( !m_bodyWriter );
54 Q_ASSERT( !m_storeDevice );
56 Q_ASSERT( !m_contentTmpFile );
57 delete m_contentTmpFile;
58 Q_ASSERT( !m_manifestWriter );
59 delete m_manifestWriter;
64 if ( !m_contentWriter )
66 if ( !m_store->open(
"content.xml" ) )
71 return m_contentWriter;
78 Q_ASSERT( !m_contentTmpFile );
79 m_contentTmpFile =
new KTempFile;
80 m_contentTmpFile->setAutoDelete(
true );
81 m_bodyWriter =
new KoXmlWriter( m_contentTmpFile->file(), 1 );
88 Q_ASSERT( m_bodyWriter );
89 Q_ASSERT( m_contentTmpFile );
91 delete m_bodyWriter; m_bodyWriter = 0;
93 TQFile* tmpFile = m_contentTmpFile->file();
95 m_contentWriter->addCompleteElement( tmpFile );
96 m_contentTmpFile->close();
97 delete m_contentTmpFile; m_contentTmpFile = 0;
99 Q_ASSERT( m_contentWriter );
100 m_contentWriter->endElement();
101 m_contentWriter->endDocument();
102 delete m_contentWriter; m_contentWriter = 0;
103 delete m_storeDevice; m_storeDevice = 0;
104 if ( !m_store->close() )
111 if ( !m_manifestWriter )
114 TQBuffer *manifestBuffer =
new TQBuffer;
115 manifestBuffer->open( IO_WriteOnly );
116 m_manifestWriter =
new KoXmlWriter( manifestBuffer );
117 m_manifestWriter->startDocument(
"manifest:manifest" );
118 m_manifestWriter->startElement(
"manifest:manifest" );
119 m_manifestWriter->addAttribute(
"xmlns:manifest", KoXmlNS::manifest );
120 m_manifestWriter->addManifestEntry(
"/", mimeType );
122 return m_manifestWriter;
127 m_manifestWriter->endElement();
128 m_manifestWriter->endDocument();
129 TQBuffer* buffer =
static_cast<TQBuffer*
>(m_manifestWriter->device());
130 delete m_manifestWriter; m_manifestWriter = 0;
132 if ( m_store->open(
"META-INF/manifest.xml" ) )
134 TQ_LONG written = m_store->write( buffer->buffer() );
135 ok = ( written == (TQ_LONG)buffer->buffer().size() && m_store->close() );
145 if (!m_store->open(fileName))
147 kdWarning(30003) <<
"Entry " << fileName <<
" not found!" << endl;
148 errorMessage = i18n(
"Could not find %1" ).arg( fileName );
153 int errorLine, errorColumn;
159 TQXmlInputSource source( m_store->device() );
161 TQXmlSimpleReader reader;
164 bool ok = doc.setContent( &source, &reader, &errorMsg, &errorLine, &errorColumn );
167 kdError(30003) <<
"Parsing error in " << fileName <<
"! Aborting!" << endl
168 <<
" In line: " << errorLine <<
", column: " << errorColumn << endl
169 <<
" Error message: " << errorMsg << endl;
170 errorMessage = i18n(
"Parsing error in the main document at line %1, column %2\nError message: %3" )
171 .arg( errorLine ).arg( errorColumn ).arg( i18n (
"TQXml", errorMsg.utf8() ) );
175 kdDebug(30003) <<
"File " << fileName <<
" loaded and parsed" << endl;
183 TQDomElement docElem = doc.documentElement();
185 forEachElement( elem, docElem )
187 if ( elem.localName() ==
"file-entry" && elem.namespaceURI() == KoXmlNS::manifest )
189 if ( elem.attributeNS( KoXmlNS::manifest,
"full-path", TQString() ) == fullPath )
190 return elem.attributeNS( KoXmlNS::manifest,
"media-type", TQString() );
static void setupXmlReader(TQXmlSimpleReader &reader, bool namespaceProcessing=false)
setup the XML reader, so that we don't have to duplicate the code.
static KoXmlWriter * createOasisXmlWriter(TQIODevice *dev, const char *rootElementName)
Return an XML writer for saving Oasis XML into the device dev, including the XML processing instructi...
static TQString mimeForPath(const TQDomDocument &doc, const TQString &fullPath)
Another method for loading: get mimetype from full path, using the manifest.
bool closeManifestWriter()
Close the manifest writer, writing its contents to manifest.xml.
bool closeContentWriter()
This will copy the body into the content writer, delete the bodyWriter and the contentWriter,...
KoXmlWriter * contentWriter()
Open contents.xml for writing and return the KoXmlWriter.
KoXmlWriter * bodyWriter()
Open another KoXmlWriter for writing out the contents into a temporary file, to collect automatic sty...
KoXmlWriter * manifestWriter(const char *mimeType)
Create and return a manifest writer. It will write to a memory buffer.
bool loadAndParse(const TQString &fileName, TQDomDocument &doc, TQString &errorMessage)
A completely unrelated method, for loading a file from an oasis store.
KoOasisStore(KoStore *store)
This class implements a TQIODevice around KoStore, so that it can be used to create a TQDomDocument f...
Saves and loads KOffice documents using various backends.
A class for writing out XML (to any TQIODevice), with a special attention on performance.