added open-ended field name handling
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: internfile.cpp,v 1.30 2007-05-23 08:29:04 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: internfile.cpp,v 1.31 2007-06-19 08:36:24 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -270,12 +270,12 @@ static const string keyab("abstract");
|
||||
static const string keyau("author");
|
||||
static const string keycs("charset");
|
||||
static const string keyct("content");
|
||||
static const string keyds("description");
|
||||
static const string keyfn("filename");
|
||||
static const string keykw("keywords");
|
||||
static const string keymd("modificationdate");
|
||||
static const string keymt("mimetype");
|
||||
static const string keyoc("origcharset");
|
||||
static const string keysm("sample");
|
||||
static const string keytt("title");
|
||||
|
||||
bool FileInterner::dijontorcl(Rcl::Doc& doc)
|
||||
@@ -283,15 +283,24 @@ bool FileInterner::dijontorcl(Rcl::Doc& doc)
|
||||
Dijon::Filter *df = m_handlers.back();
|
||||
const std::map<std::string, std::string>& docdata = df->get_meta_data();
|
||||
|
||||
getKeyValue(docdata, keyau, doc.author);
|
||||
getKeyValue(docdata, keyoc, doc.origcharset);
|
||||
getKeyValue(docdata, keyct, doc.text);
|
||||
getKeyValue(docdata, keytt, doc.title);
|
||||
getKeyValue(docdata, keykw, doc.keywords);
|
||||
getKeyValue(docdata, keymd, doc.dmtime);
|
||||
if (!getKeyValue(docdata, keyab, doc.abstract))
|
||||
getKeyValue(docdata, keysm, doc.abstract);
|
||||
LOGDEB1(("FILENAME: %s\n", doc.utf8fn.c_str()));
|
||||
for (map<string,string>::const_iterator it = docdata.begin();
|
||||
it != docdata.end(); it++) {
|
||||
if (it->first == keyct) {
|
||||
doc.text = it->second;
|
||||
} else if (it->first == keymd) {
|
||||
doc.dmtime = it->second;
|
||||
} else if (it->first == keyoc) {
|
||||
doc.origcharset = it->second;
|
||||
} else if (it->first == keymt || it->first == keycs) {
|
||||
// don't need these.
|
||||
} else {
|
||||
doc.meta[it->first] = it->second;
|
||||
}
|
||||
}
|
||||
if (doc.meta[keyab].empty() && !doc.meta[keyds].empty()) {
|
||||
doc.meta[keyab] = doc.meta[keyds];
|
||||
doc.meta.erase(keyds);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -324,7 +333,7 @@ void FileInterner::collectIpathAndMT(Rcl::Doc& doc, string& ipath) const
|
||||
} else {
|
||||
ipath += isep;
|
||||
}
|
||||
getKeyValue(docdata, keyau, doc.author);
|
||||
getKeyValue(docdata, keyau, doc.meta["author"]);
|
||||
getKeyValue(docdata, keymd, doc.dmtime);
|
||||
}
|
||||
|
||||
@@ -672,7 +681,7 @@ int main(int argc, char **argv)
|
||||
"]]]]\n-----------------------------------------------------\n" <<
|
||||
"doc.keywords [[[[" << doc.keywords <<
|
||||
"]]]]\n-----------------------------------------------------\n" <<
|
||||
"doc.abstract [[[[" << doc.abstract <<
|
||||
"doc.meta["abstract"] [[[[" << doc.meta["abstract"] <<
|
||||
"]]]]\n-----------------------------------------------------\n" <<
|
||||
"doc.text [[[[" << doc.text << "]]]]\n";
|
||||
}
|
||||
|
||||
@@ -136,15 +136,16 @@ bool MimeHandlerHtml::next_document()
|
||||
m_metaData["origcharset"] = m_defcharset;
|
||||
m_metaData["content"] = result.dump;
|
||||
m_metaData["charset"] = "utf-8";
|
||||
m_metaData["title"] = result.title;
|
||||
m_metaData["keywords"] = result.keywords;
|
||||
// Avoid setting empty values which would crush ones possibly inherited
|
||||
// from parent (if we're an attachment)
|
||||
if (!result.author.empty())
|
||||
m_metaData["author"] = result.author;
|
||||
if (!result.dmtime.empty())
|
||||
m_metaData["modificationdate"] = result.dmtime;
|
||||
m_metaData["sample"] = result.sample;
|
||||
m_metaData["mimetype"] = "text/plain";
|
||||
|
||||
for (map<string,string>::const_iterator it = result.meta.begin();
|
||||
it != result.meta.end(); it++) {
|
||||
if (!it->second.empty())
|
||||
m_metaData[it->first] = it->second;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -144,22 +144,7 @@ MyHtmlParser::opening_tag(const string &tag, const map<string,string> &p)
|
||||
if ((j = p.find("name")) != p.end()) {
|
||||
string name = j->second;
|
||||
lowercase_term(name);
|
||||
if (name == "description") {
|
||||
if (sample.empty()) {
|
||||
sample = i->second;
|
||||
decode_entities(sample);
|
||||
}
|
||||
} else if (name == "keywords") {
|
||||
if (!keywords.empty()) keywords += ' ';
|
||||
string tmp = i->second;
|
||||
decode_entities(tmp);
|
||||
keywords += tmp;
|
||||
} else if (name == "author") {
|
||||
if (!author.empty()) author += ' ';
|
||||
string tmp = i->second;
|
||||
decode_entities(tmp);
|
||||
author += tmp;
|
||||
} else if (name == "date") {
|
||||
if (name == "date") {
|
||||
// Yes this doesnt exist. It's output by filters
|
||||
// And the format isn't even standard http/html
|
||||
// FIXME
|
||||
@@ -172,7 +157,14 @@ MyHtmlParser::opening_tag(const string &tag, const map<string,string> &p)
|
||||
sprintf(ascuxtime, "%ld", (long)mktime(&tm));
|
||||
dmtime = ascuxtime;
|
||||
}
|
||||
}
|
||||
} else if (name == "robots") {
|
||||
} else {
|
||||
if (!meta[name].empty())
|
||||
meta[name] += ' ';
|
||||
string tmp = i->second;
|
||||
decode_entities(tmp);
|
||||
meta[name] += tmp;
|
||||
}
|
||||
} else if ((j = p.find("http-equiv")) != p.end()) {
|
||||
string hequiv = j->second;
|
||||
lowercase_term(hequiv);
|
||||
@@ -309,8 +301,8 @@ MyHtmlParser::closing_tag(const string &tag)
|
||||
break;
|
||||
case 't':
|
||||
if (tag == "title") {
|
||||
if (title.empty()) {
|
||||
title = dump;
|
||||
if (meta["title"].empty()) {
|
||||
meta["title"] = dump;
|
||||
dump = "";
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
* USA
|
||||
* -----END-LICENCE-----
|
||||
*/
|
||||
#include <map>
|
||||
using std::map;
|
||||
|
||||
#include "htmlparse.h"
|
||||
|
||||
@@ -37,7 +39,8 @@ class MyHtmlParser : public HtmlParser {
|
||||
bool in_body_tag;
|
||||
bool in_pre_tag;
|
||||
bool pending_space;
|
||||
string title, sample, keywords, dump, dmtime, author;
|
||||
map<string,string> meta;
|
||||
string dump, dmtime;
|
||||
string ocharset; // This is the charset our user thinks the doc was
|
||||
string charset; // This is the charset it was supposedly converted to
|
||||
string doccharset; // Set this to value of charset parameter in header
|
||||
|
||||
Reference in New Issue
Block a user