~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to filters/kspread/xlsx/XlsxXmlCommentsReader.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of Office 2007 Filters for KOffice
 
3
 *
 
4
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 
5
 *
 
6
 * Contact: Suresh Chande suresh.chande@nokia.com
 
7
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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
 
20
 * 02110-1301 USA
 
21
 *
 
22
 */
 
23
 
 
24
#include "XlsxXmlCommentsReader.h"
 
25
#include "XlsxXmlWorksheetReader.h"
 
26
#include "XlsxImport.h"
 
27
#include <MsooXmlSchemas.h>
 
28
 
 
29
//#define MSOOXML_CURRENT_NS
 
30
#define MSOOXML_CURRENT_CLASS XlsxXmlCommentsReaderContext
 
31
#define BIND_READ_CLASS MSOOXML_CURRENT_CLASS
 
32
 
 
33
#include <MsooXmlReader_p.h>
 
34
#include <MsooXmlUtils.h>
 
35
 
 
36
#include <memory>
 
37
 
 
38
XlsxComment::XlsxComment(uint authorId)
 
39
    : m_authorId(authorId)
 
40
{
 
41
}
 
42
 
 
43
XlsxComments::XlsxComments()
 
44
{
 
45
}
 
46
 
 
47
XlsxXmlCommentsReaderContext::XlsxXmlCommentsReaderContext(XlsxComments& _comments)
 
48
    : MSOOXML::MsooXmlReaderContext()
 
49
    , comments(&_comments)
 
50
{
 
51
}
 
52
 
 
53
XlsxXmlCommentsReaderContext::~XlsxXmlCommentsReaderContext()
 
54
{
 
55
}
 
56
 
 
57
XlsxXmlCommentsReader::XlsxXmlCommentsReader(KoOdfWriters *writers)
 
58
    : MSOOXML::MsooXmlCommonReader(writers)
 
59
{
 
60
}
 
61
 
 
62
XlsxXmlCommentsReader::~XlsxXmlCommentsReader()
 
63
{
 
64
}
 
65
 
 
66
KoFilter::ConversionStatus XlsxXmlCommentsReader::read(MSOOXML::MsooXmlReaderContext* context)
 
67
{
 
68
    m_context = dynamic_cast<XlsxXmlCommentsReaderContext*>(context);
 
69
    Q_ASSERT(m_context);
 
70
 
 
71
    const KoFilter::ConversionStatus result = readInternal();
 
72
    m_context = 0;
 
73
    if (result == KoFilter::OK)
 
74
        return KoFilter::OK;
 
75
    return result;
 
76
}
 
77
 
 
78
KoFilter::ConversionStatus XlsxXmlCommentsReader::readInternal()
 
79
{
 
80
    readNext();
 
81
    if (!isStartDocument()) {
 
82
        return KoFilter::WrongFormat;
 
83
    }
 
84
 
 
85
    // comments
 
86
    readNext();
 
87
    kDebug() << *this << namespaceUri();
 
88
 
 
89
    if (!expectEl("comments")) {
 
90
        return KoFilter::WrongFormat;
 
91
    }
 
92
    if (!expectNS(MSOOXML::Schemas::spreadsheetml)) {
 
93
        return KoFilter::WrongFormat;
 
94
    }
 
95
 
 
96
    QXmlStreamNamespaceDeclarations namespaces(namespaceDeclarations());
 
97
    for (int i = 0; i < namespaces.count(); i++) {
 
98
        kDebug() << "NS prefix:" << namespaces[i].prefix() << "uri:" << namespaces[i].namespaceUri();
 
99
    }
 
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;
 
105
    }
 
106
//! @todo expect other namespaces too...
 
107
 
 
108
    TRY_READ(comments)
 
109
 
 
110
    kDebug() << "===========finished============";
 
111
    return KoFilter::OK;
 
112
}
 
113
 
 
114
#undef CURRENT_EL
 
115
#define CURRENT_EL comments
 
116
KoFilter::ConversionStatus XlsxXmlCommentsReader::read_comments()
 
117
{
 
118
    READ_PROLOGUE
 
119
    while (!atEnd()) {
 
120
        readNext();
 
121
        BREAK_IF_END_OF(CURRENT_EL);
 
122
        if (isStartElement()) {
 
123
            TRY_READ_IF(authors)
 
124
            ELSE_TRY_READ_IF(commentList)
 
125
//            ELSE_TRY_READ_IF(extLst)
 
126
        }
 
127
    }
 
128
    READ_EPILOGUE
 
129
}
 
130
 
 
131
//! 18.7.2 authors (Authors)
 
132
#undef CURRENT_EL
 
133
#define CURRENT_EL authors
 
134
KoFilter::ConversionStatus XlsxXmlCommentsReader::read_authors()
 
