1
/* This file is part of Strigi Desktop Search
3
* Copyright (C) 2006 Jos van den Oever <jos@vandenoever.info>
4
* Copyright (C) 2007 Arend van Beelen jr. <arend@auton.nl>
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Library General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Library General Public License for more details.
16
* You should have received a copy of the GNU Library General Public License
17
* along with this library; see the file COPYING.LIB. If not, write to
18
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
* Boston, MA 02110-1301, USA.
22
#include "odfmimetypelineanalyzer.h"
26
#include <strigi/analysisresult.h>
27
#include <strigi/fieldtypes.h>
29
using namespace Strigi;
32
OdfMimeTypeLineAnalyzerFactory::registerFields(FieldRegister ®) {
33
mimeTypeField = reg.mimetypeField;
34
typeField = reg.typeField;
35
addField(mimeTypeField);
39
Strigi::StreamLineAnalyzer *
40
OdfMimeTypeLineAnalyzerFactory::newInstance() const {
41
return new OdfMimeTypeLineAnalyzer(this);
44
OdfMimeTypeLineAnalyzer::OdfMimeTypeLineAnalyzer(
45
const OdfMimeTypeLineAnalyzerFactory *factory) :
49
assert(m_factory != 0);
53
OdfMimeTypeLineAnalyzer::startAnalysis(AnalysisResult *result) {
56
if(result->fileName() == "mimetype" && result->parent() != 0
57
&& result->parent()->mimeType() == "application/zip") {
58
m_result = result->parent();
66
OdfMimeTypeLineAnalyzer::endAnalysis(bool /*complete*/) {
71
OdfMimeTypeLineAnalyzer::handleLine(const char *data, uint32_t length) {
72
assert(m_result != 0);
74
if (length < 35 || std::strncmp(data,
75
"application/vnd.oasis.opendocument.", 35) != 0) {
80
application/vnd.oasis.opendocument.text odt
81
application/vnd.oasis.opendocument.text-template ott
82
application/vnd.oasis.opendocument.text-master odm
83
application/vnd.oasis.opendocument.text-web oth
84
application/vnd.oasis.opendocument.graphics odg
85
application/vnd.oasis.opendocument.graphics-template otg
86
application/vnd.oasis.opendocument.presentation odp
87
application/vnd.oasis.opendocument.presentation-template otp
88
application/vnd.oasis.opendocument.spreadsheet ods
89
application/vnd.oasis.opendocument.spreadsheet-template ots
90
application/vnd.oasis.opendocument.chart odc
91
application/vnd.oasis.opendocument.chart-template otc
92
application/vnd.oasis.opendocument.image odi
93
application/vnd.oasis.opendocument.image-template oti
94
application/vnd.oasis.opendocument.formula odf
95
application/vnd.oasis.opendocument.formula-template otf
98
const char *rdftype = NULL;
99
if( length >= (35+4) && std::strncmp(data+35, "text", 4) == 0 ) {
100
rdftype = "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#PaginatedTextDocument";
101
} else if ( length >= (35+12) && std::strncmp(data+35, "presentation", 12) == 0 ) {
102
rdftype = "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Presentation";
103
} else if ( length >= (35+11) && std::strncmp(data+35, "spreadsheet", 11) == 0 ) {
104
rdftype = "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Spreadsheet";
108
m_result->addValue(m_factory->typeField, rdftype);
111
std::string mimeType;
112
mimeType.assign(data, length);
114
m_result->addValue(m_factory->mimeTypeField, mimeType);
115
m_result->setMimeType(mimeType);
118
bool OdfMimeTypeLineAnalyzer::isReadyWithStream() {