1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
/*
* This file is part of Office 2007 Filters for Calligra
*
* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
*
* Contact: Suresh Chande suresh.chande@nokia.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#include "MsooXmlRelationshipsReader.h"
#include <MsooXmlSchemas.h>
#include <MsooXmlUtils.h>
//#define MSOOXML_CURRENT_NS
#define MSOOXML_CURRENT_CLASS MsooXmlRelationshipsReader
#define BIND_READ_CLASS MSOOXML_CURRENT_CLASS
#include <MsooXmlReader_p.h>
using namespace MSOOXML;
MsooXmlRelationshipsReaderContext::MsooXmlRelationshipsReaderContext(
const QString& _path, const QString& _file, QMap<QString, QString>& _rels,
QMap<QString, QString>& _targetsForTypes)
: path(_path), file(_file)
, rels(&_rels), targetsForTypes(&_targetsForTypes)
{
}
class MsooXmlRelationshipsReader::Private
{
public:
Private() {
}
~Private() {
}
QString pathAndFile;
};
MsooXmlRelationshipsReader::MsooXmlRelationshipsReader(KoOdfWriters *writers)
: MSOOXML::MsooXmlReader(writers)
, m_context(0)
, d(new Private)
{
init();
}
MsooXmlRelationshipsReader::~MsooXmlRelationshipsReader()
{
delete d;
}
void MsooXmlRelationshipsReader::init()
{
}
KoFilter::ConversionStatus MsooXmlRelationshipsReader::read(MSOOXML::MsooXmlReaderContext* context)
{
m_context = dynamic_cast<MsooXmlRelationshipsReaderContext*>(context);
const KoFilter::ConversionStatus result = readInternal();
m_context = 0;
if (result == KoFilter::OK)
return KoFilter::OK;
return result;
}
KoFilter::ConversionStatus MsooXmlRelationshipsReader::readInternal()
{
kDebug() << "=============================";
d->pathAndFile = MsooXmlRelationshipsReader::relKey(m_context->path, m_context->file, QString());
readNext();
if (!isStartDocument()) {
return KoFilter::WrongFormat;
}
// Relationships
readNext();
kDebug() << *this << namespaceUri();
if (!expectEl("Relationships")) {
return KoFilter::WrongFormat;
}
if (!expectNS(MSOOXML::Schemas::relationships)) {
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();
}
TRY_READ(Relationships)
kDebug() << "===========finished============";
return KoFilter::OK;
}
#undef CURRENT_EL
#define CURRENT_EL Relationships
//! Relationships handler
/*!
No parent elements.
Child elements:
- [done] Relationship
*/
KoFilter::ConversionStatus MsooXmlRelationshipsReader::read_Relationships()
{
READ_PROLOGUE
while (!atEnd()) {
readNext();
kDebug() << *this;
BREAK_IF_END_OF(CURRENT_EL)
if (isStartElement()) {
TRY_READ_IF(Relationship)
ELSE_WRONG_FORMAT
}
}
READ_EPILOGUE
}
#undef CURRENT_EL
#define CURRENT_EL Relationship
//! Relationship handler
/*!
Parent elements:
- [done] Relationships
No child elements.
*/
KoFilter::ConversionStatus MsooXmlRelationshipsReader::read_Relationship()
{
READ_PROLOGUE
const QXmlStreamAttributes attrs(attributes());
READ_ATTR_WITHOUT_NS(Id)
READ_ATTR_WITHOUT_NS(Type)
READ_ATTR_WITHOUT_NS(Target)
QString fixedPath(m_context->path);
while (Target.startsWith("../")) {
//kDebug() << "- Target:" << Target << "fixedPath:" << fixedPath;
Target.remove(0, 3);
fixedPath.truncate(fixedPath.lastIndexOf('/'));
//kDebug() << "= Target:" << Target << "fixedPath:" << fixedPath;
}
//kDebug() << "adding rel:";
//kDebug() << d->pathAndFile + Id;
//kDebug() << fixedPath + '/' + Target;
m_context->rels->insert(d->pathAndFile + Id, fixedPath + '/' + Target);
//kDebug() << "added target" << Target << "for type" << Type << "path=" << fixedPath << "key=" << targetKey(m_context->path + '/' + m_context->file, Type);
m_context->targetsForTypes->insert(targetKey(m_context->path + '/' + m_context->file, Type), fixedPath + '/' + Target);
readNext();
READ_EPILOGUE
}
|