135
{
 
136
    READ_PROLOGUE
 
137
    while (!atEnd()) {
 
138
        readNext();
 
139
        BREAK_IF_END_OF(CURRENT_EL);
 
140
        if (isStartElement()) {
 
141
            TRY_READ_IF(author)
 
142
            ELSE_WRONG_FORMAT
 
143
        }
 
144
    }
 
145
    READ_EPILOGUE
 
146
}
 
147
 
 
148
//! 18.7.1 author (Author)
 
149
#undef CURRENT_EL
 
150
#define CURRENT_EL author
 
151
KoFilter::ConversionStatus XlsxXmlCommentsReader::read_author()
 
152
{
 
153
    READ_PROLOGUE
 
154
    readNext();
 
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);
 
158
    while (!atEnd()) {
 
159
        readNext();
 
160
        BREAK_IF_END_OF(CURRENT_EL);
 
161
    }
 
162
    READ_EPILOGUE
 
163
}
 
164
 
 
165
#undef CURRENT_EL
 
166
#define CURRENT_EL commentList
 
167
KoFilter::ConversionStatus XlsxXmlCommentsReader::read_commentList()
 
168
{
 
169
    READ_PROLOGUE
 
170
    while (!atEnd()) {
 
171
        readNext();
 
172
        BREAK_IF_END_OF(CURRENT_EL);
 
173
        if (isStartElement()) {
 
174
            TRY_READ_IF(comment)
 
175
            ELSE_WRONG_FORMAT
 
176
        }
 
177
    }
 
178
    READ_EPILOGUE
 
179
}
 
180
 
 
181
#undef CURRENT_EL
 
182
#define CURRENT_EL comment
 
183
KoFilter::ConversionStatus XlsxXmlCommentsReader::read_comment()
 
184
{
 
185
    READ_PROLOGUE
 
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));
 
192
    while (!atEnd()) {
 
193
        readNext();
 
194
        BREAK_IF_END_OF(CURRENT_EL);
 
195
        if (isStartElement()) {
 
196
            TRY_READ_IF(text)
 
197
            //! @todo ELSE_TRY_READ_IF(commentPr)
 
198
            //! @todo add ELSE_WRONG_FORMAT
 
199
        }
 
200
    }
 
201
    if (comment.get()) {
 
202
        comment.get()->texts = m_currentCommentText;
 
203
        m_context->comments->insert(ref, comment.release());
 
204
        kDebug() << "Added comment for" << ref;
 
205
    }
 
206
    READ_EPILOGUE
 
207
}
 
208
 
 
209
#undef CURRENT_EL
 
210
#define CURRENT_EL text
 
211
KoFilter::ConversionStatus XlsxXmlCommentsReader::read_text()
 
212
{
 
213
    READ_PROLOGUE
 
214
    m_currentCommentText.clear();
 
215
    while (!atEnd()) {
 
216
        readNext();
 
217
        BREAK_IF_END_OF(CURRENT_EL);
 
218
        if (isStartElement()) {
 
219
            TRY_READ_IF(r)
 
220
            ELSE_TRY_READ_IF(t)
 
221
            //! @todo ELSE_TRY_READ_IF(rPh)
 
222
            //! @todo ELSE_TRY_READ_IF(phoneticPr)
 
223
            //! @todo add ELSE_WRONG_FORMAT
 
224
        }
 
225
    }
 
226
    READ_EPILOGUE
 
227
}
 
228
 
 
229
#undef CURRENT_EL
 
230
#define CURRENT_EL r
 
231
KoFilter::ConversionStatus XlsxXmlCommentsReader::read_r()
 
232
{
 
233
    READ_PROLOGUE
 
234
    while (!atEnd()) {
 
235
        readNext();
 
236
        BREAK_IF_END_OF(CURRENT_EL);
 
237
        if (isStartElement()) {
 
238
            TRY_READ_IF(t)
 
239
            //! @todo ELSE_TRY_READ_IF(rPr)
 
240
            //! @todo add ELSE_WRONG_FORMAT
 
241
        }
 
242
    }
 
243
    kDebug() << m_currentCommentText;
 
244
    READ_EPILOGUE
 
245
}
 
246
 
 
247
#undef CURRENT_EL
 
248
#define CURRENT_EL t
 
249
KoFilter::ConversionStatus XlsxXmlCommentsReader::read_t()
 
250
{
 
251
    READ_PROLOGUE
 
252
    readNext();
 
253
    //! @todo is trimming ok here?
 
254
    m_currentCommentText += text().toString().trimmed();
 
255
    while (!atEnd()) {
 
256
        readNext();
 
257
        BREAK_IF_END_OF(CURRENT_EL);
 
258
    }
 
259
    READ_EPILOGUE
 
260
}