Switch to unified view

a/src/internfile/mimehandler.h b/src/internfile/mimehandler.h
...
...
14
 *   Free Software Foundation, Inc.,
14
 *   Free Software Foundation, Inc.,
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
 */
16
 */
17
#ifndef _MIMEHANDLER_H_INCLUDED_
17
#ifndef _MIMEHANDLER_H_INCLUDED_
18
#define _MIMEHANDLER_H_INCLUDED_
18
#define _MIMEHANDLER_H_INCLUDED_
19
/* @(#$Id: mimehandler.h,v 1.12 2006-03-29 13:08:08 dockes Exp $  (C) 2004 J.F.Dockes */
19
/* @(#$Id: mimehandler.h,v 1.13 2006-12-15 12:40:02 dockes Exp $  (C) 2004 J.F.Dockes */
20
20
21
#include <string>
21
#include <string>
22
#include <list>
22
#include <list>
23
using std::string;
24
using std::list;
23
25
24
#include "rclconfig.h"
26
#include <Filter.h>
25
#include "rcldb.h"
26
27
28
class RclConfig;
27
29
28
/**
30
class RecollFilter : public Dijon::Filter {
29
 * Document interner class. 
30
 */
31
class MimeHandler {
32
 public:
31
public:
33
    MimeHandler() : m_forPreview(false) {}
32
    RecollFilter(const string& mtype)
33
  : Dijon::Filter(mtype), m_forPreview(false), m_havedoc(false)
34
    {}
34
    virtual ~MimeHandler() {}
35
    virtual ~RecollFilter() {}
36
    virtual bool set_property(Properties p, const string &v) {
37
  switch (p) {
38
  case DEFAULT_CHARSET: 
39
      m_defcharset = v;
40
      break;
41
  case OPERATING_MODE: 
42
      if (!v.empty() && v[0] == 'v') 
43
      m_forPreview = true; 
44
      else 
45
      m_forPreview = false;
46
      break;
47
  }
48
  return true;
49
    }
35
50
36
    /// Status from mkDoc method.
51
    // We don't use this for now
37
    enum Status {MHError, MHDone, MHAgain};
52
    virtual bool set_document_uri(const std::string &) {return false;}
38
    /**
39
     * Transform external data into internal utf8 document
40
     *
41
     * @param conf the global configuration
42
     * @param filename File from which the data comes from
43
     * @param mimetype its mime type (from the mimemap configuration file)
44
     * @param outdoc   The output document
45
     * @param ipath the access path for the document inside the file. 
46
     *              For mono-document file types, this will always be empty. 
47
     *              It is used, for example for mbox files which may contain
48
     *              multiple emails. If this is not empty in input, then the
49
     *              caller is requesting a single document (ie: for display).
50
     *              If this is empty (during indexation), it will be filled-up
51
     *              by the function, and all the file's documents will be 
52
     *              returned by successive calls.
53
     * @return The return value indicates if there are more documents to be 
54
     *         fetched from the same file.
55
     */
56
    virtual MimeHandler::Status mkDoc(RclConfig * conf, 
57
                    const std::string &filename, 
58
                    const std::string &mimetype, 
59
                    Rcl::Doc& outdoc,
60
                    string& ipath) = 0;
61
53
62
    virtual void setForPreview(bool onoff) {m_forPreview = onoff;};
54
    // Default implementations
55
    virtual bool set_document_string(const std::string &) {return false;}
56
    virtual bool set_document_data(const char *cp, unsigned int sz) {
57
  return set_document_string(string(cp, sz));
58
    }
63
59
60
    virtual bool has_documents() const {return m_havedoc;}
61
62
    // Most doc types are single-doc
63
    virtual bool skip_to_document(const string& s) {
64
  if (s.empty())
65
      return true;
66
  return false;
67
    }
68
69
    virtual DataInput get_required_data_input() const 
70
    {return DOCUMENT_FILE_NAME;}
71
    virtual string get_error() const {
72
  return m_reason;
73
    }
74
64
 protected:
75
protected:
65
    bool m_forPreview;
76
    bool   m_forPreview;
77
    string m_defcharset;
78
    string m_reason;
79
    bool   m_havedoc;
66
};
80
};
67
81
68
/**
82
/**
69
 * Return indexing handler object for the given mime type
83
 * Return indexing handler object for the given mime type
70
 * returned pointer should be deleted by caller
84
 * returned pointer should be deleted by caller
71
 */
85
 */
72
extern MimeHandler *getMimeHandler(const std::string &mtyp, RclConfig *cfg);
86
extern Dijon::Filter *getMimeHandler(const std::string &mtyp, RclConfig *cfg);
73
87
74
/// Can this mime type be interned ?
88
/// Can this mime type be interned ?
75
extern bool canIntern(const std::string mimetype, RclConfig *cfg);
89
extern bool canIntern(const std::string mimetype, RclConfig *cfg);
76
90
77
#endif /* _MIMEHANDLER_H_INCLUDED_ */
91
#endif /* _MIMEHANDLER_H_INCLUDED_ */