2
* This file is part of Office 2007 Filters for KOffice
4
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6
* Contact: Suresh Chande suresh.chande@nokia.com
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public License
10
* version 2.1 as published by the Free Software Foundation.
12
* This library is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24
#include "XlsxXmlCommentsReader.h"
25
#include "XlsxXmlWorksheetReader.h"
26
#include "XlsxImport.h"
27
#include <MsooXmlSchemas.h>
29
//#define MSOOXML_CURRENT_NS
30
#define MSOOXML_CURRENT_CLASS XlsxXmlCommentsReaderContext
31
#define BIND_READ_CLASS MSOOXML_CURRENT_CLASS
33
#include <MsooXmlReader_p.h>
34
#include <MsooXmlUtils.h>
38
XlsxComment::XlsxComment(uint authorId)
39
: m_authorId(authorId)
43
XlsxComments::XlsxComments()
47
XlsxXmlCommentsReaderContext::XlsxXmlCommentsReaderContext(XlsxComments& _comments)
48
: MSOOXML::MsooXmlReaderContext()
49
, comments(&_comments)
53
XlsxXmlCommentsReaderContext::~XlsxXmlCommentsReaderContext()
57
XlsxXmlCommentsReader::XlsxXmlCommentsReader(KoOdfWriters *writers)
58
: MSOOXML::MsooXmlCommonReader(writers)
62
XlsxXmlCommentsReader::~XlsxXmlCommentsReader()
66
KoFilter::ConversionStatus XlsxXmlCommentsReader::read(MSOOXML::MsooXmlReaderContext* context)
68
m_context = dynamic_cast<XlsxXmlCommentsReaderContext*>(context);
71
const KoFilter::ConversionStatus result = readInternal();
73
if (result == KoFilter::OK)
78
KoFilter::ConversionStatus XlsxXmlCommentsReader::readInternal()
81
if (!isStartDocument()) {
82
return KoFilter::WrongFormat;
87
kDebug() << *this << namespaceUri();
89
if (!expectEl("comments")) {
90
return KoFilter::WrongFormat;
92
if (!expectNS(MSOOXML::Schemas::spreadsheetml)) {
93
return KoFilter::WrongFormat;
96
QXmlStreamNamespaceDeclarations namespaces(namespaceDeclarations());
97
for (int i = 0; i < namespaces.count(); i++) {
98
kDebug() << "NS prefix:" << namespaces[i].prefix() << "uri:" << namespaces[i].namespaceUri();
100
//! @todo find out whether the namespace returned by namespaceUri()
101
//! is exactly the same ref as the element of namespaceDeclarations()
102
if (!namespaces.contains(QXmlStreamNamespaceDeclaration(QString(), MSOOXML::Schemas::spreadsheetml))) {
103
raiseError(i18n("Namespace \"%1\" not found", MSOOXML::Schemas::spreadsheetml));
104
return KoFilter::WrongFormat;
106
//! @todo expect other namespaces too...
110
kDebug() << "===========finished============";
115
#define CURRENT_EL comments
116
KoFilter::ConversionStatus XlsxXmlCommentsReader::read_comments()
121
BREAK_IF_END_OF(CURRENT_EL);
122
if (isStartElement()) {
124
ELSE_TRY_READ_IF(commentList)
125
// ELSE_TRY_READ_IF(extLst)
131
//! 18.7.2 authors (Authors)
133
#define CURRENT_EL authors
134
KoFilter::ConversionStatus XlsxXmlCommentsReader::read_authors()
139
BREAK_IF_END_OF(CURRENT_EL);
140
if (isStartElement()) {
148
//! 18.7.1 author (Author)
150
#define CURRENT_EL author
151
KoFilter::ConversionStatus XlsxXmlCommentsReader::read_author()
155
const QString author(text().toString().trimmed());
156
kDebug() << "Added author #" << (m_context->comments->count() + 1) << author;
157
m_context->comments->m_authors.append(author);
160
BREAK_IF_END_OF(CURRENT_EL);
166
#define CURRENT_EL commentList
167
KoFilter::ConversionStatus XlsxXmlCommentsReader::read_commentList()
172
BREAK_IF_END_OF(CURRENT_EL);
173
if (isStartElement()) {
182
#define CURRENT_EL comment
183
KoFilter::ConversionStatus XlsxXmlCommentsReader::read_comment()
186
const QXmlStreamAttributes attrs(attributes());
187
READ_ATTR_WITHOUT_NS(ref)
188
READ_ATTR_WITHOUT_NS(authorId)
189
int authorIdInt = -1;
190
STRING_TO_INT(authorId, authorIdInt, "comment@authorId")
191
std::auto_ptr<XlsxComment> comment(authorIdInt < 0 ? 0 : new XlsxComment(authorIdInt));
194
BREAK_IF_END_OF(CURRENT_EL);
195
if (isStartElement()) {
197
//! @todo ELSE_TRY_READ_IF(commentPr)
198
//! @todo add ELSE_WRONG_FORMAT
202
comment.get()->texts = m_currentCommentText;
203
m_context->comments->insert(ref, comment.release());
204
kDebug() << "Added comment for" << ref;
210
#define CURRENT_EL text
211
KoFilter::ConversionStatus XlsxXmlCommentsReader::read_text()
214
m_currentCommentText.clear();
217
BREAK_IF_END_OF(CURRENT_EL);
218
if (isStartElement()) {
221
//! @todo ELSE_TRY_READ_IF(rPh)
222
//! @todo ELSE_TRY_READ_IF(phoneticPr)
223
//! @todo add ELSE_WRONG_FORMAT
231
KoFilter::ConversionStatus XlsxXmlCommentsReader::read_r()
236
BREAK_IF_END_OF(CURRENT_EL);
237
if (isStartElement()) {
239
//! @todo ELSE_TRY_READ_IF(rPr)
240
//! @todo add ELSE_WRONG_FORMAT
243
kDebug() << m_currentCommentText;
249
KoFilter::ConversionStatus XlsxXmlCommentsReader::read_t()
253
//! @todo is trimming ok here?
254
m_currentCommentText += text().toString().trimmed();
257
BREAK_IF_END_OF(CURRENT_EL);