~ubuntu-branches/ubuntu/oneiric/strigi/oneiric

« back to all changes in this revision

Viewing changes to libstreamanalyzer/lib/lineanalyzers/odfmimetypelineanalyzer.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2011-09-24 17:12:15 UTC
  • mfrom: (1.2.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: package-import@ubuntu.com-20110924171215-zmbi1f77jntvz65h
Tags: upstream-0.7.6
ImportĀ upstreamĀ versionĀ 0.7.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of Strigi Desktop Search
 
2
 *
 
3
 * Copyright (C) 2006 Jos van den Oever <jos@vandenoever.info>
 
4
 * Copyright (C) 2007 Arend van Beelen jr. <arend@auton.nl>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
20
 */
 
21
 
 
22
#include "odfmimetypelineanalyzer.h"
 
23
#include <cassert>
 
24
#include <cstring>
 
25
 
 
26
#include <strigi/analysisresult.h>
 
27
#include <strigi/fieldtypes.h>
 
28
 
 
29
using namespace Strigi;
 
30
 
 
31
void
 
32
OdfMimeTypeLineAnalyzerFactory::registerFields(FieldRegister &reg) {
 
33
    mimeTypeField = reg.mimetypeField;
 
34
    typeField = reg.typeField;
 
35
    addField(mimeTypeField);
 
36
    addField(typeField);
 
37
}
 
38
 
 
39
Strigi::StreamLineAnalyzer *
 
40
OdfMimeTypeLineAnalyzerFactory::newInstance() const {
 
41
    return new OdfMimeTypeLineAnalyzer(this);
 
42
}
 
43
 
 
44
OdfMimeTypeLineAnalyzer::OdfMimeTypeLineAnalyzer(
 
45
        const OdfMimeTypeLineAnalyzerFactory *factory) :
 
46
    m_factory(factory),
 
47
    m_ready(true),
 
48
    m_result(0) {
 
49
    assert(m_factory != 0);
 
50
}
 
51
 
 
52
void
 
53
OdfMimeTypeLineAnalyzer::startAnalysis(AnalysisResult *result) {
 
54
    assert(result != 0);
 
55
 
 
56
    if(result->fileName() == "mimetype" && result->parent() != 0
 
57
            && result->parent()->mimeType() == "application/zip") {
 
58
        m_result = result->parent();
 
59
        m_ready = false;
 
60
    } else {
 
61
        m_ready = true;
 
62
    }
 
63
}
 
64
 
 
65
void
 
66
OdfMimeTypeLineAnalyzer::endAnalysis(bool /*complete*/) {
 
67
    m_result = 0;
 
68
}
 
69
 
 
70
void
 
71
OdfMimeTypeLineAnalyzer::handleLine(const char *data, uint32_t length) {
 
72
    assert(m_result != 0);
 
73
 
 
74
    if (length < 35 || std::strncmp(data,
 
75
            "application/vnd.oasis.opendocument.", 35) != 0) {
 
76
        m_ready = true;
 
77
        return;
 
78
    }
 
79
/*
 
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
 
96
*/
 
97
 
 
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";
 
105
    }
 
106
 
 
107
    if(rdftype) {
 
108
        m_result->addValue(m_factory->typeField, rdftype);
 
109
    }
 
110
 
 
111
    std::string mimeType;
 
112
    mimeType.assign(data, length);
 
113
 
 
114
    m_result->addValue(m_factory->mimeTypeField, mimeType);
 
115
    m_result->setMimeType(mimeType);
 
116
}
 
117
 
 
118
bool OdfMimeTypeLineAnalyzer::isReadyWithStream() {
 
119
    return m_ready;
 
120
}