static KoDocumentInfo *loadDocumentInfo(const QString &odt) { KoStore *store = KoStore::createStore(odt, KoStore::Read, "", KoStore::Zip); KoOdfReadStore odfReadStore(store); KoXmlDocument metaDoc; KoDocumentInfo *documentInfo = new KoDocumentInfo; QString error; if (!odfReadStore.loadAndParse("meta.xml", metaDoc, error)) { delete store; delete documentInfo; return 0; } if (!documentInfo->loadOasis(metaDoc)) { delete store; delete documentInfo; return 0; } delete store; return documentInfo; }
KoFilter::ConversionStatus Odp2Kpr::convert( const QByteArray& from, const QByteArray& to ) { if ( to != "application/x-kpresenter" || from != "application/vnd.oasis.opendocument.presentation" ) return KoFilter::NotImplemented; KoStoreDevice* inpdev = m_chain->storageFile( "content.xml", KoStore::Read ); if ( !inpdev ) { kError(31000) << "Unable to open input stream"; return KoFilter::StorageCreationError; } // Parse presentation content.xml QXmlInputSource source( inpdev ); QXmlSimpleReader reader; KoOdfReadStore::setupXmlReader( reader, true /*namespaceProcessing*/ ); QString errorMsg; int errorLine, errorColumn; bool ok = doc.setContent( &source, &reader, &errorMsg, &errorLine, &errorColumn ); if ( !ok ) { kError(31000) << "Parsing error! Aborting!" << endl << " In line: " << errorLine << ", column: " << errorColumn << endl << " Error message: " << errorMsg; return KoFilter::ParsingError; } QDomElement docElem = doc.documentElement(); QDomElement realBody( KoDom::namedItemNS( docElem, KoXmlNS::office, "body" ) ); if ( realBody.isNull() ) { kError(31000) << "No office:body found!"; //setErrorMessage( i18n( "Invalid OASIS OpenDocument file. No office:body tag found." ) ); return KoFilter::WrongFormat; } QDomElement body = KoDom::namedItemNS( realBody, KoXmlNS::office, "presentation" ); if ( body.isNull() ) { kError(32001) << "No office:text found!"; return KoFilter::WrongFormat; } //now we can transform it. //Parse meta.xml directly inpdev = m_chain->storageFile( "meta.xml", KoStore::Read ); KoXmlDocument metaDoc; QString errorMessage; KoDocumentInfo info; if ( KoOdfReadStore::loadAndParse( inpdev, metaDoc, errorMessage, "meta.xml" /*just for debug message*/ ) ) { info.loadOasis( metaDoc ); } // Write output file KoStoreDevice* out = m_chain->storageFile( "root", KoStore::Write ); if(!out) { kError(30502) << "Unable to open output file!"; return KoFilter::StorageCreationError; } QByteArray cstring = outdoc.toByteArray(); // utf-8 already out->write( cstring.data(), cstring.length() ); out->close(); //Write documentinfo.xml out = m_chain->storageFile( "documentinfo.xml", KoStore::Write ); if(!out) { kError(30502) << "Unable to open output file!"; return KoFilter::StorageCreationError; } QDomDocument doc = info.save(); QByteArray s = doc.toByteArray(); // this is already Utf8! out->write( cstring.data(), cstring.length() ); out->close(); return KoFilter::OK; }