KoFilter::ConversionStatus VmlDrawingReader::read(MSOOXML::MsooXmlReaderContext* context) { m_context = static_cast<VmlDrawingReaderContext*>(context); readNext(); if (!isStartDocument()) { return KoFilter::WrongFormat; } readNext(); kDebug() << *this << namespaceUri(); if (!expectEl(QList<QByteArray>() << "xml")) { return KoFilter::WrongFormat; } const QString qn(qualifiedName().toString()); RETURN_IF_ERROR(read_xml()) if (!expectElEnd(qn)) { return KoFilter::WrongFormat; } kDebug() << "===========finished============"; return KoFilter::OK; }
KoFilter::ConversionStatus XlsxXmlCommentsReader::readInternal() { readNext(); if (!isStartDocument()) { return KoFilter::WrongFormat; } // comments readNext(); kDebug() << *this << namespaceUri(); if (!expectEl("comments")) { return KoFilter::WrongFormat; } if (!expectNS(MSOOXML::Schemas::spreadsheetml)) { return KoFilter::WrongFormat; } QXmlStreamNamespaceDeclarations namespaces(namespaceDeclarations()); for (int i = 0; i < namespaces.count(); i++) { kDebug() << "NS prefix:" << namespaces[i].prefix() << "uri:" << namespaces[i].namespaceUri(); } //! @todo find out whether the namespace returned by namespaceUri() //! is exactly the same ref as the element of namespaceDeclarations() if (!namespaces.contains(QXmlStreamNamespaceDeclaration(QString(), MSOOXML::Schemas::spreadsheetml))) { raiseError(i18n("Namespace \"%1\" not found", MSOOXML::Schemas::spreadsheetml)); return KoFilter::WrongFormat; } //! @todo expect other namespaces too... TRY_READ(comments) kDebug() << "===========finished============"; return KoFilter::OK; }
OpmlParser::ElementType OpmlParser::elementType() const { if( isEndDocument() || isStartDocument() ) return Document; if( isCDATA() || isCharacters() ) return CharacterData; ElementType elementType = sd.knownElements[ QXmlStreamReader::name().toString()]; return elementType; }
KoFilter::ConversionStatus PptxXmlCommentAuthorsReader::read(MSOOXML::MsooXmlReaderContext* context) { d->context = dynamic_cast<PptxXmlCommentAuthorsReaderContext*>(context); Q_ASSERT(d->context); readNext(); if (!isStartDocument()) { return KoFilter::WrongFormat; } readNext(); TRY_READ(cmAuthorLst) return KoFilter::OK; }
KoFilter::ConversionStatus XlsxXmlDocumentReader::readInternal() { kDebug() << "============================="; readNext(); if (!isStartDocument()) { return KoFilter::WrongFormat; } // workbook readNext(); kDebug() << *this << namespaceUri(); if (!expectEl("workbook")) { return KoFilter::WrongFormat; } if (!expectNS(MSOOXML::Schemas::spreadsheetml)) { return KoFilter::WrongFormat; } /* const QXmlStreamAttributes attrs( attributes() ); for (int i=0; i<attrs.count(); i++) { kDebug() << "1 NS prefix:" << attrs[i].name() << "uri:" << attrs[i].namespaceUri(); }*/ QXmlStreamNamespaceDeclarations namespaces(namespaceDeclarations()); for (int i = 0; i < namespaces.count(); i++) { kDebug() << "NS prefix:" << namespaces[i].prefix() << "uri:" << namespaces[i].namespaceUri(); } //! @todo find out whether the namespace returned by namespaceUri() //! is exactly the same ref as the element of namespaceDeclarations() if (!namespaces.contains(QXmlStreamNamespaceDeclaration(QString(), MSOOXML::Schemas::spreadsheetml))) { raiseError(i18n("Namespace \"%1\" not found", MSOOXML::Schemas::spreadsheetml)); return KoFilter::WrongFormat; } //! @todo expect other namespaces too... TRY_READ(workbook) //! @todo hardcoded font face list; look at fonts used by theme mainStyles->insertFontFace(KOdfFontData("Calibri")); mainStyles->insertFontFace(KOdfFontData("Arial")); mainStyles->insertFontFace(KOdfFontData("Tahoma")); kDebug() << "===========finished============"; return KoFilter::OK; }
KoFilter::ConversionStatus DocxXmlFontTableReader::read(MSOOXML::MsooXmlReaderContext* context) { m_context = dynamic_cast<DocxXmlFontTableReaderContext*>(context); kDebug() << "============================="; readNext(); if (!isStartDocument()) { return KoFilter::WrongFormat; } //w:document readNext(); kDebug() << namespaceUri(); if (!expectEl("w:fonts")) { return KoFilter::WrongFormat; } if (!expectNS(MSOOXML::Schemas::wordprocessingml)) { return KoFilter::WrongFormat; } /* const QXmlStreamAttributes attrs( attributes() ); for (int i=0; i<attrs.count(); i++) { kDebug() << "1 NS prefix:" << attrs[i].name() << "uri:" << attrs[i].namespaceUri(); }*/ QXmlStreamNamespaceDeclarations namespaces(namespaceDeclarations()); for (int i = 0; i < namespaces.count(); i++) { kDebug() << "NS prefix:" << namespaces[i].prefix() << "uri:" << namespaces[i].namespaceUri(); } //! @todo find out whether the namespace returned by namespaceUri() //! is exactly the same ref as the element of namespaceDeclarations() if (!namespaces.contains(QXmlStreamNamespaceDeclaration("w", MSOOXML::Schemas::wordprocessingml))) { raiseError(i18n("Namespace \"%1\" not found", MSOOXML::Schemas::wordprocessingml)); return KoFilter::WrongFormat; } //! @todo expect other namespaces too... TRY_READ(fonts) if (!expectElEnd("w:fonts")) { return KoFilter::WrongFormat; } kDebug() << "===========finished============"; return KoFilter::OK; }
KoFilter::ConversionStatus PptxXmlCommentsReader::read(MSOOXML::MsooXmlReaderContext* context) { d->context = dynamic_cast<PptxXmlCommentsReaderContext*>(context); Q_ASSERT(d->context); readNext(); if (!isStartDocument()) { return KoFilter::WrongFormat; } readNext(); KoFilter::ConversionStatus result = read_cmLst(); Q_ASSERT(result == KoFilter::OK); if( result == KoFilter::OK ) { saveOdfComments(); } return KoFilter::OK; }
QList<KeyData> QCrmlParser::parseQCrml(const QString &filePath) { QList<KeyData> rv; QFile inputFile(filePath); if (!inputFile.exists()) { setError(FileNotFound, QObject::tr("File does not exist: %1").arg(filePath)); return rv; } if (!inputFile.open(QFile::ReadOnly)) { setError(FileOpenError, QObject::tr("Error opening file: %1").arg(filePath)); } setDevice(&inputFile); readNext(); if (QXmlStreamReader::error() != QXmlStreamReader::NoError) { setError(ParseError, QXmlStreamReader::errorString()); rv.clear(); return rv; } if(isStartDocument()) { readNext(); if (QXmlStreamReader::error() != QXmlStreamReader::NoError) { setError(ParseError, QXmlStreamReader::errorString()); rv.clear(); return rv; } } if (isStartElement()) { if (name() == "repository") { rv = parseRepository(); } else { setError(ParseError, QObject::tr("root element is not a repository element")); } } return rv; }
KoFilter::ConversionStatus DocxXmlHeaderReader::read(MSOOXML::MsooXmlReaderContext* context) { m_context = static_cast<DocxXmlDocumentReaderContext*>(context); kDebug() << "============================="; readNext(); if (!isStartDocument()) { return KoFilter::WrongFormat; } readNext(); kDebug() << *this << namespaceUri(); if (!expectEl(QList<QByteArray>() << "w:hdr")) { return KoFilter::WrongFormat; } if (!expectNS(MSOOXML::Schemas::wordprocessingml)) { return KoFilter::WrongFormat; } QXmlStreamNamespaceDeclarations namespaces(namespaceDeclarations()); //! @todo find out whether the namespace returned by namespaceUri() //! is exactly the same ref as the element of namespaceDeclarations() if (!namespaces.contains(QXmlStreamNamespaceDeclaration("w", MSOOXML::Schemas::wordprocessingml))) { raiseError(i18n("Namespace \"%1\" not found", MSOOXML::Schemas::wordprocessingml)); return KoFilter::WrongFormat; } const QString qn(qualifiedName().toString()); RETURN_IF_ERROR(read_hdr()) if (!expectElEnd(qn)) { return KoFilter::WrongFormat; } kDebug() << "===========finished============"; return KoFilter::OK; }
bool TSReader::read(Translator &translator) { STRING(both); STRING(byte); STRING(comment); STRING(context); STRING(defaultcodec); STRING(encoding); STRING(extracomment); STRING(filename); STRING(id); STRING(language); STRING(line); STRING(location); STRING(message); STRING(name); STRING(numerus); STRING(numerusform); STRING(obsolete); STRING(oldcomment); STRING(oldsource); STRING(source); STRING(sourcelanguage); STRING(translation); STRING(translatorcomment); STRING(true); STRING(TS); STRING(type); STRING(unfinished); STRING(userdata); STRING(utf8); STRING(value); //STRING(version); STRING(yes); static const QString strextrans(QLatin1String("extra-")); static const QString strUtf8(QLatin1String("UTF-8")); while (!atEnd()) { readNext(); if (isStartDocument()) { // <!DOCTYPE TS> //qDebug() << attributes(); } else if (isEndDocument()) { // <!DOCTYPE TS> //qDebug() << attributes(); } else if (isDTD()) { // <!DOCTYPE TS> //qDebug() << tokenString(); } else if (elementStarts(strTS)) { // <TS> //qDebug() << "TS " << attributes(); QHash<QString, int> currentLine; QString currentFile; QXmlStreamAttributes atts = attributes(); //QString version = atts.value(strversion).toString(); translator.setLanguageCode(atts.value(strlanguage).toString()); translator.setSourceLanguageCode(atts.value(strsourcelanguage).toString()); while (!atEnd()) { readNext(); if (isEndElement()) { // </TS> found, finish local loop break; } else if (isWhiteSpace()) { // ignore these, just whitespace } else if (elementStarts(strdefaultcodec)) { // <defaultcodec> const QString &codec = readElementText(); if (!codec.isEmpty()) translator.setCodecName(codec.toLatin1()); // </defaultcodec> } else if (isStartElement() && name().toString().startsWith(strextrans)) { // <extra-...> QString tag = name().toString(); translator.setExtra(tag.mid(6), readContents()); // </extra-...> } else if (elementStarts(strcontext)) { // <context> QString context; while (!atEnd()) { readNext(); if (isEndElement()) { // </context> found, finish local loop break; } else if (isWhiteSpace()) { // ignore these, just whitespace } else if (elementStarts(strname)) { // <name> context = readElementText(); // </name> } else if (elementStarts(strmessage)) { // <message> TranslatorMessage::References refs; QString currentMsgFile = currentFile; TranslatorMessage msg; msg.setId(attributes().value(strid).toString()); msg.setContext(context); msg.setType(TranslatorMessage::Finished); msg.setPlural(attributes().value(strnumerus) == stryes); const QStringRef &utf8Attr = attributes().value(strutf8); msg.setNonUtf8(utf8Attr == strboth); msg.setUtf8(msg.isNonUtf8() || utf8Attr == strtrue || attributes().value(strencoding) == strUtf8); while (!atEnd()) { readNext(); if (isEndElement()) { // </message> found, finish local loop msg.setReferences(refs); translator.append(msg); break; } else if (isWhiteSpace()) { // ignore these, just whitespace } else if (elementStarts(strsource)) { // <source>...</source> msg.setSourceText(readContents()); } else if (elementStarts(stroldsource)) { // <oldsource>...</oldsource> msg.setOldSourceText(readContents()); } else if (elementStarts(stroldcomment)) { // <oldcomment>...</oldcomment> msg.setOldComment(readContents()); } else if (elementStarts(strextracomment)) { // <extracomment>...</extracomment> msg.setExtraComment(readContents()); } else if (elementStarts(strtranslatorcomment)) { // <translatorcomment>...</translatorcomment> msg.setTranslatorComment(readContents()); } else if (elementStarts(strlocation)) { // <location/> QXmlStreamAttributes atts = attributes(); QString fileName = atts.value(strfilename).toString(); if (fileName.isEmpty()) { fileName = currentMsgFile; } else { if (refs.isEmpty()) currentFile = fileName; currentMsgFile = fileName; } const QString lin = atts.value(strline).toString(); if (lin.isEmpty()) { translator.setLocationsType(Translator::RelativeLocations); refs.append(TranslatorMessage::Reference(fileName, -1)); } else { bool bOK; int lineNo = lin.toInt(&bOK); if (bOK) { if (lin.startsWith(QLatin1Char('+')) || lin.startsWith(QLatin1Char('-'))) { lineNo = (currentLine[fileName] += lineNo); translator.setLocationsType(Translator::RelativeLocations); } else { translator.setLocationsType(Translator::AbsoluteLocations); } refs.append(TranslatorMessage::Reference(fileName, lineNo)); } } readContents(); } else if (elementStarts(strcomment)) { // <comment>...</comment> msg.setComment(readContents()); } else if (elementStarts(struserdata)) { // <userdata>...</userdata> msg.setUserData(readContents()); } else if (elementStarts(strtranslation)) { // <translation> QXmlStreamAttributes atts = attributes(); QStringRef type = atts.value(strtype); if (type == strunfinished) msg.setType(TranslatorMessage::Unfinished); else if (type == strobsolete) msg.setType(TranslatorMessage::Obsolete); if (msg.isPlural()) { QStringList translations; while (!atEnd()) { readNext(); if (isEndElement()) { break; } else if (isWhiteSpace()) { // ignore these, just whitespace } else if (elementStarts(strnumerusform)) { translations.append(readTransContents()); } else { handleError(); break; } } msg.setTranslations(translations); } else { msg.setTranslation(readTransContents()); } // </translation> } else if (isStartElement() && name().toString().startsWith(strextrans)) { // <extra-...> QString tag = name().toString(); msg.setExtra(tag.mid(6), readContents()); // </extra-...> } else { handleError(); } } // </message> } else { handleError(); } } // </context> } else { handleError(); } } // </TS> } else { handleError(); } } if (hasError()) { m_cd.appendError(errorString()); return false; } return true; }